using System; using System.Collections.Generic; using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; namespace Mtxfw.shop._Admin { public partial class admin_business_add : Mtxfw.Utility.AdminPage { public Mtxfw.DAL.P_Category daoCategory = new Mtxfw.DAL.P_Category(); public Mtxfw.DAL.P_Product daoProduct = new Mtxfw.DAL.P_Product(); public Mtxfw.DAL.business_info daoBus = new Mtxfw.DAL.business_info(); public Mtxfw.Utility.Config config = new Mtxfw.Utility.Config(); public String TitName = String.Empty; public String CityID = String.Empty; public String CountyID = String.Empty; protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!IsPostBack) { Select_Bind(); Hidd_Url.Value = Request.UrlReferrer.ToString(); if (Request.QueryString["action"] == "add") { TitName = "添加商家"; Btn_Update.Visible = false; if (Session["Province"] != null) { for (int i = 0; i < Drop_Province.Items.Count; i++) { if (Drop_Province.Items[i].Value == Session["Province"].ToString()) { Drop_Province.Items[i].Selected = true; } else { Drop_Province.Items[i].Selected = false; } } } if (Session["business_Category"] != null) { for (int i = 0; i < Drop_Cls.Items.Count; i++) { if (Drop_Cls.Items[i].Value == Session["business_Category"].ToString()) { Drop_Cls.Items[i].Selected = true; } else { Drop_Cls.Items[i].Selected = false; } } } if (Session["City"] != null) { CityID = Session["City"].ToString(); } if (Session["County"] != null) { CountyID = Session["County"].ToString(); } } else { TitName = "修改商家"; Btn_Insert.Visible = false; Mtxfw.Model.business_info model = daoBus.GetModel(int.Parse(Request.QueryString["ID"])); Text_CompanyName.Text = model.CompanyName; Text_ContactPeople.Text = model.ContactPeople; Text_ContactPhone.Text = model.ContactPhone; Drop_Cls.SelectedValue = model.ClsID.ToString(); if (model.ClsID.ToString() != "") { for (int i = 0; i < Drop_Cls.Items.Count; i++) { if (Drop_Cls.Items[i].Value == model.ClsID.ToString()) { Drop_Cls.Items[i].Selected = true; } else { Drop_Cls.Items[i].Selected = false; } } } Drop_Province.SelectedValue = model.Province; Text_Busroutes.Text = model.Busroutes; Text_Introduction.Value = model.Introduction; Text_WebSize.Text = model.InternetSite; Text_CompanyAddress.Text = model.Companyaddress; Text_BusinessRange.Text = model.BusinessRange; Drop_State.SelectedValue = model.ApplyState; if (!String.IsNullOrEmpty(model.picture)) { Image_PicTrue.Visible = true; Image_PicTrue.ImageUrl = Mtxfw.Utility.Common.GetCoverPic(model.picture, "280x200", "cut"); Hidd_PicTrue.Value = model.picture; } CityID = model.City; CountyID = model.County; Hidd_CompanyId.Value = model.CompanyId; } } Btn_Insert.Click += delegate(object s, EventArgs ex) { Mtxfw.Model.business_info model = new Mtxfw.Model.business_info(); model.CompanyName = Text_CompanyName.Text; model.ClsID = int.Parse(Drop_Cls.SelectedItem.Value); model.ClsnName = Drop_Cls.SelectedItem.Text; model.ClsID2 = int.Parse(Drop_Cls2.SelectedItem.Value); model.ClsnName2 = Drop_Cls2.SelectedItem.Text; model.ClsID2 = int.Parse(Drop_Cls2.SelectedItem.Value); model.ClsnName2 = Drop_Cls2.SelectedItem.Text; model.Province = Drop_Province.SelectedItem.Value; if (Request.Form["Drop_City"] != null) { model.City = Request.Form["Drop_City"]; } else { model.City = ""; } if (Request.Form["Drop_County"] != null) { model.County = Request.Form["Drop_County"]; } else { model.County = ""; } model.Introduction2 = ""; model.Introduction3 = ""; model.Busroutes = ""; Session["Province"] = model.Province; Session["City"] = model.City; Session["County"] = model.County; Session["business_Category"] = Drop_Cls.SelectedItem.Value; Session["business_Category2"] = Drop_Cls2.SelectedItem.Value; if (File_PicTrue.FileContent.Length > 0) { Mtxfw.Utility.UploadFile upload = new Mtxfw.Utility.UploadFile(File_PicTrue.PostedFile, config.webUpPath, config.webUpType, int.Parse(config.webUpSize)); if (upload.StatrUpFile()) { model.picture = upload.UploadPath; } else model.picture = String.Empty; } else model.picture = String.Empty; model.BusinessRange = Text_BusinessRange.Text; model.Companyaddress = Text_CompanyAddress.Text; model.InternetSite = Text_WebSize.Text; model.Busroutes = Text_Busroutes.Text; model.Introduction = Text_Introduction.Value; model.ContactPeople = Text_ContactPeople.Text; model.ContactPhone = Text_ContactPhone.Text; model.ApplyTime = DateTime.Now; model.ApplyState = Drop_State.SelectedItem.Text; model.CompanyId = "0"; model.Discount = ""; model.utype = "0"; model.Businesslicense = ""; model.TaxRegistration = ""; model.UserId = 0; daoBus.Add(model); Response.Redirect(Hidd_Url.Value); }; Btn_Update.Click += delegate(object s, EventArgs ex) { Int32 ID = int.Parse(Request.QueryString["ID"]); Mtxfw.Model.business_info model = daoBus.GetModel(ID); model.Id = ID; model.CompanyName = Text_CompanyName.Text; model.ClsID = int.Parse(Drop_Cls.SelectedItem.Value); model.ClsnName = Drop_Cls.SelectedItem.Text; model.ClsID2 = int.Parse(Drop_Cls2.SelectedItem.Value); model.ClsnName2 = Drop_Cls2.SelectedItem.Text; model.Province = Drop_Province.SelectedItem.Value; if (Request.Form["Drop_City"] != null) { model.City = Request.Form["Drop_City"]; } else { model.City = ""; } if (Request.Form["Drop_County"] != null) { model.County = Request.Form["Drop_County"]; } else { model.County = ""; } model.Introduction2 = ""; model.Introduction3 = ""; model.Busroutes = ""; if (File_PicTrue.FileContent.Length > 0) { Mtxfw.Utility.UploadFile upload = new Mtxfw.Utility.UploadFile(File_PicTrue.PostedFile, config.webUpPath, config.webUpType, int.Parse(config.webUpSize)); if (upload.StatrUpFile()) { model.picture = upload.UploadPath; } else model.picture = Hidd_PicTrue.Value; } else model.picture = Hidd_PicTrue.Value; model.BusinessRange = Text_BusinessRange.Text; model.Companyaddress = Text_CompanyAddress.Text; model.InternetSite = Text_WebSize.Text; model.Busroutes = Text_Busroutes.Text; model.Introduction = Text_Introduction.Value; model.ContactPeople = Text_ContactPeople.Text; model.ContactPhone = Text_ContactPhone.Text; model.ApplyState = Drop_State.SelectedItem.Text; model.Discount = ""; model.CompanyId = Hidd_CompanyId.Value; model.Businesslicense = ""; model.TaxRegistration = ""; daoBus.Update(model); Response.Redirect(Hidd_Url.Value); }; } protected void Select_Bind() { string remark = null; int lbConut2 = 0; DataSet ds = daoCategory.GetList("ttype=0 Order By C_Layer asc,C_LinkID asc"); foreach (DataRowView drv2 in ds.Tables[0].DefaultView)//绑定根结点 { lbConut2 = Convert.ToInt32(drv2["C_Layer"].ToString()); string LB = drv2["C_NAME"].ToString(); string Pid = drv2["C_PARENTID"].ToString(); string id = drv2["C_ID"].ToString(); remark = ""; for (int l = 0; l < lbConut2; l++) { remark += "├"; } if (lbConut2 == 1) { Drop_Cls.Items.Add(new ListItem(remark + LB, id + "|" + Pid)); } else { int jj = 0; for (int j = 0; j < Drop_Cls.Items.Count; j++) { string[] lbpid = Drop_Cls.Items[j].Value.Split('|'); if (lbpid.Length == 2) { if (Pid == lbpid[1]) { jj += 1; } } } for (int j = 0; j < Drop_Cls.Items.Count; j++) { string[] lbpid = Drop_Cls.Items[j].Value.Split('|'); if (lbpid.Length == 2) { if (Pid == lbpid[0]) { if (jj != 0) { Drop_Cls.Items.Insert(j + jj + 1, new ListItem(remark + LB, id + "|" + Pid)); } else { Drop_Cls.Items.Insert(j + 1, new ListItem(remark + LB, id + "|" + Pid)); } } } } } } ds.Clear(); Mtxfw.DAL.province daoPro = new Mtxfw.DAL.province(); System.Data.DataSet Ds = daoPro.GetCacheList("", "1=1 Order by Id Asc", "Province"); System.Data.DataTable Dt = (Ds != null && Ds.Tables[0] != null) ? Ds.Tables[0] : null; foreach (System.Data.DataRow Dr in Dt.Rows) { Drop_Province.Items.Add(new ListItem(Dr["ProvinceName"].ToString(), Dr["ProvinceID"].ToString())); } } } }