/// <summary> /// 添加产品小类 /// </summary> /// <param name="id"></param> /// <param name="info"></param> /// <returns></returns> public int AddType(ProductTypeInfo info) { int id = add(tableName, "parentId",1,8,info.parentId, "typeName",2,255,info.typeName, "imgUrl",2,255,info.imgUrl, "orderId",1,8,info.orderId, "content",2,info.content.Length,info.content ); return id; }
/// <summary> /// 修改产品类型 /// </summary> /// <param name="info"></param> /// <returns></returns> public bool Update(ProductTypeInfo info) { // DataSetExecuteText(@"update JOLE_produceType set typeName=@typeName, // imgUrl=@imgUrl,orderId=@orderId,content=@content where id=@id", // "@id", info.id, // "@typeName", info.typeName, // "@imgUrl", info.imgUrl, // "@orderId", info.orderId, // "@content", info.content); edit(tableName, info.id.ToString(), "typeName", 2, 255, info.typeName, "imgUrl", 2, 255, info.imgUrl, "orderId", 1, 8, info.orderId, "content", 2, info.content.Length, info.content ); return true; }
/// <summary> /// 读取信息 /// </summary> /// <param name="id"></param> /// <returns></returns> public ProductTypeInfo read(int id) { ProductTypeInfo tp = new ProductTypeInfo(); DataSet ds = find("productType", id.ToString()); if (ds.Tables.Count>0) { if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Rows[0]; tp.typeName = dr["typeName"].ToString(); tp.imgUrl = dr["imgUrl"].ToString(); tp.parentId = Int32.Parse(dr["parentId"].ToString()); tp.orderId = int.Parse(dr["orderId"].ToString()); tp.content = dr["content"].ToString(); tp.id = id; } } return tp; }
protected void save_ServerClick(object sender, EventArgs e) { string TypeName = ProductTypeName.Value.ToString(); string err; if (TypeName != "") { ProductTypeInfo info = new ProductTypeInfo(); ProductTypeDal ad = new ProductTypeDal(); Img img = new Img(); img.savePathName = "producttype"; if (action == "edit") { string delimg = pform("delimg"); if (delimg == "1") { img.dropimg(imgUrl.Value); info.imgUrl = ""; } else { info.imgUrl = img.saveImage(imgUrl.Value); } if (img.error != "") showMessage(img.error); info.typeName = ProductTypeName.Value; info.orderId = int.Parse(orderId.Value); info.id = getId("id"); info.content = pform("content"); ad.Update(info); err = "修改成功"; } else { info.typeName = TypeName; info.orderId = int.Parse(orderId.Value); info.imgUrl = img.saveImage(""); info.content = pform("content"); if (img.error != "") showMessage(img.error); int id = 0; gnum(ref id, "id"); info.parentId = id; ad.AddType(info); err = "添加成功"; } showMessage(err, "pro_type.aspx"); } else { labelErr.Text = "<font color=red>不能为空</font>"; } }
/// <summary> /// 大类列表 /// </summary> /// <returns></returns> public List<ProductTypeInfo> Getbigtypelist() { List<ProductTypeInfo> list = new List<ProductTypeInfo>(); DataSet ds = find("productType", "parentId=0"); if (ds.Tables.Count>0) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataRow dr in ds.Tables[0].Rows) { ProductTypeInfo info = new ProductTypeInfo(); info.typeName = dr["typeName"].ToString(); info.imgUrl = dr["imgUrl"].ToString(); info.parentId = Int32.Parse(dr["parentId"].ToString()); info.orderId = int.Parse(dr["orderId"].ToString()); info.id = int.Parse(dr["id"].ToString()) ; list.Add(info); } } } return list; }
/// <summary> /// 读父类数据 /// </summary> /// <param name="id"></param> /// <returns></returns> public ProductTypeInfo load_parent(int id) { ProductTypeInfo tp = new ProductTypeInfo(); DataRow dr = get_info("productType", "parentId="+id.ToString()); if (!dr.IsNull("id")) { tp.typeName = dr["typeName"].ToString(); tp.imgUrl = dr["imgUrl"].ToString(); tp.parentId = Int32.Parse(dr["parentId"].ToString()); tp.orderId = int.Parse(dr["orderId"].ToString()); tp.id = id; } return tp; }