//单击save按钮 protected void btnSave_Click(object sender, EventArgs e) { string petCategoryID = tbEditPetCategoryID.Text.Trim().ToString(); string petCategoryInfo = tbEditPetCategoryInfo.Text.Trim().ToString(); string petCategoryName = tbEditPetCategoryName.Text.Trim().ToString(); bool isVisible = bool.Parse(cbIsvisible.Checked.ToString()); CTPetCategory tpetcategory = new CTPetCategory(); tpetcategory.petCategoryID = petCategoryID; tpetcategory.petCategoryInfo = petCategoryInfo; tpetcategory.petCategoryName = petCategoryName; tpetcategory.IsVisible = isVisible; PetCategory petcategory = new PetCategory(); int insertStatus = petcategory.EditPetCategory(tpetcategory); if (insertStatus != 0) { LoadData(); Response.Write("<script>alert('update成功!')</script>"); } else { Response.Write("<script>alert('update失败!')</script>"); } }
protected void BtnAdd_Click(object sender, EventArgs e) { string petcategoryID = tbPetCategoryID.Text.Trim().ToString(); string categoryName = tbCategoryName.Text.Trim().ToString(); string categoryInfo = tbCategoryInfo.Text.Trim().ToString(); CTPetCategory category = new CTPetCategory(); category.petCategoryID = petcategoryID; category.petCategoryName = categoryName; category.petCategoryInfo = categoryInfo; PetCategory petcategory = new PetCategory(); int insertStatus = 0; insertStatus = petcategory.InsertPetCategory(category); if (insertStatus != 0) { Response.Write("<script>alert('添加成功!')</script>"); } else { Response.Write("<script>alert('添加失败!')</script>"); } }
//增加宠物分类信息 public int InsertPetCategory(CTPetCategory petCategory) { int insertStatus = 0; SqlParameter[] parms = null; parms = new SqlParameter[] { new SqlParameter("@PetCategoryId", SqlDbType.NVarChar, 20), new SqlParameter("@PetCategoryName", SqlDbType.NVarChar, 50), new SqlParameter("@PetCategoryInfo", SqlDbType.NVarChar, 50), }; parms[0].Value = petCategory.petCategoryID; parms[1].Value = petCategory.petCategoryName; parms[2].Value = petCategory.petCategoryInfo; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringOrderDistributedTransaction)) { insertStatus = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_PetCategory, parms); } return(insertStatus); }
//编辑宠物分类信息 public int EditPetCategoryInfo(CTPetCategory petCategory) { int editStatus = 0; SqlParameter[] parms = null; parms = new SqlParameter[] { new SqlParameter("@PetCategoryID", SqlDbType.NVarChar, 20), new SqlParameter("@PetCategoryName", SqlDbType.NVarChar, 50), new SqlParameter("@PetCategoryInfo", SqlDbType.NVarChar, 50), new SqlParameter("@IsVisible", SqlDbType.Bit), }; parms[0].Value = petCategory.petCategoryID; parms[1].Value = petCategory.petCategoryName; parms[2].Value = petCategory.petCategoryInfo; parms[3].Value = petCategory.IsVisible; using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringOrderDistributedTransaction)) { editStatus = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_EDIT_PetCategory, parms); } return(editStatus); }
//得到所有的宠物分类 public List <CTPetCategory> GetAllPetCategoryInfo() { List <CTPetCategory> list = new List <CTPetCategory>(); //execute the query using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_PetCategory, null)) { while (rdr.Read()) { CTPetCategory petCategory = new CTPetCategory(); petCategory.petCategoryID = rdr["PetCategoryID"].ToString(); petCategory.petCategoryName = rdr["PetCategoryName"].ToString(); petCategory.petCategoryInfo = rdr["petCategoryInfo"].ToString(); petCategory.IsVisible = bool.Parse(rdr["IsVisible"].ToString()); list.Add(petCategory); } rdr.Close(); rdr.Dispose(); } return(list); }
//编辑宠物的种类信息 public int EditPetCategory(CTPetCategory petcategory) { return(dal.EditPetCategoryInfo(petcategory)); }
//插入新的宠物的种类信息 public int InsertPetCategory(CTPetCategory petcategory) { return(dal.InsertPetCategory(petcategory)); }