/// <summary> /// Event gridview button /// </summary> /// <modified> /// Author Date Comment /// HungNM 19/06/2014 Add /// </modified> protected void grvCity_RowCommand(object sender, GridViewCommandEventArgs e) { switch (e.CommandName) { case "SUA": Response.Redirect(string.Format("~/Admin/City/Action.aspx?id={0}", e.CommandArgument)); break; case "XOA": // Convert id short intId; if (!short.TryParse((string)e.CommandArgument, out intId)) { ShowMessage("Id không hợp lệ!"); BindCity(); return; } BUS.CITY objBUS = new BUS.CITY(); // Check delete if (objBUS.CheckDel(intId) > 0) { ShowMessage("Thành phố này đã có trường học. Không được phép xóa!"); return; } // Delete if (objBUS.Delete(intId) > 0) ShowMessage("Xóa thành công!"); else ShowMessage("Xóa thất bại!"); // Rebind girdview BindCity(); break; default: ShowMessage("Không tồn tại chức năng này!"); break; } }
/// <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 short intId; if (!short.TryParse(Request["id"], out intId)) { RunJavascript("alert('Id không hợp lệ!');window.location='/Admin/City/Default.aspx';"); return; } BUS.CITY objBUS = new BUS.CITY(); // Get object update _city = objBUS.GetById(intId); if (_city == null) { ShowMessage("Không tìm thấy thành phố này để cập nhật thông tin!"); return; } // Validate _validate = new Common.Validate(); GetInput(); if (_validate.IsError) { ShowMessage(_validate.Message); return; } // Check exist if (objBUS.CheckExist(_city.ID, _city.CITY_NAME.ToLower()) > 0) { ShowMessage("Tên thành phố đã tồn tại!"); return; } // Update if (objBUS.Update(_city) > 0) RunJavascript("alert('Cập nhật thành công!');window.location='/Admin/City/Default.aspx';"); else ShowMessage("Cập nhật thất bại!"); }
/// <summary> /// Event button insert click /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> protected void btnInsert_Click(object sender, EventArgs e) { _city = new VO.CITY(); // Validate _validate = new Common.Validate(); GetInput(); if (_validate.IsError) { ShowMessage(_validate.Message); return; } // Check exist BUS.CITY objBUS = new BUS.CITY(); if (objBUS.CheckExist(_city.ID, _city.CITY_NAME.ToLower()) > 0) { ShowMessage("Tên thành phố đã tồn tại!"); return; } // Insert if (objBUS.Insert(_city) > 0) RunJavascript("alert('Thêm mới thành công');window.location='/Admin/City/Default.aspx'"); else RunJavascript("alert('Thêm mới thất bại');window.location='/Admin/City/Default.aspx'"); }
/// <summary> /// Get data input /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> private void GetInput() { // Validate school name _school.SCHOOL_NAME = txtSchoolName.Text.Trim(); if (_school.SCHOOL_NAME == string.Empty) { _validate.IsError = true; _validate.Message = "Yêu cầu nhập tên trường học!"; return; } if (_school.SCHOOL_NAME.Length > 500) { _validate.IsError = true; _validate.Message = "Tên trường học tối đa 500 ký tự!"; return; } // Validate address string strAddress = txtAddress.Text.Trim(); if (strAddress != string.Empty) { if (strAddress.Length > 500) { _validate.IsError = true; _validate.Message = "Địa chỉ tối đa 500 ký tự!"; return; } _school.ADDRESS = strAddress; } // Validate telephone string strTelephone = txtTelephone.Text.Trim(); if (strTelephone != string.Empty) { if (strTelephone.Length > 20) { _validate.IsError = true; _validate.Message = "Số điện thoại tối đa 20 ký tự!"; return; } if (!Common.Common.ValidateTelephoneNumber(strTelephone)) { _validate.IsError = true; _validate.Message = "Số điện thoại không hợp lệ!"; return; } _school.TELEPHONE = strTelephone; } // Validate email address string strEmail = txtEmail.Text.Trim(); if (strEmail != string.Empty) { if (strEmail.Length > 320) { _validate.IsError = true; _validate.Message = "Email tối đa 320 ký tự"; return; } if (!Common.Common.ValidateEmailAddress(strEmail)) { _validate.IsError = true; _validate.Message = "Email không hợp lệ!"; return; } _school.EMAIL = strEmail; } // Validate website string strWebsite = txtWebsite.Text.Trim(); if (strWebsite != string.Empty) { if (strWebsite.Length > 253) { _validate.IsError = true; _validate.Message = "Website tối đa 253 ký tự"; return; } if (!Common.Common.ValidateDomain(strWebsite)) { _validate.IsError = true; _validate.Message = "Website không hợp lệ!"; return; } _school.WEBSITE = strWebsite; } // Validate city if (string.IsNullOrEmpty(ddlCity.SelectedValue)) { _validate.IsError = true; _validate.Message = "Yêu cầu chọn thành phố!"; return; } short sCityId; if (!short.TryParse(ddlCity.SelectedValue, out sCityId)) { _validate.IsError = true; _validate.Message = "Id thành phố không hợp lệ!"; return; } VO.CITY objCity = new BUS.CITY().GetById(sCityId); if (objCity == null) { _validate.IsError = true; _validate.Message = "Không tìm thấy thành phố này!"; return; } _school.CITY_ID = objCity.ID; }
/// <summary> /// Bind dropdownlist City /// </summary> /// <modified> /// Author Date Comment /// HungNM 14/06/2014 Add /// </modified> private void BindCity() { DataTable dt = new BUS.CITY().GetForLI(); ddlCity.DataSource = dt; ddlCity.DataValueField = "ID"; ddlCity.DataTextField = "CITY_NAME"; ddlCity.DataBind(); ddlCity.Items.Insert(0, new ListItem("--- Chọn thành phố ---", string.Empty)); }