/// <summary> /// 更新一条数据 /// </summary> public bool Update(MODEL.T_STOCK_Report model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_STOCK_Report set "); strSql.Append("BookID=@BookID,"); strSql.Append("Num=@Num"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@BookID", SqlDbType.Int, 4), new SqlParameter("@Num", SqlDbType.Int, 4), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.BookID; parameters[1].Value = model.Num; parameters[2].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(MODEL.T_STOCK_Report model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_STOCK_Report("); strSql.Append("BookID,Num)"); strSql.Append(" values ("); strSql.Append("@BookID,@Num)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@BookID", SqlDbType.Int, 4), new SqlParameter("@Num", SqlDbType.Int, 4) }; parameters[0].Value = model.BookID; parameters[1].Value = model.Num; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public MODEL.T_STOCK_Report DataRowToModel(DataRow row) { MODEL.T_STOCK_Report model = new MODEL.T_STOCK_Report(); 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["Num"] != null && row["Num"].ToString() != "") { model.Num = int.Parse(row["Num"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public MODEL.T_STOCK_Report GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,BookID,Num from T_STOCK_Report "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; MODEL.T_STOCK_Report model = new MODEL.T_STOCK_Report(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }