Example #1
0
    private void GV_List_DataBind(ScheduleView scheduleView)
    {
        this.fld_Group.Visible = true;
        IList<ScheduleBody> scheduleBodys = scheduleView.ScheduleBodys;
        IList<ScheduleHead> scheduleHeads = scheduleView.ScheduleHeads;

        if (scheduleHeads != null && scheduleHeads.Count > 0)
        {
            int i = 0;
            foreach (ScheduleHead scheduleHead in scheduleHeads)
            {
                string qty = "Qty" + i.ToString();

                PropertyInfo[] scheduleBodyPropertyInfo = typeof(ScheduleBody).GetProperties();
                foreach (PropertyInfo pi in scheduleBodyPropertyInfo)
                {
                    if (pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), qty))
                    {
                        BoundField bfColumn = new BoundField();
                        bfColumn.DataField = qty;
                        bfColumn.DataFormatString = "{0:0.##}";
                        bfColumn.HeaderText = scheduleHead.DateHead;
                        this.GV_List.Columns.Add(bfColumn);
                        break;
                    }
                }
                i++;
            }
            this.ltl_GV_List_Result.Visible = false;
        }
        else
        {
            this.ltl_GV_List_Result.Visible = true;
        }

        this.GV_List.DataSource = scheduleBodys;
        this.GV_List.DataBind();
    }
Example #2
0
    private void GV_List_DataBind(ScheduleView scheduleView)
    {
        for (int i = this.GV_List.Columns.Count; i > 6; i--)
        {
            this.GV_List.Columns.RemoveAt(this.GV_List.Columns.Count - 1);
        }

        this.div_MRP_Detail.Visible = false;
        this.div_OrderDetail.Visible = false;
        this.fld_Group.Visible = true;

        if (scheduleView == null) return;
        IList<ScheduleBody> scheduleBodys = scheduleView.ScheduleBodys;
        IList<ScheduleHead> scheduleHeads = scheduleView.ScheduleHeads;

        #region add qty column
        if (scheduleHeads != null && scheduleHeads.Count > 0)
        {
            int i = 0;
            foreach (ScheduleHead scheduleHead in scheduleHeads)
            {
                string qty = "Qty" + i.ToString();
                if (enableDiscon)
                {
                    qty = "DisplayQty" + i.ToString();
                }

                PropertyInfo[] scheduleBodyPropertyInfo = typeof(ScheduleBody).GetProperties();
                foreach (PropertyInfo pi in scheduleBodyPropertyInfo)
                {
                    if (pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), qty))
                    {
                        BoundField bfColumn = new BoundField();
                        bfColumn.DataField = qty;
                        bfColumn.DataFormatString = "{0:#,##0.##}";
                        bfColumn.HtmlEncode = false;
                        bfColumn.HeaderText = isWinTime ? scheduleHead.DateTo.ToString("yyyy-MM-dd") : scheduleHead.DateFrom.ToString("yyyy-MM-dd");
                        bfColumn.SortExpression = isWinTime ? scheduleHead.DateTo.ToString("yyyy-MM-dd") : scheduleHead.DateFrom.ToString("yyyy-MM-dd");
                        bfColumn.FooterText = isWinTime ? (scheduleHead.LastDateTo.HasValue ? scheduleHead.LastDateTo.Value.ToString("yyyy-MM-dd") : string.Empty) : (scheduleHead.LastDateFrom.HasValue ? scheduleHead.LastDateFrom.Value.ToString("yyyy-MM-dd") : string.Empty);
                        this.GV_List.Columns.Add(bfColumn);
                        break;
                    }
                }
                i++;
            }
            this.ltl_GV_List_Result.Visible = false;
        }
        else
        {
            this.ltl_GV_List_Result.Visible = true;
        }
        #endregion
        this.GV_List.DataSource = scheduleBodys;
        this.GV_List.DataBind();
        //this.btnSave.Visible = false;
    }
        public ScheduleView TransferCustomerScheduleDetails2ScheduleView(IList<CustomerScheduleDetail> customerScheduleDetails, DateTime effDate)
        {
            customerScheduleDetails = this.GetEffectiveCustomerScheduleDetail(customerScheduleDetails, effDate).ToList();

            #region ͷ
            List<ScheduleHead> scheduleHeads =
               (from det in customerScheduleDetails
                group det by new { det.DateFrom, det.DateTo, det.Type, det.CustomerSchedule.ReleaseDate } into result
                select new ScheduleHead
            {
                DateFrom = result.Key.DateFrom,
                DateTo = result.Key.DateTo,
                Type = result.Key.Type,
                ReleaseDate = result.Key.ReleaseDate
            }).ToList();
            scheduleHeads = scheduleHeads.OrderBy(c => c.DateFrom).Take(41).ToList();
            #endregion

            #region ��ϸ
            List<ScheduleBody> scheduleBodys =
                (from det in customerScheduleDetails
                 group det by new { det.Item, det.Uom, det.UnitCount, det.Location, det.ItemDescription, det.ItemReference } into result
                 select new ScheduleBody
                 {
                     Item = result.Key.Item,
                     Uom = result.Key.Uom,
                     UnitCount = result.Key.UnitCount,
                     Location = result.Key.Location,
                     ItemDescription = result.Key.ItemDescription,
                     ItemReference = result.Key.ItemReference
                 }).ToList();
            #endregion

            #region ��ֵ
            #region ����1
            if (false)
            {
                foreach (CustomerScheduleDetail customerScheduleDetail in customerScheduleDetails)
                {
                    var q_scheduleHeads = scheduleHeads.Where(c => c.DateFrom == customerScheduleDetail.DateFrom
                        && c.DateTo == customerScheduleDetail.DateTo && StringHelper.Eq(c.Type, customerScheduleDetail.Type));
                    if (q_scheduleHeads.Count() == 1)
                    {
                        int index = scheduleHeads.IndexOf(q_scheduleHeads.Single());
                        string qtyIndex = "Qty" + index.ToString();
                        var q_scheduleBodys = scheduleBodys.Where(c => StringHelper.Eq(c.Item, customerScheduleDetail.Item) && c.UnitCount == customerScheduleDetail.UnitCount
                             && StringHelper.Eq(c.Uom, customerScheduleDetail.Uom) && StringHelper.Eq(c.Location, customerScheduleDetail.Location));
                        if (q_scheduleBodys.Count() == 1)
                        {
                            ScheduleBody scheduleBody = q_scheduleBodys.Single();
                            PropertyInfo[] scheduleBodyPropertyInfo = typeof(ScheduleBody).GetProperties();
                            foreach (PropertyInfo pi in scheduleBodyPropertyInfo)
                            {
                                if (pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), qtyIndex))
                                {
                                    pi.SetValue(scheduleBody, customerScheduleDetail.Qty, null);
                                    break;
                                }
                            }
                        }

                    }
                }
            }
            #endregion
            #region ����2
            foreach (ScheduleBody scheduleBody in scheduleBodys)
            {
                int i = 0;
                foreach (ScheduleHead scheduleHead in scheduleHeads)
                {
                    string qty = "Qty" + i.ToString();
                    var q = customerScheduleDetails
                        .Where(c => StringHelper.Eq(c.Item, scheduleBody.Item) && StringHelper.Eq(c.Uom, scheduleBody.Uom) && c.UnitCount == scheduleBody.UnitCount &&
                            c.DateFrom == scheduleHead.DateFrom && c.DateTo == scheduleHead.DateTo && c.Type == scheduleHead.Type);
                    if (q.Count() == 1)
                    {
                        PropertyInfo[] scheduleBodyPropertyInfo = typeof(ScheduleBody).GetProperties();
                        foreach (PropertyInfo pi in scheduleBodyPropertyInfo)
                        {
                            if (pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), qty))
                            {
                                pi.SetValue(scheduleBody, q.Single().Qty, null);
                                break;
                            }
                        }
                    }
                    i++;
                }
            }
            #endregion
            #endregion

            #region ����ȫ����0��
            scheduleBodys = scheduleBodys.Where(s => s.TotalQty > 0).ToList();
            #endregion

            ScheduleView scheduleView = new ScheduleView();
            scheduleView.ScheduleHeads = scheduleHeads;
            scheduleView.ScheduleBodys = scheduleBodys;
            return scheduleView;
        }
        public ScheduleView TransferMrpShipPlanViews2ScheduleView(IList<MrpShipPlanView> mrpShipPlanViews,
            IList<ExpectTransitInventoryView> expectTransitInventoryViews,
            string locOrFlow, string winOrStartTime)
        {
            if (mrpShipPlanViews == null || mrpShipPlanViews.Count == 0)
            {
                return null;
            }
            #region ͷ
            List<ScheduleHead> scheduleHeads = new List<ScheduleHead>();

            if (locOrFlow == "Flow")
            {
                if (winOrStartTime == "WindowTime")
                {
                    scheduleHeads = (from det in mrpShipPlanViews
                                     group det by new { det.Flow, det.FlowType, det.WindowTime } into result
                                     select new ScheduleHead
                                     {
                                         Flow = result.Key.Flow,
                                         Type = result.Key.FlowType,
                                         DateTo = result.Key.WindowTime
                                     }).ToList();
                }
                else
                {
                    scheduleHeads = (from det in mrpShipPlanViews
                                     group det by new { det.Flow, det.FlowType, det.StartTime } into result
                                     select new ScheduleHead
                                     {
                                         Flow = result.Key.Flow,
                                         Type = result.Key.FlowType,
                                         DateFrom = result.Key.StartTime
                                     }).ToList();
                }
            }
            else if (locOrFlow == "Location")
            {
                if (winOrStartTime == "WindowTime")
                {
                    scheduleHeads = (from det in mrpShipPlanViews
                                     group det by new { det.Location, det.WindowTime } into result
                                     select new ScheduleHead
                                     {
                                         Location = result.Key.Location,
                                         Type = "Location",
                                         DateTo = result.Key.WindowTime,
                                     }).ToList();
                }
                else
                {
                    scheduleHeads = (from det in mrpShipPlanViews
                                     group det by new { det.Location, det.StartTime } into result
                                     select new ScheduleHead
                                     {
                                         Location = result.Key.Location,
                                         Type = "Location",
                                         DateFrom = result.Key.StartTime,
                                     }).ToList();
                }
            }
            else
            {
                throw new TechnicalException(locOrFlow);
            }

            if (winOrStartTime == "WindowTime")
            {
                scheduleHeads = scheduleHeads.OrderBy(c => c.DateTo).Take(41).ToList();
            }
            else
            {
                scheduleHeads = scheduleHeads.OrderBy(c => c.DateFrom).Take(41).ToList();
            }
            #endregion

            #region ��ϸ
            List<ScheduleBody> scheduleBodys =
                (from det in mrpShipPlanViews
                 group det by new { det.Item, det.ItemDescription, det.ItemReference, det.Uom, det.UnitCount } into result
                 select new ScheduleBody
                 {
                     Item = result.Key.Item,
                     ItemDescription = result.Key.ItemDescription,
                     ItemReference = result.Key.ItemReference,
                     Uom = result.Key.Uom,
                     UnitCount = result.Key.UnitCount,
                 }).ToList();
            #endregion

            #region ��ֵ
            foreach (ScheduleBody scheduleBody in scheduleBodys)
            {
                int i = 0;
                DateTime? lastDate = null;
                ScheduleHead lastScheduleHead = null;

                foreach (ScheduleHead scheduleHead in scheduleHeads)
                {

                    string qty = "Qty" + i.ToString();
                    string actQty = "ActQty" + i.ToString();
                    string requiredQty = "RequiredQty" + i.ToString();

                    decimal rQty = 0;
                    decimal? aQty = 0;

                    PropertyInfo[] scheduleBodyPropertyInfo = typeof(ScheduleBody).GetProperties().OrderBy(c => c.Name).ToArray();
                    if (locOrFlow == "Location")
                    {
                        if (winOrStartTime == "WindowTime")
                        {
                            rQty = (from plan in mrpShipPlanViews
                                    where plan.Location == scheduleHead.Location
                                    && plan.Item == scheduleBody.Item
                                    && plan.WindowTime == scheduleHead.DateTo
                                    select plan.Qty).Sum();

                            aQty = (from inv in expectTransitInventoryViews
                                    where inv.Location == scheduleHead.Location
                                    && inv.Item == scheduleBody.Item
                                    && inv.WindowTime <= scheduleHead.DateTo
                                    && (!lastDate.HasValue || inv.WindowTime > lastDate.Value)
                                    select inv.TransitQty).Sum();

                        }
                        else if (winOrStartTime == "StartTime")
                        {
                            rQty = (from plan in mrpShipPlanViews
                                    where plan.Location == scheduleHead.Location
                                    && plan.Item == scheduleBody.Item
                                    && plan.StartTime == scheduleHead.DateFrom
                                    select plan.Qty).Sum();

                            aQty = (from inv in expectTransitInventoryViews
                                    where inv.Location == scheduleHead.Location
                                    && inv.Item == scheduleBody.Item
                                    && inv.StartTime <= scheduleHead.DateFrom
                                    && (!lastDate.HasValue || inv.StartTime > lastDate.Value)
                                    select inv.TransitQty).Sum();

                        }
                    }
                    else if (locOrFlow == "Flow")
                    {
                        if (winOrStartTime == "WindowTime")
                        {
                            rQty = (from plan in mrpShipPlanViews
                                    where plan.Flow == scheduleHead.Flow
                                    && plan.Item == scheduleBody.Item
                                    && plan.WindowTime == scheduleHead.DateTo
                                    select plan.Qty).Sum();

                            aQty = (from inv in expectTransitInventoryViews
                                    where inv.Flow == scheduleHead.Flow
                                    && inv.Item == scheduleBody.Item
                                    && inv.WindowTime <= scheduleHead.DateTo
                                    && (!lastDate.HasValue || inv.WindowTime > lastDate.Value)
                                    select inv.TransitQty).Sum();

                        }
                        else if (winOrStartTime == "StartTime")
                        {
                            rQty = (from plan in mrpShipPlanViews
                                    where plan.Flow == scheduleHead.Flow
                                    && plan.Item == scheduleBody.Item
                                    && plan.StartTime == scheduleHead.DateFrom
                                    select plan.Qty).Sum();

                            aQty = (from inv in expectTransitInventoryViews
                                    where inv.Flow == scheduleHead.Flow
                                    && inv.Item == scheduleBody.Item
                                    && inv.StartTime <= scheduleHead.DateFrom
                                    && (!lastDate.HasValue || inv.StartTime > lastDate.Value)
                                    select inv.TransitQty).Sum();

                        }
                    }

                    decimal qQty = (rQty - (aQty.HasValue ? aQty.Value : 0)) > 0 ? (rQty - (aQty.HasValue ? aQty.Value : 0)) : 0;
                    foreach (PropertyInfo pi in scheduleBodyPropertyInfo)
                    {
                        if (pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), actQty))
                        {
                            pi.SetValue(scheduleBody, aQty, null);
                            continue;
                        }
                        if ((aQty.HasValue && aQty.Value > 0 || rQty > 0) && pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), qty))
                        {
                            pi.SetValue(scheduleBody, qQty, null);
                            continue;
                        }
                        if (pi.Name != null && StringHelper.Eq(pi.Name.ToLower(), requiredQty))
                        {
                            pi.SetValue(scheduleBody, rQty, null);
                            break;
                        }

                    }
                    i++;
                    if (winOrStartTime == "WindowTime")
                    {
                        lastDate = scheduleHead.DateTo;
                    }
                    else if (winOrStartTime == "StartTime")
                    {
                        lastDate = scheduleHead.DateFrom;
                    }
                    else
                    {
                        throw new TechnicalException(winOrStartTime);
                    }

                    if (lastScheduleHead != null)
                    {
                        scheduleHead.LastDateTo = lastScheduleHead.DateTo;
                        scheduleHead.LastDateFrom = lastScheduleHead.DateFrom;
                    }
                    lastScheduleHead = scheduleHead;
                }

            }

            #endregion

            ScheduleView scheduleView = new ScheduleView();
            scheduleView.ScheduleHeads = scheduleHeads;
            scheduleView.ScheduleBodys = scheduleBodys;
            return scheduleView;
        }