/// <summary> /// Constructor /// </summary> /// <param name="AResultContext">context where this verification happens (e.g. DB field name)</param> /// <param name="AErrorCodeInfo">An <see cref="ErrCodeInfo" /> that contains data which is used for populating the Verification Result's Properites.</param> /// <param name="ADataValidationRunID">A Data Validation Run ID that this instance should be associated with. Default: a new System.Guid instance.</param> public TVerificationResult(object AResultContext, ErrCodeInfo AErrorCodeInfo, System.Guid ADataValidationRunID = new System.Guid()) { FResultContext = AResultContext; FResultCode = AErrorCodeInfo.ErrorCode; if (AErrorCodeInfo.ErrorMessageText == String.Empty) { FResultText = AErrorCodeInfo.ShortDescription; } else { FResultText = AErrorCodeInfo.ErrorMessageText; } if (AErrorCodeInfo.ErrorMessageTitle != String.Empty) { FResultTextCaption = AErrorCodeInfo.ErrorMessageTitle; } if ((AErrorCodeInfo.Category == ErrCodeCategory.Error) || (AErrorCodeInfo.Category == ErrCodeCategory.Validation)) { FResultSeverity = TResultSeverity.Resv_Critical; } else if (AErrorCodeInfo.Category == ErrCodeCategory.NonCriticalError) { FResultSeverity = TResultSeverity.Resv_Noncritical; } FControlValueUndoRequested = AErrorCodeInfo.ControlValueUndoRequested; FDataValidationRunID = ADataValidationRunID; }
/// <summary> /// Handles validation of a duplicate or non-duplicate record entered in the GUI /// </summary> /// <param name="AHostContext">Context that describes where the data validation occurs (usually specified as 'this').</param> /// <param name="AConstraintExceptionOccurred">Set to True if a constraint exception occurred when saving the data or False otherwise</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="APrimaryKeyColumn">The data column that will be used to identify the error (usually the first of the primary key columns)</param> /// <param name="APrimaryKeyControl">The control corresponding to the Primary Key column</param> /// <param name="APrimaryKeys">The array of primary key data columns that define the unique constraint being validated</param> public static void ValidateNonDuplicateRecord(object AHostContext, bool AConstraintExceptionOccurred, TVerificationResultCollection AVerificationResultCollection, System.Data.DataColumn APrimaryKeyColumn, System.Windows.Forms.Control APrimaryKeyControl, System.Data.DataColumn[] APrimaryKeys) { TVerificationResult verificationResult = null; string resultText = String.Empty; if (AConstraintExceptionOccurred) { // Work out what the current user input values are for the primary keys ErrCodeInfo errInfo = ErrorCodes.GetErrorInfo(CommonErrorCodes.ERR_DUPLICATE_RECORD); resultText = errInfo.ErrorMessageText; string hintText = String.Empty; bool bFoundOne = false; foreach (System.Data.DataColumn column in APrimaryKeys) { // Look at each primary key name and find its control. It is quite common for one key (eg Ledger number) to not have a control. System.Windows.Forms.Label label; System.Windows.Forms.Control control; string controlText = String.Empty; if (GetControlsForPrimaryKey(column, (System.Windows.Forms.Control)AHostContext, out label, out control)) { bFoundOne = true; hintText += Environment.NewLine; hintText += label.Text.Replace("&", String.Empty); controlText = GetDisplayTextForControl(control); if (controlText != String.Empty) { // Note from Alan: I may not have implemented getting control text for all control types // If you find a missing type, please add it to GetDisplayTextForControl() // In the meantime we have to ignore empty text and just display the label text... if (!hintText.EndsWith(":")) { hintText += ":"; } hintText += " "; hintText += controlText; } } } if (!bFoundOne) { // See Alan's note above. This will occur on a form that has no control type that has GetDisplayTextForControl() hintText += Environment.NewLine; hintText += Environment.NewLine; hintText += String.Format(Catalog.GetString( "No hint text is available for the following screen:{0}{1}.{0}Please inform the OpenPetra team if you see this message."), Environment.NewLine, AHostContext.ToString()); } resultText += hintText; } verificationResult = TGuiChecks.ValidateNonDuplicateRecord(AHostContext, AConstraintExceptionOccurred, resultText, APrimaryKeyColumn, APrimaryKeyControl); // Add or remove the error from the collection AVerificationResultCollection.AddOrRemove(verificationResult, APrimaryKeyColumn); }
private static void ProcessFile(CSParser AParsedFile, ref Dictionary <string, ErrCodeInfo> AErrorCodes) { ErrCodeInfo ErrCodeDetails = null; string ErrCodeValue; string ShortDescription = String.Empty; string LongDescription = String.Empty; ErrCodeCategory ErrCodeCat; foreach (TypeDeclaration t in AParsedFile.GetClasses()) { foreach (object child in t.Children) { if (child is INode) { INode node = (INode)child; Type type = node.GetType(); if (type.Name == "FieldDeclaration") { FieldDeclaration fd = (FieldDeclaration)node; foreach (VariableDeclaration vd in fd.Fields) { foreach (AttributeSection attrSection in fd.Attributes) { foreach (ICSharpCode.NRefactory.Ast.Attribute attr in attrSection.Attributes) { LongDescription = String.Empty; if (attr.Name == "ErrCodeAttribute") { ErrCodeValue = ((PrimitiveExpression)vd.Initializer).Value.ToString(); if (ErrCodeValue.EndsWith("V")) { ErrCodeCat = ErrCodeCategory.Validation; } else if (ErrCodeValue.EndsWith("N")) { ErrCodeCat = ErrCodeCategory.NonCriticalError; } else { ErrCodeCat = ErrCodeCategory.Error; } // TLogging.Log(""); // TLogging.Log(""); // TLogging.Log(""); // TLogging.Log(vd.Name + " = " + ((PrimitiveExpression)vd.Initializer).Value.ToString()); foreach (Expression e in attr.PositionalArguments) { // TLogging.Log("ShortDescription: " + ShortDescription); ShortDescription = ((PrimitiveExpression)e).Value.ToString(); } foreach (Expression e in attr.NamedArguments) { if (((NamedArgumentExpression)e).Name == "FullDescription") { LongDescription = ExpressionToString(((NamedArgumentExpression)e).Expression); } // TLogging.Log("NamedArgumentExpression Name: " + LongDescription); } ErrCodeDetails = new ErrCodeInfo(ErrCodeValue, t.Name, vd.Name, ShortDescription, LongDescription, String.Empty, String.Empty, ErrCodeCat, String.Empty, false); AErrorCodes.Add(ErrCodeValue, ErrCodeDetails); } } } } } } } } }
/// <summary> /// Creates a HTML file that contains central documentation of the Error Codes that are used throughout OpenPetra code /// </summary> public static bool Execute(string ACSharpPath, string ATemplateFilePath, string AOutFilePath) { Dictionary <string, ErrCodeInfo> ErrorCodes = new Dictionary <string, ErrCodeInfo>(); CSParser parsedFile = new CSParser(ACSharpPath + "/ICT/Common/ErrorCodes.cs"); string ErrCodeCategoryNice = String.Empty; TLogging.Log("Creating HTML documentation of OpenPetra Error Codes..."); ProcessFile(parsedFile, ref ErrorCodes); parsedFile = new CSParser(ACSharpPath + "/ICT/Petra/Shared/ErrorCodes.cs"); ProcessFile(parsedFile, ref ErrorCodes); parsedFile = new CSParser(ACSharpPath + "/ICT/Common/Verification/StringChecks.cs"); ProcessFile(parsedFile, ref ErrorCodes); ProcessTemplate t = new ProcessTemplate(ATemplateFilePath); Dictionary <string, ProcessTemplate> snippets = new Dictionary <string, ProcessTemplate>(); snippets.Add("GENC", t.GetSnippet("TABLE")); snippets["GENC"].SetCodelet("TABLEDESCRIPTION", "GENERAL (<i>Ict.Common* Libraries only</i>)"); snippets.Add("GEN", t.GetSnippet("TABLE")); snippets["GEN"].SetCodelet("TABLEDESCRIPTION", "GENERAL (across the OpenPetra application)"); snippets.Add("PARTN", t.GetSnippet("TABLE")); snippets["PARTN"].SetCodelet("TABLEDESCRIPTION", "PARTNER Module"); snippets.Add("PERS", t.GetSnippet("TABLE")); snippets["PERS"].SetCodelet("TABLEDESCRIPTION", "PERSONNEL Module"); snippets.Add("FIN", t.GetSnippet("TABLE")); snippets["FIN"].SetCodelet("TABLEDESCRIPTION", "FINANCE Module"); snippets.Add("CONF", t.GetSnippet("TABLE")); snippets["CONF"].SetCodelet("TABLEDESCRIPTION", "CONFERENCE Module"); snippets.Add("FINDEV", t.GetSnippet("TABLE")); snippets["FINDEV"].SetCodelet("TABLEDESCRIPTION", "FINANCIAL DEVELOPMENT Module"); snippets.Add("SYSMAN", t.GetSnippet("TABLE")); snippets["SYSMAN"].SetCodelet("TABLEDESCRIPTION", "SYSTEM MANAGER Module"); foreach (string snippetkey in snippets.Keys) { snippets[snippetkey].SetCodelet("ABBREVIATION", snippetkey); snippets[snippetkey].SetCodelet("ROWS", string.Empty); } foreach (string code in ErrorCodes.Keys) { foreach (string snippetkey in snippets.Keys) { if (code.StartsWith(snippetkey + ".")) { ProcessTemplate row = t.GetSnippet("ROW"); row.SetCodelet("CODE", code); ErrCodeInfo ErrCode = ErrorCodes[code]; switch (ErrCode.Category) { case ErrCodeCategory.NonCriticalError: ErrCodeCategoryNice = "Non-critical Error"; break; default: ErrCodeCategoryNice = ErrCode.Category.ToString("G"); break; } row.AddToCodelet("SHORTDESCRIPTION", (ErrCode.ShortDescription)); row.AddToCodelet("FULLDESCRIPTION", (ErrCode.FullDescription)); row.AddToCodelet("ERRORCODECATEGORY", (ErrCodeCategoryNice)); row.AddToCodelet("DECLARINGCLASS", (ErrCode.ErrorCodeConstantClass)); snippets[snippetkey].InsertSnippet("ROWS", row); } } } foreach (string snippetkey in snippets.Keys) { t.InsertSnippet("TABLES", snippets[snippetkey]); } return(t.FinishWriting(AOutFilePath, ".html", true)); }
/// <summary> /// Displays a MessageBox that shows a question and returns the users' choice. /// </summary> /// <param name="AErrCodeInfo">ErrCodeInfo which contains all the information.</param> /// <param name="ATypeWhichRaisesError">Instance of an object which raises the Error.</param> /// <param name="ADefaultToAnswerYes">Makes 'Yes' the button which is selected by default if true, /// otherwise 'No' is selected by default.</param> /// <returns>Users' choice.</returns> public static DialogResult MsgQuestion(ErrCodeInfo AErrCodeInfo, System.Type ATypeWhichRaisesError, bool ADefaultToAnswerYes) { return(MsgQuestion(new TVerificationResult(ATypeWhichRaisesError, AErrCodeInfo), ATypeWhichRaisesError, ADefaultToAnswerYes)); }