/// <summary> /// Copy a temporary investor application to permanent Investor /// </summary> public int InvestorApplication_to_newInvestor(int InvestorApplicationId) { InvestorDS.InvestorApplicationsDataTable invAppDT = null; // new InvestorDS.InvestorApplicationsDataTable(); InvestorDSTableAdapters.InvestorApplicationsTableAdapter invAppTA = new InvestorDSTableAdapters.InvestorApplicationsTableAdapter(); InvestorDS.InvestorApplicationsRow invAppRow = null; StringBuilder invAppErrorMsgSB = new StringBuilder(); //invAppTA invAppDT = invAppTA.GetDataById(InvestorApplicationId); if (1 != invAppDT.Rows.Count) { return(-1); } else { invAppRow = invAppDT.Rows[0] as InvestorDS.InvestorApplicationsRow; if (invAppRow.IsPrimary_LastNameNull()) { invAppErrorMsgSB.AppendLine("Primary Investor's Last Name cannot be null."); } if (invAppRow.IsPrimary_DOBNull()) { invAppErrorMsgSB.AppendLine("Primary Investor's DOB cannot be null."); } if (invAppErrorMsgSB.Length > 0) { string invAppErrorMsg = invAppErrorMsgSB.ToString(); throw new ApplicationException(invAppErrorMsg); } } InvestorDS.InvestorDataTable invDT = new InvestorDS.InvestorDataTable(); InvestorDS.InvestorRow invRow = invDT.NewRow() as InvestorDS.InvestorRow; invRow.InvestorApplicationId = invAppRow.Id; invRow.FirstName = invAppRow.Primary_FirstName.Trim(); invRow.LastName = invAppRow.Primary_LastName.Trim(); invRow.DOB = invAppRow.Primary_DOB; return(1); //invRow = invAppRow.Id }
protected string SaveInvestorPermRecord(int invAppId) { StringBuilder validationErrorSB = new StringBuilder(); bool IsOtherApplicantPresent = false; InvestorDS ds = new InvestorDS(); InvestorDS.InvestorApplicationsDataTable invAppDT = ds.InvestorApplications; InvestorDS.InvestorDataTable invDT = ds.Investor; InvestorApplicationsTableAdapter invAppTA = new DataUtils.InvestorDSTableAdapters.InvestorApplicationsTableAdapter(); try { invAppTA.FillById(invAppDT, invAppId); //GetDataById(invAppId); } catch (System.Data.ConstraintException constrExc) { System.Data.DataRow[] rowsErr = invAppDT.GetErrors(); for (int i = 0; i < rowsErr.Length; i++) { if (rowsErr[i].HasErrors) { string err = rowsErr[i].RowError; if (!String.IsNullOrWhiteSpace(err)) { validationErrorSB.AppendLine(err); return(validationErrorSB.ToString()); } } } } if (invAppDT.Rows.Count != 1) { throw new ArgumentException(String.Concat("InvestorApplication with Id ", invAppId, " could not be found."), "InvestorApplication.Id"); } DataUtils.InvestorDS.InvestorApplicationsRow currentInvAppRow = invAppDT.Rows[0] as InvestorDS.InvestorApplicationsRow; InvestorDS.InvestorRow invRow = invDT.NewInvestorRow(); InvestorDS.InvestorRow othinvRow = null; InvestorTableAdapter invTA = new InvestorTableAdapter(); PropertyTableAdapter prtyTA = new PropertyTableAdapter(); TableAdapterManager tam = new TableAdapterManager(); //tam.InvestorApplicationsTableAdapter = ; tam.PropertyTableAdapter = prtyTA; tam.InvestorTableAdapter = invTA; tam.UpdateOrder = TableAdapterManager.UpdateOrderOption.InsertUpdateDelete; //InvestorTableAdapter invTA = new InvestorTableAdapter(); //if (currentInvAppRow.IsPrimary_FirstNameNull() || String.IsNullOrEmpty(currentInvAppRow.Primary_FirstName)) //{ // validationErrorSB.AppendLine("Primary Applicant's First name is empty"); //} invRow.InvestorApplicationId = currentInvAppRow.Id; if (!currentInvAppRow.IsOther_LastNameNull() && !String.IsNullOrWhiteSpace(currentInvAppRow.Other_LastName)) { IsOtherApplicantPresent = true; } #region PrimaryInvestor //invRow.Id = -1; if (currentInvAppRow.IsPrimary_FirstNameNull()) { invRow.FirstName = null; } else { invRow.FirstName = currentInvAppRow.Primary_FirstName.Trim(); } if (currentInvAppRow.IsPrimary_OtherNamesNull()) { invRow.OtherNames = null; } else { invRow.OtherNames = currentInvAppRow.Primary_OtherNames.Trim(); } if (currentInvAppRow.IsPrimary_LastNameNull() || String.IsNullOrEmpty(currentInvAppRow.Primary_LastName)) { validationErrorSB.AppendLine("Primary Applicant's Last name is empty"); } else { invRow.LastName = currentInvAppRow.Primary_LastName.Trim(); } if (currentInvAppRow.IsPrimary_DOBNull() || currentInvAppRow.Primary_DOB < DateTime.Today.AddYears(-100)) { validationErrorSB.AppendLine("Primary Applicant's DOB is empty or invalid"); } else { invRow.DOB = currentInvAppRow.Primary_DOB; } if (currentInvAppRow.IsPrimary_LastNameNull()) { validationErrorSB.AppendLine("Primary Applicant's Last Name is empty or invalid"); } else { invRow.LastName = currentInvAppRow.Primary_LastName.Trim(); } if (currentInvAppRow.IsEmailNull() || String.IsNullOrWhiteSpace(currentInvAppRow.Email)) { validationErrorSB.AppendLine("Primary Applicant's Email address is empty or invalid"); } else { invRow.Email = currentInvAppRow.Email; } currentInvAppRow.Other_Email = null; //invRow.Gender = if (String.IsNullOrWhiteSpace(currentInvAppRow.Primary_Gender)) { validationErrorSB.AppendLine(""); } else { string gender = currentInvAppRow.Primary_Gender.Trim(); if (gender.StartsWith("m", StringComparison.InvariantCultureIgnoreCase)) { invRow.Gender = 'M'; } else if (gender.StartsWith("f", StringComparison.InvariantCultureIgnoreCase)) { invRow.Gender = 'F'; } else { invRow.Gender = 'O'; } } if (currentInvAppRow.IsPrimary_Res_Street1Null() || String.IsNullOrWhiteSpace(currentInvAppRow.Primary_Res_Street1)) { validationErrorSB.AppendLine("Primary Applicant's Street address is empty or invalid"); } else { string unitKeyword = "unit"; string street1 = currentInvAppRow.Primary_Res_Street1; int unitKeywdIndex = new CultureInfo("EN-AU").CompareInfo.IndexOf(street1, unitKeyword, CompareOptions.IgnoreCase); if (unitKeywdIndex > 0) { string unitNo = street1.Substring(unitKeywdIndex + unitKeyword.Length).TrimStart(); int endOfUnitNo = unitNo.Length - unitNo.IndexOf(" ", StringComparison.InvariantCultureIgnoreCase); unitNo = unitNo.Substring(0, endOfUnitNo); if (!String.IsNullOrWhiteSpace(unitNo)) { invRow.Res_UnitNum = unitNo; invRow.Res_Street1 = street1.Substring(unitKeywdIndex + endOfUnitNo); } else { invRow.Res_Street1 = street1; } } else { invRow.Res_Street1 = currentInvAppRow.Primary_Res_Street1.Trim(); } } if (String.IsNullOrWhiteSpace(currentInvAppRow.Primary_Res_Street2)) { invRow.Res_Street2 = null; } else { invRow.Res_Street2 = currentInvAppRow.Primary_Res_Street2.Trim(); } if (currentInvAppRow.IsPrimary_Res_PostCodeNull()) { invRow.Res_Postcode = -1; } else { invRow.Res_Postcode = currentInvAppRow.Primary_Res_PostCode; } // invRow.Res_Suburb = currentInvAppRow.Primary_Res if (currentInvAppRow.IsPrimary_Res_SuburbNull()) { validationErrorSB.AppendLine("Primary current residence Suburb cannot be empty."); //invRow.Res_Suburb = null; } else { invRow.Res_Suburb = currentInvAppRow.Primary_Res_Suburb.Trim(); } invRow.Res_City = null; if (currentInvAppRow.IsPrimary_Res_StateNull()) { invRow.Res_State = null; } else { invRow.Res_State = currentInvAppRow.Primary_Res_State; } if (String.IsNullOrWhiteSpace(currentInvAppRow.Primary_Res_Country)) { invRow.Res_Country = "Australia"; } else { invRow.Res_Country = currentInvAppRow.Primary_Res_Country; } invRow.Res_Street3 = null; invRow.Res_Street4 = null; invRow.Res_Street5 = null; if (String.IsNullOrWhiteSpace(currentInvAppRow.Mobile)) { invRow.PhoneMobile = null; } else { invRow.PhoneMobile = currentInvAppRow.Mobile.Trim(); } if (currentInvAppRow.IsPrimary_HomePhoneNull()) { invRow.PhoneHome = null; } else { invRow.PhoneHome = currentInvAppRow.Primary_HomePhone.Trim(); } invRow.PhoneWork = null; invRow.PhoneOther = null; invRow.Bill_Street1 = null; invRow.Bill_Street2 = null; invRow.Bill_Street3 = null; invRow.Bill_Street4 = null; invRow.Bill_Street5 = null; invRow.AssquireStatus = "New"; invRow.AppliedDate = currentInvAppRow.EntryDate; invRow.Created = DateTime.Now; invRow.CreatedBy = "pdvorak"; invDT.AddInvestorRow(invRow); #endregion PrimaryInvestor #region PrimaryInvestorProperty // We will create property only if the details are provided and it must be confirmed //TODO bool hasProperty = true; //this.chckPrptyValFeePaid.Checked; InvestorDS.PropertyRow prptyNewR = null; // validate if property is included if (hasProperty) { // InvestorDS.PropertyDataTable prptyDT = new InvestorDS.PropertyDataTable(); AddPermPropertyFromInvAppRow(ds, currentInvAppRow, invRow); } #endregion PrimaryInvestorProperty #region OtherApplicant if (IsOtherApplicantPresent) { othinvRow = invDT.NewInvestorRow(); othinvRow.PrimaryInvestorID = invRow.Id; //othinvRow.PrimaryInvestorID = invRow.Id; othinvRow.LastName = currentInvAppRow.Other_LastName; if (currentInvAppRow.IsOther_FirstNameNull()) { othinvRow = null; } else { othinvRow.FirstName = currentInvAppRow.Other_FirstName; } if (currentInvAppRow.IsOther_OtherNamesNull()) { othinvRow.OtherNames = null; } else { othinvRow.OtherNames = currentInvAppRow.Other_OtherNames.Trim(); } if (currentInvAppRow.IsOther_DOBNull() || (currentInvAppRow.Other_DOB <= DateTime.Today.AddYears(-100))) { validationErrorSB.AppendLine("Other Investor DOB cannot be null"); } else { othinvRow.DOB = currentInvAppRow.Other_DOB; } if (currentInvAppRow.IsOther_Res_Street1Null() || String.IsNullOrWhiteSpace(currentInvAppRow.Other_Res_Street1)) { validationErrorSB.AppendLine("Other Applicant's Street address is empty or invalid"); } else { string unitKeyword = "unit"; string street1 = currentInvAppRow.Other_Res_Street1; int unitKeywdIndex = new CultureInfo("EN-AU").CompareInfo.IndexOf(street1, unitKeyword, CompareOptions.IgnoreCase); if (unitKeywdIndex > 0) { string unitNo = street1.Substring(unitKeywdIndex + unitKeyword.Length).TrimStart(); int endOfUnitNo = unitNo.Length - unitNo.IndexOf(" ", StringComparison.InvariantCultureIgnoreCase); unitNo = unitNo.Substring(0, endOfUnitNo); if (!String.IsNullOrWhiteSpace(unitNo)) { othinvRow.Res_UnitNum = unitNo; othinvRow.Res_Street1 = street1.Substring(unitKeywdIndex + endOfUnitNo); } else { othinvRow.Res_Street1 = street1; } } else { othinvRow.Res_Street1 = currentInvAppRow.Other_Res_Street1.Trim(); } } if (String.IsNullOrWhiteSpace(currentInvAppRow.Other_Res_Street2)) { othinvRow.Res_Street2 = null; } else { othinvRow.Res_Street2 = currentInvAppRow.Other_Res_Street2.Trim(); } if (currentInvAppRow.IsOther_Res_PostCodeNull()) { othinvRow.Res_Postcode = -1; } else { othinvRow.Res_Postcode = currentInvAppRow.Other_Res_PostCode; } // othinvRow.Res_Suburb = currentInvAppRow.Other_Res if (currentInvAppRow.IsOther_Res_SuburbNull()) { othinvRow.Res_Suburb = null; } else { othinvRow.Res_Suburb = currentInvAppRow.Other_Res_Suburb.Trim(); } othinvRow.Res_City = null; if (currentInvAppRow.IsOther_Res_StateNull()) { othinvRow.Res_State = null; } else { othinvRow.Res_State = currentInvAppRow.Other_Res_State; } if (String.IsNullOrWhiteSpace(currentInvAppRow.Other_Res_Country)) { othinvRow.Res_Country = "Australia"; } else { othinvRow.Res_Country = currentInvAppRow.Other_Res_Country; } othinvRow.Res_Street3 = null; othinvRow.Res_Street4 = null; othinvRow.Res_Street5 = null; if (String.IsNullOrWhiteSpace(currentInvAppRow.Mobile)) { othinvRow.PhoneMobile = null; } else { othinvRow.PhoneMobile = currentInvAppRow.Mobile.Trim(); } if (currentInvAppRow.IsPrimary_HomePhoneNull()) { othinvRow.PhoneHome = null; } else { othinvRow.PhoneHome = currentInvAppRow.Other_HomePhone.Trim(); } othinvRow.PhoneWork = null; othinvRow.PhoneOther = null; othinvRow.Bill_Street1 = null; othinvRow.Bill_Street2 = null; othinvRow.Bill_Street3 = null; othinvRow.Bill_Street4 = null; othinvRow.Bill_Street5 = null; othinvRow.InvestorApplicationId = currentInvAppRow.Id; othinvRow.AssquireStatus = "New"; othinvRow.AppliedDate = currentInvAppRow.EntryDate; othinvRow.Created = DateTime.Now; othinvRow.CreatedBy = "pdvorak"; invDT.AddInvestorRow(othinvRow); } #endregion OtherApplicant if (validationErrorSB.Length > 0) { return(validationErrorSB.ToString()); } else { //this.lblValidationErrorsTxtBoxLabel.Visible = false; //this.txtValidationErrors.Visible = false; //this.txtValidationErrors.Text = String.Empty(); try { //invTA.Update(invRow); //invTA.Update(othinvRow); //prtyTA.Update(prptyNewR); //Inserts tam.UpdateAll(ds); //update relationships bool refUpdate = false; if (IsOtherApplicantPresent) { othinvRow.PrimaryInvestorID = invRow.Id; refUpdate = true; } if (hasProperty) { //updates references prptyNewR.PrimaryInvestorId = invRow.Id; refUpdate = true; } if (refUpdate) { tam.UpdateAll(ds); } } catch (SqlException se) { return("Error adding new Investor(s): " + se.Message); } } return(null); }