protected void btnPicUpload1_OnClick(object sender, EventArgs e) { this.lblRedInfo.Visible = false; this.btnPicUpload.Enabled = false; if (uploadpic1.FileName == string.Empty || uploadpicsmall.Value == string.Empty) { this.lblRedInfo.Text = "上传大小图片地址不能为空!"; this.lblRedInfo.Visible = true; this.btnPicUpload.Enabled = true; return; } PictureStore ps = (PictureStore)ViewState["PictureStoreInfo"]; UpLoadClass upload = new UpLoadClass(); string filepath = ""; string newfilepath = upload.UploadImageFile(uploadpic1, "/uploadfiles/pictures/"); PicOperate WaterMark = new PicOperate(); //Water Mark Operation filepath = newfilepath.Substring(0, newfilepath.LastIndexOf(".")) + "_new" + System.IO.Path.GetExtension(newfilepath); WaterMark.AddWaterMarkOperate(newfilepath, Server.MapPath(WaterSettings.WaterMarkPath), filepath, WaterSettings.CopyrightText); filepath = GetPath(filepath); System.Threading.Thread.Sleep(1000); string filepathSmall = upload.UpLoadImg(uploadpicsmall, "/uploadfiles/pictures/"); string hairStyleID = ""; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) { string commString = "select id from HairStyle where PictureStoreId=" + ps.PictureStoreID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commString; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { if (sdr.Read()) { hairStyleID = sdr["id"].ToString(); } } } } if (filepath != string.Empty) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) { string commString = "insert into PictureStoreSet(PictureStoreId,PictureStoreURL,SmallPictureUrl,IsHairStyle,HairStylePos) values(" + hairStyleID + ",'" + filepath + "','" + filepathSmall + "',0,0)"; using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commString; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { } } } int pssid = 0; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) { string commString = "select top 1 * from PictureStoreSet where IsHairStyle=0 order by id desc"; using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commString; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { if (sdr.Read()) { pssid = Convert.ToInt32(sdr["ID"].ToString()); } } } } this.lblImg.Text = "<img src='" + filepathSmall + "' width=100 height=50 /><a href='" + filepath + "' target='_blank'><img src='" + filepath + "' width=200 height=100 /></a> <a href='PictureStoreOperate.aspx?id=" + pssid + "&pid=" + ps.PictureStoreID.ToString() + "'>删除</a>" + " " + this.lblImg.Text; this.btnPicUpload.Enabled = true; } }
protected void btnPicUpload1_OnClick(object sender, EventArgs e) { this.lblRedInfo.Visible = false; this.btnPicUpload.Enabled = false; if (uploadpic1.FileName == string.Empty || uploadpicsmall.Value == string.Empty) { this.lblRedInfo.Text = "上传大小图片地址均不能为空!"; this.lblRedInfo.Visible = true; this.btnPicUpload.Enabled = true; return; } UpLoadClass upload = new UpLoadClass(); string filepath = ""; string newfilepath = upload.UploadImageFile(uploadpic1, "/uploadfiles/pictures/"); PicOperate WaterMark = new PicOperate(); //Water Mark Operation filepath = newfilepath.Substring(0, newfilepath.LastIndexOf(".")) + "_new" + System.IO.Path.GetExtension(newfilepath); WaterMark.AddWaterMarkOperate(newfilepath, Server.MapPath(WaterSettings.WaterMarkPath), filepath, WaterSettings.CopyrightText); filepath = GetPath(filepath); System.Threading.Thread.Sleep(1000); string filepathSmall = upload.UpLoadImg(uploadpicsmall, "/uploadfiles/pictures/"); if (filepath != string.Empty) { int num = Convert.ToInt32(Session["num"].ToString()); num++; Session["num"] = num; int picNum = int.Parse(Session["picNum"].ToString()); picNum++; if (picNum == 1) { Session["pic" + num.ToString()] = filepath; Session["picSmall" + num.ToString()] = filepathSmall; this.picString.Text = "<img width=100 heigth=50 src='" + filepathSmall + "' /> <img width=200 heigth=100 src='" + filepath + "' /> <a href='PictureStoreOperate2.aspx?num="+num.ToString()+"'>删除</a>"; this.pic.Text = filepath; this.picsmall.Text = filepathSmall; } else { this.picString.Text += " <img width=100 heigth=50 src='" + filepathSmall + "' /> <img width=200 heigth=100 src='" + filepath + "' /> <a href='PictureStoreOperate2.aspx?num=" + num.ToString() + "'>删除</a>"; this.pic.Text += ";" + filepath; this.picsmall.Text += ";" + filepathSmall; } Session["pic" + num.ToString()] = filepath; Session["picSmall" + num.ToString()] = filepathSmall; Session["picString"] = this.picString.Text; Session["pic"] = this.pic.Text; Session["picSmall"] = this.picsmall.Text; Session["picNum"] = picNum; Session["PSGIDS"] = this.GetPSGIDs(); Session["PictureStoreName"] = txtPictureStoreName.Text.Trim(); Session["PictureStoreDescription"] = txtPictureStoreDescription.Text.Trim(); Session["PictureTags"] = txtPictureStoreTag.Text.Trim(); Session["iHairNature"] = this.ddlHairNature.SelectedItem.Value; Session["iHairQuantity"] = this.ddlHairQuantity.SelectedItem.Value; Session["iFaceStyle"] = this.ddlFaceStyle.SelectedItem.Value; Session["iSex"] = this.ddlSex.SelectedItem.Value; Session["iHairStyleClassName"] = this.ddlHairStyleClassName.SelectedItem.Value; Session["iTemperament"] = this.ddlTemperament.SelectedItem.Value; Session["iOccasion"] = this.ddlOccasion.SelectedItem.Value; Session["bbsUrl"] = txtBbsurl.Text.Trim(); this.btnPicUpload.Enabled = true; } }