Exemplo n.º 1
0
        public override FileInfo GenerateLoanForm(Multimedia template, Loan loan, List<LoanMaterial> material, List<Trait> traits, Contact originator, Contact requestor, Contact receiver)
        {
            var tempFile = TempFileManager.NewTempFilename(".docx");
            var bytes = SupportService.GetMultimediaBytes(template.MultimediaID);

            Func<String, String> fieldDataFunc = (String fieldName) => {
                return base.SubstitutePlaceHolder(NormaliseFieldName(fieldName), loan, material, traits, originator, requestor, receiver);
            };

            Merge(fieldDataFunc, bytes, tempFile);
            return new FileInfo(tempFile);
        }
Exemplo n.º 2
0
 private void testTemplate(String template, String expected)
 {
     var loan = new Loan {
         OriginatorGivenName = "origGivenName", OriginatorName = "origName", OriginatorTitle = "origTitle", OriginatorPostalAddress = "orig postal address", OriginatorStreetAddress = "origStreetAddress", OriginatorID = -1,
         ReceiverGivenName = "recGivenName", ReceiverName = "recName", ReceiverInstitution = "recInstitution", ReceiverPostalAddress = "rec postal address", ReceiverStreetAddress = "rec street address", ReceiverTitle = "recTitle", ReceiverID = -1,
         RequestorGivenName = "reqGivenName", RequestorName = "reqName", RequestorInstitution = "reqInsititution", RequestorPostalAddress = "req postal address", RequestorStreetAddress = "req street address", RequestorTitle = "req title", RequestorID = -1,
         DateCreated = DateTime.Now, DateClosed = null, DateDue = DateTime.Now, DateInitiated = new DateTime(2001,1,1), LoanClosed = false, LoanID = 1, LoanNumber = "loan number", MethodOfTransfer = "transfer method", PermitNumber = "permit number", Restrictions = "restrictions",
         TypeOfReturn = "type of return"
     };
     var actual = LoanFormGenerator.GenerateLoanForm(template, loan, new List<LoanMaterial>(), new List<Trait>());
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 3
0
        protected string SubstitutePlaceHolder(string key, Loan loan, IEnumerable<LoanMaterial> material, IEnumerable<Trait> traits, Contact originator, Contact requestor, Contact receiver)
        {
            var sb = new StringBuilder();

            // Special placeholders

            switch (key.ToLower()) {
                case "totalspecimencount":
                    return CountTotalSpecimens(material) + "";
            }

            if (key.Contains('(')) {
                // group...
                var collectionName = key.Substring(0, key.IndexOf('('));
                var fieldstr = key.Substring(key.IndexOf('(') + 1);
                var fields = fieldstr.Substring(0, fieldstr.Length - 1).Split(',');

                List<object> collection = null;
                if (collectionName.Equals("material", StringComparison.CurrentCultureIgnoreCase)) {
                    collection = new List<object>(material);
                } else if (collectionName.Equals("trait", StringComparison.CurrentCultureIgnoreCase)) {
                    collection = new List<object>(traits);
                }

                if (collection != null) {
                    foreach (Object obj in collection) {
                        int i = 0;
                        foreach (string field in fields) {
                            var value = GetPropertyValue(obj, field);
                            if (!string.IsNullOrEmpty(value)) {
                                sb.Append(RTFUtils.EscapeUnicode(value));
                            }
                            sb.Append(++i < fields.Length ? ", " : String.Format(". {0}", NewLineSequence));
                        }
                    }
                }
            } else if (key.Contains(".")) {
                // is a property of a linked object (currently just the three different contacts attached to the loan)
                // e.g. receiver.EMail
                var bits = key.Split('.');

                if (bits.Length > 0) {
                    Object srcObject = null;
                    switch (bits[0].ToLower()) {
                        case "receiver":
                            srcObject = receiver;
                            break;
                        case "requestor":
                            srcObject = requestor;
                            break;
                        case "originator":
                            srcObject = originator;
                            break;
                    }

                    if (srcObject != null) {
                        var value = GetPropertyValue(srcObject, bits[1]);
                        if (!string.IsNullOrEmpty(value)) {
                            sb.Append(RTFUtils.EscapeUnicode(value));
                        }
                    }
                }

            } else {
                // single value from the Loan model...
                var value = GetPropertyValue(loan, key);
                if (!string.IsNullOrEmpty(value)) {
                    sb.Append(RTFUtils.EscapeUnicode(value));
                }
            }
            return sb.ToString();
        }
Exemplo n.º 4
0
 public abstract FileInfo GenerateLoanForm(Multimedia template, Loan loan, List<LoanMaterial> material, List<Trait> traits, Contact originator, Contact requestor, Contact receiver);
Exemplo n.º 5
0
        private string ChooseFilename(Loan loan, Multimedia template)
        {
            var dlg = new SaveFileDialog();
            var defaultDir = Config.GetUser(User, "Loans.Forms.DefaultOutputDirectory", dlg.InitialDirectory);
            if (!string.IsNullOrWhiteSpace(defaultDir)) {
                var dirinfo = new DirectoryInfo(defaultDir);
                if (dirinfo.Exists) {
                    dlg.InitialDirectory = dirinfo.FullName;
                }
            }

            var borrowerName = LoanService.FormatName("", loan.RequestorGivenName, loan.RequestorName);
            dlg.FileName = SystemUtils.StripIllegalFilenameChars(string.Format("{0}_{1}_{2:yyyy-MM-dd}.{3}", loan.LoanNumber, borrowerName, DateTime.Now, template.FileExtension));
            if (dlg.ShowDialog() == true) {
                var finfo = new FileInfo(dlg.FileName);
                Config.SetUser(User, "Loans.Forms.DefaultOutputDirectory", finfo.DirectoryName);
                return dlg.FileName;
            }
            return null;
        }
Exemplo n.º 6
0
 public void UpdateLoan(Loan loan)
 {
     StoredProcUpdate("spLoanUpdate",
         _P("intLoanID", loan.LoanID),
         _P("vchrLoanNumber", loan.LoanNumber),
         _P("intRequestorID", loan.RequestorID),
         _P("intReceiverID", loan.ReceiverID),
         _P("intOriginatorID", loan.OriginatorID),
         _P("dtDateInitiated", loan.DateInitiated),
         _P("dtDateDue", loan.DateDue),
         _P("vchrMethodOfTransfer", loan.MethodOfTransfer),
         _P("vchrPermitNumber", loan.PermitNumber),
         _P("vchrTypeOfReturn", loan.TypeOfReturn),
         _P("vchrRestrictions", loan.Restrictions),
         _P("dtDateClosed", loan.DateClosed),
         _P("bitLoanClosed", loan.LoanClosed)
     );
 }
Exemplo n.º 7
0
        public int InsertLoan(Loan loan)
        {
            var retval = ReturnParam("NewLoanID");
            StoredProcUpdate("spLoanInsert",
                _P("vchrLoanNumber", loan.LoanNumber),
                _P("intRequestorID", loan.RequestorID),
                _P("intReceiverID", loan.ReceiverID),
                _P("intOriginatorID", loan.OriginatorID),
                _P("dtDateInitiated", loan.DateInitiated),
                _P("dtDateDue", loan.DateDue),
                _P("vchrMethodOfTransfer", loan.MethodOfTransfer),
                _P("vchrPermitNumber", loan.PermitNumber),
                _P("vchrTypeOfReturn", loan.TypeOfReturn),
                _P("vchrRestrictions", loan.Restrictions),
                _P("dtDateClosed", loan.DateClosed),
                _P("bitLoanClosed", loan.LoanClosed),
                retval
            );

            return (int)retval.Value;
        }