private void ApplySecurity() { if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PPartnerTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner. This continues in the switch statments! // timop: I have disabled all controls. usually you have p_partner modify permissions, or none CustomEnablingDisabling.DisableControlGroup(pnlContent); } switch (SharedTypes.PartnerClassStringToEnum(FPartnerClass)) { case TPartnerClass.PERSON: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PPersonTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlPerson, cmbPersonAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlPerson, chkPersonNoSolicitations); // need to disable all Fields that are DataBound to p_person CustomEnablingDisabling.DisableControlGroup(pnlPerson); cmbPersonAddresseeTypeCode.Focus(); } break; case TPartnerClass.FAMILY: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PFamilyTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlFamily, cmbFamilyAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlFamily, chkFamilyNoSolicitations); // need to disable all Fields that are DataBound to p_family CustomEnablingDisabling.DisableControlGroup(pnlFamily); cmbFamilyAddresseeTypeCode.Focus(); } break; case TPartnerClass.CHURCH: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PChurchTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_church CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.ORGANISATION: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, POrganisationTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_organisation CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.UNIT: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PUnitTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_unit CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.BANK: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PBankTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_bank CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.VENUE: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PVenueTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_venue CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; default: MessageBox.Show(String.Format(Catalog.GetString("Unrecognised Partner Class '{0}'!"), FPartnerClass)); break; } }
public static Int32 CreateGiftBatch( Int32 ALedgerNumber, Int32 AStatementKey, Int32 AGiftBatchNumber, out TVerificationResultCollection AVerificationResult) { BankImportTDS MainDS = GetBankStatementTransactionsAndMatches(AStatementKey, ALedgerNumber); string MyClientID = DomainManager.GClientID.ToString(); TProgressTracker.InitProgressTracker(MyClientID, Catalog.GetString("Creating gift batch"), MainDS.AEpTransaction.DefaultView.Count + 10); AVerificationResult = new TVerificationResultCollection(); MainDS.AEpTransaction.DefaultView.RowFilter = String.Format("{0}={1}", AEpTransactionTable.GetStatementKeyDBName(), AStatementKey); MainDS.AEpStatement.DefaultView.RowFilter = String.Format("{0}={1}", AEpStatementTable.GetStatementKeyDBName(), AStatementKey); AEpStatementRow stmt = (AEpStatementRow)MainDS.AEpStatement.DefaultView[0].Row; // TODO: optional: use the preselected gift batch, AGiftBatchNumber Int32 DateEffectivePeriodNumber, DateEffectiveYearNumber; DateTime BatchDateEffective = stmt.Date; TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted); if (!TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber, ref BatchDateEffective, out DateEffectiveYearNumber, out DateEffectivePeriodNumber, Transaction, true)) { // just use the latest possible date string msg = String.Format(Catalog.GetString("Date {0} is not in an open period of the ledger, using date {1} instead for the gift batch."), stmt.Date.ToShortDateString(), BatchDateEffective.ToShortDateString()); AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Creating Gift Batch"), msg, TResultSeverity.Resv_Info)); } ACostCentreAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); MainDS.AEpMatch.DefaultView.Sort = AEpMatchTable.GetActionDBName() + ", " + AEpMatchTable.GetMatchTextDBName(); if (MainDS.AEpTransaction.DefaultView.Count == 0) { AVerificationResult.Add(new TVerificationResult( Catalog.GetString("Creating Gift Batch"), String.Format(Catalog.GetString("There are no transactions for statement #{0}."), AStatementKey), TResultSeverity.Resv_Info)); return(-1); } foreach (DataRowView dv in MainDS.AEpTransaction.DefaultView) { AEpTransactionRow transactionRow = (AEpTransactionRow)dv.Row; DataRowView[] matches = MainDS.AEpMatch.DefaultView.FindRows(new object[] { MFinanceConstants.BANK_STMT_STATUS_MATCHED_GIFT, transactionRow.MatchText }); if (matches.Length > 0) { AEpMatchRow match = (AEpMatchRow)matches[0].Row; if (match.IsDonorKeyNull() || (match.DonorKey == 0)) { string msg = String.Format(Catalog.GetString("Cannot create a gift for transaction {0} since there is no valid donor."), transactionRow.Description); AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Creating Gift Batch"), msg, TResultSeverity.Resv_Critical)); DBAccess.GDBAccessObj.RollbackTransaction(); return(-1); } } } string MatchedGiftReference = stmt.Filename; if (!stmt.IsBankAccountKeyNull()) { string sqlGetBankSortCode = "SELECT bank.p_branch_code_c " + "FROM PUB_p_banking_details details, PUB_p_bank bank " + "WHERE details.p_banking_details_key_i = ?" + "AND details.p_bank_key_n = bank.p_partner_key_n"; OdbcParameter param = new OdbcParameter("detailkey", OdbcType.Int); param.Value = stmt.BankAccountKey; PBankTable bankTable = new PBankTable(); DBAccess.GDBAccessObj.SelectDT(bankTable, sqlGetBankSortCode, Transaction, new OdbcParameter[] { param }, 0, 0); MatchedGiftReference = bankTable[0].BranchCode + " " + stmt.Date.Day.ToString(); } DBAccess.GDBAccessObj.RollbackTransaction(); GiftBatchTDS GiftDS = TGiftTransactionWebConnector.CreateAGiftBatch( ALedgerNumber, BatchDateEffective, String.Format(Catalog.GetString("bank import for date {0}"), stmt.Date.ToShortDateString())); AGiftBatchRow giftbatchRow = GiftDS.AGiftBatch[0]; giftbatchRow.BankAccountCode = stmt.BankAccountCode; decimal HashTotal = 0.0M; MainDS.AEpTransaction.DefaultView.Sort = AEpTransactionTable.GetNumberOnPaperStatementDBName(); MainDS.AEpMatch.DefaultView.RowFilter = String.Empty; MainDS.AEpMatch.DefaultView.Sort = AEpMatchTable.GetActionDBName() + ", " + AEpMatchTable.GetMatchTextDBName(); int counter = 5; foreach (DataRowView dv in MainDS.AEpTransaction.DefaultView) { TProgressTracker.SetCurrentState(MyClientID, Catalog.GetString("Preparing the gifts"), counter++); AEpTransactionRow transactionRow = (AEpTransactionRow)dv.Row; DataRowView[] matches = MainDS.AEpMatch.DefaultView.FindRows(new object[] { MFinanceConstants.BANK_STMT_STATUS_MATCHED_GIFT, transactionRow.MatchText }); if (matches.Length > 0) { AEpMatchRow match = (AEpMatchRow)matches[0].Row; AGiftRow gift = GiftDS.AGift.NewRowTyped(); gift.LedgerNumber = giftbatchRow.LedgerNumber; gift.BatchNumber = giftbatchRow.BatchNumber; gift.GiftTransactionNumber = giftbatchRow.LastGiftNumber + 1; gift.DonorKey = match.DonorKey; gift.DateEntered = transactionRow.DateEffective; gift.Reference = MatchedGiftReference; GiftDS.AGift.Rows.Add(gift); giftbatchRow.LastGiftNumber++; foreach (DataRowView r in matches) { match = (AEpMatchRow)r.Row; AGiftDetailRow detail = GiftDS.AGiftDetail.NewRowTyped(); detail.LedgerNumber = gift.LedgerNumber; detail.BatchNumber = gift.BatchNumber; detail.GiftTransactionNumber = gift.GiftTransactionNumber; detail.DetailNumber = gift.LastDetailNumber + 1; gift.LastDetailNumber++; detail.GiftTransactionAmount = match.GiftTransactionAmount; detail.GiftAmount = match.GiftTransactionAmount; HashTotal += match.GiftTransactionAmount; detail.MotivationGroupCode = match.MotivationGroupCode; detail.MotivationDetailCode = match.MotivationDetailCode; // do not use the description in comment one, because that could show up on the gift receipt??? // detail.GiftCommentOne = transactionRow.Description; detail.CommentOneType = MFinanceConstants.GIFT_COMMENT_TYPE_BOTH; detail.CostCentreCode = match.CostCentreCode; detail.RecipientKey = match.RecipientKey; detail.RecipientLedgerNumber = match.RecipientLedgerNumber; AMotivationDetailRow motivation = (AMotivationDetailRow)MainDS.AMotivationDetail.Rows.Find( new object[] { ALedgerNumber, detail.MotivationGroupCode, detail.MotivationDetailCode }); if (motivation == null) { AVerificationResult.Add(new TVerificationResult( String.Format(Catalog.GetString("creating gift for match {0}"), transactionRow.Description), String.Format(Catalog.GetString("Cannot find motivation group '{0}' and motivation detail '{1}'"), detail.MotivationGroupCode, detail.MotivationDetailCode), TResultSeverity.Resv_Critical)); } if (detail.CostCentreCode.Length == 0) { // try to retrieve the current costcentre for this recipient if (detail.RecipientKey != 0) { detail.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(detail.RecipientKey); detail.CostCentreCode = TGiftTransactionWebConnector.IdentifyPartnerCostCentre(detail.LedgerNumber, detail.RecipientLedgerNumber); } else { if (motivation != null) { detail.CostCentreCode = motivation.CostCentreCode; } } } // check for active cost centre ACostCentreRow costcentre = (ACostCentreRow)MainDS.ACostCentre.Rows.Find(new object[] { ALedgerNumber, detail.CostCentreCode }); if ((costcentre == null) || !costcentre.CostCentreActiveFlag) { AVerificationResult.Add(new TVerificationResult( String.Format(Catalog.GetString("creating gift for match {0}"), transactionRow.Description), Catalog.GetString("Invalid or inactive cost centre"), TResultSeverity.Resv_Critical)); } GiftDS.AGiftDetail.Rows.Add(detail); } } } TProgressTracker.SetCurrentState(MyClientID, Catalog.GetString("Submit to database"), counter++); if (AVerificationResult.HasCriticalErrors) { return(-1); } giftbatchRow.HashTotal = HashTotal; giftbatchRow.BatchTotal = HashTotal; // do not overwrite the parameter, because there might be the hint for a different gift batch date TVerificationResultCollection VerificationResultSubmitChanges; TSubmitChangesResult result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref GiftDS, out VerificationResultSubmitChanges); TProgressTracker.FinishJob(MyClientID); if (result == TSubmitChangesResult.scrOK) { return(giftbatchRow.BatchNumber); } return(-1); }
private void Filter(System.Object sender, EventArgs e) { // Apply filter to the grid DataView MyDataView = FCriteriaData.DefaultView; String Filter = ""; if (!string.IsNullOrEmpty(txtBranchName.Text)) { Filter += FCriteriaData.Columns[PBankTable.GetBranchNameDBName()] + " LIKE '" + txtBranchName.Text + "%'"; } if (!string.IsNullOrEmpty(txtBranchCode.Text)) { if (Filter != "") { Filter += " AND "; } Filter += FCriteriaData.Columns[PBankTable.GetBranchCodeDBName()] + " LIKE '" + txtBranchCode.Text + "%'"; } if (!string.IsNullOrEmpty(txtBicCode.Text)) { if (Filter != "") { Filter += " AND "; } Filter += FCriteriaData.Columns[PBankTable.GetBicDBName()] + " LIKE '" + txtBicCode.Text + "%'"; } if (!string.IsNullOrEmpty(txtCity.Text)) { if (Filter != "") { Filter += " AND "; } Filter += FCriteriaData.Columns[PLocationTable.GetCityDBName()] + " LIKE '" + txtCity.Text + "%'"; } if (!string.IsNullOrEmpty(txtCountry.Text)) { if (Filter != "") { Filter += " AND "; } Filter += FCriteriaData.Columns[PLocationTable.GetCountryCodeDBName()] + " LIKE '" + txtCountry.Text + "%'"; } if (!chkShowInactive.Checked) { if (Filter != "") { Filter += " AND "; } Filter += FCriteriaData.Columns[BankTDSPBankTable.GetStatusCodeDBName()] + " = '" + SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE) + "'"; } MyDataView.RowFilter = Filter; grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(MyDataView); UpdateRecordNumberDisplay(); SelectRowInGrid(); FocusedRowChanged(this, null); }
public static Int64 GetBankBySortCode(string ABranchCode) { TDBTransaction ReadTransaction = null; string sqlFindBankBySortCode = String.Format("SELECT * FROM PUB_{0} WHERE {1}=?", PBankTable.GetTableDBName(), PBankTable.GetBranchCodeDBName()); OdbcParameter param = new OdbcParameter("branchcode", OdbcType.VarChar); param.Value = ABranchCode; PBankTable bank = new PBankTable(); DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref ReadTransaction, delegate { DBAccess.GDBAccessObj.SelectDT(bank, sqlFindBankBySortCode, ReadTransaction, new OdbcParameter[] { param }, -1, -1); }); if (bank.Count > 0) { return bank[0].PartnerKey; } else { // create new bank partner, with empty location PartnerEditTDS MainDS = new PartnerEditTDS(); PPartnerRow newPartner = MainDS.PPartner.NewRowTyped(); Int64 BankPartnerKey = TNewPartnerKey.GetNewPartnerKey(DomainManager.GSiteKey); TNewPartnerKey.SubmitNewPartnerKey(DomainManager.GSiteKey, BankPartnerKey, ref BankPartnerKey); newPartner.PartnerKey = BankPartnerKey; newPartner.PartnerShortName = "Bank " + ABranchCode; newPartner.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; newPartner.PartnerClass = MPartnerConstants.PARTNERCLASS_BANK; MainDS.PPartner.Rows.Add(newPartner); PBankRow newBank = MainDS.PBank.NewRowTyped(true); newBank.PartnerKey = newPartner.PartnerKey; newBank.BranchCode = ABranchCode; newBank.BranchName = newPartner.PartnerShortName; MainDS.PBank.Rows.Add(newBank); PPartnerLocationRow partnerlocation = MainDS.PPartnerLocation.NewRowTyped(true); partnerlocation.SiteKey = DomainManager.GSiteKey; partnerlocation.PartnerKey = newPartner.PartnerKey; partnerlocation.DateEffective = DateTime.Now; partnerlocation.LocationType = "HOME"; partnerlocation.SendMail = false; MainDS.PPartnerLocation.Rows.Add(partnerlocation); PartnerEditTDSAccess.SubmitChanges(MainDS); return newPartner.PartnerKey; } }
/// <summary> /// Load data into grid /// </summary> /// <param name="AFirstTime">True if being run for the first time</param> public void LoadDataGrid(bool AFirstTime) { // Only call data from server if the dataset is actually empty. // (A filled dataset is passed to this screen from the 'Finance Details' tab and 'Find By Bank Details'.) if ((FMainDS == null) || (FMainDS.PBank.Rows.Count == 0)) { FMainDS = new BankTDS(); FMainDS.Merge(TRemote.MPartner.Partner.WebConnectors.GetPBankRecords()); } FCriteriaData.Clear(); if (AFirstTime) { // setup the grid on first run SetupGrid(); } // create a new row for each bank record foreach (BankTDSPBankRow BankRow in FMainDS.PBank.Rows) { if (BankRow.PartnerKey >= 0) { DataRow NewBankRow = FCriteriaData.NewRow(); NewBankRow[PBankTable.GetPartnerKeyDBName()] = BankRow.PartnerKey; NewBankRow[BankTDSPBankTable.GetCityDBName()] = BankRow.City; NewBankRow[BankTDSPBankTable.GetCountryCodeDBName()] = BankRow.CountryCode; NewBankRow[PBankTable.GetBranchNameDBName()] = BankRow.BranchName; if (BankRow.BranchCode.StartsWith(SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ")) { NewBankRow[PBankTable.GetBranchCodeDBName()] = BankRow.BranchCode.Substring(11); } else if (BankRow.BranchCode.StartsWith(SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS)) { NewBankRow[PBankTable.GetBranchCodeDBName()] = BankRow.BranchCode.Substring(10); } else { NewBankRow[PBankTable.GetBranchCodeDBName()] = BankRow.BranchCode; } NewBankRow[BankTDSPBankTable.GetSiteKeyDBName()] = BankRow.SiteKey; NewBankRow[BankTDSPBankTable.GetLocationKeyDBName()] = BankRow.LocationKey; NewBankRow[PBankTable.GetBicDBName()] = BankRow.Bic; NewBankRow[BankTDSPBankTable.GetStatusCodeDBName()] = BankRow.StatusCode; FCriteriaData.Rows.Add(NewBankRow); } } // sort order for grid DataView MyDataView = FCriteriaData.DefaultView; MyDataView.Sort = "p_branch_name_c ASC"; grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(MyDataView); SelectRowInGrid(); FinishButtonPanelSetup(); Filter(this, null); }
// automatically select the currently selected Bank (if it exists) private void SelectRowInGrid() { int RowPos = 1; // if no bank is selected then no row should be selected if ((grdDetails.Rows.Count <= 1) || (FBankPartnerKey == 0)) { // select the first row in the grid if (grdDetails.Rows.Count > 1) { grdDetails.SelectRowWithoutFocus(1); } else { btnAccept.Enabled = false; btnEdit.Enabled = false; } return; } BankTDSPBankRow BankRow = null; // Multiple rows could have the same partner keys but different locations. // We just want the first row. foreach (BankTDSPBankRow Row in FMainDS.PBank.Rows) { if (Row.PartnerKey == FBankPartnerKey) { BankRow = Row; break; } } // if current bank is 'inactive' then make sure chkShowInactive is checked (unchecked by default) if ((BankRow != null) && (BankRow.StatusCode != SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE)) && (chkShowInactive.Checked == false)) { chkShowInactive.Checked = true; } if (BankRow == null) { grdDetails.SelectRowWithoutFocus(1); } else { // look through each row in the grid foreach (DataRowView RowView in FCriteriaData.DefaultView) { // if current grid row is the row we are looking for the select it if (Convert.ToInt64(RowView[PBankTable.GetPartnerKeyDBName()]) == FBankPartnerKey) { grdDetails.SelectRowWithoutFocus(RowPos); btnAccept.Enabled = true; btnEdit.Enabled = true; return; } // account for grid rows being filtered by being inactive if (chkShowInactive.Checked || (!chkShowInactive.Checked && (RowView[BankTDSPBankTable.GetStatusCodeDBName()].ToString() == SharedTypes.StdPartnerStatusCodeEnumToString(TStdPartnerStatusCode.spscACTIVE)))) { RowPos++; } } } }
public static Int32 CreateGiftBatch( Int32 ALedgerNumber, Int32 AStatementKey, Int32 AGiftBatchNumber, out TVerificationResultCollection AVerificationResult) { BankImportTDS MainDS = GetBankStatementTransactionsAndMatches(AStatementKey, ALedgerNumber); string MyClientID = DomainManager.GClientID.ToString(); TProgressTracker.InitProgressTracker(MyClientID, Catalog.GetString("Creating gift batch"), MainDS.AEpTransaction.DefaultView.Count + 10); AVerificationResult = new TVerificationResultCollection(); MainDS.AEpTransaction.DefaultView.RowFilter = String.Format("{0}={1}", AEpTransactionTable.GetStatementKeyDBName(), AStatementKey); MainDS.AEpStatement.DefaultView.RowFilter = String.Format("{0}={1}", AEpStatementTable.GetStatementKeyDBName(), AStatementKey); AEpStatementRow stmt = (AEpStatementRow)MainDS.AEpStatement.DefaultView[0].Row; // TODO: optional: use the preselected gift batch, AGiftBatchNumber Int32 DateEffectivePeriodNumber, DateEffectiveYearNumber; DateTime BatchDateEffective = stmt.Date; TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted); if (!TFinancialYear.GetLedgerDatePostingPeriod(ALedgerNumber, ref BatchDateEffective, out DateEffectiveYearNumber, out DateEffectivePeriodNumber, Transaction, true)) { // just use the latest possible date string msg = String.Format(Catalog.GetString("Date {0} is not in an open period of the ledger, using date {1} instead for the gift batch."), stmt.Date.ToShortDateString(), BatchDateEffective.ToShortDateString()); AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Creating Gift Batch"), msg, TResultSeverity.Resv_Info)); } ACostCentreAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); AMotivationDetailAccess.LoadViaALedger(MainDS, ALedgerNumber, Transaction); MainDS.AEpMatch.DefaultView.Sort = AEpMatchTable.GetActionDBName() + ", " + AEpMatchTable.GetMatchTextDBName(); if (MainDS.AEpTransaction.DefaultView.Count == 0) { AVerificationResult.Add(new TVerificationResult( Catalog.GetString("Creating Gift Batch"), String.Format(Catalog.GetString("There are no transactions for statement #{0}."), AStatementKey), TResultSeverity.Resv_Info)); TProgressTracker.FinishJob(MyClientID); return -1; } foreach (DataRowView dv in MainDS.AEpTransaction.DefaultView) { AEpTransactionRow transactionRow = (AEpTransactionRow)dv.Row; DataRowView[] matches = MainDS.AEpMatch.DefaultView.FindRows(new object[] { MFinanceConstants.BANK_STMT_STATUS_MATCHED_GIFT, transactionRow.MatchText }); if (matches.Length > 0) { AEpMatchRow match = (AEpMatchRow)matches[0].Row; if (match.IsDonorKeyNull() || (match.DonorKey == 0)) { string msg = String.Format(Catalog.GetString("Cannot create a gift for transaction {0} since there is no valid donor."), transactionRow.Description); AVerificationResult.Add(new TVerificationResult(Catalog.GetString("Creating Gift Batch"), msg, TResultSeverity.Resv_Critical)); DBAccess.GDBAccessObj.RollbackTransaction(); TProgressTracker.FinishJob(MyClientID); return -1; } } } string MatchedGiftReference = stmt.Filename; if (!stmt.IsBankAccountKeyNull()) { string sqlGetBankSortCode = "SELECT bank.p_branch_code_c " + "FROM PUB_p_banking_details details, PUB_p_bank bank " + "WHERE details.p_banking_details_key_i = ?" + "AND details.p_bank_key_n = bank.p_partner_key_n"; OdbcParameter param = new OdbcParameter("detailkey", OdbcType.Int); param.Value = stmt.BankAccountKey; PBankTable bankTable = new PBankTable(); DBAccess.GDBAccessObj.SelectDT(bankTable, sqlGetBankSortCode, Transaction, new OdbcParameter[] { param }, 0, 0); MatchedGiftReference = bankTable[0].BranchCode + " " + stmt.Date.Day.ToString(); } DBAccess.GDBAccessObj.RollbackTransaction(); GiftBatchTDS GiftDS = TGiftTransactionWebConnector.CreateAGiftBatch( ALedgerNumber, BatchDateEffective, String.Format(Catalog.GetString("bank import for date {0}"), stmt.Date.ToShortDateString())); AGiftBatchRow giftbatchRow = GiftDS.AGiftBatch[0]; giftbatchRow.BankAccountCode = stmt.BankAccountCode; decimal HashTotal = 0.0M; MainDS.AEpTransaction.DefaultView.Sort = AEpTransactionTable.GetNumberOnPaperStatementDBName(); MainDS.AEpMatch.DefaultView.RowFilter = String.Empty; MainDS.AEpMatch.DefaultView.Sort = AEpMatchTable.GetActionDBName() + ", " + AEpMatchTable.GetMatchTextDBName(); int counter = 5; foreach (DataRowView dv in MainDS.AEpTransaction.DefaultView) { TProgressTracker.SetCurrentState(MyClientID, Catalog.GetString("Preparing the gifts"), counter++); AEpTransactionRow transactionRow = (AEpTransactionRow)dv.Row; DataRowView[] matches = MainDS.AEpMatch.DefaultView.FindRows(new object[] { MFinanceConstants.BANK_STMT_STATUS_MATCHED_GIFT, transactionRow.MatchText }); if (matches.Length > 0) { AEpMatchRow match = (AEpMatchRow)matches[0].Row; AGiftRow gift = GiftDS.AGift.NewRowTyped(); gift.LedgerNumber = giftbatchRow.LedgerNumber; gift.BatchNumber = giftbatchRow.BatchNumber; gift.GiftTransactionNumber = giftbatchRow.LastGiftNumber + 1; gift.DonorKey = match.DonorKey; gift.DateEntered = transactionRow.DateEffective; gift.Reference = MatchedGiftReference; GiftDS.AGift.Rows.Add(gift); giftbatchRow.LastGiftNumber++; foreach (DataRowView r in matches) { match = (AEpMatchRow)r.Row; AGiftDetailRow detail = GiftDS.AGiftDetail.NewRowTyped(); detail.LedgerNumber = gift.LedgerNumber; detail.BatchNumber = gift.BatchNumber; detail.GiftTransactionNumber = gift.GiftTransactionNumber; detail.DetailNumber = gift.LastDetailNumber + 1; gift.LastDetailNumber++; detail.GiftTransactionAmount = match.GiftTransactionAmount; detail.GiftAmount = match.GiftTransactionAmount; HashTotal += match.GiftTransactionAmount; detail.MotivationGroupCode = match.MotivationGroupCode; detail.MotivationDetailCode = match.MotivationDetailCode; // do not use the description in comment one, because that could show up on the gift receipt??? // detail.GiftCommentOne = transactionRow.Description; detail.CommentOneType = MFinanceConstants.GIFT_COMMENT_TYPE_BOTH; detail.CostCentreCode = match.CostCentreCode; detail.RecipientKey = match.RecipientKey; detail.RecipientLedgerNumber = match.RecipientLedgerNumber; AMotivationDetailRow motivation = (AMotivationDetailRow)MainDS.AMotivationDetail.Rows.Find( new object[] { ALedgerNumber, detail.MotivationGroupCode, detail.MotivationDetailCode }); if (motivation == null) { AVerificationResult.Add(new TVerificationResult( String.Format(Catalog.GetString("creating gift for match {0}"), transactionRow.Description), String.Format(Catalog.GetString("Cannot find motivation group '{0}' and motivation detail '{1}'"), detail.MotivationGroupCode, detail.MotivationDetailCode), TResultSeverity.Resv_Critical)); } // try to retrieve the current costcentre for this recipient if (detail.RecipientKey != 0) { detail.RecipientLedgerNumber = TGiftTransactionWebConnector.GetRecipientFundNumber(detail.RecipientKey); detail.CostCentreCode = TGiftTransactionWebConnector.IdentifyPartnerCostCentre(detail.LedgerNumber, detail.RecipientLedgerNumber); } else { if (motivation != null) { detail.CostCentreCode = motivation.CostCentreCode; } } // check for active cost centre ACostCentreRow costcentre = (ACostCentreRow)MainDS.ACostCentre.Rows.Find(new object[] { ALedgerNumber, detail.CostCentreCode }); if ((costcentre == null) || !costcentre.CostCentreActiveFlag) { AVerificationResult.Add(new TVerificationResult( String.Format(Catalog.GetString("creating gift for match {0}"), transactionRow.Description), Catalog.GetString("Invalid or inactive cost centre"), TResultSeverity.Resv_Critical)); } GiftDS.AGiftDetail.Rows.Add(detail); } } } TProgressTracker.SetCurrentState(MyClientID, Catalog.GetString("Submit to database"), counter++); if (AVerificationResult.HasCriticalErrors) { TProgressTracker.FinishJob(MyClientID); return -1; } giftbatchRow.HashTotal = HashTotal; giftbatchRow.BatchTotal = HashTotal; // do not overwrite the parameter, because there might be the hint for a different gift batch date TVerificationResultCollection VerificationResultSubmitChanges; TSubmitChangesResult result = TGiftTransactionWebConnector.SaveGiftBatchTDS(ref GiftDS, out VerificationResultSubmitChanges); TProgressTracker.FinishJob(MyClientID); if (result == TSubmitChangesResult.scrOK) { return giftbatchRow.BatchNumber; } return -1; }
private static void ParseFinancialDetails(PartnerImportExportTDS AMainDS, XmlNode AFinancialDetailsNode, Int64 APartnerKey, TDBTransaction ATransaction) { if (AFinancialDetailsNode != null) { string BankAccountNumber = TYml2Xml.GetAttributeRecursive(AFinancialDetailsNode, "AccountNumber"); string BankSortCode = TYml2Xml.GetAttributeRecursive(AFinancialDetailsNode, "BankSortCode"); // do we already have a bank with this sort code? Int64 bankPartnerKey = 0; AMainDS.PBank.DefaultView.Sort = PBankTable.GetBranchCodeDBName(); int bankIndex = AMainDS.PBank.DefaultView.Find(BankSortCode); if (bankIndex != -1) { bankPartnerKey = ((PBankRow)AMainDS.PBank.DefaultView[bankIndex].Row).PartnerKey; } if (bankPartnerKey == 0) { string sqlFindBankBySortCode = String.Format("SELECT * FROM PUB_{0} WHERE {1}=?", PBankTable.GetTableDBName(), PBankTable.GetBranchCodeDBName()); OdbcParameter param = new OdbcParameter("branchcode", OdbcType.VarChar); param.Value = BankSortCode; PBankTable bank = new PBankTable(); DBAccess.GDBAccessObj.SelectDT(bank, sqlFindBankBySortCode, ATransaction, new OdbcParameter[] { param }, -1, -1); if (bank.Count > 0) { bankPartnerKey = bank[0].PartnerKey; } } if (bankPartnerKey == 0) { // create a new bank record PBankRow bankRow = AMainDS.PBank.NewRowTyped(true); bankRow.PartnerKey = TImportExportYml.NewPartnerKey; TImportExportYml.NewPartnerKey--; bankRow.BranchCode = BankSortCode; bankRow.BranchName = BankSortCode; AMainDS.PBank.Rows.Add(bankRow); bankPartnerKey = bankRow.PartnerKey; } PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped(true); bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1; bankingDetailsRow.BankingType = 0; bankingDetailsRow.BankAccountNumber = BankAccountNumber; bankingDetailsRow.BankKey = bankPartnerKey; AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow); PPartnerBankingDetailsRow partnerBankingDetailsRow = AMainDS.PPartnerBankingDetails.NewRowTyped(true); partnerBankingDetailsRow.PartnerKey = APartnerKey; partnerBankingDetailsRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey; AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingDetailsRow); } }
private void PopulateComboBoxes() { // For some reason this method enables the save button // temporarily remove the event that enables the save button when data is changed FPetraUtilsObject.ActionEnablingEvent -= ((TFrmPartnerEdit)FPetraUtilsObject.GetForm()).ActionEnabledEvent; bool HasChanges = FPetraUtilsObject.HasChanges; // temporily remove events from comboboxes cmbBankName.SelectedValueChanged -= new System.EventHandler(this.BankNameChanged); cmbBankCode.SelectedValueChanged -= new System.EventHandler(this.BankCodeChanged); // load bank records if (FBankDataset == null) { FBankDataset = TRemote.MPartner.Partner.WebConnectors.GetPBankRecords(); txtBankKey.DataSet = FBankDataset; } // create new datatable without any partnerkey duplicates (same bank with different locations) PBankTable ComboboxTable = new PBankTable(); bool CreateInactiveCode = false; foreach (BankTDSPBankRow Row in FBankDataset.PBank.Rows) { if (!ComboboxTable.Rows.Contains(Row.PartnerKey)) { PBankRow AddRow = (PBankRow)ComboboxTable.NewRow(); AddRow.PartnerKey = Row.PartnerKey; AddRow.BranchName = Row.BranchName; AddRow.BranchCode = Row.BranchCode; ComboboxTable.Rows.Add(AddRow); if (Row.BranchCode == SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ") { CreateInactiveCode = true; } } } // add empty row DataRow emptyRow = ComboboxTable.NewRow(); emptyRow[PBankTable.ColumnPartnerKeyId] = -1; emptyRow[PBankTable.ColumnBranchNameId] = Catalog.GetString(""); emptyRow[PBankTable.ColumnBranchCodeId] = Catalog.GetString(""); ComboboxTable.Rows.Add(emptyRow); if (CreateInactiveCode) { // add inactive row emptyRow = ComboboxTable.NewRow(); emptyRow[PBankTable.ColumnPartnerKeyId] = -2; emptyRow[PBankTable.ColumnBranchNameId] = Catalog.GetString(""); emptyRow[PBankTable.ColumnBranchCodeId] = SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " "; ComboboxTable.Rows.Add(emptyRow); } // populate the bank name combo box cmbBankName.InitialiseUserControl(ComboboxTable, PBankTable.GetPartnerKeyDBName(), PBankTable.GetBranchNameDBName(), PBankTable.GetBranchCodeDBName(), null); cmbBankName.AppearanceSetup(new int[] { 230, 160 }, -1); cmbBankName.Filter = PBankTable.GetBranchNameDBName() + " <> '' OR " + PBankTable.GetBranchNameDBName() + " = '' AND " + PBankTable.GetBranchCodeDBName() + " = ''"; cmbBankName.SelectedValueChanged += new System.EventHandler(this.BankNameChanged); // populate the bank code combo box cmbBankCode.InitialiseUserControl(ComboboxTable, PBankTable.GetBranchCodeDBName(), PBankTable.GetPartnerKeyDBName(), null); cmbBankCode.AppearanceSetup(new int[] { 210 }, -1); // filter rows that are blank or <INACTIVE> cmbBankCode.Filter = "(" + PBankTable.GetBranchCodeDBName() + " <> '' AND " + PBankTable.GetBranchCodeDBName() + " <> '" + SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ') " + "OR (" + PBankTable.GetBranchNameDBName() + " = '' AND " + PBankTable.GetBranchCodeDBName() + " = '') " + "OR (" + PBankTable.GetBranchNameDBName() + " = '' AND " + PBankTable.GetBranchCodeDBName() + " = '" + SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ')"; cmbBankCode.SelectedValueChanged += new System.EventHandler(this.BankCodeChanged); FComboBoxesCreated = true; if ((FPreviouslySelectedDetailRow != null) && (FPreviouslySelectedDetailRow.BankKey != 0) && (((FCurrentBankRow == null) || (FPreviouslySelectedDetailRow.BankKey != FCurrentBankRow.PartnerKey)))) { PartnerKeyChanged(FPreviouslySelectedDetailRow.BankKey, "", true); } FPetraUtilsObject.ActionEnablingEvent += ((TFrmPartnerEdit)FPetraUtilsObject.GetForm()).ActionEnabledEvent; FPetraUtilsObject.HasChanges = HasChanges; }
/// <summary> /// Populates cmbBankName and cmbBankCode (loads data from database if needed) /// </summary> public void PopulateBankComboBoxes() { // temporily remove events from comboboxes cmbBankName.SelectedValueChanged -= new System.EventHandler(this.BankNameChanged); cmbBankCode.SelectedValueChanged -= new System.EventHandler(this.BankCodeChanged); // Load bank records. (I don't think this will ever be null. Database is populated when tab is loaded.) if (FBankDataset == null) { FBankDataset = TRemote.MPartner.Partner.WebConnectors.GetPBankRecords(); } txtBankKey.DataSet = FBankDataset; // create new datatable without any partnerkey duplicates (same bank with different locations) PBankTable ComboboxTable = new PBankTable(); foreach (BankTDSPBankRow Row in FBankDataset.PBank.Rows) { if (!ComboboxTable.Rows.Contains(Row.PartnerKey)) { PBankRow AddRow = (PBankRow)ComboboxTable.NewRow(); AddRow.PartnerKey = Row.PartnerKey; AddRow.BranchName = Row.BranchName; AddRow.BranchCode = Row.BranchCode; ComboboxTable.Rows.Add(AddRow); } } // add empty row DataRow emptyRow = ComboboxTable.NewRow(); emptyRow[PBankTable.ColumnPartnerKeyId] = -1; emptyRow[PBankTable.ColumnBranchNameId] = Catalog.GetString(""); emptyRow[PBankTable.ColumnBranchCodeId] = Catalog.GetString(""); ComboboxTable.Rows.Add(emptyRow); // add inactive row emptyRow = ComboboxTable.NewRow(); emptyRow[PBankTable.ColumnPartnerKeyId] = -2; emptyRow[PBankTable.ColumnBranchNameId] = Catalog.GetString(""); emptyRow[PBankTable.ColumnBranchCodeId] = SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " "; ComboboxTable.Rows.Add(emptyRow); // populate the bank name combo box cmbBankName.InitialiseUserControl(ComboboxTable, PBankTable.GetPartnerKeyDBName(), PBankTable.GetBranchNameDBName(), PBankTable.GetBranchCodeDBName(), null); cmbBankName.Filter = PBankTable.GetBranchNameDBName() + " <> '' OR " + PBankTable.GetBranchNameDBName() + " = '' AND " + PBankTable.GetBranchCodeDBName() + " = ''"; cmbBankName.SelectedValueChanged += new System.EventHandler(this.BankNameChanged); // populate the bank code combo box cmbBankCode.InitialiseUserControl(ComboboxTable, PBankTable.GetBranchCodeDBName(), PBankTable.GetPartnerKeyDBName(), null); // filter rows that are blank or <INACTIVE> cmbBankCode.Filter = "(" + PBankTable.GetBranchCodeDBName() + " <> '' AND " + PBankTable.GetBranchCodeDBName() + " <> '" + SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ') " + "OR (" + PBankTable.GetBranchNameDBName() + " = '' AND " + PBankTable.GetBranchCodeDBName() + " = '') " + "OR (" + PBankTable.GetBranchNameDBName() + " = '' AND " + PBankTable.GetBranchCodeDBName() + " = '" + SharedConstants.INACTIVE_VALUE_WITH_QUALIFIERS + " ')"; cmbBankCode.SelectedValueChanged += new System.EventHandler(this.BankCodeChanged); FComboBoxesCreated = true; }
/// <summary> /// return an XmlDocument with all partner info; /// the partners are grouped by class, country, status, and sitekey /// </summary> /// <returns></returns> public static string ExportPartners() { PartnerEditTDS MainDS = new PartnerEditTDS(); LoadDataFromDB(ref MainDS); // Group partners into categories. // // A partner's category is defined by his: class, country, status, and sitekey // It is stored as a string e.g. "FAMILY,DE,ACTIVE,0". // SortedList <string, List <long> > PartnerCategories = GroupPartnersIntoCategories(MainDS); // create XML structure for each category XmlDocument PartnerData = TYml2Xml.CreateXmlDocument(); XmlNode rootNode = PartnerData.FirstChild.NextSibling; Int32 groupCounter = 0; foreach (string category in PartnerCategories.Keys) { // get category data groupCounter++; XmlElement groupNode = PartnerData.CreateElement("PartnerGroup" + groupCounter.ToString()); rootNode.AppendChild(groupNode); Int32 partnerCounter = 0; string[] categoryDetails = category.Split(new char[] { ',' }); // may want to skip the categories with sitekey = -1 // right now, we still export them and ignore the partners 0 and 1000000 later groupNode.SetAttribute("class", categoryDetails[0]); groupNode.SetAttribute("Country", categoryDetails[1]); groupNode.SetAttribute("status", categoryDetails[2]); groupNode.SetAttribute("SiteKey", categoryDetails[3]); List <long> partnerKeys = PartnerCategories[category]; foreach (long partnerKey in partnerKeys) { if ((partnerKey != 0) && (partnerKey != 1000000)) // skip organization root and the 0 when exporting { MainDS.PPartner.DefaultView.RowFilter = PPartnerTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); PPartnerRow partnerRow = (PPartnerRow)MainDS.PPartner.DefaultView[0].Row; PFamilyRow familyRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { MainDS.PFamily.DefaultView.RowFilter = PFamilyTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); familyRow = (PFamilyRow)MainDS.PFamily.DefaultView[0].Row; } PPersonRow personRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { MainDS.PPerson.DefaultView.RowFilter = PPersonTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); personRow = (PPersonRow)MainDS.PPerson.DefaultView[0].Row; } POrganisationRow organisationRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { MainDS.POrganisation.DefaultView.RowFilter = POrganisationTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); organisationRow = (POrganisationRow)MainDS.POrganisation.DefaultView[0].Row; } PUnitRow unitRow = null; UmUnitStructureRow unitStructureRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { MainDS.PUnit.DefaultView.RowFilter = PUnitTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); unitRow = (PUnitRow)MainDS.PUnit.DefaultView[0].Row; MainDS.UmUnitStructure.DefaultView.RowFilter = UmUnitStructureTable.GetChildUnitKeyDBName() + " = " + partnerKey.ToString(); long numParents = MainDS.UmUnitStructure.DefaultView.Count; if (numParents == 1) { unitStructureRow = (UmUnitStructureRow)MainDS.UmUnitStructure.DefaultView[0].Row; } else { throw new Exception( "Units must have exactly one ParentUnit. " + "The unit with partnerKey " + partnerKey.ToString() + " has " + numParents.ToString() + "."); } } PBankRow BankRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { MainDS.PBank.DefaultView.RowFilter = PBankTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); BankRow = (PBankRow)MainDS.PBank.DefaultView[0].Row; } partnerCounter++; XmlElement partnerNode = PartnerData.CreateElement("Partner" + partnerCounter.ToString()); groupNode.AppendChild(partnerNode); partnerNode.SetAttribute("PartnerKey", partnerRow.PartnerKey.ToString()); //groupNode.SetAttribute("ShortName", partnerRow.PartnerShortName.ToString()); if (personRow != null) { partnerNode.SetAttribute("FirstName", personRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", personRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", personRow.Title.ToString()); } else if (familyRow != null) { partnerNode.SetAttribute("FirstName", familyRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", familyRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", familyRow.Title.ToString()); } else if (organisationRow != null) { partnerNode.SetAttribute("Name", organisationRow.OrganisationName.ToString()); } else if (unitRow != null) { partnerNode.SetAttribute("Name", unitRow.UnitName.ToString()); partnerNode.SetAttribute("UnitTypeCode", unitRow.UnitTypeCode.ToString()); if (unitStructureRow != null) { partnerNode.SetAttribute("ParentUnitKey", unitStructureRow.ParentUnitKey.ToString()); } } if (BankRow != null) { partnerNode.SetAttribute("BranchName", BankRow.BranchName); partnerNode.SetAttribute("BranchCode", BankRow.BranchCode); partnerNode.SetAttribute("BranchBic", BankRow.Bic); partnerNode.SetAttribute("EpFormatFile", BankRow.EpFormatFile); } partnerNode.SetAttribute("CreatedAt", partnerRow.DateCreated.Value.ToString("yyyy-MM-dd HH:mm:ss")); // special types string specialTypes = ""; MainDS.PPartnerType.DefaultView.RowFilter = PPartnerTypeTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); foreach (DataRowView rv in MainDS.PPartnerType.DefaultView) { if (specialTypes.Length > 0) { specialTypes += ", "; } specialTypes += ((PPartnerTypeRow)rv.Row).TypeCode; } if (specialTypes.Length > 0) { partnerNode.SetAttribute("SpecialTypes", specialTypes); } // addresses DataView partnerLocationView = MainDS.PPartnerLocation.DefaultView; partnerLocationView.RowFilter = PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerRow.PartnerKey.ToString() + "AND " + PPartnerLocationTable.GetLocationKeyDBName() + " <> 0 "; // ignore invalid addresses Int32 addressCounter = 0; foreach (DataRowView rv in partnerLocationView) { XmlElement addressNode = PartnerData.CreateElement("Address" + (addressCounter > 0 ? addressCounter.ToString() : "")); addressCounter++; partnerNode.AppendChild(addressNode); PPartnerLocationRow partnerLocationRow = (PPartnerLocationRow)rv.Row; DataView locationView = MainDS.PLocation.DefaultView; locationView.RowFilter = PLocationTable.GetSiteKeyDBName() + "=" + partnerLocationRow.SiteKey.ToString() + " AND " + PLocationTable.GetLocationKeyDBName() + "=" + partnerLocationRow.LocationKey.ToString(); if (locationView.Count > 0) { PLocationRow locationRow = (PLocationRow)locationView[0].Row; addressNode.SetAttribute("Street", locationRow.StreetName); addressNode.SetAttribute("City", locationRow.City); addressNode.SetAttribute("PostCode", locationRow.PostalCode); } addressNode.SetAttribute("Email", partnerLocationRow.EmailAddress); addressNode.SetAttribute("Phone", partnerLocationRow.TelephoneNumber); addressNode.SetAttribute("MobilePhone", partnerLocationRow.MobileNumber); } // TODO: notes // TODO: This doesn't export as much data as it should? } } } return(TXMLParser.XmlToString(PartnerData)); }
private static void ParsePartners(ref PartnerImportExportTDS AMainDS, XmlNode ACurNode, TDBTransaction ATransaction, ref TVerificationResultCollection AVerificationResult) { XmlNode LocalNode = ACurNode; while (LocalNode != null) { if (LocalNode.Name.StartsWith("PartnerGroup")) { ParsePartners(ref AMainDS, LocalNode.FirstChild, ATransaction, ref AVerificationResult); } else if (LocalNode.Name.StartsWith("Partner")) { PPartnerRow PartnerRow = AMainDS.PPartner.NewRowTyped(); Boolean IsExistingPartner = false; if (!TYml2Xml.HasAttributeRecursive(LocalNode, "SiteKey")) { throw new Exception(Catalog.GetString("Missing SiteKey Attribute")); } if (!TYml2Xml.HasAttributeRecursive(LocalNode, "status")) { throw new Exception(Catalog.GetString("Missing status Attribute")); } // get a new partner key if (TYml2Xml.HasAttribute(LocalNode, "PartnerKey")) { PartnerRow.PartnerKey = Convert.ToInt64(TYml2Xml.GetAttribute(LocalNode, "PartnerKey")); if (PPartnerAccess.Exists(PartnerRow.PartnerKey, ATransaction)) { AMainDS.Merge(PPartnerAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.PPartner.DefaultView.RowFilter = String.Format("{0} = '{1}'", PPartnerTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey); PartnerRow = (PPartnerRow)AMainDS.PPartner.DefaultView[0].Row; IsExistingPartner = true; } else { AMainDS.PPartner.Rows.Add(PartnerRow); } } else { PartnerRow.PartnerKey = TImportExportYml.NewPartnerKey; TImportExportYml.NewPartnerKey--; } String PartnerClass = TYml2Xml.GetAttributeRecursive(LocalNode, "class"); TLogging.LogAtLevel(TLogging.DEBUGLEVEL_TRACE, PartnerClass + " " + LocalNode.Name + " " + "PartnerKey=" + PartnerRow.PartnerKey ); if (IsExistingPartner && (PartnerClass != PartnerRow.PartnerClass)) { throw new Exception(String.Format("Error: Yml contains Existing Partner {0} with a different partner class {1}!", PartnerRow.PartnerKey, PartnerClass)); } PartnerRow.PartnerClass = PartnerClass; if (PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { PFamilyRow FamilyRow; if (IsExistingPartner) { AMainDS.Merge(PFamilyAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.PFamily.DefaultView.RowFilter = String.Format("{0} = '{1}'", PFamilyTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey); FamilyRow = (PFamilyRow)AMainDS.PFamily.DefaultView[0].Row; } else { FamilyRow = AMainDS.PFamily.NewRowTyped(); FamilyRow.PartnerKey = PartnerRow.PartnerKey; PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY; AMainDS.PFamily.Rows.Add(FamilyRow); } FamilyRow.FamilyName = TYml2Xml.GetAttributeRecursive(LocalNode, "LastName"); FamilyRow.FirstName = TYml2Xml.GetAttribute(LocalNode, "FirstName"); FamilyRow.Title = TYml2Xml.GetAttribute(LocalNode, "Title"); if (TYml2Xml.HasAttribute(LocalNode, "CreatedAt")) { FamilyRow.DateCreated = Convert.ToDateTime(TYml2Xml.GetAttribute(LocalNode, "CreatedAt")); } PartnerRow.AddresseeTypeCode = MPartnerConstants.PARTNERCLASS_FAMILY; PartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(FamilyRow.FamilyName, FamilyRow.Title, FamilyRow.FirstName); } if (PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { PPersonRow PersonRow; if (IsExistingPartner) { AMainDS.Merge(PPersonAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.PPerson.DefaultView.RowFilter = String.Format("{0} = '{1}'", PPersonTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey); PersonRow = (PPersonRow)AMainDS.PPerson.DefaultView[0].Row; } else { PersonRow = AMainDS.PPerson.NewRowTyped(); PersonRow.PartnerKey = PartnerRow.PartnerKey; AMainDS.PPerson.Rows.Add(PersonRow); } PersonRow.FamilyName = TYml2Xml.GetAttributeRecursive(LocalNode, "LastName"); PersonRow.FirstName = TYml2Xml.GetAttribute(LocalNode, "FirstName"); PersonRow.Title = TYml2Xml.GetAttribute(LocalNode, "Title"); if (TYml2Xml.HasAttribute(LocalNode, "CreatedAt")) { PersonRow.DateCreated = Convert.ToDateTime(TYml2Xml.GetAttribute(LocalNode, "CreatedAt")); } // PersonRow.Sp PartnerRow.PartnerShortName = Calculations.DeterminePartnerShortName(PersonRow.FamilyName, PersonRow.Title, PersonRow.FirstName); } else if (PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { POrganisationRow OrganisationRow; if (IsExistingPartner) { AMainDS.Merge(POrganisationAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.POrganisation.DefaultView.RowFilter = String.Format("{0} = '{1}'", POrganisationTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey); OrganisationRow = (POrganisationRow)AMainDS.POrganisation.DefaultView[0].Row; } else { OrganisationRow = AMainDS.POrganisation.NewRowTyped(); OrganisationRow.PartnerKey = PartnerRow.PartnerKey; AMainDS.POrganisation.Rows.Add(OrganisationRow); } OrganisationRow.OrganisationName = TYml2Xml.GetAttributeRecursive(LocalNode, "Name"); PartnerRow.PartnerShortName = OrganisationRow.OrganisationName; } else if (PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { PUnitRow UnitRow; if (IsExistingPartner) { AMainDS.Merge(PUnitAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.PUnit.DefaultView.RowFilter = String.Format("{0} = '{1}'", PUnitTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey); UnitRow = (PUnitRow)AMainDS.PUnit.DefaultView[0].Row; } else { UnitRow = AMainDS.PUnit.NewRowTyped(); UnitRow.PartnerKey = PartnerRow.PartnerKey; AMainDS.PUnit.Rows.Add(UnitRow); } UnitRow.UnitTypeCode = TYml2Xml.GetAttributeRecursive(LocalNode, "UnitTypeCode"); UnitRow.UnitName = TYml2Xml.GetAttributeRecursive(LocalNode, "Name"); if (PartnerRow.PartnerKey < -1) { throw new Exception("Invalid Partner Key or No Partner Key - and no proper handling implemented"); // from here... /* * AVerificationResult.Add(new TVerificationResult( * String.Format(Catalog.GetString("Importing Unit {0}"), UnitRow.UnitName), * Catalog.GetString("You need to provide a partner key for the unit"), * TResultSeverity.Resv_Critical)); */ // ...to here: throws Exception in case of a illegal import file? // The above code must have a glitch } if (!TYml2Xml.HasAttribute(LocalNode, "ParentUnitKey")) { throw new Exception( "The currently being processed unit (PartnerKey " + PartnerRow.PartnerKey + ") requires a ParentUnitKey."); } Int64 ParentKey = Convert.ToInt64(TYml2Xml.GetAttributeRecursive(LocalNode, "ParentUnitKey")); UmUnitStructureRow UnitStructureRow = null; if (IsExistingPartner) { AMainDS.Merge(UmUnitStructureAccess.LoadViaPUnitChildUnitKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.UmUnitStructure.DefaultView.RowFilter = String.Format("{0} = '{1}'", UmUnitStructureTable.GetChildUnitKeyDBName(), PartnerRow.PartnerKey); if (AMainDS.UmUnitStructure.DefaultView.Count > 0) { UnitStructureRow = (UmUnitStructureRow)AMainDS.UmUnitStructure.DefaultView[0].Row; } } if (UnitStructureRow == null) { UnitStructureRow = AMainDS.UmUnitStructure.NewRowTyped(); UnitStructureRow.ParentUnitKey = ParentKey; UnitStructureRow.ChildUnitKey = PartnerRow.PartnerKey; AMainDS.UmUnitStructure.Rows.Add(UnitStructureRow); } else { UnitStructureRow.ParentUnitKey = ParentKey; UnitStructureRow.ChildUnitKey = PartnerRow.PartnerKey; } PartnerRow.PartnerShortName = UnitRow.UnitName; } else if (PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { PBankRow BankRow; if (IsExistingPartner) { AMainDS.Merge(PBankAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction)); AMainDS.PBank.DefaultView.RowFilter = String.Format("{0} = '{1}'", PBankTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey); BankRow = (PBankRow)AMainDS.PBank.DefaultView[0].Row; } else { BankRow = AMainDS.PBank.NewRowTyped(); BankRow.PartnerKey = PartnerRow.PartnerKey; AMainDS.PBank.Rows.Add(BankRow); } BankRow.BranchName = TYml2Xml.GetAttribute(LocalNode, "BranchName"); BankRow.BranchCode = TYml2Xml.GetAttribute(LocalNode, "BranchCode"); BankRow.Bic = TYml2Xml.GetAttribute(LocalNode, "BranchBic"); BankRow.EpFormatFile = TYml2Xml.GetAttribute(LocalNode, "EpFormatFile"); if (TYml2Xml.HasAttribute(LocalNode, "CreatedAt")) { BankRow.DateCreated = Convert.ToDateTime(TYml2Xml.GetAttribute(LocalNode, "CreatedAt")); } } else { /* * throw new Exception( * "Unknown Partner Class" + * TYml2Xml.GetAttributeRecursive(LocalNode, "class")); */ // TODO AVerificationResult add failing problem: unknown partner class } PartnerRow.StatusCode = TYml2Xml.GetAttributeRecursive(LocalNode, "status"); // import special types StringCollection SpecialTypes = StringHelper.StrSplit(TYml2Xml.GetAttributeRecursive(LocalNode, "SpecialTypes"), ","); if (IsExistingPartner) { PPartnerTypeAccess.LoadViaPPartner(AMainDS, PartnerRow.PartnerKey, ATransaction); } foreach (string SpecialType in SpecialTypes) { PPartnerTypeRow PartnerTypeRow = null; AMainDS.PPartnerType.DefaultView.RowFilter = String.Format("{0}={1} AND {2}='{3}'", PPartnerTypeTable.GetPartnerKeyDBName(), PartnerRow.PartnerKey, PPartnerTypeTable.GetTypeCodeDBName(), SpecialType ); if (AMainDS.PPartnerType.DefaultView.Count > 0) { PartnerTypeRow = (PPartnerTypeRow)AMainDS.PPartnerType.DefaultView[0].Row; } else { PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped(); PartnerTypeRow.PartnerKey = PartnerRow.PartnerKey; PartnerTypeRow.TypeCode = SpecialType.Trim(); AMainDS.PPartnerType.Rows.Add(PartnerTypeRow); } // Check Partner type exists, or create it bool TypeIsKnown = PTypeAccess.Exists(PartnerTypeRow.TypeCode, ATransaction); if (!TypeIsKnown) { Int32 RowIdx = AMainDS.PType.DefaultView.Find(PartnerTypeRow.TypeCode); // I might have created it a second ago.. if (RowIdx < 0) { PTypeRow TypeRow = AMainDS.PType.NewRowTyped(); TypeRow.TypeCode = PartnerTypeRow.TypeCode; TypeRow.TypeDescription = "Created from YAML import"; AMainDS.PType.Rows.Add(TypeRow); } } } // import subscriptions StringCollection Subscriptions = StringHelper.StrSplit(TYml2Xml.GetAttributeRecursive(LocalNode, "Subscriptions"), ","); foreach (string publicationCode in Subscriptions) { PSubscriptionRow subscription = AMainDS.PSubscription.NewRowTyped(); subscription.PartnerKey = PartnerRow.PartnerKey; subscription.PublicationCode = publicationCode.Trim(); subscription.ReasonSubsGivenCode = "FREE"; AMainDS.PSubscription.Rows.Add(subscription); } // import address XmlNode addressNode = TYml2Xml.GetChild(LocalNode, "Address"); if ((addressNode == null) || (TYml2Xml.GetAttributeRecursive(addressNode, "Street").Length == 0)) { if (!IsExistingPartner) { // add the empty location PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true); partnerlocation.SiteKey = 0; partnerlocation.PartnerKey = PartnerRow.PartnerKey; partnerlocation.DateEffective = DateTime.Now; partnerlocation.LocationType = "HOME"; partnerlocation.SendMail = false; partnerlocation.EmailAddress = TYml2Xml.GetAttributeRecursive(addressNode, "Email"); partnerlocation.TelephoneNumber = TYml2Xml.GetAttributeRecursive(addressNode, "Phone"); partnerlocation.MobileNumber = TYml2Xml.GetAttributeRecursive(addressNode, "MobilePhone"); AMainDS.PPartnerLocation.Rows.Add(partnerlocation); } } else { PLocationRow location = AMainDS.PLocation.NewRowTyped(true); location.LocationKey = (AMainDS.PLocation.Rows.Count + 1) * -1; location.SiteKey = 0; if (!TYml2Xml.HasAttributeRecursive(LocalNode, "Country")) { throw new Exception(Catalog.GetString("Missing Country Attribute")); } location.CountryCode = TYml2Xml.GetAttributeRecursive(addressNode, "Country"); location.StreetName = TYml2Xml.GetAttributeRecursive(addressNode, "Street"); location.City = TYml2Xml.GetAttributeRecursive(addressNode, "City"); location.PostalCode = TYml2Xml.GetAttributeRecursive(addressNode, "PostCode"); AMainDS.PLocation.Rows.Add(location); PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true); partnerlocation.SiteKey = 0; partnerlocation.LocationKey = location.LocationKey; partnerlocation.PartnerKey = PartnerRow.PartnerKey; partnerlocation.SendMail = true; partnerlocation.DateEffective = DateTime.Now; partnerlocation.LocationType = "HOME"; partnerlocation.EmailAddress = TYml2Xml.GetAttributeRecursive(addressNode, "Email"); partnerlocation.TelephoneNumber = TYml2Xml.GetAttributeRecursive(addressNode, "Phone"); partnerlocation.MobileNumber = TYml2Xml.GetAttributeRecursive(addressNode, "MobilePhone"); AMainDS.PPartnerLocation.Rows.Add(partnerlocation); } // import finance details (bank account number) XmlNode financialDetailsNode = TYml2Xml.GetChild(LocalNode, "FinancialDetails"); ParseFinancialDetails(AMainDS, financialDetailsNode, PartnerRow.PartnerKey, ATransaction); } LocalNode = LocalNode.NextSibling; } }