protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtName.Text.Trim().Length == 0) { strErr += "Name不能为空!\\n"; } if (this.txtPhotourl.Text.Trim().Length == 0) { strErr += "Photourl不能为空!\\n"; } if (this.txtComment.Text.Trim().Length == 0) { strErr += "Comment不能为空!\\n"; } if (this.txtBeizhu.Text.Trim().Length == 0) { strErr += "Beizhu不能为空!\\n"; } if (!PageValidate.IsDecimal(txtBY1.Text)) { strErr += "BY1格式错误!\\n"; } if (!PageValidate.IsDecimal(txtBY2.Text)) { strErr += "BY2格式错误!\\n"; } if (!PageValidate.IsDecimal(txtBY3.Text)) { strErr += "BY3格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } string Name = this.txtName.Text; string Photourl = this.txtPhotourl.Text; string Comment = this.txtComment.Text; string Beizhu = this.txtBeizhu.Text; decimal BY1 = decimal.Parse(this.txtBY1.Text); decimal BY2 = decimal.Parse(this.txtBY2.Text); decimal BY3 = decimal.Parse(this.txtBY3.Text); byte[] BY4 = new UnicodeEncoding().GetBytes(this.txtBY4.Text); byte[] BY5 = new UnicodeEncoding().GetBytes(this.txtBY5.Text); byte[] BY6 = new UnicodeEncoding().GetBytes(this.txtBY6.Text); byte[] BY7 = new UnicodeEncoding().GetBytes(this.txtBY7.Text); Maticsoft.Model.Homemadetab model = new Maticsoft.Model.Homemadetab(); model.Name = Name; model.Photourl = Photourl; model.Comment = Comment; model.Beizhu = Beizhu; model.BY1 = BY1; model.BY2 = BY2; model.BY3 = BY3; model.BY4 = BY4; model.BY5 = BY5; model.BY6 = BY6; model.BY7 = BY7; Maticsoft.BLL.Homemadetab bll = new Maticsoft.BLL.Homemadetab(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 添加自制商品(确定按钮) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ImageButton1_Click(object sender, EventArgs e) { try { if (TextBox1.Text.Trim() != "") { string t = Convert.ToString("ZZSP" + DateTime.Now.ToString("yyyyMMddhhmmss")); Model.Homemadetab ho = new Model.Homemadetab(); if (FileUpload1.FileName != "") { string name1 = FileUpload1.FileName;//上传文件名字 string type1 = FileUpload1.PostedFile.ContentType; string type11 = name1.Substring(name1.LastIndexOf(".") + 1); //string path1 = HttpContext.Current.Request.MapPath("~/") + "picture\\" + FileUpload1.FileName; if (type11 == "jpg" || type11 == "gif" || type11 == "bmp" || type11 == "png") { string ming1 = name1.Substring(name1.Length - 4, 4); string wj1 = "D1" + t + ming1; string path = HttpContext.Current.Request.MapPath("~/") + "picture\\"; FileUpload1.SaveAs(path + wj1); ho.Photourl = "../picture/" + wj1; ho.Name = TextBox1.Text; ho.Comment = TextBox6.Text; ho.Beizhu = TextBox2.Text; ho.BY1 = 1; int a = hot.Add(ho); if (a > 0) { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('添加成功!');</script>"); bind(sql); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('添加失败!');</script>"); bind(sql); } } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('图片格式不正确请传(.jpg/.gif/.bmp/.png)!');</script>"); } } else { ho.Name = TextBox1.Text; ho.Comment = TextBox6.Text; ho.Beizhu = TextBox2.Text; int a = hot.Add(ho); if (a > 0) { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('添加成功!');</script>"); bind(sql); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('添加失败!');</script>"); bind(sql); } } } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('自制商品名称不能为空!');</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>javascript:showDiv1();</script>"); } } catch (Exception ee) { //Response.Write("<script>alert('确定异常 " + ee.Message + "')</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "this", "<script language=javascript>alert('确定异常 " + ee.Message + "');</script>"); } }