//出库 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); }
static public bool Add(Indetail indetail, out string msg) { string command = $"insert into Indetail (stockID,batchNum,date,quantity,price,batchNum2,suppliers,note) values ('{indetail.stockID}','{indetail.batchNum}','{indetail.date}','{indetail.quantity}','{indetail.price}','{indetail.batchNum2}','{indetail.suppliers}','{indetail.note}')"; try { msg = null; return(SQL.Excute(command)); } catch (Exception ex) { msg = ex.Message; return(false); } }
static public bool Update(Indetail indetail, out string msg) { string command = $"update Indetail set stockID = '{indetail.stockID}',batchNum = '{indetail.batchNum}',date = '{indetail.date}',quantity = '{indetail.quantity}',price = '{indetail.price}',batchNum2 = '{indetail.batchNum2}',suppliers = '{indetail.suppliers}',note = '{indetail.note}' where id = '{indetail.id}'"; try { msg = null; return(SQL.Excute(command)); } catch (Exception e) { msg = e.Message; System.Diagnostics.Debug.Write(msg); return(false); } }
static public Indetail QueryById(int id, out string msg) { string command = $"select * from Indetail where id = '{id}'"; SqlDataReader read = SQL.getData(command); if (read == null) { msg = "查询结果为空"; SQL.Dispose(); return(null); } Indetail indetail = new Indetail((int)read["id"], (int)read["stockID"], (string)read["batchNum"], (string)read["date"], (int)read["quantity"], (decimal)read["price"], read["batchNum2"].ToString(), read["suppliers"].ToString(), read["note"].ToString()); SQL.Dispose(); msg = null; return(indetail); }
public static string DestoryAllRecord() { string msg1; List <Dictionary <string, string> > temp = Models.BLL.DestoryManage.Query(storeID, ref totalPage, ref currentPage, out msg1); if (temp == null) { return(JsonConvert.SerializeObject(new Packet(201, msg1))); } List <Indetail> list = new List <Indetail>(); foreach (Dictionary <string, string> read in temp) { Indetail d = new Indetail(int.Parse(read["id"]), int.Parse(read["stockID"]), read["batchNum"], read["date"], int.Parse(read["quantity"]), decimal.Parse(read["price"]), read["batchNum2"], read["suppliers"], read["note"]); list.Add(d); } string msg; return(Models.BLL.DestoryManage.Destory(list, num, out msg) ? JsonConvert.SerializeObject(new Packet(200, null)) : JsonConvert.SerializeObject(new Packet(202, msg))); }