//JIRA-908 Changes by ravi in 13/02/2019 --End #endregion Events #region Methods private void LoadData() { ownerMaintenanceBL = new OwnerMaintenanceBL(); DataSet initialData = ownerMaintenanceBL.GetInitialData(out newOwnerCode, out errorId); ownerMaintenanceBL = null; if (newOwnerCode != 0) { txtOwnerCode.Text = newOwnerCode.ToString(); } if (initialData.Tables.Count != 0 && errorId != 2) { hdnPageNumber.Value = "1"; Session["OwnerMaintData"] = initialData.Tables[0]; BindGrid(initialData.Tables[0]); } else { ExceptionHandler("Error in fetching filter list data", string.Empty); } if (Request.QueryString != null && Request.QueryString.Count > 0) { txtOwnerSearch.Text = Request.QueryString[0]; OwnerSelected(); } }
//JIRA-908 Changes by ravi in 13/02/2019 -- Start protected void btnYes_Click(object sender, EventArgs e) { try { int ownerCode = Convert.ToInt32(hdnOwnerCode.Value); ownerMaintenanceBL = new OwnerMaintenanceBL(); DataSet ownerData = ownerMaintenanceBL.DeleteOwnerData(ownerCode, Convert.ToString(Session["UserCode"]), out newOwnerCode, out errorId); ownerMaintenanceBL = null; if (errorId == 1) { msgView.SetMessage("Can't delete owner as it's being used in contract.", MessageType.Success, PositionType.Auto); } else if (ownerData.Tables.Count != 0 && errorId == 0) { Session["OwnerList"] = ownerData.Tables[0]; BindGrid(ownerData.Tables[0]); txtOwnerSearch.Text = string.Empty; hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Owner deleted successfully.", MessageType.Success, PositionType.Auto); hdnOwnerCode.Value = ""; } else { msgView.SetMessage("Failed to delete owner.", MessageType.Warning, PositionType.Auto); } } catch (Exception ex) { ExceptionHandler("Failed to delete owner.", ex.Message); } }
protected void imgBtnInsert_Click(object sender, ImageClickEventArgs e) { try { if (Session["OwnerMaintData"] != null) { DataTable dtOwnerData = Session["OwnerMaintData"] as DataTable; if (dtOwnerData.Select("owner_code = '" + txtOwnerCode.Text + "'").Length != 0) { msgView.SetMessage("Owner already exists with this owner code.", MessageType.Success, PositionType.Auto); return; } } string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); ownerMaintenanceBL = new OwnerMaintenanceBL(); DataSet ownerData = ownerMaintenanceBL.InsertOwnerData(Convert.ToInt32(txtOwnerCode.Text.Trim()), txtOwnerDesc.Text.Trim().ToUpper(), userCode, out newOwnerCode, out errorId); ownerMaintenanceBL = null; if (ownerData.Tables.Count != 0 && errorId != 2 && newOwnerCode != 0) { Session["OwnerMaintData"] = ownerData.Tables[0]; Session["FuzzySearchAllOwnerList"] = ownerData.Tables[1]; gvOwnerDetails.PageIndex = gvOwnerDetails.PageCount - 1; BindGrid(ownerData.Tables[0]); txtOwnerDesc.Text = string.Empty; txtOwnerCode.Text = string.Empty; txtOwnerSearch.Text = string.Empty; hdnChangeNotSaved.Value = "N"; hdnInsertDataNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; txtOwnerCode.Text = newOwnerCode.ToString(); msgView.SetMessage("Owner created successfully.", MessageType.Success, PositionType.Auto); } else if (newOwnerCode == 0) { msgView.SetMessage("Owner already exists with this owner code.", MessageType.Success, PositionType.Auto); return; } else { msgView.SetMessage("Failed to create owner.", MessageType.Warning, PositionType.Auto); } } catch (Exception ex) { ExceptionHandler("Error in creating owner.", ex.Message); } }
protected void btnSaveChanges_Click(object sender, EventArgs e) { try { if (hdnInsertDataNotSaved.Value == "Y") { //Validate Page.Validate("valInsertOwner"); if (!Page.IsValid) { mpeSaveUndo.Hide(); msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto); return; } if (Session["OwnerMaintData"] != null) { DataTable dtOwnerData = Session["OwnerMaintData"] as DataTable; if (dtOwnerData.Select("owner_code = '" + txtOwnerCode.Text + "'").Length != 0) { msgView.SetMessage("Owner already exists with this owner code.", MessageType.Success, PositionType.Auto); return; } } string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); ownerMaintenanceBL = new OwnerMaintenanceBL(); DataSet ownerData = ownerMaintenanceBL.InsertOwnerData(Convert.ToInt32(txtOwnerCode.Text.Trim()), txtOwnerDesc.Text.Trim().ToUpper(), userCode, out newOwnerCode, out errorId); ownerMaintenanceBL = null; if (ownerData.Tables.Count != 0 && errorId != 2) { Session["OwnerMaintData"] = ownerData.Tables[0]; Session["FuzzySearchAllOwnerList"] = ownerData.Tables[1]; gvOwnerDetails.PageIndex = gvOwnerDetails.PageCount - 1; BindGrid(ownerData.Tables[0]); txtOwnerDesc.Text = string.Empty; txtOwnerCode.Text = string.Empty; txtOwnerSearch.Text = string.Empty; hdnChangeNotSaved.Value = "N"; hdnInsertDataNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Owner created successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to create owner.", MessageType.Warning, PositionType.Auto); } } else if (hdnChangeNotSaved.Value == "Y") { //Validate //WUIN-932 -corrections - moved the validation to blow logic as this is not working on save/undo popup //Page.Validate("valUpdateOwner"); //if (!Page.IsValid) //{ // mpeSaveUndo.Hide(); // msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto); // return; //} string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); int rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value); int ownerCode = Convert.ToInt32(((Label)gvOwnerDetails.Rows[rowIndex].FindControl("lblOwnerCode")).Text); string ownerName = ((TextBox)gvOwnerDetails.Rows[rowIndex].FindControl("txtOwnerName")).Text; //Validate if (ownerName == string.Empty) { mpeSaveUndo.Hide(); msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto); return; } ownerMaintenanceBL = new OwnerMaintenanceBL(); DataSet ownerData = ownerMaintenanceBL.UpdateOwnerData(ownerCode, ownerName, userCode, out newOwnerCode, out errorId); ownerMaintenanceBL = null; if (ownerData.Tables.Count != 0 && errorId != 2) { Session["OwnerMaintData"] = ownerData.Tables[0]; Session["FuzzySearchAllOwnerList"] = ownerData.Tables[1]; //check if there is only one row in the grid before binding updated data. //if count is 1 then only display that row if (gvOwnerDetails.Rows.Count == 1) { DataTable dtSearched = ownerData.Tables[0].Clone(); DataRow[] foundRows = ownerData.Tables[0].Select("owner_code = '" + ownerCode + "'"); if (foundRows.Length != 0) { dtSearched = foundRows.CopyToDataTable(); BindGrid(dtSearched); } } else { BindGrid(ownerData.Tables[0]); } hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Owner details updated successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to updated owner details.", MessageType.Warning, PositionType.Auto); } } } catch (Exception ex) { ExceptionHandler("Error in saving grid data.", ex.Message); } }
protected void gvOwnerDetails_RowCommand(object sender, GridViewCommandEventArgs e) { try { string userCode = WebUtility.HtmlDecode(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString()); if (e.CommandName == "saverow") { if (!string.IsNullOrEmpty(hdnGridRowSelectedPrvious.Value)) { int rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value); int ownerCode = Convert.ToInt32(((Label)gvOwnerDetails.Rows[rowIndex].FindControl("lblOwnerCode")).Text); string ownerName = ((TextBox)gvOwnerDetails.Rows[rowIndex].FindControl("txtOwnerName")).Text; ownerMaintenanceBL = new OwnerMaintenanceBL(); DataSet ownerData = ownerMaintenanceBL.UpdateOwnerData(ownerCode, ownerName.Trim().ToUpper(), userCode, out newOwnerCode, out errorId); ownerMaintenanceBL = null; if (ownerData.Tables.Count != 0 && errorId != 2) { Session["OwnerMaintData"] = ownerData.Tables[0]; Session["FuzzySearchAllOwnerList"] = ownerData.Tables[1]; //check if there is only one row in the grid before binding updated data. //if count is 1 then only display that row if (gvOwnerDetails.Rows.Count == 1) { DataTable dtSearched = ownerData.Tables[0].Clone(); DataRow[] foundRows = ownerData.Tables[0].Select("owner_code = '" + ownerCode + "'"); if (foundRows.Length != 0) { dtSearched = foundRows.CopyToDataTable(); BindGrid(dtSearched); } } else { BindGrid(ownerData.Tables[0]); } hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Owner details updated successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to updated owner details.", MessageType.Warning, PositionType.Auto); } } } else if (e.CommandName == "cancelrow") { if (Session["OwnerMaintData"] != null) { DataTable dtOwnerData = Session["OwnerMaintData"] as DataTable; if (gvOwnerDetails.Rows.Count == 1) { string ownerName = ((Label)gvOwnerDetails.Rows[0].FindControl("lblOwnerName")).Text; ((TextBox)gvOwnerDetails.Rows[0].FindControl("txtOwnerName")).Text = ownerName; } else { BindGrid(dtOwnerData); txtOwnerSearch.Text = string.Empty; } hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; } } } catch (Exception ex) { ExceptionHandler("Error in saving/deleting owner data.", ex.Message); } }