private void LoadDataGrid() { List <long> HomeOfficeKeyList = new List <long>(); FMainDS.PcAttendee.Clear(); FMainDS.PmGeneralApplication.Clear(); FMainDS.PmShortTermApplication.Clear(); FMainDS.PPartner.Clear(); // populate dataset TRemote.MConference.Conference.WebConnectors.GetConferenceApplications(ref FMainDS, FPartnerKey); // Add all homeofficekeys to list as this column will be removed from dataset foreach (PcAttendeeRow Row in FMainDS.PcAttendee.Rows) { if (Row.IsHomeOfficeKeyNull() || (Row.HomeOfficeKey == 0)) { HomeOfficeKeyList.Add(((int)Row.PartnerKey / 1000000) * 1000000); } else { HomeOfficeKeyList.Add(Row.HomeOfficeKey); } } FMainDS.PcAttendee.Columns.Add(PPartnerTable.GetPartnerShortNameDBName(), Type.GetType("System.String")); FMainDS.PcAttendee.Columns.Add(PmShortTermApplicationTable.GetStFieldChargedDBName(), Type.GetType("System.String")); FMainDS.PcAttendee.Columns.Add(PmShortTermApplicationTable.GetStCurrentFieldDBName(), Type.GetType("System.String")); // This column is removed and readded with a different type. This allows the partner short name to be displayed rather than the partner key. FMainDS.PcAttendee.Columns.Remove(PcAttendeeTable.GetHomeOfficeKeyDBName()); FMainDS.PcAttendee.Columns.Add(PcAttendeeTable.GetHomeOfficeKeyDBName(), Type.GetType("System.String")); FMainDS.PcAttendee.DefaultView.AllowNew = false; for (int Counter = 0; Counter < FMainDS.PcAttendee.Rows.Count; ++Counter) { long PartnerKey = ((PcAttendeeRow)FMainDS.PcAttendee.Rows[Counter]).PartnerKey; long HomeOfficeKey = HomeOfficeKeyList[Counter]; long StFieldCharged = 0; long StConfirmedOption = 0; foreach (PmShortTermApplicationRow Row in FMainDS.PmShortTermApplication.Rows) { if (Row.PartnerKey == PartnerKey) { if (Row.IsStFieldChargedNull() || (Row.StFieldCharged == 0)) { if (Row.IsStCurrentFieldNull() || (Row.StCurrentField == 0)) { StFieldCharged = HomeOfficeKey; } else { StFieldCharged = Row.StCurrentField; } } else { StFieldCharged = Row.StFieldCharged; } if (Row.IsStCurrentFieldNull() || (Row.StConfirmedOption == 0)) { FMainDS.PcAttendee.Rows[Counter][PmShortTermApplicationTable.GetStCurrentFieldDBName()] = ((PcAttendeeRow)FMainDS.PcAttendee.Rows[Counter]).OutreachType; } else { StConfirmedOption = Row.StConfirmedOption; } break; } } int PartnersFound = 0; foreach (PPartnerRow Row in FMainDS.PPartner.Rows) { if (Row.PartnerKey == PartnerKey) { FMainDS.PcAttendee.Rows[Counter][PPartnerTable.GetPartnerShortNameDBName()] = Row.PartnerShortName; if (PartnersFound == 3) { break; } else { PartnersFound++; } } // display partner short name rather than the partner key if ((StFieldCharged != 0) && (Row.PartnerKey == StFieldCharged)) { FMainDS.PcAttendee.Rows[Counter][PmShortTermApplicationTable.GetStFieldChargedDBName()] = Row.PartnerShortName; if (PartnersFound == 3) { break; } else { PartnersFound++; } } // display partner short name rather than the partner key if ((StConfirmedOption != 0) && (Row.PartnerKey == StConfirmedOption)) { FMainDS.PcAttendee.Rows[Counter][PmShortTermApplicationTable.GetStCurrentFieldDBName()] = Row.PartnerShortName; if (PartnersFound == 3) { break; } else { PartnersFound++; } } // display partner short name rather than the partner key if ((HomeOfficeKey != 0) && (Row.PartnerKey == HomeOfficeKey)) { FMainDS.PcAttendee.Rows[Counter][PcAttendeeTable.GetHomeOfficeKeyDBName()] = Row.PartnerShortName; if (!(Row.PartnerShortName.Length > 0)) { } if (PartnersFound == 3) { break; } else { PartnersFound++; } } } } // sort order for grid DataView MyDataView = FMainDS.PcAttendee.DefaultView; MyDataView.Sort = "p_partner_short_name_c ASC"; grdAttendees.DataSource = new DevAge.ComponentModel.BoundDataView(MyDataView); }
public static bool GetFieldUnits(Int64 AConferenceKey, TUnitTypeEnum AFieldTypes, out DataTable AFieldsTable, out String AConferencePrefix) { TDBTransaction ReadTransaction; Boolean NewTransaction = false; AFieldsTable = new DataTable("Field Units"); AConferencePrefix = ""; PUnitTable UnitTable; DataTable TmpTable; PmShortTermApplicationTable ShortTermerTable = new PmShortTermApplicationTable(); AFieldsTable.Columns.Add("Selection", System.Type.GetType("System.Boolean")); AFieldsTable.Columns.Add("Unit_Key", System.Type.GetType("System.Int64")); AFieldsTable.Columns.Add("Unit_Name", System.Type.GetType("System.String")); AFieldsTable.Columns.Add("Outreach_Code", System.Type.GetType("System.String")); AFieldsTable.Columns.Add("Used_in_Conference", System.Type.GetType("System.Boolean")); AConferencePrefix = TConferenceOptions.GetConferencePrefix(AConferenceKey); switch (AFieldTypes) { case TUnitTypeEnum.utSendingFields: return(TConferenceOptions.GetSendingFields(AConferenceKey, ref AFieldsTable)); case TUnitTypeEnum.utReceivingFields: return(TConferenceOptions.GetReceivingFields(AConferenceKey, ref AFieldsTable)); case TUnitTypeEnum.utOutreachOptions: if (TConferenceOptions.GetOutreachOptions(AConferenceKey, out TmpTable)) { foreach (DataRow Row in TmpTable.Rows) { DataRow NewRow = AFieldsTable.NewRow(); NewRow[SELECTION] = false; NewRow[UNIT_KEY] = Row["Partner Key"]; NewRow[UNIT_NAME] = Row["Unit Name"]; NewRow[CAMPAIGN_CODE] = Row["Outreach Code"]; NewRow[USED_IN_CONFERENCE] = true; AFieldsTable.Rows.Add(NewRow); } return(true); } return(false); default: break; } TLogging.LogAtLevel(9, "TConferenceOptions.GetFieldUnits called!"); TDataBase db = DBAccess.Connect("GetFieldUnits"); ReadTransaction = db.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, out NewTransaction); try { StringCollection FieldList = new StringCollection(); FieldList.Add(PmShortTermApplicationTable.GetStFieldChargedDBName()); FieldList.Add(PmShortTermApplicationTable.GetConfirmedOptionCodeDBName()); FieldList.Add(PmShortTermApplicationTable.GetRegistrationOfficeDBName()); ShortTermerTable = PmShortTermApplicationAccess.LoadAll(FieldList, ReadTransaction); long LastUnitKey = 0; long NewUnitKey = 0; bool IsUsedInOneConference = false; String ConfirmedOptionCode = ""; System.Type StringType = System.Type.GetType("System.String"); String SearchedColumnName = ""; switch (AFieldTypes) { case TUnitTypeEnum.utChargedFields: SearchedColumnName = PmShortTermApplicationTable.GetStFieldChargedDBName(); break; case TUnitTypeEnum.utRegisteringFields: SearchedColumnName = PmShortTermApplicationTable.GetRegistrationOfficeDBName(); break; default: break; } foreach (DataRow ShortTermerRow in ShortTermerTable.Select("", SearchedColumnName)) { if ((ShortTermerRow[SearchedColumnName] != null) && (ShortTermerRow[SearchedColumnName].ToString().Length > 0)) { NewUnitKey = (long)ShortTermerRow[SearchedColumnName]; } else { continue; } if (LastUnitKey != NewUnitKey) { if ((AFieldsTable.Rows.Count > 0) && (IsUsedInOneConference)) { AFieldsTable.Rows[AFieldsTable.Rows.Count - 1][USED_IN_CONFERENCE] = true; } IsUsedInOneConference = false; } // We have to check from every shorttermer if the charged field is used // in this conference if (IsUsedInOneConference) { continue; } if (ShortTermerRow[PmShortTermApplicationTable.GetConfirmedOptionCodeDBName()].GetType() == StringType) { ConfirmedOptionCode = (string)ShortTermerRow[PmShortTermApplicationTable.GetConfirmedOptionCodeDBName()]; } else { ConfirmedOptionCode = ""; } if (ConfirmedOptionCode.StartsWith(AConferencePrefix)) { IsUsedInOneConference = true; } if (LastUnitKey == NewUnitKey) { continue; } UnitTable = PUnitAccess.LoadByPrimaryKey(NewUnitKey, ReadTransaction); if (UnitTable.Rows.Count > 0) { DataRow ResultRow = AFieldsTable.NewRow(); ResultRow[SELECTION] = false; ResultRow[UNIT_KEY] = NewUnitKey; ResultRow[UNIT_NAME] = UnitTable[0][PUnitTable.GetUnitNameDBName()]; ResultRow[CAMPAIGN_CODE] = ConfirmedOptionCode; ResultRow[USED_IN_CONFERENCE] = IsUsedInOneConference; AFieldsTable.Rows.Add(ResultRow); LastUnitKey = NewUnitKey; } } // Check for the previous entry the "IsUsedInConference" field if ((AFieldsTable.Rows.Count > 0) && (IsUsedInOneConference)) { AFieldsTable.Rows[AFieldsTable.Rows.Count - 1][USED_IN_CONFERENCE] = true; } } finally { if (NewTransaction) { ReadTransaction.Commit(); TLogging.LogAtLevel(7, "TConferenceOptions.GetFieldUnits: committed own transaction."); } } return(true); }