protected void btnActiveOrDeactive_Command(object sender, CommandEventArgs e) { try { string id = Convert.ToString(e.CommandArgument); if (!string.IsNullOrEmpty(id)) { CountryBLL countryBLL = new CountryBLL(); DataTable dt = countryBLL.GetById(Convert.ToInt32(QuaintSecurityManager.Decrypt(id))); if (dt != null) { if (dt.Rows.Count > 0) { string actionStatus = "Updated"; Countries country = new Countries(); country.CountryId = Convert.ToInt32(Convert.ToString(dt.Rows[0]["CountryId"])); country.CountryCode = Convert.ToString(dt.Rows[0]["CountryCode"]); country.Name = Convert.ToString(dt.Rows[0]["Name"]); country.CountryCodeAlpha2 = Convert.ToString(dt.Rows[0]["CountryCodeAlpha2"]); country.CountryCodeAlpha3 = Convert.ToString(dt.Rows[0]["CountryCodeAlpha3"]); country.Description = Convert.ToString(dt.Rows[0]["Description"]); country.IsActive = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"])); country.CreatedDate = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"])); country.CreatedBy = Convert.ToString(dt.Rows[0]["CreatedBy"]); country.CreatedFrom = Convert.ToString(dt.Rows[0]["CreatedFrom"]); country.UpdatedDate = DateTime.Now; country.UpdatedBy = UserInfo; country.UpdatedFrom = StationInfo; if (country.IsActive) { country.IsActive = false; actionStatus = "Deactivated"; } else { country.IsActive = true; actionStatus = "Activated"; } if (countryBLL.Update(country)) { Alert(AlertType.Success, actionStatus + " successfully."); LoadList(); } else { Alert(AlertType.Error, "Failed to update."); } } } } } catch (Exception) { Alert(AlertType.Error, "Failed to process."); } }
static public Country GetById(int id) { Country country = null; Role user_role = Role.Admin; Type type = typeof(CountryBLL); MethodInfo method = type.GetMethod("GetById"); RoleAttribute attribute = method.GetCustomAttribute <RoleAttribute>(); Role function_role = attribute.Role; if (user_role == function_role) { DataRow dr = CountryBLL.GetById(id); country = new Country(); country.ID = dr.Field <int>("ID"); country.Country_Name = dr.Field <string>("Name"); } return(country); }
private void Edit(int id) { try { CountryBLL countryBLL = new CountryBLL(); DataTable dt = countryBLL.GetById(id); if (dt != null) { if (dt.Rows.Count > 0) { this.ModelId = Convert.ToInt32(Convert.ToString(dt.Rows[0]["CountryId"])); this.ModelCode = Convert.ToString(dt.Rows[0]["CountryCode"]); txtName.Text = Convert.ToString(dt.Rows[0]["Name"]); txtCountryCodeAlpha2.Text = Convert.ToString(dt.Rows[0]["CountryCodeAlpha2"]); txtCountryCodeAlpha3.Text = Convert.ToString(dt.Rows[0]["CountryCodeAlpha3"]); txtDescription.Text = Convert.ToString(dt.Rows[0]["Description"]); } } } catch (Exception) { Alert(AlertType.Error, "Failed to edit."); } }
private void SaveAndUpdate() { try { if (string.IsNullOrEmpty(txtName.Text)) { Alert(AlertType.Warning, "Enter country name."); txtName.Focus(); } else { string name = Convert.ToString(txtName.Text); string countryCodeAlpha2 = Convert.ToString(txtCountryCodeAlpha2.Text); string countryCodeAlpha3 = Convert.ToString(txtCountryCodeAlpha3.Text); string description = Convert.ToString(txtDescription.Text); CountryBLL countryBLL = new CountryBLL(); if (this.ModelId > 0) { DataTable dt = countryBLL.GetById(this.ModelId); Countries country = new Countries(); country.CountryId = Convert.ToInt32(Convert.ToString(dt.Rows[0]["CountryId"])); country.CountryCode = Convert.ToString(dt.Rows[0]["CountryCode"]); country.Name = Convert.ToString(dt.Rows[0]["Name"]); country.CountryCodeAlpha2 = Convert.ToString(dt.Rows[0]["CountryCodeAlpha2"]); country.CountryCodeAlpha3 = Convert.ToString(dt.Rows[0]["CountryCodeAlpha3"]); country.Description = Convert.ToString(dt.Rows[0]["Description"]); country.IsActive = Convert.ToBoolean(Convert.ToString(dt.Rows[0]["IsActive"])); country.CreatedDate = (string.IsNullOrEmpty(Convert.ToString(dt.Rows[0]["CreatedDate"]))) ? (DateTime?)null : Convert.ToDateTime(Convert.ToString(dt.Rows[0]["CreatedDate"])); country.CreatedBy = Convert.ToString(dt.Rows[0]["CreatedBy"]); country.CreatedFrom = Convert.ToString(dt.Rows[0]["CreatedFrom"]); country.Name = name.Trim(); country.CountryCodeAlpha2 = countryCodeAlpha2; country.CountryCodeAlpha3 = countryCodeAlpha3; country.Description = description; country.UpdatedDate = DateTime.Now; country.UpdatedBy = this.UserInfo; country.UpdatedFrom = this.StationInfo; if (countryBLL.Update(country)) { this.MultiEntryDisallow = true; Alert(AlertType.Success, "Updated successfully."); ClearFields(); } else { Alert(AlertType.Error, "Failed to update."); } } else { Countries country = new Countries(); country.CountryCode = this.ModelCode; country.Name = name.Trim(); country.CountryCodeAlpha2 = countryCodeAlpha2; country.CountryCodeAlpha3 = countryCodeAlpha3; country.Description = description; country.IsActive = true; country.CreatedDate = DateTime.Now; country.CreatedBy = this.UserInfo; country.CreatedFrom = this.StationInfo; if (countryBLL.Save(country)) { Alert(AlertType.Success, "Saved successfully."); ClearFields(); GenerateCode(); } else { Alert(AlertType.Error, "Failed to save."); } } } } catch (Exception ex) { Alert(AlertType.Error, ex.Message.ToString()); } }