/// <summary> /// show form as dialog with given parameters /// </summary> /// <param name="AMessage">Message to be displayed to the user</param> /// <param name="ACaption">Caption of the dialog window</param> /// <param name="AChkOptionText">Text to be shown with check box (check box hidden if text empty)</param> /// <param name="AButtons">Button set to be displayed</param> /// <param name="ADefaultButton">The button with a default action</param> /// <param name="AIcon">Icon to be displayed</param> /// <returns></returns> public TFrmExtendedMessageBox.TResult ShowDialog(string AMessage, string ACaption, string AChkOptionText, TFrmExtendedMessageBox.TButtons AButtons, TFrmExtendedMessageBox.TDefaultButton ADefaultButton, TFrmExtendedMessageBox.TIcon AIcon) { return(ShowDialog(AMessage, ACaption, AChkOptionText, AButtons, ADefaultButton, AIcon, false)); }
/// <summary> /// The main method to run a reference check on a single item of data /// </summary> /// <param name="APetraUtilsObject">The calling forms PetraUtils Object</param> /// <param name="AVerificationResults">The results collection to check</param> /// <param name="ALimitedCount">Will be true if the reference count call was a limited check</param> /// <returns>A message box result. Yes implies doing a new unlimited count, Undefined implies there are no references so deletion can proceed. /// Any other value implies that references exist</returns> public TFrmExtendedMessageBox.TResult HandleReferences(TFrmPetraEditUtils APetraUtilsObject, TVerificationResultCollection AVerificationResults, bool ALimitedCount) { Form MyForm = APetraUtilsObject.GetForm(); // There were reference(s) TRowReferenceInfo info = (TRowReferenceInfo)AVerificationResults[0].ResultContext; bool bIncomplete = info.CascadingCountEndedEarly; // Build up a message string string msgContent = Messages.BuildMessageFromVerificationResult( MCommonResourcestrings.StrRecordCannotBeDeleted + Environment.NewLine + Catalog.GetPluralString(MCommonResourcestrings.StrReasonColon, MCommonResourcestrings.StrReasonsColon, AVerificationResults.Count), AVerificationResults); TFrmExtendedMessageBox.TButtons buttons = TFrmExtendedMessageBox.TButtons.embbOK; TFrmExtendedMessageBox.TDefaultButton defButton = TFrmExtendedMessageBox.TDefaultButton.embdDefButton1; if (bIncomplete && ALimitedCount) { msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarly1, Environment.NewLine, APetraUtilsObject.MaxReferenceCountOnDelete); msgContent += MCommonResourcestrings.StrCountTerminatedEarly2; msgContent += MCommonResourcestrings.StrCountTerminatedEarly3; msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarly4, Environment.NewLine, MyForm.Text); buttons = TFrmExtendedMessageBox.TButtons.embbYesNo; defButton = TFrmExtendedMessageBox.TDefaultButton.embdDefButton2; } else { if (bIncomplete) { // We should never get an incomplete count on an unlimited check } msgContent += String.Format(MCommonResourcestrings.StrCountTerminatedEarlyOK, Environment.NewLine); } // Show an Extended Message Box and return the value TFrmExtendedMessageBox extendedMsgBox = new TFrmExtendedMessageBox(MyForm); return(extendedMsgBox.ShowDialog( msgContent, MCommonResourcestrings.StrRecordDeletionTitle, String.Empty, buttons, defButton, TFrmExtendedMessageBox.TIcon.embiInformation)); }
/// <summary> /// show form as dialog with given parameters /// </summary> /// <param name="AMessage">Message to be displayed to the user</param> /// <param name="ACaption">Caption of the dialog window</param> /// <param name="AChkOptionText">Text to be shown with check box (check box hidden if text empty)</param> /// <param name="AButtons">Button set to be displayed</param> /// <param name="ADefaultButton">The button with a default action</param> /// <param name="AIcon">Icon to be displayed</param> /// <param name="AOptionSelected">initial value for option check box</param> /// <returns></returns> public TFrmExtendedMessageBox.TResult ShowDialog(string AMessage, string ACaption, string AChkOptionText, TFrmExtendedMessageBox.TButtons AButtons, TFrmExtendedMessageBox.TDefaultButton ADefaultButton, TFrmExtendedMessageBox.TIcon AIcon, bool AOptionSelected) { string ResourceDirectory; string IconFileName; ToolTip ButtonTooltip = new ToolTip(); // initialize return values FResult = TResult.embrUndefined; FOptionSelected = AOptionSelected; txtMessage.Text = AMessage; txtMessage.BorderStyle = BorderStyle.FixedSingle; txtMessage.HideSelection = true; txtMessage.SelectionStart = 0; txtMessage.SelectionLength = 0; txtMessage.Font = new System.Drawing.Font(txtMessage.Font, FontStyle.Regular); pnlLeftButtons.MinimumSize = new Size(btnHelp.Width + btnCopy.Width + 10, pnlLeftButtons.Height); ButtonTooltip.SetToolTip(btnHelp, "Help"); ButtonTooltip.SetToolTip(btnCopy, "Copy to Clipboard"); this.Text = ACaption; chkOption.Text = AChkOptionText; if (AChkOptionText.Length == 0) { chkOption.Visible = false; } chkOption.Checked = AOptionSelected; this.MinimumSize = new System.Drawing.Size(pnlLeftButtons.Width + pnlRightButtons.Width, 250); btnYes.Visible = false; btnYesToAll.Visible = false; btnNo.Visible = false; btnNoToAll.Visible = false; btnOK.Visible = false; btnCancel.Visible = false; FDefaultButton = ADefaultButton; switch (AButtons) { case TButtons.embbYesYesToAllNoCancel: btnYes.Visible = true; btnYesToAll.Visible = true; btnNo.Visible = true; btnCancel.Visible = true; break; case TButtons.embbYesYesToAllNoNoToAllCancel: btnYes.Visible = true; btnYesToAll.Visible = true; btnNo.Visible = true; btnNoToAll.Visible = true; btnCancel.Visible = true; break; case TButtons.embbYesYesToAllNoNoToAll: btnYes.Visible = true; btnYesToAll.Visible = true; btnNo.Visible = true; btnNoToAll.Visible = true; break; case TButtons.embbYesNo: btnYes.Visible = true; btnNo.Visible = true; break; case TButtons.embbYesNoCancel: btnYes.Visible = true; btnNo.Visible = true; btnCancel.Visible = true; break; case TButtons.embbOK: btnOK.Visible = true; break; case TButtons.embbOKCancel: btnOK.Visible = true; btnCancel.Visible = true; break; default: break; } // dispose of items in case they were used already earlier if (FBitmap != null) { FBitmap.Dispose(); } // find the right icon name switch (AIcon) { case TIcon.embiQuestion: IconFileName = "Help.ico"; break; case TIcon.embiInformation: IconFileName = "PetraInformation.ico"; break; case TIcon.embiWarning: IconFileName = "Warning.ico"; break; case TIcon.embiError: IconFileName = "Error.ico"; break; default: IconFileName = ""; break; } if (FIconControl == null) { FIconControl = new PictureBox(); // Stretches the image to fit the pictureBox. FIconControl.SizeMode = PictureBoxSizeMode.StretchImage; FIconControl.ClientSize = new Size(30, 30); pnlIcon.Padding = new Padding(3, 3, 3, 3); } // load and set the image ResourceDirectory = TAppSettingsManager.GetValue("Resource.Dir"); if ((AIcon != TIcon.embiNone) && System.IO.File.Exists(ResourceDirectory + System.IO.Path.DirectorySeparatorChar + IconFileName)) { pnlIcon.Visible = true; FBitmap = new System.Drawing.Bitmap(ResourceDirectory + System.IO.Path.DirectorySeparatorChar + IconFileName); FIconControl.Image = (Image)FBitmap; if (!pnlIcon.Controls.Contains(FIconControl)) { pnlIcon.Controls.Add(FIconControl); } } else { // remove icon panel if it already exists if (pnlIcon.Controls.Contains(FIconControl)) { pnlIcon.Controls.Remove(FIconControl); } pnlIcon.Visible = false; } // remove the controlbox as we do not need these options (min, max and close_ this.ControlBox = false; // now show the actual dialog this.StartPosition = FormStartPosition.CenterScreen; this.ShowDialog(); // FResult is initialized when buttons are pressed return(FResult); }