public void dg_OnItemCommand(object sender, DataGridCommandEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { if (e.CommandName == "recommand") { int hairEngineerID = int.Parse(this.dg.DataKeys[e.Item.ItemIndex].ToString()); string redirectUrl = "HairEngineerRecommandUpdate.aspx?hairEngineerID="+hairEngineerID.ToString()+"&hairEngineerRecommandID=0&operateType="+Convert.ToInt32(UserAction.Create).ToString(); this.Response.Redirect(redirectUrl); } if (e.CommandName == "delete") { int hairEngineerID = int.Parse(this.dg.DataKeys[e.Item.ItemIndex].ToString()); HairEngineer he = ProviderFactory.GetHairEngineerDataProviderInstance().GetHairEngineerByHairEngineerID(hairEngineerID); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "delete from HairEngineerRecommand where HairEngineerRawID=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } //tag逻辑 //先处理TAG逻辑,先删除HS所对应的所有TAG if (he.HairEngineerTagIDs != string.Empty) { string[] tempTagC = he.HairEngineerTagIDs.Split(",".ToCharArray()); if (tempTagC[0] != string.Empty) { for (int k = 0; k < tempTagC.Length; k++) { HairEngineerTag hst = new HairEngineerTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairEngineerTag where HairEngineerTagID=" + tempTagC[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 { } } } } } string[] tempHairEngineerIDC = hst.HairEngineerIDs.Split(",".ToCharArray()); string hairEngineerIDs = ""; int tempNum = 0; for (int i = 0; i < tempHairEngineerIDC.Length; i++) { if (tempHairEngineerIDC[i] != he.HairEngineerID.ToString()) { tempNum++; if (tempNum == 1) { hairEngineerIDs = tempHairEngineerIDC[i]; } else { hairEngineerIDs += "," + tempHairEngineerIDC[i]; } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairEngineerTag set HairEngineerIDs='" + hairEngineerIDs + "' where HairEngineerTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } } } // 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); } } } if (InfoAdmin.DeleteHairEngineer(hairEngineerID)) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairStyle where hairEngineerID=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { string hid = sdr["ID"].ToString(); this.deleteHairStyle(int.Parse(hid)); using (SqlConnection conn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString2 = "delete from picturestoreset where picturestoreid=" + hid; using (SqlCommand comm2 = new SqlCommand()) { comm2.CommandText = commString2; comm2.Connection = conn2; conn2.Open(); try { comm2.ExecuteNonQuery(); } catch { } } } } } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "delete from enginpics where ownerid=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "delete from HairEngineerRecommand where HairEngineerRawID=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } StringHelper.AlertInfo("删除成功",this.Page); this.Response.Redirect("HairEngineerAdmin.aspx"); } else { StringHelper.AlertInfo("删除失败", this.Page); } } } }
/// <summary> /// ��ȡ����ʦTAG�б� /// </summary> /// <param name="count"></param> /// <returns></returns> public List<HairEngineerTag> GetHairEngineerTags(int count) { List<HairEngineerTag> list = new List<HairEngineerTag>(); string commText = ""; switch (count) { case 0: commText = "select * from HairEngineerTag Order by HairEngineerTagID desc"; break; default: commText = "select top "+count.ToString()+" * from HairEngineerTag order by HairEngineerTagID desc"; break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { HairEngineerTag hairEngineerTag = new HairEngineerTag(); hairEngineerTag.HairEngineerIDs = sdr["HairEngineerIDs"].ToString(); hairEngineerTag.TagID = int.Parse(sdr["HairEngineerTagID"].ToString()); hairEngineerTag.TagName = sdr["HairEngineerTagName"].ToString(); list.Add(hairEngineerTag); } } } } } return list; }
/// <summary> /// �������ʦTAGʵ�� /// </summary> /// <param name="hairEngineerTagID"></param> /// <returns></returns> public HairEngineerTag GetHairEngineerTagByHairEngineerTagID(int hairEngineerTagID) { HairEngineerTag hairEngineerTag = new HairEngineerTag(); string commText = "select * from HairEngineerTag where HairEngineerTagID = " + hairEngineerTagID.ToString(); using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandText = commText; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { hairEngineerTag.HairEngineerIDs = sdr["HairEngineerIDs"].ToString(); hairEngineerTag.TagID = int.Parse(sdr["HairEngineerTagID"].ToString()); hairEngineerTag.TagName = sdr["HairEngineerTagName"].ToString(); } } } } } return hairEngineerTag; }
/// <summary> /// ����ʦTAG ��ӣ�ɾ������ /// </summary> /// <param name="hairEngineerTag"></param> /// <param name="ua"></param> /// <returns></returns> public bool HairEngineerTagCreateDeleteUpdate(HairEngineerTag hairEngineerTag, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "insert into HairEngineerTag(HairEngineerTagName,HairEngineerIDs) values('"+hairEngineerTag.TagName+"','"+hairEngineerTag.HairEngineerIDs+"')"; break; case UserAction.Delete: commandText = "delete from HairEngineerTag where HairEngineerTagID="+hairEngineerTag.TagID.ToString(); break; case UserAction.Update: commandText = "update HairEngineerTag set HairEngineerTagName = '"+hairEngineerTag.TagName+"',HairEngineerIDs='"+hairEngineerTag.HairEngineerIDs+"' where HairEngineerTagID="+hairEngineerTag.TagID.ToString(); break; } using (SqlConnection conn = new SqlConnection(DataHelper2.SqlConnectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commandText; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); result = true; } catch (Exception ex) { throw new Exception(ex.Message); } } } return result; }
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); }
public void deleteHairEngineer(int heid) { int hairEngineerID = heid; HairEngineer he = ProviderFactory.GetHairEngineerDataProviderInstance().GetHairEngineerByHairEngineerID(hairEngineerID); //tag逻辑 //先处理TAG逻辑,先删除HS所对应的所有TAG if (he.HairEngineerTagIDs != string.Empty) { string[] tempTagC = he.HairEngineerTagIDs.Split(",".ToCharArray()); for (int k = 0; k < tempTagC.Length; k++) { HairEngineerTag hst = new HairEngineerTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairEngineerTag where HairEngineerTagID=" + tempTagC[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 { } } } } } string[] tempHairEngineerIDC = hst.HairEngineerIDs.Split(",".ToCharArray()); string hairEngineerIDs = ""; int tempNum = 0; for (int i = 0; i < tempHairEngineerIDC.Length; i++) { if (tempHairEngineerIDC[i] != he.HairEngineerID.ToString()) { tempNum++; if (tempNum == 1) { hairEngineerIDs = tempHairEngineerIDC[i]; } else { hairEngineerIDs += "," + tempHairEngineerIDC[i]; } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairEngineerTag set HairEngineerIDs='" + hairEngineerIDs + "' where HairEngineerTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } } // 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); } } } if (InfoAdmin.DeleteHairEngineer(hairEngineerID)) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairStyle where hairEngineerID=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { string hid = sdr["ID"].ToString(); this.deleteHairStyle(int.Parse(hid)); using (SqlConnection conn2 = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString2 = "delete from picturestoreset where picturestoreid=" + hid; using (SqlCommand comm2 = new SqlCommand()) { comm2.CommandText = commString2; comm2.Connection = conn2; conn2.Open(); try { comm2.ExecuteNonQuery(); } catch { } } } } } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "delete from enginpics where ownerid=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "delete from HairEngineerRecommand where HairEngineerRawID=" + hairEngineerID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } else { StringHelper.AlertInfo("删除失败", this.Page); } }