protected void tbFlow_TextChanged(Object sender, EventArgs e)
    {
        try
        {
            if (this.CurrentFlowCode == null || this.CurrentFlowCode != this.tbFlow.Text)
            {
                Flow currentFlow = TheFlowMgr.LoadFlow(tbFlow.Text, this.CurrentUser.Code, true, this.ModuleType);
                if (currentFlow != null)
                {
                    this.CurrentFlowCode      = currentFlow.Code;
                    this.cbPrintOrder.Checked = currentFlow.NeedPrintOrder;
                    OrderHead orderHead = TheOrderMgr.TransferFlow2Order(currentFlow);
                    orderHead.SubType    = this.ModuleSubType;
                    orderHead.WindowTime = DateTime.Now;

                    InitDetailParamater(orderHead);
                }
                else
                {
                    this.tbFlow.Text    = string.Empty;
                    this.ucList.Visible = false;
                }
            }
        }
        catch (BusinessErrorException ex)
        {
            this.ShowErrorMessage(ex);
        }
    }
Beispiel #2
0
 protected void tbWinTime_TextChanged(object sender, EventArgs e)
 {
     if (tbWinTime.Text.Trim() != string.Empty && tbFlow.Text.Trim() != string.Empty)
     {
         OrderHead orderHead = TheOrderMgr.TransferFlow2Order(this.tbFlow.Text.Trim());
         orderHead.SubType    = this.ModuleSubType;
         orderHead.WindowTime = DateTime.Parse(tbWinTime.Text.Trim());
         InitDetailParamater(orderHead);
     }
 }
Beispiel #3
0
    public override void UpdateView()
    {
        List <OrderLocationTransaction> orderLocationTransactionInList  = new List <OrderLocationTransaction>();
        List <OrderLocationTransaction> orderLocationTransactionOutList = new List <OrderLocationTransaction>();

        try
        {
            OrderHead orderHead = TheOrderMgr.TransferFlow2Order(this.FlowCode, true);
            if (orderHead.OrderDetails != null)
            {
                foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                {
                    if (orderDetail.OrderLocationTransactions != null)
                    {
                        foreach (OrderLocationTransaction orderLocationTransaction in orderDetail.OrderLocationTransactions)
                        {
                            if (orderLocationTransaction.IOType == BusinessConstants.IO_TYPE_IN)
                            {
                                orderLocationTransactionInList.Add(orderLocationTransaction);
                            }
                            else if (
                                orderLocationTransaction.IOType == BusinessConstants.IO_TYPE_OUT)
                            {
                                orderLocationTransactionOutList.Add(orderLocationTransaction);
                            }
                        }
                    }
                }
            }
            if (this.IOType == BusinessConstants.IO_TYPE_IN)
            {
                this.GV_List.DataSource = orderLocationTransactionInList;

                this.Parent.Visible = orderLocationTransactionInList.Count == 0 ? false : true;
            }
            else if (this.IOType == BusinessConstants.IO_TYPE_OUT)
            {
                this.GV_List.DataSource         = orderLocationTransactionOutList;
                this.GV_List.Columns[6].Visible = false;
                this.Parent.Visible             = orderLocationTransactionOutList.Count == 0 ? false : true;
            }
            this.GV_List.DataBind();
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
    }
Beispiel #4
0
    protected void tbFlow_TextChanged(Object sender, EventArgs e)
    {
        try
        {
            this.ucList.Visible   = false;
            this.tbWinTime.Text   = string.Empty;
            this.tbStartTime.Text = string.Empty;
            if (this.CurrentFlowCode == null || this.CurrentFlowCode != this.tbFlow.Text)
            {
                Flow currentFlow = TheFlowMgr.LoadFlow(tbFlow.Text, this.CurrentUser.Code, true, this.ModuleType);
                if (currentFlow != null)
                {
                    this.CurrentFlowCode = currentFlow.Code;

                    this.cbReleaseOrder.Checked = currentFlow.IsAutoRelease;
                    this.cbPrintOrder.Checked   = currentFlow.NeedPrintOrder;

                    OrderHead orderHead = TheOrderMgr.TransferFlow2Order(currentFlow);
                    orderHead.SubType    = this.ModuleSubType;
                    orderHead.WindowTime = DateTime.Now;

                    this.ucList.InitPageParameter(orderHead);
                    this.ucList.Visible = true;
                    this.ucList.CleanPrice();
                    this.ucHuList.Visible = false;

                    this.hfLeadTime.Value = currentFlow.LeadTime.ToString();
                    this.hfEmTime.Value   = currentFlow.EmTime.ToString();

                    //  InitDetailParamater(orderHead);

                    this.BindShift();
                }
                else
                {
                    this.tbFlow.Text    = string.Empty;
                    this.ucList.Visible = false;
                }
            }
        }
        catch (BusinessErrorException ex)
        {
            this.ShowErrorMessage(ex);
        }
    }
Beispiel #5
0
    private IList <OrderHead> GetList()
    {
        IList <OrderHead> orderHeadList = new List <OrderHead>();

        foreach (GridViewRow gvr in GV_List.Rows)
        {
            string    flowCode   = ((Label)gvr.FindControl("lblFlow")).Text;
            DateTime  startTime  = DateTime.Parse(((TextBox)gvr.FindControl("tbStartTime")).Text);
            DateTime  windowTime = DateTime.Parse(((TextBox)gvr.FindControl("tbWindowTime")).Text);
            string    refOrderNo = ((HiddenField)gvr.FindControl("tbRefOrderNo")).Value;//客户参考订单号
            OrderHead oh         = new OrderHead();
            oh                  = TheOrderMgr.TransferFlow2Order(flowCode);
            oh.Priority         = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
            oh.StartTime        = startTime;
            oh.WindowTime       = windowTime;
            oh.ReferenceOrderNo = refOrderNo;
            this.GetDetailControl(gvr).CollectData(oh);
            OrderHelper.FilterZeroOrderQty(oh);
            orderHeadList.Add(oh);
        }
        return(orderHeadList);
    }
Beispiel #6
0
    private void SaveRender(object sender, EventArgs e)
    {
        if (this.cvStartTime.IsValid || this.IsReject)
        {
            IList <OrderDetail> resultOrderDetailList = new List <OrderDetail>();
            OrderHead           orderHead             = CloneHelper.DeepClone <OrderHead>((OrderHead)sender); //Clone:避免修改List Page的TheOrder,导致出错

            if (orderHead != null && orderHead.OrderDetails != null && orderHead.OrderDetails.Count > 0)
            {
                foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                {
                    if (orderDetail.OrderedQty != 0)
                    {
                        if (orderDetail.Item.Type == BusinessConstants.CODE_MASTER_ITEM_TYPE_VALUE_K)
                        {
                            IList <Item>    newItemList = new List <Item>(); //填充套件子件
                            decimal?        convertRate = null;
                            IList <ItemKit> itemKitList = null;

                            var maxSequence = orderHead.OrderDetails.Max(o => o.Sequence);
                            itemKitList = this.TheItemKitMgr.GetChildItemKit(orderDetail.Item);
                            for (int i = 0; i < itemKitList.Count; i++)
                            {
                                Item item = itemKitList[i].ChildItem;
                                if (!convertRate.HasValue)
                                {
                                    if (itemKitList[i].ParentItem.Uom.Code != orderDetail.Item.Uom.Code)
                                    {
                                        convertRate = this.TheUomConversionMgr.ConvertUomQty(orderDetail.Item, orderDetail.Item.Uom, 1, itemKitList[i].ParentItem.Uom);
                                    }
                                    else
                                    {
                                        convertRate = 1;
                                    }
                                }
                                OrderDetail newOrderDetail = new OrderDetail();

                                newOrderDetail.OrderHead     = orderDetail.OrderHead;
                                newOrderDetail.Sequence      = maxSequence + (i + 1);
                                newOrderDetail.IsBlankDetail = false;
                                newOrderDetail.Item          = item;



                                newOrderDetail.Uom         = item.Uom;
                                newOrderDetail.UnitCount   = orderDetail.Item.UnitCount * itemKitList[i].Qty * convertRate.Value;
                                newOrderDetail.OrderedQty  = orderDetail.OrderedQty * itemKitList[i].Qty * convertRate.Value;
                                newOrderDetail.PackageType = orderDetail.PackageType;

                                #region 价格字段

                                if (this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
                                {
                                    if (orderDetail.PriceListFrom != null && orderDetail.PriceListFrom.Code != string.Empty)
                                    {
                                        newOrderDetail.PriceListFrom = ThePurchasePriceListMgr.LoadPurchasePriceList(orderDetail.PriceListFrom.Code);

                                        if (newOrderDetail.PriceListFrom != null)
                                        {
                                            newOrderDetail.PriceListDetailFrom = this.ThePriceListDetailMgr.GetLastestPriceListDetail(newOrderDetail.PriceListFrom, item, DateTime.Now, newOrderDetail.OrderHead.Currency, item.Uom);
                                        }
                                    }
                                }
                                else if (this.ModuleType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
                                {
                                    if (orderDetail.PriceListTo != null && orderDetail.PriceListTo.Code != string.Empty)
                                    {
                                        newOrderDetail.PriceListTo = TheSalesPriceListMgr.LoadSalesPriceList(orderDetail.PriceListTo.Code);
                                    }
                                    if (newOrderDetail.PriceListTo != null)
                                    {
                                        newOrderDetail.PriceListDetailTo = this.ThePriceListDetailMgr.GetLastestPriceListDetail(newOrderDetail.PriceListTo, item, DateTime.Now, newOrderDetail.OrderHead.Currency, item.Uom);
                                    }
                                }

                                #endregion
                                resultOrderDetailList.Add(newOrderDetail);
                            }
                        }
                        else
                        {
                            resultOrderDetailList.Add(orderDetail);
                        }
                    }
                }
            }
            if (resultOrderDetailList.Count == 0)
            {
                this.ShowErrorMessage("MasterData.Order.OrderHead.OrderDetail.Required");
                return;
            }
            else
            {
                Flow currentFlow = TheFlowMgr.LoadFlow(CurrentFlowCode, true);

                DateTime winTime   = this.tbWinTime.Text.Trim() == string.Empty ? DateTime.Now : DateTime.Parse(this.tbWinTime.Text);
                DateTime startTime = winTime;

                if (this.tbStartTime.Text != string.Empty)
                {
                    startTime = DateTime.Parse(this.tbStartTime.Text.Trim());
                }
                else
                {
                    double leadTime = this.hfLeadTime.Value == string.Empty ? 0 : double.Parse(this.hfLeadTime.Value);
                    double emTime   = this.hfEmTime.Value == string.Empty ? 0 : double.Parse(this.hfEmTime.Value);
                    double lTime    = this.cbIsUrgent.Checked ? emTime : leadTime;
                    startTime = winTime.AddHours(0 - lTime);
                }

                orderHead.OrderDetails  = resultOrderDetailList;
                orderHead.WindowTime    = winTime;
                orderHead.StartTime     = startTime;
                orderHead.IsAutoRelease = this.cbReleaseOrder.Checked;

                orderHead.IsNewItem = this.NewItem;
                if (this.cbIsUrgent.Checked)
                {
                    orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_URGENT;
                }
                else
                {
                    orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
                }
                if (this.tbRefOrderNo.Text.Trim() != string.Empty)
                {
                    orderHead.ReferenceOrderNo = this.tbRefOrderNo.Text.Trim();
                }
                if (this.tbExtOrderNo.Text.Trim() != string.Empty)
                {
                    orderHead.ExternalOrderNo = this.tbExtOrderNo.Text.Trim();
                }
            }

            //创建订单
            try
            {
                if (this.IsQuick)
                {
                    Receipt receipt = TheOrderMgr.QuickReceiveOrder(orderHead.Flow, orderHead.OrderDetails, this.CurrentUser.Code, this.ModuleSubType, orderHead.WindowTime, orderHead.StartTime, this.cbIsUrgent.Checked, orderHead.ReferenceOrderNo, orderHead.ExternalOrderNo);
                    if (receipt.ReceiptDetails != null && receipt.ReceiptDetails.Count > 0)
                    {
                        orderHead = receipt.ReceiptDetails[0].OrderLocationTransaction.OrderDetail.OrderHead;
                        if (this.cbPrintOrder.Checked)
                        {
                            IList <OrderDetail> orderDetails = orderHead.OrderDetails;
                            IList <object>      list         = new List <object>();
                            list.Add(orderHead);
                            list.Add(orderDetails);

                            IList <OrderLocationTransaction> orderLocationTransactions = TheOrderLocationTransactionMgr.GetOrderLocationTransaction(orderHead.OrderNo);
                            list.Add(orderLocationTransactions);

                            //TheReportProductionMgr.FillValues(orderHead.OrderTemplate, list);
                            string printUrl = TheReportMgr.WriteToFile(orderHead.OrderTemplate, list);

                            Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + printUrl + "'); </script>");
                        }
                    }
                    this.ShowSuccessMessage("Receipt.Receive.Successfully", receipt.ReceiptNo);

                    if (!this.cbContinuousCreate.Checked)
                    {
                        this.PageCleanup();
                        if (QuickCreateEvent != null)
                        {
                            QuickCreateEvent(new Object[] { receipt, orderHead.NeedPrintReceipt }, e);
                        }
                    }
                    else
                    {
                        orderHead = TheOrderMgr.TransferFlow2Order(this.tbFlow.Text.Trim());
                        InitDetailParamater(orderHead);
                    }
                }
                else
                {
                    TheOrderMgr.CreateOrder(orderHead, this.CurrentUser);
                    if (this.cbPrintOrder.Checked)
                    {
                        IList <OrderDetail> orderDetails = orderHead.OrderDetails;
                        IList <object>      list         = new List <object>();
                        list.Add(orderHead);
                        list.Add(orderDetails);

                        IList <OrderLocationTransaction> orderLocationTransactions = TheOrderLocationTransactionMgr.GetOrderLocationTransaction(orderHead.OrderNo);
                        list.Add(orderLocationTransactions);

                        //TheReportProductionMgr.FillValues(orderHead.OrderTemplate, list);
                        string printUrl = TheReportMgr.WriteToFile(orderHead.OrderTemplate, list);

                        Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + printUrl + "'); </script>");
                    }
                    this.ShowSuccessMessage("MasterData.Order.OrderHead.AddOrder.Successfully", orderHead.OrderNo);
                    if (!this.cbContinuousCreate.Checked)
                    {
                        this.PageCleanup();
                        if (CreateEvent != null)
                        {
                            CreateEvent(orderHead.OrderNo, e);
                        }
                    }
                    else
                    {
                        orderHead = TheOrderMgr.TransferFlow2Order(this.tbFlow.Text.Trim());
                        InitDetailParamater(orderHead);
                    }
                }
            }
            catch (BusinessErrorException ex)
            {
                this.ShowErrorMessage(ex);
                return;
            }
        }
    }
Beispiel #7
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            HSSFWorkbook excel = new HSSFWorkbook(fileUpload.PostedFile.InputStream);
            Sheet        sheet = excel.GetSheetAt(0);
            IEnumerator  rows  = sheet.GetRowEnumerator();
            ImportHelper.JumpRows(rows, 10);
            //供货路线	窗口时间	物料号	订单数

            #region 列定义
            int colFlow       = 1; //供货路线
            int colWindowTime = 2; //窗口时间
            int colItem       = 3; // 物料号
            int colQty        = 4; //订单数
            #endregion
            int rowCount = 10;
            //IList<Exception> exceptionList = new List<Exception>();
            //Exception exceptio = new Exception();
            string            errorMessage  = string.Empty;
            IList <OrderHead> orderHeadList = new List <OrderHead>();
            while (rows.MoveNext())
            {
                rowCount++;
                HSSFRow row = (HSSFRow)rows.Current;
                if (!TheImportMgr.CheckValidDataRow(row, 1, 4))
                {
                    break;//边界
                }
                string    flowCode    = string.Empty;
                DateTime  windowTime  = DateTime.Now;
                string    itemCode    = string.Empty;
                decimal   qty         = 0;
                OrderHead orderHead   = new OrderHead();
                Flow      currentFlow = new Flow();

                #region 读取数据
                #region 供货路线
                flowCode = row.GetCell(colFlow) != null?row.GetCell(colFlow).StringCellValue : string.Empty;

                if (string.IsNullOrEmpty(flowCode))
                {
                    //ShowErrorMessage(string.Format("第{0}行:供货路线不能为空。", rowCount));
                    errorMessage += string.Format("第{0}行:供货路线不能为空。<br/>", rowCount);
                    continue;
                }
                else
                {
                    currentFlow = TheFlowMgr.LoadFlow(flowCode, this.CurrentUser.Code, true);
                }
                #endregion

                #region 读取窗口时间
                try
                {
                    string readwindowTime = row.GetCell(colWindowTime).StringCellValue;
                    if (DateTime.TryParse(readwindowTime, out windowTime))
                    {
                        orderHead.WindowTime = windowTime;
                    }
                    else
                    {
                        errorMessage += string.Format("第{0}行:窗口时间填写有误。<br/>", rowCount);
                        continue;
                    }
                }
                catch
                {
                    errorMessage += string.Format("第{0}行:窗口时间填写有误。<br/>", rowCount);
                    //ShowErrorMessage(string.Format("第{0}行:窗口时间填写有误。", rowCount));
                    continue;
                }
                #endregion

                #region 读取物料代码
                itemCode = row.GetCell(colItem) != null?row.GetCell(colItem).StringCellValue : string.Empty;

                if (itemCode == null || itemCode.Trim() == string.Empty)
                {
                    errorMessage += string.Format("第{0}行:物料代码不能为空。<br/>", rowCount);
                    //ShowErrorMessage(string.Format("第{0}行:物料代码不能为空。", rowCount));
                    continue;
                }
                else
                {
                    currentFlow.FlowDetails = currentFlow.FlowDetails.Where(f => f.Item.Code == itemCode).ToList();
                    if (currentFlow.FlowDetails.Count == 0)
                    {
                        errorMessage += string.Format("第{0}行:物料代码{1}在路线{2}中不存在。<br/>", rowCount, itemCode, flowCode);
                        continue;
                    }
                }

                #endregion

                #region 读取数量
                try
                {
                    qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue);
                }
                catch
                {
                    //ShowErrorMessage(string.Format("第{0}行:订单数量填写有误。<br/>", rowCount));
                    errorMessage += string.Format("第{0}行:订单数量填写有误。<br/>", rowCount);
                    continue;
                }
                #endregion
                #endregion

                #region 填充数据
                orderHead            = TheOrderMgr.TransferFlow2Order(currentFlow);
                orderHead.SubType    = "Nml";
                orderHead.WindowTime = windowTime;
                orderHead.Priority   = "Normal";
                //orderHead.Type = "Procurement";
                orderHead.StartTime     = System.DateTime.Now;
                orderHead.IsAutoRelease = true;
                foreach (OrderDetail det in orderHead.OrderDetails)
                {
                    det.RequiredQty = qty;
                    det.OrderedQty  = qty;
                }
                orderHeadList.Add(orderHead);
                #endregion
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new Exception(errorMessage);
            }
            if (orderHeadList.Count == 0)
            {
                throw new Exception("导入的有效数据为0.");
            }
            var groups = (from tak in orderHeadList
                          group tak by new
            {
                tak.WindowTime,
                tak.Flow,
            }
                          into result
                          select new
            {
                WindowTime = result.Key.WindowTime,
                Flow = result.Key.Flow,
                list = result.ToList()
            }
                          ).ToList();
            string orderNos = "导入成功,生成单号:";
            foreach (var order in groups)
            {
                OrderHead           newOrderHead = order.list.First();
                IList <OrderDetail> detList      = new List <OrderDetail>();
                //OrderHead newOrderHead = new OrderHead();
                foreach (var d in order.list)
                {
                    OrderDetail det = d.OrderDetails.First();
                    det.OrderHead = newOrderHead;
                    detList.Add(det);
                }
                newOrderHead.OrderDetails = detList;
                CreateOrder(newOrderHead);
                orderNos += newOrderHead.OrderNo + ",";
            }
            ShowSuccessMessage(orderNos);
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
        catch (Exception ex)
        {
            ShowErrorMessage(ex.Message);
            return;
        }
    }
Beispiel #8
0
    private void SaveRender(object sender, EventArgs e)
    {
        if (this.cvStartTime.IsValid)
        {
            IList <OrderDetail> resultOrderDetailList = new List <OrderDetail>();
            OrderHead           orderHead             = CloneHelper.DeepClone <OrderHead>((OrderHead)sender); //Clone:避免修改List Page的TheOrder,导致出错

            if (orderHead != null && orderHead.OrderDetails != null && orderHead.OrderDetails.Count > 0)
            {
                foreach (OrderDetail orderDetail in orderHead.OrderDetails)
                {
                    if (orderDetail.OrderedQty != 0)
                    {
                        resultOrderDetailList.Add(orderDetail);
                    }
                }
            }

            if (resultOrderDetailList.Count == 0)
            {
                this.ShowErrorMessage("MasterData.Order.OrderHead.OrderDetail.Required");
                return;
            }
            else
            {
                Flow     currentFlow = TheFlowMgr.LoadFlow(CurrentFlowCode, true);
                DateTime winTime     = DateTime.Parse(this.tbWinTime.Text);
                DateTime startTime   = DateTime.Parse(this.tbWinTime.Text);
                string   shiftCode   = this.ucShift.ShiftCode;

                if (this.tbStartTime.Text != string.Empty)
                {
                    startTime = DateTime.Parse(this.tbStartTime.Text.Trim());
                }
                else
                {
                    double leadTime = this.hfLeadTime.Value == string.Empty ? 0 : double.Parse(this.hfLeadTime.Value);
                    double emTime   = this.hfEmTime.Value == string.Empty ? 0 : double.Parse(this.hfEmTime.Value);
                    double lTime    = this.cbIsUrgent.Checked ? emTime : leadTime;
                    startTime = winTime.AddHours(0 - lTime);
                }

                orderHead.OrderDetails  = resultOrderDetailList;
                orderHead.WindowTime    = winTime;
                orderHead.StartTime     = startTime;
                orderHead.IsAutoRelease = this.cbReleaseOrder.Checked;
                orderHead.IsNewItem     = this.NewItem;
                if (this.ucShift.ShiftCode != string.Empty)
                {
                    orderHead.Shift = TheShiftMgr.LoadShift(this.ucShift.ShiftCode);
                }
                if (this.cbIsUrgent.Checked)
                {
                    orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_URGENT;
                }
                else
                {
                    orderHead.Priority = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
                }
                if (this.tbRefOrderNo.Text.Trim() != string.Empty)
                {
                    orderHead.ReferenceOrderNo = this.tbRefOrderNo.Text.Trim();
                }
                if (this.tbExtOrderNo.Text.Trim() != string.Empty)
                {
                    orderHead.ExternalOrderNo = this.tbExtOrderNo.Text.Trim();
                }

                if (this.IsQuick)
                {
                    orderHead.IsAutoRelease   = true;
                    orderHead.IsAutoStart     = true;
                    orderHead.IsAutoShip      = true;
                    orderHead.IsAutoReceive   = true;
                    orderHead.StartLatency    = 0;
                    orderHead.CompleteLatency = 0;
                }
                if (orderHead.ReferenceOrderNo != null && orderHead.ReferenceOrderNo != string.Empty)
                {
                    orderHead.IsAdditional = true;
                }
            }

            //创建订单
            try
            {
                //if (this.IsQuick)
                //{
                //    Receipt receipt = TheOrderMgr.QuickReceiveOrder(orderHead.Flow, orderHead.OrderDetails, this.CurrentUser, this.ModuleSubType, orderHead.WindowTime, orderHead.StartTime, this.cbIsUrgent.Checked, orderHead.ReferenceOrderNo, orderHead.ExternalOrderNo);

                //    if (receipt.ReceiptDetails != null && receipt.ReceiptDetails.Count > 0)
                //    {
                //        orderHead = receipt.ReceiptDetails[0].OrderLocationTransaction.OrderDetail.OrderHead;
                //        if (this.cbPrintOrder.Checked)
                //        {
                //            IList<OrderDetail> orderDetails = orderHead.OrderDetails;
                //            IList<object> list = new List<object>();
                //            list.Add(orderHead);
                //            list.Add(orderDetails);

                //            IList<OrderLocationTransaction> orderLocationTransactions = TheOrderLocationTransactionMgr.GetOrderLocationTransaction(orderHead.OrderNo);
                //            list.Add(orderLocationTransactions);

                //              //TheReportProductionMgr.FillValues(orderHead.OrderTemplate, list);
                //              string printUrl = TheReportMgr.WriteToFile(orderHead.OrderTemplate, list);

                //            Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + printUrl + "'); </script>");
                //        }
                //    }
                //    this.ShowSuccessMessage("Receipt.Receive.Successfully", receipt.ReceiptNo);
                //    this.PageCleanup();
                //    if (!this.cbContinuousCreate.Checked)
                //    {
                //        if (QuickCreateEvent != null)
                //        {
                //            QuickCreateEvent(new Object[] { receipt, orderHead.NeedPrintReceipt }, e);
                //        }

                //    }
                //}
                //else
                //{
                TheOrderMgr.CreateOrder(orderHead, this.CurrentUser);
                if (this.cbPrintOrder.Checked)
                {
                    IList <OrderDetail> orderDetails = orderHead.OrderDetails;
                    IList <object>      list         = new List <object>();
                    list.Add(orderHead);
                    list.Add(orderDetails);

                    IList <OrderLocationTransaction> orderLocationTransactions = TheOrderLocationTransactionMgr.GetOrderLocationTransaction(orderHead.OrderNo);
                    list.Add(orderLocationTransactions);

                    //TheReportProductionMgr.FillValues(orderHead.OrderTemplate, list);
                    string printUrl = TheReportMgr.WriteToFile(orderHead.OrderTemplate, list);

                    Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + printUrl + "'); </script>");
                }
                this.ShowSuccessMessage("MasterData.Order.OrderHead.AddOrder.Successfully", orderHead.OrderNo);
                if (!this.cbContinuousCreate.Checked)
                {
                    this.PageCleanup();
                    if (CreateEvent != null)
                    {
                        CreateEvent(orderHead.OrderNo, e);
                    }
                }
                else
                {
                    orderHead = TheOrderMgr.TransferFlow2Order(this.tbFlow.Text.Trim());
                    this.ucList.InitPageParameter(orderHead);
                }

                //}
            }
            catch (BusinessErrorException ex)
            {
                this.ShowErrorMessage(ex);
                return;
            }
        }
    }
Beispiel #9
0
    private void SaveRender(object sender, EventArgs e)
    {
        IList <OrderDetail> resultOrderDetailList = new List <OrderDetail>();
        OrderHead           orderHead             = CloneHelper.DeepClone <OrderHead>((OrderHead)sender); //Clone:避免修改List Page的TheOrder,导致出错

        if (orderHead != null && orderHead.OrderDetails != null && orderHead.OrderDetails.Count > 0)
        {
            foreach (OrderDetail orderDetail in orderHead.OrderDetails)
            {
                if (orderDetail.OrderedQty != 0)
                {
                    resultOrderDetailList.Add(orderDetail);
                }
            }
        }

        if (resultOrderDetailList.Count == 0)
        {
            this.ShowErrorMessage("MasterData.Order.OrderHead.OrderDetail.Required");
            return;
        }

        //创建订单
        try
        {
            Receipt receipt = TheOrderMgr.QuickReceiveOrder(this.CurrentFlowCode, resultOrderDetailList, this.CurrentUser.Code, BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML, DateTime.Now, DateTime.Now, true, null, null);

            if (receipt.ReceiptDetails != null && receipt.ReceiptDetails.Count > 0)
            {
                orderHead = receipt.ReceiptDetails[0].OrderLocationTransaction.OrderDetail.OrderHead;
                if (this.cbPrintOrder.Checked)
                {
                    IList <OrderDetail> orderDetails = orderHead.OrderDetails;
                    IList <object>      list         = new List <object>();
                    list.Add(orderHead);
                    list.Add(orderDetails);

                    IList <OrderLocationTransaction> orderLocationTransactions = TheOrderLocationTransactionMgr.GetOrderLocationTransaction(orderHead.OrderNo);
                    list.Add(orderLocationTransactions);

                    //TheReportProductionMgr.FillValues(orderHead.OrderTemplate,list);
                    string printUrl = TheReportMgr.WriteToFile(orderHead.OrderTemplate, list);

                    Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + printUrl + "'); </script>");
                }
            }
            this.ShowSuccessMessage("MasterData.Order.OrderHead.Transfer.AddOrder.Successfully");


            if (!this.cbContinuousCreate.Checked)
            {
                this.PageCleanup();
                if (CreateEvent != null)
                {
                    CreateEvent(new Object[] { receipt, orderHead.NeedPrintReceipt }, e);
                }
            }
            else
            {
                orderHead = TheOrderMgr.TransferFlow2Order(this.tbFlow.Text.Trim());
                InitDetailParamater(orderHead);
            }
        }
        catch (BusinessErrorException ex)
        {
            this.ShowErrorMessage(ex);
            return;
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        try
        {
            HSSFWorkbook excel = new HSSFWorkbook(fileUpload.PostedFile.InputStream);
            Sheet        sheet = excel.GetSheetAt(0);
            IEnumerator  rows  = sheet.GetRowEnumerator();
            ImportHelper.JumpRows(rows, 10);
            //发货路线	窗口时间 外部订单号 参考订单号 物料号	订单数

            #region 列定义
            int colFlow       = 1; //发货路线
            int colExtOrderNo = 2; //外部订单号
            int colItem       = 3; // 物料号
            int colQty        = 4; //订单数
            #endregion
            int rowCount = 10;
            //IList<Exception> exceptionList = new List<Exception>();
            //Exception exceptio = new Exception();
            string            errorMessage  = string.Empty;
            IList <OrderHead> orderHeadList = new List <OrderHead>();
            while (rows.MoveNext())
            {
                rowCount++;
                HSSFRow row = (HSSFRow)rows.Current;
                if (!TheImportMgr.CheckValidDataRow(row, 1, 4))
                {
                    break;//边界
                }
                string    flowCode    = string.Empty;
                string    extOrderNo  = string.Empty;
                string    itemCode    = string.Empty;
                decimal   qty         = 0;
                OrderHead orderHead   = new OrderHead();
                Flow      currentFlow = new Flow();

                #region 读取数据
                #region 发货路线
                flowCode = row.GetCell(colFlow) != null?row.GetCell(colFlow).StringCellValue : string.Empty;

                if (string.IsNullOrEmpty(flowCode))
                {
                    errorMessage += string.Format("第{0}行:发货路线不能为空。<br/>", rowCount);
                    continue;
                }
                else
                {
                    currentFlow = TheFlowMgr.LoadFlow(flowCode, this.CurrentUser.Code, true);
                }
                #endregion

                #region 读取窗口时间
                //try
                //{
                //    string readwindowTime = row.GetCell(colWindowTime).StringCellValue;
                //    if (DateTime.TryParse(readwindowTime, out windowTime))
                //    {
                //        orderHead.WindowTime = windowTime;
                //    }
                //    else
                //    {
                //        errorMessage += string.Format("第{0}行:窗口时间填写有误。<br/>", rowCount);
                //        continue;
                //    }
                //}
                //catch
                //{
                //    errorMessage += string.Format("第{0}行:窗口时间填写有误。<br/>", rowCount);
                //    continue;
                //}
                #endregion

                extOrderNo = row.GetCell(colExtOrderNo) != null?row.GetCell(colExtOrderNo).StringCellValue : string.Empty;

                //refOrderNo = row.GetCell(colRefOrderNo) != null ? row.GetCell(colRefOrderNo).StringCellValue : string.Empty;

                #region 读取物料代码
                itemCode = row.GetCell(colItem) != null?row.GetCell(colItem).StringCellValue : string.Empty;

                if (itemCode == null || itemCode.Trim() == string.Empty)
                {
                    errorMessage += string.Format("第{0}行:物料代码不能为空。<br/>", rowCount);
                    //ShowErrorMessage(string.Format("第{0}行:物料代码不能为空。", rowCount));
                    continue;
                }
                else
                {
                    currentFlow.FlowDetails = currentFlow.FlowDetails.Where(f => f.Item.Code == itemCode).ToList();
                    if (currentFlow.FlowDetails.Count == 0)
                    {
                        errorMessage += string.Format("第{0}行:物料代码{1}在路线{2}中不存在。<br/>", rowCount, itemCode, flowCode);
                        continue;
                    }
                }

                #endregion

                #region 读取数量
                try
                {
                    qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue);
                }
                catch
                {
                    //ShowErrorMessage(string.Format("第{0}行:订单数量填写有误。<br/>", rowCount));
                    errorMessage += string.Format("第{0}行:订单数量填写有误。<br/>", rowCount);
                    continue;
                }
                #endregion
                #endregion

                #region 填充数据
                orderHead                 = TheOrderMgr.TransferFlow2Order(currentFlow);
                orderHead.SubType         = this.ModuleSubType;
                orderHead.WindowTime      = System.DateTime.Now;
                orderHead.Priority        = "Normal";
                orderHead.Type            = this.ModuleType;
                orderHead.StartTime       = System.DateTime.Now;
                orderHead.ExternalOrderNo = extOrderNo;
                //orderHead.ReferenceOrderNo = refOrderNo;
                orderHead.IsAutoRelease   = true;
                orderHead.IsAutoStart     = true;
                orderHead.IsAutoShip      = true;
                orderHead.IsAutoReceive   = true;
                orderHead.StartLatency    = 0;
                orderHead.CompleteLatency = 0;
                foreach (OrderDetail det in orderHead.OrderDetails)
                {
                    det.RequiredQty = qty;
                    det.OrderedQty  = qty;
                }
                orderHeadList.Add(orderHead);
                #endregion
            }
            if (!string.IsNullOrEmpty(errorMessage))
            {
                throw new Exception(errorMessage);
            }
            if (orderHeadList.Count == 0)
            {
                throw new Exception("导入的有效数据为0.");
            }
            string successMessage = TheOrderMgr.QuickImportDistributionOrder(orderHeadList, this.CurrentUser.Code, this.ModuleSubType);
            ShowSuccessMessage(successMessage);
            //var groups = (from tak in orderHeadList
            //              group tak by new
            //              {
            //                  tak.Flow,
            //                  tak.ExternalOrderNo,
            //              }
            //                  into result
            //                  select new
            //                  {
            //                      Flow = result.Key.Flow,
            //                      ExternalOrderNo = result.Key.ExternalOrderNo,
            //                      list = result.ToList()
            //                  }
            //               ).ToList();
            //string orderNos = "导入成功,生成送货单号:";
            //foreach (var order in groups)
            //{
            //    OrderHead newOrderHead = order.list.First();
            //    IList<OrderDetail> detList = new List<OrderDetail>();
            //    //OrderHead newOrderHead = new OrderHead();
            //    foreach (var d in order.list)
            //    {
            //        OrderDetail det = d.OrderDetails.First();
            //        det.OrderHead = newOrderHead;
            //        detList.Add(det);
            //    }
            //    newOrderHead.OrderDetails = detList;

            //    orderNos += CreateOrder(newOrderHead);
            //}
            //ShowSuccessMessage(orderNos);
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
        catch (Exception ex)
        {
            ShowErrorMessage(ex.Message);
            return;
        }
    }