Ejemplo n.º 1
0
 public void Status(string F_Id, string userName)
 {
     using (DbTransactionScope <PI_HeadInfo> dbtran = base.CreateTransactionScope())
     {
         try
         {
             //更新登记单主表审核状态,审核人,审核时间
             PI_HeadInfo head = PI_Head.Instance.FindByID(F_Id, dbtran.Transaction);
             head.F_Status   = 1;
             head.F_Verify   = userName;
             head.F_VeriDate = DateTime.Now;
             PI_Head.Instance.Update(head, F_Id, dbtran.Transaction);
             //找到登记单子表
             SearchCondition condition = new SearchCondition();
             condition.AddCondition("F_HId", F_Id, SqlOperator.Equal);
             List <PI_BodyInfo> list = PI_Body.Instance.Find(condition.BuildConditionSql().Replace("Where (1=1)  AND ", string.Empty), dbtran.Transaction);
             //资产编号
             foreach (PI_BodyInfo item in list)
             {
                 for (int i = 0; i < item.F_InStockNum; i++)
                 {
                     PI_BodyInfo entity = new PI_BodyInfo();
                     entity.F_Id          = Guid.NewGuid().ToString();
                     entity.F_EnCode      = item.F_EnCode;
                     entity.F_FullName    = item.F_FullName;
                     entity.F_OrderNo     = item.F_OrderNo;
                     entity.F_Supplier    = item.F_Supplier;
                     entity.F_Unit        = item.F_Unit;
                     entity.F_Description = item.F_Description;
                     PI_Body.Instance.Insert(entity, dbtran.Transaction);
                 }
             }
             dbtran.Commit();
         }
         catch (Exception ex)
         {
             dbtran.RollBack();
             throw ex;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///审核单据
        /// </summary>
        /// <param name="date">审核日期</param>
        /// <param name="Id">审核单据</param>
        /// <param name="user">审核人</param>
        public string Audit(string date, string user, string Id, List <PI_BodyInfo> stockinfo)
        {
            string SqlAuditSel = "select F_Status from PI_Head where F_Id='" + Id + "'";
            string AuditState  = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString();

            if (AuditState == "1")
            {
                return("单据已被审核");
            }
            else
            {
                using (DbTransactionScope <PI_HeadInfo> dbtran = base.CreateTransactionScope())
                {
                    try
                    {
                        //查询所有库存信息
                        List <Sys_StockInfo> stockList = BLLFactory <Sys_Stock> .Instance.GetAll();

                        //查询主表信息
                        PI_HeadInfo hinfo = BLLFactory <PI_Head> .Instance.FindByID(Id);


                        foreach (PI_BodyInfo item in stockinfo)
                        {
                            //判断是否入库
                            PI_BodyInfo binfo = BLLFactory <PI_Body> .Instance.FindByID(item.F_Id);

                            if (binfo.F_AlreadyOperatedNum == "")
                            {
                                binfo.F_AlreadyOperatedNum = "0";
                            }
                            if (int.Parse(binfo.F_AlreadyOperatedNum) > 0)
                            {
                                return("该单据已入库,不能重复执行入库操作");
                            }

                            if (binfo.F_WarehouseId == "" || binfo.F_CargoPositionId == "")
                            {
                                return("该单据中仓库或仓位为空,审核未通过");
                            }

                            Sys_StockInfo stock = stockList.Find(u => u.F_WarehouseId == binfo.F_WarehouseId && u.F_CargoPositionId == binfo.F_CargoPositionId && u.F_GoodsId == binfo.F_GoodsId && u.F_Batch == binfo.F_SerialNum);
                            if (stock == null)
                            {
                                item.IsHave = false;
                            }
                            else
                            {
                                item.IsHave      = true;
                                item.StockID     = stock.F_Id;
                                item.StockNumber = stock.F_Number;
                            }

                            //查询库存表是否存在该仓库中的产品
                            //没有
                            if (!item.IsHave)
                            {
                                //新添加一条数据 库存表
                                Sys_StockInfo entity = new Sys_StockInfo();
                                entity.F_Id = Guid.NewGuid().ToString();
                                entity.F_CargoPositionId   = item.F_CargoPositionId;
                                entity.F_CargoPositionName = item.F_CargoPositionName;
                                entity.F_WarehouseId       = item.F_WarehouseId;
                                entity.F_WarehouseName     = item.F_WarehouseName;
                                entity.F_GoodsName         = item.F_FullName;
                                entity.F_Batch             = item.F_SerialNum;
                                entity.F_GoodsId           = item.F_GoodsId;
                                entity.F_SpecifModel       = item.F_SpecifModel;
                                entity.F_SellingPrice      = item.F_SellingPrice;
                                entity.F_PurchasePrice     = item.F_PurchasePrice;
                                entity.F_Unit   = item.F_Unit;
                                entity.F_Number = item.F_InStockNum;
                                Sys_Stock.Instance.Insert(entity, dbtran.Transaction);

                                //更新审核状态
                                string    sql  = string.Format("update PI_Head set F_Status=1,F_VeriDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id);
                                Hashtable hash = new Hashtable();
                                base.ExecuteNonQuery(sql, hash, dbtran.Transaction);

                                //添加入库履历 入库履历
                                Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
                                inRec.F_Id                = Guid.NewGuid().ToString();
                                inRec.F_WarehouseId       = item.F_WarehouseId;
                                inRec.F_Vendor            = hinfo.F_Vendor;
                                inRec.F_VendorName        = hinfo.F_VendorName;
                                inRec.F_Contacts          = hinfo.F_Contacts;
                                inRec.F_TelePhone         = hinfo.F_TelePhone;
                                inRec.F_Verify            = user;
                                inRec.F_Maker             = hinfo.F_Maker;
                                inRec.F_VeriDate          = DateTime.Now;
                                inRec.F_EnCode            = item.F_OrderNo;
                                inRec.F_Batch             = item.F_SerialNum;
                                inRec.F_WarehouseName     = item.F_WarehouseName;
                                inRec.F_GoodsName         = item.F_FullName;
                                inRec.F_GoodsId           = item.F_GoodsId;
                                inRec.F_CargoPositionId   = item.F_CargoPositionId;
                                inRec.F_CargoPositionName = item.F_CargoPositionName;
                                inRec.F_SpecifModel       = item.F_SpecifModel;
                                inRec.F_SellingPrice      = item.F_SellingPrice;
                                inRec.F_PurchasePrice     = item.F_PurchasePrice;
                                inRec.F_Unit              = item.F_Unit;
                                inRec.F_InStockNum        = item.F_InStockNum;
                                inRec.F_CreatorTime       = DateTime.Now;
                                Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction);



                                //添加  库存履历
                                Sys_StockHistoryInfo instock = new Sys_StockHistoryInfo();
                                instock.F_Id                = Guid.NewGuid().ToString();
                                instock.F_WarehouseId       = item.F_WarehouseId;
                                instock.F_Vendor            = hinfo.F_Vendor;
                                instock.F_VendorName        = hinfo.F_VendorName;
                                instock.F_Contacts          = hinfo.F_Contacts;
                                instock.F_TelePhone         = hinfo.F_TelePhone;
                                instock.F_Verify            = user;
                                instock.F_Maker             = hinfo.F_Maker;
                                instock.F_VeriDate          = DateTime.Now;
                                instock.F_EnCode            = item.F_OrderNo;
                                instock.F_Batch             = item.F_SerialNum;
                                instock.F_WarehouseName     = item.F_WarehouseName;
                                instock.F_BllCategory       = "入库";
                                instock.F_GoodsName         = item.F_FullName;
                                instock.F_GoodsId           = item.F_GoodsId;
                                instock.F_CargoPositionId   = item.F_CargoPositionId;
                                instock.F_CargoPositionName = item.F_CargoPositionName;
                                instock.F_SpecifModel       = item.F_SpecifModel;
                                instock.F_SellingPrice      = item.F_SellingPrice;
                                instock.F_PurchasePrice     = item.F_PurchasePrice;
                                instock.F_Unit              = item.F_Unit;
                                instock.F_OperationNum      = item.F_InStockNum;
                                instock.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instock, dbtran.Transaction);



                                //更新子表入库状态
                                hash = new Hashtable();
                                hash.Add("F_AlreadyOperatedNum", 1);
                                PI_Body.Instance.Update(item.F_Id, hash, dbtran.Transaction);

                                //更新主表入库状态
                                hash = new Hashtable();
                                hash.Add("F_State", 1);
                                PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction);
                            }
                            else
                            {
                                //更新前库存数量
                                Hashtable hash = new Hashtable();
                                hash.Add("F_Number", item.StockNumber + item.F_InStockNum);
                                Sys_Stock.Instance.Update(item.StockID, hash, dbtran.Transaction);
                                for (int i = 0; i < stockinfo.Count; i++)
                                {
                                    if (stockinfo[i].StockID == item.StockID)
                                    {
                                        stockinfo[i].StockNumber += item.F_InStockNum;
                                    }
                                }

                                //更新审核状态
                                string sql = string.Format("update PI_Head set F_Status=1,F_VeriDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id);
                                hash = new Hashtable();
                                base.ExecuteNonQuery(sql, hash, dbtran.Transaction);

                                //更新子表入库状态
                                hash = new Hashtable();
                                hash.Add("F_AlreadyOperatedNum", 1);
                                PI_Body.Instance.Update(item.F_Id, hash, dbtran.Transaction);

                                //更新主表入库状态
                                hash = new Hashtable();
                                hash.Add("F_State", 1);
                                PI_Head.Instance.Update(item.F_HId, hash, dbtran.Transaction);


                                //添加履历
                                Sys_InRecordsInfo inRec = new Sys_InRecordsInfo();
                                inRec.F_Id                = Guid.NewGuid().ToString();
                                inRec.F_WarehouseId       = item.F_WarehouseId;
                                inRec.F_EnCode            = item.F_OrderNo;
                                inRec.F_Batch             = item.F_SerialNum;
                                inRec.F_Vendor            = hinfo.F_Vendor;
                                inRec.F_VendorName        = hinfo.F_VendorName;
                                inRec.F_Contacts          = hinfo.F_Contacts;
                                inRec.F_TelePhone         = hinfo.F_TelePhone;
                                inRec.F_Verify            = user;
                                inRec.F_Maker             = hinfo.F_Maker;
                                inRec.F_VeriDate          = DateTime.Now;
                                inRec.F_WarehouseName     = item.F_WarehouseName;
                                inRec.F_GoodsName         = item.F_FullName;
                                inRec.F_GoodsId           = item.F_GoodsId;
                                inRec.F_CargoPositionId   = item.F_CargoPositionId;
                                inRec.F_CargoPositionName = item.F_CargoPositionName;
                                inRec.F_SpecifModel       = item.F_SpecifModel;
                                inRec.F_SellingPrice      = item.F_SellingPrice;
                                inRec.F_PurchasePrice     = item.F_PurchasePrice;
                                inRec.F_Unit              = item.F_Unit;
                                inRec.F_InStockNum        = item.F_InStockNum;
                                inRec.F_CreatorTime       = DateTime.Now;
                                Sys_InRecords.Instance.Insert(inRec, dbtran.Transaction);

                                //添加库存履历
                                Sys_StockHistoryInfo instock = new Sys_StockHistoryInfo();
                                instock.F_Id                = Guid.NewGuid().ToString();
                                instock.F_WarehouseId       = item.F_WarehouseId;
                                instock.F_EnCode            = item.F_OrderNo;
                                instock.F_Batch             = item.F_SerialNum;
                                instock.F_Vendor            = hinfo.F_Vendor;
                                instock.F_VendorName        = hinfo.F_VendorName;
                                instock.F_Contacts          = hinfo.F_Contacts;
                                instock.F_TelePhone         = hinfo.F_TelePhone;
                                instock.F_Verify            = user;
                                instock.F_Maker             = hinfo.F_Maker;
                                instock.F_VeriDate          = DateTime.Now;
                                instock.F_WarehouseName     = item.F_WarehouseName;
                                instock.F_BllCategory       = "入库";
                                instock.F_GoodsName         = item.F_FullName;
                                instock.F_GoodsId           = item.F_GoodsId;
                                instock.F_CargoPositionId   = item.F_CargoPositionId;
                                instock.F_CargoPositionName = item.F_CargoPositionName;
                                instock.F_SpecifModel       = item.F_SpecifModel;
                                instock.F_SellingPrice      = item.F_SellingPrice;
                                instock.F_PurchasePrice     = item.F_PurchasePrice;
                                instock.F_Unit              = item.F_Unit;
                                instock.F_OperationNum      = item.F_InStockNum;
                                instock.F_CreatorTime       = DateTime.Now;
                                Sys_StockHistory.Instance.Insert(instock, dbtran.Transaction);
                            }
                        }
                        dbtran.Commit();
                        return("单据审核成功");
                    }
                    catch (Exception ex)
                    {
                        dbtran.RollBack();
                        return("操作失败");

                        throw ex;
                    }
                }
            }
        }