public List<Maticsoft.Model.Shop.Products.BrandInfo> DataTableToList(DataTable dt) { List<Maticsoft.Model.Shop.Products.BrandInfo> list = new List<Maticsoft.Model.Shop.Products.BrandInfo>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Shop.Products.BrandInfo item = new Maticsoft.Model.Shop.Products.BrandInfo(); if ((dt.Rows[i]["BrandId"] != null) && (dt.Rows[i]["BrandId"].ToString() != "")) { item.BrandId = int.Parse(dt.Rows[i]["BrandId"].ToString()); } if ((dt.Rows[i]["BrandName"] != null) && (dt.Rows[i]["BrandName"].ToString() != "")) { item.BrandName = dt.Rows[i]["BrandName"].ToString(); } if ((dt.Rows[i]["BrandSpell"] != null) && (dt.Rows[i]["BrandSpell"].ToString() != "")) { item.BrandSpell = dt.Rows[i]["BrandSpell"].ToString(); } if ((dt.Rows[i]["Meta_Description"] != null) && (dt.Rows[i]["Meta_Description"].ToString() != "")) { item.Meta_Description = dt.Rows[i]["Meta_Description"].ToString(); } if ((dt.Rows[i]["Meta_Keywords"] != null) && (dt.Rows[i]["Meta_Keywords"].ToString() != "")) { item.Meta_Keywords = dt.Rows[i]["Meta_Keywords"].ToString(); } if ((dt.Rows[i]["Logo"] != null) && (dt.Rows[i]["Logo"].ToString() != "")) { item.Logo = dt.Rows[i]["Logo"].ToString(); } if ((dt.Rows[i]["CompanyUrl"] != null) && (dt.Rows[i]["CompanyUrl"].ToString() != "")) { item.CompanyUrl = dt.Rows[i]["CompanyUrl"].ToString(); } if ((dt.Rows[i]["Description"] != null) && (dt.Rows[i]["Description"].ToString() != "")) { item.Description = dt.Rows[i]["Description"].ToString(); } if ((dt.Rows[i]["DisplaySequence"] != null) && (dt.Rows[i]["DisplaySequence"].ToString() != "")) { item.DisplaySequence = int.Parse(dt.Rows[i]["DisplaySequence"].ToString()); } if ((dt.Rows[i]["Theme"] != null) && (dt.Rows[i]["Theme"].ToString() != "")) { item.Theme = dt.Rows[i]["Theme"].ToString(); } list.Add(item); } } return list; }
public void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.txtBrandName.Text.Trim())) { MessageBox.ShowFailTip(this, "请输入品牌名称!"); } else if (string.IsNullOrWhiteSpace(this.txtDisplaySequence.Text.Trim()) || !PageValidate.IsNumber(this.txtDisplaySequence.Text)) { MessageBox.ShowFailTip(this, "请输入正确的显示顺序!"); } else { string text = this.txtBrandName.Text; string str2 = this.txtBrandSpell.Text; string str3 = this.txtMeta_Description.Text; string str4 = this.txtMeta_Keywords.Text; string str5 = this.txtCompanyUrl.Text; string str6 = this.txtDescription.Text; int num = int.Parse(this.txtDisplaySequence.Text); IList<int> list = new List<int>(); foreach (ListItem item in this.chkProductTpyes.Items) { if (item.Selected) { list.Add(int.Parse(item.Value)); } } Maticsoft.Model.Shop.Products.BrandInfo model = new Maticsoft.Model.Shop.Products.BrandInfo { BrandId = this.BrandId, ProductTypes = list, BrandName = text, BrandSpell = str2, Meta_Description = str3, Meta_Keywords = str4, CompanyUrl = str5 }; string oldValue = string.Format("/Upload/Temp/{0}", DateTime.Now.ToString("yyyyMMdd")); string newValue = "/Upload/Shop/Brands"; ArrayList fileNameList = new ArrayList(); if (!string.IsNullOrWhiteSpace(this.HiddenField_ISModifyImage.Value)) { string str9 = string.Format(this.hfLogoUrl.Value, ""); fileNameList.Add(str9.Replace(oldValue, "")); model.Logo = str9.Replace(oldValue, newValue); } else { model.Logo = this.hfLogoUrl.Value; } model.Description = str6; model.DisplaySequence = num; if (this.bll.CreateBrandsAndTypes(model, DataProviderAction.Update)) { this.btnCancle.Enabled = false; this.btnSave.Enabled = false; if (!string.IsNullOrWhiteSpace(this.HiddenField_ISModifyImage.Value)) { FileManage.MoveFile(base.Server.MapPath(oldValue), base.Server.MapPath(newValue), fileNameList); if (!string.IsNullOrWhiteSpace(this.HiddenField_OldImage.Value)) { FileManage.DeleteFile(base.Server.MapPath(this.HiddenField_OldImage.Value)); } } else if (!string.IsNullOrWhiteSpace(this.HiddenField_IsDeleteAttachment.Value)) { FileManage.DeleteFile(base.Server.MapPath(this.HiddenField_OldImage.Value)); } MessageBox.ShowSuccessTip(this, "保存成功!", "Alist.aspx"); } else { MessageBox.ShowFailTip(this, "保存失败!", "Alist.aspx"); } } }