Пример #1
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Hi.Model.BD_GoodsAttrsInfo model)
 {
     return(dal.Add(model));
 }
Пример #2
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Hi.Model.BD_GoodsAttrsInfo model)
 {
     return(dal.Update(model));
 }
Пример #3
0
    /// <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'}");
        }
    }