Example #1
0
        static void SetSecondNumberByNumber(ProduceOutput dmo)
        {
            foreach (ProduceOutput_Detail detail in dmo.Details)
            {
                DmoUtil.RefreshDependency(detail, "Goods_ID");
                if (detail.Goods_UnitConvertDirection == null)
                {
                    continue;
                }

                if (detail.Goods_UnitConvertDirection == 主辅转换方向.双向转换 || detail.Goods_UnitConvertDirection == 主辅转换方向.由主至辅)
                {
                    //辅单位数量
                    if (detail.Goods_MainUnitRatio != null && detail.Goods_SecondUnitRatio != null)
                    {
                        detail.SecondNumber = detail.Number * detail.Goods_SecondUnitRatio / detail.Goods_MainUnitRatio;
                    }
                    //辅单位Ⅱ数量
                    if (detail.Goods_SecondUnitII_MainUnitRatio != null && detail.Goods_SecondUnitII_SecondUnitRatio != null)
                    {
                        detail.SecondNumber2 = detail.Number * detail.Goods_SecondUnitII_SecondUnitRatio / detail.Goods_SecondUnitII_MainUnitRatio;
                    }
                }
            }
        }
Example #2
0
        public static long CreateOutPut(ProduceOutput output)
        {
            using (var session = Dmo.NewSession())
            {
                var bl = BIFactory.Create <IProduceOutputBL>(session);

                output.Domain_ID = DomainContext.Current.ID;

                foreach (var detail in output.Details)
                {
                    if (detail.Goods_ID == 0)
                    {
                        var goodsid = GetGoodsIdByName(session, detail.Goods_Name);
                        if (goodsid == null || goodsid == 0)
                        {
                            throw new Exception("没有找到计数名称:" + detail.Goods_Name + " 对应的存货");
                        }
                        detail.Goods_ID = goodsid.Value;
                    }
                }

                bl.Insert(output);
                return(output.ID);
            }
        }
Example #3
0
        public static long Insert(ProduceOutput dmo)
        {
            var bl = BIFactory.Create <IProduceOutputBL>();

            bl.InitNewDmo(dmo);
            bl.Insert(dmo);
            return(dmo.ID);
        }
Example #4
0
        public static long CreateOutPutByJson2(string json)
        {
            var dto = JsonConvert.DeserializeObject <OutPutDto>(json);

            using (var session = Dmo.NewSession())
            {
                var bl  = BIFactory.Create <IProduceOutputBL>(session);
                var dmo = new ProduceOutput();

                dmo.Domain_ID         = DomainContext.Current.ID;
                dmo.AccountingUnit_ID = dto.AccountingUnit_ID;
                dmo.Department_ID     = dto.Department_ID;
                dmo.ProductionUnit_ID = dto.ProductionUnit_ID;
                dmo.Time = dto.Time;

                foreach (var dtodetail in dto.Details)
                {
                    var detail = new ProduceOutput_Detail();
                    detail.Goods_ID          = dtodetail.Goods_ID ?? 0;
                    detail.CalculateGoods_ID = dtodetail.CalculateGoods_ID;
                    detail.Goods_Name        = dtodetail.Goods_Name;
                    detail.Remark            = dtodetail.CalculateSpec_Name;
                    detail.Number            = dtodetail.Number;
                    detail.SecondNumber      = dtodetail.SecondNumber;
                    detail.SecondNumber2     = dtodetail.SecondNumber2;
                    detail.RecordCount       = dtodetail.RecordCount;
                    //detail.CalculateCatalog_Name = dtodetail.CalculateCatalog_Name;
                    //var calculateCatalog = GetCalculateCatalogIDByName(session, detail.Goods_Name);
                    //if (calculateCatalog != null)
                    //{
                    //    detail.CalculateCatalog_ID = calculateCatalog.Item1;
                    //    detail.CalculateGoods_ID = calculateCatalog.Item2;
                    //}
                    if (detail.Goods_ID == 0)
                    {
                        var goodsid = GetGoodsIdByName2(session, detail.Goods_Name);
                        if (goodsid == null || goodsid == 0)
                        {
                            throw new Exception("没有找到存货名称:" + detail.Goods_Name + " 对应的存货");
                        }
                        detail.Goods_ID = goodsid.Value;
                    }
                    var id = GetProductIdByName(session, dtodetail.PlanNumber);
                    if (id == null)
                    {
                        throw new Exception("生产计划中不存在" + dtodetail.PlanNumber + "计划号");
                    }
                    detail.PlanNumber_ID = id;

                    dmo.Details.Add(detail);
                }

                bl.Insert(dmo);

                session.Commit();
                return(dmo.ID);
            }
        }
Example #5
0
        public static long PdaInsert(ProduceOutput dmo)
        {
            using (var context = new TransactionContext())
            {
                var bl = BIFactory.Create <IProduceOutputBL>(context.Session);
                dmo.Time          = DateTime.Today;
                dmo.IsHandsetSend = true;
                dmo.Employee_ID   = B3ButcheryUtil.GetCurrentBindingEmployeeID(context.Session);
                //        bl.InitNewDmo(dmo); 板块信息由手持机传入
                bl.Insert(dmo);
                bl.Check(dmo);
                context.Commit();
            }

            return(dmo.ID);
        }
Example #6
0
        public static long PdaInsertAndCheck(ProduceOutput dmo)
        {
            SetSecondNumberByNumber(dmo);
            using (var context = new TransactionContext())
            {
                var bl = BIFactory.Create <IProduceOutputBL>(context.Session);
                dmo.Time = dmo.Time ?? DateTime.Today;

                dmo.Employee_ID = B3ButcheryUtil.GetCurrentBindingEmployeeID(context.Session);
                bl.InitNewDmo(dmo);
                bl.Insert(dmo);
                bl.Check(dmo);
                context.Commit();
            }

            return(dmo.ID);
        }
Example #7
0
 public static void InsertProduceOutput(ProduceOutput dmo)
 {
     using (var context = new TransactionContext())
     {
         foreach (var d in dmo.Details)
         {
             d.Price = 0;
             d.Money = 0;
         }
         var bl = BIFactory.Create <IProduceOutputBL>(context);
         dmo.Time          = BLContext.Today;
         dmo.BillState     = 单据状态.已审核;
         dmo.IsHandsetSend = true;
         bl.Insert(dmo);
         context.Commit();
     }
 }
Example #8
0
        static void LoadDetail(ProduceOutput dmo)
        {
            if (dmo.ProductLinkTemplate_ID == null)
            {
                throw new ArgumentException("请先选择生产环节模板");
            }
            var bill = new JoinAlias(typeof(ProductLinkTemplate));
            var productLinkDetail = new JoinAlias(typeof(ProductLinkTemplate_Detail));
            var query             = new DQueryDom(productLinkDetail);

            query.From.AddJoin(JoinType.Left, new DQDmoSource(bill), DQCondition.EQ(bill, "ID", productLinkDetail, "ProductLinkTemplate_ID"));
            query.Columns.Add(DQSelectColumn.Field("Goods_ID", productLinkDetail));
            query.Columns.Add(DQSelectColumn.Field("Goods_Name", productLinkDetail));
            query.Columns.Add(DQSelectColumn.Field("Goods_Code", productLinkDetail));
            query.Columns.Add(DQSelectColumn.Field("Goods_Spec", productLinkDetail));
            query.Columns.Add(DQSelectColumn.Field("Goods_MainUnitRatio", productLinkDetail));
            query.Columns.Add(DQSelectColumn.Field("Goods_SecondUnitRatio", productLinkDetail));
            query.Where.Conditions.Add(DQCondition.EQ(productLinkDetail, "ProductLinkTemplate_ID", dmo.ProductLinkTemplate_ID));
            dmo.Details.Clear();
            using (var context = new TransactionContext())
            {
                using (var reader = context.Session.ExecuteReader(query))
                {
                    while (reader.Read())
                    {
                        var detail = new ProduceOutput_Detail
                        {
                            Goods_ID              = (long)reader[0],
                            Goods_Name            = (string)reader[1],
                            Goods_Code            = (string)reader[2],
                            Goods_Spec            = (string)reader[3],
                            Goods_MainUnitRatio   = (Money <decimal>?)reader[4],
                            Goods_SecondUnitRatio = (Money <decimal>?)reader[5]
                        };
                        dmo.Details.Add(detail);
                    }
                }
            }
        }
Example #9
0
        public static FormData FormActions(string action, FormData data)
        {
            var productOutput = (ProduceOutput)data.MainObject;
            var bl            = BIFactory.Create <IProduceOutputBL>();

            switch (action)
            {
            case FormActionNames.Load:
                var dom = bl.Load(productOutput.ID);
                data.MainObject = dom;
                break;

            case FormActionNames.Save:
                if (productOutput.Details.Count <= 0)
                {
                    LoadDetail(productOutput);
                    //在 save 的 FormAction 里,向客户端返回脚本: "scrollToCollection(0)", 也就是: "0 ()scrollToCollection "
                    data.Codes = "0 ()scrollToCollection ";
                }
                if (productOutput.ID == 0)
                {
                    bl.InitNewDmo(productOutput);
                    bl.Insert(productOutput);
                    data.MainObject = productOutput;
                    //在 save 的 FormAction 里,向客户端返回脚本: "scrollToCollection(0)", 也就是: "0 ()scrollToCollection "
                    data.Codes = "0 ()scrollToCollection ";
                    return(FormActions(FormActionNames.Load, data));
                }
                bl.Update(productOutput);
                return(FormActions(FormActionNames.Load, data));

            case FormActionNames.New:
                var dmo = new ProduceOutput();
                data.MainObject = dmo;
                dmo.Time        = DateTime.Now;
                bl.InitNewDmo(dmo);
                var productPlan = GetProductPlan(dmo.AccountingUnit_ID, dmo.Department_ID, Convert.ToDateTime(Convert.ToDateTime(dmo.Time).ToShortDateString()));
                if (productPlan != null)
                {
                    dmo.PlanNumber_ID   = productPlan.Item1;
                    dmo.PlanNumber_Name = productPlan.Item2;
                }
                break;

            case FormActionNames.Prev:
                var prevDmo = GetPrevOrNext(productOutput.ID);
                if (prevDmo == null)
                {
                    throw new IndexOutOfRangeException("Current is first");
                }
                data.MainObject = prevDmo;
                break;

            case FormActionNames.Next:
                var nextDmo = GetPrevOrNext(productOutput.ID, false);
                if (nextDmo == null)
                {
                    throw new IndexOutOfRangeException("Current is last");
                }
                data.MainObject = nextDmo;
                break;

            case "LoadDetail":
                LoadDetail(productOutput);
                bl.Update(productOutput);
                break;

            case "ReferToCreate":
                data.MainObject = HippoUtil.ReferenceToCreate <ProduceOutput>(productOutput);
                break;

            default:
                throw new ArgumentException("Unknown action: " + action);
            }
            return(data);
        }
Example #10
0
        public void Import(Stream fileStream)
        {
            var man       = new ExcelImportManager();
            var accColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "会计单位",
                Required = true,
                Nullable = false
            });

            var deptColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "部门",
                Required = true,
                Nullable = false
            });

            var empColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "经办人",
                Required = true,
                Nullable = false
            });

            var timeColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "日期",
                Required = true,
                Nullable = false
            });

            var planNumberColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "计划号",
                Required = false,
                Nullable = true
            });

            var productLinksColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "生产环节",
                Required = false,
                Nullable = true
            });
            var remarkColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "摘要",
                Required = false,
                Nullable = true
            });


            var nameColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "存货名称",
                Required = true,
                Nullable = false
            });

            var codeColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "存货编码",
                Required = false,
                Nullable = true
            });

            var numberColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "数量",
                Required = true,
                Nullable = false
            });

            var detailRemarkColumn = man.Add(new ExecelImportColumn()
            {
                Name     = "备注",
                Required = false,
                Nullable = true
            });

            var billList = new DmoCollection <ProduceOutput>();
            int i        = 0;

            using (var context = new TransactionContext()) {
                var bl = BIFactory.Create <IProduceOutputBL>(context);

                foreach (var row in man.Parse(fileStream))
                {
                    var bill = new ProduceOutput();
                    bl.InitNewDmo(bill);
                    i++;
                    bill.ID = i;
                    billList.Add(bill);
                    long accID = default(long);
                    if (accColumn.TryGetIDByName <AccountingUnit>(row, ref accID))
                    {
                        bill.AccountingUnit_ID = accID;
                    }

                    long deptID = default(long);
                    if (deptColumn.TryGetIDByName <Department>(row, ref deptID))
                    {
                        bill.Department_ID = deptID;
                    }

                    long empID = default(long);
                    if (empColumn.TryGetIDByName <Employee>(row, ref empID))
                    {
                        bill.Employee_ID = empID;
                    }

                    long planNumberID = default(long);
                    if (ExecelImportHelper.TryGetID <ProductPlan>(planNumberColumn, row, "PlanNumber", ref planNumberID))
                    {
                        bill.PlanNumber_ID = planNumberID;
                    }

                    long productLinksID = default(long);
                    if (productLinksColumn.TryGetIDByName <ProductLinks>(row, ref productLinksID))
                    {
                        bill.ProductLinks_ID = productLinksID;
                    }

                    DateTime time = default(DateTime);
                    if (timeColumn.TryGetValue(row, ref time))
                    {
                        bill.Time = time;
                    }

                    bill.Remark = remarkColumn.GetStringValue(row);

                    var  detail  = new ProduceOutput_Detail();
                    long goodsID = default(long);
                    if (codeColumn.TryGetIDByCode <Goods>(row, ref goodsID))
                    {
                        detail.Goods_ID = goodsID;
                    }
                    else if (nameColumn.TryGetIDByName <Goods>(row, ref goodsID))
                    {
                        detail.Goods_ID = goodsID;
                    }

                    decimal number = default(decimal);
                    if (numberColumn.TryGetValue(row, ref number))
                    {
                        detail.Number = number;
                    }

                    detail.Remark = detailRemarkColumn.GetStringValue(row);

                    DmoUtil.RefreshDependency(detail, "Goods_ID");
                    ConvertToSecondNumber(detail);
                    bill.Details.Add(detail);
                }

                foreach (var group in billList.GroupBy(x => new { x.Time, x.AccountingUnit_ID, x.Employee_ID, x.Department_ID, x.PlanNumber_ID, x.ProductLinks_ID }))
                {
                    var dmo = group.FirstOrDefault();
                    foreach (var produceOutput in group)
                    {
                        if (dmo.ID == produceOutput.ID)
                        {
                            continue;
                        }
                        foreach (var detail in produceOutput.Details)
                        {
                            dmo.Details.Add(detail);
                        }
                    }
                    dmo.ID = 0;
                    bl.Insert(dmo);
                }
                context.Commit();
            }
        }