Ejemplo n.º 1
0
 public void SaveProductionSet(Sender sender, ProductionSet obj)
 {
     try
     {
         using (ObjectProxy op = new ObjectProxy(true))
         {
             if (op.LoadProductionSet(obj) == 0)
             {
                 obj.Created   = DateTime.Now;
                 obj.CreatedBy = sender.UserCode + "." + sender.UserName;
                 op.InsertProductionSet(obj);
             }
             else
             {
                 obj.Created   = DateTime.Now;
                 obj.CreatedBy = sender.UserCode + "." + sender.UserName;
                 op.UpdateProductionSetBySetID(obj);
             }
             op.CommitTransaction();
         }
     }
     catch (Exception ex)
     {
         PLogger.LogError(ex);
         throw ex;
     }
 }
Ejemplo n.º 2
0
 public List <ProductionSet> GetProductionSetBySetID(Sender sender, Guid SetID)
 {
     try
     {
         using (ObjectProxy op = new ObjectProxy())
         {
             ProductionSet obj = new ProductionSet();
             obj.SetID = SetID;
             return(op.LoadProductionSetBySetID(obj));
         }
     }
     catch (Exception ex)
     {
         PLogger.LogError(ex);
         throw ex;
     }
 }
Ejemplo n.º 3
0
 public ProductionSet GetProductionSet(Sender sender, Guid SetID)
 {
     try
     {
         using (ObjectProxy op = new ObjectProxy())
         {
             ProductionSet obj = new ProductionSet();
             obj.SetID = SetID;
             if (op.LoadProductionSet(obj) == 0)
             {
                 return(null);
             }
             return(obj);
         }
     }
     catch (Exception ex)
     {
         PLogger.LogError(ex);
         throw ex;
     }
 }
Ejemplo n.º 4
0
        public void SaveProductionSet()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    SaveProductionSetArgs args = new SaveProductionSetArgs();
                    ProductionSet         obj  = new ProductionSet();
                    if (!string.IsNullOrEmpty(Request["edit"]))
                    {
                        obj = p.Client.GetProductionSet(SenderUser, parm.SetID);
                    }
                    if (obj == null)
                    {
                        throw new Exception("数据不存在。");
                    }
                    if (string.IsNullOrEmpty(Request["calendars"]))
                    {
                        throw new Exception("参数错误。");
                    }
                    if (string.IsNullOrEmpty(Request["totalareal"]))
                    {
                        throw new Exception("参数错误。");
                    }
                    if (string.IsNullOrEmpty(Request["weeks"]))
                    {
                        throw new Exception("参数错误。");
                    }

                    decimal         Monthtotalareal = decimal.Parse(Request["totalareal"]);//销售预测总量
                    List <Calendar> mainlist        = JsonMapper.ToObject <List <Calendar> >(Request["calendars"]).OrderBy(t => t.datetime).ToList();

                    obj.SetID          = Guid.NewGuid();
                    obj.Started        = mainlist.OrderBy(t => t.datetime).FirstOrDefault().datetime;
                    obj.Ended          = mainlist.OrderByDescending(t => t.datetime).FirstOrDefault().datetime;
                    obj.Weeks          = mainlist.GroupBy(t => t.weekno).Count();
                    obj.Days           = mainlist.Count;
                    obj.TotalAreal     = Monthtotalareal;
                    args.ProductionSet = obj;

                    if (p.Client.ExistsProductionSetDayDetailByDatetime(obj.Started, obj.Ended))
                    {
                        throw new Exception(string.Format("{0}至{1}已有排班设置", obj.Started.ToString("D"), obj.Ended.ToString("D")));
                    }

                    #region 生产订单排单设置周计划详情表
                    List <ProductionSetWeekDetail> weeklist = new List <ProductionSetWeekDetail>();
                    JsonData sj = JsonMapper.ToObject(Request["weeks"]);
                    if (sj.Count > 0)
                    {
                        foreach (JsonData item in sj)
                        {
                            var MaxCapacity               = decimal.Parse(item["MaxCapacity"].ToString());
                            var weekTotalAreal            = obj.TotalAreal * (MaxCapacity / 100);//每周总产量=销售预测总量*周比列
                            ProductionSetWeekDetail model = new ProductionSetWeekDetail()
                            {
                                ID          = Guid.NewGuid(),
                                SetID       = obj.SetID,
                                WeekNo      = int.Parse(item["WeekNo"].ToString()),
                                TotalAreal  = weekTotalAreal,
                                MaxCapacity = MaxCapacity,
                            };
                            weeklist.Add(model);
                        }
                    }
                    var weekCapacity = weeklist.Sum(t => t.MaxCapacity);
                    if (weekCapacity != 100)
                    {
                        throw new Exception(string.Format("比列设置相加必需为100%,当前比列为{0}%", weekCapacity));
                    }
                    var TotalAreal = weeklist.Sum(t => t.TotalAreal);
                    //if (MaxCapacity != 100)
                    //{
                    //    WriteMessage(-1, string.Format("当前周比列设置可排{0}㎡,实际应排{1}㎡", weekstotal, obj.TotalAreal));
                    //    return;
                    //}
                    args.ProductionSetWeekDetails = weeklist.OrderBy(t => t.WeekNo).ToList();

                    #endregion

                    #region 生产订单排单设置日计划详情表

                    List <ProductionSetDayDetail> daylist = new List <ProductionSetDayDetail>();
                    foreach (Calendar Item in mainlist)
                    {
                        //周排产量
                        var weekTotalAreal = weeklist.Where(t => t.WeekNo == Item.weekno).FirstOrDefault().MaxCapacity *obj.TotalAreal;
                        //这周有多少天
                        var daycount = mainlist.Where(t => t.weekno == Item.weekno).Count();
                        //每天排多少
                        var dayTotalAreal = weekTotalAreal / daycount;

                        ProductionSetDayDetail model = new ProductionSetDayDetail()
                        {
                            ID         = Guid.NewGuid(),
                            SetID      = obj.SetID,
                            Datetime   = Item.datetime,
                            TotalAreal = GetRoundParse(dayTotalAreal),
                            //TotalAreal =dayTotalAreal,
                            MadeTotalAreal = 0,
                            WeekNo         = Item.weekno,
                        };
                        daylist.Add(model);
                    }
                    var daytotal = daylist.Sum(t => t.TotalAreal);

                    args.ProductionSetDayDetails = daylist.OrderBy(t => t.Datetime).ToList();
                    #endregion

                    p.Client.SaveProductionSets(SenderUser, args);
                }
                WriteSuccess();
            }
            catch (Exception ex)
            {
                //Response.Write(ex.Message);
                WriteError(ex.Message, ex);
            }
        }