protected void btnSaveChanges_Click(object sender, EventArgs e) { string branchAdd = ""; UserVo userVo = null; try { branchAdd = Session["BranchAdd"].ToString(); userVo = (UserVo)Session["UserVo"]; // if (chkAvailability()) //{ if (Validation()) { AdvisorBo advisorBo = new AdvisorBo(); advisorId = advisorVo.advisorId; userId = userVo.UserId; //advisorBranchVo.BranchId = advisorBo.getId(); advisorBranchVo.AddressLine1 = txtLine1.Text.ToString(); advisorBranchVo.AddressLine2 = txtLine2.Text.ToString(); advisorBranchVo.AddressLine3 = txtLine3.Text.ToString(); advisorBranchVo.BranchCode = txtBranchCode.Text.ToString(); rmList = advisorStaffBo.GetRMList(advisorVo.advisorId); if (rmList == null) { advisorBranchVo.BranchHeadId = 100; } else { if (ddlRmlist.SelectedIndex != 0) { advisorBranchVo.BranchHeadId = int.Parse(ddlRmlist.SelectedItem.Value.ToString()); } } if (txtMobileNumber.Text == "") { advisorBranchVo.MobileNumber = 0; } else { advisorBranchVo.MobileNumber = long.Parse(txtMobileNumber.Text); } //advisorBranchVo.BranchId = advisorBo.getId().ToString(); advisorBranchVo.BranchName = txtBranchName.Text.ToString(); advisorBranchVo.City = txtCity.Text.Trim(); advisorBranchVo.Country = ddlCountry.SelectedItem.Value.ToString(); advisorBranchVo.Email = txtEmail.Text.Trim().ToString(); advisorBranchVo.BranchTypeCode = Int32.Parse(ddlBranchAssociateType.SelectedItem.Value.ToString()); if (ddlBranchAssociateType.SelectedValue.ToString() == "2") { if (ddlAssociateCategory.SelectedIndex != 0) { advisorBranchVo.AssociateCategoryId = Int32.Parse(ddlAssociateCategory.SelectedItem.Value.ToString()); } if (FileUpload.HasFile) { advisorBranchVo.LogoPath = advisorVo.advisorId + "_" + txtBranchCode.Text.ToString() + ".jpg"; HttpPostedFile myFile = FileUpload.PostedFile; UploadImage(imgPath, myFile, advisorBranchVo.LogoPath); //FileUpload.SaveAs(Server.MapPath("Images") + "\\" + advisorVo.advisorId + "_" + txtBranchCode.Text.ToString() + ".jpg"); } } if (txtFax.Text == "") { advisorBranchVo.Fax = 0; } else { advisorBranchVo.Fax = int.Parse(txtFax.Text.ToString()); } if (txtIsdFax.Text == "") { advisorBranchVo.FaxIsd = 0; } else { advisorBranchVo.FaxIsd = int.Parse(txtIsdFax.Text.ToString()); } if (txtIsdPhone1.Text == "") { advisorBranchVo.Phone1Isd = 0; } else { advisorBranchVo.Phone1Isd = int.Parse(txtIsdPhone1.Text.ToString()); } if (txtIsdPhone2.Text == "") { advisorBranchVo.Phone2Isd = 0; } else { advisorBranchVo.Phone2Isd = int.Parse(txtIsdPhone2.Text.ToString()); } if (txtPhone2.Text == "") { advisorBranchVo.Phone2Number = 0; } else { advisorBranchVo.Phone2Number = int.Parse(txtPhone2.Text.ToString()); } if (txtStdFax.Text == "") { advisorBranchVo.FaxStd = 0; } else { advisorBranchVo.FaxStd = int.Parse(txtStdFax.Text.ToString()); } if (txtStdPhone2.Text == "") { advisorBranchVo.Phone2Std = 0; } else { advisorBranchVo.Phone2Std = int.Parse(txtStdPhone2.Text.ToString()); } advisorBranchVo.Phone1Number = int.Parse(txtPhone1.Text.ToString()); advisorBranchVo.Phone1Std = int.Parse(txtStdPhone1.Text.ToString()); if (txtPinCode.Text == "") { advisorBranchVo.PinCode = 0; } else { advisorBranchVo.PinCode = int.Parse(txtPinCode.Text.ToString()); } if (ddlState.SelectedIndex != 0) { advisorBranchVo.State = ddlState.SelectedItem.Value.ToString(); } else { advisorBranchVo.State = ""; } // Create Branch advisorBranchVo.BranchId = advisorBranchBo.CreateAdvisorBranch(advisorBranchVo, advisorId, userId); //Add Associate Commission Details if (ddlBranchAssociateType.SelectedValue.ToString() == "2") { foreach (GridViewRow row in gvCommStructure.Rows) { DropDownList ddlAssGp = (DropDownList)row.FindControl("ddlAssetGroup"); TextBox commfee = (TextBox)row.FindControl("txtCommFee"); TextBox revUpper = (TextBox)row.FindControl("txtRevUpperLimit"); TextBox revLower = (TextBox)row.FindControl("txtRevLowerLimit"); TextBox startDate = (TextBox)row.FindControl("txtStartDate"); TextBox endDate = (TextBox)row.FindControl("txtEndDate"); if (ddlAssGp.SelectedValue.ToString() != "Select Asset Group") { advisorAssociateCommissionVo.LOBAssetGroupsCode = ddlAssGp.SelectedValue.ToString(); if (commfee.Text.ToString() != string.Empty) { advisorAssociateCommissionVo.CommissionFee = float.Parse(commfee.Text.ToString()); } else { advisorAssociateCommissionVo.CommissionFee = 0; } if (revUpper.Text.ToString() != string.Empty) { advisorAssociateCommissionVo.RevenueUpperlimit = double.Parse(revUpper.Text.ToString()); } else { advisorAssociateCommissionVo.RevenueUpperlimit = 0; } if (revLower.Text.ToString() != string.Empty) { advisorAssociateCommissionVo.RevenueLowerlimit = double.Parse(revLower.Text.ToString()); } else { advisorAssociateCommissionVo.RevenueLowerlimit = 0; } if (startDate.Text.ToString() != string.Empty) { advisorAssociateCommissionVo.StartDate = Convert.ToDateTime(startDate.Text.ToString()); } else { advisorAssociateCommissionVo.StartDate = DateTime.MinValue; } if (endDate.Text.ToString() != string.Empty) { advisorAssociateCommissionVo.EndDate = Convert.ToDateTime(endDate.Text.ToString()); } else { advisorAssociateCommissionVo.EndDate = DateTime.MinValue; } advisorAssociateCommissionVo.BranchId = advisorBranchVo.BranchId; advisorBranchBo.AddAssociateCommission(userId, advisorAssociateCommissionVo); } } } // Creating Branch Association int cnt = advisorStaffBo.CheckRMMainBranch(advisorBranchVo.BranchHeadId); if (cnt == 0) { advisorBranchBo.AssociateBranch(advisorBranchVo.BranchHeadId, advisorBranchVo.BranchId, 1, userId); } else { advisorBranchBo.AssociateBranch(advisorBranchVo.BranchHeadId, advisorBranchVo.BranchId, 0, userId); } //if (!advisorBranchBo.CheckBranchMgrRole(advisorBranchVo.BranchHeadId)) //{ // int rmUserId = advisorStaffBo.GetUserId(advisorBranchVo.BranchHeadId); // userBo.CreateRoleAssociation(rmUserId, 1002); //} //if (branchAdd == "forAdvisor") //{ // rmVo = advisorStaffBo.GetAdvisorStaff(userVo.UserId); // if (advisorBranchBo.AssociateBranch(rmVo.RMId, advisorBranchVo.BranchId, 0, userId)) // { // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Pageloadscript", "alert(' Association is done successfully');", true); // } // else // { // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Pageloadscript", "alert('Sorry.. Association is not done');", true); // } //} //if (branchAdd == "forBM" || branchAdd.Trim().ToString() == "forRM") //{ // if (rmList != null) // { // rmVo = (RMVo)Session["newRMVo"]; // //Session["newRMVo"] = rmVo; // if (advisorBranchBo.AssociateBranch(rmVo.RMId, advisorBranchVo.BranchId, 0, userId)) // { // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Pageloadscript", "alert(' Association is done successfully');", true); // } // else // { // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Pageloadscript", "alert('Sorry.. Association is not done');", true); // } // } //} // Add Terminals to the Branch if (Session["terminalId"] != null) { List <int> terminalId = (List <int>)Session["terminalId"]; for (int i = 0; i < terminalId.Count; i++) { advisorBranchBo.AddBranchTerminal(advisorBranchVo.BranchId, terminalId[i], userId); } } Session.Remove("terminalId"); Session.Remove("table"); Session.Remove("count"); btnSubmit.Enabled = false; ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "loadcontrol('ViewBranches','none');", true); } else { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Pageloadscript", "alert('Please select the Branch Head..!');", true); } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "AddBranch.ascx:btnSaveChanges_Click()"); object[] objects = new object[4]; objects[0] = advisorBranchVo; objects[1] = rmVo; objects[2] = advisorVo; objects[3] = userVo; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } }