/// <summary> /// //自定义字段 /// </summary> private void GetZiDingYi(Hi.Model.BD_Goods model) { string html = string.Empty; List <Hi.Model.SYS_SysName> l = new Hi.BLL.SYS_SysName().GetList("", "isnull(dr,0)=0 and compId=" + model.CompID + " and name='商品自定义字段'", ""); if (l.Count > 0) { if (!Util.IsEmpty(l[0].Value.Trim())) { string[] valuelist = l[0].Value.Trim().Split(','); if (valuelist.Length == 5) { html = "<div class=\"li\"><i class=\"bt2\">" + valuelist[0] + ":</i><i >" + model.Value1.Trim() + "</i> <i class=\"bt2\">" + valuelist[1] + ":</i><i >" + model.Value2.Trim() + "</i><br /> <i class=\"bt2\">" + valuelist[2] + ":</i><i >" + model.Value3.Trim() + "</i> <i class=\"bt2\">" + valuelist[3] + ":</i><i >" + model.Value4.Trim() + "</i><br /><i class=\"bt2\">" + valuelist[4] + ":</i><i >" + model.Value5.Trim() + "</i></div>"; } else if (valuelist.Length == 4) { html = "<div class=\"li\"><i class=\"bt2\">" + valuelist[0] + ":</i><i >" + model.Value1.Trim() + "</i> <i class=\"bt2\">" + valuelist[1] + ":</i><i >" + model.Value2.Trim() + "</i><br /> <i class=\"bt2\">" + valuelist[2] + ":</i><i >" + model.Value3.Trim() + "</i> <i class=\"bt2\">" + valuelist[3] + ":</i><i >" + model.Value4.Trim() + "</i></div>"; } else if (valuelist.Length == 3) { html = "<div class=\"li\"><i class=\"bt2\">" + valuelist[0] + ":</i><i >" + model.Value1.Trim() + "</i> <i class=\"bt2\">" + valuelist[1] + ":</i><i >" + model.Value3.Trim() + "</i><br /> <i class=\"bt2\">" + valuelist[2] + ":</i><i >" + model.Value3.Trim() + "</i></div>"; } else if (valuelist.Length == 2) { html = "<div class=\"li\"><i class=\"bt2\">" + valuelist[0] + ":</i><i >" + model.Value1.Trim() + "</i> <i class=\"bt2\">" + valuelist[1] + ":</i><i >" + model.Value2.Trim() + "</i></div>"; } else if (valuelist.Length == 1) { html = "<div class=\"li\"><i class=\"bt2\">" + valuelist[0] + ":</i><i >" + model.Value1.Trim() + "</i></div>"; } } } this.litZiDingYi.Text = html; }
/// <summary> /// //自定义字段 /// </summary> private void GetZiDingYi(Hi.Model.BD_Goods model) { string html = string.Empty; List <Hi.Model.SYS_SysName> l = new Hi.BLL.SYS_SysName().GetList("", "isnull(dr,0)=0 and compId=" + model.CompID + " and name='商品自定义字段'", ""); if (l.Count > 0) { if (!Util.IsEmpty(l[0].Value.Trim())) { string[] valuelist = l[0].Value.Trim().Split(','); for (int i = 0; i < valuelist.Length; i++) { string strvalue = string.Empty; if (i == 0) { strvalue = model.Value1.Trim(); } else if (i == 1) { strvalue = model.Value2.Trim(); } else if (i == 2) { strvalue = model.Value3.Trim(); } else if (i == 3) { strvalue = model.Value4.Trim(); } else if (i == 4) { strvalue = model.Value5.Trim(); } if (Util.IsEmpty(strvalue)) { continue; } html += "<div class=\"li\"><div class=\"t\" style=\"margin-top: -7px;\">" + valuelist[i] + ":</div><div class=\"n zidingyi\">" + strvalue + "</div></div>"; } // } } } this.litZiDingYi.InnerHtml = html; }
/// <summary> /// 确定导入 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnImport_Click(object sender, EventArgs e) { if (HttpContext.Current.Session["GoodsTable"] != null) { SqlTransaction Tran = null; SqlConnection Connection = new SqlConnection(SqlHelper.LocalSqlServer); Connection.Open(); Tran = Connection.BeginTransaction(); try { DataTable dt = HttpContext.Current.Session["GoodsTable"] as DataTable; for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["chkstr"].ToString() == "数据正确!") { Hi.Model.BD_Goods model = new Hi.Model.BD_Goods(); model.CompID = this.CompID; model.GoodsName = dt.Rows[i]["goodsname"].ToString(); model.GoodsCode = "";// dt.Rows[i]["barcode"].ToString(); ; model.CategoryID = Convert.ToInt32(dt.Rows[i]["categoryid"].ToString()); model.Unit = CheckGoodsUnit(dt.Rows[i]["unit"].ToString(), "计量单位", Tran); model.SalePrice = Convert.ToDecimal(dt.Rows[i]["price"].ToString()); //if (dt.Rows[i]["isoffline"] == null) //{ // model.IsOffline = 1; //} //else //{ model.IsOffline = dt.Rows[i]["isoffline"].ToString() == "是" || dt.Rows[i]["isoffline"].ToString() == "" ? 1 : 0; // } model.IsSale = 0; //if (dt.Rows[i]["isrecommended"] == null) //{ // model.IsRecommended = 1; //} //else //{ model.IsRecommended = dt.Rows[i]["isrecommended"].ToString() == "是" || dt.Rows[i]["isrecommended"].ToString() == "" ? 1 : 0; // } model.IsIndex = 0; model.Title = dt.Rows[i]["title"].ToString(); model.CreateUserID = this.UserID; model.CreateDate = DateTime.Now; model.IsEnabled = 1; model.modifyuser = this.UserID; model.memo = dt.Rows[i]["details"].ToString(); model.ts = DateTime.Now; int goodsId = new Hi.BLL.BD_Goods().Add(model, Tran); string[] spec = (string[])dt.Rows[i]["spec"]; if (spec.Length == 0) { Hi.Model.BD_GoodsInfo model4 = new Hi.Model.BD_GoodsInfo(); model4.CompID = this.CompID; if (dt.Rows[i]["barcode"].ToString() == "") { model4.BarCode = GoodsCode(Tran); } else { model4.BarCode = dt.Rows[i]["barcode"].ToString(); } model4.GoodsID = goodsId; if (dt.Rows[i]["inventory"].ToString() != "") { model4.Inventory = Convert.ToDecimal(dt.Rows[i]["inventory"].ToString()); } model4.IsOffline = 1; model4.ValueInfo = ""; model4.SalePrice = Convert.ToDecimal(dt.Rows[i]["price"].ToString()); model4.TinkerPrice = Convert.ToDecimal(dt.Rows[i]["price"].ToString()); model4.IsEnabled = true; model4.CreateDate = DateTime.Now; model4.CreateUserID = this.UserID; model4.ts = DateTime.Now; model4.modifyuser = this.UserID; int goodsInfoId = new Hi.BLL.BD_GoodsInfo().Add(model4, Tran); model.ID = goodsId; model.ViewInfoID = goodsInfoId; model.ts = DateTime.Now; model.modifyuser = this.UserID; new Hi.BLL.BD_Goods().Update(model, Tran); } else { List <List <string> > valueList = new List <List <string> >(); for (int v = 0; v < spec.Length; v++) { //添加商品属性数据 Hi.Model.BD_GoodsAttrs attr = new Hi.Model.BD_GoodsAttrs(); attr.GoodsID = goodsId; attr.CompID = CompID; attr.dr = 0; attr.ts = DateTime.Now; attr.modifyuser = UserID; attr.AttrsName = spec[v].Trim(); int attrid = new Hi.BLL.BD_GoodsAttrs().Add(attr, Tran); List <string> valueList2 = new List <string>(); string[] values = dt.Rows[i]["value" + (v + 1) + ""].ToString().Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); foreach (string value in values) { valueList2.Add(value); //添加商品属性值明细数据 Hi.Model.BD_GoodsAttrsInfo attrinfo = new Hi.Model.BD_GoodsAttrsInfo(); attrinfo.AttrsID = attrid; attrinfo.GoodsID = goodsId; attrinfo.CompID = CompID; attrinfo.ts = DateTime.Now; attrinfo.modifyuser = UserID; attrinfo.AttrsInfoName = value.Trim(); new Hi.BLL.BD_GoodsAttrsInfo().Add(attrinfo, Tran); } valueList.Add(valueList2); } string[] valueInfos = makeValueInfo(valueList, spec); //生成商品ValueInfo int firstInfoId = 0; foreach (string valueinfo in valueInfos) { Hi.Model.BD_GoodsInfo goodsinfo = new Hi.Model.BD_GoodsInfo(); goodsinfo.IsOffline = 1; goodsinfo.ValueInfo = ""; goodsinfo.SalePrice = dt.Rows[i]["price"].ToString().ToDecimal(0); goodsinfo.TinkerPrice = dt.Rows[i]["price"].ToString().ToDecimal(0); goodsinfo.IsEnabled = true; goodsinfo.CreateDate = DateTime.Now; goodsinfo.CreateUserID = this.UserID; goodsinfo.ts = DateTime.Now; goodsinfo.modifyuser = this.UserID; goodsinfo.GoodsID = goodsId; if (dt.Rows[i]["inventory"].ToString() != "") { goodsinfo.Inventory = Convert.ToDecimal(dt.Rows[i]["inventory"].ToString()); } goodsinfo.BarCode = GoodsCode(Tran); goodsinfo.CompID = this.CompID; goodsinfo.ValueInfo = valueinfo; string[] infos = valueinfo.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); for (int index = 0; index < infos.Length; index++) { goodsinfo.GetType().GetProperty("Value" + (index + 1) + "").SetValue(goodsinfo, infos[index].Split(new char[] { ':' })[1], null); } int goodsInfoId = new Hi.BLL.BD_GoodsInfo().Add(goodsinfo, Tran); if (firstInfoId == 0) { firstInfoId = goodsInfoId; } } model.ID = goodsId; model.ViewInfoID = firstInfoId; model.ts = DateTime.Now; model.modifyuser = this.UserID; new Hi.BLL.BD_Goods().Update(model, Tran); } } } Tran.Commit(); Response.Redirect("ImportGoods3.aspx", false); //ClientScript.RegisterStartupScript(this.GetType(), "Add", "<script>addlis(" + count + "," + count2 + ",'" + str + "');</script>"); } catch (Exception ex) { if (Tran != null) { if (Tran.Connection != null) { Tran.Rollback(); } } HttpContext.Current.Session["GoodsTable"] = null; JScript.AlertMethod(this, "系统错误,导入商品失败!", JScript.IconOption.错误, "function(){location.href='ImportGoods.aspx'}"); } } else { JScript.AlertMethod(this, "Excel没有数据,请重新导入", JScript.IconOption.错误, "function(){location.href='ImportGoods.aspx'}"); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Hi.Model.BD_Goods model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Hi.Model.BD_Goods model) { return(dal.Add(model)); }
public void btnAddList_Click(object sender, EventArgs e) { string path = ""; int count = 0; int count2 = 0; int index = 0; SqlTransaction Tran = null; try { if (FileUpload1.HasFile == false)//HasFile用来检查FileUpload是否有指定文件 { JScript.AlertMethod(this, "请您选择Excel文件", JScript.IconOption.错误); return; //当无文件时,返回 } string IsXls = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower(); //System.IO.Path.GetExtension获得文件的扩展名 if (IsXls != ".xls" && IsXls != ".xlsx") { JScript.AlertMethod(this, "只可以选择Excel文件", JScript.IconOption.错误); return;//当选择的不是Excel文件时,返回 } if (!Directory.Exists(Server.MapPath("TemplateFile"))) { Directory.CreateDirectory(Server.MapPath("TemplateFile")); } string filename = FileUpload1.FileName; string name = filename.Replace(IsXls, ""); path = Server.MapPath("TemplateFile/") + name + "-" + DateTime.Now.ToString("yyyyMMddhhmmssffff") + IsXls; FileUpload1.SaveAs(path); System.Data.DataTable dt = Common.ExcelToDataTable(path, TitleIndex); if (dt == null) { throw new Exception("Excel表中无数据"); } if (dt.Rows.Count == 0) { throw new Exception("Excel表中无数据"); } string goodsName = string.Empty; string goodsPrice = string.Empty; string goodsUnit = string.Empty; string goodsRemark = string.Empty; string goodsKuc = string.Empty; string goodsBarCode = string.Empty; string goodsCate = string.Empty; string goodsCate2 = string.Empty; string goodsCate3 = string.Empty; DataRow[] rows = dt.Select(); Tran = DBUtility.SqlHelper.CreateStoreTranSaction(); Eroor = false; TitleError = string.Empty; int goodsId = 0; foreach (DataRow row in rows) { List <string[]> al = new List <string[]>(); string goodsAttrValue = string.Empty; string goodsAttr = string.Empty; try { if (row["分类*(必填项,“/”号分割分类)"].ToString().Trim() == "" && row["商品名称*(必填项,不能重复,不超过30个汉字)"].ToString().Trim() == "" && row["计量单位*(必填项,例如:件、个)"].ToString().Trim() == "" && row["价格*(必填项,最多两位小数)"].ToString().Trim() == "") { continue; } index++; if (row["分类*(必填项,“/”号分割分类)"].ToString().Trim() == "示例:食品/面包" || row["分类*(必填项,“/”号分割分类)"].ToString().Trim() == "示例:食品/牛奶/伊利" || row["分类*(必填项,“/”号分割分类)"].ToString().Trim() == "示例:食品/牛奶/伊利") { continue; } string str = string.Empty;//几级商品分类 if (Util.IsEmpty(row["分类*(必填项,“/”号分割分类)"].ToString().Trim())) { CheckVal(row["分类*(必填项,“/”号分割分类)"].ToString().Trim(), "分类", index); } else { goodsCate = CheckGoodsCate(CheckVal(row["分类*(必填项,“/”号分割分类)"].ToString().Trim(), "分类", index), "", index, Tran); categoryId = goodsCate.Split('@')[1]; } } catch (Exception ex) { if (ex is ApplicationException) { Eroor = true; TitleError += ex.Message; continue; } else { throw new Exception("商品Excel模版格式错误,请重新下载模版填入数据后导入。"); } } goodsName = GoodsObjExists(CheckVal(row["商品名称*(必填项,不能重复,不超过30个汉字)"].ToString().Trim(), "商品名称", index), "商品名称", index, Tran); goodsBarCode = GoodsObjExists(CheckVal(row["商品编码(非必填项,允许为空。如果填了,不能重复,不超过15个字符)"].ToString().Trim(), "商品编码", index), "商品编码", index, Tran); //if (goodsName == "ycz" || goodsBarCode == "ycz") //{ //已存在的数据,则跳过 // count2++; // continue; //} goodsUnit = CheckGoodsUnit(CheckVal(row["计量单位*(必填项,例如:件、个)"].ToString().Trim(), "计量单位", index), "计量单位", index, Tran); goodsPrice = CheckPrice(CheckVal(row["价格*(必填项,最多两位小数)"].ToString().Trim(), "价格", index), "价格", index); goodsKuc = CheckVal(row["库存(可设置是否启用)"].ToString().Trim(), "商品库存", index); goodsRemark = row["卖点/关键词(可不填,所填内容用来简单描述商品卖点信息)"].ToString().Trim(); Hi.Model.BD_Goods model = new Hi.Model.BD_Goods(); model.CompID = this.CompID; model.GoodsName = goodsName; model.GoodsCode = goodsBarCode; model.CategoryID = Convert.ToInt32(categoryId); model.Unit = goodsUnit; model.SalePrice = Convert.ToDecimal(goodsPrice); model.IsOffline = 1; model.IsSale = 0; model.IsRecommended = 1; model.IsIndex = 0; model.Title = goodsRemark; model.CreateUserID = this.UserID; model.CreateDate = DateTime.Now; model.IsEnabled = 1; model.modifyuser = this.UserID; model.ts = DateTime.Now; goodsId = new Hi.BLL.BD_Goods().Add(model, Tran); Hi.Model.BD_GoodsInfo model4 = new Hi.Model.BD_GoodsInfo(); model4.CompID = this.CompID; model4.BarCode = goodsBarCode; model4.GoodsID = goodsId; if (!Util.IsEmpty(goodsKuc)) { model4.Inventory = Convert.ToDecimal(goodsKuc); } model4.IsOffline = 1; model4.ValueInfo = ""; model4.SalePrice = Convert.ToDecimal(goodsPrice); model4.TinkerPrice = Convert.ToDecimal(goodsPrice); model4.IsEnabled = true; model4.CreateDate = DateTime.Now; model4.CreateUserID = this.UserID; model4.ts = DateTime.Now; model4.modifyuser = this.UserID; int goodsInfoId = new Hi.BLL.BD_GoodsInfo().Add(model4, Tran); Hi.Model.BD_Goods goodsModel = new Hi.BLL.BD_Goods().GetModel(goodsId, Tran); goodsModel.ViewInfoID = goodsInfoId; goodsModel.ts = DateTime.Now; goodsModel.modifyuser = this.UserID; new Hi.BLL.BD_Goods().Update(goodsModel, Tran); //} count++; } if (!Eroor) { Tran.Commit(); string str = string.Empty; if (count2 != 0) { str = ",剩余" + count2 + "条为重复数据"; } ClientScript.RegisterStartupScript(this.GetType(), "Add", "<script>addlis(" + count + "," + count2 + ",'" + str + "');</script>"); } else { Tran.Rollback(); JScript.AlertMethod(this, TitleError, JScript.IconOption.错误, "function(){ addList(); }"); } } catch (Exception ex) { if (Tran != null) { if (Tran.Connection != null) { Tran.Rollback(); } } JScript.AlertMethod(this, ex.Message, JScript.IconOption.错误, "function(){ addList(); }"); } finally { if (!Util.IsEmpty(path)) { if (File.Exists(path)) { File.Delete(path); } } } }
protected void btnGoodsTransfer_Click(object sender, EventArgs e) { SqlTransaction TranSaction = null; string ShowStr = "<i style='color:red;'>{0}</i>"; int GoodsAdd = 0; int GoodsTB = 0; int CategoryAdd = 0; int CategoryTB = 0; int PayAdd = 0; int PayTB = 0; try { #region 商品分类新增/同步方法 XmlDocument xml = null;//ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetInvClass", "获取产品分类"); XmlElement elment = xml.DocumentElement; if (!string.IsNullOrEmpty(elment.GetAttribute("err"))) { lblGoodsIpResult.InnerText = elment.GetAttribute("err"); return; } TranSaction = DBUtility.SqlHelper.CreateStoreTranSaction(); XmlNodeList xmllist = xml.DocumentElement.SelectNodes("bill"); foreach (XmlNode xmlbill in xmllist) { XmlNode xmlheader = xmlbill.SelectSingleNode("header"); string goodsflcode = xmlheader.SelectSingleNode("inventoryclasscode").InnerText; string goodsflname = xmlheader.SelectSingleNode("inventoryclassname").InnerText; string goodsflprecode = xmlheader.SelectSingleNode("inventoryclassprecode").InnerText; Hi.Model.BD_GoodsCategory goodsfl = null; DataTable dt = ImportDisProD.GetDataSource("", "BD_GoodsCategory", "and CategoryCode=" + goodsflcode + " and compid=" + CompID, "", TranSaction); if (dt.Rows.Count > 0) { if (string.IsNullOrEmpty(goodsflname)) { SetErrorTb("商品分类(同步)", "分类名称不能为空。分类编码:" + goodsflcode); continue; } DataTable dt1 = ImportDisProD.GetDataSource("", "BD_GoodsCategory", " and CategoryName='" + goodsflname + "' and ParentId=" + goodsflprecode.ToInt(0) + " and compid=" + CompID, "", TranSaction); if (dt1.Rows.Count > 0) { continue; } else { goodsfl = Common.GetEntity <Hi.Model.BD_GoodsCategory>(dt); goodsfl.CategoryName = goodsflname; goodsfl.ParentId = goodsflprecode == "" ? 0 : int.Parse(goodsflprecode); goodsfl.ts = DateTime.Now; goodsfl.modifyuser = UserID; if (new Hi.BLL.BD_GoodsCategory().Update(goodsfl, TranSaction)) { CategoryTB++; } } } else { goodsfl = new Hi.Model.BD_GoodsCategory(); goodsfl.CompID = CompID; goodsfl.GoodsTypeID = 17; goodsfl.CategoryCode = goodsflcode; goodsfl.CategoryName = goodsflname; goodsfl.ParentId = goodsflprecode == "" ? 0 : int.Parse(goodsflprecode); goodsfl.IsEnabled = 1; goodsfl.CreateUserID = UserID; goodsfl.CreateDate = DateTime.Now; goodsfl.ts = DateTime.Now; goodsfl.dr = 0; goodsfl.modifyuser = UserID; if (new Hi.BLL.BD_GoodsCategory().Add(goodsfl) > 0) { CategoryAdd++; } } } #endregion #region 商品基本信息、商品详情新增/同步 xml = null;//ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetInv", "获取产品档案"); elment = xml.DocumentElement; if (!string.IsNullOrEmpty(elment.GetAttribute("err"))) { lblGoodsIpResult.InnerText = elment.GetAttribute("err"); return; } xmllist = xml.DocumentElement.SelectNodes("bill"); foreach (XmlNode xmlbill in xmllist) { XmlNode xmlheader = xmlbill.SelectSingleNode("header"); string goodscode = xmlheader.SelectSingleNode("inventorycode").InnerText; string goodsname = xmlheader.SelectSingleNode("customername").InnerText; string goodstypecode = xmlheader.SelectSingleNode("inventoryclasscode").InnerText; string unit = xmlheader.SelectSingleNode("unit").InnerText; string startdate = xmlheader.SelectSingleNode("startdate").InnerText; string enddate = xmlheader.SelectSingleNode("enddate").InnerText; Hi.Model.BD_Goods goods = null; DataTable dt = ImportDisProD.GetDataSource("", "BD_Goods", " and goodscode='" + goodscode + "' and compid=" + CompID, "", TranSaction); if (dt.Rows.Count > 0) { if (string.IsNullOrEmpty(goodsname)) { SetErrorTb("商品(同步)", "商品名称不能为空。产品编码:" + goodscode); continue; } else if (string.IsNullOrEmpty(unit)) { SetErrorTb("商品(同步)", "商品单位不能为空。产品编码:" + unit); continue; } DataTable dt1 = ImportDisProD.GetDataSource("top 1 *", "BD_GoodsCategory", "and CategoryCode=" + goodstypecode + " and compid=" + CompID, "", TranSaction); goods = Common.GetEntity <Hi.Model.BD_Goods>(dt); goods.GoodsName = goodsname; if (dt1.Rows.Count > 0) { goods.CategoryID = (int)dt1.Rows[0]["id"]; } else { goods.CategoryID = 0; } goods.Unit = unit; if (!string.IsNullOrEmpty(startdate)) { goods.OfflineStateDate = DateTime.Parse(startdate); } if (!string.IsNullOrEmpty(enddate)) { goods.OfflineEndDate = DateTime.Parse(enddate); } if (DateTime.Now >= goods.OfflineStateDate && DateTime.Now <= goods.OfflineEndDate) { goods.IsOffline = 1; } else { goods.IsOffline = 0; } xml = null;//ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetInvPrice", "获取产品价格", "<bill><header><inventorycode>" + goodscode + "</inventorycode></header></bill>"); elment = xml.DocumentElement; if (!string.IsNullOrEmpty(elment.GetAttribute("err"))) { lblGoodsIpResult.InnerText = elment.GetAttribute("err"); return; } xmllist = xml.DocumentElement.SelectNodes("bill"); XmlNode xmlheaderinfo = xmllist[0].SelectSingleNode("header"); string goodsprice = xmlheaderinfo.SelectSingleNode("price").InnerText; if (string.IsNullOrEmpty(goodsprice)) { SetErrorTb("商品(同步)", "商品价格不能为空。产品编码:" + goodscode); continue; } goods.SalePrice = decimal.Parse(goodsprice); Hi.Model.BD_GoodsInfo goodsinfo = null; DataTable dt2 = ImportDisProD.GetDataSource("top 1 *", "BD_GoodsInfo", "and value1=" + goods.GoodsCode + " and compid=" + CompID, "", TranSaction); if (dt2.Rows.Count > 0) { goodsinfo = Common.GetEntity <Hi.Model.BD_GoodsInfo>(dt2); goodsinfo.SalePrice = decimal.Parse(goodsprice); goodsinfo.TinkerPrice = decimal.Parse(goodsprice); goodsinfo.IsEnabled = true; goodsinfo.ts = DateTime.Now; goodsinfo.modifyuser = UserID; goods.ts = DateTime.Now; goods.modifyuser = UserID; if (new Hi.BLL.BD_Goods().Update(goods, TranSaction)) { GoodsTB++; } if (new Hi.BLL.BD_GoodsInfo().Update(goodsinfo, TranSaction)) { PayTB++; } } else { goodsinfo = new Hi.Model.BD_GoodsInfo(); goodsinfo.CompID = CompID; goodsinfo.GoodsID = goods.ID; goodsinfo.Value1 = goods.GoodsCode; goodsinfo.SalePrice = decimal.Parse(goodsprice); goodsinfo.TinkerPrice = decimal.Parse(goodsprice); goodsinfo.IsEnabled = true; goodsinfo.CreateUserID = UserID; goodsinfo.CreateDate = DateTime.Now; goodsinfo.ts = DateTime.Now; goodsinfo.modifyuser = UserID; goods.ts = DateTime.Now; goods.modifyuser = UserID; if (new Hi.BLL.BD_Goods().Update(goods, TranSaction)) { GoodsTB++; } if (new Hi.BLL.BD_GoodsInfo().Add(goodsinfo, TranSaction) > 0) { PayAdd++; } } } else { if (string.IsNullOrEmpty(goodsname)) { SetErrorTb("商品(添加)", "商品名称不能为空。产品编码:" + goodscode); continue; } else if (string.IsNullOrEmpty(unit)) { SetErrorTb("商品(添加)", "商品单位不能为空。产品编码:" + unit); continue; } DataTable dt1 = ImportDisProD.GetDataSource("top 1 *", "BD_GoodsCategory", "and CategoryCode=" + goodstypecode + " and compid=" + CompID, "", TranSaction); goods = new Hi.Model.BD_Goods(); if (dt1.Rows.Count > 0) { goods.CategoryID = (int)dt1.Rows[0]["id"]; } else { goods.CategoryID = 0; } goods.CompID = CompID; goods.GoodsName = goodsname; goods.GoodsCode = goodscode; goods.Unit = unit; if (DateTime.Now >= goods.OfflineStateDate && DateTime.Now <= goods.OfflineEndDate) { goods.IsOffline = 1; } else { goods.IsOffline = 0; } goods.IsIndex = 0; goods.IsSale = 0; goods.IsRecommended = 1; goods.IsEnabled = 1; goods.CreateUserID = UserID; goods.CreateDate = DateTime.Now; goods.ts = DateTime.Now; goods.modifyuser = UserID; xml = null;// ImportDisProD.GetServiceXmlStr(Enum.GetName(typeof(Enums.Erptype), Erptype), "GetInvPrice", "获取产品价格", "<bill><header><inventorycode>" + goodscode + "</inventorycode></header></bill>"); elment = xml.DocumentElement; if (!string.IsNullOrEmpty(elment.GetAttribute("err"))) { lblGoodsIpResult.InnerText = elment.GetAttribute("err"); return; } xmllist = xml.DocumentElement.SelectNodes("bill"); XmlNode xmlheaderinfo = xmllist[0].SelectSingleNode("header"); string goodsprice = xmlheaderinfo.SelectSingleNode("price").InnerText; if (string.IsNullOrEmpty(goodsprice)) { SetErrorTb("商品(添加)", "商品价格不能为空。产品编码:" + goodscode); continue; } goods.SalePrice = decimal.Parse(goodsprice); int goodsid = new Hi.BLL.BD_Goods().Add(goods, TranSaction); if (goodsid > 0) { GoodsAdd++; Hi.Model.BD_GoodsInfo goodsinfo = new Hi.Model.BD_GoodsInfo(); goodsinfo.CompID = CompID; goodsinfo.GoodsID = goodsid; goodsinfo.Value1 = goodscode; goodsinfo.SalePrice = decimal.Parse(goodsprice); goodsinfo.TinkerPrice = decimal.Parse(goodsprice); goodsinfo.IsEnabled = true; goodsinfo.CreateDate = DateTime.Now; goodsinfo.CreateUserID = UserID; goodsinfo.ts = DateTime.Now; goodsinfo.modifyuser = UserID; if (new Hi.BLL.BD_GoodsInfo().Add(goodsinfo, TranSaction) > 0) { PayAdd++; } } } } #endregion } catch { lblGoodsIpResult.InnerText = "读取文件错误,请联系管理员"; } finally { if (ErrTb.Rows.Count > 0) { HERCount.InnerText = ErrTb.Rows.Count.ToString(); DivError.Visible = true; Rpt_Error.DataSource = ErrTb; Rpt_Error.DataBind(); } } }