コード例 #1
0
        public string Parse(int certificateId, int templateId)
        {
            IUnitOfWork            repository    = new UnitOfWork();
            LetterTemplateService  letterService = new LetterTemplateService();
            GiftCertificateService giftService   = new GiftCertificateService(repository);

            BLL.GiftCertificate gift = giftService.FindById(certificateId);

            BLL.LetterTemplate template    = letterService.FindById(templateId);
            string             raw         = HttpContext.Current.Server.HtmlDecode(template.Template);
            string             tableString = string.Empty;
            int startIndex = raw.IndexOf("<table id=\"detail\"");//("<table id=\"detail\" style=\"width:100%;\">")

            if (startIndex != -1)
            {
                int lastIndex = raw.IndexOf("</table>", startIndex) + 8;
                if (lastIndex != -1)
                {
                    int length = lastIndex - startIndex;
                    tableString = raw.Substring(startIndex, length);
                }
            }
            if (@tableString != "")
            {
                raw = raw.Replace(@tableString, "{tablePlaceHolder}");
            }
            raw = PopulateCertificate(raw, gift);
            string populatedTable = string.Empty;

            if (@tableString != "")
            {
                populatedTable = PopulateTableData(gift.GiftCertificateDetails.ToList(), tableString.Replace("&nbsp;", ""));
            }
            string finalString = raw.Replace("{tablePlaceHolder}", populatedTable);

            return(finalString);
        }