예제 #1
0
        public void GetweekManual()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    if (string.IsNullOrEmpty(Request["totalareal"]))
                    {
                        throw new Exception("参数错误");
                    }
                    if (string.IsNullOrEmpty(Request["weeks"]))
                    {
                        throw new Exception("参数错误");
                    }
                    if (string.IsNullOrEmpty(Request["calendars"]))
                    {
                        throw new Exception("参数错误");
                    }
                    List <WeekCapacity> list            = new List <WeekCapacity>();
                    decimal             Monthtotalareal = decimal.Parse(Request["totalareal"]);
                    List <Calendar>     mainlist        = JsonMapper.ToObject <List <Calendar> >(Request["calendars"]).OrderBy(t => t.datetime).ToList();
                    JsonData            sj = JsonMapper.ToObject(Request["weeks"]);
                    if (sj.Count > 0)
                    {
                        foreach (JsonData item in sj)
                        {
                            var WeekNo         = int.Parse(item["WeekNo"].ToString());
                            var MaxCapacity    = decimal.Parse(item["MaxCapacity"].ToString());   //自定义比列
                            var weekdaycount   = mainlist.Where(t => t.weekno == WeekNo).Count(); //这周有多少天
                            var weekTotalAreal = Monthtotalareal * (MaxCapacity / 100);           //这周总量
                            var dayTotalAreal  = weekTotalAreal / weekdaycount;                   //每天排多少

                            WeekCapacity model = new WeekCapacity()
                            {
                                weekno       = int.Parse(item["WeekNo"].ToString()),
                                weekdaycount = weekdaycount,
                                maxcapacity  = MaxCapacity,
                                totalareal   = GetRoundParse(weekTotalAreal),
                                dayaverage   = GetRoundParse(dayTotalAreal),
                            };
                            list.Add(model);
                        }
                    }
                    var weekCapacity = list.Sum(t => t.maxcapacity);
                    if (weekCapacity != 100)
                    {
                        throw new Exception(string.Format("比列设置相加必需为100%,当前比列为{0}%", weekCapacity));
                    }
                    string json = JSONHelper.List2DataSetJson(list);
                    Response.Write(json);
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
예제 #2
0
        public void GetweekAverage()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    if (string.IsNullOrEmpty(Request["totalareal"]))
                    {
                        throw new Exception("参数错误");
                    }
                    if (string.IsNullOrEmpty(Request["calendars"]))
                    {
                        throw new Exception("参数错误");
                    }
                    List <WeekCapacity> list = new List <WeekCapacity>();

                    decimal Monthtotalareal = decimal.Parse(Request["totalareal"]);//销售预测总量

                    List <Calendar> mainlist = JsonMapper.ToObject <List <Calendar> >(Request["calendars"]).OrderBy(t => t.datetime).ToList();

                    var dayAverage = Monthtotalareal / mainlist.Count;                                             //所有工作日平均分配多少

                    var weeklist = mainlist.GroupBy(a => a.weekno).Select(g => (new { weekno = g.Key })).ToList(); //总工有几周

                    #region 周运算
                    for (var i = 0; i < weeklist.Count; i++)
                    {
                        var weekdaycount = mainlist.Where(t => t.weekno == weeklist[i].weekno).Count(); //这周有多少天
                        var Totalareal   = dayAverage * weekdaycount;                                   //每周总量
                        var Maxcapacity  = Totalareal / Monthtotalareal;                                //建议比列=每周总量/销售预测总量

                        WeekCapacity model = new WeekCapacity()
                        {
                            weekno       = weeklist[i].weekno,
                            weekdaycount = weekdaycount,
                            maxcapacity  = GetRoundParse(Maxcapacity * 100),
                            totalareal   = GetRoundParse(Totalareal),
                            dayaverage   = GetRoundParse(dayAverage),
                        };
                        list.Add(model);
                    }
                    #endregion

                    string json = JSONHelper.List2DataSetJson(SetWeekCapacityByList(list));
                    Response.Write(json);
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }