Beispiel #1
0
        //删除出库单
        public static void DelCKD(int i_OutStockID)
        {
            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try
            {
                OutStock toDel1 = session.Get <OutStock>(i_OutStockID);


                //删除OutStockItem中的相关项
                List <int> toDelItemsID = BLL.CKBLL.GetItemIDs(toDel1.OutStockID);
                foreach (int i in toDelItemsID)
                {
                    OutStockItems toDel2 = session.Get <OutStockItems>(i);
                    session.Delete(toDel2);
                    //更新库存
                    PKModel pk = new PKModel();
                    pk.GoodsID     = toDel2.GoodsID;
                    pk.WareHouseID = toDel1.WareHouseID;
                    WareHouseStock tWH = session.Get <WareHouseStock>(pk);
                    if (tWH != null)
                    {
                        tWH.Number += toDel2.GoodsQty;
                        tWH.Amount += toDel2.GoodsAmt;
                        if (tWH.Number != 0)
                        {
                            tWH.Price = Math.Round(tWH.Amount / tWH.Number, 2);
                        }
                        else
                        {
                            tWH.Price = 0;
                        }
                    }
                }
                session.Delete(toDel1);
                //事务提交
                tx.Commit();
                session.Close();
            }
            catch (Exception e)
            {
                Debug.Assert(false, e.Message);
                tx.Rollback();
                session.Close();
            }
        }
Beispiel #2
0
        void ModifyOutStock()
        {
            //修改数据,用事务处理
            OutStock tR = new OutStock();

            tR.OutStockID  = Convert.ToInt32(textBoxID.Text);
            tR.OutStockNum = textBoxNumber.Text;

            tR.OutStockDate = dateTimePickerRKDate.Value;
            tR.ProjectID    = Convert.ToInt32(comboBoxProjectID.SelectedValue.ToString());
            tR.CompanyID    = Convert.ToInt32(comboBoxCompanyID.SelectedValue.ToString());
            tR.WareHouseID  = Convert.ToInt32(comboBoxWareHouseID.SelectedValue.ToString());
            int    i_OutStockType = 0;
            string tS1            = comboBoxOutStockType.Text;

            switch (tS1)
            {
            case "领料出库":
                i_OutStockType = 0;
                break;

            case "领料退货":
                i_OutStockType = 1;
                break;

            case "物资借出":
                i_OutStockType = 2;
                break;

            case "物资归还":
                i_OutStockType = 3;
                break;

            case "报损出库":
                i_OutStockType = 4;
                break;

            case "报损归还":
                i_OutStockType = 5;
                break;

            default:
                break;
            }
            tR.OutStockType = i_OutStockType;

            tR.OutBillAmt    = dTotal;
            tR.OutBillRemark = waterTextBoxRemark.Text;
            List <OutStockItems> tItems = new List <OutStockItems>();

            int row = dataGridView1.Rows.Count;            //得到总行数

            for (int i = 0; i < row - 1; i++)
            {
                //最后一行是新行,不算
                OutStockItems tItem;
                tItem             = new OutStockItems();
                tItem.GoodsID     = Convert.ToInt32(dataGridView1.Rows[i].Cells["GoodsID"].Value);
                tItem.GoodsQty    = Convert.ToDecimal(dataGridView1.Rows[i].Cells["GoodsQty"].Value);
                tItem.GoodsPrc    = Convert.ToDecimal(dataGridView1.Rows[i].Cells["GoodsPrc"].Value);
                tItem.GoodsAmt    = Convert.ToDecimal(dataGridView1.Rows[i].Cells["GoodsAmt"].Value);
                tItem.GoodsName   = dataGridView1.Rows[i].Cells["GoodsName"].Value.ToString();
                tItem.GoodsSpec   = dataGridView1.Rows[i].Cells["GoodsSpec"].Value.ToString();
                tItem.GoodsUnit   = dataGridView1.Rows[i].Cells["GoodsUnit"].Value.ToString();
                tItem.UsePosition = dataGridView1.Rows[i].Cells["UsePosition"].Value.ToString();

                tItems.Add(tItem);
            }

            BLL.CKBLL.ModifyCKD(tR, tItems);
            this.Close();
        }
Beispiel #3
0
        void AddNewOutStock()
        {
            //保存数据,注意使用事务进行处理
            //1、入库单号的生成与修改;2、入库单的增加;3入库单项目的增加
            OutStock tR = new OutStock();

            tR.OutStockDate = dateTimePickerRKDate.Value;
            tR.ProjectID    = Convert.ToInt32(comboBoxProjectID.SelectedValue.ToString());
            tR.CompanyID    = Convert.ToInt32(comboBoxCompanyID.SelectedValue.ToString());
            tR.WareHouseID  = Convert.ToInt32(comboBoxWareHouseID.SelectedValue.ToString());
            int    i_OutStockType = 0;
            string tS1            = comboBoxOutStockType.Text;

            switch (tS1)
            {
            case "领料出库":
                i_OutStockType = 0;
                break;

            case "领料退货":
                i_OutStockType = 1;
                break;

            case "物资借出":
                i_OutStockType = 2;
                break;

            case "物资归还":
                i_OutStockType = 3;
                break;

            case "报损出库":
                i_OutStockType = 4;
                break;

            case "报损归还":
                i_OutStockType = 5;
                break;

            default:
                break;
            }
            tR.OutStockType  = i_OutStockType;
            tR.OutBillAmt    = dTotal;
            tR.OutBillRemark = waterTextBoxRemark.Text;
            tR.UseMan        = textBoxUseMan.Text;
            tR.OutMan        = textBoxOutMan.Text;
            tR.RecordStatus  = "已记账";
            List <OutStockItems> tItems = new List <OutStockItems>();

            int row = dataGridView1.Rows.Count;            //得到总行数

            for (int i = 0; i < row - 1; i++)
            {
                //最后一行是新行,不算
                if (dataGridView1.Rows[i].Cells["GoodsID"].Value == DBNull.Value)
                {
                    continue;
                }
                OutStockItems tItem;
                tItem             = new OutStockItems();
                tItem.GoodsID     = Convert.ToInt32(dataGridView1.Rows[i].Cells["GoodsID"].Value);
                tItem.GoodsQty    = Convert.ToDecimal(dataGridView1.Rows[i].Cells["GoodsQty"].Value);
                tItem.GoodsPrc    = Convert.ToDecimal(dataGridView1.Rows[i].Cells["GoodsPrc"].Value);
                tItem.GoodsAmt    = Convert.ToDecimal(dataGridView1.Rows[i].Cells["GoodsAmt"].Value);
                tItem.GoodsName   = dataGridView1.Rows[i].Cells["GoodsName"].Value.ToString();
                tItem.GoodsSpec   = dataGridView1.Rows[i].Cells["GoodsSpec"].Value.ToString();
                tItem.GoodsUnit   = dataGridView1.Rows[i].Cells["GoodsUnit"].Value.ToString();
                tItem.UsePosition = dataGridView1.Rows[i].Cells["UsePosition"].Value.ToString();
                if (dataGridView1.Rows[i].Cells["UsePosition"].Value != null)
                {
                    tItem.UsePosition = dataGridView1.Rows[i].Cells["UsePosition"].Value.ToString();
                }
                tItems.Add(tItem);
            }

            BLL.CKBLL.AddCKD(tR, tItems);
            this.Close();
        }
Beispiel #4
0
        //修改出库单
        public static void ModifyCKD(OutStock tOutStock, List <OutStockItems> tItemsList)
        {
            //修改出库单
            ISession     session = NHibernateHelper.sessionFactory.OpenSession();
            ITransaction tx      = session.BeginTransaction();

            try
            {
                //得到未变更的出库单
                OutStock tOldOutStock = new OutStock();
                tOldOutStock = BLL.CKBLL.GetOutStock(tOutStock.OutStockID);

                //删除OutStockItem中的相关项
                List <int> toDelItemsID = BLL.CKBLL.GetItemIDs(tOldOutStock.OutStockID);
                foreach (int i in toDelItemsID)
                {
                    OutStockItems toDel1 = session.Get <OutStockItems>(i);
                    session.Delete(toDel1);
                    //更新库存
                    PKModel pk = new PKModel();
                    pk.GoodsID     = toDel1.GoodsID;
                    pk.WareHouseID = tOldOutStock.WareHouseID;
                    WareHouseStock tWH = session.Get <WareHouseStock>(pk);
                    if (tWH == null)
                    {
                        WareHouseStock tWHNew = new WareHouseStock();
                        tWHNew.Pk = pk;

                        tWHNew.Number = -toDel1.GoodsQty;
                        tWHNew.Price  = toDel1.GoodsPrc;
                        tWHNew.Amount = -toDel1.GoodsAmt;
                        session.Save(tWHNew);
                    }
                    else
                    {
                        tWH.Number += toDel1.GoodsQty;
                        tWH.Amount += toDel1.GoodsAmt;
                        if (tWH.Number != 0)
                        {
                            tWH.Price = Math.Round(tWH.Amount / tWH.Number, 2);
                        }
                        session.Flush();
                    }
                }
                //保存OutStock的修改
                OutStock toModify = session.Get <OutStock>(tOldOutStock.OutStockID);
                toModify.CompanyID     = tOutStock.CompanyID;
                toModify.ProjectID     = tOutStock.ProjectID;
                toModify.OutBillAmt    = tOutStock.OutBillAmt;
                toModify.OutBillRemark = tOutStock.OutBillRemark;
                toModify.WareHouseID   = tOutStock.WareHouseID;
                toModify.OutStockType  = tOutStock.OutStockType;

                //将新的OutStockItem加入
                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();
            }
        }