To commemorate the optimized code

Source: Internet
Author: User
BLL. ADCLASS_TAB bll = new BLL. ADCLASS_TAB ();
Model. ADCLASS_TAB model = (Model. ADCLASS_TAB) (ViewState ["Info"]);
Model. QJID = int. Parse (Common. Filter. Auth (Request. QueryString ["AreaID"]); // interval ID
Model. QJLX = textAD. Checked = true? 1: 2; // default range text
System. Text. RegularExpressions. Regex reg1 = new System. Text. RegularExpressions. Regex (@ "^ [-]? \ D + [.]? \ D * $ "); // verify the regular expression of the number and import Text
If (model. QJLX = 1) // text
{
If (! Reg1.IsMatch (txtQJCD. Text. Trim ()))
{
Common. Alert. AddScript ("please ensure that the text length in the interval is limited to numbers! "," Num ");
Return;
}
If (txtQJWB. Text. Trim () = string. Empty)
{
Common. Alert. AddScript ("the default text range cannot be blank! "," Require ");
Return;
}
Model. QJCD = int. Parse (Common. Filter. Auth (txtQJCD. Text. Trim (); // Text Length
Model. QJWB = Common. Filter. Auth (txtQJWB. Text. Trim (); // default Text content
}
Else // Image
{
If (model. QJTP = ""&&! TxtQJTP. HasFile) // no image in the past, and no image now
{
Common. Alert. AddScript ("upload an image! "," Pic ");
Return;
}
If (! Reg1.ismatch (txtqjkd. Text. Trim () |! Reg1.ismatch (txtqjgd. Text. Trim () // The image width and height.
{
Common. Alert. addscript ("the image width and height must be numbers! "," Pic ");
Return;
}
Model. qjkd = int. parse (common. Filter. Auth (txtqjkd. Text. Trim (); // The image width.
Model. qjgd = int. parse (common. Filter. Auth (txtqjgd. Text. Trim (); // The Image Height.
String picType = System. IO. Path. GetExtension (txtQJTP. FileName. Trim (); // whether the image type is standard
Int size = txtQJTP. PostedFile. ContentLength/1024; // whether the size is standard
If (txtQJTP. HasFile) // if there is an image
{
If (! Common. Upload. PicType (picType) |! Common. Upload. PicSize (size ))
{
Common. Alert. AddScript ("the format of the last image is incorrect or the image is too large! "," Pic ");
Return;
}
If (model. QJTP! = String. Empty) // indicates that data has been deleted before.
{
Common. FileManager. DelFile (Server. MapPath ("~ /Uploadfile/ad/"), model. QJTP); // Delete
}
Model. QJTP = Common. webEditer. GetFileName () + picType; // image address
TxtQJTP. SaveAs (Server. MapPath ("~ /Uploadfile/ad/"+ model. QJTP); // upload to the corresponding directory
}
}
If (bll. Update (model)> 0) // The Last Update object information.
{
Common. Alert. AlertAndJump ("/Admin/AD/AreaList. aspx", "Update successful! ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.