protected void btnHairEngineerAdd_Click(object sender, EventArgs e) { if (this.txtHairEngineerTag.Text.Trim() != string.Empty) { string[] tagCondition = this.txtHairEngineerTag.Text.Split(",".ToCharArray()); this.lblRedInfo.Visible = false; for (int k = 0; k < tagCondition.Length; k++) { if (tagCondition[k] == string.Empty) { this.lblRedInfo.Text = "TAG格式不正确(正确的格式 1,2,3)"; this.lblRedInfo.Visible = true; return; } } } HairEngineer he = new HairEngineer(); he.HairEngineerName = txtHairEngineerName.Text.Trim(); //he.HairEngineerAge = txtHairEngineerAge.Text.Trim(); he.HairEngineerSex = int.Parse(rBtnListHairEngineerSex.SelectedValue); he.HairEngineerTel = txtHairEngineerTel.Text.Trim(); he.HairEngineerRawPrice = txtHairEngineerRawPrice.Text.Trim(); he.HairEngineerYear = txtHairEngineerYear.Text.Trim(); he.HairEngineerSkill = txtHairEngineerSkill.Text.Trim(); he.HairEngineerDescription = txtHairEngineerDescription.Text.Trim(); he.HairEngineerConstellation = this.ddlConstellation.SelectedItem.Text; he.HairEngineerClassID = txtHairEngineerClass.Text.Trim(); he.HairEngineerClassName = txtHairEngineerClass.Text.Trim(); he.HairShopID = int.Parse(ddlHairShop.SelectedValue); he.HairShopName = ddlHairShop.SelectedItem.Text; he.IsImportant = this.chkIsImportant.Checked; UpLoadClass upload = new UpLoadClass(); //he.HairEngineerPhoto = upload.UpLoadImg(fileLogo, "/uploadfiles/pictures/"); he.HairEngineerTagIDs = ""; int id = InfoAdmin.AddHairEngineer(he); he.HairEngineerID = id; string content=buildBBSContent(he); int postId = 0; BBSPost post = new BBSPost(); bool bSuc = post.AddPost(he.HairEngineerName, content, BBSPost.Category.HairEngineer, out postId); he.PostId = postId; if (bSuc) { //update postid using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairEngineer set postid=" + he.PostId.ToString() + " where HairEngineerID=" + he.HairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } } } Session["HairEngineerInfo"] = he; if (txtHairEngineerTag.Text.Trim() != string.Empty) { //TAG逻辑 string tagIDs = ""; string[] tagCollection = txtHairEngineerTag.Text.Split(",".ToCharArray()); for (int k = 0; k < tagCollection.Length; k++) { string tagID = ""; bool isExist = false; HairEngineerTag hst = new HairEngineerTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairEngineerTag where HairEngineerTagName='" + tagCollection[k] + "'"; using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { if (sdr.Read()) { try { hst.TagID = int.Parse(sdr["HairEngineerTagID"].ToString()); hst.TagName = sdr["HairEngineerTagName"].ToString(); hst.HairEngineerIDs = sdr["HairEngineerIDs"].ToString(); } catch { } } } } } if (hst.TagID == 0) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "insert HairEngineerTag(HairEngineerTagName,HairEngineerIDs) values('" + tagCollection[k] + "','" + id.ToString() + "');select @@identity;"; using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); tagID = comm.ExecuteScalar().ToString(); } } } else { tagID = hst.TagID.ToString(); if (hst.HairEngineerIDs == string.Empty) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairEngineerTag set HairEngineerIDs='" + id.ToString() + "' where HairEngineerTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } else { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairEngineerTag set HairEngineerIDs=HairEngineerIDs+'," + id.ToString() + "' where HairEngineerTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } } if (k == 0) { tagIDs = tagID; } else { tagIDs += "," + tagID; } } he.HairEngineerTagIDs = tagIDs; he.HairEngineerID = id; ProviderFactory.GetHairEngineerDataProviderInstance().HairEngineerCreateDeleteUpdate(he, UserAction.Update, out id); } id = he.HairEngineerID; //个人图片逻辑 string photoIDs = ""; string[] photoSmallString = lblpicsmallString.Text.Split(";".ToCharArray()); string[] photoString = lblpicSring.Text.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); for(int k=0;k<photoString.Length;k++) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "insert into enginpics(picurl,picsmallurl,ownerid,classid) values('" + photoString[k] + "','"+photoSmallString[k]+"'," + id.ToString() + ",1);select @@identity;"; using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { photoIDs += "," + comm.ExecuteScalar().ToString(); } catch (Exception ex) { throw new Exception(ex.Message); } } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairEngineer set HairEngineerPhotoIDs = '"+photoIDs+"' where HairEngineerID=" + id.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairShop set HairShopEngineerNum = HairShopEngineerNum+1 where HairShopID="+he.HairShopID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } } ResetControlState(); this.Response.Redirect("HairEngineerAddSwitch.aspx?id="+id.ToString()+"&shopid="+this.ddlHairShop.SelectedItem.Value); }
protected void btnSubmit_OnClick(object sender,EventArgs e) { this.btnSubmit.Enabled = false; this.btnSubmit.Visible = false; if (this.txtPictureStoreTag.Text.Trim() != string.Empty) { string[] tagCondition = this.txtPictureStoreTag.Text.Split(",".ToCharArray()); this.lblRedInfo1.Visible = false; for (int k = 0; k < tagCondition.Length; k++) { if (tagCondition[k] == string.Empty) { this.lblRedInfo1.Text = "TAG格式不正确(正确的格式 1,2,3)"; this.lblRedInfo1.Visible = true; return; } } } Session["num"] = ""; Session["picNum"] = ""; Session["PictureStoreName"] = ""; Session["PictureStoreDescription"] = ""; Session["PictureTags"] = ""; Session["iHairNature"] = ""; Session["iHairQuantity"] = ""; Session["iFaceStyle"] = ""; Session["iSex"] = ""; Session["iHairStyleClassName"] = ""; Session["iTemperament"] = ""; Session["iOccasion"] = ""; Session["bbsUrl"] = ""; Session["picString"] = ""; Session["pic"] = ""; Session["picSmall"] = ""; Session["PSGIDS"] = ""; string PSGIDS = this.GetPSGIDs(); PictureStore ps = new PictureStore(); ps.PictureStoreName = txtPictureStoreName.Text.Trim(); ps.PictureStoreGroupIDs = PSGIDS; ps.PictureStoreDescription = txtPictureStoreDescription.Text.Trim(); //ps.PictureStoreHits = 0; ps.PictureStoreCreateTime = DateTime.Now; //ps.PictureStoreRawUrl = ""; //ps.PictureStoreLittleUrl = ""; ps.PictureStoreID = InfoAdmin.AddPictureStore(ps); Byte iHairNature = Byte.Parse(this.ddlHairNature.SelectedItem.Value); Byte iHairQuantity = Byte.Parse(this.ddlHairQuantity.SelectedItem.Value); Byte iFaceStyle = Byte.Parse(this.ddlFaceStyle.SelectedItem.Value); Byte iSex = Byte.Parse(this.ddlSex.SelectedItem.Value); Byte iHairStyleClassName = Byte.Parse(this.ddlHairStyleClassName.SelectedItem.Value); Byte iTemperament = Byte.Parse(this.ddlTemperament.SelectedItem.Value); Byte iOccasion = Byte.Parse(this.ddlOccasion.SelectedItem.Value); string bbsUrl = txtBbsurl.Text.Trim(); int hairShopID = 0; int hairEngineerID = 0; HairStyleEntity HairStyle = new HairStyleEntity(this.txtPictureStoreName.Text.Trim(),iHairQuantity,bbsUrl, hairShopID, hairEngineerID, iHairStyleClassName, iFaceStyle, iTemperament, iOccasion, iSex, iHairNature,ps.PictureStoreID, this.txtPictureStoreDescription.Text.Trim(),PSGIDS,false,0); int newid = 0; InfoAdmin.AddHairStyle(HairStyle,out newid); //问题1-------------- string hstyleid = newid.ToString(); HairStyle.ID = int.Parse(hstyleid); //using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) //{ // string commString = "select id from hairstyle order by id desc"; // using (SqlCommand comm = new SqlCommand()) // { // comm.Connection = conn; // comm.CommandText = commString; // conn.Open(); // hstyleid = comm.ExecuteScalar().ToString(); // HairStyle.ID = int.Parse( hstyleid); // } //} //发帖子 string content = buildBBSContent(HairStyle); BBSPost post = new BBSPost(); int postid = 0; bool bSuc = post.AddPost(HairStyle.HairName, content, BBSPost.Category.PhotoGroup, out postid); if (bSuc) { HairStyle.PostID = postid; using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update hairstyle set postid=" + HairStyle.PostID.ToString() + " where ID=" + HairStyle.ID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { throw new Exception(ex.Message); } } } } //tag逻辑 string tagIDs = ""; string[] tagCollection = txtPictureStoreTag.Text.Split(",".ToCharArray()); if (tagCollection[0] != string.Empty) { for (int k = 0; k < tagCollection.Length; k++) { string tagID = ""; bool isExist = false; PictureStoreTag hst = new PictureStoreTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from PictureStoreTag where PictureStoreTagName='" + tagCollection[k] + "'"; using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { if (sdr.Read()) { try { hst.TagID = int.Parse(sdr["PictureStoreTagID"].ToString()); hst.TagName = sdr["PictureStoreTagName"].ToString(); hst.PictureStoreIDs = sdr["PictureStoreIDs"].ToString(); } catch { } } } } } if (hst.TagID == 0) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "insert PictureStoreTag(PictureStoreTagName,PictureStoreIDs) values('" + tagCollection[k] + "','" + hstyleid.ToString() + "');select @@identity;"; using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); tagID = comm.ExecuteScalar().ToString(); } } } else { tagID = hst.TagID.ToString(); if (hst.PictureStoreIDs == string.Empty) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update PictureStoreTag set PictureStoreIDs='" + hstyleid.ToString() + "' where PictureStoreTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } else { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update PictureStoreTag set PictureStoreIDs=PictureStoreIDs+'," + hstyleid.ToString() + "' where PictureStoreTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } } if (k == 0) { tagIDs = tagID; } else { tagIDs += "," + tagID; } } } HairStyleEntity HairStyle1 = new HairStyleEntity(int.Parse(hstyleid),tagIDs,txtPictureStoreName.Text.Trim(), iHairQuantity, bbsUrl, hairShopID, hairEngineerID, iHairStyleClassName, iFaceStyle, iTemperament, iOccasion, iSex, iHairNature, ps.PictureStoreID, this.txtPictureStoreDescription.Text.Trim(), PSGIDS, false, postid); InfoAdmin.UpdateHairStyle(HairStyle1); // //同步TAG using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) { string commString = "update PictureStore set PictureStoreTagIDs = '" + tagIDs + "' where PictureStoreid=" +ps.PictureStoreID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commString; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { } } } string[] PPSGCollection = PSGIDS.Split(",".ToCharArray()); foreach (string s in PPSGCollection) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) { string commString = "update PictureStoreGroup set PictureStoreIDs = PictureStoreIDs+',"+hstyleid+"' where PictureStoreGroupID="+s; using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commString; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { } } } } string[] ppicString = this.pic.Text.Split(";".ToCharArray()); string[] ppicSmallString = this.picsmall.Text.Split(";".ToCharArray()); if (ppicString[0] != string.Empty) { for(int k=0;k<ppicString.Length;k++) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ToString())) { string commString = "insert into PictureStoreSet(PictureStoreId,PictureStoreURL,SmallPictureUrl,IsHairStyle,HairStylePos) values(" + hstyleid + ",'" + ppicString[k] + "','"+ppicSmallString[k]+"',0,0)"; using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commString; conn.Open(); try { comm.ExecuteNonQuery(); } catch (Exception ex) { } } } } } this.Response.Redirect("PictureStoreAdmin.aspx"); }