/// <summary> /// Additional manual validation for Form Design Setup /// </summary> /// <param name="AContext">Context that describes what I'm validating.</param> /// <param name="ARow">DataRow with the the data I'm validating</param> /// <param name="AVerificationResultCollection">Will be filled with 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 ValidateFormDesignManual(object AContext, PFormRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // FormTypeCode must not be blank DataColumn ValidationColumn = ARow.Table.Columns[PFormTable.ColumnFormTypeCodeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.FormTypeCode, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // MinimumAmount must be zero or positive ValidationColumn = ARow.Table.Columns[PFormTable.ColumnMinimumAmountId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveOrZeroDecimal(ARow.MinimumAmount, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // Description must not be blank ValidationColumn = ARow.Table.Columns[PFormTable.ColumnFormDescriptionId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.FormDescription, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // Formality level must be between 1 and 6 ValidationColumn = ARow.Table.Columns[PFormTable.ColumnFormalityLevelId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsInRange(ARow.FormalityLevel, 1, 6, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
/// <summary> /// Main private method to return a table with forms for partner or finance /// </summary> /// <param name="AFormCode">Form Code Filter</param> /// <param name="AFormTypeCode">Form Type Code Filter, ignore this filter if empty string</param> /// <returns>Result Form Table. Note: only those where the template is 'available' are returned</returns> private static PFormTable GetForms(String AFormCode, String AFormTypeCode) { PFormTable ResultTable = new PFormTable(); PFormRow TemplateRow = ResultTable.NewRowTyped(false); // Check for a valid form code if ((AFormCode == MCommonConstants.FORM_CODE_PARTNER) || (AFormCode == MCommonConstants.FORM_CODE_PERSONNEL) || (AFormCode == MCommonConstants.FORM_CODE_CHEQUE) || (AFormCode == MCommonConstants.FORM_CODE_RECEIPT) || (AFormCode == MCommonConstants.FORM_CODE_REMITTANCE) || (AFormCode == MCommonConstants.FORM_CODE_CONFERENCE)) { TemplateRow.FormCode = AFormCode; TemplateRow.TemplateAvailable = true; if (AFormTypeCode != "") { TemplateRow.FormTypeCode = AFormTypeCode; } TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref Transaction, delegate { // This method only needs some of the columns - and definitely not the template itself! StringCollection fieldList = new StringCollection(); fieldList.Add(PFormTable.GetFormCodeDBName()); fieldList.Add(PFormTable.GetFormTypeCodeDBName()); fieldList.Add(PFormTable.GetFormLanguageDBName()); fieldList.Add(PFormTable.GetFormNameDBName()); fieldList.Add(PFormTable.GetFormDescriptionDBName()); fieldList.Add(PFormTable.GetTemplateFileExtensionDBName()); fieldList.Add(PFormTable.GetAddressLayoutCodeDBName()); fieldList.Add(PFormTable.GetFormalityLevelDBName()); // Probably don't need these on the client fieldList.Add(PFormTable.GetMinimumAmountDBName()); fieldList.Add(PFormTable.GetOptionsDBName()); ResultTable = PFormAccess.LoadUsingTemplate(TemplateRow, fieldList, Transaction); }); } return(ResultTable); }
private static string GetTemplatePath(TModule AModule, TPrintUsing APrintApplication, string AFormName) { string ReturnValue = string.Empty; string msgTitle = Catalog.GetString("Print"); #if USING_TEMPLATER PFormTable formTable = null; switch (AModule) { case TModule.mPartner: formTable = TRemote.MCommon.FormTemplates.WebConnectors.DownloadPartnerFormTemplate(AFormName, "99"); break; case TModule.mPersonnel: formTable = TRemote.MCommon.FormTemplates.WebConnectors.DownloadPersonnelFormTemplate(AFormName, "99"); break; case TModule.mFinance: formTable = TRemote.MCommon.FormTemplates.WebConnectors.DownloadFinanceFormTemplate("PRINTGRID", AFormName, "99"); break; default: break; } if ((formTable != null) && (formTable.Rows.Count == 1)) { // We got something from the DB PFormRow row = (PFormRow)(formTable.Rows[0]); string base64Text = row.TemplateDocument; // Work out the default file editing location for this template string uniqueFileName = row.FormCode + "_" + row.FormName + "_" + row.FormLanguage; string extension = row.TemplateFileExtension.Length == 0 ? APrintApplication == TPrintUsing.Excel ? "xlsx" : "docx" : row.TemplateFileExtension; string templateFileName = TFileHelper.GetDefaultTemporaryTemplatePath(uniqueFileName, extension); if (File.Exists(templateFileName)) { // delete the existing file // If this fails it must already be open in the editor Boolean showInUseMessage = false; try { File.Delete(templateFileName); System.Threading.Thread.Sleep(500); } catch (UnauthorizedAccessException) { showInUseMessage = true; } catch (IOException) { showInUseMessage = true; } if (showInUseMessage) { string msg = Catalog.GetString("Cannot access the template file. Maybe you already have it open in an editor? "); msg += Catalog.GetString("The file is: "); msg += templateFileName; msg += Environment.NewLine + Environment.NewLine; msg += Catalog.GetString("Do you want to continue? Click Yes to try again or No to cancel."); if (MessageBox.Show(msg, msgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No) { return(ReturnValue); } } } // Write the file string failMessage; if (TFileHelper.WriteBinaryFileConvertedFromBase64String(base64Text, templateFileName, out failMessage)) { // Succeeded in writing the file locally, so now we can open it ... return(templateFileName); } else { MessageBox.Show(failMessage, msgTitle); return(ReturnValue); } } // So we did not get anything from the database. Lets try the file system string tryPath = Path.Combine(TTemplaterAccess.GetFormLetterTemplateBaseDirectory(TModule.mPartner), AFormName + (APrintApplication == TPrintUsing.Excel ? ".xlsx" : ".docx")); if (File.Exists(tryPath)) { // Use this one then return(tryPath); } #endif // Did not find anything return(ReturnValue); }