/// <summary> ///审核单据 /// </summary> /// <param name="date">审核日期</param> /// <param name="Id">审核单据</param> /// <param name="user">审核人</param> public string Audit(string date, string user, string Id, List <Allocation_BodyInfo> DbInfo) { string SqlAuditSel = "select F_Status from Allocation_Head where F_Id='" + Id + "'"; string AuditState = this.GetDataTableBySql(SqlAuditSel).Rows[0][0].ToString(); if (AuditState == "1") { return("单据已被审核"); } else { using (DbTransactionScope <Allocation_HeadInfo> dbtran = base.CreateTransactionScope()) { try { Hashtable hash = new Hashtable(); List <Sys_StockInfo> StockList = BLLFactory <Sys_Stock> .Instance.GetAll(); //查询主表信息 Allocation_HeadInfo hinfo = BLLFactory <Allocation_Head> .Instance.FindByID(Id); for (int i = 0; i < DbInfo.Count; i++) { //查询子表信息 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Id", DbInfo[i].F_Id, SqlOperator.Equal); Allocation_BodyInfo bodyinfo = BLLFactory <Allocation_Body> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty))[0]; //判断是否出库 if (bodyinfo.F_FreeTerm1 == "") //F_FreeTerm1--0未出库 1已出库 { bodyinfo.F_FreeTerm1 = "0"; } if (int.Parse(bodyinfo.F_FreeTerm1) > 0) { return("该单据已出库,不能重复执行出库操作"); } if (bodyinfo.F_OutWareId == "" || bodyinfo.F_OutCargoPositionId == "" || bodyinfo.F_InWareId == "" || bodyinfo.F_InCargoPositionId == "") { return("该单据中仓库或仓位为空,审核未通过"); } //查询库存表是否存在该仓库中的产品 Sys_StockInfo stock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_OutWareId && u.F_CargoPositionId == bodyinfo.F_OutCargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId && u.F_Batch == bodyinfo.F_SerialNum); if (stock == null) { dbtran.RollBack(); return("该仓库无此产品"); } //判断库存数量是否足够 if (stock.F_Number > bodyinfo.F_DbNum) { //扣减库存 hash = new Hashtable(); hash.Add("F_Number", stock.F_Number - bodyinfo.F_DbNum); Sys_Stock.Instance.Update(stock.F_Id, hash, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_WarehouseId = bodyinfo.F_OutWareId; instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_WarehouseName = bodyinfo.F_OutWareName; instockHistory.F_BllCategory = "调出"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_OutCargoPositionId; instockHistory.F_CargoPositionName = bodyinfo.F_OutCargoPositionName; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = 0 - bodyinfo.F_DbNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); //更新出库状态 hash = new Hashtable(); hash.Add("F_FreeTerm1", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); } else { return(bodyinfo.F_OutWareName + "仓库库存不足,当前产品" + bodyinfo.F_GoodsName + "库存为" + stock.F_Number); } Sys_StockInfo instock = StockList.Find(u => u.F_WarehouseId == bodyinfo.F_InWareId && u.F_CargoPositionId == bodyinfo.F_InCargoPositionId && u.F_GoodsId == bodyinfo.F_GoodsId); //如果不存在 if (instock == null) { //新添加一条数据 Sys_StockInfo entity = new Sys_StockInfo(); entity.F_Id = Guid.NewGuid().ToString(); entity.F_GoodsId = bodyinfo.F_GoodsId; entity.F_GoodsName = bodyinfo.F_GoodsName; entity.F_WarehouseId = bodyinfo.F_InWareId; entity.F_WarehouseName = bodyinfo.F_InWareName; entity.F_CargoPositionId = bodyinfo.F_InCargoPositionId; entity.F_CargoPositionName = bodyinfo.F_InCargoPositionName; entity.F_Batch = bodyinfo.F_SerialNum; entity.F_Unit = bodyinfo.F_Unit; entity.F_Number = bodyinfo.F_DbNum; Sys_Stock.Instance.Insert(entity, dbtran.Transaction); //添加履历 Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo(); Dbinfo.F_Id = Guid.NewGuid().ToString(); Dbinfo.F_GoodsId = bodyinfo.F_GoodsId; Dbinfo.F_InWareName = bodyinfo.F_InWareName; Dbinfo.F_EnCode = bodyinfo.F_OrderNo; Dbinfo.F_Batch = bodyinfo.F_SerialNum; Dbinfo.F_GoodsName = bodyinfo.F_GoodsName; Dbinfo.F_Verify = user; Dbinfo.F_Maker = hinfo.F_Maker; Dbinfo.F_VeriDate = DateTime.Now; Dbinfo.F_OutWareId = bodyinfo.F_OutWareId; Dbinfo.F_InWareId = bodyinfo.F_InWareId; Dbinfo.F_OutWareName = bodyinfo.F_OutWareName; Dbinfo.F_InCargoPositionId = bodyinfo.F_InCargoPositionId; Dbinfo.F_InCargoPositionName = bodyinfo.F_InCargoPositionName; Dbinfo.F_OutCargoPositionId = bodyinfo.F_OutCargoPositionId; Dbinfo.F_OutCargoPositionName = bodyinfo.F_OutCargoPositionName; Dbinfo.F_Unit = bodyinfo.F_Unit; Dbinfo.F_DBNum = bodyinfo.F_DbNum; Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel; Dbinfo.F_CreatorTime = DateTime.Now; Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_WarehouseId = bodyinfo.F_OutWareId; instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_WarehouseName = bodyinfo.F_InWareName; instockHistory.F_BllCategory = "调入"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_InCargoPositionName; instockHistory.F_CargoPositionName = bodyinfo.F_InCargoPositionId; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = bodyinfo.F_DbNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); //更新入库状态 hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); } //如果存在 else { //增加库存 hash = new Hashtable(); hash.Add("F_Number", instock.F_Number + bodyinfo.F_DbNum); Sys_Stock.Instance.Update(instock.F_Id, hash, dbtran.Transaction); //更新入库状态 hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); //添加履历 Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo(); Dbinfo.F_Id = Guid.NewGuid().ToString(); Dbinfo.F_GoodsId = bodyinfo.F_GoodsId; Dbinfo.F_Verify = user; Dbinfo.F_Maker = hinfo.F_Maker; Dbinfo.F_VeriDate = DateTime.Now; Dbinfo.F_EnCode = bodyinfo.F_OrderNo; Dbinfo.F_Batch = bodyinfo.F_SerialNum; Dbinfo.F_InWareName = bodyinfo.F_InWareName; Dbinfo.F_GoodsName = bodyinfo.F_GoodsName; Dbinfo.F_OutWareId = bodyinfo.F_OutWareId; Dbinfo.F_InWareId = bodyinfo.F_InWareId; Dbinfo.F_OutWareName = bodyinfo.F_OutWareName; Dbinfo.F_InCargoPositionId = bodyinfo.F_InCargoPositionId; Dbinfo.F_InCargoPositionName = bodyinfo.F_InCargoPositionName; Dbinfo.F_OutCargoPositionId = bodyinfo.F_OutCargoPositionId; Dbinfo.F_OutCargoPositionName = bodyinfo.F_OutCargoPositionName; Dbinfo.F_Unit = bodyinfo.F_Unit; Dbinfo.F_DBNum = bodyinfo.F_DbNum; Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel; Dbinfo.F_CreatorTime = DateTime.Now; Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction); //添加库存履历 Sys_StockHistoryInfo instockHistory = new Sys_StockHistoryInfo(); instockHistory.F_Id = Guid.NewGuid().ToString(); instockHistory.F_WarehouseId = bodyinfo.F_InWareId; instockHistory.F_WarehouseName = bodyinfo.F_InWareName; instockHistory.F_EnCode = bodyinfo.F_OrderNo; instockHistory.F_Batch = bodyinfo.F_SerialNum; instockHistory.F_Verify = user; instockHistory.F_Maker = hinfo.F_Maker; instockHistory.F_VeriDate = DateTime.Now; instockHistory.F_BllCategory = "调入"; instockHistory.F_GoodsName = bodyinfo.F_GoodsName; instockHistory.F_GoodsId = bodyinfo.F_GoodsId; instockHistory.F_CargoPositionId = bodyinfo.F_InCargoPositionId; instockHistory.F_CargoPositionName = bodyinfo.F_InCargoPositionName; instockHistory.F_SpecifModel = bodyinfo.F_SpecifModel; instockHistory.F_Unit = bodyinfo.F_Unit; instockHistory.F_OperationNum = bodyinfo.F_DbNum; instockHistory.F_CreatorTime = DateTime.Now; Sys_StockHistory.Instance.Insert(instockHistory, dbtran.Transaction); } } //更新审核状态 string sql = string.Format("update Allocation_Head set F_Status=1,F_AccountDate='{0}',F_Verify='{1}' where F_Id='{2}'", date, user, Id); hash = new Hashtable(); base.ExecuteNonQuery(sql, hash, dbtran.Transaction); dbtran.Commit(); return("单据审核成功"); } catch (Exception ex) { dbtran.RollBack(); return("操作失败"); throw ex; } } } }
/// <summary> /// 产品入库操作 /// </summary> /// <param name="Batch"></param> /// <param name="stockinfo"></param> /// <returns></returns> public string InStock(string Batch, string id) { using (DbTransactionScope <Allocation_BodyInfo> dbtran = base.CreateTransactionScope()) { try { //查询子表信息 SearchCondition condition = new SearchCondition(); condition.AddCondition("F_Id", id, SqlOperator.Equal); Allocation_BodyInfo bodyinfo = BLLFactory <Allocation_Body> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty))[0]; //查询主表判断是否审核 condition = new SearchCondition(); condition.AddCondition("F_Id", bodyinfo.F_HId, SqlOperator.Equal); Allocation_HeadInfo headinfo = BLLFactory <Allocation_Head> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty))[0]; if (headinfo.F_Status == 0) { return("该调拨单未审核,不能进行出库操作"); } //判断是否已入库 if (bodyinfo.F_AlreadyOperatedNum == null)//F_AlreadyOperatedNum--0未入库 1已入库 { bodyinfo.F_AlreadyOperatedNum = 0; } if (bodyinfo.F_AlreadyOperatedNum > 0) { return("该单据已入库,不能重复执行入库操作"); } //判断该调拨单是否出库 if (bodyinfo.F_FreeTerm1 == null)//F_FreeTerm1--0未出库 1已出库 { bodyinfo.F_FreeTerm1 = "0"; return("调拨单中产品未出库,不能进行入库操作"); } if (int.Parse(bodyinfo.F_FreeTerm1) > 0) { //查询库存表是否存在该仓库中的产品 condition = new SearchCondition(); condition.AddCondition("F_GoodsId", bodyinfo.F_GoodsId, SqlOperator.Equal); condition.AddCondition("F_WarehouseId", bodyinfo.F_InWareId, SqlOperator.Equal); List <Sys_StockInfo> stock = BLLFactory <Sys_Stock> .Instance.Find(condition.BuildConditionSql().Replace("Where (1=1) AND ", string.Empty)); //如果不存在 if (stock.Count == 0) { //新添加一条数据 Sys_StockInfo entity = new Sys_StockInfo(); entity.F_Id = Guid.NewGuid().ToString(); entity.F_GoodsId = bodyinfo.F_GoodsId; entity.F_GoodsName = bodyinfo.F_GoodsName; entity.F_WarehouseId = bodyinfo.F_InWareId; entity.F_WarehouseName = bodyinfo.F_InWareName; entity.F_Number = bodyinfo.F_DbNum; Sys_Stock.Instance.Insert(entity, dbtran.Transaction); //添加履历 Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo(); Dbinfo.F_Id = Guid.NewGuid().ToString(); Dbinfo.F_GoodsId = bodyinfo.F_GoodsId; Dbinfo.F_InWareName = bodyinfo.F_InWareName; Dbinfo.F_GoodsName = bodyinfo.F_GoodsName; Dbinfo.F_OutWareId = bodyinfo.F_OutWareId; Dbinfo.F_InWareId = bodyinfo.F_InWareId; Dbinfo.F_OutWareName = bodyinfo.F_OutWareName; Dbinfo.F_Unit = bodyinfo.F_Unit; Dbinfo.F_DBNum = bodyinfo.F_DbNum; Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel; Dbinfo.F_CreatorTime = DateTime.Now; Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction); //更新入库状态 Hashtable hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); } //如果存在 else { //增加库存 Hashtable hash = new Hashtable(); hash.Add("F_Number", stock[0].F_Number + bodyinfo.F_DbNum); Sys_Stock.Instance.Update(stock[0].F_Id, hash, dbtran.Transaction); //更新入库状态 hash = new Hashtable(); hash.Add("F_AlreadyOperatedNum", 1); Allocation_Body.Instance.Update(bodyinfo.F_Id, hash, dbtran.Transaction); //添加履历 Sys_AllocationHistoryInfo Dbinfo = new Sys_AllocationHistoryInfo(); Dbinfo.F_Id = Guid.NewGuid().ToString(); Dbinfo.F_GoodsId = bodyinfo.F_GoodsId; Dbinfo.F_InWareName = bodyinfo.F_InWareName; Dbinfo.F_GoodsName = bodyinfo.F_GoodsName; Dbinfo.F_OutWareId = bodyinfo.F_OutWareId; Dbinfo.F_InWareId = bodyinfo.F_InWareId; Dbinfo.F_OutWareName = bodyinfo.F_OutWareName; Dbinfo.F_Unit = bodyinfo.F_Unit; Dbinfo.F_DBNum = bodyinfo.F_DbNum; Dbinfo.F_SpecifModel = bodyinfo.F_SpecifModel; Dbinfo.F_CreatorTime = DateTime.Now; Sys_AllocationHistory.Instance.Insert(Dbinfo, dbtran.Transaction); } } dbtran.Commit(); return("操作成功"); } catch (Exception ex) { dbtran.RollBack(); return("操作失败"); throw ex; } } }