Esempio n. 1
0
 public ProductionSetDayDetail GetProductionSetDayDetailByMadeTotalAreal(Sender sender, decimal MadeTotalAreal)
 {
     try
     {
         using (ObjectProxy op = new ObjectProxy())
         {
             ProductionSetDayDetail obj = new ProductionSetDayDetail();
             obj.MadeTotalAreal = MadeTotalAreal;
             if (op.LoadProductionSetDayDetailByMadeTotalAreal(obj) == 0)
             {
                 return(null);
             }
             return(obj);
         }
     }
     catch (Exception ex)
     {
         PLogger.LogError(ex);
         throw ex;
     }
 }
Esempio n. 2
0
        public void SchedulingProductionOrder()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    SchedulingProductionOrderArgs args = new SchedulingProductionOrderArgs();

                    if (string.IsNullOrEmpty(Request["ProductionIDs"]))
                    {
                        throw new Exception("参数错误!");
                    }
                    string[] array = Request["ProductionIDs"].TrimEnd(',').Split(',');
                    for (int i = 0; i < array.Length; i++)
                    {
                        Guid            ProductionID    = new Guid(array[i]);
                        ProductionOrder productionorder = p.Client.GetProductionOrder(SenderUser, ProductionID);
                        if (productionorder == null)
                        {
                            throw new Exception(string.Format("订单{0}不存在!", productionorder.OrderNo));
                        }
                        if (productionorder.Status.Trim() != "N")
                        {
                            throw new Exception(string.Format("订单{0}已排单!", productionorder.OrderNo));
                        }

                        List <ProductComponent> componentlist = p.Client.GetProductComponentByOrderID(SenderUser, productionorder.OrderID);
                        if (componentlist.Count < 1)
                        {
                            throw new Exception(string.Format("订单{0}未查询到组件!", productionorder.OrderNo));
                        }
                        int ComponentTypeID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["ComponentTypeID"]);
                        var SumAmount       = componentlist.Where(t => t.ComponentTypeID == ComponentTypeID).ToList().Sum(t => t.Amount);
                        if (SumAmount < 1)
                        {
                            throw new Exception("订单面积有误!");
                        }
                        ProductionSetDayDetail detail = p.Client.GetProductionSetDayDetailByMadeTotalAreal(SenderUser, SumAmount);
                        if (detail == null)
                        {
                            throw new Exception("请先进行排单参数设置!");
                        }
                        //排产记录
                        ProductionOrderScheduling scheduling = new ProductionOrderScheduling()
                        {
                            SchedulingID = Guid.NewGuid(),
                            OrderID      = productionorder.OrderID,
                            ProductionID = ProductionID,
                            DaysDetailID = detail.ID,
                            TotalAreal   = SumAmount,
                        };
                        args.ProductionOrderScheduling = scheduling;

                        //更新已排单量和未排单量
                        detail.MadeTotalAreal       = detail.MadeTotalAreal + SumAmount;
                        args.ProductionSetDayDetail = detail;

                        //更新生产订单状态,预计完工时间
                        productionorder.Status     = ProductionOrderStatus.Y.ToString();
                        productionorder.FinishDate = detail.Datetime;
                        args.ProductionOrder       = productionorder;

                        //订单日志
                        OrderStepLog ot = new OrderStepLog();
                        ot.StepID         = Guid.NewGuid();
                        ot.OrderID        = scheduling.OrderID;
                        ot.StepNo         = 0;
                        ot.StepName       = "订单已排单";
                        ot.Remark         = string.Format("预计完工日期:{0}", detail.Datetime.ToString("D"));
                        args.OrderStepLog = ot;

                        p.Client.SchedulingProductionOrder(SenderUser, args);
                    }
                }
                WriteSuccess();
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
Esempio n. 3
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);
            }
        }