protected void btnSubmit_OnClick(object sender, EventArgs e) { if (this.txtHairShopTag.Text.Trim() != string.Empty) { string[] tagCondition = this.txtHairShopTag.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; } } } if (ddlHotZone.SelectedItem.Value == "28") { this.lblInfo.Visible = true; this.lblInfo.Text = "美发商圈未指定!"; return; } HairShop hs = (HairShop)ViewState["HairShop"]; //先处理TAG逻辑,先删除HS所对应的所有TAG if (hs.HairShopTagIDs != string.Empty) { string[] tempTagC = hs.HairShopTagIDs.Split(",".ToCharArray()); for (int k = 0; k < tempTagC.Length; k++) { HairShopTag hst = new HairShopTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairShopTag where HairShopTagID=" + 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["HairShopTagID"].ToString()); hst.TagName = sdr["HairShopTagName"].ToString(); hst.HairShopIDs = sdr["HairShopIDs"].ToString(); } catch { } } } } } string[] tempHairShopIDC = hst.HairShopIDs.Split(",".ToCharArray()); string hairShopIDs = ""; int tempNum = 0; for (int i = 0; i < tempHairShopIDC.Length; i++) { if (tempHairShopIDC[i] != hs.HairShopID.ToString()) { tempNum++; if (tempNum == 1) { hairShopIDs = tempHairShopIDC[i]; } else { hairShopIDs += "," + tempHairShopIDC[i]; } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairShopTag set HairShopIDs='" + hairShopIDs + "' where HairShopTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } } // hs.HairShopName = txtHairShopName.Text.Trim(); hs.HairShopShortName = txtHairShopShortName.Text.Trim(); hs.TypeID = int.Parse(ddlTypeTable.SelectedValue); hs.HairShopWebSite = txtHairShopWebSite.Text.Trim(); hs.HairShopEmail = txtHairShopEmail.Text.Trim(); hs.HairShopDiscount = txtHairShopDiscount.Text.Trim(); //获取上传图片后的路径 if (fileLogo.Value!="") { UpLoadClass upload = new UpLoadClass(); hs.HairShopLogo = upload.UpLoadImg(fileLogo, "/uploadfiles/logo/"); upload = null; } else { hs.HairShopLogo = imgLogo.ImageUrl; } try { hs.HairCutDiscountMin = Decimal.Parse(txtHairCutPriceMin.Text.Trim()); } catch { hs.HairCutDiscountMin = 0; } try { hs.HairMarcelDiscountMin = Decimal.Parse(txtMarcelPriceMin.Text.Trim()); } catch { hs.HairMarcelDiscountMin = 0; } try { hs.HairDyeDiscountMin = Decimal.Parse(txtHairDyePriceMin.Text.Trim()); } catch { hs.HairDyeDiscountMin = 0; } try { hs.HairShapeDiscountMin = Decimal.Parse(txtShapePriceMin.Text.Trim()); } catch { hs.HairShapeDiscountMin = 0; } try { hs.HairConservationDiscountMin = Decimal.Parse(txtConservationPriceMin.Text.Trim()); } catch { hs.HairConservationDiscountMin = 0; } hs.HairShopCreateTime = txtHairShopCreateTime.Text.Trim(); hs.HairShopCityID = int.Parse(ddlCity.SelectedValue); hs.HairShopMapZoneID = int.Parse(ddlMapZone.SelectedValue); hs.HairShopHotZoneID = int.Parse(ddlHotZone.SelectedValue); hs.HairShopAddress = txtHairShopAddress.Text.Trim(); hs.HairShopPhoneNum = txtHairShopPhoneNum.Text.Trim(); hs.HairShopOpenTime = txtHairShopOpenTime.Text.Trim(); hs.TravelInfo = txtTravelInfo.Text.Trim(); hs.HairShopTagIDs = ""; try { hs.HairCutDiscount = Decimal.Parse(tbHairCutDiscount.Text.Trim()); } catch { hs.HairCutDiscount = 0; } try { hs.HairCutPirce = Decimal.Parse(tbHairCutPrice.Text.Trim()); } catch { hs.HairCutPirce = 0; } try { hs.HairMarcelDiscount = Decimal.Parse(tbMarclDiscount.Text.Trim()); } catch { hs.HairMarcelDiscount = 0; } try { hs.HairMarcelPrice = Decimal.Parse(tbMarcelPrice.Text.Trim()); } catch { hs.HairMarcelPrice = 0; } try { hs.HairDyeDiscount = Decimal.Parse(tbHairDyeDiscount.Text.Trim()); } catch { hs.HairDyeDiscount = 0; } try { hs.HairDyePrice = Decimal.Parse(tbHairDyePrice.Text.Trim()); } catch { hs.HairDyePrice = 0; } try { hs.HairShapePrice = Decimal.Parse(tbShapePrice.Text.Trim()); } catch { hs.HairShapePrice = 0; } try { hs.HairShapeDiscount = Decimal.Parse(tbShapeDiscount.Text.Trim()); } catch { hs.HairShapeDiscount = 0; } try { hs.HairConservationPrice = Decimal.Parse(tbConservationPrice.Text.Trim()); } catch { hs.HairConservationPrice = 0; } try { hs.HairConservationDiscount = Decimal.Parse(tbConservationDiscount.Text.Trim()); } catch { hs.HairConservationDiscount = 0; } hs.LocationMapURL = tbLocation.Text.Trim(); try { hs.Square = int.Parse(tbSquare.Text.Trim()).ToString(); } catch { hs.Square = "0"; } hs.IsServeHairCut = chkCut.Checked; hs.IsServeMarce = chkMarcel.Checked; hs.IsServeDye = chkDye.Checked; hs.IsJoin = chkIsJoin.Checked; hs.IsPostMachine = chkIsPostMachine.Checked; hs.IsPostStation = chkIsPostStation.Checked; hs.HairShopDescription = txtDescription.Text.Trim(); hs.MemberInfo = txtMemberInfo.Text.Trim(); string productIDs = ""; int num = 0; foreach (ListItem li in this.chkList.Items) { if (li.Selected) { num++; if (num == 1) { productIDs = li.Value; } else { productIDs += "," + li.Value; } } } hs.ProductIDs = productIDs; //TAG逻辑 string tagIDs = ""; string id = hs.HairShopID.ToString(); string[] tagCollection = txtHairShopTag.Text.Split(",".ToCharArray()); if (tagCollection[0] != string.Empty) { for (int k = 0; k < tagCollection.Length; k++) { string tagID = ""; bool isExist = false; HairShopTag hst = new HairShopTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairShopTag where HairShopTagName='" + 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["HairShopTagID"].ToString()); hst.TagName = sdr["HairShopTagName"].ToString(); hst.HairShopIDs = sdr["HairShopIDs"].ToString(); } catch { } } } } } if (hst.TagID == 0) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "insert HairShopTag(HairShopTagName,HairShopIDs) 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.HairShopIDs == string.Empty) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairShopTag set HairShopIDs='" + id.ToString() + "' where HairShopTagID=" + 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 HairShopTag set HairShopIDs=HairShopIDs+'," + id.ToString() + "' where HairShopTagID=" + 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; } } } hs.HairShopTagIDs = tagIDs; Session["HairShopInfo"] = hs; InfoAdmin.UpdateHairShopInfo(hs); this.Response.Redirect("HairShopAdmin.aspx"); }
protected void btnSubmit_OnClick(object sender, EventArgs e) { this.Response.Write("<script>enableButton();</script>"); if (this.txtHairShopTag.Text.Trim() != string.Empty) { string[] tagCondition = this.txtHairShopTag.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; } } } HairShop hs = new HairShop(); hs.HairShopName = txtHairShopName.Text.Trim(); hs.HairShopShortName = txtHairShopShortName.Text.Trim(); hs.TypeID = int.Parse(ddlTypeTable.SelectedValue); hs.TypeName = ddlTypeTable.SelectedItem.Text; hs.HairShopWebSite = txtHairShopWebSite.Text.Trim(); hs.HairShopEmail = txtHairShopEmail.Text.Trim(); hs.HairShopDiscount = txtHairShopDiscount.Text.Trim(); hs.TravelInfo = txtTravelInfo.Text.Trim(); if (fileLogo.Value != string.Empty) { //获取上传图片后的路径 UpLoadClass upload = new UpLoadClass(); if (!PicOperate.isPermission(StringHelper.GetExtraType(fileLogo.Value))) { this.lblInfo.Text = "上传图片格式不对"; this.lblInfo.Visible = true; return; } hs.HairShopLogo = upload.UpLoadImg(fileLogo, "/uploadfiles/logo/"); } else { hs.HairShopLogo = string.Empty; } hs.HairShopCreateTime = txtHairShopCreateTime.Text.Trim(); hs.HairShopCityID = int.Parse(ddlCity.SelectedValue); hs.HairShopMapZoneID = int.Parse(ddlMapZone.SelectedValue); hs.HairShopHotZoneID = int.Parse(ddlHotZone.SelectedValue); hs.HairShopAddress = txtHairShopAddress.Text.Trim(); hs.HairShopPhoneNum = txtHairShopPhoneNum.Text.Trim(); hs.HairShopOpenTime = txtHairShopOpenTime.Text.Trim(); //TAG逻辑,先复制空,然后插入TAG表,然后UPDATE美发厅表 hs.HairShopTagIDs = ""; //List<string> IDs = new List<string>(); //int chkI = chkListWorkRange.Items.Count; //for (int i = 0; i < chkI; i++) //{ // if (chkListWorkRange.Items[i].Selected) // { // IDs.Add(chkListWorkRange.Items[i].Value); // } //} //IDs.Sort(); //hs.WorkRangeIDs = string.Join(",", IDs.ToArray()); //hs.IsBest = chkIsBest.Checked; hs.IsJoin = chkIsJoin.Checked; hs.IsPostMachine = chkIsPostMachine.Checked; hs.IsPostStation = chkIsPostStation.Checked; hs.HairShopDescription = txtDescription.Text.Trim(); //Session["HairShopInfo"] = hs; try { hs.HairCutDiscountMin = Decimal.Parse(txtHairCutPriceMin.Text.Trim()); } catch { hs.HairCutDiscountMin = 0; } try { hs.HairMarcelDiscountMin = Decimal.Parse(txtMarcelPriceMin.Text.Trim()); } catch { hs.HairMarcelDiscountMin = 0; } try { hs.HairDyeDiscountMin = Decimal.Parse(txtHairDyePriceMin.Text.Trim()); } catch { hs.HairDyeDiscountMin = 0; } try { hs.HairShapeDiscountMin = Decimal.Parse(txtShapePriceMin.Text.Trim()); } catch { hs.HairShapeDiscountMin = 0; } try { hs.HairConservationDiscountMin = Decimal.Parse(txtConservationPriceMin.Text.Trim()); } catch { hs.HairConservationDiscountMin = 0; } try { hs.HairCutDiscount = Decimal.Parse(tbHairCutDiscount.Text.Trim()); } catch { hs.HairCutDiscount = 0; } try { hs.HairCutPirce = Decimal.Parse(tbHairCutPrice.Text.Trim()); } catch { hs.HairCutPirce = 0; } try { hs.HairMarcelDiscount = Decimal.Parse(tbMarclDiscount.Text.Trim()); } catch { hs.HairMarcelDiscount = 0; } try { hs.HairMarcelPrice = Decimal.Parse(tbMarcelPrice.Text.Trim()); } catch { hs.HairMarcelPrice = 0; } try { hs.HairDyeDiscount = Decimal.Parse(tbHairDyeDiscount.Text.Trim()); } catch { hs.HairDyeDiscount = 0; } try { hs.HairDyePrice = Decimal.Parse(tbHairDyePrice.Text.Trim()); } catch { hs.HairDyePrice = 0; } try { hs.HairShapePrice = Decimal.Parse(tbShapePrice.Text.Trim()); } catch { hs.HairShapePrice = 0; } try { hs.HairShapeDiscount = Decimal.Parse(tbShapeDiscount.Text.Trim()); } catch { hs.HairShapeDiscount = 0; } try { hs.HairConservationPrice = Decimal.Parse(tbConservationPrice.Text.Trim()); } catch { hs.HairConservationPrice = 0; } try { hs.HairConservationDiscount = Decimal.Parse(tbConservationDiscount.Text.Trim()); } catch { hs.HairConservationDiscount = 0; } hs.LocationMapURL = tbLocation.Text.Trim(); try { hs.Square = int.Parse(TextBox4.Text.Trim()).ToString(); } catch { hs.Square = "0"; } hs.IsServeHairCut = chkCut.Checked; hs.IsServeMarce = chkMarcel.Checked; hs.IsServeDye = chkDye.Checked; hs.MemberInfo = txtMemberInfo.Text.Trim(); string productIDs = ""; int num = 0; foreach (ListItem li in this.chkList.Items) { if (li.Selected) { num++; if (num == 1) { productIDs = li.Value; hs.ProductsName = li.Text; } else { productIDs += ","+li.Value; hs.ProductsName += "," + li.Text; } } } hs.ProductIDs = productIDs; //InfoAdmin.AddHairShop(hs); int newid = 0; InfoAdmin.AddHairShopInfo(hs,out newid); Session["HairShop"] = hs; string id = newid.ToString(); string tagIDs = ""; string[] tagCollection = txtHairShopTag.Text.Split(",".ToCharArray()); if (tagCollection[0] != string.Empty) { for (int k = 0; k < tagCollection.Length; k++) { string tagID = ""; bool isExist = false; HairShopTag hst = new HairShopTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairShopTag where HairShopTagName='" + 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["HairShopTagID"].ToString()); hst.TagName = sdr["HairShopTagName"].ToString(); hst.HairShopIDs = sdr["HairShopIDs"].ToString(); } catch { } } } } } if (hst.TagID == 0) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "insert HairShopTag(HairShopTagName,HairShopIDs) 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.HairShopIDs == string.Empty) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairShopTag set HairShopIDs='" + id.ToString() + "' where HairShopTagID=" + 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 HairShopTag set HairShopIDs=HairShopIDs+'," + id.ToString() + "' where HairShopTagID=" + 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; } } } hs.HairShopTagIDs = tagIDs; hs.HairShopID = int.Parse(id.ToString()); int nnewid = 0; ProviderFactory.GetHairShopDataProviderInstance().HairShopCreateDeleteUpdate(hs, UserAction.Update,out nnewid); this.Response.Redirect("HairShopAddNext1.aspx?id="+id.ToString()); //this.Response.Redirect("HairEngineerAdd.aspx"); }
private void bindBaseInfo() { string id = Request["id"]; HairShop hs = ProviderFactory.GetHairShopDataProviderInstance().GetHairShopByHairShopID(int.Parse(id)); //绑定TAG if (hs.HairShopTagIDs != string.Empty) { string[] tempTagC = hs.HairShopTagIDs.Split(",".ToCharArray()); for (int k = 0; k < tempTagC.Length; k++) { HairShopTag hst = new HairShopTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairShopTag where HairShopTagID=" + 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["HairShopTagID"].ToString()); hst.TagName = sdr["HairShopTagName"].ToString(); hst.HairShopIDs = sdr["HairShopIDs"].ToString(); } catch { } } } } } if (k == 0) { this.txtHairShopTag.Text = hst.TagName; } else { this.txtHairShopTag.Text += "," + hst.TagName; } } } txtTravelInfo.Text = hs.TravelInfo; txtDescription.Text = hs.HairShopDescription; txtHairShopAddress.Text = hs.HairShopAddress; txtHairShopCreateTime.Text = hs.HairShopCreateTime.ToString(); txtHairShopDiscount.Text = hs.HairShopDiscount; txtHairShopEmail.Text = hs.HairShopEmail; txtHairShopName.Text = hs.HairShopName; txtHairShopOpenTime.Text = hs.HairShopOpenTime.ToString(); txtHairShopPhoneNum.Text = hs.HairShopPhoneNum; txtHairShopShortName.Text = hs.HairShopShortName; txtHairShopWebSite.Text = hs.HairShopWebSite; txtHairCutPriceMin.Text = hs.HairCutDiscountMin.ToString(); txtHairDyePriceMin.Text = hs.HairDyeDiscountMin.ToString(); txtMarcelPriceMin.Text = hs.HairMarcelDiscountMin.ToString(); txtConservationPriceMin.Text = hs.HairConservationDiscountMin.ToString(); txtShapePriceMin.Text = hs.HairShapeDiscountMin.ToString(); imgLogo.ImageUrl = hs.HairShopLogo; ddlTypeTable.SelectedValue = hs.TypeID.ToString(); this.bindcity(); ddlCity.SelectedValue = hs.HairShopCityID.ToString(); this.bindmapzone(); ddlMapZone.SelectedValue = hs.HairShopMapZoneID.ToString(); this.bindhotzone(); ddlHotZone.SelectedValue = hs.HairShopHotZoneID.ToString(); tbHairCutPrice.Text = hs.HairCutPirce.ToString(); tbHairCutDiscount.Text = hs.HairCutDiscount.ToString(); tbMarcelPrice.Text = hs.HairMarcelPrice.ToString(); tbMarclDiscount.Text = hs.HairMarcelDiscount.ToString(); tbHairDyePrice.Text = hs.HairDyePrice.ToString(); tbHairDyeDiscount.Text = hs.HairDyeDiscount.ToString(); tbShapePrice.Text = hs.HairShapePrice.ToString(); tbShapeDiscount.Text = hs.HairShapeDiscount.ToString(); tbConservationPrice.Text = hs.HairConservationPrice.ToString(); tbConservationDiscount.Text = hs.HairConservationDiscount.ToString(); chkCut.Checked = hs.IsServeHairCut; chkMarcel.Checked = hs.IsServeMarce; chkDye.Checked = hs.IsServeDye; tbSquare.Text = hs.Square; tbLocation.Text = hs.LocationMapURL; chkIsJoin.Checked = hs.IsJoin; chkIsPostMachine.Checked = hs.IsPostMachine; chkIsPostStation.Checked = hs.IsPostStation; string[] productids = hs.ProductIDs.Split(",".ToCharArray()); foreach (ListItem li in chkList.Items) { if (isExistID(li.Value, productids)) { li.Selected = true; } } this.txtMemberInfo.Text = hs.MemberInfo; ViewState["HairShop"] = hs; }
/// <summary> /// ������TAG�б� ��ӣ�ɾ������ /// </summary> /// <param name="hairShopTag"></param> /// <param name="ua"></param> /// <returns></returns> public bool HairShopTagCreateDeleteUpdate(HairShopTag hairShopTag, UserAction ua) { bool result = false; string commandText = string.Empty; switch (ua) { case UserAction.Create: commandText = "insert into HairShopTag(HairShopTagName,HairShopIDs) values('"+hairShopTag.TagName+"','"+hairShopTag.HairShopIDs+"')"; break; case UserAction.Delete: commandText = "delete from HairShopTag where HairShopTagID="+hairShopTag.TagID.ToString(); break; case UserAction.Update: commandText = "update HairShopTag set HairShopTagName='"+hairShopTag.TagName+"', HairShopIDs='"+hairShopTag.HairShopIDs+"' where HairShopTagID="+hairShopTag.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; }
/// <summary> /// ��ȡ������TAG�б� /// </summary> /// <param name="count"></param> /// <returns></returns> public List<HairShopTag> GetHairShopTags(int count) { List<HairShopTag> list = new List<HairShopTag>(); string commText = ""; switch (count) { case 0: commText = "select * from HairShopTag order by HairShopTagID desc"; break; default: commText = "select top "+count.ToString()+" * from HairShopTag order by HairShopTagID 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()) { HairShopTag hairShopTag = new HairShopTag(); hairShopTag.HairShopIDs = sdr["HairShopIDs"].ToString(); hairShopTag.TagID = int.Parse(sdr["HairShopTagID"].ToString()); hairShopTag.TagName = sdr["HairShopTagName"].ToString(); list.Add(hairShopTag); } } } } } return list; }
/// <summary> /// ͨ��TAGID��ȡ������TAGʵ�� /// </summary> /// <param name="hairShopTagID"></param> /// <returns></returns> public HairShopTag GetHairShopTagByHairShopTagID(int hairShopTagID) { HairShopTag hairShopTag = new HairShopTag(); string commText = "select * from HairShopTag where HairShopTagID="+hairShopTagID.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()) { hairShopTag.HairShopIDs = sdr["HairShopIDs"].ToString(); hairShopTag.TagID = int.Parse(sdr["HairShopTagID"].ToString()); hairShopTag.TagName = sdr["HairShopTagName"].ToString(); } } } } } return hairShopTag; }
public void dg_OnItemCommand(object sender, DataGridCommandEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item) { if (e.CommandName == "recommand") { int hairShopID = int.Parse(this.dg.DataKeys[e.Item.ItemIndex].ToString()); string redirectUrl = "HairShopRecommandUpdate.aspx?hairShopID=" + hairShopID.ToString() + "&hairShopRecommandID=0&operateType=" + Convert.ToInt32(UserAction.Create).ToString(); this.Response.Redirect(redirectUrl); } if (e.CommandName == "delete") { int hairShopID = int.Parse(this.dg.DataKeys[e.Item.ItemIndex].ToString()); HairShop hs = ProviderFactory.GetHairShopDataProviderInstance().GetHairShopByHairShopID(hairShopID); //先处理TAG逻辑,先删除HS所对应的所有TAG if (hs.HairShopTagIDs != string.Empty) { string[] tempTagC = hs.HairShopTagIDs.Split(",".ToCharArray()); for (int k = 0; k < tempTagC.Length; k++) { HairShopTag hst = new HairShopTag(); using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "select * from HairShopTag where HairShopTagID=" + 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["HairShopTagID"].ToString()); hst.TagName = sdr["HairShopTagName"].ToString(); hst.HairShopIDs = sdr["HairShopIDs"].ToString(); } catch { } } } } } string[] tempHairShopIDC = hst.HairShopIDs.Split(",".ToCharArray()); string hairShopIDs = ""; int tempNum = 0; for (int i = 0; i < tempHairShopIDC.Length; i++) { if (tempHairShopIDC[i] != hs.HairShopID.ToString()) { tempNum++; if (tempNum == 1) { hairShopIDs = tempHairShopIDC[i]; } else { hairShopIDs += "," + tempHairShopIDC[i]; } } } using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "update HairShopTag set HairShopIDs='" + hairShopIDs + "' where HairShopTagID=" + hst.TagID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); try { comm.ExecuteNonQuery(); } catch { } } } } } if (InfoAdmin.DeleteHairShop(hairShopID)) { using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSqlServer"].ConnectionString)) { string commString = "delete from shoppics where hairshopid="+hairShopID.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 Coupon where hairshopid=" + hairShopID.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 HairShopRecommand where HairShopRawID=" + hairShopID.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 = "select * from HairEngineer where HairShopID=" + hairShopID.ToString(); using (SqlCommand comm = new SqlCommand()) { comm.CommandText = commString; comm.Connection = conn; conn.Open(); using (SqlDataReader sdr = comm.ExecuteReader()) { while (sdr.Read()) { int heid = int.Parse(sdr["HairEngineerID"].ToString()); this.deleteHairEngineer(heid); } } } } StringHelper.AlertInfo("删除成功", this.Page); this.Response.Redirect("HairShopAdmin.aspx"); } else { StringHelper.AlertInfo("删除失败", this.Page); } } } }