/// <summary> /// Called during loading of the form /// Adds the available labels to the Selection box. /// </summary> private void SetLocalDataLabels() { double widthInCm; PDataLabelTable DataLabels; PDataLabelUseTable DataLabelUse; DataRow[] filteredRows; DataLabels = (PDataLabelTable)TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.DataLabelList); DataLabelUse = (PDataLabelUseTable)TDataCache.TMPartner.GetCacheablePartnerTable(TCacheablePartnerTablesEnum.DataLabelUseList); foreach (PDataLabelUseRow UseRow in DataLabelUse.Rows) { if ((UseRow.Use == "Bank") || (UseRow.Use == "Church") || (UseRow.Use == "Family") || (UseRow.Use == "Organisation") || (UseRow.Use == "Person") || (UseRow.Use == "Unit") || (UseRow.Use == "Venue")) { filteredRows = DataLabels.Select(PDataLabelTable.GetKeyDBName() + " = " + UseRow.DataLabelKey.ToString()); if (filteredRows.Length > 0) { PDataLabelRow row = (PDataLabelRow)filteredRows[0]; if (row.DataType == "char") { widthInCm = TPartnerColumnFunction.CharLengthToCM(row.CharLength); } else if (row.DataType == "partnerkey") { widthInCm = TPartnerColumnFunction.CharLengthToCM(10); } else if (row.DataType == "lookup") { widthInCm = TPartnerColumnFunction.CharLengthToCM(14); } else if (row.DataType == "boolean") { widthInCm = TPartnerColumnFunction.CharLengthToCM(5); } else { widthInCm = TPartnerColumnFunction.CharLengthToCM(10); } /* minimum width of column, so that the caption can be displayed (with a footnote number if necessary) */ if (widthInCm < 1.5) { widthInCm = 1.5; } FPetraUtilsObject.AddAvailableFunction(new TPartnerColumnFunction("DataLabelColumn", "param_label", row.Text, widthInCm)); //FPetraUtilsObject.AddAvailableFunction(new TPartnerColumnFunction(row.Text, "param_label", // "DataLabelColumn", widthInCm)); } } } }
/// create new PM data public static PDataLabelTable CreateNewPMData(long AFromPartnerKey, long AToPartnerKey, IndividualDataTDS AMainDS, TDataBase ADataBase = null) { TDataBase db = DBAccess.Connect("CreateNewPMData", ADataBase); TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.ReadCommitted); // Create a new DataLabel record PDataLabelTable AllDataLabelTable = PDataLabelAccess.LoadAll(Transaction); PDataLabelTable DataLabelTable = new PDataLabelTable(); PDataLabelRow DataLabelRow = DataLabelTable.NewRowTyped(); // Get the first available key, which is our unique primary key field Int32 Key = 1; while (AllDataLabelTable.Rows.Find(new object[] { Key }) != null) { Key++; } DataLabelRow.Key = Key; DataLabelRow.DataType = "char"; DataLabelTable.Rows.Add(DataLabelRow); // Create a new DataLabelValuePartner record PDataLabelValuePartnerRow DataLabelValuePartner = AMainDS.PDataLabelValuePartner.NewRowTyped(); DataLabelValuePartner.PartnerKey = AFromPartnerKey; DataLabelValuePartner.DataLabelKey = DataLabelRow.Key; AMainDS.PDataLabelValuePartner.Rows.Add(DataLabelValuePartner); // Create a new PassportDetails record IndividualDataTDSPmPassportDetailsRow PassportDetails = AMainDS.PmPassportDetails.NewRowTyped(); PassportDetails.PartnerKey = AFromPartnerKey; PassportDetails.PassportNumber = "0"; PassportDetails.PassportNationalityName = "IRELAND"; AMainDS.PmPassportDetails.Rows.Add(PassportDetails); // Create two new PersonalData records PmPersonalDataRow FromPersonalData = AMainDS.PmPersonalData.NewRowTyped(); FromPersonalData.PartnerKey = AFromPartnerKey; FromPersonalData.HeightCm = 175; FromPersonalData.WeightKg = 80; AMainDS.PmPersonalData.Rows.Add(FromPersonalData); PmPersonalDataRow ToPersonalData = AMainDS.PmPersonalData.NewRowTyped(); ToPersonalData.PartnerKey = AToPartnerKey; ToPersonalData.WeightKg = 95; AMainDS.PmPersonalData.Rows.Add(ToPersonalData); Transaction.Rollback(); return(DataLabelTable); }
private bool DeleteRowManual(PDataLabelRow ARowToDelete, ref string ACompletionMessage) { bool ReturnValue = false; // We need to delete the rows in PDataLabelUse that reference the current row int key = ARowToDelete.Key; DataRow[] MatchingRows = FExtraDS.PDataLabelUse.Select("p_data_label_key_i=" + key.ToString()); foreach (DataRow row in MatchingRows) { row.Delete(); } // Now we can delete the row in the main table ARowToDelete.Delete(); ReturnValue = true; return(ReturnValue); }
private void ValidateDataDetailsManual(PDataLabelRow ARow) { // For this validation we have to validate the UsedBy data here in the manual code. // This is because it is not backed directly by a row in a data table. // Nor is the control associated with a column in any data table TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; DataColumn ValidationColumn; TVerificationResult VerificationResult = null; // Personnel context is bound to be valid because it has no UsedBy UI if ((CurrentContext == Context.Partner) || (CurrentContext == Context.Application)) { // The added column at the end of the table, which is a concatenated string of checkedListBox entries, must not be empty ValidationColumn = ARow.Table.Columns[UsedByColumnOrdinal]; VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow[UsedByColumnOrdinal].ToString(), GUIUsedBy, this, ValidationColumn, clbUsedBy); if (VerificationResult != null) { if (CurrentContext == Context.Partner) { VerificationResult.OverrideResultText(Catalog.GetString("You must check at least one box in the list of Partner classes.")); } else if (CurrentContext == Context.Application) { VerificationResult.OverrideResultText(Catalog.GetString("You must check at least one box in the list of Application types.")); } } // Handle addition to/removal from TVerificationResultCollection. VerificationResultCollection.Auto_Add_Or_AddOrRemove(this, VerificationResult, ValidationColumn, false); } // Now call the central validation routine for the other verification tasks TSharedValidation_CacheableDataTables.ValidateLocalDataFieldSetup(this, ARow, ref VerificationResultCollection, FPetraUtilsObject.ValidationControlsDict); }
private bool PreDeleteManual(PDataLabelRow ARowToDelete, ref string ADeletionQuestion) { string question = ADeletionQuestion; question += (Environment.NewLine + Environment.NewLine + "("); if (txtDetailGroup.Text.Length > 0) { question += String.Format("{0}: {1}, ", Catalog.GetString("Group"), txtDetailGroup.Text); } question += String.Format("{0} {1})", lblDetailText.Text, txtDetailText.Text); int classesCount = ARowToDelete[UsedByColumnOrdinal].ToString().Split(new char[] { ',' }).Length; string s = Catalog.GetPluralString("{0}{0}This {1} is used in {2} Partner Class", "{0}{0}This {1} is used in {2} Partner Classes", classesCount); question += String.Format(s, Environment.NewLine, lblDetailText.Text.Substring(0, lblDetailText.Text.Length - 1), classesCount); ADeletionQuestion = question; return(true); }
/// <summary> /// returns true if the value of the cell is null /// </summary> /// <param name="ADataLabelRow"></param> /// <param name="ARow"></param> /// <param name="AColumn"></param> /// <returns></returns> private Boolean IsCellValueNull(PDataLabelRow ADataLabelRow, int ARow, int AColumn) { Boolean ReturnValue = false; System.Windows.Forms.Control CurrentControl; switch (ADataLabelRow.DataType) { case MCommonConstants.OFFICESPECIFIC_DATATYPE_CHAR: CurrentControl = (System.Windows.Forms.Control)((SourceGrid.Cells.Cell)FLocalDataLabelValuesGrid.GetCell(ARow, AColumn)).Tag; if (((System.Windows.Forms.TextBox)CurrentControl).Text.Trim() == "") { ReturnValue = true; } break; case MCommonConstants.OFFICESPECIFIC_DATATYPE_FLOAT: case MCommonConstants.OFFICESPECIFIC_DATATYPE_INTEGER: case MCommonConstants.OFFICESPECIFIC_DATATYPE_CURRENCY: CurrentControl = (System.Windows.Forms.Control)((SourceGrid.Cells.Cell)FLocalDataLabelValuesGrid.GetCell(ARow, AColumn)).Tag; if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CURRENCY) { if (((TTxtCurrencyTextBox)CurrentControl).Text.Trim() == "") { ReturnValue = true; } } else if (((TTxtNumericTextBox)CurrentControl).Text.Trim() == "") { ReturnValue = true; } break; case MCommonConstants.OFFICESPECIFIC_DATATYPE_DATE: CurrentControl = (System.Windows.Forms.Control)((SourceGrid.Cells.Cell)FLocalDataLabelValuesGrid.GetCell(ARow, AColumn)).Tag; if (((TtxtPetraDate)CurrentControl).Text.Trim() == "") { ReturnValue = true; } break; case MCommonConstants.OFFICESPECIFIC_DATATYPE_BOOLEAN: // can't determine at the moment if "unchecked" is set on purpose ReturnValue = false; break; case MCommonConstants.OFFICESPECIFIC_DATATYPE_PARTNERKEY: CurrentControl = (System.Windows.Forms.Control)((SourceGrid.Cells.Cell)FLocalDataLabelValuesGrid.GetCell(ARow, AColumn)).Tag; if ((((TtxtAutoPopulatedButtonLabel)CurrentControl).Text.Trim() == "") || (Convert.ToInt64(((TtxtAutoPopulatedButtonLabel)CurrentControl).Text) == 0)) { ReturnValue = true; } break; case MCommonConstants.OFFICESPECIFIC_DATATYPE_LOOKUP: CurrentControl = (System.Windows.Forms.Control)((SourceGrid.Cells.Cell)FLocalDataLabelValuesGrid.GetCell(ARow, AColumn)).Tag; if (((TCmbAutoPopulated)CurrentControl).GetSelectedString().Trim() == "") { ReturnValue = true; } break; default: break; } return ReturnValue; }
private void NewRowManual(ref PDataLabelRow ARow) { // Get the first available key, which is our unique primary key field // Note that this field is not displayed - it is internal to the DB Int32 labelKey = 1; while (FMainDS.PDataLabel.Rows.Find(new object[] { labelKey }) != null) { labelKey++; } ARow.Key = labelKey; // Initialise the other values that always apply to new records ARow.Text = Catalog.GetString("NewLabel"); ARow[ContextColumnOrdinal] = (int)CurrentContext; ARow[UsedByColumnOrdinal - 1] = String.Empty; // Now initialise other values PDataLabelRow CurrentRow = GetSelectedDetailRow(); DTUsedBy.DefaultView.AllowEdit = true; if (CurrentRow == null) { // This is the first row of an empty grid // Default to a char type ARow.DataType = "char"; ARow.CharLength = DefaultCharLength; ARow.Group = String.Empty; txtDetailNumDecimalPlaces.NumberValueInt = DefaultNumDecimalPlaces; cmbDetailCurrencyCode.SetSelectedString(DefaultCurrencyCode); cmbDetailLookupCategoryCode.SelectedIndex = (cmbDetailLookupCategoryCode.Count > 0) ? 0 : -1; switch (CurrentContext) { case Context.Partner: ARow[UsedByColumnOrdinal] = DefaultPartnerUsedBy; break; case Context.Application: ARow[UsedByColumnOrdinal] = DefaultApplicationUsedBy; break; case Context.Personnel: ARow[UsedByColumnOrdinal] = DefaultPersonnelUsedBy; break; } // Check all the boxes clbUsedBy.SetCheckedStringList(clbUsedBy.GetAllStringList(true)); } else { // New row in a grid that has existing rows, so default to values from the current row GetDetailsFromControls(CurrentRow); ARow.Group = CurrentRow.Group; ARow.DataType = CurrentRow.DataType; int VisibleIndex = -1; if (String.Compare(ARow.DataType, "char", true) == 0) { if (!CurrentRow.IsCharLengthNull()) { ARow.CharLength = CurrentRow.CharLength; VisibleIndex = 0; } } else if (String.Compare(ARow.DataType, "float", true) == 0) { if (!CurrentRow.IsNumDecimalPlacesNull()) { ARow.NumDecimalPlaces = CurrentRow.NumDecimalPlaces; VisibleIndex = 1; } } else if (String.Compare(ARow.DataType, "currency", true) == 0) { if (!CurrentRow.IsCurrencyCodeNull()) { ARow.CurrencyCode = CurrentRow.CurrencyCode; VisibleIndex = 2; } } else if (String.Compare(ARow.DataType, "lookup", true) == 0) { if (!CurrentRow.IsLookupCategoryCodeNull()) { ARow.LookupCategoryCode = CurrentRow.LookupCategoryCode; VisibleIndex = 6; } } // Now set the hidden fields to default values in case the user selects them if (VisibleIndex != 0) { txtDetailCharLength.NumberValueInt = DefaultCharLength; } if (VisibleIndex != 1) { txtDetailNumDecimalPlaces.NumberValueInt = DefaultNumDecimalPlaces; } if (VisibleIndex != 2) { cmbDetailCurrencyCode.SetSelectedString(DefaultCurrencyCode); } if (VisibleIndex != 6) { cmbDetailLookupCategoryCode.SelectedIndex = (cmbDetailLookupCategoryCode.Count > 0) ? 0 : -1; } ARow[UsedByColumnOrdinal] = clbUsedBy.GetCheckedStringList(); } }
/// <summary> /// Get or create a data column for a given data label /// /// </summary> /// <returns>void</returns> private void GetOrCreateDataLabelValueRow(Boolean ACreateIfNotExisting, PDataLabelRow ADataLabelRow, out PDataLabelValuePartnerRow ADataLabelValuePartnerRow, out PDataLabelValueApplicationRow ADataLabelValueApplicationRow) { // Find out whether this Partner has already got a value for this Label and put // it into the corresponding table or create a new row if it does not exist yet ADataLabelValuePartnerRow = null; ADataLabelValueApplicationRow = null; switch (FOfficeSpecificDataLabelUse) { case TOfficeSpecificDataLabelUseEnum.Person: case TOfficeSpecificDataLabelUseEnum.Family: case TOfficeSpecificDataLabelUseEnum.Church: case TOfficeSpecificDataLabelUseEnum.Organisation: case TOfficeSpecificDataLabelUseEnum.Unit: case TOfficeSpecificDataLabelUseEnum.Bank: case TOfficeSpecificDataLabelUseEnum.Venue: case TOfficeSpecificDataLabelUseEnum.Personnel: ADataLabelValuePartnerRow = (PDataLabelValuePartnerRow)FDataLabelValuePartnerDT.Rows.Find(new Object[] { FPartnerKey, ADataLabelRow.Key }); // if value record does not exist yet then create it here if ((ADataLabelValuePartnerRow == null) && ACreateIfNotExisting) { ADataLabelValuePartnerRow = FDataLabelValuePartnerDT.NewRowTyped(true); ADataLabelValuePartnerRow.PartnerKey = FPartnerKey; ADataLabelValuePartnerRow.DataLabelKey = (int)ADataLabelRow.Key; FDataLabelValuePartnerDT.Rows.Add(ADataLabelValuePartnerRow); } break; case TOfficeSpecificDataLabelUseEnum.LongTermApp: case TOfficeSpecificDataLabelUseEnum.ShortTermApp: ADataLabelValueApplicationRow = (PDataLabelValueApplicationRow)FDataLabelValueApplicationDT.Rows.Find(new Object[] { FPartnerKey, FApplicationKey, FRegistrationOffice, ADataLabelRow.Key }); // if value record does not exist yet then create it here if ((ADataLabelValueApplicationRow == null) && ACreateIfNotExisting) { ADataLabelValueApplicationRow = FDataLabelValueApplicationDT.NewRowTyped(true); ADataLabelValueApplicationRow.PartnerKey = FPartnerKey; ADataLabelValueApplicationRow.ApplicationKey = FApplicationKey; ADataLabelValueApplicationRow.RegistrationOffice = FRegistrationOffice; ADataLabelValueApplicationRow.DataLabelKey = (int)ADataLabelRow.Key; FDataLabelValueApplicationDT.Rows.Add(ADataLabelValueApplicationRow); } break; } }
private void RunOnceOnActivationManual() { // Set up the window title if (String.Compare(Context, "Bank", true) == 0) { this.Text += Catalog.GetString(" For Bank"); } else if (String.Compare(Context, "Church", true) == 0) { this.Text += Catalog.GetString(" For Church"); } else if (String.Compare(Context, "Family", true) == 0) { this.Text += Catalog.GetString(" For Family"); } else if (String.Compare(Context, "Organisation", true) == 0) { this.Text += Catalog.GetString(" For Organisation"); } else if (String.Compare(Context, "Person", true) == 0) { this.Text += Catalog.GetString(" For Person"); } else if (String.Compare(Context, "Unit", true) == 0) { this.Text += Catalog.GetString(" For Unit"); } else if (String.Compare(Context, "Venue", true) == 0) { this.Text += Catalog.GetString(" For Venue"); } else if (String.Compare(Context, "LongTermApp", true) == 0) { this.Text += Catalog.GetString(" For Long Term Applications"); } else if (String.Compare(Context, "ShortTermApp", true) == 0) { this.Text += Catalog.GetString(" For Short Term Applications"); } else if (String.Compare(Context, "Personnel", true) == 0) { this.Text += Catalog.GetString(" For Personnel"); } // Initialize 'Helper Class' for handling the Indexes of the DataRows. FIndexedGridRowsHelper = new TSgrdDataGrid.IndexedGridRowsHelper( grdDetails, PDataLabelUseTable.ColumnIdx1Id, btnDemote, btnPromote, delegate { FPetraUtilsObject.SetChangedFlag(); }); // Load the Extra Data from DataLabel table Type DataTableType; FExtraDS.PDataLabel = new PDataLabelTable(); DataTable CacheDT = TDataCache.GetCacheableDataTableFromCache("DataLabelList", String.Empty, null, out DataTableType); FExtraDS.PDataLabel.Merge(CacheDT); // Extend our main DataLabelUse table int NameOrdinal = FMainDS.PDataLabelUse.Columns.Add("Name", typeof(String)).Ordinal; int GroupOrdinal = FMainDS.PDataLabelUse.Columns.Add("GroupHeading", typeof(String)).Ordinal; int DescriptionOrdinal = FMainDS.PDataLabelUse.Columns.Add("Description", typeof(String)).Ordinal; // Take each row of our main dataset and populate the new columns with relevant data // from the DataLabelUse table foreach (PDataLabelUseRow useRow in FMainDS.PDataLabelUse.Rows) { PDataLabelRow labelRow = (PDataLabelRow)FExtraDS.PDataLabel.Rows.Find(new object[] { useRow.DataLabelKey }); useRow[NameOrdinal] = labelRow.Text; useRow[GroupOrdinal] = labelRow.Group; useRow[DescriptionOrdinal] = labelRow.Description; } // Add columns to the grid for the label details grdDetails.AddTextColumn(Catalog.GetString("Name"), FMainDS.PDataLabelUse.Columns[NameOrdinal]); grdDetails.AddTextColumn(Catalog.GetString("Group Heading"), FMainDS.PDataLabelUse.Columns[GroupOrdinal]); grdDetails.AddTextColumn(Catalog.GetString("Description"), FMainDS.PDataLabelUse.Columns[DescriptionOrdinal]); grdDetails.Selection.SelectionChanged += HandleSelectionChanged; // Remove the first column. We added this in the YAML so that the auto-generator had something to do grdDetails.Columns.Remove(0); grdDetails.SetHeaderTooltip(0, Catalog.GetString("Name")); grdDetails.SetHeaderTooltip(1, Catalog.GetString("Group Heading")); grdDetails.SetHeaderTooltip(2, Catalog.GetString("Description")); // Create a view that will only show the rows applicable to our currentContext DataView contextView = new DataView(FMainDS.PDataLabelUse, "p_use_c='" + Context + "'", "p_idx1_i", DataViewRowState.CurrentRows); contextView.AllowNew = false; // Bind the view to our grid grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(contextView); grdDetails.Refresh(); SelectRowInGrid(1); }
private void ShowDetailsManual(PDataLabelRow ARow) { // In this special case we have to handle an empty grid differently from normal // Because we applied a rowFilter to the dataset during activation, the panel may contain initial information // about a row that has now been filtered out. if (ARow == null) { txtDetailText.Text = String.Empty; txtDetailGroup.Text = String.Empty; cmbDetailDataType.SelectedIndex = 0; txtDetailCharLength.NumberValueInt = DefaultCharLength; txtDetailDescription.Text = String.Empty; pnlDetails.Enabled = false; return; } int defaultCategoryCode = (cmbDetailLookupCategoryCode.Count > 0) ? 0 : -1; // Now 'translate' the database values like 'float' to comboBox values like 'Number' if (String.Compare(ARow.DataType, "float", true) == 0) { cmbDetailDataType.SelectedIndex = 1; } else if (String.Compare(ARow.DataType, "currency", true) == 0) { cmbDetailDataType.SelectedIndex = 2; } else if (String.Compare(ARow.DataType, "boolean", true) == 0) { cmbDetailDataType.SelectedIndex = 3; } else if (String.Compare(ARow.DataType, "date", true) == 0) { cmbDetailDataType.SelectedIndex = 4; } else if (String.Compare(ARow.DataType, "time", true) == 0) { cmbDetailDataType.SelectedIndex = 5; } else if (String.Compare(ARow.DataType, "lookup", true) == 0) { cmbDetailDataType.SelectedIndex = 6; } else if (String.Compare(ARow.DataType, "partnerkey", true) == 0) { cmbDetailDataType.SelectedIndex = 7; } else { // Use char cmbDetailDataType.SelectedIndex = 0; } // Initialise the hidden controls to something sensible, in case they get shown if (cmbDetailDataType.SelectedIndex != 0) { txtDetailCharLength.NumberValueInt = DefaultCharLength; } if (cmbDetailDataType.SelectedIndex != 1) { txtDetailNumDecimalPlaces.NumberValueInt = DefaultNumDecimalPlaces; } if (cmbDetailDataType.SelectedIndex != 2) { cmbDetailCurrencyCode.SetSelectedString(DefaultCurrencyCode); } if (cmbDetailDataType.SelectedIndex != 6) { cmbDetailLookupCategoryCode.SelectedIndex = defaultCategoryCode; } // Set the checkboxes in the UsedBy list DTUsedBy.DefaultView.AllowEdit = true; clbUsedBy.SetCheckedStringList(ARow[UsedByColumnOrdinal].ToString()); }
/// <summary> /// Validates the MCommon Local Data Field Setup screen data. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> public static void ValidateLocalDataFieldSetup(object AContext, PDataLabelRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult = null; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // If the 'DataType' is 'lookup' then categoryCode cannot be empty string (which would indicate no entries in the DataLabelCategory DB table) VerificationResult = null; ValidationColumn = ARow.Table.Columns[PDataLabelTable.ColumnLookupCategoryCodeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (String.Compare(ARow.DataType, "lookup", true) == 0) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.LookupCategoryCode, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); if (VerificationResult != null) { VerificationResult.OverrideResultText(Catalog.GetString( "You cannot use the option list until you have defined at least one option using the 'Local Data Option List Names' main menu selection")); } } // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
private void GetDetailDataFromControlsManual(PDataLabelRow ARow) { // Translate comboBox items like 'Number' back to database entries like 'float' // and make sure that unused fields in the database are set to null (where controls are currently hidden) switch (cmbDetailDataType.SelectedIndex) { case 1: ARow.DataType = "float"; break; case 2: ARow.DataType = "currency"; break; case 3: ARow.DataType = "boolean"; break; case 4: ARow.DataType = "date"; break; case 5: ARow.DataType = "time"; break; case 6: ARow.DataType = "lookup"; break; case 7: ARow.DataType = "partnerkey"; break; default: ARow.DataType = "char"; break; } // Set all fields to null where the control is not visible, because the information is not required if (!txtDetailCharLength.Visible) { ARow.SetCharLengthNull(); } if (!txtDetailNumDecimalPlaces.Visible) { ARow.SetNumDecimalPlacesNull(); } if (!cmbDetailCurrencyCode.Visible) { ARow.SetCurrencyCodeNull(); } if (!cmbDetailLookupCategoryCode.Visible) { ARow.SetLookupCategoryCodeNull(); } // Get the checked items from the UsedBy ListBox and update our UsedBy column ARow[UsedByColumnOrdinal] = clbUsedBy.GetCheckedStringList(); }
private bool DeleteRowManual(PDataLabelRow ARowToDelete, ref string ACompletionMessage) { bool ReturnValue = false; // We need to delete the rows in PDataLabelUse that reference the current row int key = ARowToDelete.Key; DataRow[] MatchingRows = FExtraDS.PDataLabelUse.Select("p_data_label_key_i=" + key.ToString()); foreach (DataRow row in MatchingRows) { row.Delete(); } // Now we can delete the row in the main table ARowToDelete.Delete(); ReturnValue = true; return ReturnValue; }
private bool PreDeleteManual(PDataLabelRow ARowToDelete, ref string ADeletionQuestion) { string question = ADeletionQuestion; question += (Environment.NewLine + Environment.NewLine + "("); if (txtDetailGroup.Text.Length > 0) { question += String.Format("{0}: {1}, ", Catalog.GetString("Group"), txtDetailGroup.Text); } question += String.Format("{0} {1})", lblDetailText.Text, txtDetailText.Text); int classesCount = ARowToDelete[UsedByColumnOrdinal].ToString().Split(new char[] { ',' }).Length; string s = Catalog.GetPluralString("{0}{0}This {1} is used in {2} Partner Class", "{0}{0}This {1} is used in {2} Partner Classes", classesCount); question += String.Format(s, Environment.NewLine, lblDetailText.Text.Substring(0, lblDetailText.Text.Length - 1), classesCount); ADeletionQuestion = question; return true; }
private void NewRowManual(ref PDataLabelRow ARow) { // Get the first available key, which is our unique primary key field // Note that this field is not displayed - it is internal to the DB Int32 labelKey = 1; while (FMainDS.PDataLabel.Rows.Find(new object[] { labelKey }) != null) { labelKey++; } ARow.Key = labelKey; // Initialise the other values that always apply to new records ARow.Text = Catalog.GetString("NewLabel"); ARow[ContextColumnOrdinal] = (int)CurrentContext; ARow[UsedByColumnOrdinal - 1] = String.Empty; // Now initialise other values PDataLabelRow CurrentRow = GetSelectedDetailRow(); DTUsedBy.DefaultView.AllowEdit = true; if (CurrentRow == null) { // This is the first row of an empty grid // Default to a char type ARow.DataType = "char"; ARow.CharLength = DefaultCharLength; ARow.Group = String.Empty; txtDetailNumDecimalPlaces.NumberValueInt = DefaultNumDecimalPlaces; cmbDetailCurrencyCode.SetSelectedString(DefaultCurrencyCode); cmbDetailLookupCategoryCode.SelectedIndex = (cmbDetailLookupCategoryCode.Count > 0) ? 0 : -1; switch (CurrentContext) { case Context.Partner: ARow[UsedByColumnOrdinal] = DefaultPartnerUsedBy; break; case Context.Application: ARow[UsedByColumnOrdinal] = DefaultApplicationUsedBy; break; case Context.Personnel: ARow[UsedByColumnOrdinal] = DefaultPersonnelUsedBy; break; } // Check all the boxes clbUsedBy.SetCheckedStringList(clbUsedBy.GetAllStringList()); } else { // New row in a grid that has existing rows, so default to values from the current row GetDetailsFromControls(CurrentRow); ARow.Group = CurrentRow.Group; ARow.DataType = CurrentRow.DataType; int VisibleIndex = -1; if (String.Compare(ARow.DataType, "char", true) == 0) { if (!CurrentRow.IsCharLengthNull()) { ARow.CharLength = CurrentRow.CharLength; VisibleIndex = 0; } } else if (String.Compare(ARow.DataType, "float", true) == 0) { if (!CurrentRow.IsNumDecimalPlacesNull()) { ARow.NumDecimalPlaces = CurrentRow.NumDecimalPlaces; VisibleIndex = 1; } } else if (String.Compare(ARow.DataType, "currency", true) == 0) { if (!CurrentRow.IsCurrencyCodeNull()) { ARow.CurrencyCode = CurrentRow.CurrencyCode; VisibleIndex = 2; } } else if (String.Compare(ARow.DataType, "lookup", true) == 0) { if (!CurrentRow.IsLookupCategoryCodeNull()) { ARow.LookupCategoryCode = CurrentRow.LookupCategoryCode; VisibleIndex = 6; } } // Now set the hidden fields to default values in case the user selects them if (VisibleIndex != 0) { txtDetailCharLength.NumberValueInt = DefaultCharLength; } if (VisibleIndex != 1) { txtDetailNumDecimalPlaces.NumberValueInt = DefaultNumDecimalPlaces; } if (VisibleIndex != 2) { cmbDetailCurrencyCode.SetSelectedString(DefaultCurrencyCode); } if (VisibleIndex != 6) { cmbDetailLookupCategoryCode.SelectedIndex = (cmbDetailLookupCategoryCode.Count > 0) ? 0 : -1; } ARow[UsedByColumnOrdinal] = clbUsedBy.GetCheckedStringList(); } }
/// <summary> /// Sets up the value cell(s) for a specific data label /// /// </summary> /// <returns>void</returns> private void SetupGridValueCell(Int32 ARowIndex, PDataLabelRow ADataLabelRow) { Control cellControl; System.Windows.Forms.TextBox TextBoxEditor; TtxtPetraDate DateEditor; System.Windows.Forms.CheckBox CheckBoxEditor; TTxtNumericTextBox TextBoxNumericEditor; TTxtCurrencyTextBox TextBoxCurrencyEditor; TCmbAutoPopulated LookupValueEditor; TtxtAutoPopulatedButtonLabel PartnerKeyEditor; SourceGrid.Cells.Views.Cell ValueModel; SourceGrid.Cells.Views.Cell SuffixModel; PDataLabelValuePartnerRow DataLabelValuePartnerRow; PDataLabelValueApplicationRow DataLabelValueApplicationRow; // prepare model for the value cells ValueModel = new SourceGrid.Cells.Views.Cell(); ValueModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft; ValueModel.Font = new Font(FLocalDataLabelValuesGrid.Font.FontFamily.Name, FLocalDataLabelValuesGrid.Font.Size, FontStyle.Bold); // prepare model for suffix cells (e.g. for currency) SuffixModel = new SourceGrid.Cells.Views.Cell(); SuffixModel.BackColor = FLocalDataLabelValuesGrid.BackColor; SuffixModel.TextAlignment = DevAge.Drawing.ContentAlignment.MiddleLeft; // In this case the data value rows will only be created once a value is entered GetOrCreateDataLabelValueRow(false, ADataLabelRow, out DataLabelValuePartnerRow, out DataLabelValueApplicationRow); // initialize cell control cellControl = null; // Create field, according to specified data type // Create character field if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CHAR) { TextBoxEditor = new System.Windows.Forms.TextBox(); cellControl = TextBoxEditor; if (DataLabelValuePartnerRow != null) { TextBoxEditor.Text = DataLabelValuePartnerRow.ValueChar; } else if (DataLabelValueApplicationRow != null) { TextBoxEditor.Text = DataLabelValueApplicationRow.ValueChar; } else { // Default value if no Label data exists for the Partner TextBoxEditor.Text = ""; } // enable save button in editor when cell contents have changed TextBoxEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxEditor; } // Create float field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_FLOAT) { TextBoxNumericEditor = new TTxtNumericTextBox(); if (ADataLabelRow.NumDecimalPlaces == 0) { TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.LongInteger; TextBoxNumericEditor.MaxLength = 14; } else { TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Decimal; TextBoxNumericEditor.DecimalPlaces = ADataLabelRow.NumDecimalPlaces; // limit text length. 14 for number of digits, 5 for decimal and thousands separators TextBoxNumericEditor.MaxLength = 14 + 5 + ADataLabelRow.NumDecimalPlaces; } TextBoxNumericEditor.NullValueAllowed = true; cellControl = TextBoxNumericEditor; if (ADataLabelRow.NumDecimalPlaces == 0) { if (DataLabelValuePartnerRow != null) { TextBoxNumericEditor.NumberValueLongInt = (long)DataLabelValuePartnerRow.ValueNum; } else if (DataLabelValueApplicationRow != null) { TextBoxNumericEditor.NumberValueLongInt = (long)DataLabelValueApplicationRow.ValueNum; } else { // Default value if no Label data exists for the Partner TextBoxNumericEditor.NumberValueLongInt = null; } } else { if (DataLabelValuePartnerRow != null) { TextBoxNumericEditor.NumberValueDecimal = DataLabelValuePartnerRow.ValueNum; } else if (DataLabelValueApplicationRow != null) { TextBoxNumericEditor.NumberValueDecimal = DataLabelValueApplicationRow.ValueNum; } else { // Default value if no Label data exists for the Partner TextBoxNumericEditor.NumberValueDecimal = null; } } // enable save button in editor when cell contents have changed TextBoxNumericEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxNumericEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxNumericEditor; } // Create data field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_DATE) { DateEditor = new TtxtPetraDate(); DateEditor.Date = null; cellControl = DateEditor; if (DataLabelValuePartnerRow != null) { if (!DataLabelValuePartnerRow.IsValueDateNull()) { DateEditor.Date = DataLabelValuePartnerRow.ValueDate; } } else if (DataLabelValueApplicationRow != null) { if (!DataLabelValueApplicationRow.IsValueDateNull()) { DateEditor.Date = DataLabelValueApplicationRow.ValueDate; } } // enable save button in editor when cell contents have changed DateEditor.DateChanged += new TPetraDateChangedEventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)DateEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = DateEditor; } // Create integer field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_INTEGER) { TextBoxNumericEditor = new TTxtNumericTextBox(); TextBoxNumericEditor.ControlMode = TTxtNumericTextBox.TNumericTextBoxMode.Integer; TextBoxNumericEditor.NullValueAllowed = true; cellControl = TextBoxNumericEditor; if (DataLabelValuePartnerRow != null) { TextBoxNumericEditor.NumberValueInt = DataLabelValuePartnerRow.ValueInt; } else if (DataLabelValueApplicationRow != null) { TextBoxNumericEditor.NumberValueInt = DataLabelValueApplicationRow.ValueInt; } else { // Default value if no Label data exists for the Partner TextBoxNumericEditor.NumberValueInt = null; } // enable save button in editor when cell contents have changed TextBoxNumericEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxNumericEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxNumericEditor; } // Create currency field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_CURRENCY) { TextBoxCurrencyEditor = new TTxtCurrencyTextBox(); TextBoxCurrencyEditor.DecimalPlaces = 2; TextBoxCurrencyEditor.CurrencyCode = ADataLabelRow.CurrencyCode; TextBoxCurrencyEditor.NullValueAllowed = true; cellControl = TextBoxCurrencyEditor; if (DataLabelValuePartnerRow != null) { TextBoxCurrencyEditor.NumberValueDecimal = DataLabelValuePartnerRow.ValueCurrency; } else if (DataLabelValueApplicationRow != null) { TextBoxCurrencyEditor.NumberValueDecimal = DataLabelValueApplicationRow.ValueCurrency; } else { // Default value if no Label data exists for the Partner TextBoxCurrencyEditor.NumberValueDecimal = null; } // enable save button in editor when cell contents have changed TextBoxCurrencyEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)TextBoxCurrencyEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = TextBoxCurrencyEditor; } // Create boolean field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_BOOLEAN) { CheckBoxEditor = new System.Windows.Forms.CheckBox(); cellControl = CheckBoxEditor; if (DataLabelValuePartnerRow != null) { CheckBoxEditor.Checked = DataLabelValuePartnerRow.ValueBool; } else if (DataLabelValueApplicationRow != null) { CheckBoxEditor.Checked = DataLabelValueApplicationRow.ValueBool; } else { // Default value if no Label data exists for the Partner CheckBoxEditor.Checked = false; } // enable save button in editor when cell contents have changed CheckBoxEditor.CheckedChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)CheckBoxEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = CheckBoxEditor; } // Create partner key field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_PARTNERKEY) { PartnerKeyEditor = new TtxtAutoPopulatedButtonLabel(); PartnerKeyEditor.ASpecialSetting = true; PartnerKeyEditor.ButtonText = ADataLabelRow.Text + ':'; PartnerKeyEditor.ButtonTextAlign = System.Drawing.ContentAlignment.MiddleRight; PartnerKeyEditor.ListTable = TtxtAutoPopulatedButtonLabel.TListTableEnum.PartnerKey; PartnerKeyEditor.TabStop = false; cellControl = PartnerKeyEditor; // AutomaticallyUpdateDataSource: very rare, but needed here PartnerKeyEditor.AutomaticallyUpdateDataSource = true; if (DataLabelValuePartnerRow != null) { PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(DataLabelValuePartnerRow.ValuePartnerKey); } else if (DataLabelValueApplicationRow != null) { PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(DataLabelValueApplicationRow.ValuePartnerKey); } else { // Default value if no Label data exists for the Partner PartnerKeyEditor.Text = StringHelper.PartnerKeyToStr(0); } // display partner name linked to partner key PartnerKeyEditor.ResetLabelText(); // enable save button in editor when cell contents have changed PartnerKeyEditor.ValueChanged += new TDelegatePartnerChanged(this.PartnerKeyControlValueHasChanged); PartnerKeyEditor.TextChanged += new System.EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 0] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue(PartnerKeyEditor, new Position(ARowIndex, 0))); FLocalDataLabelValuesGrid[ARowIndex, 0].Tag = PartnerKeyEditor; FLocalDataLabelValuesGrid[ARowIndex, 0].ColumnSpan = 3; } // Create lookup field else if (ADataLabelRow.DataType == MCommonConstants.OFFICESPECIFIC_DATATYPE_LOOKUP) { // Get the instance of the combobox (created in the actual user interface class) LookupValueEditor = new TCmbAutoPopulated(); LookupValueEditor.Filter = PDataLabelLookupTable.GetCategoryCodeDBName() + " = '" + ADataLabelRow.LookupCategoryCode + "'"; LookupValueEditor.ListTable = TCmbAutoPopulated.TListTableEnum.DataLabelLookupList; LookupValueEditor.InitialiseUserControl(); cellControl = LookupValueEditor; if (DataLabelValuePartnerRow != null) { LookupValueEditor.SetSelectedString(DataLabelValuePartnerRow.ValueLookup); } else if (DataLabelValueApplicationRow != null) { LookupValueEditor.SetSelectedString(DataLabelValueApplicationRow.ValueLookup); } else { // Default value if no Label data exists for the Partner LookupValueEditor.Text = ""; } // enable save button in editor when cell contents have changed LookupValueEditor.SelectedValueChanged += new EventHandler(this.ControlValueHasChanged); LookupValueEditor.TextChanged += new EventHandler(this.ControlValueHasChanged); FLocalDataLabelValuesGrid[ARowIndex, 1] = new SourceGrid.Cells.Cell(); FLocalDataLabelValuesGrid.LinkedControls.Add(new LinkedControlValue((Control)LookupValueEditor, new Position(ARowIndex, 1))); FLocalDataLabelValuesGrid[ARowIndex, 1].Tag = LookupValueEditor; FLocalDataLabelValuesGrid[ARowIndex, 1].ColumnSpan = 2; } // perform actions that need to be done for each control if (cellControl != null) { // remember the added control to get the value back lateron FGridRowInfo.SetControl(ARowIndex, cellControl); // handle focus change when field is entered cellControl.Enter += new EventHandler(this.UpdateGridFocusFromExternalControl); // set help text for control PetraUtilsObject.SetStatusBarText(cellControl, ADataLabelRow.Description); } // check if value is editable if (!ADataLabelRow.Editable) { FLocalDataLabelValuesGrid[ARowIndex, 1].Editor.EnableEdit = false; } }