/// <summary> /// 更新一条数据 /// </summary> public bool Update(ProductTypeM model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update productType set "); strSql.Append("productName=@productName"); strSql.Append(" where productTypeid=@productTypeid"); SqlParameter[] parameters = { new SqlParameter("@productTypeid", SqlDbType.Int, 4), new SqlParameter("@productName", SqlDbType.VarChar, 50) }; parameters[0].Value = model.productTypeid; parameters[1].Value = model.productName; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ProductTypeM model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into productType("); strSql.Append("productName,orderId)"); strSql.Append(" values ("); strSql.Append("@productName,@orderId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@productName", SqlDbType.VarChar, 50), new SqlParameter("@orderId", SqlDbType.Int) }; parameters[0].Value = model.productName; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public ProductTypeM GetModel(int productTypeid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 productTypeid,productName,orderId from productType "); strSql.Append(" where productTypeid=@productTypeid"); SqlParameter[] parameters = { new SqlParameter("@productTypeid", SqlDbType.Int, 4) }; parameters[0].Value = productTypeid; ProductTypeM model = new ProductTypeM(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["productTypeid"].ToString() != "") { model.productTypeid = int.Parse(ds.Tables[0].Rows[0]["productTypeid"].ToString()); } model.orderId = int.Parse(ds.Tables[0].Rows[0]["orderId"].ToString()); model.productName = ds.Tables[0].Rows[0]["productName"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 获得数据列表 /// </summary> public List <ProductTypeM> DataTableToList(DataTable dt) { List <ProductTypeM> modelList = new List <ProductTypeM>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { ProductTypeM model; for (int n = 0; n < rowsCount; n++) { model = new ProductTypeM(); if (dt.Rows[n]["productTypeid"].ToString() != "") { model.productTypeid = int.Parse(dt.Rows[n]["productTypeid"].ToString()); } model.productName = dt.Rows[n]["productName"].ToString(); modelList.Add(model); } } return(modelList); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ProductTypeM model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(ProductTypeM model) { return(dal.Add(model)); }