예제 #1
0
        public void CreateRccpPlan(CodeMaster.TimeUnit dateType, List<RccpPlanLog> rccpPlanLogList)
        {
            var flowStategyDic = new Dictionary<string, FlowStrategy>();
            var flowCodes = rccpPlanLogList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct();
            if (flowCodes != null && flowCodes.Count() > 0)
            {
                flowStategyDic = this.genericMgr.FindAllIn<FlowStrategy>
                 (" from FlowStrategy where Flow in(? ", rccpPlanLogList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct())
                 .ToDictionary(d => d.Flow, d => d);
            }

            var user = SecurityContextHolder.Get();
            var oldRccpPlanDic = (this.genericMgr.FindAllIn<RccpPlan>
                    ("from RccpPlan as w where w.DateType = ? and w.DateIndexTo in(?",
                    rccpPlanLogList.Select(p => p.DateIndexTo).Distinct(), new object[] { dateType }) ?? new List<RccpPlan>())
                    .GroupBy(p => p.Item, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g.ToList());

            int planVersion = 0;
            if (dateType == CodeMaster.TimeUnit.Month)
            {
                planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_MONTHLYPLAN));
            }
            else if (dateType == CodeMaster.TimeUnit.Week)
            {
                planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_WEEKLYPLAN));
            }
            else if (dateType == CodeMaster.TimeUnit.Day)
            {
                planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_DAILYLYPLAN));
            }

            foreach (var rccpPlanLog in rccpPlanLogList)
            {
                string dateIndexFrom = rccpPlanLog.DateIndexTo;
                if (!string.IsNullOrWhiteSpace(rccpPlanLog.Flow))
                {
                    var flowStategy = flowStategyDic.ValueOrDefault(rccpPlanLog.Flow);
                    if (flowStategy != null)
                    {
                        decimal _leadTime = dateType == CodeMaster.TimeUnit.Day ? flowStategy.LeadTime : flowStategy.RccpLeadTime;
                        double leadTime = Math.Round(DateTimeHelper.TimeTranfer(_leadTime, flowStategy.TimeUnit, CodeMaster.TimeUnit.Day));
                        if (leadTime > 0)
                        {
                            if (dateType == CodeMaster.TimeUnit.Day)
                            {
                                dateIndexFrom = DateTime.Parse(rccpPlanLog.DateIndex).AddDays(-leadTime).ToString("yyyy-MM-dd");
                            }
                            else if (dateType == CodeMaster.TimeUnit.Week)
                            {
                                dateIndexFrom = Utility.DateTimeHelper.GetWeekOfYear(
                                    Utility.DateTimeHelper.GetWeekIndexDateFrom(rccpPlanLog.DateIndex).AddDays(3 - leadTime)
                                    );
                            }
                            else if (dateType == CodeMaster.TimeUnit.Month)
                            {
                                dateIndexFrom = DateTime.Parse(rccpPlanLog.DateIndex + "-15").AddDays(-leadTime).ToString("yyyy-MM");
                            }
                        }
                    }
                }

                var oldRccpPlans = (oldRccpPlanDic.ValueOrDefault(rccpPlanLog.Item) ?? new List<RccpPlan>())
                    .Where(p => p.DateIndex == rccpPlanLog.DateIndex && p.Flow == rccpPlanLog.Flow && p.DateType == rccpPlanLog.DateType);
                if (oldRccpPlans.Count() == 0)
                {
                    #region New RccpPlan
                    var rccpPlan = new RccpPlan();
                    rccpPlan.DateIndex = dateIndexFrom;
                    rccpPlan.DateIndexTo = rccpPlanLog.DateIndexTo;
                    rccpPlan.Item = rccpPlanLog.Item;
                    rccpPlan.Flow = rccpPlanLog.Flow;
                    rccpPlan.Qty = rccpPlanLog.Qty * (double)rccpPlanLog.UnitQty;
                    rccpPlan.PlanVersion = planVersion;
                    rccpPlan.DateType = dateType;

                    this.genericMgr.Create(rccpPlan);
                    #endregion

                    #region New RccpPlanLog
                    rccpPlanLog.PlanId = rccpPlan.Id;
                    rccpPlanLog.PlanVersion = planVersion;
                    rccpPlanLog.DateIndex = dateIndexFrom;
                    rccpPlanLog.DateType = dateType;
                    rccpPlanLog.CreateDate = System.DateTime.Now;
                    rccpPlanLog.CreateUserId = user.Id;
                    rccpPlanLog.CreateUserName = user.FullName;
                    this.genericMgr.Create(rccpPlanLog);
                    #endregion
                }
                else if (oldRccpPlans.Count() == 1)
                {
                    var oldRccpPlan = oldRccpPlans.First();
                    if (oldRccpPlan.Qty != rccpPlanLog.Qty * (double)rccpPlanLog.UnitQty
                        || oldRccpPlan.Flow != rccpPlanLog.Flow)
                    {
                        oldRccpPlan.Qty = rccpPlanLog.Qty * (double)rccpPlanLog.UnitQty;
                        oldRccpPlan.DateIndex = dateIndexFrom;
                        oldRccpPlan.PlanVersion = planVersion;
                        oldRccpPlan.Flow = rccpPlanLog.Flow;
                        this.genericMgr.Update(oldRccpPlan);

                        #region New RccpPlanLog
                        rccpPlanLog.PlanId = oldRccpPlan.Id;
                        rccpPlanLog.DateIndex = dateIndexFrom;
                        rccpPlanLog.PlanVersion = planVersion;
                        rccpPlanLog.DateType = dateType;
                        rccpPlanLog.CreateDate = System.DateTime.Now;
                        rccpPlanLog.CreateUserId = user.Id;
                        rccpPlanLog.CreateUserName = user.FullName;
                        this.genericMgr.Create(rccpPlanLog);
                        #endregion
                    }
                }
                else
                {
                    throw new TechnicalException("Error:DateException");
                }
            }
        }
예제 #2
0
        public string GetStringRccpPlanView(IList<RccpPlan> rccpPlanList, int planVersion, string timeType)
        {
            if (rccpPlanList.Count == 0)
            {
                return "没有记录";
            }
            StringBuilder str = new StringBuilder("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"display\" id=\"datatable\" width=\"100%\"><thead><tr>");

            #region Head

            str.Append("<th>");
            str.Append(Resources.MRP.RccpPlan.RccpPlan_Flow);
            str.Append("</th>");

            str.Append("<th>");
            str.Append(Resources.MRP.RccpPlan.RccpPlan_Item);
            str.Append("</th>");

            str.Append("<th>");
            str.Append(Resources.MRP.RccpPlan.RccpPlan_ItemDescription);
            str.Append("</th>");

            str.Append("<th>");
            str.Append(Resources.MRP.RccpPlan.RccpPlan_Uom);
            str.Append("</th>");

            var dateIndexs = new List<string>();
            if (timeType == "WindowTime")
            {
                dateIndexs = rccpPlanList.Select(p => p.DateIndexTo).Distinct().OrderBy(p => p).ToList();
            }
            else
            {
                dateIndexs = rccpPlanList.Select(p => p.DateIndex).Distinct().OrderBy(p => p).ToList();
            }

            foreach (var dateIndex in dateIndexs)
            {
                str.Append("<th style='min-width:50px'>");
                str.Append(dateIndex);
                str.Append("</th>");
            }

            str.Append("</tr></thead><tbody>");
            #endregion

            #region
            IList<object[]> planLogs = new List<object[]>();
            if (planVersion > 0)
            {
                var sql = string.Empty;
                if (timeType == "WindowTime")
                {
                    sql = @"SELECT T.PlanId,T.Qty FROM
                         (select distinct(PlanId) from MRP_RccpPlanLog where PlanVersion <=? and DateType=? and DateIndexTo between ? and ?) AS E
                          CROSS APPLY (SELECT TOP(1)* FROM MRP_RccpPlanLog AS T1 WHERE E.PlanId = T1.PlanId ORDER BY T1.PlanVersion DESC) AS T";
                }
                else
                {
                    sql = @"SELECT T.PlanId,T.Qty FROM
                         (select distinct(PlanId) from MRP_RccpPlanLog where PlanVersion <=? and DateType=? and DateIndex between ? and ?) AS E
                          CROSS APPLY (SELECT TOP(1)* FROM MRP_RccpPlanLog AS T1 WHERE E.PlanId = T1.PlanId ORDER BY T1.PlanVersion DESC) AS T";
                }

                planLogs = this.genericMgr.FindAllWithNativeSql<object[]>(sql, new object[] { planVersion, rccpPlanList[0].DateType, dateIndexs.Min(), dateIndexs.Max() });
            }
            var planLogDic = planLogs.ToDictionary(d => (int)d[0], d => (double)d[1]);

            var rccpPlanListGruopby = from r in rccpPlanList
                                      orderby r.Item
                                      group r by
                                      new
                                      {
                                          Flow = r.Flow,
                                          Item = r.Item,
                                      } into g
                                      select new
                                      {
                                          Flow = g.Key.Flow,
                                          Item = g.Key.Item,
                                          List = g
                                      };
            int l = 0;
            foreach (var groupPlan in rccpPlanListGruopby)
            {
                Item newItem = itemMgr.GetCacheItem(groupPlan.Item);

                l++;
                if (l % 2 == 0)
                {
                    str.Append("<tr class=\"t-alt\">");
                }
                else
                {
                    str.Append("<tr>");
                }


                str.Append("<td style=\"text-align:center\">");
                str.Append(groupPlan.Flow);
                str.Append("</td>");

                str.Append("<td style=\"text-align:center\">");
                str.Append(groupPlan.Item);
                str.Append("</td>");
                str.Append("<td>");
                str.Append(newItem.Description);
                str.Append("</td>");

                str.Append("<td>");
                str.Append(newItem.Uom);
                str.Append("</td>");

                #region
                foreach (var dateIndex in dateIndexs)
                {
                    var rccpPlanFirst = new RccpPlan();
                    if (timeType == "WindowTime")
                    {
                        rccpPlanFirst = groupPlan.List.FirstOrDefault(m => m.DateIndexTo == dateIndex);
                    }
                    else
                    {
                        rccpPlanFirst = groupPlan.List.FirstOrDefault(m => m.DateIndex == dateIndex);
                    }

                    if (rccpPlanFirst != null)
                    {
                        if (planVersion > 0)
                        {
                            //var rccpPlanLog = this.genericMgr.FindAll<RccpPlanLog>
                            //    ("from RccpPlanLog where PlanId=?  and PlanVersion <=? order by PlanVersion desc",
                            //    new object[] { 
                            //            rccpPlanFirst.Id,
                            //            planVersion
                            //        }, 0, 1).FirstOrDefault();
                            var qty = planLogDic.ValueOrDefault(rccpPlanFirst.Id);
                            if (qty != rccpPlanFirst.Qty)
                            {
                                str.Append("<td style=\"background:#FFF2F2;\">");
                            }
                            else
                            {
                                str.Append("<td>");
                            }
                            str.Append(qty);
                            str.Append("</td>");
                        }
                        else
                        {
                            str.Append("<td>");
                            str.Append(rccpPlanFirst.Qty);
                            str.Append("</td>");
                        }
                    }
                    else
                    {
                        str.Append("<td>");
                        str.Append("0");
                        str.Append("</td>");
                    }
                }

                #endregion

                str.Append("</tr>");
            }
            #endregion

            //表尾
            str.Append("</tbody>");
            str.Append("</table>");
            return str.ToString();
        }
예제 #3
0
        public ActionResult _Update(GridCommand command, RccpPlan rccpPlan, string importTypeTo, string startMonthTo
            , string endMonthTo, string startWeekTo, string endWeekTo, string itemTo, DateTime? startDate, DateTime? endDate)
        {
            RccpPlanSearchModel searchModel = new RccpPlanSearchModel();
            searchModel.ImportType = importTypeTo;

            searchModel.Item = itemTo;
            searchModel.StartMonth = startMonthTo;
            searchModel.EndMonth = endMonthTo;
            searchModel.StartWeek = startWeekTo;
            searchModel.EndWeek = endWeekTo;
            searchModel.StartDate = startDate;
            searchModel.EndDate = endDate;

            RccpPlan newRccpPlan = genericMgr.FindById<RccpPlan>(rccpPlan.Id);
            if (rccpPlan.Qty != newRccpPlan.Qty)
            {
                newRccpPlan.Qty = rccpPlan.Qty;
                genericMgr.Update(newRccpPlan);
                var rccpPlanLog = genericMgr.FindAll<RccpPlanLog>
                    (" from RccpPlanLog where PlanId =? and PlanVersion = ?", new object[] { rccpPlan.Id, rccpPlan.PlanVersion }).First();
                rccpPlanLog.Qty = rccpPlan.Qty;
                rccpPlanLog.UnitQty = 1;
                this.genericMgr.Update(rccpPlanLog);
            }

            SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
            return PartialView(GetAjaxPageData<RccpPlan>(searchStatementModel, command));
        }