/// <summary> /// Returns the Key Count of an Extract. /// </summary> /// <param name="AExtractId">ExtractId of the Extract that the KeyCount should /// get returned for.</param> /// <returns>The Key Count of the Extract, or -1 if the Extract with the given /// Extract Id doesn't exist.</returns> public static Int32 GetExtractKeyCount(int AExtractId) { Boolean NewTransaction; TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { MExtractMasterTable ExtractDT = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, ReadTransaction); if (ExtractDT.Rows.Count == 1) { return(ExtractDT[0].KeyCount); } else { return(-1); } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TExtractsHandling.GetExtractKeyCount: committed own transaction."); } } }
/// <summary> /// Open Dialog to find extracts to be added list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddExtractToList(System.Object sender, EventArgs e) { TFrmExtractFindDialog ExtractFindDialog = new TFrmExtractFindDialog(this.ParentForm); MExtractMasterTable ExtractMasterTable = new MExtractMasterTable(); MExtractMasterRow NewRow; // let the user select base extract ExtractFindDialog.AllowMultipleSelect = true; ExtractFindDialog.ShowDialog(true); // get data for selected base extract ExtractFindDialog.GetResult(ref ExtractMasterTable); ExtractFindDialog.Dispose(); // only continue if an extract was selected foreach (MExtractMasterRow Row in ExtractMasterTable.Rows) { if (!FExtractMasterTable.Rows.Contains(new object[] { Row.ExtractId })) { NewRow = FExtractMasterTable.NewRowTyped(); NewRow.ExtractId = Row.ExtractId; NewRow.ExtractName = Row.ExtractName; NewRow.ExtractDesc = Row.ExtractDesc; NewRow.KeyCount = Row.KeyCount; NewRow.CreatedBy = Row.CreatedBy; NewRow.DateCreated = Row.DateCreated; FExtractMasterTable.Rows.Add(NewRow); btnRemove.Enabled = true; } } }
/// <summary> /// Called by the instantiator of this Dialog to retrieve the result of the dialog /// /// </summary> /// <param name="AExtractMasterTable"></param> /// <returns>true if at least one row was selected /// </returns> public bool GetResult(ref MExtractMasterTable AExtractMasterTable) { MExtractMasterRow NewRow; AExtractMasterTable.Clear(); if (FResultTable == null) { return(false); } foreach (MExtractMasterRow Row in FResultTable.Rows) { NewRow = AExtractMasterTable.NewRowTyped(); NewRow.ExtractId = Row.ExtractId; NewRow.ExtractName = Row.ExtractName; NewRow.ExtractDesc = Row.ExtractDesc; NewRow.KeyCount = Row.KeyCount; NewRow.CreatedBy = Row.CreatedBy; NewRow.DateCreated = Row.DateCreated; AExtractMasterTable.Rows.Add(NewRow); } return(AExtractMasterTable.Count >= 0); }
/// <summary> /// Updates the KeyCount on an Extract. /// </summary> /// <param name="AExtractId">ExtractId of the Extract that the KeyCount should /// get updated for.</param> /// <param name="ACount">New Key Count.</param> /// <param name="AVerificationResult">Contains errors or DB call exceptions, if there are any.</param> /// <returns>True if the updating was successful, otherwise false.</returns> public static bool UpdateExtractKeyCount(int AExtractId, int ACount, out TVerificationResultCollection AVerificationResult) { TDBTransaction Transaction = null; bool SubmissionOK = false; TVerificationResultCollection VerificationResult = new TVerificationResultCollection(); DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { MExtractMasterTable ExtractMasterDT = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, Transaction); if (ExtractMasterDT.Rows.Count == 1) { ExtractMasterDT[0].KeyCount = ACount; MExtractMasterAccess.SubmitChanges(ExtractMasterDT, Transaction); SubmissionOK = true; } else { VerificationResult.Add(new TVerificationResult( "TExtractsHandling.UpdateExtractCount", "Extract with Extract Id " + AExtractId.ToString() + " doesn't exist!", TResultSeverity.Resv_Critical)); } }); AVerificationResult = VerificationResult; return(SubmissionOK); }
private void InitializeManualCode() { // show this dialog in center of screen this.StartPosition = FormStartPosition.CenterScreen; // enable grid to react to insert and delete keyboard keys grdExtracts.InsertKeyPressed += new TKeyPressedEventHandler(grdExtracts_InsertKeyPressed); grdExtracts.DeleteKeyPressed += new TKeyPressedEventHandler(grdExtracts_DeleteKeyPressed); FExtractMasterTable = new MExtractMasterTable(); grdExtracts.Columns.Clear(); grdExtracts.AddTextColumn("Extract Name", FExtractMasterTable.ColumnExtractName); grdExtracts.AddTextColumn("Created By", FExtractMasterTable.ColumnCreatedBy); grdExtracts.AddTextColumn("Key Count", FExtractMasterTable.ColumnKeyCount); grdExtracts.AddTextColumn("Description", FExtractMasterTable.ColumnExtractDesc); grdExtracts.AddDateColumn("Created Date", FExtractMasterTable.ColumnDateCreated); DataView myDataView = FExtractMasterTable.DefaultView; myDataView.AllowNew = false; grdExtracts.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView); btnRemove.Enabled = false; }
public static Boolean GetExtractDescription(String AExtractName, out String AExtractDescription) { TDBTransaction ReadTransaction; Boolean NewTransaction; Boolean ReturnValue = false; AExtractDescription = "Can not retrieve description"; TLogging.LogAtLevel(9, "TPartnerServerLookups.GetExtractDescription called!"); MExtractMasterTable ExtractMasterDT = new MExtractMasterTable(); ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); // Load data MExtractMasterTable TemplateExtractDT = new MExtractMasterTable(); MExtractMasterRow TemplateRow = TemplateExtractDT.NewRowTyped(false); TemplateRow.ExtractName = AExtractName; try { ExtractMasterDT = MExtractMasterAccess.LoadUsingTemplate(TemplateRow, ReadTransaction); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TPartnerServerLookups.GetExtractDescription: committed own transaction."); } } if (ExtractMasterDT.Rows.Count < 1) { ReturnValue = false; TLogging.LogAtLevel(7, "TPartnerServerLookups.TPartnerServerLookups.GetExtractDescription: m_extract_master DB Table is empty"); } else { MExtractMasterRow ExtractRow = ExtractMasterDT.Rows[0] as MExtractMasterRow; if (ExtractRow != null) { AExtractDescription = ExtractRow.ExtractDesc; ReturnValue = true; } } return(ReturnValue); }
public static MExtractMasterTable GetAllExtractHeaders() { MExtractMasterTable ExtractMasterDT = new MExtractMasterTable(); TDBTransaction Transaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction, delegate { ExtractMasterDT = MExtractMasterAccess.LoadAll(Transaction); }); return ExtractMasterDT; }
/// <summary> /// close the screen and return the selected extract as accepted record /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AcceptExtract(System.Object sender, EventArgs e) { MExtractMasterRow ExtractMasterRow; FResultTable = new MExtractMasterTable(); //MExtractMasterRow SelectedRow = null; DataRow SelectedRow = null; if (AllowMultipleSelect) { // multiple rows may have been selected: find all the ones where first column is ticked foreach (DataRow Row in FDataTable.Rows) { if (Convert.ToBoolean(Row[FCheckedColumnName]) == true) { ExtractMasterRow = FResultTable.NewRowTyped(); ExtractMasterRow.ExtractId = (int)Row[MExtractMasterTable.GetExtractIdDBName()]; ExtractMasterRow.ExtractName = Row[MExtractMasterTable.GetExtractNameDBName()].ToString(); ExtractMasterRow.ExtractDesc = Row[MExtractMasterTable.GetExtractDescDBName()].ToString(); ExtractMasterRow.KeyCount = (int)Row[MExtractMasterTable.GetKeyCountDBName()]; ExtractMasterRow.CreatedBy = Row[MExtractMasterTable.GetCreatedByDBName()].ToString(); ExtractMasterRow.DateCreated = (DateTime)Row[MExtractMasterTable.GetDateCreatedDBName()]; FResultTable.Rows.Add(ExtractMasterRow); } } } else { // just one row can be selected DataRowView[] SelectedGridRow = clbDetails.SelectedDataRowsAsDataRowView; if (SelectedGridRow.Length >= 1) { SelectedRow = SelectedGridRow[0].Row; ExtractMasterRow = FResultTable.NewRowTyped(); ExtractMasterRow.ExtractId = (int)SelectedRow[MExtractMasterTable.GetExtractIdDBName()]; ExtractMasterRow.ExtractName = SelectedRow[MExtractMasterTable.GetExtractNameDBName()].ToString(); ExtractMasterRow.ExtractDesc = SelectedRow[MExtractMasterTable.GetExtractDescDBName()].ToString(); ExtractMasterRow.KeyCount = (int)SelectedRow[MExtractMasterTable.GetKeyCountDBName()]; ExtractMasterRow.CreatedBy = SelectedRow[MExtractMasterTable.GetCreatedByDBName()].ToString(); ExtractMasterRow.DateCreated = (DateTime)SelectedRow[MExtractMasterTable.GetDateCreatedDBName()]; FResultTable.Rows.Add(ExtractMasterRow); } } Close(); }
/// <summary> /// Create grid and populate /// </summary> private void CreateGrid() { string CheckedMember = FCheckedColumnName; string IdMember = MExtractMasterTable.GetExtractIdDBName(); string NameMember = MExtractMasterTable.GetExtractNameDBName(); string DescriptionMember = MExtractMasterTable.GetExtractDescDBName(); string DeletableMember = MExtractMasterTable.GetDeletableDBName(); string KeyCountMember = MExtractMasterTable.GetKeyCountDBName(); string CreatedByMember = MExtractMasterTable.GetCreatedByDBName(); string DateCreatedMember = MExtractMasterTable.GetDateCreatedDBName(); string ModifiedByMember = MExtractMasterTable.GetModifiedByDBName(); string DateModifiedMember = MExtractMasterTable.GetDateModifiedDBName(); FExtractMasterTable = TRemote.MPartner.Partner.WebConnectors.GetAllExtractHeaders(); if (FExtractMasterTable != null) { DataView view = new DataView(FExtractMasterTable); FDataTable = view.ToTable(true, new string[] { IdMember, NameMember, DescriptionMember, DeletableMember, KeyCountMember, CreatedByMember, DateCreatedMember, ModifiedByMember, DateModifiedMember }); FDataTable.Columns.Add(new DataColumn(CheckedMember, typeof(bool))); clbDetails.Columns.Clear(); if (FAllowMultipleSelect) { clbDetails.AddCheckBoxColumn("Select", FDataTable.Columns[FCheckedColumnName], 17, false); } else { clbDetails.AutoFindColumn = 0; } clbDetails.AddTextColumn("Extract Name", FDataTable.Columns[NameMember] /*, 200*/); clbDetails.AddCheckBoxColumn("Deletable", FDataTable.Columns[DeletableMember] /*, 120*/); clbDetails.AddTextColumn("Key Count", FDataTable.Columns[KeyCountMember] /*, 80*/); clbDetails.AddTextColumn("Description", FDataTable.Columns[DescriptionMember] /*, 300*/); clbDetails.DataBindGrid(FDataTable, NameMember, CheckedMember, NameMember, false, true, false); clbDetails.SetCheckedStringList(""); } this.clbDetails.ValueChanged += new System.EventHandler(this.UpdateRecordCount); PrepareButtons(); UpdateRecordCount(); }
/// <summary> /// Checks whether an Extract with a certain Extract Name exists. /// </summary> /// <param name="AExtractName">Name of the Extract to check for.</param> /// <returns>True if an Extract with the specified Extract Name exists, /// otherwise false.</returns> public static bool CheckExtractExists(string AExtractName) { TDBTransaction ReadTransaction; Boolean NewTransaction; Boolean ReturnValue = false; MExtractMasterRow TemplateRow; ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); // Check if there is already an extract with the extract name try { TemplateRow = new MExtractMasterTable().NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, ReadTransaction) > 0) { ReturnValue = true; } if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TExtractsHandling.CheckExtractExists: committed own transaction!"); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the checking whether an Extract exists:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } return(ReturnValue); }
/// <summary> /// Checks whether an Extract with a certain Extract Name exists. /// </summary> /// <param name="AExtractName">Name of the Extract to check for.</param> /// <returns>True if an Extract with the specified Extract Name exists, /// otherwise false.</returns> public static bool CheckExtractExists(string AExtractName) { TDBTransaction Transaction = new TDBTransaction(); Boolean ReturnValue = false; MExtractMasterRow TemplateRow; DBAccess.ReadTransaction( ref Transaction, delegate { // Check if there is already an extract with the extract name TemplateRow = new MExtractMasterTable().NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, Transaction) > 0) { ReturnValue = true; } }); return(ReturnValue); }
/// <summary> /// Returns the Key Count of an Extract. /// </summary> /// <param name="AExtractId">ExtractId of the Extract that the KeyCount should /// get returned for.</param> /// <returns>The Key Count of the Extract, or -1 if the Extract with the given /// Extract Id doesn't exist.</returns> public static Int32 GetExtractKeyCount(int AExtractId) { TDBTransaction Transaction = new TDBTransaction(); Int32 KeyCount = 0; DBAccess.ReadTransaction( ref Transaction, delegate { MExtractMasterTable ExtractDT = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, Transaction); if (ExtractDT.Rows.Count == 1) { KeyCount = ExtractDT[0].KeyCount; } else { KeyCount = -1; } }); return(KeyCount); }
/// <summary> /// Checks whether an Extract with a certain Extract Name exists. /// </summary> /// <param name="AExtractName">Name of the Extract to check for.</param> /// <returns>True if an Extract with the specified Extract Name exists, /// otherwise false.</returns> public static bool CheckExtractExists(string AExtractName) { TDBTransaction Transaction = null; Boolean ReturnValue = false; MExtractMasterRow TemplateRow; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { // Check if there is already an extract with the extract name TemplateRow = new MExtractMasterTable().NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, Transaction) > 0) { ReturnValue = true; } }); return(ReturnValue); }
/// <summary> /// Returns the Key Count of an Extract. /// </summary> /// <param name="AExtractId">ExtractId of the Extract that the KeyCount should /// get returned for.</param> /// <returns>The Key Count of the Extract, or -1 if the Extract with the given /// Extract Id doesn't exist.</returns> public static Int32 GetExtractKeyCount(int AExtractId) { TDBTransaction Transaction = null; Int32 KeyCount = 0; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { MExtractMasterTable ExtractDT = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, Transaction); if (ExtractDT.Rows.Count == 1) { KeyCount = ExtractDT[0].KeyCount; } else { KeyCount = -1; } }); return(KeyCount); }
private void RefreshFilter(System.Object sender, EventArgs e) { if (FDataTable == null) { return; } DataView dv = FDataTable.DefaultView; string FilterString = string.Empty; if (!string.IsNullOrEmpty(txtExtractName.Text)) { FilterString = MExtractMasterTable.GetExtractNameDBName() + " LIKE '%" + txtExtractName.Text + "%' AND "; } if (!string.IsNullOrEmpty(txtExtractDesc.Text)) { FilterString += MExtractMasterTable.GetExtractDescDBName() + " LIKE '%" + txtExtractDesc.Text + "%' AND "; } if (!string.IsNullOrEmpty(cmbUserCreated.GetSelectedString())) { FilterString += MExtractMasterTable.GetCreatedByDBName() + " = '" + cmbUserCreated.GetSelectedString() + "' AND "; } if ((dtpCreatedFrom.Date != null) && dtpCreatedFrom.ValidDate()) { FilterString += MExtractMasterTable.GetDateCreatedDBName() + " >= '" + ((DateTime)dtpCreatedFrom.Date).ToShortDateString() + "' AND "; } if ((dtpCreatedTo.Date != null) && dtpCreatedTo.ValidDate()) { FilterString += MExtractMasterTable.GetDateCreatedDBName() + " <= '" + ((DateTime)dtpCreatedTo.Date).ToShortDateString() + "' AND "; } if (!string.IsNullOrEmpty(cmbUserModified.GetSelectedString())) { FilterString += MExtractMasterTable.GetModifiedByDBName() + " = '" + cmbUserModified.GetSelectedString() + "' AND "; } if ((dtpModifiedFrom.Date != null) && dtpModifiedFrom.ValidDate()) { FilterString += MExtractMasterTable.GetDateModifiedDBName() + " >= '" + ((DateTime)dtpModifiedFrom.Date).ToShortDateString() + "' AND "; } if ((dtpModifiedTo.Date != null) && dtpModifiedTo.ValidDate()) { FilterString += MExtractMasterTable.GetDateModifiedDBName() + " <= '" + ((DateTime)dtpModifiedTo.Date).ToShortDateString() + "'"; } if (FilterString.EndsWith(" AND ")) { FilterString = FilterString.Remove(FilterString.Length - 5); } dv.RowFilter = FilterString; // temp remove event so UpdateRecordCount doesn't get called for every row this.clbDetails.ValueChanged -= new System.EventHandler(this.UpdateRecordCount); clbDetails.SetCheckedStringList(""); clbDetails.DataSource = new DevAge.ComponentModel.BoundDataView(dv); clbDetails.AutoResizeGrid(); this.clbDetails.ValueChanged += new System.EventHandler(this.UpdateRecordCount); UpdateRecordCount(); }
/// <summary> /// reload extract list when search button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RefreshExtractList(System.Object sender, EventArgs e) { bool AllUsers = true; String CreatedByUser = ""; String ModifiedByUser = ""; DateTime?DateCreatedFrom = null; DateTime?DateCreatedTo = null; DateTime?DateModifiedFrom = null; DateTime?DateModifiedTo = null; string CheckedMember = FCheckedColumnName; string IdMember = MExtractMasterTable.GetExtractIdDBName(); string NameMember = MExtractMasterTable.GetExtractNameDBName(); string DescriptionMember = MExtractMasterTable.GetExtractDescDBName(); string DeletableMember = MExtractMasterTable.GetDeletableDBName(); string KeyCountMember = MExtractMasterTable.GetKeyCountDBName(); string CreatedByMember = MExtractMasterTable.GetCreatedByDBName(); string DateCreatedMember = MExtractMasterTable.GetDateCreatedDBName(); if (cmbUserCreated.GetSelectedString().Length > 0) { AllUsers = false; CreatedByUser = cmbUserCreated.GetSelectedString(); } if (cmbUserModified.GetSelectedString().Length > 0) { AllUsers = false; ModifiedByUser = cmbUserModified.GetSelectedString(); } if (dtpCreatedFrom.Text.Length > 0) { DateCreatedFrom = dtpCreatedFrom.Date; } if (dtpCreatedTo.Text.Length > 0) { DateCreatedTo = dtpCreatedTo.Date; } if (dtpModifiedFrom.Text.Length > 0) { DateModifiedFrom = dtpModifiedFrom.Date; } if (dtpModifiedTo.Text.Length > 0) { DateModifiedTo = dtpModifiedTo.Date; } FExtractMasterTable = TRemote.MPartner.Partner.WebConnectors.GetAllExtractHeaders(txtExtractName.Text, txtExtractDesc.Text, AllUsers, CreatedByUser, ModifiedByUser, DateCreatedFrom, DateCreatedTo, DateModifiedFrom, DateModifiedTo); if (FExtractMasterTable != null) { DataView view = new DataView(FExtractMasterTable); FDataTable = view.ToTable(true, new string[] { IdMember, NameMember, DescriptionMember, DeletableMember, KeyCountMember, CreatedByMember, DateCreatedMember }); FDataTable.Columns.Add(new DataColumn(CheckedMember, typeof(bool))); clbDetails.Columns.Clear(); if (FAllowMultipleSelect) { clbDetails.AddCheckBoxColumn("Select", FDataTable.Columns[FCheckedColumnName], 17, false); } clbDetails.AddTextColumn("Extract Name", FDataTable.Columns[NameMember], 200); clbDetails.AddCheckBoxColumn("Deletable", FDataTable.Columns[DeletableMember], 120); clbDetails.AddTextColumn("Key Count", FDataTable.Columns[KeyCountMember], 80); clbDetails.AddTextColumn("Description", FDataTable.Columns[DescriptionMember], 300); clbDetails.DataBindGrid(FDataTable, NameMember, CheckedMember, NameMember, false, true, false); clbDetails.SetCheckedStringList(""); } PrepareButtons(); clbDetails.Select(); }
/// <summary> /// extend an extract from a list of best addresses /// </summary> /// <param name="AExtractId">Extract Id of the Extract to extend</param> /// <param name="APartnerKeysTable"></param> /// <param name="APartnerKeyColumn">number of the column that contains the partner keys</param> /// <param name="ASiteKeyColumn">number of the column that contains the site keys</param> /// <param name="ALocationKeyColumn">number of the column that contains the location keys</param> /// <param name="AIgnoreDuplicates">true if duplicates should be looked out for. Can be set to false if called only once and not several times per extract.</param> public static void ExtendExtractFromListOfPartnerKeys( Int32 AExtractId, DataTable APartnerKeysTable, Int32 APartnerKeyColumn, Int32 ASiteKeyColumn, Int32 ALocationKeyColumn, bool AIgnoreDuplicates) { int RecordCounter = 0; PPartnerLocationTable PartnerLocationKeysTable; Int64 PartnerKey; TDBTransaction Transaction = null; bool SubmissionOK = true; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { MExtractTable ExtractTable = new MExtractTable(); ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, Transaction); // Location Keys need to be determined as extracts do not only need partner keys but // also Location Keys. DetermineBestLocationKeys(APartnerKeysTable, APartnerKeyColumn, ASiteKeyColumn, ALocationKeyColumn, out PartnerLocationKeysTable, Transaction); // use the returned table which contains partner and location keys to build the extract foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationKeysTable.Rows) { PartnerKey = Convert.ToInt64(PartnerLocationRow[PPartnerLocationTable.GetPartnerKeyDBName()]); if (PartnerKey > 0) { RecordCounter += 1; TLogging.LogAtLevel(1, "Preparing Partner " + PartnerKey + " (Record Number " + RecordCounter + ")"); // add row for partner to extract and fill with contents MExtractRow NewRow = ExtractTable.NewRowTyped(); NewRow.ExtractId = AExtractId; NewRow.PartnerKey = PartnerKey; NewRow.SiteKey = Convert.ToInt64(PartnerLocationRow[PPartnerLocationTable.GetSiteKeyDBName()]); NewRow.LocationKey = Convert.ToInt32(PartnerLocationRow[PPartnerLocationTable.GetLocationKeyDBName()]); // only add row if it does not already exist for this partner if (AIgnoreDuplicates || !ExtractTable.Rows.Contains(new object[] { NewRow.ExtractId, NewRow.PartnerKey, NewRow.SiteKey })) { ExtractTable.Rows.Add(NewRow); } } } if (ExtractTable.Rows.Count > 0) { // update field in extract master for quick access to number of partners in extract MExtractMasterTable ExtractMaster = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, Transaction); ExtractMaster[0].KeyCount = ExtractTable.Rows.Count; ExtractTable.ThrowAwayAfterSubmitChanges = true; // no need to keep data as this increases speed significantly MExtractAccess.SubmitChanges(ExtractTable, Transaction); MExtractMasterAccess.SubmitChanges(ExtractMaster, Transaction); } }); }
public static TSubmitChangesResult SaveExtractMaster(ref MExtractMasterTable AExtractMasterTable) { TDBTransaction SubmitChangesTransaction; int ExtractId; int CountRecords; MExtractMasterRow Row; if (AExtractMasterTable != null) { SubmitChangesTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { /* Cascading delete for deleted rows. Once the cascading delete has been done the row * needs to be removed from the table with AcceptChanges as otherwise the later call * to SubmitChanges will complain about those rows that have already been deleted in * the database. * Use a loop to run through the table in reverse Order (Index--) so that the rows * can actually be removed from the table without affecting the access throug Index. */ CountRecords = AExtractMasterTable.Rows.Count; for (int Index = CountRecords - 1; Index >= 0; Index--) { Row = (MExtractMasterRow)AExtractMasterTable.Rows[Index]; if (Row.RowState == DataRowState.Deleted) { ExtractId = Convert.ToInt32(Row[MExtractMasterTable.GetExtractIdDBName(), DataRowVersion.Original]); MExtractMasterCascading.DeleteByPrimaryKey(ExtractId, SubmitChangesTransaction, true); // accept changes: this actually removes row from table Row.AcceptChanges(); } } // now submit all changes to extract master table MExtractMasterAccess.SubmitChanges(AExtractMasterTable, SubmitChangesTransaction); DBAccess.GDBAccessObj.CommitTransaction(); } catch (Exception Exc) { TLogging.Log("An Exception occured during the saving of Extract Master:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } } return TSubmitChangesResult.scrOK; }
/// <summary> /// extend an extract from a list of best addresses /// </summary> /// <param name="AExtractId">Extract Id of the Extract to extend</param> /// <param name="APartnerKeysTable"></param> /// <param name="APartnerKeyColumn">number of the column that contains the partner keys</param> /// <param name="ASiteKeyColumn">number of the column that contains the site keys</param> /// <param name="ALocationKeyColumn">number of the column that contains the location keys</param> /// <param name="AKeyCount">The number of keys that were actually added to the extract (any duplicates are excluded)</param> /// <param name="AIgnoredKeyList">A reference to a List of long. If not null the server will fill it with the partner keys that were ignored. Does not include duplicates.</param> /// <param name="AIgnoreDuplicates">true if duplicates should be looked out for. Can be set to false if called only once and not several times per extract.</param> /// <param name="AIgnoreInactive">true if inactive partners should be ignored</param> /// <param name="AIgnoreNonMailingLocations">true to ignore if the partner's best address is a non-mailing location</param> /// <param name="AIgnoreNoSolicitations">true to ignore partners where the No Solicitations flag is set</param> public static void ExtendExtractFromListOfPartnerKeys( Int32 AExtractId, DataTable APartnerKeysTable, Int32 APartnerKeyColumn, Int32 ASiteKeyColumn, Int32 ALocationKeyColumn, out Int32 AKeyCount, out List <long> AIgnoredKeyList, bool AIgnoreDuplicates, bool AIgnoreInactive, bool AIgnoreNonMailingLocations, bool AIgnoreNoSolicitations) { int RecordCounter = 0; PPartnerLocationTable PartnerLocationKeysTable; Int64 PartnerKey; List <long> ignoredKeyList = new List <long>(); TDBTransaction Transaction = null; bool SubmissionOK = true; DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { // Pre-process the table to remove partner rows that do not match the filter requirements for (int i = APartnerKeysTable.Rows.Count - 1; i >= 0; i--) { DataRow dr = APartnerKeysTable.Rows[i]; Int64 partnerKey = Convert.ToInt64(dr[APartnerKeyColumn]); // Get a partner record containing our fields of interest StringCollection fields = new StringCollection(); fields.Add(PPartnerTable.GetStatusCodeDBName()); fields.Add(PPartnerTable.GetNoSolicitationsDBName()); DataTable dt = PPartnerAccess.LoadByPrimaryKey(partnerKey, fields, Transaction); if (dt.Rows.Count > 0) { if (AIgnoreInactive || AIgnoreNoSolicitations) { bool isActive = false; bool isNoSolicitation = false; object o = dt.Rows[0][PPartnerTable.GetStatusCodeDBName()]; if (o != null) { TStdPartnerStatusCode statusCode = SharedTypes.StdPartnerStatusCodeStringToEnum(o.ToString()); isActive = (statusCode == TStdPartnerStatusCode.spscACTIVE); } o = dt.Rows[0][PPartnerTable.GetNoSolicitationsDBName()]; if (o != null) { isNoSolicitation = Convert.ToBoolean(o); } if ((AIgnoreInactive && !isActive) || (AIgnoreNoSolicitations && isNoSolicitation)) { ignoredKeyList.Add(partnerKey); APartnerKeysTable.Rows.Remove(dr); } } } else { ignoredKeyList.Add(partnerKey); } } MExtractTable ExtractTable = new MExtractTable(); ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, Transaction); // Location Keys need to be determined as extracts do not only need partner keys but // also Location Keys. DetermineBestLocationKeys(APartnerKeysTable, APartnerKeyColumn, ASiteKeyColumn, ALocationKeyColumn, out PartnerLocationKeysTable, Transaction); // use the returned table which contains partner and location keys to build the extract foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationKeysTable.Rows) { PartnerKey = PartnerLocationRow.PartnerKey; if (PartnerKey > 0) { if (AIgnoreNonMailingLocations) { // The PartnerLocationRow only contains the PK fields so now we need to get the SendMail column StringCollection fields = new StringCollection(); fields.Add(PPartnerLocationTable.GetSendMailDBName()); PPartnerLocationTable t = PPartnerLocationAccess.LoadByPrimaryKey(PartnerKey, PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey, fields, Transaction); if ((t != null) && (t.Rows.Count > 0) && (((PPartnerLocationRow)t.Rows[0]).SendMail == false)) { ignoredKeyList.Add(PartnerKey); continue; } } RecordCounter += 1; TLogging.LogAtLevel(1, "Preparing Partner " + PartnerKey + " (Record Number " + RecordCounter + ")"); // add row for partner to extract and fill with contents MExtractRow NewRow = ExtractTable.NewRowTyped(); NewRow.ExtractId = AExtractId; NewRow.PartnerKey = PartnerKey; NewRow.SiteKey = Convert.ToInt64(PartnerLocationRow[PPartnerLocationTable.GetSiteKeyDBName()]); NewRow.LocationKey = Convert.ToInt32(PartnerLocationRow[PPartnerLocationTable.GetLocationKeyDBName()]); // only add row if it does not already exist for this partner if (AIgnoreDuplicates || !ExtractTable.Rows.Contains(new object[] { NewRow.ExtractId, NewRow.PartnerKey, NewRow.SiteKey })) { ExtractTable.Rows.Add(NewRow); } } } if (ExtractTable.Rows.Count > 0) { // update field in extract master for quick access to number of partners in extract MExtractMasterTable ExtractMaster = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, Transaction); ExtractMaster[0].KeyCount = ExtractTable.Rows.Count; ExtractTable.ThrowAwayAfterSubmitChanges = true; // no need to keep data as this increases speed significantly MExtractAccess.SubmitChanges(ExtractTable, Transaction); MExtractMasterAccess.SubmitChanges(ExtractMaster, Transaction); } }); AKeyCount = RecordCounter; AIgnoredKeyList = ignoredKeyList; }
/// <summary> /// save the changes on the screen (code is copied from auto-generated code) /// </summary> /// <returns></returns> public bool SaveChanges() { FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs()); if (FPetraUtilsObject.VerificationResultCollection.Count == 0) { foreach (DataRow InspectDR in FMainDS.MExtractMaster.Rows) { InspectDR.EndEdit(); } if (!FPetraUtilsObject.HasChanges) { return(true); } else { FPetraUtilsObject.WriteToStatusBar("Saving data..."); this.Cursor = Cursors.WaitCursor; TSubmitChangesResult SubmissionResult; MExtractMasterTable SubmitDT = new MExtractMasterTable(); if (FMainDS.MExtractMaster.GetChangesTyped() != null) { SubmitDT.Merge(FMainDS.MExtractMaster.GetChangesTyped()); } else { // There is nothing to be saved. // Update UI FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved.")); this.Cursor = Cursors.Default; // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); return(true); } // Submit changes to the PETRAServer try { SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtractMaster (ref SubmitDT); } catch (System.Net.Sockets.SocketException) { FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); this.Cursor = Cursors.Default; MessageBox.Show("The PETRA Server cannot be reached! Data cannot be saved!", "No Server response", MessageBoxButtons.OK, MessageBoxIcon.Stop); bool ReturnValue = false; // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(ReturnValue); } /* TODO ESecurityDBTableAccessDeniedException * catch (ESecurityDBTableAccessDeniedException Exp) * { * FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); * this.Cursor = Cursors.Default; * // TODO TMessages.MsgSecurityException(Exp, this.GetType()); * bool ReturnValue = false; * // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); * return ReturnValue; * } */ catch (EDBConcurrencyException) { FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); this.Cursor = Cursors.Default; // TODO TMessages.MsgDBConcurrencyException(Exp, this.GetType()); bool ReturnValue = false; // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(ReturnValue); } catch (Exception exp) { FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); this.Cursor = Cursors.Default; TLogging.Log( Catalog.GetString( "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(), TLoggingType.ToLogfile); MessageBox.Show( Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + "For details see the log file: " + TLogging.GetLogFileName(), "Server connection error", MessageBoxButtons.OK, MessageBoxIcon.Stop); // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(false); } switch (SubmissionResult) { case TSubmitChangesResult.scrOK: // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server FMainDS.MExtractMaster.AcceptChanges(); // Merge back with data from the Server (eg. for getting Sequence values) FMainDS.MExtractMaster.Merge(SubmitDT, false); // need to accept the new modification ID FMainDS.MExtractMaster.AcceptChanges(); // Update UI FPetraUtilsObject.WriteToStatusBar("Data successfully saved."); this.Cursor = Cursors.Default; // TODO EnableSave(false); // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); SetPrimaryKeyReadOnly(true); // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(true); case TSubmitChangesResult.scrError: // TODO scrError this.Cursor = Cursors.Default; break; case TSubmitChangesResult.scrNothingToBeSaved: // TODO scrNothingToBeSaved this.Cursor = Cursors.Default; return(true); case TSubmitChangesResult.scrInfoNeeded: // TODO scrInfoNeeded this.Cursor = Cursors.Default; break; } } } return(false); }
public static MExtractMasterTable GetAllExtractHeaders(String AExtractNameFilter, String AExtractDescFilter, Boolean AAllUsers, String AUserCreated, String AUserModified, DateTime? ADateCreatedFrom, DateTime? ADateCreatedTo, DateTime? ADateModifiedFrom, DateTime ? ADateModifiedTo) { // if no filter is set then call method to get all extracts if ((AExtractNameFilter.Length == 0) && (AExtractDescFilter.Length == 0) && AAllUsers && ADateCreatedFrom.HasValue && ADateCreatedTo.HasValue && ADateModifiedFrom.HasValue && ADateModifiedTo.HasValue) { return GetAllExtractHeaders(); } MExtractMasterTable ExtractMasterDT = new MExtractMasterTable(); string SqlStmt; List <OdbcParameter>SqlParameterList = new List <OdbcParameter>(); // prepare extract name filter field if (AExtractNameFilter == "*") { AExtractNameFilter = ""; } else if (AExtractNameFilter.EndsWith("*")) { AExtractNameFilter = AExtractNameFilter.Substring(0, AExtractNameFilter.Length - 1); } AExtractNameFilter = AExtractNameFilter.Replace('*', '%') + "%"; // Use a direct sql statement rather than db access classes to improve performance as otherwise // we would need an extra query for each row of an extract to retrieve partner name and class SqlStmt = "SELECT * FROM " + MExtractMasterTable.GetTableDBName() + " WHERE pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetExtractNameDBName() + " LIKE '" + AExtractNameFilter + "'"; if (AExtractDescFilter.Length > 0) { AExtractDescFilter = AExtractDescFilter.Replace('*', '%'); SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetExtractDescDBName() + " LIKE '" + AExtractDescFilter + "'"; } if (AUserCreated.Length > 0) { SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetCreatedByDBName() + " = '" + AUserCreated + "'"; } if (AUserModified.Length > 0) { SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetModifiedByDBName() + " = '" + AUserModified + "'"; } if (ADateCreatedFrom.HasValue) { SqlParameterList.Add(new OdbcParameter("DateCreatedFrom", OdbcType.Date) { Value = ADateCreatedFrom }); SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetDateCreatedDBName() + " >= ?"; } if (ADateCreatedTo.HasValue) { // Add 1 day to date as timestamp is usually set to 00:00:00 and therefore to beginning of day. // Instead add 1 day and make sure that date queried is < (not <=). ADateCreatedTo = ADateCreatedTo.Value.AddDays(1); SqlParameterList.Add(new OdbcParameter("DateCreatedTo", OdbcType.Date) { Value = ADateCreatedTo }); SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetDateCreatedDBName() + " < ?"; } if (ADateModifiedFrom.HasValue) { SqlParameterList.Add(new OdbcParameter("DateModifiedFrom", OdbcType.Date) { Value = ADateModifiedFrom }); SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetDateModifiedDBName() + " >= ?"; } if (ADateModifiedTo.HasValue) { // Add 1 day to date as timestamp is usually set to 00:00:00 and therefore to beginning of day. // Instead add 1 day and make sure that date queried is < (not <=). ADateModifiedTo = ADateModifiedTo.Value.AddDays(1); SqlParameterList.Add(new OdbcParameter("DateModifiedTo", OdbcType.Date) { Value = ADateModifiedTo }); SqlStmt += " AND pub_" + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetDateModifiedDBName() + " < ?"; } TDBTransaction Transaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction, delegate { DBAccess.GDBAccessObj.SelectDT(ExtractMasterDT, SqlStmt, Transaction, SqlParameterList.ToArray(), -1, -1); }); return ExtractMasterDT; }
public static Boolean ExtractExists(String AExtractName) { MExtractMasterTable TemplateTable; MExtractMasterRow TemplateRow; Boolean ReturnValue = true; TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); TemplateTable = new MExtractMasterTable(); TemplateRow = TemplateTable.NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, Transaction) == 0) { ReturnValue = false; } DBAccess.GDBAccessObj.CommitTransaction(); return ReturnValue; }
/// <summary> /// save the changes on the screen (code is copied from auto-generated code) /// </summary> /// <returns></returns> public bool SaveChanges() { bool ReturnValue = false; FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs()); if (ValidateAllData(false, Common.Verification.TErrorProcessingMode.Epm_IgnoreNonCritical)) { foreach (DataRow InspectDR in FMainDS.MExtractMaster.Rows) { InspectDR.EndEdit(); } if (!FPetraUtilsObject.HasChanges) { return(true); } else { FPetraUtilsObject.WriteToStatusBar("Saving data..."); this.Cursor = Cursors.WaitCursor; TSubmitChangesResult SubmissionResult; MExtractMasterTable SubmitDT = new MExtractMasterTable(); if (FMainDS.MExtractMaster.GetChangesTyped() != null) { SubmitDT.Merge(FMainDS.MExtractMaster.GetChangesTyped()); } else { // There is nothing to be saved. // Update UI FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved.")); this.Cursor = Cursors.Default; // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); return(true); } // Submit changes to the PETRAServer try { SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtractMaster (ref SubmitDT); } catch (ESecurityDBTableAccessDeniedException Exp) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException); this.Cursor = Cursors.Default; TMessages.MsgSecurityException(Exp, this.GetType()); ReturnValue = false; FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(ReturnValue); } catch (EDBConcurrencyException Exp) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException); this.Cursor = Cursors.Default; TMessages.MsgDBConcurrencyException(Exp, this.GetType()); ReturnValue = false; FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(ReturnValue); } catch (Exception) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException); this.Cursor = Cursors.Default; FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); throw; } switch (SubmissionResult) { case TSubmitChangesResult.scrOK: // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server FMainDS.MExtractMaster.AcceptChanges(); // Merge back with data from the Server (eg. for getting Sequence values) FMainDS.MExtractMaster.Merge(SubmitDT, false); // need to accept the new modification ID FMainDS.MExtractMaster.AcceptChanges(); // Update UI FPetraUtilsObject.WriteToStatusBar("Data successfully saved."); this.Cursor = Cursors.Default; // TODO EnableSave(false); // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); SetPrimaryKeyReadOnly(true); // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return(true); case TSubmitChangesResult.scrError: // TODO scrError this.Cursor = Cursors.Default; break; case TSubmitChangesResult.scrNothingToBeSaved: // TODO scrNothingToBeSaved this.Cursor = Cursors.Default; return(true); case TSubmitChangesResult.scrInfoNeeded: // TODO scrInfoNeeded this.Cursor = Cursors.Default; break; } } } return(false); }
public static TSubmitChangesResult SaveExtractMaster(ref MExtractMasterTable AExtractMasterTable) { int ExtractId; int CountRecords; MExtractMasterRow Row; MExtractMasterTable ExtractMasterTable = AExtractMasterTable; if (AExtractMasterTable != null) { TDBTransaction Transaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { /* Cascading delete for deleted rows. Once the cascading delete has been done the row * needs to be removed from the table with AcceptChanges as otherwise the later call * to SubmitChanges will complain about those rows that have already been deleted in * the database. * Use a loop to run through the table in reverse Order (Index--) so that the rows * can actually be removed from the table without affecting the access throug Index. */ CountRecords = ExtractMasterTable.Rows.Count; for (int Index = CountRecords - 1; Index >= 0; Index--) { Row = (MExtractMasterRow)ExtractMasterTable.Rows[Index]; if (Row.RowState == DataRowState.Deleted) { ExtractId = Convert.ToInt32(Row[MExtractMasterTable.GetExtractIdDBName(), DataRowVersion.Original]); MExtractMasterCascading.DeleteByPrimaryKey(ExtractId, Transaction, true); // accept changes: this actually removes row from table Row.AcceptChanges(); } } // now submit all changes to extract master table MExtractMasterAccess.SubmitChanges(ExtractMasterTable, Transaction); SubmissionOK = true; }); AExtractMasterTable = ExtractMasterTable; } return TSubmitChangesResult.scrOK; }
public static Int32 GetExtractId(String AExtractName) { MExtractMasterTable TemplateTable; MExtractMasterRow TemplateRow; MExtractMasterTable ResultTable; MExtractMasterRow ResultRow; Int32 ReturnValue = -1; TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); TemplateTable = new MExtractMasterTable(); TemplateRow = TemplateTable.NewRowTyped(false); TemplateRow.ExtractName = AExtractName; ResultTable = MExtractMasterAccess.LoadUsingTemplate(TemplateRow, null, Transaction); if (ResultTable.Count > 0) { ResultRow = (MExtractMasterRow)ResultTable.Rows[0]; ReturnValue = ResultRow.ExtractId; } DBAccess.GDBAccessObj.RollbackTransaction(); return ReturnValue; }
public static Boolean ExtractExists(String AExtractName) { MExtractMasterTable TemplateTable; MExtractMasterRow TemplateRow; Boolean ReturnValue = true; TDBTransaction Transaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction, delegate { TemplateTable = new MExtractMasterTable(); TemplateRow = TemplateTable.NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, Transaction) == 0) { ReturnValue = false; } }); return ReturnValue; }
/// <summary> /// Checks whether an Extract with a certain Extract Name exists. /// </summary> /// <param name="AExtractName">Name of the Extract to check for.</param> /// <returns>True if an Extract with the specified Extract Name exists, /// otherwise false.</returns> public static bool CheckExtractExists(string AExtractName) { TDBTransaction ReadTransaction; Boolean NewTransaction; Boolean ReturnValue = false; MExtractMasterRow TemplateRow; ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); // Check if there is already an extract with the extract name try { TemplateRow = new MExtractMasterTable().NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, ReadTransaction) > 0) { ReturnValue = true; } if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TExtractsHandling.CheckExtractExists: committed own transaction!"); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the checking whether an Extract exists:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } return ReturnValue; }
/// <summary> /// Open Dialog to find extracts to be added list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddExtractToList(System.Object sender, EventArgs e) { TFrmExtractFindDialog ExtractFindDialog = new TFrmExtractFindDialog(this.ParentForm); MExtractMasterTable ExtractMasterTable = new MExtractMasterTable(); MExtractMasterRow NewRow; // let the user select base extract ExtractFindDialog.AllowMultipleSelect = true; ExtractFindDialog.ShowDialog(true); // get data for selected base extract ExtractFindDialog.GetResult(ref ExtractMasterTable); ExtractFindDialog.Dispose(); // only continue if an extract was selected foreach (MExtractMasterRow Row in ExtractMasterTable.Rows) { if (!FExtractMasterTable.Rows.Contains(new object[] { Row.ExtractId })) { NewRow = FExtractMasterTable.NewRowTyped(); NewRow.ExtractId = Row.ExtractId; NewRow.ExtractName = Row.ExtractName; NewRow.ExtractDesc = Row.ExtractDesc; NewRow.KeyCount = Row.KeyCount; NewRow.CreatedBy = Row.CreatedBy; NewRow.DateCreated = Row.DateCreated; FExtractMasterTable.Rows.Add(NewRow); grdExtracts.SelectRowInGrid(1); btnOK.Select(); btnRemove.Enabled = true; } } }
public static Boolean GetExtractDescription(String AExtractName, out String AExtractDescription) { TDBTransaction ReadTransaction; Boolean NewTransaction; Boolean ReturnValue = false; AExtractDescription = "Can not retrieve description"; TLogging.LogAtLevel(9, "TPartnerServerLookups.GetExtractDescription called!"); MExtractMasterTable ExtractMasterDT = new MExtractMasterTable(); ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); // Load data MExtractMasterTable TemplateExtractDT = new MExtractMasterTable(); MExtractMasterRow TemplateRow = TemplateExtractDT.NewRowTyped(false); TemplateRow.ExtractName = AExtractName; try { ExtractMasterDT = MExtractMasterAccess.LoadUsingTemplate(TemplateRow, ReadTransaction); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TPartnerServerLookups.GetExtractDescription: committed own transaction."); } } if (ExtractMasterDT.Rows.Count < 1) { ReturnValue = false; TLogging.LogAtLevel(7, "TPartnerServerLookups.TPartnerServerLookups.GetExtractDescription: m_extract_master DB Table is empty"); } else { MExtractMasterRow ExtractRow = ExtractMasterDT.Rows[0] as MExtractMasterRow; if (ExtractRow != null) { AExtractDescription = ExtractRow.ExtractDesc; ReturnValue = true; } } return ReturnValue; }
/// <summary> /// Creates a new extract with the given extract name and extract description in the /// m_extract_master data table. The Extract Id and the Extract Name must both be /// unique in the Petra Database. /// </summary> /// <param name="AExtractName">Name of the Extract to be created.</param> /// <param name="AExtractDescription">Description of the Extract to be created.</param> /// <param name="ANewExtractId">Extract Id of the created Extract, or -1 if the /// creation of the Extract was not successful.</param> /// <param name="AExtractAlreadyExists">True if there is already an extract with /// the given name, otherwise false.</param> /// <returns>True if the new Extract was created, otherwise false.</returns> public static bool CreateNewExtract(String AExtractName, String AExtractDescription, out Int32 ANewExtractId, out Boolean AExtractAlreadyExists) { TDBTransaction WriteTransaction; Boolean NewTransaction; Boolean ReturnValue = false; ANewExtractId = -1; AExtractAlreadyExists = false; TLogging.LogAtLevel(9, "CreateNewExtract called!"); WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { // Check if there is already an extract with the extract name if (!CheckExtractExists(AExtractName)) { // The extract name is unique. So create the new extract... MExtractMasterTable NewExtractMasterDT = new MExtractMasterTable(); MExtractMasterRow TemplateRow = (MExtractMasterRow)NewExtractMasterDT.NewRowTyped(true); TemplateRow.ExtractName = AExtractName; TemplateRow.ExtractDesc = AExtractDescription; TemplateRow.ExtractId = -1; // initialize id negative so sequence can be used NewExtractMasterDT.Rows.Add(TemplateRow); MExtractMasterAccess.SubmitChanges(NewExtractMasterDT, WriteTransaction); // Get the Extract Id TemplateRow = (MExtractMasterRow)NewExtractMasterDT.Rows[0]; ANewExtractId = TemplateRow.ExtractId; ReturnValue = true; } else { AExtractAlreadyExists = true; ReturnValue = false; } if (ReturnValue && NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } else if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the creation of a new Extract:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } return ReturnValue; }
private void InitializeManualCode() { // show this dialog in center of screen this.StartPosition = FormStartPosition.CenterScreen; // enable grid to react to insert and delete keyboard keys grdExtracts.InsertKeyPressed += new TKeyPressedEventHandler(grdExtracts_InsertKeyPressed); grdExtracts.DeleteKeyPressed += new TKeyPressedEventHandler(grdExtracts_DeleteKeyPressed); FExtractMasterTable = new MExtractMasterTable(); grdExtracts.Columns.Clear(); grdExtracts.AddTextColumn("Extract Name", FExtractMasterTable.ColumnExtractName); grdExtracts.AddTextColumn("Created By", FExtractMasterTable.ColumnCreatedBy); grdExtracts.AddTextColumn("Key Count", FExtractMasterTable.ColumnKeyCount); grdExtracts.AddTextColumn("Description", FExtractMasterTable.ColumnExtractDesc); grdExtracts.AddDateColumn("Created Date", FExtractMasterTable.ColumnDateCreated); DataView myDataView = FExtractMasterTable.DefaultView; myDataView.AllowNew = false; grdExtracts.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView); btnRemove.Enabled = false; // manually configure tab index pnlLeftButtons.TabIndex = pnlRightButtons.TabIndex + 1; pnlGrid.TabIndex = pnlTop.TabIndex + 1; }
/// <summary> /// save the changes on the screen (code is copied from auto-generated code) /// </summary> /// <returns></returns> public bool SaveChanges() { FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs()); if (FPetraUtilsObject.VerificationResultCollection.Count == 0) { foreach (DataRow InspectDR in FMainDS.MExtractMaster.Rows) { InspectDR.EndEdit(); } if (!FPetraUtilsObject.HasChanges) { return true; } else { FPetraUtilsObject.WriteToStatusBar("Saving data..."); this.Cursor = Cursors.WaitCursor; TSubmitChangesResult SubmissionResult; MExtractMasterTable SubmitDT = new MExtractMasterTable(); if (FMainDS.MExtractMaster.GetChangesTyped() != null) { SubmitDT.Merge(FMainDS.MExtractMaster.GetChangesTyped()); } else { // There is nothing to be saved. // Update UI FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved.")); this.Cursor = Cursors.Default; // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); return true; } // Submit changes to the PETRAServer try { SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtractMaster (ref SubmitDT); } catch (System.Net.Sockets.SocketException) { FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); this.Cursor = Cursors.Default; MessageBox.Show("The PETRA Server cannot be reached! Data cannot be saved!", "No Server response", MessageBoxButtons.OK, MessageBoxIcon.Stop); bool ReturnValue = false; // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return ReturnValue; } /* TODO ESecurityDBTableAccessDeniedException * catch (ESecurityDBTableAccessDeniedException Exp) * { * FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); * this.Cursor = Cursors.Default; * // TODO TMessages.MsgSecurityException(Exp, this.GetType()); * bool ReturnValue = false; * // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); * return ReturnValue; * } */ catch (EDBConcurrencyException) { FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); this.Cursor = Cursors.Default; // TODO TMessages.MsgDBConcurrencyException(Exp, this.GetType()); bool ReturnValue = false; // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return ReturnValue; } catch (Exception exp) { FPetraUtilsObject.WriteToStatusBar("Data could not be saved!"); this.Cursor = Cursors.Default; TLogging.Log( Catalog.GetString( "An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + exp.ToString(), TLoggingType.ToLogfile); MessageBox.Show( Catalog.GetString("An error occurred while trying to connect to the OpenPetra Server!") + Environment.NewLine + "For details see the log file: " + TLogging.GetLogFileName(), "Server connection error", MessageBoxButtons.OK, MessageBoxIcon.Stop); // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return false; } switch (SubmissionResult) { case TSubmitChangesResult.scrOK: // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server FMainDS.MExtractMaster.AcceptChanges(); // Merge back with data from the Server (eg. for getting Sequence values) FMainDS.MExtractMaster.Merge(SubmitDT, false); // need to accept the new modification ID FMainDS.MExtractMaster.AcceptChanges(); // Update UI FPetraUtilsObject.WriteToStatusBar("Data successfully saved."); this.Cursor = Cursors.Default; // TODO EnableSave(false); // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); SetPrimaryKeyReadOnly(true); // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return true; case TSubmitChangesResult.scrError: // TODO scrError this.Cursor = Cursors.Default; break; case TSubmitChangesResult.scrNothingToBeSaved: // TODO scrNothingToBeSaved this.Cursor = Cursors.Default; return true; case TSubmitChangesResult.scrInfoNeeded: // TODO scrInfoNeeded this.Cursor = Cursors.Default; break; } } } return false; }
/// <summary> /// save the changes on the screen (code is copied from auto-generated code) /// </summary> /// <returns></returns> public bool SaveChanges() { bool ReturnValue = false; FPetraUtilsObject.OnDataSavingStart(this, new System.EventArgs()); if (ValidateAllData(false, Common.Verification.TErrorProcessingMode.Epm_IgnoreNonCritical)) { foreach (DataRow InspectDR in FMainDS.MExtractMaster.Rows) { InspectDR.EndEdit(); } if (!FPetraUtilsObject.HasChanges) { return true; } else { FPetraUtilsObject.WriteToStatusBar("Saving data..."); this.Cursor = Cursors.WaitCursor; TSubmitChangesResult SubmissionResult; MExtractMasterTable SubmitDT = new MExtractMasterTable(); if (FMainDS.MExtractMaster.GetChangesTyped() != null) { SubmitDT.Merge(FMainDS.MExtractMaster.GetChangesTyped()); } else { // There is nothing to be saved. // Update UI FPetraUtilsObject.WriteToStatusBar(Catalog.GetString("There is nothing to be saved.")); this.Cursor = Cursors.Default; // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); return true; } // Submit changes to the PETRAServer try { SubmissionResult = TRemote.MPartner.Partner.WebConnectors.SaveExtractMaster (ref SubmitDT); } catch (ESecurityDBTableAccessDeniedException Exp) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException); this.Cursor = Cursors.Default; TMessages.MsgSecurityException(Exp, this.GetType()); ReturnValue = false; FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return ReturnValue; } catch (EDBConcurrencyException Exp) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException); this.Cursor = Cursors.Default; TMessages.MsgDBConcurrencyException(Exp, this.GetType()); ReturnValue = false; FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return ReturnValue; } catch (Exception) { FPetraUtilsObject.WriteToStatusBar(MCommonResourcestrings.StrSavingDataException); this.Cursor = Cursors.Default; FPetraUtilsObject.OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); throw; } switch (SubmissionResult) { case TSubmitChangesResult.scrOK: // Call AcceptChanges to get rid now of any deleted columns before we Merge with the result from the Server FMainDS.MExtractMaster.AcceptChanges(); // Merge back with data from the Server (eg. for getting Sequence values) FMainDS.MExtractMaster.Merge(SubmitDT, false); // need to accept the new modification ID FMainDS.MExtractMaster.AcceptChanges(); // Update UI FPetraUtilsObject.WriteToStatusBar("Data successfully saved."); this.Cursor = Cursors.Default; // TODO EnableSave(false); // We don't have unsaved changes anymore FPetraUtilsObject.DisableSaveButton(); SetPrimaryKeyReadOnly(true); // TODO OnDataSaved(this, new TDataSavedEventArgs(ReturnValue)); return true; case TSubmitChangesResult.scrError: // TODO scrError this.Cursor = Cursors.Default; break; case TSubmitChangesResult.scrNothingToBeSaved: // TODO scrNothingToBeSaved this.Cursor = Cursors.Default; return true; case TSubmitChangesResult.scrInfoNeeded: // TODO scrInfoNeeded this.Cursor = Cursors.Default; break; } } } return false; }
/// <summary> /// reload extract list when search button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RefreshExtractList(System.Object sender, EventArgs e) { bool AllUsers = true; String CreatedByUser = ""; String ModifiedByUser = ""; DateTime? DateCreatedFrom = null; DateTime? DateCreatedTo = null; DateTime? DateModifiedFrom = null; DateTime? DateModifiedTo = null; string CheckedMember = FCheckedColumnName; string IdMember = MExtractMasterTable.GetExtractIdDBName(); string NameMember = MExtractMasterTable.GetExtractNameDBName(); string DescriptionMember = MExtractMasterTable.GetExtractDescDBName(); string DeletableMember = MExtractMasterTable.GetDeletableDBName(); string KeyCountMember = MExtractMasterTable.GetKeyCountDBName(); string CreatedByMember = MExtractMasterTable.GetCreatedByDBName(); string DateCreatedMember = MExtractMasterTable.GetDateCreatedDBName(); if (cmbUserCreated.GetSelectedString().Length > 0) { AllUsers = false; CreatedByUser = cmbUserCreated.GetSelectedString(); } if (cmbUserModified.GetSelectedString().Length > 0) { AllUsers = false; ModifiedByUser = cmbUserModified.GetSelectedString(); } if (dtpCreatedFrom.Text.Length > 0) { DateCreatedFrom = dtpCreatedFrom.Date; } if (dtpCreatedTo.Text.Length > 0) { DateCreatedTo = dtpCreatedTo.Date; } if (dtpModifiedFrom.Text.Length > 0) { DateModifiedFrom = dtpModifiedFrom.Date; } if (dtpModifiedTo.Text.Length > 0) { DateModifiedTo = dtpModifiedTo.Date; } FExtractMasterTable = TRemote.MPartner.Partner.WebConnectors.GetAllExtractHeaders(txtExtractName.Text, txtExtractDesc.Text, AllUsers, CreatedByUser, ModifiedByUser, DateCreatedFrom, DateCreatedTo, DateModifiedFrom, DateModifiedTo); if (FExtractMasterTable != null) { DataView view = new DataView(FExtractMasterTable); FDataTable = view.ToTable(true, new string[] { IdMember, NameMember, DescriptionMember, DeletableMember, KeyCountMember, CreatedByMember, DateCreatedMember }); FDataTable.Columns.Add(new DataColumn(CheckedMember, typeof(bool))); clbDetails.Columns.Clear(); if (FAllowMultipleSelect) { clbDetails.AddCheckBoxColumn("Select", FDataTable.Columns[FCheckedColumnName], 17, false); } clbDetails.AddTextColumn("Extract Name", FDataTable.Columns[NameMember], 200); clbDetails.AddCheckBoxColumn("Deletable", FDataTable.Columns[DeletableMember], 120); clbDetails.AddTextColumn("Key Count", FDataTable.Columns[KeyCountMember], 80); clbDetails.AddTextColumn("Description", FDataTable.Columns[DescriptionMember], 300); clbDetails.DataBindGrid(FDataTable, NameMember, CheckedMember, NameMember, false, true, false); clbDetails.SetCheckedStringList(""); } PrepareButtons(); }
public static bool GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable) { // TODO: check access permissions for the current user bool NewTransaction = false; TDBTransaction ReadTransaction; TTypedDataTable tempTable = null; try { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, out NewTransaction); // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { tempTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { tempTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { tempTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { tempTable = ACurrencyAccess.LoadAll(ReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { tempTable = ADailyExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { tempTable = ACorporateExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { tempTable = ACurrencyLanguageAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { tempTable = AFeesPayableAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { tempTable = AFeesReceivableAccess.LoadAll(ReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { tempTable = AAnalysisTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { tempTable = AGiftBatchAccess.LoadAll(ReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { tempTable = AJournalAccess.LoadAll(ReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { tempTable = ALedgerAccess.LoadAll(ReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { tempTable = MExtractMasterAccess.LoadAll(ReadTransaction); } else { tempTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { tempTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { tempTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { tempTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { tempTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { tempTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { tempTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { tempTable = PInternationalPostalTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { tempTable = PtApplicationTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { tempTable = PMailingAccess.LoadAll(ReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { tempTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { tempTable = PmDocumentTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { tempTable = SGroupAccess.LoadAll(ReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } } catch (Exception Exp) { DBAccess.GDBAccessObj.RollbackTransaction(); TLogging.Log("TCommonDataReader.GetData exception: " + Exp.ToString(), TLoggingType.ToLogfile); TLogging.Log(Exp.StackTrace, TLoggingType.ToLogfile); throw; } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TCommonDataReader.GetData: committed own transaction."); } } // Accept row changes here so that the Client gets 'unmodified' rows tempTable.AcceptChanges(); // return the table AResultTable = tempTable; return(true); }
/// <summary> /// Creates a new extract with the given extract name and extract description in the /// m_extract_master data table. The Extract Id and the Extract Name must both be /// unique in the Petra Database. /// </summary> /// <param name="AExtractName">Name of the Extract to be created.</param> /// <param name="AExtractDescription">Description of the Extract to be created.</param> /// <param name="ANewExtractId">Extract Id of the created Extract, or -1 if the /// creation of the Extract was not successful.</param> /// <param name="AExtractAlreadyExists">True if there is already an extract with /// the given name, otherwise false.</param> /// <returns>True if the new Extract was created, otherwise false.</returns> public static bool CreateNewExtract(String AExtractName, String AExtractDescription, out Int32 ANewExtractId, out Boolean AExtractAlreadyExists) { TDBTransaction WriteTransaction; Boolean NewTransaction; Boolean ReturnValue = false; ANewExtractId = -1; AExtractAlreadyExists = false; TLogging.LogAtLevel(9, "CreateNewExtract called!"); WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { // Check if there is already an extract with the extract name if (!CheckExtractExists(AExtractName)) { // The extract name is unique. So create the new extract... MExtractMasterTable NewExtractMasterDT = new MExtractMasterTable(); MExtractMasterRow TemplateRow = (MExtractMasterRow)NewExtractMasterDT.NewRowTyped(true); TemplateRow.ExtractName = AExtractName; TemplateRow.ExtractDesc = AExtractDescription; TemplateRow.ExtractId = -1; // initialize id negative so sequence can be used NewExtractMasterDT.Rows.Add(TemplateRow); MExtractMasterAccess.SubmitChanges(NewExtractMasterDT, WriteTransaction); // Get the Extract Id TemplateRow = (MExtractMasterRow)NewExtractMasterDT.Rows[0]; ANewExtractId = TemplateRow.ExtractId; ReturnValue = true; } else { AExtractAlreadyExists = true; ReturnValue = false; } if (ReturnValue && NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } else if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured during the creation of a new Extract:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } return(ReturnValue); }
/// <summary> /// Creates a new extract with the given extract name and extract description in the /// m_extract_master data table. The Extract Id and the Extract Name must both be /// unique in the Petra Database. /// </summary> /// <param name="AExtractName">Name of the Extract to be created.</param> /// <param name="AExtractDescription">Description of the Extract to be created.</param> /// <param name="ANewExtractId">Extract Id of the created Extract, or -1 if the /// creation of the Extract was not successful.</param> /// <param name="AExtractAlreadyExists">True if there is already an extract with /// the given name, otherwise false.</param> /// <returns>True if the new Extract was created, otherwise false.</returns> public static bool CreateNewExtract(String AExtractName, String AExtractDescription, out Int32 ANewExtractId, out Boolean AExtractAlreadyExists) { TDBTransaction Transaction = null; Boolean ReturnValue = false; bool SubmissionOK = false; MExtractMasterTable NewExtractMasterDT = null; MExtractMasterRow TemplateRow = null; Boolean ExtractAlreadyExists = false; Int32 NewExtractId = -1; TLogging.LogAtLevel(9, "CreateNewExtract called!"); DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { // Check if there is already an extract with the extract name if (!CheckExtractExists(AExtractName)) { // The extract name is unique. So create the new extract... NewExtractMasterDT = new MExtractMasterTable(); TemplateRow = (MExtractMasterRow)NewExtractMasterDT.NewRowTyped(true); TemplateRow.ExtractName = AExtractName; TemplateRow.ExtractDesc = AExtractDescription; TemplateRow.ExtractId = -1; // initialize id negative so sequence can be used NewExtractMasterDT.Rows.Add(TemplateRow); MExtractMasterAccess.SubmitChanges(NewExtractMasterDT, Transaction); // Get the Extract Id TemplateRow = (MExtractMasterRow)NewExtractMasterDT.Rows[0]; NewExtractId = TemplateRow.ExtractId; SubmissionOK = true; ReturnValue = true; } else { ExtractAlreadyExists = true; ReturnValue = false; } if (ReturnValue) { SubmissionOK = true; } else { SubmissionOK = false; } }); // Get the Extract Id // if (NewExtractMasterDT != null) // { // TemplateRow = (MExtractMasterRow)NewExtractMasterDT.Rows[0]; // ANewExtractId = TemplateRow.ExtractId; // } ANewExtractId = NewExtractId; AExtractAlreadyExists = ExtractAlreadyExists; return(ReturnValue); }
public static bool GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable) { // TODO: check access permissions for the current user TDBTransaction ReadTransaction = null; TTypedDataTable tempTable = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { tempTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { tempTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { tempTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { tempTable = ACurrencyAccess.LoadAll(ReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { tempTable = ADailyExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { tempTable = ACorporateExchangeRateAccess.LoadAll(ReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { tempTable = ACurrencyLanguageAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { tempTable = AFeesPayableAccess.LoadAll(ReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { tempTable = AFeesReceivableAccess.LoadAll(ReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { tempTable = AAnalysisTypeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { tempTable = AGiftBatchAccess.LoadAll(ReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { tempTable = AJournalAccess.LoadAll(ReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { tempTable = ALedgerAccess.LoadAll(ReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { tempTable = MExtractMasterAccess.LoadAll(ReadTransaction); } else { tempTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { tempTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { tempTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { tempTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { tempTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { tempTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { tempTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PFormTable.GetTableDBName()) { string[] columns = TTypedDataTable.GetColumnStringList(PFormTable.TableId); StringCollection fieldList = new StringCollection(); for (int i = 0; i < columns.Length; i++) { // Do not load the template document - we don't display it and it is big! if (columns[i] != PFormTable.GetTemplateDocumentDBName()) { fieldList.Add(columns[i]); } } tempTable = PFormAccess.LoadAll(fieldList, ReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { tempTable = PInternationalPostalTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { tempTable = PtApplicationTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { tempTable = PFormalityAccess.LoadAll(ReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { tempTable = PMailingAccess.LoadAll(ReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { tempTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, ReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { tempTable = PmDocumentTypeAccess.LoadAll(ReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { tempTable = SGroupAccess.LoadAll(ReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } }); // Accept row changes here so that the Client gets 'unmodified' rows tempTable.AcceptChanges(); // return the table AResultTable = tempTable; return(true); }
/// <summary> /// This report considers gifts given between the two specified dates, and can include all gifts or, if /// selected, those to a particular motivation, motivation detail or recipient. For the defined set of gifts /// and its total value, the donors are sorted into a list, starting with those who gave most, and showing /// the percentage that their gifts contributed to the total received (for this motivation or recipient, if /// specified) and the cumulative percentage, moving down the list starting with the top donor. /// </summary> /// <param name="ATotalAmount">Pre calculated value of the total gifts given with these parameters</param> /// <param name="ATopXPercent">Upper limit of the percentage to show in the report</param> /// <param name="ABottomXPercent">Lower limit of the percentage to show in the report</param> /// <param name="AExtract">true to use only partners from an extract</param> /// <param name="AExtractName">extract name</param> /// <param name="AStartDate">Start date of the gifts given</param> /// <param name="AEndDate">End date of the gifts given</param> /// <param name="ARecipientKey">Partner key of a specific recipient. If 0 then use all recipients</param> /// <param name="AMotivationGroup">Limit gifts to this motivation group. If % use all motivation groups</param> /// <param name="AMotivationDetail">Limit gifts to this motivation detail. If % use all motivation details</param> /// <returns></returns> private bool MakeTopDonor(decimal ATotalAmount, decimal ATopXPercent, decimal ABottomXPercent, bool AExtract, String AExtractName, DateTime AStartDate, DateTime AEndDate, Int64 ARecipientKey, String AMotivationGroup, String AMotivationDetail) { Int64 LedgerNumber = situation.GetParameters().Get("param_ledger_number_i").ToInt64(); String CurrencyType = situation.GetParameters().Get("param_currency").ToString(); StringBuilder SqlString = new StringBuilder(); SqlString.Append("SELECT DISTINCT "); SqlString.Append("gift.p_donor_key_n AS DonorKey, "); SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName() + " AS ShortName, "); SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerClassDBName() + " AS PartnerClass, "); if (CurrencyType == "Base") { SqlString.Append("SUM(detail." + AGiftDetailTable.GetGiftAmountDBName() + ") AS Amount "); } else { SqlString.Append("SUM(detail." + AGiftDetailTable.GetGiftAmountIntlDBName() + ") AS Amount "); } SqlString.Append( " FROM " + AGiftTable.GetTableDBName() + " as gift, " + AGiftDetailTable.GetTableDBName() + " as detail, " + PPartnerTable.GetTableDBName() + ", " + AGiftBatchTable.GetTableDBName() + " "); if (AExtract) { SqlString.Append(", " + MExtractTable.GetTableDBName() + ", " + MExtractMasterTable.GetTableDBName()); SqlString.Append( " WHERE gift." + AGiftTable.GetDonorKeyDBName() + " = " + MExtractTable.GetTableDBName() + "." + MExtractTable.GetPartnerKeyDBName()); SqlString.Append( " AND " + MExtractTable.GetTableDBName() + "." + MExtractTable.GetExtractIdDBName() + " = " + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetExtractIdDBName()); SqlString.Append(" AND " + MExtractMasterTable.GetTableDBName() + "." + MExtractMasterTable.GetExtractNameDBName() + " = '"); SqlString.Append(AExtractName); SqlString.Append("' AND "); } else { SqlString.Append(" WHERE "); } SqlString.Append(" detail." + AGiftDetailTable.GetLedgerNumberDBName() + " = gift." + AGiftTable.GetLedgerNumberDBName()); SqlString.Append(" AND detail." + AGiftDetailTable.GetBatchNumberDBName() + " = gift." + AGiftTable.GetBatchNumberDBName()); SqlString.Append( " AND detail." + AGiftDetailTable.GetGiftTransactionNumberDBName() + " = gift." + AGiftTable.GetGiftTransactionNumberDBName()); SqlString.Append(" AND gift." + AGiftTable.GetDateEnteredDBName() + " BETWEEN '"); SqlString.Append(AStartDate.ToString("yyyy-MM-dd")); SqlString.Append("' AND '"); SqlString.Append(AEndDate.ToString("yyyy-MM-dd")); SqlString.Append("' AND gift." + AGiftTable.GetLedgerNumberDBName() + " = "); SqlString.Append(LedgerNumber.ToString()); SqlString.Append(" AND " + AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetLedgerNumberDBName() + " = "); SqlString.Append(LedgerNumber.ToString()); SqlString.Append( " AND " + AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetBatchNumberDBName() + " = gift." + AGiftTable.GetBatchNumberDBName()); SqlString.Append(" AND ( " + AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetBatchStatusDBName() + " = 'Posted' OR "); SqlString.Append(AGiftBatchTable.GetTableDBName() + "." + AGiftBatchTable.GetBatchStatusDBName() + " = 'posted' ) "); SqlString.Append( " AND " + PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerKeyDBName() + " = gift." + AGiftTable.GetDonorKeyDBName()); if (ARecipientKey != 0) { SqlString.Append(" AND detail." + AGiftDetailTable.GetRecipientKeyDBName() + " = "); SqlString.Append(ARecipientKey.ToString()); } if (AMotivationGroup != "%") { SqlString.Append(" AND detail." + AGiftDetailTable.GetMotivationGroupCodeDBName() + " LIKE '"); SqlString.Append(AMotivationGroup); SqlString.Append("' "); } if (AMotivationDetail != "%") { SqlString.Append(" AND detail." + AGiftDetailTable.GetMotivationDetailCodeDBName() + " LIKE '"); SqlString.Append(AMotivationDetail); SqlString.Append("' "); } SqlString.Append(" GROUP BY gift." + AGiftTable.GetDonorKeyDBName() + ", "); SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerShortNameDBName() + ", "); SqlString.Append(PPartnerTable.GetTableDBName() + "." + PPartnerTable.GetPartnerClassDBName()); SqlString.Append(" ORDER BY Amount DESC"); DataTable Table = situation.GetDatabaseConnection().SelectDT(SqlString.ToString(), "table", situation.GetDatabaseConnection().Transaction, new OdbcParameter[] { }); decimal CummulativeAmount = 0; decimal TopAmount = ATotalAmount * ATopXPercent / 100; decimal BottomAmount = ATotalAmount * ABottomXPercent / 100; int NumColumns = 7; int ChildRow = 1; situation.GetResults().Clear(); for (int Counter = 0; Counter < Table.Rows.Count; ++Counter) { decimal CurrentAmount = Convert.ToDecimal(Table.Rows[Counter]["Amount"]); if (CurrentAmount < 0) { continue; } if ((CummulativeAmount <= TopAmount) && (CummulativeAmount >= BottomAmount)) { Int64 DonorKey = Convert.ToInt64(Table.Rows[Counter]["DonorKey"]); String ShortName = (String)Table.Rows[Counter]["ShortName"]; String PartnerClass = (String)Table.Rows[Counter]["PartnerClass"]; CummulativeAmount += CurrentAmount; // Transfer to results TVariant[] Header = new TVariant[NumColumns]; TVariant[] Description = { new TVariant(), new TVariant() }; TVariant[] Columns = new TVariant[NumColumns]; for (int Counter2 = 0; Counter2 < NumColumns; ++Counter2) { Header[Counter2] = new TVariant(); Columns[Counter2] = new TVariant(); } StringBuilder PartnerAddress = new StringBuilder(); PPartnerLocationRow AddressRow; if (Ict.Petra.Server.MReporting.MPartner.TRptUserFunctionsPartner.GetPartnerBestAddressRow(DonorKey, situation, out AddressRow)) { PLocationTable LocationTable = PLocationAccess.LoadByPrimaryKey(AddressRow.SiteKey, AddressRow.LocationKey, situation.GetDatabaseConnection().Transaction); if (LocationTable.Rows.Count > 0) { PLocationRow LocationRow = (PLocationRow)LocationTable.Rows[0]; PartnerAddress.Append(LocationRow.Locality); if (LocationRow.Locality.Length > 0) { PartnerAddress.Append(", "); } PartnerAddress.Append(LocationRow.StreetName); if (PartnerAddress.Length > 0) { PartnerAddress.Append(", "); } PartnerAddress.Append(LocationRow.Address3); if (PartnerAddress.Length > 0) { PartnerAddress.Append(", "); } PartnerAddress.Append(LocationRow.PostalCode); PartnerAddress.Append(" "); PartnerAddress.Append(LocationRow.City); if (LocationRow.County.Length > 0) { PartnerAddress.Append(", "); PartnerAddress.Append(LocationRow.County); } PartnerAddress.Append(", "); PartnerAddress.Append(LocationRow.CountryCode); } } Columns[0] = new TVariant(DonorKey.ToString("0000000000")); Columns[1] = new TVariant(PartnerClass); Columns[2] = new TVariant(ShortName); Columns[3] = new TVariant(CurrentAmount, "-#,##0.00;#,##0.00"); Columns[4] = new TVariant((CurrentAmount * 100 / ATotalAmount), "-#,##0.00;#,##0.00"); Columns[5] = new TVariant((CummulativeAmount * 100 / ATotalAmount), "-#,##0.00;#,##0.00"); Columns[6] = new TVariant(PartnerAddress.ToString()); situation.GetResults().AddRow(0, ChildRow++, true, 2, "", "", false, Header, Description, Columns); } else { CummulativeAmount += CurrentAmount; } } return(true); }
/// <summary> /// Checks whether an Extract with a certain Extract Name exists. /// </summary> /// <param name="AExtractName">Name of the Extract to check for.</param> /// <returns>True if an Extract with the specified Extract Name exists, /// otherwise false.</returns> public static bool CheckExtractExists(string AExtractName) { TDBTransaction Transaction = null; Boolean ReturnValue = false; MExtractMasterRow TemplateRow; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { // Check if there is already an extract with the extract name TemplateRow = new MExtractMasterTable().NewRowTyped(false); TemplateRow.ExtractName = AExtractName; if (MExtractMasterAccess.CountUsingTemplate(TemplateRow, null, Transaction) > 0) { ReturnValue = true; } }); return ReturnValue; }
public static void GetData(string ATablename, TSearchCriteria[] ASearchCriteria, out TTypedDataTable AResultTable, TDBTransaction AReadTransaction) { AResultTable = null; string context = string.Format("GetData {0}", SharedConstants.MODULE_ACCESS_MANAGER); // check access permissions for the current user TModuleAccessManager.CheckUserPermissionsForTable(ATablename, TTablePermissionEnum.eCanRead); // TODO: auto generate if (ATablename == AApSupplierTable.GetTableDBName()) { AResultTable = AApSupplierAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == AApDocumentTable.GetTableDBName()) { AResultTable = AApDocumentAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == ATransactionTypeTable.GetTableDBName()) { AResultTable = ATransactionTypeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == ACurrencyTable.GetTableDBName()) { AResultTable = ACurrencyAccess.LoadAll(AReadTransaction); } else if (ATablename == ADailyExchangeRateTable.GetTableDBName()) { AResultTable = ADailyExchangeRateAccess.LoadAll(AReadTransaction); } else if (ATablename == ACorporateExchangeRateTable.GetTableDBName()) { AResultTable = ACorporateExchangeRateAccess.LoadAll(AReadTransaction); } else if (ATablename == ACurrencyLanguageTable.GetTableDBName()) { AResultTable = ACurrencyLanguageAccess.LoadAll(AReadTransaction); } else if (ATablename == AFeesPayableTable.GetTableDBName()) { AResultTable = AFeesPayableAccess.LoadAll(AReadTransaction); } else if (ATablename == AFeesReceivableTable.GetTableDBName()) { AResultTable = AFeesReceivableAccess.LoadAll(AReadTransaction); } else if (ATablename == AAnalysisTypeTable.GetTableDBName()) { AResultTable = AAnalysisTypeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == AGiftBatchTable.GetTableDBName()) { AResultTable = AGiftBatchAccess.LoadAll(AReadTransaction); } else if (ATablename == AJournalTable.GetTableDBName()) { AResultTable = AJournalAccess.LoadAll(AReadTransaction); } else if (ATablename == ALedgerTable.GetTableDBName()) { AResultTable = ALedgerAccess.LoadAll(AReadTransaction); } else if (ATablename == MExtractMasterTable.GetTableDBName()) { if (ASearchCriteria == null) { AResultTable = MExtractMasterAccess.LoadAll(AReadTransaction); } else { AResultTable = MExtractMasterAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } } else if (ATablename == MExtractTable.GetTableDBName()) { // it does not make sense to load ALL extract rows for all extract masters so search criteria needs to be set if (ASearchCriteria != null) { AResultTable = MExtractAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } } else if (ATablename == PcAttendeeTable.GetTableDBName()) { AResultTable = PcAttendeeAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcConferenceCostTable.GetTableDBName()) { AResultTable = PcConferenceCostAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcEarlyLateTable.GetTableDBName()) { AResultTable = PcEarlyLateAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcSupplementTable.GetTableDBName()) { AResultTable = PcSupplementAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PcDiscountTable.GetTableDBName()) { AResultTable = PcDiscountAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PCountryTable.GetTableDBName()) { AResultTable = PCountryAccess.LoadAll(AReadTransaction); } else if (ATablename == PFormTable.GetTableDBName()) { string[] columns = TTypedDataTable.GetColumnStringList(PFormTable.TableId); StringCollection fieldList = new StringCollection(); for (int i = 0; i < columns.Length; i++) { // Do not load the template document - we don't display it and it is big! if (columns[i] != PFormTable.GetTemplateDocumentDBName()) { fieldList.Add(columns[i]); } } AResultTable = PFormAccess.LoadAll(fieldList, AReadTransaction); } else if (ATablename == PInternationalPostalTypeTable.GetTableDBName()) { AResultTable = PInternationalPostalTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == PtApplicationTypeTable.GetTableDBName()) { AResultTable = PtApplicationTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == PFormalityTable.GetTableDBName()) { AResultTable = PFormalityAccess.LoadAll(AReadTransaction); } else if (ATablename == PMailingTable.GetTableDBName()) { AResultTable = PMailingAccess.LoadAll(AReadTransaction); } else if (ATablename == PPartnerGiftDestinationTable.GetTableDBName()) { AResultTable = PPartnerGiftDestinationAccess.LoadUsingTemplate(ASearchCriteria, AReadTransaction); } else if (ATablename == PmDocumentTypeTable.GetTableDBName()) { AResultTable = PmDocumentTypeAccess.LoadAll(AReadTransaction); } else if (ATablename == SGroupTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions(SharedConstants.PETRAMODULE_SYSADMIN, context); AResultTable = SGroupAccess.LoadAll(AReadTransaction); } else if (ATablename == SSystemDefaultsTable.GetTableDBName()) { TSecurityChecks.CheckUserModulePermissions(SharedConstants.PETRAMODULE_SYSADMIN, context); AResultTable = SSystemDefaultsAccess.LoadAll(AReadTransaction); } else if (ATablename == SSystemDefaultsGuiTable.GetTableDBName()) { AResultTable = SSystemDefaultsGuiAccess.LoadAll(AReadTransaction); } else { throw new Exception("TCommonDataReader.GetData: unknown table " + ATablename); } // Accept row changes here so that the Client gets 'unmodified' rows AResultTable.AcceptChanges(); }
/// <summary> /// Creates a new extract with the given extract name and extract description in the /// m_extract_master data table. The Extract Id and the Extract Name must both be /// unique in the Petra Database. /// </summary> /// <param name="AExtractName">Name of the Extract to be created.</param> /// <param name="AExtractDescription">Description of the Extract to be created.</param> /// <param name="ANewExtractId">Extract Id of the created Extract, or -1 if the /// creation of the Extract was not successful.</param> /// <param name="AExtractAlreadyExists">True if there is already an extract with /// the given name, otherwise false.</param> /// <returns>True if the new Extract was created, otherwise false.</returns> public static bool CreateNewExtract(String AExtractName, String AExtractDescription, out Int32 ANewExtractId, out Boolean AExtractAlreadyExists) { TDBTransaction Transaction = null; Boolean ReturnValue = false; bool SubmissionOK = false; MExtractMasterTable NewExtractMasterDT = null; MExtractMasterRow TemplateRow = null; Boolean ExtractAlreadyExists = false; Int32 NewExtractId = -1; TLogging.LogAtLevel(9, "CreateNewExtract called!"); DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { // Check if there is already an extract with the extract name if (!CheckExtractExists(AExtractName)) { // The extract name is unique. So create the new extract... NewExtractMasterDT = new MExtractMasterTable(); TemplateRow = (MExtractMasterRow)NewExtractMasterDT.NewRowTyped(true); TemplateRow.ExtractName = AExtractName; TemplateRow.ExtractDesc = AExtractDescription; TemplateRow.ExtractId = -1; // initialize id negative so sequence can be used NewExtractMasterDT.Rows.Add(TemplateRow); MExtractMasterAccess.SubmitChanges(NewExtractMasterDT, Transaction); // Get the Extract Id TemplateRow = (MExtractMasterRow)NewExtractMasterDT.Rows[0]; NewExtractId = TemplateRow.ExtractId; SubmissionOK = true; ReturnValue = true; } else { ExtractAlreadyExists = true; ReturnValue = false; } if (ReturnValue) { SubmissionOK = true; } else { SubmissionOK = false; } }); // Get the Extract Id // if (NewExtractMasterDT != null) // { // TemplateRow = (MExtractMasterRow)NewExtractMasterDT.Rows[0]; // ANewExtractId = TemplateRow.ExtractId; // } ANewExtractId = NewExtractId; AExtractAlreadyExists = ExtractAlreadyExists; return ReturnValue; }
/// <summary> /// Updates the KeyCount on an Extract. /// </summary> /// <param name="AExtractId">ExtractId of the Extract that the KeyCount should /// get updated for.</param> /// <param name="ACount">New Key Count.</param> /// <param name="AVerificationResult">Contains errors or DB call exceptions, if there are any.</param> /// <returns>True if the updating was successful, otherwise false.</returns> public static bool UpdateExtractKeyCount(int AExtractId, int ACount, out TVerificationResultCollection AVerificationResult) { Boolean NewTransaction; Boolean Success = true; AVerificationResult = null; TDBTransaction WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { MExtractMasterTable ExtractMasterDT = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, WriteTransaction); if (ExtractMasterDT.Rows.Count == 1) { ExtractMasterDT[0].KeyCount = ACount; MExtractMasterAccess.SubmitChanges(ExtractMasterDT, WriteTransaction); } else { AVerificationResult.Add(new TVerificationResult( "TExtractsHandling.UpdateExtractCount", "Extract with Extract Id " + AExtractId.ToString() + " doesn't exist!", TResultSeverity.Resv_Critical)); Success = false; } if (Success) { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TExtractsHandling.UpdateExtractCount: committed own transaction!"); } } else { if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); TLogging.LogAtLevel(8, "TExtractsHandling.UpdateExtractCount: ROLLED BACK own transaction!"); } } } catch (Exception Exc) { TLogging.Log("An Exception occured during the updating of an Extracts' Key Count:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } return(Success); }
/// <summary> /// extend an extract from a list of best addresses /// </summary> /// <param name="AExtractId">Extract Id of the Extract to extend</param> /// <param name="APartnerKeysTable"></param> /// <param name="APartnerKeyColumn">number of the column that contains the partner keys</param> /// <param name="ASiteKeyColumn">number of the column that contains the site keys</param> /// <param name="ALocationKeyColumn">number of the column that contains the location keys</param> /// <param name="AIgnoreDuplicates">true if duplicates should be looked out for. Can be set to false if called only once and not several times per extract.</param> /// <param name="ACommitTransaction">true if transaction should be committed at end of method</param> public static void ExtendExtractFromListOfPartnerKeys( Int32 AExtractId, DataTable APartnerKeysTable, Int32 APartnerKeyColumn, Int32 ASiteKeyColumn, Int32 ALocationKeyColumn, bool AIgnoreDuplicates, bool ACommitTransaction) { Boolean NewTransaction; int RecordCounter = 0; PPartnerLocationTable PartnerLocationKeysTable; Int64 PartnerKey; TDBTransaction WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { MExtractTable ExtractTable = new MExtractTable(); ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, WriteTransaction); // Location Keys need to be determined as extracts do not only need partner keys but // also Location Keys. DetermineBestLocationKeys(APartnerKeysTable, APartnerKeyColumn, ASiteKeyColumn, ALocationKeyColumn, out PartnerLocationKeysTable, WriteTransaction); // use the returned table which contains partner and location keys to build the extract foreach (PPartnerLocationRow PartnerLocationRow in PartnerLocationKeysTable.Rows) { PartnerKey = Convert.ToInt64(PartnerLocationRow[PPartnerLocationTable.GetPartnerKeyDBName()]); if (PartnerKey > 0) { RecordCounter += 1; TLogging.Log("Preparing Partner " + PartnerKey.ToString() + " (Record Number " + RecordCounter.ToString() + ")"); // add row for partner to extract and fill with contents MExtractRow NewRow = ExtractTable.NewRowTyped(); NewRow.ExtractId = AExtractId; NewRow.PartnerKey = PartnerKey; NewRow.SiteKey = Convert.ToInt64(PartnerLocationRow[PPartnerLocationTable.GetSiteKeyDBName()]); NewRow.LocationKey = Convert.ToInt32(PartnerLocationRow[PPartnerLocationTable.GetLocationKeyDBName()]); // only add row if it does not already exist for this partner if (AIgnoreDuplicates || !ExtractTable.Rows.Contains(new object[] { NewRow.ExtractId, NewRow.PartnerKey, NewRow.SiteKey })) { ExtractTable.Rows.Add(NewRow); } } } if (ExtractTable.Rows.Count > 0) { // update field in extract master for quick access to number of partners in extract MExtractMasterTable ExtractMaster = MExtractMasterAccess.LoadByPrimaryKey(AExtractId, WriteTransaction); ExtractMaster[0].KeyCount = ExtractTable.Rows.Count; ExtractTable.ThrowAwayAfterSubmitChanges = true; // no need to keep data as this increases speed significantly MExtractAccess.SubmitChanges(ExtractTable, WriteTransaction); MExtractMasterAccess.SubmitChanges(ExtractMaster, WriteTransaction); } if (ACommitTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } } catch (Exception Exc) { TLogging.Log("An Exception occured while extending an Extract from a list of Partner Keys:" + Environment.NewLine + Exc.ToString()); if (NewTransaction) { DBAccess.GDBAccessObj.RollbackTransaction(); } throw; } }
/// <summary> /// Called by the instantiator of this Dialog to retrieve the result of the dialog /// /// </summary> /// <param name="AExtractMasterTable"></param> /// <returns>true if at least one row was selected /// </returns> public bool GetResult(ref MExtractMasterTable AExtractMasterTable) { MExtractMasterRow NewRow; AExtractMasterTable.Clear(); if (FResultTable == null) { return false; } foreach (MExtractMasterRow Row in FResultTable.Rows) { NewRow = AExtractMasterTable.NewRowTyped(); NewRow.ExtractId = Row.ExtractId; NewRow.ExtractName = Row.ExtractName; NewRow.ExtractDesc = Row.ExtractDesc; NewRow.KeyCount = Row.KeyCount; NewRow.CreatedBy = Row.CreatedBy; NewRow.DateCreated = Row.DateCreated; AExtractMasterTable.Rows.Add(NewRow); } return AExtractMasterTable.Count >= 0; }