private void btn_bookSubmit_Click(object sender, EventArgs e)
{
string newBookName = this.tb_bookTitle.Text;
string newBookAuthor = this.tb_bookAuthor.Text;
string newBookISBN = this.tb_bookISBN.Text;
string description = this.tb_bookDesc.Text;
if (bookIsNotValid(newBookISBN, newBookName, newBookAuthor))
{
MessageBox.Show(this.validationError);
return;
}
if (bookService.BookTitleExists(newBookName))
{
MessageBox.Show("A book by this title already exists in the library");
return;
}
if (bookService.ISBNExists(newBookISBN))
{
MessageBox.Show("This ISBN belongs to another book in the library. Please double check the ISBN number and try again");
return;
}
if (this.authorService.doesAuthorExistByName(newBookAuthor))
{
DialogResult result = MessageBox.Show
("This author does not exist in the database. Do you want to add this author?",
"Author Does not Exist", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) this.authorService.addAuthor(newBookAuthor);
if (result == DialogResult.No)
{
MessageBox.Show("New book entry cancled. In order to enter a new book into the system a valid Author must be specified");
return ;
}
}
bookService.addBook(newBookISBN, newBookName, newBookAuthor, description);
MessageBox.Show(
string.Format("{0} succesfully added to the library", newBookName),
string.Format("{0} added Successfully", newBookName),
MessageBoxButtons.OK);
this.clearFields();
}
I actually found giving this thread a title quite hard. Im currently taking a dot Net programming course in C#. We've been given the task of building a simple library using windows forms and Entity Frameworks using a repository service pattern.
I have a form where I'm adding a Book entity to the database aka adding a new book to the library. Things I am doing in this class are checking the fields to make sure that the user actually entered some text, the ISBN number is the right format, the book doesn't already exist.... you get the point. What I've been trying to decide is how to structure the way the processes are carried out. When I click to submit the new book I originally had a bunch of if statements in the on_click method that do my validation.
private void btn_bookSubmit_Click(object sender, EventArgs e)
{
string newBookName = this.tb_bookTitle.Text;
string newBookAuthor = this.tb_bookAuthor.Text;
string newBookISBN = this.tb_bookISBN.Text;
string description = this.tb_bookDesc.Text;
if (bookIsNotValid(newBookISBN, newBookName, newBookAuthor))
{
MessageBox.Show(this.validationError);
return;
}
if (bookService.BookTitleExists(newBookName))
{
MessageBox.Show("A book by this title already exists in the library");
return;
}
if (bookService.ISBNExists(newBookISBN))
{
MessageBox.Show("This ISBN belongs to another book in the library. Please double check the ISBN number and try again");
return;
}
if (this.authorService.doesAuthorExistByName(newBookAuthor))
{
DialogResult result = MessageBox.Show
("This author does not exist in the database. Do you want to add this author?",
"Author Does not Exist", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) this.authorService.addAuthor(newBookAuthor);
if (result == DialogResult.No)
{
MessageBox.Show("New book entry cancled. In order to enter a new book into the system a valid Author must be specified");
return ;
}
}
bookService.addBook(newBookISBN, newBookName, newBookAuthor, description);
MessageBox.Show(
string.Format("{0} succesfully added to the library", newBookName),
string.Format("{0} added Successfully", newBookName),
MessageBoxButtons.OK);
this.clearFields();
}
And I thought to myself; Thats quite a lot of code for one method. So I split it up into more private functions in the form class and ended up with a method that looked like this instead:
private void btn_bookSubmit_Click(object sender, EventArgs e)
{
string newBookName = this.tb_bookTitle.Text;
string newBookAuthor = this.tb_bookAuthor.Text;
string newBookISBN = this.tb_bookISBN.Text;
string description = this.tb_bookDesc.Text;
if (!isBookValid(newBookISBN, newBookName, newBookAuthor)) return;
if (!isTitleValid(newBookName)) return;
if (!isISBNvalid(newBookISBN)) return;
if (!isAuthorNew(newBookAuthor)) return;
bookService.addBook(newBookISBN, newBookName, newBookAuthor, description);
MessageBox.Show(
string.Format("{0} succesfully added to the library", newBookName),
string.Format("{0} added Successfully", newBookName),
MessageBoxButtons.OK);
this.clearFields();
}
Now I have quite a few methods in my class. Is that good practice? It looks a lot cleaner to me, but maybe its harder to sift through methods when going over my class than it is to see all of it happening within the one function. The other thing I thought about was to move all of my validation into one function instead of many, but then I'd have to handle the boolean return and how to stop my function differently.
I've been studying my program for 2 years now, have tried out, javascript, php, html5, c++, C, now c# trying to figure out which I enjoy the most. What I've taken out the most from all the programming is that I love beautiful and efficient code. I may not be able to do that yet, but Im trying my damndest to learn it. So any other shitty practices you might notice please let me know. So far everything works fine in the class and my real question is, is the way I'm implementing my validation process ok? good? shitty? slow?
您可以使用属性vector-effect="non-scaling-stroke"来防止线条与其余线条一起缩放。 参考: http : //www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke 这种修改产生的视觉效果是笔画宽度不依赖于元素的变换(包括非均匀缩放和剪切变换)和缩放级别 看来SVG1.1不支持非缩放笔划,因此最终结果可能取决于渲染引擎。 You can use the attribute vector-effect="non-scaling ...
我不知道任何SVG + CSS解决方案。 您可以使用一些JavaScript来调整大小: // get the bounding box for the text element
var bbox = text.getBBox();
// set the svg width/height accordingly
svg.setAttribute( 'width', bbox.width );
svg.setAttribute( 'height', bbox.height );
// set the vi ...
SVG具有preserveAspectRatio属性。 你把它粘贴在元素上并根据你想要保留宽高比的方式给它一个合适的值,它会为你做所有事情,不需要javascript。 您还需要设置viewBox属性,否则将忽略preserveAspectRatio。 SVG has a preserveAspectRatio attribute. You stick it on the element and give it an appropriate value depending on how ...
画布规范对宽度或高度没有限制 ,因此如果它们是负的,则矩形将以相反的方向绘制。 SVG规范说如果宽度或高度为负, 则不绘制矩形 。 如果要在SVG中实现此功能,则必须确保矩形宽度/高度始终为正并相应地计算x / y。 The canvas specification places no restriction on width or height being negative, so if they were negative the rectangle would draw in the opposite ...
您可以使用getAttribute函数: document.getElementById('cercle1').getAttribute("width");
这将从HTML代码中获取字符串。 正如Phrogz提到的那样,你可能想要一个数字,或者实际值(可能是不同的)。 如果是这样,请参考他的回答 。 You can use the getAttribute function: document.getElementById('cercle1').getAttribute("width");
That w ...