Example #1
0
        public void BOMMOD(Entity.BillOfMaterials bom, Entity.BusiLog bl, bool isHis)
        {
            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);

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

                    Guid gd = Guid.NewGuid();

                    //判断修改操作类型 改多为入库 改少为出库
                    //专供油出库
                    Entity.BillOfMaterials oldbom = new BillOfMaterials(bom.GetOriginalValue());
                    string strOperType            = "";
                    if (oldbom.cnnCount > bom.cnnCount)
                    {
                        strOperType = InType.BOMModIn;
                    }
                    else
                    {
                        strOperType = InType.BOMModOut;
                    }

                    //验收单
                    //bom.cnvcInType = strOperType;
                    bom.cndOperDate = dtSysTime;
                    if (isHis)
                    {
                        Entity.BillOfMaterialsHis bomhis = new BillOfMaterialsHis(bom.GetOriginalValue());
                        EntityMapping.Delete(bomhis, trans);

                        //bomhis.SynchronizeModifyValue(bom);
                        EntityMapping.Create(bom, trans);
                    }
                    else
                    {
                        EntityMapping.Update(bom, trans);
                    }
                    if (bom.cnnCount != oldbom.cnnCount)
                    {
                        //库存日志
                        Entity.OilStorageLog ol = new OilStorageLog(bom.ToTable());
                        ol.cnvcDeptName  = bl.cnvcDeptName;
                        ol.cnvcOperType  = strOperType;
                        ol.cnnSerial     = gd;
                        ol.cnnLastCount  = os.cnnStorageCount;
                        ol.cnnInOutCount = oldbom.cnnCount - bom.cnnCount;                      //bom.cnnCount-oldbom.cnnCount;
                        ol.cnnCurCount   = os.cnnStorageCount + oldbom.cnnCount - bom.cnnCount;
                        EntityMapping.Create(ol, trans);

                        //库存
                        os.cnnStorageCount = ol.cnnCurCount;
                        EntityMapping.Update(os, trans);
                    }
                    //日志
                    bl.cnnSerial    = gd;
                    bl.cnvcComments = "领料单修改,出入库量:" + (oldbom.cnnCount - bom.cnnCount);
                    bl.cnvcOperType = OperType.OP203;
                    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);
                }
            }
        }
Example #2
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);
                }
            }
        }