protected void btnSaveChanges_Click(object sender, EventArgs e) { try { if (hdnInsertDataNotSaved.Value == "Y") { //Validate Page.Validate("valInsertAccountType"); 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()); string accountTypeId; string sourceType; string isConsolid; string isInclude; if (ddlAccountTypeDescInsert.SelectedIndex > 0) { accountTypeId = ddlAccountTypeDescInsert.SelectedValue; } else { accountTypeId = null; } if (ddlSourceTypeInsert.SelectedIndex > 0) { sourceType = ddlSourceTypeInsert.SelectedValue; } else { sourceType = string.Empty; } if (cbConsolidInsert.Checked) { isConsolid = "Y"; } else { isConsolid = "N"; } if (cbInIncludeInsert.Checked) { isInclude = "Y"; } else { isInclude = "N"; } accountTypeMaintenanceBL = new AccountTypeMaintenanceBL(); DataSet accountTypeData = accountTypeMaintenanceBL.InsertAccountTypeMapData(txtAccountTypeCode.Text, accountTypeId, sourceType, isConsolid, isInclude, userCode, out errorId); accountTypeMaintenanceBL = null; if (errorId == 1) { msgView.SetMessage("Account type exists with this account code and include value combination.", MessageType.Success, PositionType.Auto); } else if (accountTypeData.Tables.Count != 0 && errorId != 2) { Session["AccountTypeData"] = accountTypeData.Tables[0]; BindGrid(accountTypeData.Tables[0]); txtAccountTypeCode.Text = string.Empty; lblDisplayOrderInsert.Text = string.Empty; cbConsolidInsert.Checked = false; cbInIncludeInsert.Checked = false; ddlAccountTypeDescInsert.SelectedIndex = 0; ddlSourceTypeInsert.SelectedIndex = 0; hdnChangeNotSaved.Value = "N"; hdnInsertDataNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; hdnSearchText.Value = null; txtAccountTypeSearch.Text = string.Empty; msgView.SetMessage("Account Type details saved successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to save account type details.", MessageType.Warning, PositionType.Auto); } } else if (hdnChangeNotSaved.Value == "Y") { int rowIndex = Convert.ToInt32(hdnGridRowSelectedPrvious.Value); //Validate Page.Validate("GroupUpdate_" + rowIndex + ""); 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()); string accountTypeCode = ((Label)gvAccountTypeDetails.Rows[rowIndex].FindControl("lblAccountTypeCode")).Text; string isInclude = ((HiddenField)gvAccountTypeDetails.Rows[rowIndex].FindControl("hdnIsInclude")).Value; string sourceType = ((DropDownList)gvAccountTypeDetails.Rows[rowIndex].FindControl("ddlSourceType")).SelectedValue; if (sourceType == "-") { sourceType = string.Empty; } string isConsolid; if (((CheckBox)gvAccountTypeDetails.Rows[rowIndex].FindControl("cbConsolid")).Checked) { isConsolid = "Y"; } else { isConsolid = "N"; } string isIncludeNew; if (((CheckBox)gvAccountTypeDetails.Rows[rowIndex].FindControl("cbIsInclude")).Checked) { isIncludeNew = "Y"; } else { isIncludeNew = "N"; } accountTypeMaintenanceBL = new AccountTypeMaintenanceBL(); DataSet accountTypeData = accountTypeMaintenanceBL.UpdateAccountTypeMapData(accountTypeCode, isInclude, sourceType, isConsolid, isIncludeNew, userCode, out errorId); accountTypeMaintenanceBL = null; if (errorId == 1) { msgView.SetMessage("Account type exists with this account code and include value combination.", MessageType.Success, PositionType.Auto); } else if (accountTypeData.Tables.Count != 0 && errorId != 2) { Session["AccountTypeData"] = accountTypeData.Tables[0]; PopulateGrid(); hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Account Type details updated successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to updated account type details.", MessageType.Warning, PositionType.Auto); } } } catch (Exception ex) { ExceptionHandler("Error in saving account type data.", ex.Message); } }
protected void gvAccountTypeDetails_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); Page.Validate("GroupUpdate_" + rowIndex + ""); if (!Page.IsValid) { msgView.SetMessage("Invalid data entered.Please correct.", MessageType.Warning, PositionType.Auto); return; } //int rowIndex = ((GridViewRow)((ImageButton)(e.CommandSource)).NamingContainer).RowIndex; string accountTypeCode = ((Label)gvAccountTypeDetails.Rows[rowIndex].FindControl("lblAccountTypeCode")).Text; string isInclude = ((HiddenField)gvAccountTypeDetails.Rows[rowIndex].FindControl("hdnIsInclude")).Value; string sourceType = ((DropDownList)gvAccountTypeDetails.Rows[rowIndex].FindControl("ddlSourceType")).SelectedValue; if (sourceType == "-") { sourceType = string.Empty; } string isConsolid; if (((CheckBox)gvAccountTypeDetails.Rows[rowIndex].FindControl("cbConsolid")).Checked) { isConsolid = "Y"; } else { isConsolid = "N"; } string isIncludeNew; if (((CheckBox)gvAccountTypeDetails.Rows[rowIndex].FindControl("cbIsInclude")).Checked) { isIncludeNew = "Y"; } else { isIncludeNew = "N"; } accountTypeMaintenanceBL = new AccountTypeMaintenanceBL(); DataSet accountTypeData = accountTypeMaintenanceBL.UpdateAccountTypeMapData(accountTypeCode, isInclude, sourceType, isConsolid, isIncludeNew, userCode, out errorId); accountTypeMaintenanceBL = null; if (errorId == 1) { msgView.SetMessage("Account type exists with this account code and include value combination.", MessageType.Success, PositionType.Auto); } else if (accountTypeData.Tables.Count != 0 && errorId != 2) { Session["AccountTypeData"] = accountTypeData.Tables[0]; PopulateGrid(); hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; msgView.SetMessage("Account Type details saved successfully.", MessageType.Success, PositionType.Auto); } else { msgView.SetMessage("Failed to save account type details.", MessageType.Warning, PositionType.Auto); } } } else if (e.CommandName == "cancelrow") { PopulateGrid(); hdnChangeNotSaved.Value = "N"; hdnGridRowSelectedPrvious.Value = null; } } catch (Exception ex) { ExceptionHandler("Error in saving account type data.", ex.Message); } }