Example #1
0
    public void GetView(string searchSql)
    {
        allList = new List <EDIFordPlan>();
        IList <EDIFordPlan> eDIFordPlanList = TheGenericMgr.FindAllWithCustomQuery <EDIFordPlan>(searchSql);

        if (eDIFordPlanList != null && eDIFordPlanList.Count > 0)
        {
            IList <FlowDetail> flowdets = TheGenericMgr.FindAllWithCustomQuery <FlowDetail>(string.Format(" select d from FlowDetail as d where  d.ReferenceItemCode in('{0}') ", string.Join("','", eDIFordPlanList.Select(w => w.RefItem).Distinct().ToArray())));

            control_num = eDIFordPlanList.First().Control_Num;
            var groups = (from tak in eDIFordPlanList
                          group tak by new
            {
                tak.Control_Num,
                tak.RefItem
            }
                          into result
                          select new
            {
                RefItem = result.Key.RefItem,
                Control_Num = result.Key.Control_Num,
                List = result.ToList()
            }).ToList();

            forecastDateList = groups.First().List.OrderBy(g => g.ForecastDate).Select(g => g.ForecastDate).ToList();

            foreach (var g in groups)
            {
                EDIFordPlan newPlan = g.List.First();
                Dictionary <DateTime, decimal[]> planDateDic = new Dictionary <DateTime, decimal[]>();
                List <decimal[]> planQtyArr = new List <decimal[]>();
                foreach (var f in g.List)
                {
                    //forecastDateList.Add(f.ForecastDate);
                    decimal[] dicArr = new decimal[] { f.ForecastQty > 0?f.ForecastQty:0, f.ForecastCumQty > 0?f.ForecastCumQty:0 };
                    planQtyArr.Add(dicArr);
                }
                newPlan.PlanQtyArr = planQtyArr;
                if (flowdets != null && flowdets.Count > 0)
                {
                    var flowDet = flowdets.Where(f => f.ReferenceItemCode == newPlan.RefItem);
                    if (flowDet != null && flowDet.Count() > 0)
                    {
                        newPlan.Item     = flowDet.First().Item.Code;
                        newPlan.ItemDesc = flowDet.First().Item.Description;
                    }
                }
                allList.Add(newPlan);
            }
            totalItem = allList.Count;
        }
    }
Example #2
0
    public void GetView(string searchSql)
    {
        CurrenPage = 1;
        totalItem  = 0;
        allList    = new List <EDIFordPlan>();
        returnList = new List <EDIFordPlan>();
        IList <EDIFordPlan> eDIFordPlanList = TheGenericMgr.FindAllWithCustomQuery <EDIFordPlan>(searchSql);

        //IList<EDIFordPlan> getList = new List<EDIFordPlan>(); ;

        if (eDIFordPlanList != null && eDIFordPlanList.Count > 0)
        {
            string control_Num = string.Empty;
            var    groups      = (from tak in eDIFordPlanList
                                  group tak by new
            {
                tak.Control_Num,
            }
                                  into result
                                  select new
            {
                Control_Num = result.Key.Control_Num,
                List = result.ToList()
            }).ToList();

            foreach (var g in groups)
            {
                EDIFordPlan newPlan = g.List.First();
                newPlan.PlanDateString = g.List.Min(s => s.ForecastDate).ToShortDateString() + "~~" + g.List.Max(s => s.ForecastDate).ToShortDateString();
                allList.Add(newPlan);
            }
            totalItem     = allList.Count;
            currentItem01 = (CurrenPage - 1) * 10 + 1;
            currentItem02 = CurrenPage * 10 > totalItem ? totalItem : CurrenPage * 10;
            returnList    = allList.Skip((CurrenPage - 1) * 10).Take(10).ToList();
            isMaxPage     = currentItem02 == totalItem;
            isMinPage     = currentItem01 == 1;
        }
    }
    public override void UpdateView()
    {
        List <EDIFordPlan> returnList = new List <EDIFordPlan>();
        string             flowCode   = this.tbFlow.Text.Trim();
        Flow currentFlow = null;

        if (!string.IsNullOrEmpty(flowCode))
        {
            currentFlow = TheFlowMgr.LoadFlow(flowCode, this.CurrentUser.Code, true);
            if (currentFlow != null && currentFlow.FlowDetails != null && currentFlow.FlowDetails.Count > 0)
            {
                if (!string.IsNullOrEmpty(currentFlow.SupplierCodes))
                {
                    foreach (var supplierCode in currentFlow.SupplierCodes.Split(','))
                    {
                        this.SupplierCodeSelect.Items.Add(new ListItem(supplierCode, supplierCode));
                    }
                }
                else
                {
                    ShowErrorMessage("请维护发货路线的发货工厂。");
                }
                if (!string.IsNullOrEmpty(currentFlow.CustomerCodes))
                {
                    foreach (var customerCode in currentFlow.CustomerCodes.Split(','))
                    {
                        this.CustomerCodeSelect.Items.Add(new ListItem(customerCode, customerCode));
                    }
                }
                else
                {
                    ShowErrorMessage("请维护发货路线的收货工厂。");
                }
                foreach (var f in currentFlow.FlowDetails)
                {
                    EDIFordPlan r = new EDIFordPlan();
                    r.Item     = f.Item.Code;
                    r.ItemDesc = f.Item.Description;
                    r.RefItem  = f.ReferenceItemCode;
                    //if (!string.IsNullOrEmpty(r.RefItem))
                    //{
                    //r.CustomerCode = "BVT8A";
                    //}
                    //r.SupplierCode = f.ShipFrom;
                    r.Uom = f.Uom.Code;
                    r.TransportationMethod = f.TransModeCode;
                    r.EquipmentNum         = f.ConveyanceNumber;
                    r.CarrierCode          = f.CarrierCode;
                    try
                    {
                        r.GrossWeight = Convert.ToDecimal(f.GrossWeight);
                    }
                    catch (Exception)
                    {
                        r.GrossWeight = 0;
                    }
                    try
                    {
                        r.NetWeight = Convert.ToDecimal(f.NetWeight);
                    }
                    catch (Exception)
                    {
                        r.NetWeight = 0;
                    }
                    r.WeightUom   = f.WeightUom;
                    r.OutPackType = f.PackagingCode;
                    r.InPackType  = f.PackagingCode;
                    try
                    {
                        r.OutPackQty = Convert.ToDecimal(f.LadingQuantity);
                    }
                    catch (Exception)
                    {
                        r.OutPackQty = 0;
                    }
                    try
                    {
                        r.PerLoadQty = Convert.ToDecimal(f.UnitsPerContainer);
                    }
                    catch (Exception)
                    {
                        r.PerLoadQty = 0;
                    }
                    returnList.Add(r);
                }
            }
        }
        this.GV_List.DataSource = returnList;
        this.GV_List.DataBind();
    }
    private List <EDIFordPlan> GetShipEDIFordPlan()
    {
        var customerCode = this.CustomerCodeSelect.Value;
        var supplierCode = this.SupplierCodeSelect.Value;

        if (string.IsNullOrEmpty(customerCode))
        {
            throw new BusinessErrorException("发货工厂不能为空。");
        }
        if (string.IsNullOrEmpty(supplierCode))
        {
            throw new BusinessErrorException("收货工厂不能为空。");
        }
        List <EDIFordPlan> eDIFordPlanList = new List <EDIFordPlan>();

        foreach (GridViewRow gvr in GV_List.Rows)
        {
            EDIFordPlan eDIFordPlan     = new EDIFordPlan();
            CheckBox    cbCheckBoxGroup = (CheckBox)gvr.FindControl("CheckBoxGroup");
            if (cbCheckBoxGroup.Checked)
            {
                eDIFordPlan.Item     = ((HiddenField)gvr.FindControl("ftItem")).Value;
                eDIFordPlan.ItemDesc = ((HiddenField)gvr.FindControl("ftItemDesc")).Value;
                eDIFordPlan.RefItem  = ((HiddenField)gvr.FindControl("ftRefItem")).Value;

                #region  收货工厂
                //if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbCustomerCode")).Text.Trim()))
                //{
                //    throw new BusinessErrorException(string.Format("物料号{0}收货工厂填写有误。", eDIFordPlan.Item));
                //}
                //else
                //{
                //    eDIFordPlan.CustomerCode = ((TextBox)gvr.FindControl("tbCustomerCode")).Text.Trim();
                //}
                eDIFordPlan.CustomerCode = customerCode;
                #endregion

                #region  发货工厂
                //if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbSupplierCode")).Text.Trim()))
                //{
                //    throw new BusinessErrorException(string.Format("物料号{0}发货工厂填写有误。", eDIFordPlan.Item));
                //}
                //else
                //{
                //    eDIFordPlan.SupplierCode = ((TextBox)gvr.FindControl("tbSupplierCode")).Text.Trim();
                //}
                eDIFordPlan.SupplierCode = supplierCode;
                #endregion

                #region  采购订单号
                //if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbPurchaseOrder")).Text.Trim()))
                //{
                //    throw new BusinessErrorException(string.Format("物料号{0}采购订单号填写有误。", eDIFordPlan.Item));
                //}
                //else
                //{
                //    eDIFordPlan.PurchaseOrder = ((TextBox)gvr.FindControl("tbPurchaseOrder")).Text.Trim();
                //}
                //售后备件发货 采购订单号 默认填写
                eDIFordPlan.PurchaseOrder = "111111";
                #endregion

                #region   中间商
                eDIFordPlan.IntermediateConsignee = ((TextBox)gvr.FindControl("tbIntermediateConsignee")).Text.Trim();
                #endregion

                #region   本次发货量
                try
                {
                    eDIFordPlan.ShipQty = decimal.Parse(((TextBox)gvr.FindControl("tbShipQty")).Text.Trim());
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}本次发货量填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   发货累计数
                try
                {
                    eDIFordPlan.CurrenCumQty = decimal.Parse(((TextBox)gvr.FindControl("tbCurrenCumQty")).Text.Trim());
                    if (eDIFordPlan.CurrenCumQty == 0)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("物料号{0}发货累计数填写有误。", eDIFordPlan.Item));
                }
                #endregion

                #region   装箱单号
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbShipmentID")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}装箱单号填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.ShipmentID = ((TextBox)gvr.FindControl("tbShipmentID")).Text.Trim();
                }
                #endregion

                #region   提单号
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbLadingNum")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}提单号填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.LadingNum = ((TextBox)gvr.FindControl("tbLadingNum")).Text.Trim();
                }
                #endregion

                #region   单位
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbInUom")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}单位填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.Uom = ((TextBox)gvr.FindControl("tbInUom")).Text.Trim();
                }
                #endregion

                eDIFordPlan.Purpose = ((System.Web.UI.HtmlControls.HtmlSelect)gvr.FindControl("tbPurpose")).Value;

                #region   发货总毛重
                try
                {
                    eDIFordPlan.GrossWeight = decimal.Parse(((TextBox)gvr.FindControl("tbGrossWeight")).Text.Trim()) * eDIFordPlan.ShipQty;
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}发货总毛重填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   发货总净重
                try
                {
                    eDIFordPlan.NetWeight = decimal.Parse(((TextBox)gvr.FindControl("tbNetWeight")).Text.Trim()) * eDIFordPlan.ShipQty;
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}发货总净重填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   毛重净重单位
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbWeightUom")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}毛重净重单位填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.WeightUom = ((TextBox)gvr.FindControl("tbWeightUom")).Text.Trim();
                }
                #endregion

                #region   外包装类型
                eDIFordPlan.OutPackType = ((TextBox)gvr.FindControl("tbOutPackType")).Text.Trim();
                #endregion

                #region   外包装数量
                try
                {
                    eDIFordPlan.OutPackQty = decimal.Parse(((TextBox)gvr.FindControl("tbOutPackQty")).Text.Trim());
                }
                catch (Exception e)
                {
                    eDIFordPlan.OutPackQty = null;
                }
                #endregion

                #region   承运商
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbCarrierCode")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}承运商填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.CarrierCode = ((TextBox)gvr.FindControl("tbCarrierCode")).Text.Trim();
                }
                #endregion

                #region   运输方式
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbTransportationMethod")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}运输方式填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.TransportationMethod = ((TextBox)gvr.FindControl("tbTransportationMethod")).Text.Trim();
                }
                #endregion

                #region   运载媒介
                eDIFordPlan.EquipmentDesc = eDIFordPlan.TransportationMethod;
                if (eDIFordPlan.TransportationMethod == "M")
                {
                    eDIFordPlan.EquipmentDesc = "TL";
                }
                else if (eDIFordPlan.TransportationMethod == "O")
                {
                    eDIFordPlan.EquipmentDesc = "CN";
                }
                else if (eDIFordPlan.TransportationMethod == "A")
                {
                    eDIFordPlan.EquipmentDesc = "AF";
                }
                //if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbEquipmentDesc")).Text.Trim()))
                //{
                //    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}运载媒介填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                //}
                //else
                //{
                //eDIFordPlan.EquipmentDesc = ((TextBox)gvr.FindControl("tbEquipmentDesc")).Text.Trim();
                // }
                #endregion

                #region   运载媒介序列号
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbEquipmentNum")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}运载媒介序列号填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.EquipmentNum = ((TextBox)gvr.FindControl("tbEquipmentNum")).Text.Trim();
                }
                #endregion

                #region   内包装类型
                eDIFordPlan.InPackType = ((TextBox)gvr.FindControl("tbOutPackType")).Text.Trim();
                #endregion

                #region   每个包装数量
                try
                {
                    eDIFordPlan.PerLoadQty = decimal.Parse(((TextBox)gvr.FindControl("tbPerLoadQty")).Text.Trim());
                    if (eDIFordPlan.PerLoadQty == 0)
                    {
                        throw new BusinessErrorException(string.Format("版本号{0}物料号{1}每个包装件数必须大于0。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                    }
                }
                catch (Exception e)
                {
                    //eDIFordPlan.PerLoadQty = null;
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}每个包装件数必须大于0。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   内包装数量
                eDIFordPlan.InPackQty = eDIFordPlan.PerLoadQty == null ? 1 : (int?)Convert.ToInt32((eDIFordPlan.ShipQty.Value % eDIFordPlan.PerLoadQty.Value == 0 ? eDIFordPlan.ShipQty.Value / eDIFordPlan.PerLoadQty.Value : Convert.ToInt32(eDIFordPlan.ShipQty.Value) / Convert.ToInt32(eDIFordPlan.PerLoadQty.Value) + 1));
                //try
                //{
                //    eDIFordPlan.InPackQty = decimal.Parse(((TextBox)gvr.FindControl("tbInPackQty")).Text.Trim());
                //}
                //catch (Exception e)
                //{
                //    eDIFordPlan.InPackQty = null;
                //}
                #endregion

                #region   机场代码
                eDIFordPlan.AirportCode = ((TextBox)gvr.FindControl("tbAirportCode")).Text.Trim();
                if (eDIFordPlan.TransportationMethod == "A")
                {
                    if (string.IsNullOrEmpty(eDIFordPlan.AirportCode))
                    {
                        throw new BusinessErrorException(string.Format("版本号{0}物料号{1},在选择空运的时候机场代码不能为空。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                    }
                }
                else
                {
                    eDIFordPlan.AirportCode = string.Empty;
                }
                #endregion

                eDIFordPlanList.Add(eDIFordPlan);
            }
        }
        return(eDIFordPlanList);
    }
Example #5
0
    private List <EDIFordPlan> GetShipEDIFordPlan()
    {
        List <EDIFordPlan> eDIFordPlanList = new List <EDIFordPlan>();

        foreach (GridViewRow gvr in GV_List.Rows)
        {
            EDIFordPlan eDIFordPlan     = new EDIFordPlan();
            CheckBox    cbCheckBoxGroup = (CheckBox)gvr.FindControl("CheckBoxGroup");
            if (cbCheckBoxGroup.Checked)
            {
                int id = int.Parse(((HiddenField)gvr.FindControl("ftId")).Value);
                eDIFordPlan = TheGenericMgr.FindAllWithCustomQuery <EDIFordPlan>(" select e from EDIFordPlan as e where Id=? ", id).First();

                string itemCode = ((HiddenField)gvr.FindControl("ftItem")).Value;
                string itemDesc = ((HiddenField)gvr.FindControl("ftItemDesc")).Value;
                if (string.IsNullOrEmpty(itemCode))
                {
                    throw new BusinessErrorException(string.Format("福特物料号{0}在路线{1}中没有找到有效的路线明细,发货失败。", eDIFordPlan.RefItem, this.tbFlow.Text.Trim()));
                }
                else
                {
                    eDIFordPlan.Item     = itemCode;
                    eDIFordPlan.ItemDesc = itemDesc;
                }

                #region   本次发货量
                try
                {
                    eDIFordPlan.ShipQty = decimal.Parse(((TextBox)gvr.FindControl("tbShipQty")).Text.Trim());
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}本次发货量填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   发货总毛重
                try
                {
                    eDIFordPlan.GrossWeight = decimal.Parse(((TextBox)gvr.FindControl("tbGrossWeight")).Text.Trim()) * eDIFordPlan.ShipQty;
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}发货总毛重填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   发货总净重
                try
                {
                    eDIFordPlan.NetWeight = decimal.Parse(((TextBox)gvr.FindControl("tbNetWeight")).Text.Trim()) * eDIFordPlan.ShipQty;
                }
                catch (Exception e)
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}发货总净重填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                #endregion

                #region   毛重净重单位
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbWeightUom")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}毛重净重单位填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.WeightUom = ((TextBox)gvr.FindControl("tbWeightUom")).Text.Trim();
                }
                #endregion

                #region   装箱单号
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbShipmentID")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}装箱单号填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.ShipmentID = ((TextBox)gvr.FindControl("tbShipmentID")).Text.Trim();
                }
                #endregion

                #region   提单号
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbLadingNum")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}提单号填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.LadingNum = ((TextBox)gvr.FindControl("tbLadingNum")).Text.Trim();
                }
                #endregion

                #region   外包装类型
                eDIFordPlan.OutPackType = ((TextBox)gvr.FindControl("tbOutPackType")).Text.Trim();
                #endregion

                #region   外包装数量
                try
                {
                    eDIFordPlan.OutPackQty = decimal.Parse(((TextBox)gvr.FindControl("tbOutPackQty")).Text.Trim());
                }
                catch (Exception e)
                {
                    eDIFordPlan.OutPackQty = null;
                }
                #endregion

                #region   承运商
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbCarrierCode")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}承运商填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.CarrierCode = ((TextBox)gvr.FindControl("tbCarrierCode")).Text.Trim();
                }
                #endregion

                #region   运输方式
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbTransportationMethod")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}运输方式填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.TransportationMethod = ((TextBox)gvr.FindControl("tbTransportationMethod")).Text.Trim();
                }
                #endregion

                #region   运载媒介
                eDIFordPlan.EquipmentDesc = eDIFordPlan.TransportationMethod;
                if (eDIFordPlan.TransportationMethod == "M")
                {
                    eDIFordPlan.EquipmentDesc = "TL";
                }
                else if (eDIFordPlan.TransportationMethod == "O")
                {
                    eDIFordPlan.EquipmentDesc = "CN";
                }
                else if (eDIFordPlan.TransportationMethod == "A")
                {
                    eDIFordPlan.EquipmentDesc = "AF";
                }
                //if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbEquipmentDesc")).Text.Trim()))
                //{
                //    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}运载媒介填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                //}
                //else
                //{
                //eDIFordPlan.EquipmentDesc = ((TextBox)gvr.FindControl("tbEquipmentDesc")).Text.Trim();
                // }
                #endregion

                #region   运载媒介序列号
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbEquipmentNum")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}运载媒介序列号填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.EquipmentNum = ((TextBox)gvr.FindControl("tbEquipmentNum")).Text.Trim();
                }
                #endregion



                #region   累计发货量
                eDIFordPlan.LastShippedCumulative = eDIFordPlan.LastShippedCumulative.HasValue ? eDIFordPlan.LastShippedCumulative : 0;
                //try
                //{
                //    eDIFordPlan.ShipQtyCum = decimal.Parse(((TextBox)gvr.FindControl("tbShipQtyCum")).Text.Trim());
                //}
                //catch (Exception e)
                //{
                //    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}累计发货量填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                //}
                #endregion

                #region   单位
                if (string.IsNullOrEmpty(((TextBox)gvr.FindControl("tbInUom")).Text.Trim()))
                {
                    throw new BusinessErrorException(string.Format("版本号{0}物料号{1}单位填写有误。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                }
                else
                {
                    eDIFordPlan.Uom = ((TextBox)gvr.FindControl("tbInUom")).Text.Trim();
                }
                #endregion

                #region   内包装类型
                eDIFordPlan.InPackType = ((TextBox)gvr.FindControl("tbOutPackType")).Text.Trim();
                #endregion

                #region   每个包装数量
                try
                {
                    eDIFordPlan.PerLoadQty = decimal.Parse(((TextBox)gvr.FindControl("tbPerLoadQty")).Text.Trim());
                    if (eDIFordPlan.PerLoadQty == 0)
                    {
                        throw new BusinessErrorException(string.Format("版本号{0}物料号{1}每个包装件数必须大于0。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                    }
                }
                catch (Exception e)
                {
                    eDIFordPlan.PerLoadQty = null;
                }
                #endregion

                #region   内包装数量
                eDIFordPlan.InPackQty = eDIFordPlan.PerLoadQty == null ? 1 : (int?)Convert.ToInt32((eDIFordPlan.ShipQty.Value % eDIFordPlan.PerLoadQty.Value == 0 ? eDIFordPlan.ShipQty.Value / eDIFordPlan.PerLoadQty.Value : eDIFordPlan.ShipQty.Value / eDIFordPlan.PerLoadQty.Value + 1));
                //try
                //{
                //    eDIFordPlan.InPackQty = decimal.Parse(((TextBox)gvr.FindControl("tbInPackQty")).Text.Trim());
                //}
                //catch (Exception e)
                //{
                //    eDIFordPlan.InPackQty = null;
                //}
                #endregion

                #region   机场代码
                eDIFordPlan.AirportCode = ((TextBox)gvr.FindControl("tbAirportCode")).Text.Trim();
                if (eDIFordPlan.TransportationMethod == "A")
                {
                    if (string.IsNullOrEmpty(eDIFordPlan.AirportCode))
                    {
                        throw new BusinessErrorException(string.Format("版本号{0}物料号{1},在选择空运的时候机场代码不能为空。", eDIFordPlan.Control_Num, eDIFordPlan.Item));
                    }
                }
                else
                {
                    eDIFordPlan.AirportCode = string.Empty;
                }
                #endregion

                eDIFordPlan.Purpose = ((System.Web.UI.HtmlControls.HtmlSelect)gvr.FindControl("tbPurpose")).Value;

                eDIFordPlanList.Add(eDIFordPlan);
            }
        }
        return(eDIFordPlanList);
    }
Example #6
0
    protected void ExportExcel(IList <EDIFordPlan> exportList)
    {
        HSSFWorkbook hssfworkbook = new HSSFWorkbook();
        //Sheet sheet1 = hssfworkbook.CreateSheet("Sheet1");
        MemoryStream output = new MemoryStream();

        if (exportList != null && exportList.Count > 0)
        {
            var groups = (from tak in exportList
                          group tak by tak.Control_Num into result
                          select new
            {
                Control_Num = result.Key,
                List = result.ToList()
            }).ToList();
            for (int ti = 0; ti < groups.Count(); ti++)
            {
                var              g           = groups[ti];
                Sheet            sheet1      = hssfworkbook.CreateSheet(g.Control_Num);
                IList <DateTime> dateListDic = g.List.OrderBy(l => l.ForecastDate).Select(l => l.ForecastDate).Distinct().ToList();
                #region 写入字段
                Row rowHeader = sheet1.CreateRow(0);
                for (int i = 0; i < 6 + dateListDic.Count; i++)
                {
                    if (i == 0) //版本号
                    {
                        rowHeader.CreateCell(i).SetCellValue("版本号");
                    }
                    else if (i == 1)  //文件发布日期
                    {
                        rowHeader.CreateCell(i).SetCellValue("文件发布日期");
                    }
                    else if (i == 2) //物料号
                    {
                        rowHeader.CreateCell(i).SetCellValue("物料号");
                    }
                    else if (i == 3)    //物料描述
                    {
                        rowHeader.CreateCell(i).SetCellValue("物料描述");
                    }
                    else if (i == 4)    //福特物料号
                    {
                        rowHeader.CreateCell(i).SetCellValue("福特物料号");
                    }
                    else if (i == 5)      //单位
                    {
                        rowHeader.CreateCell(i).SetCellValue("单位");
                    }
                    else
                    {
                        foreach (var date in dateListDic)
                        {
                            rowHeader.CreateCell(i++).SetCellValue(date.ToShortDateString());
                        }
                    }
                }
                #endregion

                #region 写入数值
                //Caption.Visible = true;
                var groupByRefItem = (from tak in g.List
                                      group tak by tak.RefItem into result
                                      select new
                {
                    RefItem = result.Key,
                    List = result.ToList()
                }).ToList();
                IList <FlowDetail> flowdets = TheGenericMgr.FindAllWithCustomQuery <FlowDetail>(string.Format(" select d from FlowDetail as d where  d.ReferenceItemCode in('{0}') ", string.Join("','", g.List.Select(w => w.RefItem).Distinct().ToArray())));
                int j = 1;
                foreach (var d in groupByRefItem)
                {
                    Row         rowDetail  = sheet1.CreateRow(j);
                    Row         rowDetail2 = sheet1.CreateRow(j + 1);
                    EDIFordPlan newPlan    = d.List.First();
                    if (flowdets != null && flowdets.Count > 0)
                    {
                        var flowDet = flowdets.Where(f => f.ReferenceItemCode == newPlan.RefItem);
                        if (flowDet != null && flowDet.Count() > 0)
                        {
                            newPlan.Item     = flowDet.First().Item.Code;
                            newPlan.ItemDesc = flowDet.First().Item.Description;
                        }
                    }
                    rowDetail.CreateCell(0).SetCellValue(newPlan.Control_Num);
                    rowDetail.CreateCell(1).SetCellValue(newPlan.ReleaseIssueDate.ToShortDateString());
                    rowDetail.CreateCell(2).SetCellValue(newPlan.Item);
                    rowDetail.CreateCell(3).SetCellValue(newPlan.ItemDesc);
                    rowDetail.CreateCell(4).SetCellValue(newPlan.RefItem);
                    rowDetail.CreateCell(5).SetCellValue(newPlan.Uom);
                    int cell = 0;
                    foreach (var f in d.List.OrderBy(o => o.ForecastDate))
                    {
                        cell++;
                        //rowDetail.CreateCell(5 + cell).
                        var createCell = rowDetail.CreateCell(5 + cell);
                        createCell.SetCellType(CellType.NUMERIC);
                        createCell.SetCellValue(Convert.ToDouble(f.ForecastQty > 0 ? f.ForecastQty : 0));

                        var createCell2 = rowDetail2.CreateCell(5 + cell);
                        createCell2.SetCellType(CellType.NUMERIC);
                        createCell2.SetCellValue(Convert.ToDouble(f.ForecastCumQty > 0 ? f.ForecastCumQty : 0));
                    }
                    j += 2;
                }
                #endregion
            }
            hssfworkbook.Write(output);

            string filename = "FordEdiPlan.xls";
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", filename));
            Response.Clear();

            Response.BinaryWrite(output.GetBuffer());
            Response.End();
            //return File(output, contentType, exportName + "." + fileSuffiex);
        }
    }