protected void Page_Load(object sender, EventArgs e) { id = Request.QueryString["id"] ?? "0"; if (IsPostBack) { return; } List <Option> options = BuildProductCategorySelection(5); foreach (Option option in options) { Nodes = string.Concat(Nodes, string.Format(lblNodeFormat.Text, option.ID, option.Name)); } if (id != "0") { Sys_DanhMucDonViRepository repository = new Sys_DanhMucDonViRepository(); Sys_DanhMucDonVi department = repository.GetById(int.Parse(id)); txtCode.Text = department.MaHieuDonVi; txtName.Text = department.TenDonVi; txtNote.Text = department.GhiChu; parentID = department.MaDonViCapTren; } }
protected void btnSave_Click(object sender, EventArgs e) { try { int groupdID = 0; string name = txtCode.Text; string role = string.Empty; bool isExistName = false;// Sys_DanhMucDonVi entity = new Sys_DanhMucDonVi(); Sys_DanhMucDonViRepository repository = new Sys_DanhMucDonViRepository(); if (id != "0") { entity = repository.GetById(int.Parse(id)); if (entity.MaHieuDonVi != txtCode.Text) { isExistName = repository.IsExistDepartmentCode(name); } } else { isExistName = repository.IsExistDepartmentCode(name); } if (isExistName) { ClientScriptManager cs = Page.ClientScript; String cstext1 = "alert('Tên nhóm đã tồn tại, vui lòng chọn tên khác');"; cs.RegisterStartupScript(this.GetType(), "alert", cstext1, true); return; } entity.MaHieuDonVi = txtCode.Text; entity.NgayThayDoi = DateTime.Now; entity.NgayTao = DateTime.Now; entity.TenDonVi = txtName.Text; entity.GhiChu = txtNote.Text; int temp = 0; int.TryParse(Request.Form["ddlDepartment"], out temp); entity.MaDonViCapTren = temp; if (id == "0") { repository.Add(entity); } repository.SubmitChanges(); groupdID = entity.ID; Response.Redirect("default.aspx?page=department"); } catch (Exception ex) { //lblMessage.CssClass = "error"; //lblMessage.Visible = true; //lblMessage.Text = "Lỗi trong quá trình cập nhật, lỗi: " + ex.Message; string message = "Lỗi trong quá trình cập nhật, lỗi: " + ex.Message; String cstext2 = "alert('" + message + "');"; Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", cstext2, true); } }