/// <summary> /// 获取商户密钥,除去头部和尾部 /// </summary> /// <returns></returns> public string GetPartnerKeyBody() { return(PartnerKey .Replace("-----BEGIN RSA PRIVATE KEY-----", "") .Replace("-----END RSA PRIVATE KEY-----", "") .Trim()); }
/// <summary> /// Populate the empty table p_partner_attribute using selected data from p_partner_location. /// </summary> /// <returns>Number of created PPartnerAttribute Rows.</returns> public static int PopulatePPartnerAttribute() { int RowCounter = 0; Int64 BestPartnerLocSiteKey; int BestPartnerLocLocationKey; List <PPartnerAttributeRecord> PPARecords; if (FEmptyStringIndicator == null) { throw new EOPException("'FEmptyStringIndicator' must be set before Method 'PopulatePPartnerAttribute' gets called!"); } // FPartnerLocationRecords got created when the p_partner_location table got processed; it holds selected Columns of all // p_partner_location records of each Partner that gets loaded. // TLogging.Log(String.Format("We have entries for {0} Partners.", FPartnerClassInformation.Count)); // Process each Partner and its p_partner_location records foreach (Int64 PartnerKey in FPartnerClassInformation.Keys) { FInsertionOrderPerPartner = -1; // Get that Partner's p_partner_location records from PPartnerLocationRecords DataRow[] CurrentRows = FPartnerLocationRecords[Math.Abs(PartnerKey) % NumberOfTables].Select( "p_partner_key_n = " + PartnerKey.ToString()); if (CurrentRows.Length == 0) { continue; } DataTable PPartnersLocationsDT = TPartnerContactDetails.BestAddressHelper.GetNewPPartnerLocationTableInstance(); foreach (DataRow r in CurrentRows) { PPartnersLocationsDT.Rows.Add(r.ItemArray); } // We hazard a guess that we will possibly create 2 times as many p_partner_attribute records as there are // p_partner_location records - but in some cases there will be more (if we need to create many 'primary' // p_partner_attribute records for Contact Details that come out of the 'Best Address' p_partner_location records, // or less (if there are many p_partner_location records that don't have details that will become a Contact Detail). // The guess is done so that PPARecords doesn't need to continually get expanded by .NET as we are adding to it. // (The 2.0 factor got determined by checking the average number of records that got created by running this // over actual data from the SA DB (1.3) and then rounding the number up, as often there will only be one // p_partner_location record, and so we create at least 2 entries in that case.) PPARecords = new List <PPartnerAttributeRecord>(PPartnersLocationsDT.Rows.Count * 2); // Determine the p_partner_location record that constitutes the 'Best Address' of that Partner if (!BestAddressHelper.DetermineBestAddress(PPartnersLocationsDT, out BestPartnerLocSiteKey, out BestPartnerLocLocationKey)) { throw new Exception(String.Format( "Problem determining the 'Best Address' for the p_partner_location records of Partner with PartnerKey {0}! Number of p_partner_location records: {1}", PartnerKey, PPartnersLocationsDT.Rows.Count)); } else { if (PPartnersLocationsDT.Rows.Count > 1) { // TLogging.Log( // String.Format( // "'Best Address' for the p_parter_location records of Partner with PartnerKey {0} which has {1} p_partner_locations: p_parter_location SiteKey: {2}; p_parter_location LocationKey: {3}", // PartnerKey, PPartnersLocationsDT.Rows.Count, BestPartnerLocSiteKey, BestPartnerLocLocationKey)); } // // Create p_partner_attribute records for each p_partner_location records' // columns that hold 'Contact Detail' data and have values, and are unique, // // We want to create the p_partner_attribute records in the same order that the user // would see the p_location records (that we lift them from) on the Address Tab. DataView SortedRecordsDV = PPartnersLocationsDT.DefaultView; SortedRecordsDV.Sort = "Icon_For_Sorting ASC, p_date_effective_d DESC"; for (int Counter = 0; Counter < SortedRecordsDV.Count; Counter++) { List <PPartnerAttributeRecord> PPARecordsSingleLocation = ConstructPPartnerAttributeRecords(PartnerKey, SortedRecordsDV[Counter].Row); for (int SingleLocCounter = 0; SingleLocCounter < PPARecordsSingleLocation.Count; SingleLocCounter++) { // LINQ Query for de-duplication: Check if there are already PPARecords of a Partner that have // the same Attribute Type and Value as a record from PPARecordsSingleLocation. If so, don't add // the record from PPARecordsSingleLocation to PPARecords as it would create a duplicate Contact Detail! // (it is often the case that several p_partner_location records of a Partner hold the same data!) var PPARecordsContainsQuery = from PPARecord in PPARecords where PPARecord.AttributeType == PPARecordsSingleLocation[SingleLocCounter].AttributeType && PPARecord.Value == PPARecordsSingleLocation[SingleLocCounter].Value select PPARecord; if (!PPARecordsContainsQuery.Any()) { PPARecords.Add(PPARecordsSingleLocation[SingleLocCounter]); } } } // LINQ Query to establish Index values: Group all PPARecords of a Partner by // Attribute Type and have the Primary record come first in each Group, followed by // the other PPARecords in their insertion order. var PPARecordsGroupedQuery = from PPARecord in PPARecords orderby PPARecord.Primary descending, PPARecord.InsertionOrderPerPartner group PPARecord by PPARecord.AttributeType into grouping orderby grouping.Key select grouping; // Iterate over each Group and determine the Index values of their individual members. // The first member always starts with Index 0. // Reason for this: The Contact Details Tab displays Contact Details grouped by // Contact Category, and the ones of the same Contact Category are sorted by Index // within each Contact Category. With this approach, 'Primary' PPARecords will be // listed first, followed by other records in the order that a user would have seen // them on the 'Addresses' Tab in Petra 2.x! foreach (var PPARecordGroup in PPARecordsGroupedQuery) { int IndexInGroup = 0; foreach (var PPARecGroupMember in PPARecordGroup) { PPARecGroupMember.Index = IndexInGroup++; } } // Create new Rows and write them out foreach (var PPARec in PPARecords) { CreateContactDetailsRow(PPARec, PartnerAttributeHoldingDataSet); } RowCounter += PPARecords.Count; } } // Get rid of the Data Structure that we don't need anymore! FPartnerLocationRecords = null; // ... and kindly ask .NET's Garbage Collector to really get it out of memory, if it's convenient. GC.Collect(0, GCCollectionMode.Optimized); return(RowCounter); }
/// <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> /// Demotes selected ID (and promotes the FamilyID next (lower) to selected FamilyID /// </summary> /// <returns>void</returns> public void DemoteFamilyID() { Int32 Buttonvalue = -1; Int32 NumberOfRows; Int32 Counter; Int32 CounterToMax; Int32 FamilyIDint; System.Object PartnerKey; System.Object FamilyID = -1; System.Object PreviousFamilyID = -1; System.Object PersonName1 = ""; System.Object PersonName2 = ""; Boolean MemberFind; MessageBoxButtons Button; // Get the PartnerKey of the selected Row PartnerKey = ((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]; NumberOfRows = GetNumberOfRows(); // for loop to get the selected partners ID for (Counter = 0; Counter <= (NumberOfRows - 1); Counter += 1) { if (FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FamilyID = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; PersonName1 = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; break; } } if ((this.IsMinimum()) && (Convert.ToInt32(FamilyID) > 0)) { FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)0; Buttonvalue = 1; FamilyID = (object)0; } // loop to find the nearest smaller FamilyID compared to selected FamilyID. // sets the previous FamilyID to correct. MemberFind = true; FamilyIDint = Convert.ToInt32(FamilyID); // If Family ID is 2, or A parent is to be replaced with child, gives warning. if (FamilyIDint == 2) { Button = MessageBoxButtons.YesNo; if (MessageBox.Show("Parents should be Family ID 0 or 1" + "\r\nAre you sure you want to change this Family ID?", "Family ID Change", Button) == DialogResult.No) { Buttonvalue = 1; } } // if FamilyID to be demoted is 2 and cancel is selected from warnind messagebox, does nothing. otherwice goes through the for loop if (Buttonvalue != 1) { // Goes through the FamilyID:s from 1 to selected FamilyID for (CounterToMax = 1; CounterToMax <= FamilyIDint; CounterToMax += 1) { // Goes through all the FamilyID:s for (Counter = 0; Counter <= (NumberOfRows - 1); Counter += 1) { // when finds FamilyID next to selected (below), Sets the found Family ID to selected if (Convert.ToInt32(FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()].ToString()) == (FamilyIDint - CounterToMax)) { // saves the found FamilyID PreviousFamilyID = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)(Convert.ToInt32(PreviousFamilyID) + 1); PersonName2 = FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; if (PersonName2 == PersonName1) { PersonName1 = PreviousPartnerMemory; } MemberFind = false; break; } } if (!MemberFind) { break; } } // loop to set the selected FamilyID to the PreviousFamilyID for (Counter = 0; Counter <= (NumberOfRows - 1); Counter += 1) { if (FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FFamilyMembersDV[Counter].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = PreviousFamilyID; break; } } MessageBox.Show(String.Format(StrFamilyIDChangeDone, PersonName1, FamilyID, PreviousFamilyID, PersonName2, PreviousFamilyID, (Convert.ToInt32(PreviousFamilyID) + 1)), StrFamilyIDChangeDoneTitle); PreviousPartnerMemory = PersonName1; } else { } }
/// <summary> /// Promotes selected ID (and demotes the FamilyID next (up) to selected FamilyID /// </summary> /// <returns>void</returns> public void PromoteFamilyID() { Int32 buttonvalue = -1; Int32 Counter1; Int32 NumberOfRows; Int32 Counter2; Int32 Counter2ToMax; Int32 FamilyIDint; System.Object PartnerKey; System.Object FamilyID = -1; System.Object PersonName1 = ""; System.Object PersonName2 = ""; System.Object NextFamilyID = ""; Boolean MemberFind; MessageBoxButtons Button; // Get the PartnerKey of the selected Row PartnerKey = ((DataRowView)FDataGrid.SelectedDataRows[0]).Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()]; NumberOfRows = GetNumberOfRows(); // for loop to get the selected partners ID for (Counter2 = 0; Counter2 <= (NumberOfRows - 1); Counter2 += 1) { if (FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FamilyID = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; PersonName1 = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; break; } } // loop to find the nearest FamilyID compared to selected FamilyID. // sets the next FamilyID to correct. MemberFind = true; FamilyIDint = Convert.ToInt32(FamilyID); // If Family ID 1 (parent) is about to be promoted if (FamilyIDint == 1) { Button = MessageBoxButtons.YesNo; buttonvalue = 0; // if pressed No to question below, does nothing. if (MessageBox.Show("Parents should be Family ID 0 or 1" + "\r\nAre you sure you want to change this Family ID?", "Family ID Change", Button) == DialogResult.No) { buttonvalue = 1; } } // Executes this loop, if Family ID to be promoted is not 1. if (buttonvalue != 1) { Counter2ToMax = 100; // goes through all values from selected +1 to 100+selected. for (Counter1 = 1; Counter1 <= Counter2ToMax; Counter1 += 1) { // goes through all FamilyID:s for (Counter2 = 0; Counter2 <= (NumberOfRows - 1); Counter2 += 1) { // When finds FamilyID that's next (above) to selected FamilyID, Replaces the Found Family members ID with selected ID if (Convert.ToInt32(FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()].ToString()) == FamilyIDint + Counter1) { // saves the FamilyIF just found NextFamilyID = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()]; FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = FamilyID; PersonName2 = FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerShortNameDBName()]; MemberFind = false; break; } } if (!MemberFind) { break; } } // end; // loop to set the selected FamilyID to the PreviousFamilyID for (Counter2 = 0; Counter2 <= (NumberOfRows - 1); Counter2 += 1) { if (FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetPartnerKeyDBName()].ToString() == PartnerKey.ToString()) { FFamilyMembersDV[Counter2].Row[PartnerEditTDSFamilyMembersTable.GetFamilyIdDBName()] = (object)(FamilyIDint + 1); break; } } // button := MessageBoxButtons.OK; MessageBox.Show(String.Format(StrFamilyIDChangeDone, PersonName1, FamilyID, (FamilyIDint + 1), PersonName2, NextFamilyID, FamilyID), StrFamilyIDChangeDoneTitle); } else { } }