private DataTable GetInstalledSitesListTable(TDBTransaction AReadTransaction, string ATableName) { // Used eg. in New Partner Dialog. StringCollection RequiredColumns = new StringCollection(); RequiredColumns.Add(PPartnerLedgerTable.GetPartnerKeyDBName()); PPartnerLedgerTable TmpInstalledSitesDT = PPartnerLedgerAccess.LoadAll(RequiredColumns, AReadTransaction, null, 0, 0); if (TmpInstalledSitesDT.Rows.Count != 0) { TmpInstalledSitesDT.Columns.Remove(PPartnerLedgerTable.GetLastPartnerIdDBName()); TmpInstalledSitesDT.Columns.Add(PPartnerTable.GetPartnerShortNameDBName(), System.Type.GetType("System.String")); RequiredColumns = new StringCollection(); RequiredColumns.Add(PPartnerTable.GetPartnerShortNameDBName()); for (int Counter = 0; Counter <= TmpInstalledSitesDT.Rows.Count - 1; Counter += 1) { PPartnerTable PartnerDT = PPartnerAccess.LoadByPrimaryKey( TmpInstalledSitesDT[Counter].PartnerKey, RequiredColumns, AReadTransaction, null, 0, 0); TmpInstalledSitesDT[Counter][PPartnerTable.GetPartnerShortNameDBName()] = PartnerDT[0].PartnerShortName; } } return(TmpInstalledSitesDT); }
/// <summary> /// this returns the default next available (highest) partner key of the given field /// </summary> /// <param name="AFieldPartnerKey">if this is -1, then the sitekey defined in System Parameters is used</param> /// <returns>void</returns> public static System.Int64 GetNewPartnerKey(System.Int64 AFieldPartnerKey) { PPartnerLedgerTable PartnerLedgerTable = null; Int64 ReturnValue = -1; if (AFieldPartnerKey == -1) { AFieldPartnerKey = DomainManager.GSiteKey; } TDBTransaction ReadTransaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { PartnerLedgerTable = PPartnerLedgerAccess.LoadByPrimaryKey(AFieldPartnerKey, ReadTransaction); ReturnValue = PartnerLedgerTable[0].PartnerKey + PartnerLedgerTable[0].LastPartnerId + 1; // Now check that this does not exist, and increment until we // find one which does not while (PPartnerAccess.Exists(ReturnValue, ReadTransaction)) { ReturnValue = ReturnValue + 1; } }); return(ReturnValue); }
/// <summary> /// todoComment /// </summary> /// <param name="AGridDataView"></param> /// <param name="APreselectedSiteKey"></param> /// <param name="ARowNumber"></param> /// <param name="ASiteKey"></param> public void DetermineInitiallySelectedSite(DataView AGridDataView, Int64 APreselectedSiteKey, out Int32 ARowNumber, out Int64 ASiteKey) { System.Int16 CurrentRow; if ((APreselectedSiteKey == 0) || (APreselectedSiteKey == -1)) { ASiteKey = Convert.ToInt64(TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_SITEKEY)); } else { ASiteKey = APreselectedSiteKey; } FSiteKey = ASiteKey; ARowNumber = 0; for (CurrentRow = 0; CurrentRow <= AGridDataView.Count - 1; CurrentRow += 1) { ARowNumber = ARowNumber + 1; if (Convert.ToInt64(AGridDataView[CurrentRow].Row[PPartnerLedgerTable.GetPartnerKeyDBName()]) == ASiteKey) { break; } } }
private DataTable GetInstalledSitesListTable(TDBTransaction AReadTransaction, string ATableName) { // Used eg. in New Partner Dialog. StringCollection RequiredColumns = new StringCollection(); RequiredColumns.Add(PPartnerLedgerTable.GetPartnerKeyDBName()); PPartnerLedgerTable TmpInstalledSitesDT = PPartnerLedgerAccess.LoadAll(RequiredColumns, AReadTransaction, null, 0, 0); if (TmpInstalledSitesDT.Rows.Count != 0) { TmpInstalledSitesDT.Columns.Remove(PPartnerLedgerTable.GetLastPartnerIdDBName()); TmpInstalledSitesDT.Columns.Add(PPartnerTable.GetPartnerShortNameDBName(), System.Type.GetType("System.String")); RequiredColumns = new StringCollection(); RequiredColumns.Add(PPartnerTable.GetPartnerShortNameDBName()); for (int Counter = 0; Counter <= TmpInstalledSitesDT.Rows.Count - 1; Counter += 1) { PPartnerTable PartnerDT = PPartnerAccess.LoadByPrimaryKey( TmpInstalledSitesDT[Counter].PartnerKey, RequiredColumns, AReadTransaction, null, 0, 0); TmpInstalledSitesDT[Counter][PPartnerTable.GetPartnerShortNameDBName()] = PartnerDT[0].PartnerShortName; } } // As part of bug 5556 testing, checked if this DataTable contained any Added rows. It didn't, so there isn't an issue here. // Findings: DataTable summary: 1 rows; 0 Added, 0 deleted, 0 detached, 1 modified, 0 unchanged. Table name PPartnerLedger return(TmpInstalledSitesDT); }
/// <summary> /// this returns the default next available (highest) partner key of the given field /// </summary> /// <param name="AFieldPartnerKey">if this is -1, then the sitekey defined in System Parameters is used</param> /// <returns>void</returns> public static System.Int64 GetNewPartnerKey(System.Int64 AFieldPartnerKey) { Boolean NewTransaction; TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, out NewTransaction); if (AFieldPartnerKey == -1) { AFieldPartnerKey = DomainManager.GSiteKey; } PPartnerLedgerTable PartnerLedgerTable = PPartnerLedgerAccess.LoadByPrimaryKey(AFieldPartnerKey, ReadTransaction); if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_TRACE) { Console.WriteLine("TNewPartnerKey.GetNewPartnerKey: committed own transaction."); } } return(PartnerLedgerTable[0].PartnerKey + PartnerLedgerTable[0].LastPartnerId + 1); }
/// <summary> /// this returns the default next available (highest) partner key of the given field /// </summary> /// <param name="AFieldPartnerKey">if this is -1, then the sitekey defined in System Parameters is used</param> /// <param name="ADataBase"></param> /// <returns>void</returns> public static System.Int64 GetNewPartnerKey(System.Int64 AFieldPartnerKey, TDataBase ADataBase = null) { PPartnerLedgerTable PartnerLedgerTable = null; Int64 ReturnValue = -1; if (AFieldPartnerKey == -1) { AFieldPartnerKey = DomainManager.GSiteKey; } TDBTransaction ReadTransaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("GetNewPartnerKey", ADataBase); db.ReadTransaction(ref ReadTransaction, delegate { PartnerLedgerTable = PPartnerLedgerAccess.LoadByPrimaryKey(AFieldPartnerKey, ReadTransaction); ReturnValue = PartnerLedgerTable[0].PartnerKey + PartnerLedgerTable[0].LastPartnerId + 1; // Now check that this does not exist, and increment until we // find one which does not while (PPartnerAccess.Exists(ReturnValue, ReadTransaction)) { ReturnValue = ReturnValue + 1; } }); if (ADataBase == null) { db.CloseDBConnection(); } return(ReturnValue); }
public static bool SaveSiteKeys(List <Int64> ASiteKeysSetUpForUse, List <Int64> ASiteKeysToRemove) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = true; PPartnerLedgerTable PartnerLedgerTable = new PPartnerLedgerTable(); PPartnerLedgerRow PartnerLedgerRow; // save site keys that can be used in p_partner_ledger DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { // create new records in p_partner_ledger if not there yet foreach (Int64 SiteKey in ASiteKeysSetUpForUse) { if (PPartnerLedgerAccess.CountViaPUnit(SiteKey, Transaction) == 0) { PartnerLedgerRow = PartnerLedgerTable.NewRowTyped(); PartnerLedgerRow.PartnerKey = SiteKey; // calculate last partner id, from older uses of this ledger number object MaxExistingPartnerKeyObj = Transaction.DataBaseObj.ExecuteScalar( String.Format("SELECT MAX(" + PPartnerTable.GetPartnerKeyDBName() + ") FROM " + PPartnerTable.GetTableDBName() + " WHERE " + PPartnerTable.GetPartnerKeyDBName() + " > {0} AND " + PPartnerTable.GetPartnerKeyDBName() + " < {1}", SiteKey, SiteKey + 500000), Transaction); if (MaxExistingPartnerKeyObj.GetType() != typeof(DBNull)) { // found a partner key for this site already: set it to last used value PartnerLedgerRow.LastPartnerId = Convert.ToInt32(Convert.ToInt64(MaxExistingPartnerKeyObj) - SiteKey); } else { // in this case there was no partner key for this site yet PartnerLedgerRow.LastPartnerId = 0; } PartnerLedgerTable.Rows.Add(PartnerLedgerRow); } } // delete records from p_partner_ledger that are no longer needed foreach (Int64 SiteKey in ASiteKeysToRemove) { PPartnerLedgerAccess.DeleteByPrimaryKey(SiteKey, Transaction); } PPartnerLedgerAccess.SubmitChanges(PartnerLedgerTable, Transaction); }); // make sure SitesList will be refreshed when called next time TPartnerCacheableWebConnector.RefreshCacheableTable(TCacheablePartnerTablesEnum.InstalledSitesList); return(SubmissionOK); }
/// <summary> /// reserve a number of partner keys, to be used by the calling function. /// useful to create many partner at once, eg. for the demodata /// </summary> /// <param name="AFieldPartnerKey"></param> /// <param name="ANumberOfKeys"></param> /// <param name="ADataBase"></param> /// <returns>the first valid partner key to use</returns> public static System.Int64 ReservePartnerKeys(System.Int64 AFieldPartnerKey, ref Int32 ANumberOfKeys, TDataBase ADataBase = null) { Int64 NextPartnerKey = -1; Int32 NumberOfKeys = ANumberOfKeys; if (AFieldPartnerKey == -1) { AFieldPartnerKey = DomainManager.GSiteKey; } TDBTransaction ReadWriteTransaction = new TDBTransaction(); TDataBase db = DBAccess.Connect("ReservePartnerKeys", ADataBase); bool SubmissionOK = true; db.WriteTransaction(ref ReadWriteTransaction, ref SubmissionOK, delegate { PPartnerLedgerTable PartnerLedgerDT = PPartnerLedgerAccess.LoadByPrimaryKey(AFieldPartnerKey, ReadWriteTransaction); NextPartnerKey = PartnerLedgerDT[0].PartnerKey + PartnerLedgerDT[0].LastPartnerId + 1; Int64 NextUsedKey = Convert.ToInt64(db.ExecuteScalar("SELECT MIN(p_partner_key_n) FROM PUB_p_partner WHERE p_partner_key_n >= " + NextPartnerKey.ToString(), ReadWriteTransaction)); if (NextUsedKey < NextPartnerKey + NumberOfKeys) { NumberOfKeys = Convert.ToInt32(NextUsedKey - NextPartnerKey); } PartnerLedgerDT[0].LastPartnerId = Convert.ToInt32((NextPartnerKey + NumberOfKeys - 1) - PartnerLedgerDT[0].PartnerKey); PPartnerLedgerAccess.SubmitChanges(PartnerLedgerDT, ReadWriteTransaction); SubmissionOK = true; }); if (ADataBase == null) { db.CloseDBConnection(); } if (!SubmissionOK) { throw new Exception("ReservePartnerKeys failed"); } ANumberOfKeys = NumberOfKeys; return(NextPartnerKey); }
/// <summary> /// reserve a number of partner keys, to be used by the calling function. /// useful to create many partner at once, eg. for the demodata /// </summary> /// <param name="AFieldPartnerKey"></param> /// <param name="ANumberOfKeys"></param> /// <returns>the first valid partner key to use</returns> public static System.Int64 ReservePartnerKeys(System.Int64 AFieldPartnerKey, ref Int32 ANumberOfKeys) { Int64 NextPartnerKey = -1; if (AFieldPartnerKey == -1) { AFieldPartnerKey = DomainManager.GSiteKey; } TDBTransaction ReadWriteTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { PPartnerLedgerTable PartnerLedgerDT = PPartnerLedgerAccess.LoadByPrimaryKey(AFieldPartnerKey, ReadWriteTransaction); NextPartnerKey = PartnerLedgerDT[0].PartnerKey + PartnerLedgerDT[0].LastPartnerId + 1; Int64 NextUsedKey = Convert.ToInt64(DBAccess.GDBAccessObj.ExecuteScalar("SELECT MIN(p_partner_key_n) FROM PUB_p_partner WHERE p_partner_key_n >= " + NextPartnerKey.ToString(), ReadWriteTransaction)); if (NextUsedKey < NextPartnerKey + ANumberOfKeys) { ANumberOfKeys = Convert.ToInt32(NextUsedKey - NextPartnerKey); } PartnerLedgerDT[0].LastPartnerId = Convert.ToInt32((NextPartnerKey + ANumberOfKeys - 1) - PartnerLedgerDT[0].PartnerKey); PPartnerLedgerAccess.SubmitChanges(PartnerLedgerDT, ReadWriteTransaction); DBAccess.GDBAccessObj.CommitTransaction(); } catch (Exception Exc) { TLogging.Log("An Exception occured during the reservation of a PartnerKey:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } return(NextPartnerKey); }
/// <summary> /// todoComment /// </summary> /// <param name="AGrid"></param> /// <returns></returns> public Int64 DetermineCurrentSitePartnerKey(TSgrdDataGrid AGrid) { DataRowView[] TheDataRowViewArray; Int64 SitePartnerKey; // MessageBox.Show(ARow.ToString); TheDataRowViewArray = AGrid.SelectedDataRowsAsDataRowView; // get PartnerKey of current DataRow try { SitePartnerKey = Convert.ToInt64(TheDataRowViewArray[0].Row[PPartnerLedgerTable.GetPartnerKeyDBName()]); } catch (Exception) { throw; } // MessageBox.Show(FPartnerKey.ToString); FSiteKey = SitePartnerKey; return(SitePartnerKey); }
/// <summary> /// todoComment /// </summary> /// <param name="AGrid"></param> /// <param name="ASourceTable"></param> public void CreateColumns(TSgrdDataGrid AGrid, DataTable ASourceTable) { AGrid.AddPartnerKeyColumn("Site Key", ASourceTable.Columns[PPartnerLedgerTable.GetPartnerKeyDBName()], 75); AGrid.AddTextColumn("Site Name", ASourceTable.Columns[PPartnerTable.GetPartnerShortNameDBName()], 353); }
public static bool SaveSiteKeys(List <Int64>ASiteKeysSetUpForUse, List <Int64>ASiteKeysToRemove) { TDBTransaction Transaction = null; bool SubmissionOK = true; PPartnerLedgerTable PartnerLedgerTable = new PPartnerLedgerTable(); PPartnerLedgerRow PartnerLedgerRow; // save site keys that can be used in p_partner_ledger DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK, delegate { // create new records in p_partner_ledger if not there yet foreach (Int64 SiteKey in ASiteKeysSetUpForUse) { if (PPartnerLedgerAccess.CountViaPUnit(SiteKey, Transaction) == 0) { PartnerLedgerRow = PartnerLedgerTable.NewRowTyped(); PartnerLedgerRow.PartnerKey = SiteKey; // calculate last partner id, from older uses of this ledger number object MaxExistingPartnerKeyObj = DBAccess.GDBAccessObj.ExecuteScalar( String.Format("SELECT MAX(" + PPartnerTable.GetPartnerKeyDBName() + ") FROM " + PPartnerTable.GetTableDBName() + " WHERE " + PPartnerTable.GetPartnerKeyDBName() + " > {0} AND " + PPartnerTable.GetPartnerKeyDBName() + " < {1}", SiteKey, SiteKey + 500000), Transaction); if (MaxExistingPartnerKeyObj.GetType() != typeof(DBNull)) { // found a partner key for this site already: set it to last used value PartnerLedgerRow.LastPartnerId = Convert.ToInt32(Convert.ToInt64(MaxExistingPartnerKeyObj) - SiteKey); } else { // in this case there was no partner key for this site yet PartnerLedgerRow.LastPartnerId = 0; } PartnerLedgerTable.Rows.Add(PartnerLedgerRow); } } // delete records from p_partner_ledger that are no longer needed foreach (Int64 SiteKey in ASiteKeysToRemove) { PPartnerLedgerAccess.DeleteByPrimaryKey(SiteKey, Transaction); } PPartnerLedgerAccess.SubmitChanges(PartnerLedgerTable, Transaction); }); // make sure SitesList will be refreshed when called next time TPartnerCacheableWebConnector.RefreshCacheableTable(TCacheablePartnerTablesEnum.InstalledSitesList); return SubmissionOK; }