/// <summary> /// Event button insert click /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> protected void btnInsert_Click(object sender, EventArgs e) { // Validate input _validate = new Common.Validate(); _school = new VO.SCHOOL(); GetInput(); if (_validate.IsError) { ShowMessage(_validate.Message); return; } BUS.SCHOOL objBUS = new BUS.SCHOOL(); // Check exist if (objBUS.CheckExist(_school.ID, _school.SCHOOL_NAME.ToLower()) > 0) { ShowMessage("Đã tồn tại trường học với tên này!"); return; } // Insert if (objBUS.Insert(_school) > 0) RunJavascript("alert('Thêm mới thành công!');window.location='/Admin/School/Default.aspx';"); else ShowMessage("Thêm mới thất bại!"); }
/// <summary> /// Get by id /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> public VO.SCHOOL GetById(int id) { DataTable dt = new DAO.SCHOOL().GetById(id); if (dt != null && dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; VO.SCHOOL obj = new VO.SCHOOL(); obj.ID = (int)dr["ID"]; obj.SCHOOL_NAME = (string)dr["SCHOOL_NAME"]; if (dr["ADDRESS"] != DBNull.Value) obj.ADDRESS = (string)dr["ADDRESS"]; if (dr["TELEPHONE"] != DBNull.Value) obj.TELEPHONE = (string)dr["TELEPHONE"]; if (dr["EMAIL"] != DBNull.Value) obj.EMAIL = (string)dr["EMAIL"]; if (dr["WEBSITE"] != DBNull.Value) obj.WEBSITE = (string)dr["WEBSITE"]; obj.CITY_ID = (short)dr["CITY_ID"]; return obj; } else return null; }
/// <summary> /// Event button update click /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> protected void btnUpdate_Click(object sender, EventArgs e) { // Convert id int intId; if (!int.TryParse(Request["id"], out intId)) { RunJavascript("alert('Id không hợp lệ');window.location='/Admin/School/Default.aspx';"); return; } BUS.SCHOOL objBUS = new BUS.SCHOOL(); // Get object update _school = objBUS.GetById(intId); if (_school == null) { RunJavascript("alert('Không tìm thấy trường để sửa');window.location='/Admin/School/Default.aspx';"); return; } // Validate input _validate = new Common.Validate(); GetInput(); if (_validate.IsError) { ShowMessage(_validate.Message); return; } // Check exist if (objBUS.CheckExist(_school.ID, _school.SCHOOL_NAME.ToLower()) > 0) { ShowMessage("Đã tồn tại trườnghọc với tên này!"); return; } // Update if (objBUS.Update(_school) > 0) RunJavascript("alert('Cập nhật thành công!');window.location='/Admin/School/Default.aspx';"); else ShowMessage("Cập nhật thất bại!"); }
/// <summary> /// Bind school /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> private void BindSchool(int id) { _school = new BUS.SCHOOL().GetById(id); if (_school == null) { _validate.IsError = true; _validate.Message = "Không tìm thấy trường này!"; return; } txtSchoolName.Text = _school.SCHOOL_NAME; txtAddress.Text = _school.ADDRESS; txtEmail.Text = _school.EMAIL; txtTelephone.Text = _school.TELEPHONE; txtWebsite.Text = _school.WEBSITE; string strCityID = _school.CITY_ID.ToString(); if (ddlCity.Items.FindByValue(strCityID) != null) ddlCity.SelectedValue = strCityID; }