public CategoryTypeInfo GetInfo(int id) { CategoryTypeInfo oCategoryType = null; var param = new[] { new SqlParameter("@pk_ID", SqlDbType.Int) { Value = id } }; var r = DataHelper.ExecuteReader(Config.ConnectionString, "usp_CategoryType_GetDetail", param); while (r.Read()) { oCategoryType = new CategoryTypeInfo { pk_ID = Convert.ToInt32(r["pk_ID"]), s_CategoryName = r["s_CategoryName"].ToString(), ParentID = ConvertUtility.ToInt32(r["ParentID"]), IsContent = (r["IsContent"].ToString().ToLower() == "true") }; } r.Close(); r.Dispose(); return(oCategoryType); }
protected void btSubmit_Click(object sender, EventArgs e) { if (!UserRightImpl.CheckRightAdminnistrator().UserEdit) { Response.Redirect(Utility.UrlRoot + Config.PathNotRight, false); return; } try { int userID = 0; CategoryTypeImpl obj = new CategoryTypeImpl(); if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != string.Empty) { try { userID = int.Parse(Request.QueryString["ID"]); CategoryTypeInfo item = obj.GetInfo(userID); if (item == null) { Response.Redirect(Utility.UrlRoot + Config.PathError, false); return; } else { item.s_CategoryName = txtName.Text; obj.Update(item); //reset cache DeleteCache(item.pk_ID); } } catch { Response.Redirect(Utility.UrlRoot + Config.PathError, false); return; } } else { CategoryTypeInfo item = new CategoryTypeInfo(); item.s_CategoryName = txtName.Text; obj.Insert(item); //reset cache DeleteCache(item.pk_ID); } Response.Redirect("newtype_manager.aspx", false); } catch { lblMsg.Text = "Tên loại tin đã tồn tại. Bạn chạy chọn một tên khác"; } }
public int Insert(CategoryTypeInfo info) { SqlParameter[] sqlParameter = { new SqlParameter("@s_CategoryName", info.s_CategoryName), new SqlParameter("@ParentID", info.ParentID), new SqlParameter("@IsContent", info.IsContent) }; int result = DataHelper.ExecuteNonQuery(Config.ConnectionString, "usp_CategoryType_Insert", sqlParameter); return(result); }
private void EditData() { try { CategoryTypeImpl obj = new CategoryTypeImpl(); CategoryTypeInfo item = obj.GetInfo(int.Parse(Request.QueryString["ID"])); if (item == null) { Response.Redirect(Utility.UrlRoot + Config.PathError, false); return; } else { txtName.Text = item.s_CategoryName; } } catch { Response.Redirect(Utility.UrlRoot + Config.PathError, false); return; } }