public JsonResult AddSave() { Book.Model.T_STOCK_OutHead head = new Book.Model.T_STOCK_OutHead(); head.CeateTime = Convert.ToDateTime(Request.Form["CreateName"]); head.OrderNumber = Convert.ToString(Request.Form["OrderNumber"]); head.GuestID = Convert.ToInt32(Request.Form["json.ID"]); head.GuestName = Convert.ToString(Request.Form["json.Name"]); head.UserID = 1; head.UserName = "******"; List <Book.Model.T_STOCK_OutBody> lst = new List <Book.Model.T_STOCK_OutBody>(); int i = 0; while (Request.Form["items[" + i + "].book.ID"] != null) { Book.Model.T_STOCK_OutBody body = new Book.Model.T_STOCK_OutBody(); string BookID = Request.Form["items[" + i + "].book.ID"]; BookID = BookID.Replace(",", ""); body.BookID = Convert.ToInt32(BookID); body.Discount = Convert.ToDecimal(Request.Form["items[" + i + "].book.Discount"]); body.InHeadID = 0; body.Num = Convert.ToInt32(Request.Form["items[" + i + "].book.Num"]); body.Price = Convert.ToDecimal(Request.Form["items[" + i + "].book.Price"]); lst.Add(body); i++; } BLL.T_Stock_Out bll = new BLL.T_Stock_Out(); bool result = bll.Add(head, lst); if (result) { MODEL.Message message = new MODEL.Message(); message = BookProject.Public.T_CloseSMess("OutList", "OutList", "添加出库单成功!"); return(Json(message)); } else { MODEL.Message message = new MODEL.Message(); message = BookProject.Public.T_CloseFMess("InList", "InList", "添加入库单失败!"); return(Json(message)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Book.Model.T_STOCK_OutBody model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_STOCK_OutBody set "); strSql.Append("BookID=@BookID,"); strSql.Append("Discount=@Discount,"); strSql.Append("Num=@Num,"); strSql.Append("Total=@Total,"); strSql.Append("Price=@Price,"); strSql.Append("InHeadID=@InHeadID"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@BookID", SqlDbType.Int, 4), new SqlParameter("@Discount", SqlDbType.Decimal, 5), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@Total", SqlDbType.Decimal, 9), new SqlParameter("@Price", SqlDbType.Decimal, 5), new SqlParameter("@InHeadID", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.BookID; parameters[1].Value = model.Discount; parameters[2].Value = model.Num; parameters[3].Value = model.Total; parameters[4].Value = model.Price; parameters[5].Value = model.InHeadID; parameters[6].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Book.Model.T_STOCK_OutBody model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_STOCK_OutBody("); strSql.Append("BookID,Discount,Num,Total,Price,InHeadID)"); strSql.Append(" values ("); strSql.Append("@BookID,@Discount,@Num,@Total,@Price,@InHeadID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@BookID", SqlDbType.Int, 4), new SqlParameter("@Discount", SqlDbType.Decimal, 5), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@Total", SqlDbType.Decimal, 9), new SqlParameter("@Price", SqlDbType.Decimal, 5), new SqlParameter("@InHeadID", SqlDbType.Int, 4) }; parameters[0].Value = model.BookID; parameters[1].Value = model.Discount; parameters[2].Value = model.Num; parameters[3].Value = model.Total; parameters[4].Value = model.Price; parameters[5].Value = model.InHeadID; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Book.Model.T_STOCK_OutBody DataRowToModel(DataRow row) { Book.Model.T_STOCK_OutBody model = new Book.Model.T_STOCK_OutBody(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["BookID"] != null && row["BookID"].ToString() != "") { model.BookID = int.Parse(row["BookID"].ToString()); } if (row["Discount"] != null && row["Discount"].ToString() != "") { model.Discount = decimal.Parse(row["Discount"].ToString()); } if (row["Num"] != null && row["Num"].ToString() != "") { model.Num = int.Parse(row["Num"].ToString()); } if (row["Total"] != null && row["Total"].ToString() != "") { model.Total = decimal.Parse(row["Total"].ToString()); } if (row["Price"] != null && row["Price"].ToString() != "") { model.Price = decimal.Parse(row["Price"].ToString()); } if (row["InHeadID"] != null && row["InHeadID"].ToString() != "") { model.InHeadID = int.Parse(row["InHeadID"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Book.Model.T_STOCK_OutBody GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,BookID,Discount,Num,Total,Price,InHeadID from T_STOCK_OutBody "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; Book.Model.T_STOCK_OutBody model = new Book.Model.T_STOCK_OutBody(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }