Example #1
0
        public static void UpdateBOS(BillOfOutStorage bos, BusiLog bl)
        {
            //ConnectionPool.IsCenter = false;
            using (SqlConnection conn = ConnectionPool.BorrowConnection())
            {
                //conn.Open();
                SqlTransaction trans = conn.BeginTransaction(IsolationLevel.ReadCommitted);
                try
                {
                    string   strSysTime = SqlHelper.ExecuteScalar(trans, CommandType.Text, "select getdate()").ToString();
                    DateTime dtSysTime  = DateTime.Parse(strSysTime);

                    Dept dept = new Dept();
                    dept.cnvcDeptID = bos.cnvcDeptID;
                    dept            = EntityMapping.Get(dept, trans) as Dept;

                    OilStorage os = new OilStorage();
                    os.cnvcGoodsName = bos.cnvcGoodsName;
                    os.cnvcGoodsType = bos.cnvcGoodsType;
                    os.cnvcDeptID    = bos.cnvcDeptID;
                    os = EntityMapping.Get(os, trans) as OilStorage;
                    if (null == os)
                    {
                        throw new BusinessException(bexType.noobject, "库存获取错误");
                    }

                    Guid gd = Guid.NewGuid();

                    //判断修改操作类型 改多为入库 改少为出库
                    BillOfOutStorage oldbos = new BillOfOutStorage();
                    oldbos.cnvcBillNo = bos.cnvcBillNo;
                    oldbos.cnvcDeptID = bos.cnvcDeptID;
                    oldbos            = EntityMapping.Get(oldbos, trans) as BillOfOutStorage;

                    string strOperType = "";
                    if (oldbos.cnnCount > bos.cnnCount)
                    {
                        strOperType = OutType.BOSIn;
                    }
                    else
                    {
                        strOperType = OutType.BOSOut;
                    }

                    //验收单

                    if (bos.cnnCount != oldbos.cnnCount)
                    {
                        //库存日志
                        OilStorageLog ol = new OilStorageLog(bos.ToTable());
                        ol.cnvcDeptName  = dept.cnvcDeptName;
                        ol.cndOperDate   = dtSysTime;
                        ol.cnvcOperType  = strOperType;
                        ol.cnnSerial     = gd;
                        ol.cnnLastCount  = oldbos.cnnCount;                   //os.cnnStorageCount;
                        ol.cnnInOutCount = oldbos.cnnCount - bos.cnnCount;    //bos.cnnCount-oldbos.cnnCount;
                        ol.cnnCurCount   = bos.cnnCount;                      //os.cnnStorageCount + oldbos.cnnCount-bos.cnnCount ;
                        EntityMapping.Create(ol, trans);

                        OilStorageLogHis olhis = new OilStorageLogHis(ol.ToTable());
                        EntityMapping.Create(olhis, trans);

                        oldbos.SynchronizeModifyValue(bos);
                        oldbos.cnnCount           = bos.cnnCount;
                        oldbos.cnnReceivableCount = bos.cnnReceivableCount;
                        oldbos.cnvcOutType        = strOperType;
                        EntityMapping.Update(oldbos, trans);
                        //库存
                        os.cnnStorageCount = os.cnnStorageCount + ol.cnnInOutCount;                      //ol.cnnCurCount;
                        EntityMapping.Update(os, trans);
                    }
                    //日志
                    bl.cnnSerial    = gd;
                    bl.cnvcComments = "出库单修改,出入库量:" + (oldbos.cnnCount - bos.cnnCount);                //(bos.cnnCount-oldbos.cnnCount);
                    bl.cnvcOperType = OperType.OP202;
                    bl.cndOperDate  = dtSysTime;
                    bl.cnvcSource   = InSource.cs;
                    EntityMapping.Create(bl, trans);

                    trans.Commit();
                }
                catch (BusinessException bex)
                {
                    trans.Rollback();
                    LogAdapter.WriteBusinessException(bex);
                    throw bex;
                }
                catch (SqlException sex)
                {
                    trans.Rollback();
                    LogAdapter.WriteDatabaseException(sex);
                    throw sex;
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    LogAdapter.WriteFeaturesException(ex);
                    throw ex;
                }
                finally
                {
                    ConnectionPool.ReturnConnection(conn);
                }
            }
        }