Exemplo n.º 1
0
        //由入库单类型获取类型解释
        protected string GetSIType(object obj)
        {
            string reValue = string.Empty;

            if (obj == null)
            {
                return("");
            }

            string code = obj.ToString();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                var tmp = edm.DataDict.Where(o => (o.Category == "SIType" && o.Code == code)).Select(o => o.Name).ToList();
                if (tmp.Count != 0 && tmp != null)
                {
                    reValue = tmp[0].ToString();
                }
            }

            if (reValue.ToString() == string.Empty)
            {
                using (var edm = new Gold.DAL.GoldEntities())
                {
                    var tmp = edm.DataDict.Where(o => (o.Category == "SCType" && o.Code == code)).Select(o => o.Name).ToList();
                    if (tmp.Count != 0 && tmp != null)
                    {
                        reValue = tmp[0].ToString();
                    }
                }
            }

            return(reValue);
        }
Exemplo n.º 2
0
        //确定按钮
        protected void hideModalPopupViaServer_Click(object sender, EventArgs e)
        {
            try
            {
                string orderCode = Request.QueryString["orderCode"];
                using (var edm = new Gold.DAL.GoldEntities())
                {
                    var tmp = edm.ShiftOrder.SingleOrDefault(o => o.OrderCode == orderCode);
                    if (tmp != null)
                    {
                        if (Session["UserInfo"] != null)
                        {
                            Users userInfo = (Users)Session["UserInfo"];
                            tmp.EditorID   = userInfo.UserId;
                            tmp.EditorName = userInfo.UserName;
                        }
                        tmp.EditTime   = System.DateTime.Now;
                        tmp.EditStatus = 1;//设置当前订单状态为正在编辑

                        //保存数据
                        edm.ShiftOrder.ApplyCurrentValues(tmp);
                        edm.SaveChanges();
                    }
                }

                string sortDiEx = string.Empty;
                if (ViewState["viewSortDirectionExpression"] != null)
                {
                    sortDiEx = ViewState["viewSortDirectionExpression"].ToString();
                }

                if (btnGenStockIn.Visible)
                {
                    Response.Redirect("../StockMove/StockInReg.aspx?sourceType=shiftorder&sourceCode=" + orderCode + "&sortExDi=" + sortDiEx);
                }
                else if (btnGetStockOut.Visible)
                {
                    Response.Redirect("../StockMove/StockOutReg.aspx?sourceType=shiftorder&sourceCode=" + orderCode + "&sortExDi=" + sortDiEx);
                }

                this.programmaticModalPopup.Hide();
                //return;
            }
            catch (Exception ex)
            {
                string msg = Utility.LogHelper.GetExceptionMsg(ex);
                msg = msg.Replace("\r\n", "");
                DAL.CommonConvert.ShowMessageBox(this.Page, "跳转界面发生异常!" + msg);
            }
        }
Exemplo n.º 3
0
        //添加记录
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            //TextBox txtName = GridView1.FooterRow.FindControl("txtName") as TextBox;
            //TextBox txtDesc = GridView1.FooterRow.FindControl("txtDescription") as TextBox;

            using (var context = new Gold.DAL.GoldEntities())
            {
                var tmp = context.CreateObject <Position>();
                tmp.PositionName = _txtName.Text;
                tmp.Description  = _txtDesc.Text;
                context.AddToPosition(tmp);
                context.SaveChanges();
                GridView1.DataBind();
            }
        }
Exemplo n.º 4
0
        public static string[] GetClientName(string prefixText, int count)
        {
            List <string> lstClientName = new List <string>();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                var tmp = (edm.SalesOrder.Where(o => o.ClientName.Contains(prefixText)).Select(o => o.ClientName)).Distinct().ToList();
                if (tmp != null || tmp.Count != 0)
                {
                    //绑定数据
                    lstClientName = tmp;
                }
            }
            return(lstClientName.ToArray());
        }
Exemplo n.º 5
0
        public static string[] GetReceiverName(string prefixText, int count)
        {
            List <string> lstReceiverName = new List <string>();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                //SQL:Select Distinct ReceiverName from edm.ShiftOrder where ReceiverName like '%王%'
                var tmp = (edm.ShiftOrder.Where(o => o.ReceiverName.Contains(prefixText)).Select(o => o.ReceiverName)).Distinct().ToList();
                if (tmp != null || tmp.Count != 0)
                {
                    //绑定数据
                    lstReceiverName = tmp;
                }
            }
            return(lstReceiverName.ToArray());
        }
Exemplo n.º 6
0
        public static string[] GetSupplier(string prefixText, int count)
        {
            List <string> lstSupplier = new List <string>();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                //SQL:Select Distinct Supplier from edm.TransferOrder where Supplier like '%王%'
                var tmp = (edm.TransferOrder.Where(o => o.Supplier.Contains(prefixText)).Select(o => o.Supplier)).Distinct().ToList();
                if (tmp != null || tmp.Count != 0)
                {
                    //绑定数据
                    lstSupplier = tmp;
                }
            }
            return(lstSupplier.ToArray());
        }
Exemplo n.º 7
0
        public static string[] GetBusinessDepartment(string prefixText, int count)
        {
            List <string> lstBusinessDepartment = new List <string>();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                //SQL:Select Distinct BusinessDepartmentName from edm.TransferOrder where BusinessDepartmentName like '%王%'
                var tmp = (edm.TransferOrder.Where(o => o.BusinessDepartmentName.Contains(prefixText)).Select(o => o.BusinessDepartmentName)).Distinct().ToList();
                if (tmp != null || tmp.Count != 0)
                {
                    //绑定数据
                    lstBusinessDepartment = tmp;
                }
            }
            return(lstBusinessDepartment.ToArray());
        }
Exemplo n.º 8
0
        //排序
        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            string sortDirection  = "ASC";

            if (sortExpression.Equals(GridView1.Attributes["sortExpression"]) && "ASC".Equals(GridView1.Attributes["sortDirection"]))
            {
                sortDirection = "DESC";
            }

            try
            {
                string orderCode = Request.QueryString["orderCode"];
                using (var edm = new Gold.DAL.GoldEntities())
                {
                    var tmp = edm.ShiftOrderDetail.Where(o => o.OrderCode == orderCode).ToList();
                    if (tmp == null || tmp.Count == 0)
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "无此销售订单详细记录。订单编码=" + orderCode);
                    }
                    else
                    {
                        if (sortDirection == "ASC")
                        {
                            tmp = tmp.OrderBy(r => r.GetType().GetProperty(sortExpression).GetValue(r, null)).ToList();
                        }
                        else if (sortDirection == "DESC")
                        {
                            tmp = tmp.OrderByDescending(r => r.GetType().GetProperty(sortExpression).GetValue(r, null)).ToList();
                        }

                        GridView1.DataSource = tmp;
                        GridView1.Attributes.Add("sortExpression", sortExpression);
                        GridView1.Attributes.Add("sortDirection", sortDirection);
                        GridView1.DataBind();
                    }
                }
                ViewState["viewSortDirectionExpression"] = sortDirection + "," + sortExpression;//保存sortExpression和sortDirection
            }
            catch (Exception ex)
            {
                string msg = Utility.LogHelper.GetExceptionMsg(ex);
                msg = msg.Replace("\r\n", "");
                DAL.CommonConvert.ShowMessageBox(this.Page, "排序出错!" + msg);
            }
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string orderCode = Request.QueryString["orderCode"];

            if (string.IsNullOrEmpty(orderCode))
            {
                Server.Transfer("../error.aspx?errorInfo=缺少参数:orderCode");
            }
            else
            {
                using (var edm = new Gold.DAL.GoldEntities())
                {
                    var tmp = edm.TransferOrder.Where(o => o.OrderCode == orderCode).ToList();
                    if (tmp == null || tmp.Count == 0)
                    {
                        Server.Transfer("../error.aspx?errorInfo=无此采购订单记录。订单编码=" + orderCode);
                    }
                    else
                    {
                        //绑定数据
                        fvTransferOrder.DataSource = tmp;
                        fvTransferOrder.DataBind();

                        grdTransferOrderDetail.DataSource = tmp[0].TransferOrderDetail.OrderBy(o => o.CargoName);
                        grdTransferOrderDetail.PageSize   = Utility.WebConfigHelper.Instance.GetDefaultPageSize();
                        grdTransferOrderDetail.DataBind();

                        lblEditorID.Text   = tmp[0].EditorID;
                        lblEditorName.Text = tmp[0].EditorName;
                    }
                }
            }

            this.lblTitle.Text = "调拨订单:" + orderCode;

            //这里要注意,一定要放在if (!this.IsPostBack)之外
            DisplayFixHeader(this.grdTransferOrderDetail);//生成固定表头
        }
Exemplo n.º 10
0
        //页面加载事件
        protected void Page_Load(object sender, EventArgs e)
        {
            string orderCode = Request.QueryString["orderCode"];

            if (string.IsNullOrEmpty(orderCode))
            {
                DAL.CommonConvert.ShowMessageBox(this.Page, "缺少参数:" + orderCode);
            }
            else
            {
                using (var edm = new Gold.DAL.GoldEntities())
                {
                    var tmp = edm.PurchaseOrder.Where(o => o.OrderCode == orderCode).ToList();
                    if (tmp == null || tmp.Count == 0)
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "无此采购订单记录。订单编码=" + orderCode);
                    }
                    else
                    {
                        //绑定数据
                        FormView1.DataSource = tmp;
                        FormView1.DataBind();

                        GridView1.DataSource = tmp[0].PurchaseOrderDetail.OrderBy(o => o.CargoName);
                        //GridView1.PageSize = Utility.WebConfigHelper.Instance.GetDefaultPageSize();
                        GridView1.DataBind();

                        lblEditorID.Text   = tmp[0].EditorID;
                        lblEditorName.Text = tmp[0].EditorName;
                    }
                }
            }

            this.lblTitle.Text = "采购订单:" + orderCode;

            //这里要注意,一定要放在if (!this.IsPostBack)之外
            DisplayFixHeader(this.GridView1);//生成固定表头
        }
Exemplo n.º 11
0
        //生成入库单
        protected void btnGenStockIn_Click(object sender, EventArgs e)
        {
            string orderCode = Request.QueryString["orderCode"];

            using (var edm = new Gold.DAL.GoldEntities())
            {
                var tmp = edm.ShiftOrder.SingleOrDefault(o => o.OrderCode == orderCode);
                if (tmp != null)
                {
                    //行项目=0的判断
                    if (tmp.ShiftOrderDetail.Count == 0)
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "此订单没有有效商品,不能生成入库单!");
                        return;
                    }

                    //判断是否有人正在编辑此订单
                    if (tmp.EditStatus == null)//如果为空,则设置状态为0
                    {
                        tmp.EditStatus = 0;
                    }

                    if (tmp.EditStatus == 0)//0-无人编辑,则保存当前用户信息
                    {
                        if (Session["UserInfo"] != null)
                        {
                            Users userInfo = (Users)Session["UserInfo"];
                            tmp.EditorID   = userInfo.UserId;
                            tmp.EditorName = userInfo.UserName;
                        }
                        tmp.EditTime   = System.DateTime.Now;
                        tmp.EditStatus = 1;//设置当前订单状态为正在编辑

                        //保存数据
                        edm.ShiftOrder.ApplyCurrentValues(tmp);
                        edm.SaveChanges();
                    }
                    else if (tmp.EditStatus == 1 && tmp.OrderStatus != 0)//正在编辑 且订单状态不是已完成
                    {
                        //判断该数据库编辑人是否是当前用户
                        if (Session["UserInfo"] != null)
                        {
                            Users userInfo = (Users)Session["UserInfo"];

                            if (tmp.EditorID != userInfo.UserId)
                            {
                                lblInOrOut.Text = "入库单";
                                programmaticModalPopup.Show();
                                return;
                            }
                        }
                    }

                    if (tmp.OrderStatus == 0)//0-全部完成;1-部分完成;2-初始态;3-全部已转;4-部分已转
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "此订单已完成入库,不能再生成入库单!");
                        return;
                    }
                    else if (tmp.OrderStatus == 3)
                    {
                        DAL.CommonConvert.ShowMessageBox(this.Page, "此订单已全部生成入库单,不能再次生成入库单!");
                        return;
                    }
                }
            }

            string sortDiEx = string.Empty;

            if (ViewState["viewSortDirectionExpression"] != null)
            {
                sortDiEx = ViewState["viewSortDirectionExpression"].ToString();
            }
            Response.Redirect("../StockMove/StockInReg.aspx?sourceType=shiftorder&sourceCode=" + Request.QueryString["orderCode"] + "&sortExDi=" + sortDiEx);
        }
Exemplo n.º 12
0
        //保存数据
        public override string SaveData()
        {
            if (string.IsNullOrEmpty(_stockIn.SIType))
            {
                _stockIn.SIType = "22";//调拨入库单
            }
            if (string.IsNullOrEmpty(_stockIn.FromType))
            {
                _stockIn.FromType = CommonConvert.GetFromTypeCode("源于Excel导入的入库单");
            }

            _stockIn.SIStatus     = 1;    //已保存
            _stockIn.FromBillType = "22"; //21采购入库单、22调拨入库单、23其他入库单
            _stockIn.EditStatus   = 0;    //无人编辑

            StringBuilder sb = new StringBuilder();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                try
                {
                    var tmp = edm.StockIn.SingleOrDefault(o => o.SICode == _stockIn.SICode);
                    if (tmp == null)
                    {
                        edm.StockIn.AddObject(_stockIn);
                    }
                    else
                    {
                        if (tmp.SIStatus == 2)
                        {
                            throw new Exception("此入库单(" + tmp.SICode + ")已提交,不允许再次上传!");
                        }
                        else if (tmp.SIStatus == 5)
                        {
                            throw new Exception("此入库单(" + tmp.SICode + ")正在撤销中,不允许再次上传!");
                        }
                        else if (tmp.SIStatus == 3)
                        {
                            throw new Exception("此入库单(" + tmp.SICode + ")入库已完成,不允许再次上传!");
                        }
                        else if (tmp.SIStatus == 4)//已撤销,则默认是全部撤销,用户可重新上传而不是覆盖
                        {
                            //_stockIn.SICode = KeyGenerator.Instance.GetStockInKey();
                            //foreach (StockDetail sd in _stockIn.StockDetail)
                            //{
                            //    sd.BillCode = _stockIn.SICode;
                            //    sd.SOCode = _stockIn.SICode;
                            //}
                            //edm.StockIn.AddObject(_stockIn);
                            throw new Exception("此入库单(" + tmp.SICode + ")已完成撤销,不允许再次上传!");
                        }
                        else
                        {
                            List <StockDetail> lstDetail = new List <StockDetail>();
                            foreach (StockDetail oldDetail in tmp.StockDetail)
                            {
                                lstDetail.Add(oldDetail);

                                //如果实收数量为0,则直接删除
                                if (oldDetail.NumActual == 0)
                                {
                                    continue;
                                }
                                else
                                {
                                    bool isExist = false;//是否新旧订单都有此商品
                                    foreach (StockDetail newDetail in _stockIn.StockDetail)
                                    {
                                        //判断在当前的新excel中是否有此商品,如果有,则保存实收数量
                                        if (newDetail.CargoCode == oldDetail.CargoCode)
                                        {
                                            newDetail.NumActual = oldDetail.NumActual;
                                            isExist             = true;
                                            break;
                                        }
                                    }
                                    if (isExist)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        //如果当前新excel没有此商品,则直接添加
                                        StockDetail sd = new StockDetail();
                                        sd.BillCode          = oldDetail.BillCode;
                                        sd.BillRowNumber     = oldDetail.BillRowNumber;
                                        sd.BillType          = oldDetail.BillType;
                                        sd.BinCode           = oldDetail.BinCode;
                                        sd.BinName           = oldDetail.BinName;
                                        sd.CargoCode         = oldDetail.CargoCode;
                                        sd.CargoModel        = oldDetail.CargoModel;
                                        sd.CargoName         = oldDetail.CargoName;
                                        sd.CargoSpec         = oldDetail.CargoSpec;
                                        sd.CargoStatus       = oldDetail.CargoStatus;
                                        sd.CargoUnits        = oldDetail.CargoUnits;
                                        sd.Comment           = oldDetail.Comment;
                                        sd.HandSetFinishTime = oldDetail.HandSetFinishTime;
                                        sd.HandSetPersonID   = oldDetail.HandSetPersonID;
                                        sd.HandSetPersonName = oldDetail.HandSetPersonName;
                                        sd.InOutWHCode       = oldDetail.InOutWHCode;
                                        sd.InOutWHName       = oldDetail.InOutWHName;
                                        sd.NumActual         = oldDetail.NumActual;
                                        sd.NumCurrentPlan    = oldDetail.NumCurrentPlan;
                                        sd.NumOriginalPlan   = oldDetail.NumOriginalPlan;
                                        sd.ReleaseYear       = oldDetail.ReleaseYear;
                                        sd.Reserve1          = oldDetail.Reserve1;
                                        sd.Reserve2          = oldDetail.Reserve2;
                                        sd.RFIDOrderNo       = oldDetail.RFIDOrderNo;
                                        sd.RFIDSubmitTime    = oldDetail.RFIDSubmitTime;
                                        sd.RowTotalMoney     = oldDetail.RowTotalMoney;
                                        sd.SICode            = oldDetail.SICode;
                                        sd.UCOrderNo         = oldDetail.UCOrderNo;

                                        _stockIn.StockDetail.Add(sd);
                                    }
                                }
                            }

                            //由于遍历原数据行项目,导致后续删除无法级联删除。故先删除行项目。
                            foreach (StockDetail detail in lstDetail)
                            {
                                edm.StockDetail.DeleteObject(detail);
                                edm.SaveChanges();
                            }

                            edm.StockIn.DeleteObject(tmp);
                            edm.SaveChanges();
                            edm.StockIn.AddObject(_stockIn);
                        }
                    }

                    edm.SaveChanges();
                    sb.AppendLine("保存成功!");
                }
                catch (Exception ex)
                {
                    sb.Append("保存数据时发生异常:");
                    string msg = Utility.LogHelper.GetExceptionMsg(ex);
                    sb.Append(msg);

                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "调拨入库单保存异常", ex);
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 13
0
        //设置生成出入库单、生成入库单按钮的可见性
        protected void fvTransferOrder_DataBound(object sender, EventArgs e)
        {
            Label  lblOutWHName  = fvTransferOrder.FindControl("lblOutWHName") as Label; //出库编码
            Label  lblInWHName   = fvTransferOrder.FindControl("lblInWHName") as Label;  //入库编码
            string defaultWHCode = string.Empty;

            //从配置文件读取默认的仓库--地王26库
            if (System.Configuration.ConfigurationManager.AppSettings.AllKeys.Contains("DefaultWHCode"))
            {
                defaultWHCode = System.Configuration.ConfigurationManager.AppSettings["DefaultWHCode"].ToString();
            }

            if (lblOutWHName != null || lblInWHName != null)
            {
                if (lblOutWHName != null && lblInWHName != null)
                {
                    if (lblOutWHName.Text.ToString() != string.Empty && defaultWHCode.ToString() != string.Empty)//出库
                    {
                        string outWHName = lblOutWHName.Text.ToString();
                        string outWhCode = string.Empty;
                        using (var edm = new Gold.DAL.GoldEntities())
                        {
                            var tmp = edm.WareHouse.SingleOrDefault(o => o.WHName == outWHName);
                            if (tmp != null)
                            {
                                outWhCode = tmp.WHCode;
                            }
                        }
                        if (outWhCode == defaultWHCode)
                        {
                            btnGenStockIn.Visible  = false;
                            btnGenStockOut.Visible = true;
                            return;
                        }
                    }
                    if (lblInWHName.Text.ToString() != string.Empty && defaultWHCode.ToString() != string.Empty)//入库
                    {
                        string inWHName = lblInWHName.Text.ToString();
                        string inWhCode = string.Empty;
                        using (var edm = new Gold.DAL.GoldEntities())
                        {
                            var tmp = edm.WareHouse.SingleOrDefault(o => o.WHName == inWHName);
                            if (tmp != null)
                            {
                                inWhCode = tmp.WHCode;
                            }
                        }
                        if (inWhCode == defaultWHCode)
                        {
                            btnGenStockIn.Visible  = true;
                            btnGenStockOut.Visible = false;
                            return;
                        }
                    }
                    btnGenStockIn.Visible  = false;
                    btnGenStockOut.Visible = false;
                    return;
                }
                else if (lblInWHName != null)//入库
                {
                    if (lblInWHName.Text.ToString() != string.Empty && defaultWHCode.ToString() != string.Empty)
                    {
                        string inWHName = lblInWHName.Text.ToString();
                        string inWhCode = string.Empty;
                        using (var edm = new Gold.DAL.GoldEntities())
                        {
                            var tmp = edm.WareHouse.SingleOrDefault(o => o.WHName == inWHName);
                            if (tmp != null)
                            {
                                inWhCode = tmp.WHCode;
                            }
                        }
                        if (inWhCode == defaultWHCode)
                        {
                            btnGenStockIn.Visible  = true;
                            btnGenStockOut.Visible = false;
                            return;
                        }
                    }
                }
                else if (lblInWHName != null)//入库
                {
                    if (lblInWHName.Text.ToString() != string.Empty && defaultWHCode.ToString() != string.Empty)
                    {
                        string inWHName = lblInWHName.Text.ToString();
                        string inWhCode = string.Empty;
                        using (var edm = new Gold.DAL.GoldEntities())
                        {
                            var tmp = edm.WareHouse.SingleOrDefault(o => o.WHName == inWHName);
                            if (tmp != null)
                            {
                                inWhCode = tmp.WHCode;
                            }
                        }
                        if (inWhCode == defaultWHCode)
                        {
                            btnGenStockIn.Visible  = true;
                            btnGenStockOut.Visible = false;
                            return;
                        }
                    }
                }
                else if (lblOutWHName != null)                                                                    //出库
                {
                    if (lblOutWHName.Text.ToString() != string.Empty && defaultWHCode.ToString() != string.Empty) //出库
                    {
                        string outWHName = lblOutWHName.Text.ToString();
                        string outWhCode = string.Empty;
                        using (var edm = new Gold.DAL.GoldEntities())
                        {
                            var tmp = edm.WareHouse.SingleOrDefault(o => o.WHName == outWHName);
                            if (tmp != null)
                            {
                                outWhCode = tmp.WHCode;
                            }
                        }
                        if (outWhCode == defaultWHCode)
                        {
                            btnGenStockIn.Visible  = false;
                            btnGenStockOut.Visible = true;
                            return;
                        }
                    }
                }
            }

            btnGenStockIn.Visible  = false;
            btnGenStockOut.Visible = false;
            return;
        }
Exemplo n.º 14
0
        //保存数据
        public override string SaveData()
        {
            //if (_order.EntityKey == null)
            //{
            //    IEnumerable<KeyValuePair<string, object>> entityKeyValues =
            //        new KeyValuePair<string, object>[] {
            //            new KeyValuePair<string, object>("OrderCode", _order.OrderCode),
            //        };
            //    _order.EntityKey = new EntityKey("GoldEntities.PurchaseOrder", entityKeyValues);
            //}

            _order.OrderStatus = 2; //初始态
            _order.EditStatus  = 0; //无人编辑

            StringBuilder sb = new StringBuilder();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                try
                {
                    var tmp = edm.PurchaseOrder.SingleOrDefault(o => o.OrderCode == _order.OrderCode);
                    if (tmp == null)
                    {
                        edm.PurchaseOrder.AddObject(_order);
                    }
                    else
                    {
                        //判断该订单是否已经开始其他作业,如果是,则不允许覆盖
                        if (tmp.OrderStatus != 2)
                        {
                            throw new Exception("此订单(" + tmp.OrderCode + ")已开始其他作业,不允许再次上传!");
                        }

                        foreach (PurchaseOrderDetail oldpod in tmp.PurchaseOrderDetail)
                        {
                            //如果实收数量为0,则直接删除
                            if (oldpod.NumActual == null || oldpod.NumActual == 0)
                            {
                                continue;
                            }
                            else
                            {
                                bool isExist = false;//是否新旧订单都有此商品
                                foreach (PurchaseOrderDetail newpod in _order.PurchaseOrderDetail)
                                {
                                    //判断在当前的新excel中是否有此商品,如果有,则保存实收数量
                                    if (newpod.CargoCode == oldpod.CargoCode)
                                    {
                                        newpod.NumActual   = oldpod.NumActual;
                                        isExist            = true;
                                        _order.OrderStatus = 1;//部分已下发
                                        break;
                                    }
                                }
                                if (isExist)
                                {
                                    continue;
                                }
                                else
                                {
                                    //如果当前新excel没有此商品,则直接添加
                                    PurchaseOrderDetail pd = new PurchaseOrderDetail();
                                    pd.CargoCode          = oldpod.CargoCode;
                                    pd.CargoModel         = oldpod.CargoModel;
                                    pd.CargoName          = oldpod.CargoName;
                                    pd.CargoSpec          = oldpod.CargoSpec;
                                    pd.CargoUnits         = oldpod.CargoUnits;
                                    pd.ContractNo         = oldpod.ContractNo;
                                    pd.CurrencyType       = oldpod.CurrencyType;//币种
                                    pd.DeductRate         = oldpod.DeductRate;
                                    pd.DetailRowNumber    = oldpod.DetailRowNumber;
                                    pd.DetailRowStatus    = oldpod.DetailRowStatus;
                                    pd.ExchangeRate       = oldpod.ExchangeRate;
                                    pd.FreedomItem        = oldpod.FreedomItem;
                                    pd.NCOrderCode        = oldpod.NCOrderCode;
                                    pd.NetPrice           = oldpod.NetPrice;
                                    pd.NumActual          = oldpod.NumActual;
                                    pd.NumCurrentPlan     = oldpod.NumCurrentPlan;
                                    pd.NumOriginalPlan    = oldpod.NumOriginalPlan;
                                    pd.OrderCode          = oldpod.OrderCode;
                                    pd.PlanArrivalDate    = oldpod.PlanArrivalDate;
                                    pd.Price              = oldpod.Price;
                                    pd.PriceOfNetTax      = oldpod.PriceOfNetTax;
                                    pd.PriceOfTax         = oldpod.PriceOfTax;
                                    pd.ReceiveBillCompany = oldpod.ReceiveBillCompany;
                                    pd.ReceiveCompany     = oldpod.ReceiveCompany;
                                    pd.ReceiveOrg         = oldpod.ReceiveOrg;
                                    pd.ReleaseYear        = oldpod.ReleaseYear;
                                    pd.Reserve1           = oldpod.Reserve1;
                                    pd.Reserve2           = oldpod.Reserve2;
                                    pd.TaxRate            = oldpod.TaxRate;
                                    pd.TotalPrice         = oldpod.TotalPrice;
                                    pd.TotalTax           = oldpod.TotalTax;
                                    pd.TotalTaxAndPrice   = oldpod.TotalTaxAndPrice;
                                    pd.WHCode             = oldpod.WHCode;
                                    pd.WHName             = oldpod.WHName;
                                    if (pd.NumActual != null && pd.NumActual != 0)
                                    {
                                        _order.OrderStatus = 1;//部分已下发
                                    }

                                    _order.PurchaseOrderDetail.Add(pd);
                                }
                            }
                        }

                        edm.PurchaseOrder.DeleteObject(tmp);
                        edm.SaveChanges();
                        edm.PurchaseOrder.AddObject(_order);
                        //int count = tmp.PurchaseOrderDetail.Count;
                        //List<EntityKey> orignalKeys = new List<EntityKey>();
                        //for (int i = 0; i < count; )
                        //{
                        //    orignalKeys.Add(tmp.PurchaseOrderDetail.ElementAt(i).EntityKey);
                        //    edm.ObjectStateManager.ChangeObjectState(tmp.PurchaseOrderDetail.ElementAt(i), EntityState.Deleted);
                        //    count--;
                        //}

                        //foreach (PurchaseOrderDetail item in _order.PurchaseOrderDetail)
                        //{
                        //    if (orignalKeys.Contains(item.EntityKey))
                        //    {
                        //        edm.ObjectStateManager.ChangeObjectState(item, EntityState.Modified);
                        //        edm.PurchaseOrderDetail.ApplyCurrentValues(item as PurchaseOrderDetail);
                        //    }
                        //    else
                        //    {
                        //        item.EntityKey = null;
                        //        edm.PurchaseOrderDetail.AddObject(item);
                        //        edm.ObjectStateManager.ChangeObjectState(item, EntityState.Added);
                        //    }
                        //}

                        //edm.PurchaseOrder.ApplyCurrentValues(_order);
                    }


                    //    //List<T> collectionItemList = collection.ToList();

                    //    //GenericUpdateEntityCollection<PurchaseOrderDetail>(_order.PurchaseOrderDetail, edm);

                    //    //edm.PurchaseOrder.Detach(tmp);
                    //    //edm.PurchaseOrder.Attach(_order);
                    //    //edm.ObjectStateManager.ChangeObjectState(_order, EntityState.Modified);
                    //    //sb.AppendLine("数据库存在相同单号的订单!将被更新...~");
                    //    //PurchaseOrderDetail dd = _order.PurchaseOrderDetail.First();
                    //    //edm.ObjectStateManager.ChangeObjectState(dd, EntityState.Deleted);
                    //    //foreach (PurchaseOrderDetail item in _order.PurchaseOrderDetail)
                    //    //{
                    //    //    edm.PurchaseOrderDetail.ApplyCurrentValues(item);
                    //    //    edm.ObjectStateManager.ChangeObjectState(item, EntityState.Modified);
                    //    //}
                    //    ////tmp.PurchaseOrderDetail = _order.PurchaseOrderDetail;
                    //}


                    edm.SaveChanges();
                    sb.AppendLine("保存成功!");
                }
                catch (Exception ex)
                {
                    sb.Append("保存数据时发生异常:");
                    string msg = Utility.LogHelper.GetExceptionMsg(ex);
                    sb.Append(msg);

                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "采购订单保存异常", ex);
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 15
0
        public override string SaveData()
        {
            _order.OrderStatus = 2; //初始态
            _order.EditStatus  = 0; //无人编辑

            StringBuilder sb = new StringBuilder();

            using (var edm = new Gold.DAL.GoldEntities())
            {
                try
                {
                    var tmp = edm.ShiftOrder.SingleOrDefault(o => o.OrderCode == _order.OrderCode);
                    if (tmp == null)
                    {
                        edm.ShiftOrder.AddObject(_order);
                    }
                    else
                    {
                        //判断该订单是否已经开始其他作业,如果是,则不允许覆盖
                        if (tmp.OrderStatus != 2)
                        {
                            throw new Exception("此订单(" + tmp.OrderCode + ")已开始其他作业,不允许再次上传!");
                        }

                        foreach (ShiftOrderDetail oldDetail in tmp.ShiftOrderDetail)
                        {
                            //如果实收数量为0,则直接删除
                            if (oldDetail.NumActual == null || oldDetail.NumActual == 0)
                            {
                                continue;
                            }
                            else
                            {
                                bool isExist = false;//是否新旧订单都有此商品
                                foreach (ShiftOrderDetail newDetail in _order.ShiftOrderDetail)
                                {
                                    //判断在当前的新excel中是否有此商品,如果有,则保存实收数量
                                    if (newDetail.CargoCode == oldDetail.CargoCode)
                                    {
                                        newDetail.NumActual = oldDetail.NumActual;
                                        isExist             = true;
                                        _order.OrderStatus  = 1;//部分已下发
                                        break;
                                    }
                                }
                                if (isExist)
                                {
                                    continue;
                                }
                                else
                                {
                                    //如果当前新excel没有此商品,则直接添加
                                    ShiftOrderDetail sd = new ShiftOrderDetail();
                                    sd.CargoCode       = oldDetail.CargoCode;
                                    sd.CargoModel      = oldDetail.CargoModel;
                                    sd.CargoName       = oldDetail.CargoName;
                                    sd.CargoSpec       = oldDetail.CargoSpec;
                                    sd.CargoUnits      = oldDetail.CargoUnits;
                                    sd.Comment         = oldDetail.Comment;
                                    sd.DetailRowNumber = oldDetail.DetailRowNumber;
                                    sd.DetailRowStatus = oldDetail.DetailRowStatus;
                                    sd.NCOrderCode     = oldDetail.NCOrderCode;
                                    sd.NumActual       = oldDetail.NumActual;
                                    sd.NumCurrentPlan  = oldDetail.NumCurrentPlan;
                                    sd.NumOriginalPlan = oldDetail.NumOriginalPlan;
                                    sd.OrderCode       = oldDetail.OrderCode;
                                    sd.ReleaseYear     = oldDetail.ReleaseYear;
                                    sd.Reserve1        = oldDetail.Reserve1;
                                    sd.Reserve2        = oldDetail.Reserve2;
                                    if (sd.NumActual != null && sd.NumActual != 0)
                                    {
                                        _order.OrderStatus = 1;//部分已下发
                                    }

                                    _order.ShiftOrderDetail.Add(sd);
                                }
                            }
                        }

                        edm.ShiftOrder.DeleteObject(tmp);
                        edm.SaveChanges();
                        edm.ShiftOrder.AddObject(_order);
                    }

                    edm.SaveChanges();
                    sb.AppendLine("保存成功!");
                }
                catch (Exception ex)
                {
                    sb.Append("保存数据时发生异常:");
                    string msg = Utility.LogHelper.GetExceptionMsg(ex);
                    sb.Append(msg);

                    Utility.LogHelper.WriteLog(Utility.LogHelper.LogLevel.Error, "转库订单保存异常", ex);
                }
            }

            return(sb.ToString());
        }