Beispiel #1
0
        //增加入库单
        public static void AddRKD(Receipt tReceipt, List <ReceiptItems> tItemsList)
        {
            //保存数据,注意使用事务进行处理
            //1、入库单号的生成与修改;2、入库单的增加;3入库单项目的增加
            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try
            {
                //查最后的入库单号
                IList <ProgOptions> Key1 = BLL.ProgOptionsBLL.GetOptions("RKD_LastNumber");
                string s_RKD_LastNo      = Key1[0].OptionsValue;
                string s_RKD_NewNo;
                string s_RKD_LastYM;
                string s_RKD_NewYM;
                int    LastNo;
                int    NewNo;
                string s_NewNo;
                s_RKD_NewYM = DateTime.Today.ToString("yyyyMM");
                if (s_RKD_LastNo.Length == 10)
                {
                    //4位年+2位月+4位顺序号
                    s_RKD_LastYM = s_RKD_LastNo.Substring(0, 6);
                    LastNo       = Convert.ToInt32(s_RKD_LastNo.Substring(6, 4));
                    if (s_RKD_NewYM != s_RKD_LastYM)
                    {
                        NewNo = 1;
                    }
                    else
                    {
                        NewNo = LastNo + 1;
                    }
                }
                else
                {
                    //没有数据
                    NewNo = 1;
                }
                s_NewNo = "0000" + NewNo.ToString();
                s_NewNo = s_NewNo.Substring(s_NewNo.Length - 4, 4);
                //将新的最后编号保存到数据库
                ProgOptions t1 = session.Get <ProgOptions>(Key1[0].OptionsID);
                t1.OptionsID     = Key1[0].OptionsID;
                t1.OptionsKey    = Key1[0].OptionsKey;
                s_RKD_NewNo      = s_RKD_NewYM + s_NewNo;
                t1.OptionsValue  = s_RKD_NewNo;
                t1.OptionsRemark = Key1[0].OptionsRemark;

                //保存入库单
                tReceipt.ReceiptNum = "RKD-" + t1.OptionsValue;
                session.Save(tReceipt);

                //添加应付款

                if (tReceipt.ReceiptDiscAmt != 0)
                {
                    Projects    tP1  = session.Get <Projects>(tReceipt.ProjectID);
                    Companies   tC1  = session.Get <Companies>(tReceipt.CompanyID);
                    AccountBill tAcc = new AccountBill();
                    tAcc.CompanyID     = tReceipt.CompanyID;
                    tAcc.CompanyName   = tC1.CompanyName;
                    tAcc.BillDate      = tReceipt.ReceiptDate;
                    tAcc.BillMemo      = "采购应付款" + tReceipt.ReceiptNum;
                    tAcc.BillType      = 1;
                    tAcc.BillYF        = tReceipt.ReceiptDiscAmt;
                    tAcc.ProjectID     = tReceipt.ProjectID;
                    tAcc.ProjectName   = tP1.ProjectName;
                    tAcc.MoneyTypeID   = 100;                     //材料购买
                    tAcc.MoneyTypeName = "入库单生成";
                    tAcc.BillStatus    = "已记账";
                    session.Save(tAcc);
                }

                foreach (ReceiptItems tRI in tItemsList)
                {
                    //保存进货项
                    ReceiptItems tNewReceiptItems = new ReceiptItems();
                    tNewReceiptItems.GoodsID         = tRI.GoodsID;
                    tNewReceiptItems.ReceiptID       = tReceipt.ReceiptID;
                    tNewReceiptItems.GoodsName       = tRI.GoodsName;
                    tNewReceiptItems.GoodsAmt        = tRI.GoodsAmt;
                    tNewReceiptItems.GoodsPlan       = tRI.GoodsPlan;
                    tNewReceiptItems.GoodsPlanNo     = tRI.GoodsPlanNo;
                    tNewReceiptItems.GoodsPrc        = tRI.GoodsPrc;
                    tNewReceiptItems.GoodsQty        = tRI.GoodsQty;
                    tNewReceiptItems.GoodsSpec       = tRI.GoodsSpec;
                    tNewReceiptItems.GoodsUnit       = tRI.GoodsUnit;
                    tNewReceiptItems.GoodsYF         = tRI.GoodsYF;
                    tNewReceiptItems.GoodsTaxRate    = tRI.GoodsTaxRate;
                    tNewReceiptItems.GoodsNoTaxPrice = tRI.GoodsNoTaxPrice;
                    tNewReceiptItems.MoreSpec        = tRI.MoreSpec;
                    tNewReceiptItems.UsePosition     = tRI.UsePosition;

                    session.Save(tNewReceiptItems);
                }

                //入库单同货品合并
                List <ReceiptItems> mergeList = new List <ReceiptItems>();
                foreach (ReceiptItems tRI in tItemsList)
                {
                    ReceiptItems rtnRItem = mergeList.Find(name =>
                    {
                        if (name.GoodsID == tRI.GoodsID)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    });
                    if (rtnRItem == null)
                    {
                        mergeList.Add(tRI);
                    }
                    else
                    {
                        rtnRItem.GoodsQty += tRI.GoodsQty;
                        rtnRItem.GoodsAmt += tRI.GoodsAmt;
                        if (rtnRItem.GoodsQty != 0)
                        {
                            rtnRItem.GoodsPrc = rtnRItem.GoodsAmt / rtnRItem.GoodsQty;
                        }
                    }
                }

                //更新库存
                foreach (ReceiptItems tRI in mergeList)
                {
                    PKModel pk = new PKModel();
                    pk.GoodsID     = tRI.GoodsID;
                    pk.WareHouseID = tReceipt.WareHouseID;
                    WareHouseStock tWH = session.Get <WareHouseStock>(pk);
                    if (tWH == null)
                    {
                        WareHouseStock tWHNew = new WareHouseStock();
                        tWHNew.Pk = pk;

                        tWHNew.Number    = tRI.GoodsQty;
                        tWHNew.LastPrice = tRI.GoodsPrc;
                        tWHNew.Price     = tRI.GoodsPrc;
                        tWHNew.Amount    = tRI.GoodsAmt;
                        session.Save(tWHNew);
                    }
                    else
                    {
                        tWH.Number   += tRI.GoodsQty;
                        tWH.Amount   += tRI.GoodsAmt;
                        tWH.LastPrice = tRI.GoodsPrc;
                        if (tWH.Number != 0)
                        {
                            tWH.Price = Math.Round(tWH.Amount / tWH.Number, 2);
                        }
                        session.Flush();
                    }
                }
                //事务提交
                tx.Commit();
                session.Close();
            }
            catch (Exception e)
            {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }
Beispiel #2
0
        //增加出库单
        public static void AddCKD(OutStock tOutStock, List <OutStockItems> tItemsList)
        {
            //保存数据,注意使用事务进行处理
            //1、出库单号的生成与修改;2、出库单的增加;3、出库单项目的增加
            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try
            {
                //查最后的出库单号
                IList <ProgOptions> Key1 = BLL.ProgOptionsBLL.GetOptions("CKD_LastNumber");
                string s_CKD_LastNo      = Key1[0].OptionsValue;
                string s_CKD_NewNo;
                string s_CKD_LastYM;
                string s_CKD_NewYM;
                int    LastNo;
                int    NewNo;
                string s_NewNo;
                s_CKD_NewYM = DateTime.Today.ToString("yyyyMM");
                if (s_CKD_LastNo.Length == 10)
                {
                    //4位年+2位月+4位顺序号
                    s_CKD_LastYM = s_CKD_LastNo.Substring(0, 6);
                    LastNo       = Convert.ToInt32(s_CKD_LastNo.Substring(6, 4));
                    if (s_CKD_NewYM != s_CKD_LastYM)
                    {
                        NewNo = 1;
                    }
                    else
                    {
                        NewNo = LastNo + 1;
                    }
                }
                else
                {
                    //没有数据
                    NewNo = 1;
                }
                s_NewNo = "0000" + NewNo.ToString();
                s_NewNo = s_NewNo.Substring(s_NewNo.Length - 4, 4);
                //将新的最后编号保存到数据库
                ProgOptions t1 = session.Get <ProgOptions>(Key1[0].OptionsID);
                t1.OptionsID     = Key1[0].OptionsID;
                t1.OptionsKey    = Key1[0].OptionsKey;
                s_CKD_NewNo      = s_CKD_NewYM + s_NewNo;
                t1.OptionsValue  = s_CKD_NewNo;
                t1.OptionsRemark = Key1[0].OptionsRemark;

                //保存出库单
                tOutStock.OutStockNum = "CKD-" + t1.OptionsValue;
                session.Save(tOutStock);


                //保存出库单项
                foreach (OutStockItems tOI in tItemsList)
                {
                    tOI.OutStockID = tOutStock.OutStockID;
                    session.Save(tOI);
                    //更新库存
                    PKModel pk = new PKModel();
                    pk.GoodsID     = tOI.GoodsID;
                    pk.WareHouseID = tOutStock.WareHouseID;
                    WareHouseStock tWH = session.Get <WareHouseStock>(pk);
                    if (tWH == null)
                    {
                        WareHouseStock tWHNew = new WareHouseStock();
                        tWHNew.Pk = pk;

                        tWHNew.Number = -tOI.GoodsQty;
                        tWHNew.Price  = tOI.GoodsPrc;
                        tWHNew.Amount = -tOI.GoodsAmt;
                        session.Save(tWHNew);
                    }
                    else
                    {
                        tWH.Number -= tOI.GoodsQty;
                        tWH.Amount -= tOI.GoodsAmt;
                        if (tWH.Number != 0)
                        {
                            tWH.Price = Math.Round(tWH.Amount / tWH.Number, 2);
                        }
                        session.Flush();
                    }
                }
                //事务提交
                tx.Commit();
                session.Close();
            }
            catch (Exception e)
            {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }