Inheritance: EDIFordPlanBase
コード例 #1
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;
    }
コード例 #2
0
    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;
    }
コード例 #3
0
    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();
    }
コード例 #4
0
ファイル: EDIMgr.cs プロジェクト: Novthirteen/yfkey-scms
        public void TransformationPlan(User user)
        {
            try
            {
                DateTime datetimeNow = System.DateTime.Now;
                #region  �����ܼƻ�
                string weeklySql = " select t from TEMP_FORD_EDI_830 as t where t.IsHandle=0 order by t.Id asc";
                IList<TEMP_FORD_EDI_830> weeklyPlans = this.genericMgr.FindAllWithCustomQuery<TEMP_FORD_EDI_830>(weeklySql);
                IList<EDIFordPlan> planList = new List<EDIFordPlan>();
                if (weeklyPlans != null && weeklyPlans.Count > 0)
                {
                    //IList<FlowDetail> flowdets = this.genericMgr.FindAllWithCustomQuery<FlowDetail>(string.Format(" select d from FlowDetail as d where  d.ReferenceItemCode in('{0}') ",string.Join("','", weeklyPlans.Select(w => w.Part_Num).Distinct().ToArray())));
                    //IList<ItemReference> itemReferences = this.genericMgr.FindAllWithCustomQuery<ItemReference>(string.Format(" select t from ItemReference as t where t.ReferenceCode in('{0}')", string.Join("','", weeklyPlans.Select(w => w.Part_Num).Distinct().ToArray())));
                    foreach (var weekly in weeklyPlans)
                    {
                        #region
                        //var flowDet = flowdets.Where(f => f.ReferenceItemCode == weekly.Part_Num);
                        //if (flowDet == null || flowDet.Count() == 0)
                        //{
                        //    throw new Exception("�������Ϻ��Ҳ�����Ӧ����ϸ��");
                        //}
                        //ItemReference itemReference = itemReferences.Where(i => i.ReferenceCode == weekly.Part_Num).First();
                        EDIFordPlan eDIFordPlan = new EDIFordPlan();
                        eDIFordPlan.TempId = weekly.Id;
                        eDIFordPlan.BatchNo = weekly.BatchNo;
                        eDIFordPlan.Control_Num = weekly.Interchange_Control_Num;
                        eDIFordPlan.SupplierCode = weekly.Ship_From_GSDB_Code;
                        eDIFordPlan.CustomerCode = weekly.Ship_To_GSDB_Code;
                        eDIFordPlan.ReleaseIssueDate =  DateTime.Parse(weekly.Message_Release_Date.Substring(0, 4) + "-" + weekly.Message_Release_Date.Substring(4, 2) + "-" + weekly.Message_Release_Date.Substring(6, 2));
                        eDIFordPlan.Item = string.Empty;
                        eDIFordPlan.ItemDesc = string.Empty;
                        eDIFordPlan.RefItem = weekly.Part_Num;
                        eDIFordPlan.Uom = weekly.UOM;
                        eDIFordPlan.LastShippedQuantity = string.IsNullOrEmpty(weekly.Last_Shipped_Qty) ? null : (decimal?)(Convert.ToDecimal(weekly.Last_Shipped_Qty));
                        eDIFordPlan.LastShippedCumulative = string.IsNullOrEmpty(weekly.Cum_Shipped_Qty) ? null : (decimal?)(Convert.ToDecimal(weekly.Cum_Shipped_Qty));
                        eDIFordPlan.LastShippedDate = string.IsNullOrEmpty(weekly.Last_Shipped_Date) ? null : (DateTime?)(DateTime.Parse(weekly.Last_Shipped_Date.Substring(0, 4) + "-" + weekly.Last_Shipped_Date.Substring(4, 2) + "-" + weekly.Last_Shipped_Date.Substring(6, 2)));
                        eDIFordPlan.DockCode = weekly.Dock_Code;
                        eDIFordPlan.LineFeed = weekly.Line_Feed;
                        eDIFordPlan.StorageLocation = weekly.Reserve_Line_Feed;
                        eDIFordPlan.IntermediateConsignee = weekly.Intermediate_Consignee;
                        eDIFordPlan.ForecastQty = string.IsNullOrEmpty(weekly.Forecast_Net_Qty) ? 0 : Convert.ToDecimal(weekly.Forecast_Net_Qty);
                        eDIFordPlan.ForecastCumQty = string.IsNullOrEmpty(weekly.Forecast_Cum_Qty) ? 0 : Convert.ToDecimal(weekly.Forecast_Cum_Qty);
                        eDIFordPlan.ForecastDate = string.IsNullOrEmpty(weekly.Forecast_Date) ? System.DateTime.Now.AddDays(-365) : DateTime.Parse(weekly.Forecast_Date.Substring(0, 4) + "-" + weekly.Forecast_Date.Substring(4, 2) + "-" + weekly.Forecast_Date.Substring(6, 2));
                        eDIFordPlan.CreateDate = datetimeNow;
                        eDIFordPlan.CreateUserName = user.Name;
                        eDIFordPlan.Type = weekly.Forecast_Date_Qual_r;
                        eDIFordPlan.PurchaseOrder = weekly.Purchase_Order_Num;
                        this.genericMgr.Create(eDIFordPlan);
                        planList.Add(eDIFordPlan);
                        //weekly.IsHandle = true    ;
                        //this.genericMgr.Update(weekly);
                        #endregion
                    }
                    string upIsHandleSql = string.Format("update TEMP_FORD_EDI_830 set IsHandle=1 where Interchange_Control_Num in ('{0}')",string.Join("','", weeklyPlans.Select(w=>w.Interchange_Control_Num).Distinct().ToArray()));
                    this.genericMgr.ExecuteSql(upIsHandleSql);

                    #region �ܼƻ�ת�ͻ�����
                    var groupWeeklys = weeklyPlans.GroupBy(w => w.Interchange_Control_Num).ToDictionary(d => d.Key, d => d.OrderBy(rd => rd.Forecast_Date).ToList());

                    foreach (var g in groupWeeklys)
                    {
                        string searchFlowCodeSql = string.Format("select Code from flowmstr where type='Distribution' and CustomerCodes like '%{0}%' and SupplierCodes like '%{1}%'", g.Value.First().Ship_To_GSDB_Code, g.Value.First().Ship_From_GSDB_Code);
                        var flowCodes = this.genericMgr.GetDatasetBySql(searchFlowCodeSql).Tables[0];
                        string flowCode = string.Empty;
                        foreach (System.Data.DataRow row in flowCodes.Rows)
                        {
                            flowCode = row[0].ToString();
                        }
                        foreach (var v in g.Value)
                        {
                            v.TempFlow = flowCode;
                        }
                    }
                    var groupWeeklyByFlow = weeklyPlans.GroupBy(w => w.TempFlow).ToDictionary(d => d.Key, d => d.OrderBy(rd => rd.Forecast_Date).ToList());
                    IList<CustomerScheduleDetail> tempDetList = new List<CustomerScheduleDetail>();
                    foreach (var g in groupWeeklyByFlow)
                    {
                        Flow currentFlow = this.flowMgr.LoadFlow(g.Key);
                        if (currentFlow == null) continue;
                        int customerPlanVersion = numberControlMgr.GenerateNumberNextSequence("CustomerPlan_" + currentFlow.Code + "_" + BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_WEEK);
                        var mrpLeadtime = currentFlow.MrpLeadTime.HasValue ? Convert.ToDouble(-currentFlow.MrpLeadTime.Value) : 0;
                        CustomerSchedule mstr = new CustomerSchedule
                        {
                            ReferenceScheduleNo = g.Key + "-Weekly-" + customerPlanVersion.ToString().PadLeft(3,'0'),
                            Flow = g.Key,
                            Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT,
                            Type = BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_WEEK,
                            CreateDate = datetimeNow,
                            CreateUser = user.Code,
                            LastModifyDate = datetimeNow,
                            LastModifyUser = user.Code,
                            ReleaseDate=  datetimeNow,
                            ReleaseUser=user.Code,
                            Version = customerPlanVersion,
                            ShipFlow = currentFlow.ShipFlow,
                        };
                        this.genericMgr.Create(mstr);
                        for (int i = 0; i < g.Value.Count; i++)
                        {
                            var r = g.Value[i];
                            var rn = g.Value[i + 1];
                            if (rn.Forecast_Date_Qual_r == "M")
                            {
                                for (int ii = i; ii < g.Value.Count; ii++)
                                {
                                    var r1 = g.Value[ii];
                                    var sDate = DateTime.Parse(r1.Forecast_Date.Substring(0, 4) + "-" + r1.Forecast_Date.Substring(4, 2) + "-" + r1.Forecast_Date.Substring(6, 2));
                                    var firstDate = DateTime.Parse(r1.Forecast_Date.Substring(0, 4) + "-" + r1.Forecast_Date.Substring(4, 2) + "-" + r1.Forecast_Date.Substring(6, 2));
                                    var year = sDate.Date.Year;
                                    var month = sDate.Date.Month;
                                    if (sDate.Date.Month == 12)
                                    {
                                        year = sDate.Date.Year + 1;
                                        month = 0;
                                    }
                                    var eDate = new DateTime(year, month + 1, 1).AddDays(-1);
                                    TimeSpan ts = eDate - sDate;
                                    int sub = ts.Days;
                                    int surplusWeekly = sub % 7 > 4 ? sub / 7 + 1 : sub / 7;
                                    if (surplusWeekly == 0)
                                    {
                                        if (sDate.Date.Month == 11)
                                        {
                                            year = sDate.Date.Year + 1;
                                            month = -1;
                                        }
                                        else if (sDate.Date.Month == 12)
                                        {
                                            year = sDate.Date.Year + 1;
                                            month = 0;
                                        }
                                        eDate = new DateTime(year, month + 2, 1).AddDays(-1);
                                        ts = eDate - sDate;
                                        sub = ts.Days;
                                        surplusWeekly = sub % 7 > 4 ? sub / 7 + 1 : sub / 7;
                                    }
                                    var averageQty = Convert.ToDecimal(r.Forecast_Net_Qty) / surplusWeekly;
                                    for (int j = 0; j < surplusWeekly; j++)
                                    {
                                        var cFlowDets = currentFlow.FlowDetails.Where(d => d.ReferenceItemCode == r1.Part_Num);
                                        FlowDetail fdet = cFlowDets != null && cFlowDets.Count() > 0 ? cFlowDets.First() : new FlowDetail();
                                        if (fdet.Item != null)
                                        {
                                            #region
                                            CustomerScheduleDetail cdet = new CustomerScheduleDetail();
                                            cdet.CustomerSchedule = mstr;
                                            cdet.Item = fdet.Item.Code;
                                            cdet.ItemDescription = fdet.Item.Description;
                                            cdet.ItemReference = r1.Part_Num;
                                            cdet.Type = BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_WEEK;
                                            cdet.Version = mstr.Version;
                                            cdet.DateFrom = sDate;
                                            cdet.DateTo = sDate.AddDays(7);
                                            cdet.Uom = fdet.Uom.Code;
                                            cdet.UnitCount = fdet.UnitCount;
                                            cdet.Qty = averageQty < 0 ? 0 : averageQty;
                                            cdet.Location = currentFlow.LocationFrom != null ? currentFlow.LocationFrom.Code : string.Empty;
                                            cdet.StartTime = sDate.AddDays(-mrpLeadtime).Date;
                                            cdet.Flow = mstr.Flow;
                                            cdet.ReferenceScheduleNo = mstr.ReferenceScheduleNo;
                                            cdet.ShipFlow = mstr.ShipFlow;
                                            cdet.ShipQty = 0;
                                            cdet.FordPlanId = planList.FirstOrDefault(d => d.RefItem == r1.Part_Num && d.Control_Num == r1.Interchange_Control_Num && d.ForecastDate == firstDate).Id;
                                            //this.genericMgr.Create(cdet);
                                            tempDetList.Add(cdet);
                                            sDate = sDate.AddDays(7);
                                            #endregion
                                        }
                                    }
                                }
                                break;
                            }
                            var currentFlowDets = currentFlow.FlowDetails.Where(d => d.ReferenceItemCode == r.Part_Num);
                            FlowDetail flowdet = currentFlowDets != null && currentFlowDets.Count() > 0 ? currentFlowDets.First() : new FlowDetail();
                            if (flowdet.Item != null)
                            {
                                #region
                                CustomerScheduleDetail det = new CustomerScheduleDetail();
                                det.CustomerSchedule = mstr;
                                det.Item = flowdet.Item != null ? flowdet.Item.Code : string.Empty;
                                det.ItemDescription = flowdet.Item != null ? flowdet.Item.Description : string.Empty;
                                det.ItemReference = r.Part_Num;
                                //det.Bom = null;
                                det.Type = BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_WEEK;
                                det.DateFrom = string.IsNullOrEmpty(r.Forecast_Date) ? System.DateTime.Now.AddDays(-365) : DateTime.Parse(r.Forecast_Date.Substring(0, 4) + "-" + r.Forecast_Date.Substring(4, 2) + "-" + r.Forecast_Date.Substring(6, 2));
                                det.DateTo = det.DateFrom.AddDays(7);
                                det.Uom = flowdet.Uom.Code;
                                det.UnitCount = flowdet.UnitCount;
                                det.Qty = string.IsNullOrEmpty(r.Forecast_Net_Qty) ? 0 : Convert.ToDecimal(r.Forecast_Net_Qty) < 0 ? 0 : Convert.ToDecimal(r.Forecast_Net_Qty);
                                det.Location = currentFlow.LocationFrom != null ? currentFlow.LocationFrom.Code : string.Empty;
                                //det.StartTime = det.DateFrom;
                                det.StartTime = det.DateFrom.AddDays(-mrpLeadtime).Date;
                                det.Version = mstr.Version;
                                det.Flow = mstr.Flow;
                                det.ReferenceScheduleNo = mstr.ReferenceScheduleNo;
                                det.ShipFlow = mstr.ShipFlow;
                                det.ShipQty = 0;
                                det.FordPlanId = planList.FirstOrDefault(d => d.RefItem == r.Part_Num && d.Control_Num == r.Interchange_Control_Num && d.ForecastDate==det.DateFrom).Id;
                                //this.genericMgr.Create(det);
                                tempDetList.Add(det);
                                #endregion
                            }
                        }
                        if(tempDetList.Count>0){
                            var groupbyItem = tempDetList.GroupBy(d => new { d.Item, d.DateFrom });
                            foreach (var gi in groupbyItem)
                            {
                                var det = gi.First();
                                det.Qty = gi.Sum(gd => gd.Qty);
                                this.genericMgr.Create(det);
                            }
                            tempDetList.Clear();
                        }

                    }
                    #endregion
                }
                #endregion

                #region  ������ƻ�
                planList.Clear();
                //planList = new List<EDIFordPlan>();
                string dailySql = " select t from TEMP_FORD_EDI_862 as t where t.IsHandle=0 order by t.Id asc";
                IList<TEMP_FORD_EDI_862> dailyPlans = this.genericMgr.FindAllWithCustomQuery<TEMP_FORD_EDI_862>(dailySql);
                if (dailyPlans != null && dailyPlans.Count > 0)
                {
                    //IList<FlowDetail> flowdets = this.genericMgr.FindAllWithCustomQuery<FlowDetail>(string.Format(" select d from FlowDetail as d where exists( select 1 from Flow as m where m.Code=d.Flow and m.Description like '%����%' and m.IsActive=1) and d.ReferenceItemCode in('{0}') ", string.Join("','", dailyPlans.Select(w => w.Part_Num).Distinct().ToArray())));
                    //IList<FlowDetail> flowdets = this.genericMgr.FindAllWithCustomQuery<FlowDetail>(string.Format(" select d from FlowDetail as d where d.ReferenceItemCode in('{0}') ", string.Join("','", dailyPlans.Select(w => w.Part_Num).Distinct().ToArray())));
                    //IList<ItemReference> itemReferences = this.genericMgr.FindAllWithCustomQuery<ItemReference>(string.Format(" select t from ItemReference as t where t.ReferenceCode in('{0}')", string.Join("','", dailyPlans.Select(w => w.Part_Num).Distinct().ToArray())));
                    foreach (var daily in dailyPlans)
                    {
                        #region
                        //ItemReference itemReference = itemReferences.Where(i => i.ReferenceCode == daily.Part_Num).First();
                        //var flowDet = flowdets.Where(f => f.ReferenceItemCode == daily.Part_Num);
                        //if (flowDet == null || flowDet.Count() == 0)
                        //{
                        //    throw new Exception("�������Ϻ��Ҳ�����Ӧ����ϸ��");
                        //}
                        EDIFordPlan eDIFordPlan = new EDIFordPlan();
                        eDIFordPlan.TempId = daily.Id;
                        eDIFordPlan.BatchNo = daily.BatchNo;
                        eDIFordPlan.Control_Num = daily.Interchange_Control_Num;
                        eDIFordPlan.SupplierCode = daily.Ship_From_GSDB_Code;
                        eDIFordPlan.CustomerCode = daily.Ship_To_GSDB_Code;
                        eDIFordPlan.ReleaseIssueDate = DateTime.Parse(daily.Message_Release_Date.Substring(0, 4) + "-" + daily.Message_Release_Date.Substring(4, 2) + "-" + daily.Message_Release_Date.Substring(6, 2));
                        //eDIFordPlan.Item = flowDet.First().Item.Code;
                        //eDIFordPlan.ItemDesc = flowDet.First().Item.Desc1;
                        //eDIFordPlan.RefItem = flowDet.First().ReferenceItemCode;
                        eDIFordPlan.Item = string.Empty;
                        eDIFordPlan.ItemDesc = string.Empty;
                        eDIFordPlan.RefItem = daily.Part_Num;
                        eDIFordPlan.Uom = daily.UOM;
                        eDIFordPlan.LastShippedQuantity = string.IsNullOrEmpty(daily.Last_Shipped_Qty) ? null : (decimal?)(Convert.ToDecimal(daily.Last_Shipped_Qty));
                        eDIFordPlan.LastShippedCumulative = string.IsNullOrEmpty(daily.Cum_Shipped_Qty) ? null : (decimal?)(Convert.ToDecimal(daily.Cum_Shipped_Qty));
                        eDIFordPlan.LastShippedDate = string.IsNullOrEmpty(daily.Last_Shipped_Date) ? null : (DateTime?)(DateTime.Parse(daily.Last_Shipped_Date.Substring(0, 4) + "-" + daily.Last_Shipped_Date.Substring(4, 2) + "-" + daily.Last_Shipped_Date.Substring(6, 2)));
                        eDIFordPlan.DockCode = daily.Dock_Code;
                        eDIFordPlan.LineFeed = daily.Line_Feed;
                        eDIFordPlan.StorageLocation = daily.Reserve_Line_Feed;
                        eDIFordPlan.IntermediateConsignee = daily.Intermediate_Consignee;
                        eDIFordPlan.ForecastQty = string.IsNullOrEmpty(daily.Forecast_Net_Qty) ? 0 : Convert.ToDecimal(daily.Forecast_Net_Qty);
                        eDIFordPlan.ForecastCumQty = string.IsNullOrEmpty(daily.Forecast_Cum_Qty) ? 0 : Convert.ToDecimal(daily.Forecast_Cum_Qty);
                        eDIFordPlan.ForecastDate = string.IsNullOrEmpty(daily.Forecast_Date) ? System.DateTime.Now.AddDays(-365) : DateTime.Parse(daily.Forecast_Date.Substring(0, 4) + "-" + daily.Forecast_Date.Substring(4, 2) + "-" + daily.Forecast_Date.Substring(6, 2));
                        eDIFordPlan.CreateDate = datetimeNow;
                        eDIFordPlan.CreateUserName = user.Name;
                        eDIFordPlan.Type = "D";
                        eDIFordPlan.PurchaseOrder = daily.Purchase_Order_Num;
                        this.genericMgr.Create(eDIFordPlan);
                        planList.Add(eDIFordPlan);
                        //daily.IsHandle = true;
                        //this.genericMgr.Update(daily);
                        #endregion
                    }
                    string upIsHandleSql = string.Format("update TEMP_FORD_EDI_862 set IsHandle=1 where Interchange_Control_Num in ('{0}')", string.Join("','", dailyPlans.Select(w => w.Interchange_Control_Num).Distinct().ToArray()));
                    this.genericMgr.ExecuteSql(upIsHandleSql);

                    #region   ��ƻ�ת�ͻ�����
                    var groupDailyPlan = dailyPlans.GroupBy(w => w.Interchange_Control_Num).ToDictionary(d => d.Key, d => d.ToList());

                    foreach (var g in groupDailyPlan)
                    {
                        string searchFlowCodeSql = string.Format("select Code from flowmstr where type='Distribution' and CustomerCodes like '%{0}%' and SupplierCodes like '%{1}%'", g.Value.First().Ship_To_GSDB_Code, g.Value.First().Ship_From_GSDB_Code);
                        var flowCodes = this.genericMgr.GetDatasetBySql(searchFlowCodeSql).Tables[0];
                        string flowCode = string.Empty;
                        foreach (System.Data.DataRow row in flowCodes.Rows)
                        {
                            flowCode = row[0].ToString();
                        }
                        foreach (var v in g.Value)
                        {
                            v.TempFlow = flowCode;
                        }
                    }
                    var groupdailyByFlow = dailyPlans.GroupBy(w => w.TempFlow).ToDictionary(d => d.Key, d => d.OrderBy(rd => rd.Forecast_Date).ToList());

                    IList<CustomerScheduleDetail> tempDetList = new List<CustomerScheduleDetail>();
                    foreach (var g in groupdailyByFlow)
                    {
                        Flow currentFlow = this.flowMgr.LoadFlow(g.Key);
                        if (currentFlow == null) continue;
                        int customerPlanVersion = numberControlMgr.GenerateNumberNextSequence("CustomerPlan_" + g.Key + "_" + BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_WEEK);
                        var firstWeek = g.Value.First();
                        CustomerSchedule mstr = new CustomerSchedule
                        {
                            ReferenceScheduleNo = g.Key + "-Daily-" + customerPlanVersion.ToString().PadLeft(3,'0'),
                            Flow = g.Key,
                            Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT,
                            Type = BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_DAY,
                            CreateDate = datetimeNow,
                            CreateUser = user.Code,
                            LastModifyDate = datetimeNow,
                            LastModifyUser = user.Code,
                            ReleaseDate = datetimeNow,
                            ReleaseUser = user.Code,
                            Version = customerPlanVersion,
                            ShipFlow = currentFlow.ShipFlow,
                        };
                        this.genericMgr.Create(mstr);
                        foreach (var r in g.Value)
                        {
                            var currentFlowDets = currentFlow.FlowDetails.Where(d => d.ReferenceItemCode == r.Part_Num);
                            FlowDetail flowdet = currentFlowDets != null && currentFlowDets.Count() > 0 ? currentFlowDets.First() : new FlowDetail();
                            var mrpLeadtime=currentFlow.MrpLeadTime.HasValue?  Convert.ToDouble(-currentFlow.MrpLeadTime.Value):0;
                            if (flowdet.Item != null)
                            {
                                CustomerScheduleDetail det = new CustomerScheduleDetail();
                                det.CustomerSchedule = mstr;
                                det.Item = flowdet.Item != null ? flowdet.Item.Code : string.Empty;
                                det.ItemDescription = flowdet.Item != null ? flowdet.Item.Description : string.Empty;
                                det.ItemReference = r.Part_Num;
                                //det.Bom = null;
                                det.Type = BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_DAY;
                                det.DateFrom = string.IsNullOrEmpty(r.Forecast_Date) ? System.DateTime.Now.AddDays(-365) : DateTime.Parse(r.Forecast_Date.Substring(0, 4) + "-" + r.Forecast_Date.Substring(4, 2) + "-" + r.Forecast_Date.Substring(6, 2));
                                det.DateTo = string.IsNullOrEmpty(r.Forecast_Date) ? System.DateTime.Now.AddDays(-365) : DateTime.Parse(r.Forecast_Date.Substring(0, 4) + "-" + r.Forecast_Date.Substring(4, 2) + "-" + r.Forecast_Date.Substring(6, 2));
                                det.Uom = flowdet.Uom.Code;
                                det.UnitCount = flowdet.UnitCount;
                                det.Qty = string.IsNullOrEmpty(r.Forecast_Net_Qty) ? 0 : Convert.ToDecimal(r.Forecast_Net_Qty) < 0 ? 0 : Convert.ToDecimal(r.Forecast_Net_Qty);
                                det.Location = currentFlow.LocationFrom != null ? currentFlow.LocationFrom.Code : string.Empty;
                                det.StartTime = det.DateFrom.AddDays(-mrpLeadtime).Date;
                                det.Version = mstr.Version;
                                det.Flow = mstr.Flow;
                                det.ReferenceScheduleNo = mstr.ReferenceScheduleNo;
                                det.ShipFlow = mstr.ShipFlow;
                                det.ShipQty = 0;
                                det.FordPlanId = planList.FirstOrDefault(d => d.RefItem == r.Part_Num && d.Control_Num == r.Interchange_Control_Num && d.ForecastDate==det.DateFrom).Id;
                                //this.genericMgr.Create(det);
                                tempDetList.Add(det);
                            }
                        }
                        if (tempDetList.Count > 0)
                        {
                            var groupbyItem = tempDetList.GroupBy(d => new { d.Item,d.DateFrom});
                            foreach (var gi in groupbyItem)
                            {
                                var det = gi.First();
                                det.Qty = gi.Sum(gd => gd.Qty);
                                this.genericMgr.Create(det);
                            }
                            tempDetList.Clear();
                        }
                    }
                    #endregion
                }
                #endregion
            }
            catch (Exception e)
            {
                throw e;
            }
        }