예제 #1
0
        //保存分配量
        bool SaveAllocate(GridViewRow editRow, out string saveMsg)
        {
            System.Text.StringBuilder checkMsg = new System.Text.StringBuilder();
            System.Text.StringBuilder LogMsg   = new System.Text.StringBuilder();


            //商品编码
            Label lblCargoCode = editRow.FindControl("lblCargoCode") as Label;

            if (lblCargoCode == null)
            {
                checkMsg.Append("未能获取商品编码");
                checkMsg.Append(Environment.NewLine);
            }

            //结存数量
            TextBox tbxRowTotal = editRow.FindControl("tbxRowTotal") as TextBox;

            if (tbxRowTotal == null)
            {
                checkMsg.Append("未能获取结存数量.");
                checkMsg.Append(Environment.NewLine);
            }

            //渠道部分配量
            TextBox tbxRowDeptChannelAllocation = editRow.FindControl("tbxRowDeptChannelAllocation") as TextBox;

            if (tbxRowDeptChannelAllocation == null)
            {
                checkMsg.Append("未能获取渠道部分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //销售部分配量
            TextBox tbxRowDeptSaleAllocation = editRow.FindControl("tbxRowDeptSaleAllocation") as TextBox;

            if (tbxRowDeptSaleAllocation == null)
            {
                checkMsg.Append("未能获取销售部分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //零售中心分配量
            TextBox tbxRowDeptRetailAllocation = editRow.FindControl("tbxRowDeptRetailAllocation") as TextBox;

            if (tbxRowDeptRetailAllocation == null)
            {
                checkMsg.Append("未能获取零售中心分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //电子商务分配量
            TextBox tbxRowDeptECAllocation = editRow.FindControl("tbxRowDeptECAllocation") as TextBox;

            if (tbxRowDeptECAllocation == null)
            {
                checkMsg.Append("未能获取电子商务分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //公用部门分配量
            TextBox tbxRowDeptPublicAllocation = editRow.FindControl("tbxRowDeptPublicAllocation") as TextBox;

            if (tbxRowDeptPublicAllocation == null)
            {
                checkMsg.Append("未能获取公用部门分配量.");
                checkMsg.Append(Environment.NewLine);
            }

            //机动量
            TextBox tbxRowVariation = editRow.FindControl("tbxRowVariation") as TextBox;

            if (tbxRowVariation == null)
            {
                checkMsg.Append("未能获取机动量.");
                checkMsg.Append(Environment.NewLine);
            }

            if (checkMsg.Length > 0)
            {
                saveMsg = checkMsg.ToString();
                return(false);
            }


            try
            {
                DAL.GoldEntities context = new GoldEntities();

                string cargoCode = lblCargoCode.Text;
                LogMsg.Append("商品编码为");
                LogMsg.Append(lblCargoCode.Text);

                Cargos UpdateCargos = (from r in context.Cargos where r.CargoCode == lblCargoCode.Text.Trim() select r).FirstOrDefault <Cargos>();
                LogMsg.Append(" 原商品结存数量为");
                LogMsg.Append(UpdateCargos.Total.ToString());
                UpdateCargos.Total = int.Parse(tbxRowTotal.Text);
                LogMsg.Append("。更新后商品结存数量为");
                LogMsg.Append(UpdateCargos.Total.ToString());

                LogMsg.Append(" 原商品机动量为");
                LogMsg.Append(UpdateCargos.Variation.ToString());
                UpdateCargos.Variation = int.Parse(tbxRowVariation.Text);
                LogMsg.Append("。更新后商品机动量为");
                LogMsg.Append(UpdateCargos.Variation.ToString());

                //新增或更新渠道部分配量
                string DeptChannelNo = "20103";
                SetNewOrUpdateModel(DeptChannelNo, cargoCode, int.Parse(tbxRowDeptChannelAllocation.Text), ref LogMsg, ref context);


                //新增或更新销售部分配量
                string DeptSaleNo = "20102";
                SetNewOrUpdateModel(DeptSaleNo, cargoCode, int.Parse(tbxRowDeptSaleAllocation.Text), ref LogMsg, ref context);


                //新增或更新零售中心部分配量
                string DeptRetailNo = "20105";//零售中心这里对应营业部
                SetNewOrUpdateModel(DeptRetailNo, cargoCode, int.Parse(tbxRowDeptRetailAllocation.Text), ref LogMsg, ref context);


                //新增或更新电子商务分配量
                string DeptECNo = "20110";
                SetNewOrUpdateModel(DeptECNo, cargoCode, int.Parse(tbxRowDeptECAllocation.Text), ref LogMsg, ref context);


                //新增或更新公用部门分配量
                string DeptPublicNo = "99999";
                SetNewOrUpdateModel(DeptPublicNo, cargoCode, int.Parse(tbxRowDeptPublicAllocation.Text), ref LogMsg, ref context);


                //以上新增和更新使用隐式事务
                int affectRows = context.SaveChanges();
                saveMsg = "影响行数:" + affectRows.ToString();

                context.Dispose();

                return(affectRows > 0 ? true : false);
            }
            catch (Exception ex)
            {
                saveMsg = Utility.LogHelper.GetExceptionMsg(ex);

                return(false);
            }
        }