Beispiel #1
0
    /// <summary>
    /// 下移
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public string SortDown(string id)
    {
        categoryList = new Hi.BLL.BD_GoodsCategory().GetList("", "CompID=" + this.CompID + " and isnull(dr,0)=0 ", "");
        if (categoryList == null || categoryList.Count == 0)
        {
            return("{\"result\":false,\"code\":\"操作失败\"}");
        }
        string json = string.Empty;

        if (!string.IsNullOrEmpty(id))
        {
            //老数据没有排序,就添加一个
            Hi.Model.BD_GoodsCategory type = categoryList.Find(p => p.ID.ToString() == id);
            if (type == null)
            {
                return("");
            }
            string sort = type.SortIndex;
            List <Hi.Model.BD_GoodsCategory> LType = categoryList.Where(p => p.ParentId == type.ParentId).OrderBy(p => p.SortIndex).ToList();
            if (LType == null || LType.Count < 2 || LType[LType.Count - 1] == type)
            {
                return(json);
            }
            int count = 0;
            for (int i = 0; i < LType.Count; i++)
            {
                if (LType[i].ID == type.ID)
                {
                    count = i + 1;
                }
            }
            type.SortIndex         = LType[count].SortIndex == "" ? NewCateId().ToString() : LType[count].SortIndex;
            type.ts                = DateTime.Now;
            type.modifyuser        = UserID;
            LType[count].SortIndex = sort;
            LType[count].SortIndex = LType[count].SortIndex;
            LType[count].ts        = DateTime.Now;
            if (new Hi.BLL.BD_GoodsCategory().Update(type) && new Hi.BLL.BD_GoodsCategory().Update(LType[count]))
            {
                return("{\"result\":true,\"code\":\"操作成功\"}");
            }
        }
        return(json);
    }
Beispiel #2
0
    public void BindGoodsCategory()
    {
        List <Hi.Model.BD_GoodsCategory> ClassList = new Hi.BLL.BD_GoodsCategory().GetList(" id,CategoryName ", " dr=0 and IsEnabled=1 and Parentid=0 and Compid='" + ViewState["Compid"] + "' ", " createdate ");

        string.Join(",", ClassList.Select(p => p.ID));

        if (ClassList.Count > 0)
        {
            Hi.Model.BD_GoodsCategory DefaultClass = new Hi.Model.BD_GoodsCategory();
            DefaultClass.CategoryName = "全 部";
            DefaultClass.ID           = 0;
            DefaultClass.CompID       = ClassList[0].CompID;
            DefaultClass.ParentId     = 0;
            DefaultClass.IsEnabled    = 1;
            ClassList.Insert(0, DefaultClass);
        }
        Rpt_GoodsClass.DataSource = ClassList;
        Rpt_GoodsClass.DataBind();
    }
Beispiel #3
0
    /// <summary>
    /// 新增子类
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        string Typename  = Common.NoHTML(txtTypeName.Value.Trim());
        string Parentid  = Common.NoHTML(hideTypeId.Value.Trim());
        string Typecode  = string.Empty;
        string ParentIds = "0";//父元素ID   用于判断是否存在重复子元素

        Hi.Model.BD_GoodsCategory DisType = new Hi.Model.BD_GoodsCategory();

        if (Parentid != "0" && Parentid != "")
        {
            Hi.Model.BD_GoodsCategory one = new Hi.BLL.BD_GoodsCategory().GetModel(Convert.ToInt32(Parentid));
            if (one != null)
            {
                Typecode        = one.GoodsTypeID.ToString(); //商品大类
                DisType.Code    = one.Code + "-" + NewCategoryCode((one.Deep + 1).ToString());
                DisType.Deep    = one.Deep + 1;
                DisType.ParCode = one.Code;
                ParentIds       = one.ID.ToString();
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Result",
                                                        "<script>layerCommon.msg('添加失败!', IconOption.哭脸, 2000);</script>");
                return;
            }

            if (DisType.Deep == 4)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Result",
                                                        "<script>layerCommon.msg('最多只能三级!', IconOption.哭脸, 2000);</script>");
                return;
            }
        }
        else//一级大类
        {
            Typecode        = hid_txtGtype.Value;;//商品大类
            DisType.Code    = NewCategoryCode("1");
            DisType.Deep    = 1;
            DisType.ParCode = "";
            ParentIds       = "0";
        }

        int Result = 0;

        if (string.IsNullOrEmpty(Typecode) || Typecode == "0")
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('商品大类不能为空!', IconOption.哭脸, 2000);</script>");
            return;
        }
        else if (Parentid == "0")
        {
            Hi.Model.SYS_GType gtype = new Hi.BLL.SYS_GType().GetModel(Convert.ToInt32(Typecode));
            if (gtype.Deep != 3)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('请选择三级商品大类!', IconOption.哭脸, 2000);</script>");
                return;
            }
        }
        if (string.IsNullOrEmpty(Typename))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('分类名称不能为空!', IconOption.哭脸, 2000);</script>");
            return;
        }
        if (IsExistsType("CategoryName", Typename, ParentIds))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('分类名称已存在!', IconOption.哭脸, 2000);</script>");
            return;
        }
        if (string.IsNullOrEmpty(Parentid) || !int.TryParse(Parentid, out Result))
        {
            DisType.ParentId = 0;
        }
        else
        {
            DisType.ParentId = Result;
        }
        DisType.CompID       = CompID;
        DisType.CategoryName = Typename;
        DisType.GoodsTypeID  = Convert.ToInt32(Typecode);
        DisType.SortIndex    = NewCateId().ToString();
        DisType.CreateDate   = DateTime.Now;
        DisType.CreateUserID = 0;
        DisType.IsEnabled    = 1;
        DisType.ts           = DateTime.Now;
        DisType.modifyuser   = 0;

        SqlTransaction trans = SqlHelper.CreateStoreTranSaction();

        try
        {
            int countID = 0;
            if ((countID = new Hi.BLL.BD_GoodsCategory().Add(DisType, trans)) > 0)
            {
                List <Hi.Model.BD_Goods> gList = new Hi.BLL.BD_Goods().GetList("", " CategoryID='" + Parentid + "'", "");
                if (gList != null && gList.Count > 0)
                {
                    foreach (var bdGoodse in gList)
                    {
                        bdGoodse.CategoryID = countID;
                        new Hi.BLL.BD_Goods().Update(bdGoodse, trans);
                    }
                }
                trans.Commit();

                Page.ClientScript.RegisterStartupScript(this.GetType(), "Result",
                                                        "<script>layerCommon.msg('新增成功!', IconOption.笑脸, 2000);location.href='GoodsCategory.aspx?type=" + Request["type"].ToString() + "';</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Result",
                                                        "<script>layerCommon.msg('添加失败!', IconOption.哭脸, 2000);</script>");
            }
        }
        catch (Exception ex)
        {
            if (trans != null)
            {
                if (trans.Connection != null)
                {
                    trans.Rollback();
                }
            }
            ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('" + ex.Message + "', IconOption.哭脸, 2000);</script>");
            return;
        }
        finally
        {
            SqlHelper.ConnectionClose();
            if (trans != null)
            {
                if (trans.Connection != null)
                {
                    trans.Connection.Close();
                }
            }
        }
    }
Beispiel #4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Hi.Model.BD_GoodsCategory model)
 {
     return(dal.Update(model));
 }
Beispiel #5
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Hi.Model.BD_GoodsCategory model)
 {
     return(dal.Add(model));
 }
Beispiel #6
0
    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();
            }
        }
    }