Exemple #1
0
    public void InitPageParameter(int customerScheduleId)
    {
        if (customerScheduleId > 0)
        {
            this.customerSchedule = TheCustomerScheduleMgr.LoadCustomerSchedule(customerScheduleId, true);

            this.tbFlow1.Text = customerSchedule.Flow;
            this.tbFlow1.Visible = true;
            this.tbFlow.Visible = false;

            this.tbScheduleNo.Text = customerSchedule.ReferenceScheduleNo;
            this.tbScheduleNo.ReadOnly = true;
            this.trTemplate.Visible = false;

        }
        else
        {
            this.customerSchedule = null;

            this.tbFlow.Visible = true;
            this.tbFlow.Text = string.Empty;
            this.tbFlow1.Visible = false;

            this.tbScheduleNo.ReadOnly = false;
            this.tbScheduleNo.Text = string.Empty;

            this.trTemplate.Visible = true;

        }
        this.GVDataBind();
    }
Exemple #2
0
    public void InitPageParameter(int customerScheduleId)
    {
        if (customerScheduleId > 0)
        {
            this.customerSchedule = TheCustomerScheduleMgr.LoadCustomerSchedule(customerScheduleId, true);

            this.tbFlow1.Text    = customerSchedule.Flow;
            this.tbFlow1.Visible = true;
            this.tbFlow.Visible  = false;

            this.tbScheduleNo.Text     = customerSchedule.ReferenceScheduleNo;
            this.tbScheduleNo.ReadOnly = true;
            this.trTemplate.Visible    = false;
        }
        else
        {
            this.customerSchedule = null;


            this.tbFlow.Visible  = true;
            this.tbFlow.Text     = string.Empty;
            this.tbFlow1.Visible = false;

            this.tbScheduleNo.ReadOnly = false;
            this.tbScheduleNo.Text     = string.Empty;


            this.trTemplate.Visible = true;
        }
        this.GVDataBind();
    }
        private void AddAppointment(NewAppointmentRequest request, int userId, int branchId)
        {
            var treatments = new List <CustomerScheduleTreatment>();

            foreach (var treatment in request.Treatments)
            {
                treatments.Add(new CustomerScheduleTreatment()
                {
                    Ttid      = treatment.Ttid,
                    Empno     = treatment.EmpNo,
                    StartTime = treatment.StartTime,
                    EndTime   = treatment.EndTime,
                    Qty       = treatment.Qty
                });
            }

            var customerSchedule = new CustomerSchedule()
            {
                CustomerId   = request.CustomerId,
                BookedDate   = request.BookedDate,
                Status       = AppoinmentConstant.PENDING,
                DepartmentId = request.DepartmentId,
                BranchId     = request.BranchId,
                EnteredBy    = request.EnteredBy,
                EnteredDate  = DateTime.Now,
                CustomerScheduleTreatments = treatments
            };

            _customerScheduleRepository.Add(customerSchedule);
            _customerScheduleRepository.SaveChanges();
        }
 private Schedule SearchSchedules(Customer customer)
 {
     if (customer == null)
     {
         throw new ArgumentNullException("customer");
     }
     using (IUnitOfWork unit = new UnitOfWork())
     {
         var schedules = unit.Schedules.Query(x => x.CustomerId == customer.CustomerId);
         if (schedules.Count() == 1)
         {
             return(schedules.Single());
         }
         if (schedules.Count() > 1)
         {
             SelectScheduleDialog dialog = new SelectScheduleDialog(schedules);
             if (dialog.ShowDialog() == true)
             {
                 CustomerSchedule selected =
                     ((SelectSheduleController)dialog.DataContext).SelectedItem as CustomerSchedule;
                 if (selected != null)
                 {
                     return(unit.Schedules.GetById(selected.ScheduleId));
                 }
             }
         }
     }
     throw new ObjectNotFoundException(Properties.Resources.ObjectNotFoundExcMsg);
 }
Exemple #5
0
        public CustomerSchedule LoadCustomerSchedule(int customerScheduleId, bool includeDetails)
        {
            CustomerSchedule customerSchedule = this.LoadCustomerSchedule(customerScheduleId);

            if (includeDetails && customerSchedule != null && customerSchedule.CustomerScheduleDetails != null &&
                customerSchedule.CustomerScheduleDetails.Count > 0)
            {
            }
            return(customerSchedule);
        }
 public override void DeleteCustomerSchedule(CustomerSchedule customerSchedule)
 {
     if (customerSchedule.CustomerScheduleDetails != null)
     {
         foreach (CustomerScheduleDetail customerScheduleDetail in customerSchedule.CustomerScheduleDetails)
         {
             customerScheduleDetailMgr.DeleteCustomerScheduleDetail(customerScheduleDetail);
         }
     }
     base.DeleteCustomerSchedule(customerSchedule);
 }
Exemple #7
0
 public override void DeleteCustomerSchedule(CustomerSchedule customerSchedule)
 {
     if (customerSchedule.CustomerScheduleDetails != null)
     {
         foreach (CustomerScheduleDetail customerScheduleDetail in customerSchedule.CustomerScheduleDetails)
         {
             customerScheduleDetailMgr.DeleteCustomerScheduleDetail(customerScheduleDetail);
         }
     }
     base.DeleteCustomerSchedule(customerSchedule);
 }
Exemple #8
0
 private void GVDataBind()
 {
     if (this.customerSchedule != null)
     {
         if (this.customerSchedule.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)
         {
             this.btnDelete.Visible  = true;
             this.btnRelease.Visible = true;
             this.btnSave.Visible    = true;
             this.btnCancel.Visible  = false;
             this.btnImport.Visible  = false;
         }
         else if (this.customerSchedule.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT)
         {
             this.btnDelete.Visible  = false;
             this.btnRelease.Visible = false;
             this.btnSave.Visible    = false;
             this.btnCancel.Visible  = true;
             this.btnImport.Visible  = false;
         }
         else if (this.customerSchedule.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CANCEL)
         {
             this.btnDelete.Visible  = false;
             this.btnRelease.Visible = false;
             this.btnSave.Visible    = false;
             this.btnCancel.Visible  = false;
             this.btnImport.Visible  = false;
         }
         else
         {
             this.btnDelete.Visible  = false;
             this.btnRelease.Visible = false;
             this.btnSave.Visible    = true;
             this.btnCancel.Visible  = false;
             this.btnImport.Visible  = true;
         }
     }
     else
     {
         this.customerSchedule = new CustomerSchedule();
         this.customerSchedule.CustomerScheduleDetails = new List <CustomerScheduleDetail>();
         this.btnSave.Visible   = true;
         this.btnImport.Visible = true;
     }
     this.GV_List_Detail.DataSource = this.customerSchedule.CustomerScheduleDetails;
     this.GV_List_Detail.Visible    = true;
     this.GV_List_Detail.DataBind();
     this.ltllegend.Text          = customerSchedule.ReferenceScheduleNo;
     this.div_List_Detail.Visible = this.customerSchedule.CustomerScheduleDetails.Count > 0;
     if (customerSchedule.CustomerScheduleDetails.Count > 500)
     {
         ShowWarningMessage("Common.ListCount.Warning.GreatThan500");
     }
 }
 public override void CreateCustomerSchedule(CustomerSchedule customerSchedule)
 {
     base.CreateCustomerSchedule(customerSchedule);
     if (customerSchedule.CustomerScheduleDetails != null)
     {
         foreach (CustomerScheduleDetail customerScheduleDetail in customerSchedule.CustomerScheduleDetails)
         {
             customerScheduleDetail.CustomerSchedule = customerSchedule;
             customerScheduleDetailMgr.CreateCustomerScheduleDetail(customerScheduleDetail);
         }
     }
 }
        public async Task <IActionResult> Create([Bind("CustomerScheduleId,ScheduledTime,UserId")] CustomerSchedule customerSchedule)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customerSchedule);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", customerSchedule.UserId);
            return(View(customerSchedule));
        }
Exemple #11
0
 public override void CreateCustomerSchedule(CustomerSchedule customerSchedule)
 {
     base.CreateCustomerSchedule(customerSchedule);
     if (customerSchedule.CustomerScheduleDetails != null)
     {
         foreach (CustomerScheduleDetail customerScheduleDetail in customerSchedule.CustomerScheduleDetails)
         {
             customerScheduleDetail.CustomerSchedule = customerSchedule;
             customerScheduleDetailMgr.CreateCustomerScheduleDetail(customerScheduleDetail);
         }
     }
 }
Exemple #12
0
 public override void UpdateCustomerSchedule(CustomerSchedule customerSchedule)
 {
     customerSchedule.LastModifyDate = DateTime.Now;
     base.UpdateCustomerSchedule(customerSchedule);
     if (customerSchedule.CustomerScheduleDetails != null)
     {
         foreach (CustomerScheduleDetail customerScheduleDetail in customerSchedule.CustomerScheduleDetails)
         {
             customerScheduleDetailMgr.UpdateCustomerScheduleDetail(customerScheduleDetail);
         }
     }
 }
Exemple #13
0
        public void CancelCustomerSchedule(int customerScheduleId, string userCode)
        {
            CustomerSchedule customerSchedule = this.LoadCustomerSchedule(customerScheduleId);

            if (customerSchedule.Status != BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT)
            {
                throw new BusinessErrorException("MRP.Schedule.Close.Fail", customerSchedule.Status);
            }
            customerSchedule.Status         = BusinessConstants.CODE_MASTER_STATUS_VALUE_CLOSE;
            customerSchedule.LastModifyDate = DateTime.Now;
            customerSchedule.LastModifyUser = userCode;
            this.UpdateCustomerSchedule(customerSchedule);
        }
Exemple #14
0
 protected void btnRelease_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.customerSchedule != null && this.customerSchedule.Id > 0)
         {
             TheCustomerScheduleMgr.ReleaseCustomerSchedule(this.customerSchedule.Id, this.CurrentUser.Code);
             this.customerSchedule = TheCustomerScheduleMgr.LoadCustomerSchedule(this.customerSchedule.Id, true);
             ShowSuccessMessage("MRP.Schedule.Release.Successfully");
             this.backClickEvent(this, e);
         }
     }
     catch (BusinessErrorException ex)
     {
         ShowErrorMessage(ex);
     }
 }
Exemple #15
0
 protected void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         CustomerSchedule customerSchedule = TheCustomerScheduleMgr.LoadCustomerSchedule(this.customerSchedule.Id, true);
         TheCustomerScheduleMgr.DeleteCustomerSchedule(customerSchedule);
         this.backClickEvent(this, e);
         ShowSuccessMessage("MRP.Schedule.Delete.Successfully");
     }
     catch (BusinessErrorException ex)
     {
         ShowErrorMessage(ex);
     }
     catch (Exception)
     {
         ShowErrorMessage("MRP.Schedule.Delete.Fail");
     }
 }
 public bool DeleteSchedule(int id)
 {
     if (CustomerScheduleExists(id))
     {
         CustomerSchedule scheduleOfInterest = _ctx.CustomerSchedules.Where(cS => cS.CustomerScheduleId == id).SingleOrDefault();
         try
         {
             _ctx.Remove(scheduleOfInterest);
             _ctx.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
     return(false);
 }
Exemple #17
0
 public void FillCustomerSchedules(IEnumerable <Schedule> schedules)
 {
     foreach (var schedule in schedules)
     {
         string propertyDesc = "";
         string propertyNo   = "";
         var    contracts    = schedule.ScheduleDetails.Distinct(new CompareDetailsByContract());
         foreach (var detail in contracts)
         {
             propertyDesc += detail.Contract.Property.Description + " - ";
             propertyNo   += detail.Contract.PropertyNo + " - ";
         }
         CustomerSchedule customerSchedule = new CustomerSchedule(
             schedule.ScheduleId, schedule.CustomerId, schedule.Customer.Name,
             propertyNo, propertyDesc
             );
         CustomerSchedules.Add(customerSchedule);
     }
 }
 public bool CancelInspection(int id)
 {
     if (CustomerScheduleExists(id))
     {
         CustomerSchedule scheduleOfInterest = _ctx.CustomerSchedules.Where(cS => cS.CustomerScheduleId == id).SingleOrDefault();
         scheduleOfInterest.State = Enums.InspectionState.Canceled;
         try
         {
             _ctx.Update(scheduleOfInterest);
             _ctx.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
     return(false);
 }
 public bool BookSchedule(CustomerScheduleDto customerSchedule)
 {
     try
     {
         CustomerSchedule customerToSchedule = new CustomerSchedule
         {
             CarId         = customerSchedule.CarId,
             ScheduledTime = customerSchedule.ScheduledTime,
             UserId        = customerSchedule.UserId,
             State         = Enums.InspectionState.WillInspect
         };
         _ctx.CustomerSchedules.Add(customerToSchedule);
         _ctx.SaveChanges();
         return(true);
     }
     catch {
         return(false);
     }
 }
Exemple #20
0
        public IList<CustomerSchedule> ReadCustomerScheduleFromXls(Stream inputStream, User user, DateTime? startDate, DateTime? endDate,
            string flowCode, string refScheduleNo, bool isItemRef)
        {
            if (inputStream.Length == 0)
            {
                throw new BusinessErrorException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
            Sheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            #region 读取路线,参考日程号等
            Flow flow = null;
            decimal leadTime = 0M;
            IList<string> flowList = new List<string>();
            if (flowCode != null && flowCode.Trim() != string.Empty)
            {
                flow = flowMgr.CheckAndLoadFlow(flowCode, true, true);
                leadTime = flow.LeadTime.HasValue ? flow.LeadTime.Value : 0M;
                flowList.Add(flowCode);
            }

            Row typeRow = sheet.GetRow(5);
            Row dateRow = sheet.GetRow(6);

            //IList<CustomerSchedule> customerSchedules = customerScheduleMgr.GetCustomerSchedules(flowCode, refScheduleNo, null, null, null);
            //if (customerSchedules.Count > 0)
            //{
            //    throw new BusinessErrorException("MRP.Schedule.Import.CannotImportSameProductionSchedule");
            //}
            #endregion

            #region CustomerSchedule

            IList<CustomerScheduleDetail> customerScheduleDetaiList = new List<CustomerScheduleDetail>();
            #endregion

            ImportHelper.JumpRows(rows, 7);

            #region 列定义
            int colItemCode = 0;//物料代码或参考物料号
            // int colItemDescription = 1;//物料描述
            int colUom = 2;//单位
            int colUc = 3;//单包装
            #endregion

            while (rows.MoveNext())
            {
                Item item = null;
                Uom uom = null;
                decimal? uc = null;
                string itemReference = null;
                string location = null;
                Flow currentFlow = flow;
                string bom = null;

                Row row = (HSSFRow)rows.Current;
                if (!this.CheckValidDataRow(row, 0, 3))
                {
                    break;//边界
                }
                string rowIndex = (row.RowNum + 1).ToString();

                #region 读取物料代码
                try
                {
                    string itemCode = GetCellStringValue(row.GetCell(colItemCode));
                    if (itemCode == null)
                    {
                        throw new BusinessErrorException("MRP.Schedule.Import.ItemCode.Empty", rowIndex);
                    }
                    item = itemMgr.LoadItem(itemCode);
                    if (item == null)
                    {
                        throw new BusinessErrorException("MRP.Schedule.Import.Item.NotExist", rowIndex);
                    }

                    #region 找路线,先找生产,在找销售,找不到就悲剧
                    DetachedCriteria criteria = DetachedCriteria.For(typeof(FlowDetail));
                    criteria.CreateAlias("Flow", "f");
                    criteria.Add(Expression.Eq("f.IsActive", true));
                    criteria.Add(Expression.Or(
                        Expression.And(Expression.Eq("f.FlowStrategy", BusinessConstants.CODE_MASTER_FLOW_STRATEGY_VALUE_MRP),
                        Expression.Eq("f.Type", BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_PRODUCTION)),
                        Expression.Eq("f.Type", BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_DISTRIBUTION)));
                    // criteria.Add(Expression.Eq("f.FlowStrategy", BusinessConstants.CODE_MASTER_FLOW_STRATEGY_VALUE_MRP));
                    criteria.Add(Expression.Eq("Item.Code", item.Code));
                    criteria.AddOrder(Order.Desc("f.Type"));
                    if (flow != null)
                    {
                        criteria.Add(Expression.Eq("f.Code", flow.Code));
                    }
                    IList<FlowDetail> flowDetailList = criteriaMgr.FindAll<FlowDetail>(criteria);
                    if (flowDetailList == null || flowDetailList.Count == 0)
                    {
                        throw new BusinessErrorException("MRP.Schedule.Import.Flow.NotExist", rowIndex);
                    }

                    currentFlow = flowDetailList[0].Flow;
                    location = flowDetailList[0].DefaultLocationFrom.Code;
                    leadTime = currentFlow.LeadTime.HasValue ? currentFlow.LeadTime.Value : 0M;
                    if (currentFlow.Type == BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_PRODUCTION)
                    {
                        bom = flowDetailList[0].Bom != null ? flowDetailList[0].Bom.Code : null;
                    }
                    if (!flowList.Contains(currentFlow.Code))
                    {
                        flowList.Add(currentFlow.Code);
                    }
                    #endregion

                }
                catch (BusinessErrorException ex)
                {
                    throw ex;
                }
                #endregion

                #region 读取单位
                try
                {
                    string uomCode = GetCellStringValue(row.GetCell(colUom));
                    if (uomCode != null)
                    {
                        uom = uomMgr.CheckAndLoadUom(uomCode);
                    }
                }
                catch
                {
                    this.ThrowCommonError(row, colUom);
                }
                #endregion

                #region 读取单包装
                try
                {
                    string uc_ = GetCellStringValue(row.GetCell(colUc));
                    if (uc_ != null)
                    {
                        uc = Convert.ToDecimal(uc_);
                    }
                }
                catch
                {
                    this.ThrowCommonError(row, colUc);
                }
                #endregion

                #region 读取数量
                try
                {
                    for (int i = 4; ; i++)
                    {
                        string periodType = GetCellStringValue(typeRow.GetCell(i));

                        if (periodType != BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_DAY &&
                            periodType != BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_MONTH &&
                            periodType != BusinessConstants.CODE_MASTER_TIME_PERIOD_TYPE_VALUE_WEEK)
                        {
                            break;
                        }
                        Cell dateCell = dateRow.GetCell(i);
                        DateTime? dateCellValue = null;
                        if (dateCell != null && dateCell.CellType == CellType.NUMERIC)
                        {
                            dateCellValue = dateCell.DateCellValue;
                        }
                        else
                        {
                            break;
                        }
                        if (startDate.HasValue && dateCellValue.Value.Date < startDate.Value.Date)
                        {
                            continue;
                        }
                        if (endDate.HasValue && dateCellValue.Value.Date > endDate.Value.Date)
                        {
                            break;
                        }
                        string qtyValue = GetCellStringValue(row.GetCell(i));
                        decimal qty = 0M;
                        if (qtyValue != null)
                        {
                            qty = Convert.ToDecimal(qtyValue);
                        }
                        if (qty < 0M)
                        {
                            throw new BusinessErrorException("MRP.Schedule.Import.Qty.MustGreatThanZero", rowIndex);
                        }
                        else
                        {
                            CustomerScheduleDetail customerScheduleDetail = new CustomerScheduleDetail();
                            customerScheduleDetail.DateFrom = DateTimeHelper.GetStartTime(periodType, dateCellValue.Value);
                            customerScheduleDetail.DateTo = DateTimeHelper.GetEndTime(periodType, dateCellValue.Value);
                            customerScheduleDetail.Item = item.Code;
                            customerScheduleDetail.ItemDescription = item.Description;
                            customerScheduleDetail.ItemReference = itemReference;
                            customerScheduleDetail.Location = location;
                            customerScheduleDetail.Type = periodType;
                            customerScheduleDetail.UnitCount = uc.Value;
                            customerScheduleDetail.Uom = uom.Code;
                            customerScheduleDetail.StartTime = customerScheduleDetail.DateFrom.AddHours(-(double)leadTime);
                            customerScheduleDetail.Qty = qty;
                            customerScheduleDetail.Flow = currentFlow.Code;
                            if (currentFlow.Type == BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_PRODUCTION)
                            {
                                customerScheduleDetail.Bom = bom == null ? item.Code : bom;
                            }
                            customerScheduleDetaiList.Add(customerScheduleDetail);
                        }
                    }
                }
                catch (Exception)
                {
                    throw new BusinessErrorException("MRP.Schedule.Import.Qty.Error", rowIndex);
                }
                #endregion
            }

            #region 建多个客户需求计划
            IList<CustomerSchedule> customerScheduleList = new List<CustomerSchedule>();
            if (flowList.Count > 0)
            {
                foreach (string f in flowList)
                {
                    CustomerSchedule cs = new CustomerSchedule();
                    cs.Flow = f;
                    cs.ReferenceScheduleNo = refScheduleNo;

                    var q = customerScheduleDetaiList.Where<CustomerScheduleDetail>(p => p.Flow == f);

                    var gCustomerScheduleDetails = from c in q.ToList()
                                                   group c by new
                                                   {
                                                       c.DateFrom,
                                                       c.DateTo,
                                                       c.Item,
                                                       c.ItemDescription,
                                                       c.ItemReference,
                                                       c.Location,
                                                       c.Type,
                                                       c.UnitCount,
                                                       c.Uom,
                                                       c.StartTime,
                                                       c.Flow,
                                                       c.Bom
                                                   } into customerScheduleDetail
                                                   select new CustomerScheduleDetail
                                        {

                                            DateFrom = customerScheduleDetail.Key.DateFrom,
                                            DateTo = customerScheduleDetail.Key.DateTo,
                                            Item = customerScheduleDetail.Key.Item,
                                            ItemDescription = customerScheduleDetail.Key.ItemDescription,
                                            ItemReference = customerScheduleDetail.Key.ItemReference,
                                            Location = customerScheduleDetail.Key.Location,
                                            Type = customerScheduleDetail.Key.Type,
                                            UnitCount = customerScheduleDetail.Key.UnitCount,
                                            Uom = customerScheduleDetail.Key.Uom,
                                            StartTime = customerScheduleDetail.Key.StartTime,
                                            Qty = customerScheduleDetail.Sum(p => p.Qty),
                                            Flow = customerScheduleDetail.Key.Flow,
                                            Bom = customerScheduleDetail.Key.Bom
                                        };
                    cs.CustomerScheduleDetails = gCustomerScheduleDetails.OrderBy(c => c.StartTime).ToList<CustomerScheduleDetail>();
                    customerScheduleList.Add(cs);
                }
            }

            #endregion

            return customerScheduleList;
        }
Exemple #21
0
 private void GVDataBind()
 {
     if (this.customerSchedule != null)
     {
         if (this.customerSchedule.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE)
         {
             this.btnDelete.Visible = true;
             this.btnRelease.Visible = true;
             this.btnSave.Visible = true;
             this.btnCancel.Visible = false;
             this.btnImport.Visible = false;
         }
         else if (this.customerSchedule.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT)
         {
             this.btnDelete.Visible = false;
             this.btnRelease.Visible = false;
             this.btnSave.Visible = false;
             this.btnCancel.Visible = true;
             this.btnImport.Visible = false;
         }
         else if (this.customerSchedule.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CANCEL)
         {
             this.btnDelete.Visible = false;
             this.btnRelease.Visible = false;
             this.btnSave.Visible = false;
             this.btnCancel.Visible = false;
             this.btnImport.Visible = false;
         }
         else
         {
             this.btnDelete.Visible = false;
             this.btnRelease.Visible = false;
             this.btnSave.Visible = true;
             this.btnCancel.Visible = false;
             this.btnImport.Visible = true;
         }
     }
     else
     {
         this.customerSchedule = new CustomerSchedule();
         this.customerSchedule.CustomerScheduleDetails = new List<CustomerScheduleDetail>();
         this.btnSave.Visible = true;
         this.btnImport.Visible = true;
     }
     this.GV_List_Detail.DataSource = this.customerSchedule.CustomerScheduleDetails;
     this.GV_List_Detail.Visible = true;
     this.GV_List_Detail.DataBind();
     this.ltllegend.Text = customerSchedule.ReferenceScheduleNo;
     this.div_List_Detail.Visible = this.customerSchedule.CustomerScheduleDetails.Count > 0;
     if (customerSchedule.CustomerScheduleDetails.Count > 500)
     {
         ShowWarningMessage("Common.ListCount.Warning.GreatThan500");
     }
 }
 public virtual void DeleteCustomerSchedule(CustomerSchedule entity)
 {
     entityDao.DeleteCustomerSchedule(entity);
 }
 public override void UpdateCustomerSchedule(CustomerSchedule customerSchedule)
 {
     customerSchedule.LastModifyDate = DateTime.Now;
     base.UpdateCustomerSchedule(customerSchedule);
     if (customerSchedule.CustomerScheduleDetails != null)
     {
         foreach (CustomerScheduleDetail customerScheduleDetail in customerSchedule.CustomerScheduleDetails)
         {
             customerScheduleDetailMgr.UpdateCustomerScheduleDetail(customerScheduleDetail);
         }
     }
 }
 public virtual void CreateCustomerSchedule(CustomerSchedule entity)
 {
     entityDao.CreateCustomerSchedule(entity);
 }
 public virtual void UpdateCustomerSchedule(CustomerSchedule entity)
 {
     entityDao.UpdateCustomerSchedule(entity);
 }
Exemple #26
0
 protected void btnRelease_Click(object sender, EventArgs e)
 {
     try
     {
         if (this.customerSchedule != null && this.customerSchedule.Id > 0)
         {
             TheCustomerScheduleMgr.ReleaseCustomerSchedule(this.customerSchedule.Id, this.CurrentUser.Code);
             this.customerSchedule = TheCustomerScheduleMgr.LoadCustomerSchedule(this.customerSchedule.Id, true);
             ShowSuccessMessage("MRP.Schedule.Release.Successfully");
             this.backClickEvent(this, e);
         }
     }
     catch (BusinessErrorException ex)
     {
         ShowErrorMessage(ex);
     }
 }
Exemple #27
0
 private void Awake()
 {
     _schedule = GetComponent <CustomerSchedule>();
     _spawner  = GetComponent <CustomerSpawner>();
 }
 private void Start()
 {
     _schedule = GetComponent <CustomerSchedule>();
 }
 public virtual void UpdateCustomerSchedule(CustomerSchedule entity)
 {
     Update(entity);
 }
 public virtual void DeleteCustomerSchedule(CustomerSchedule entity)
 {
     Delete(entity);
 }
 public virtual void CreateCustomerSchedule(CustomerSchedule entity)
 {
     Create(entity);
 }
Exemple #32
0
        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;
            }
        }