private void LoadControls(SqlInt32 BranchID) { BranchENT entBranch = new BranchENT(); BranchBAL balBranch = new BranchBAL(); entBranch = balBranch.SelectByPK(BranchID); if (!entBranch.BranchName.IsNull) { txtBranchName.Text = entBranch.BranchName.Value.ToString(); } if (!entBranch.MobileNo.IsNull) { txtMobileNo.Text = entBranch.MobileNo.Value.ToString(); } if (!entBranch.Address.IsNull) { txtBranchAddress.Text = entBranch.Address.Value.ToString(); } if (!entBranch.ManagerName.IsNull) { txtManagerName.Text = entBranch.ManagerName.Value.ToString(); } if (!entBranch.ManagerMobileNo.IsNull) { txtManagerMobileNo.Text = entBranch.ManagerMobileNo.Value.ToString(); } }
private void FillBranchGridView() { if (Session["UserID"] != null) { BranchBAL balBranch = new BranchBAL(); DataTable dtBranch = balBranch.SelectAll(); if (dtBranch != null && dtBranch.Rows.Count > 0) { gvBranch.DataSource = dtBranch; gvBranch.DataBind(); } } }
protected void gvBranch_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteRecord" && e.CommandArgument != null) { try { BranchBAL balBranch = new BranchBAL(); if (balBranch.Delete(Convert.ToInt32(e.CommandArgument))) { FillBranchGridView(); } else { lblMessage.Text = balBranch.Message; } } catch (Exception ex) { lblMessage.Text = ex.Message.ToString(); } } }
protected void btnSave_Click(object sender, EventArgs e) { try { #region Server Side Validation String strError = String.Empty; if (txtBranchName.Text.Trim() == String.Empty) { strError += "- Enter Branch Name<br />"; } if (txtMobileNo.Text.Trim() == String.Empty) { strError += "- Enter Mobile No<br />"; } if (txtBranchAddress.Text.Trim() == String.Empty) { strError += "- Enter Branch Address<br />"; } if (txtManagerName.Text.Trim() == String.Empty) { strError += "- Enter Manager Name<br />"; } if (txtManagerMobileNo.Text.Trim() == String.Empty) { strError += "- Enter Manager MobileNo<br />"; } #endregion Server Side Validation BranchENT entBranch = new BranchENT(); BranchBAL balBranch = new BranchBAL(); #region Gather Data if (txtBranchName.Text.Trim() != String.Empty) { entBranch.BranchName = txtBranchName.Text.Trim(); } if (txtMobileNo.Text.Trim() != String.Empty) { entBranch.MobileNo = txtMobileNo.Text.Trim(); } if (txtBranchAddress.Text.Trim() != String.Empty) { entBranch.Address = txtBranchAddress.Text.Trim(); } if (txtManagerName.Text.Trim() != String.Empty) { entBranch.ManagerName = txtManagerName.Text.Trim(); } if (txtManagerMobileNo.Text.Trim() != String.Empty) { entBranch.ManagerMobileNo = txtManagerMobileNo.Text.Trim(); } entBranch.UserID = Convert.ToInt32(Session["UserID"]); if (Request.QueryString["BranchID"] == null) { balBranch.Insert(entBranch); lblMessage.Text = "Data Inserted Successfully"; ClearControls(); } else { entBranch.BranchID = Convert.ToInt32(Request.QueryString["BranchID"]); balBranch.Update(entBranch); Response.Redirect("~/AdminPanel/Branch/BranchList.aspx"); } #endregion Gather Data } catch (Exception ex) { lblErrorMessage.Text = ex.Message.ToString(); } }