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