//出库 static public bool OutWarehouse(int indetailId, int outNum, string userNum, out string msg) { List <string> list = new List <string>(); Indetail indetail = IndetailDAL.QueryById(indetailId, out msg); if (indetail == null) { msg = "单品记录查询失败"; return(false); } if (indetail.quantity < outNum) { msg = "数量不足"; return(false); } indetail.quantity -= outNum; int stockId = indetail.stockID; Stock stock = StockDAL.QueryById(stockId, out msg); if (stock == null) { msg = "库存查询失败"; return(false); } stock.quantity -= outNum; stock.money = stock.money - outNum * indetail.price; if (stock.money < 0) { msg = "金额出错"; return(false); } string date = DateTime.Now.ToString("yyyy-MM-dd"); Outflow outflow = new Outflow(stock.cagNum, stock.storeID, date, userNum, outNum, indetail.price, indetail.batchNum, indetail.batchNum2, indetail.suppliers, "正常出库"); if (indetail.quantity == 0) { list.Add(string.Format(" delete from Indetail where id ={0}", indetailId)); list.Add(string.Format("update Stock set cagNum = '{0}', storeID = {1}, quantity = {2}, money = {3} where id = {4} ", stock.cagNum, stock.storeID, stock.quantity, stock.money, stock.id)); list.Add(string.Format("insert into Outflow (cagNum,storeID,date,userNum,quantity,price,batchNum,batchNum2,suppliers,state) values('{0}',{1},'{2}','{3}',{4},{5},'{6}','{7}','{8}','{9}')", outflow.cagNum, outflow.storeID, outflow.date, outflow.userNum, outflow.quantity, outflow.price, outflow.batchNum, outflow.batchNum2, outflow.suppliers, outflow.state)); } else { list.Add(string.Format("update Indetail set stockID = {0},batchNum = '{1}',date = '{2}',quantity = {3},price = {4},batchNum2 = '{5}',suppliers = '{6}',note = '{7}' where id = {8}", indetail.stockID, indetail.batchNum, indetail.date, indetail.quantity, indetail.price, indetail.batchNum2, indetail.suppliers, indetail.note, indetail.id)); list.Add(string.Format("update Stock set cagNum = '{0}', storeID = {1}, quantity = {2}, money = {3} where id = {4} ", stock.cagNum, stock.storeID, stock.quantity, stock.money, stock.id)); list.Add(string.Format("insert into Outflow (cagNum,storeID,date,userNum,quantity,price,batchNum,batchNum2,suppliers,state) values('{0}',{1},'{2}','{3}',{4},{5},'{6}','{7}','{8}','{9}')", outflow.cagNum, outflow.storeID, outflow.date, outflow.userNum, outflow.quantity, outflow.price, outflow.batchNum, outflow.batchNum2, outflow.suppliers, outflow.state)); } bool bol = SQL.ExecuteTransaction(list, out msg); if (bol) { msg = "出库成功"; } else { return(false); } return(true); }