// This is the main area where we set up to use the additional information from the extra table private void InitializeManualCode() { // Get our screenClassName string ScreenName = this.GetType().Name; // Initialise the list box column headings in the working DataTable and the GUI string DBCol1 = DBUsedBy; string DBCol2 = String.Empty; string GUICol2 = String.Empty; string DBCol3 = "Label"; if (String.Compare(ScreenName, "TFrmLocalPartnerDataFieldSetup", true) == 0) { CurrentContext = Context.Partner; DBCol2 = "PartnerClass"; GUICol2 = Catalog.GetString("Partner Class"); } else if (String.Compare(ScreenName, "TFrmLocalApplicationDataFieldSetup", true) == 0) { CurrentContext = Context.Application; DBCol2 = "Application"; GUICol2 = Catalog.GetString("Application"); } else if (String.Compare(ScreenName, "TFrmLocalPersonnelDataFieldSetup", true) == 0) { CurrentContext = Context.Personnel; DBCol2 = "Personnel"; GUICol2 = Catalog.GetString("Personnel"); } // Now we can initialise our little data table that backs the checkbox list view DTUsedBy.Columns.Add(DBCol1).DataType = typeof(Boolean); DTUsedBy.Columns.Add(DBCol2).DataType = typeof(String); DTUsedBy.Columns.Add(DBCol3).DataType = typeof(String); // Add a 'Context' column so we can filter the data ContextColumnOrdinal = FMainDS.PDataLabel.Columns.Add("Context", typeof(int)).Ordinal; // Add a 'Used By' column to our main dataset (Do it twice so we track changes) FMainDS.PDataLabel.Columns.Add("UsedByInit", typeof(String)); UsedByColumnOrdinal = FMainDS.PDataLabel.Columns.Add(DBUsedBy, typeof(String)).Ordinal; // Add a 'Converted Data Type' column to the dataset because we want to 'translate' from geeky database entries to friendly user ones // This column data is derived from an expression string expression = String.Format("IIF(p_data_type_c='char','{0}',", Catalog.GetString("Text")); expression += String.Format("IIF(p_data_type_c='float','{0}',", Catalog.GetString("Number")); expression += String.Format("IIF(p_data_type_c='currency','{0}',", Catalog.GetString("Currency")); expression += String.Format("IIF(p_data_type_c='boolean','{0}',", Catalog.GetString("Yes/No")); expression += String.Format("IIF(p_data_type_c='date','{0}',", Catalog.GetString("Date")); expression += String.Format("IIF(p_data_type_c='time','{0}',", Catalog.GetString("Time")); expression += String.Format("IIF(p_data_type_c='lookup','{0}',", Catalog.GetString("Option List")); expression += String.Format("IIF(p_data_type_c='partnerkey','{0}',", Catalog.GetString("Partner Key")); expression += String.Format("'{0}'))))))))", Catalog.GetString("Unknown")); DataTypeColumnOrdinal = FMainDS.PDataLabel.Columns.Add("DataTypeEx", typeof(System.String), expression).Ordinal; // Load the Extra Data from DataLabelUse table Type DataTableType; FExtraDS.PDataLabelUse = new PDataLabelUseTable(); DataTable CacheDT = TDataCache.GetCacheableDataTableFromCache("DataLabelUseList", String.Empty, null, out DataTableType); FExtraDS.PDataLabelUse.Merge(CacheDT); // Take each row of our main dataset and populate the new column with relevant data // from the DataLabelUse table foreach (PDataLabelRow labelRow in FMainDS.PDataLabel.Rows) { string usedBy = String.Empty; int key = labelRow.Key; DataRow[] rows = FExtraDS.PDataLabelUse.Select("p_data_label_key_i=" + key.ToString()); foreach (PDataLabelUseRow useRow in rows) { if (usedBy != String.Empty) { usedBy += ","; } usedBy += useRow.Use; // Update the value of our MaxIdx1Value variable if (useRow.Idx1 > MaxIdx1Value) { MaxIdx1Value = useRow.Idx1; } } // Initially our two new columns hold the same values, but if we make a change we modify the second one. labelRow[UsedByColumnOrdinal - 1] = usedBy; // since we added this column manually, it does not have a handy property labelRow[UsedByColumnOrdinal] = usedBy; // since we added this column manually, it does not have a handy property if (usedBy.IndexOf("personnel", StringComparison.InvariantCultureIgnoreCase) >= 0) { labelRow[ContextColumnOrdinal] = (int)Context.Personnel; } else if (usedBy.IndexOf("termapp", StringComparison.InvariantCultureIgnoreCase) >= 0) { labelRow[ContextColumnOrdinal] = (int)Context.Application; } else { labelRow[ContextColumnOrdinal] = (int)Context.Partner; } } // So now our main data set has everything we need // But the grid doesn't know about our new column yet // We do that in 'RunOnceOnActivationManual()' // Set the form title and list box content depending on our context if (CurrentContext == Context.Partner) { this.Text = "Maintain Local Partner Data Fields"; AddRowToUsedByList("Person", Catalog.GetString("Person")); AddRowToUsedByList("Family", Catalog.GetString("Family")); AddRowToUsedByList("Church", Catalog.GetString("Church")); AddRowToUsedByList("Organisation", Catalog.GetString("Organisation")); AddRowToUsedByList("Bank", Catalog.GetString("Bank")); AddRowToUsedByList("Unit", Catalog.GetString("Unit")); AddRowToUsedByList("Venue", Catalog.GetString("Venue")); } else if (CurrentContext == Context.Application) { this.Text = "Maintain Local Application Data Fields"; AddRowToUsedByList("LongTermApp", Catalog.GetString("Long Term")); AddRowToUsedByList("ShortTermApp", Catalog.GetString("Short Term")); } else if (CurrentContext == Context.Personnel) { this.Text = "Maintain Local Personnel Data Fields"; AddRowToUsedByList("Personnel", Catalog.GetString("Personnel")); clbUsedBy.Visible = false; } // Need to run this to ensure that the Form's Title gets prefixed with 'Read-Only: ' as the Form's title // was overwritten just above FPetraUtilsObject.SetScreenCaption(); //Set up our checked list box columns and bind to our DTUsedBy table clbUsedBy.AddCheckBoxColumn(GUIUsedBy, DTUsedBy.Columns[0], 17, false); clbUsedBy.AddTextColumn(GUICol2, DTUsedBy.Columns[2], 169); clbUsedBy.DataBindGrid(DTUsedBy, DBCol3, DBCol1, DBCol2, false, false, false); FPetraUtilsObject.SetStatusBarText(clbUsedBy, Catalog.GetString("Choose the screens when this label will be used")); // Now we have to deal with the form controls that depend on the selection of DataType // and we only want one visible at a time - so hide these three pnlCurrencyCode.Visible = false; pnlLookupCategoryCode.Visible = false; pnlNumDecimalPlaces.Visible = false; // We can prevent screen 'flicker' by setting the DefaultView RowFilter to some stupid setting that finds no rows // This stops the auto-genertaed code populating the list with incorrect data before we get it right in our code // that runs later (RunOnceOnActivationManual) // Actually this line was added after completing the rest of the code. Having added it I could probably // remove a few lines elsewhere, but I am not going to because I don't want to break anything! FMainDS.PDataLabel.DefaultView.RowFilter = "Context=0"; // We need to capture the 'DataSaved' event, so we can save our Extra DataSet FPetraUtilsObject.DataSaved += new TDataSavedHandler(FPetraUtilsObject_DataSaved); FPetraUtilsObject.DataSavingStarted += new TDataSavingStartHandler(FPetraUtilsObject_DataSavingStarted); }