예제 #1
0
파일: AuditJob.cs 프로젝트: vijaydairyf/bk
        private void GenerateAudit()
        {
            List <bk_AuditReport_Result> result = null;

            using (bkContext context = new bkContext())
            {
                result = context.bk_AuditReport().ToList();
            }

            if (result == null)
            {
                return;
            }

            var auditTypes = Enum.GetValues(typeof(AuditTypes));

            string baseString   = @"<tr><td>{0}</td><td>{1}</td></tr>";
            string templatePath = System.Web.Hosting.HostingEnvironment.MapPath("~/HtmlTemplates/audit.html");
            string html         = File.ReadAllText(templatePath);

            StringBuilder builder = new StringBuilder();

            foreach (int auditType in auditTypes)
            {
                builder.Clear();

                var tResult = result.Where(x => x.AuditType == auditType).ToList();

                if (tResult != null && tResult.Count > 0)
                {
                    foreach (var item in tResult)
                    {
                        string member = string.Empty;
                        string family = string.Empty;

                        if (!item.FamilyId.HasValue)
                        {
                            item.FamilyId = 0;
                        }

                        if (item.FamilyId.HasValue && item.FamilyId.Value > 0)
                        {
                            family = string.Format("<a href='http://brahmkshatriya.net.in/family/{0}'>{1}</a>", item.FamilyId.Value, item.FamilyName);
                        }

                        if (item.MemberId.HasValue && item.MemberId.Value > 0)
                        {
                            member = string.Format("<a href='http://brahmkshatriya.net.in/member/{0}/{1}'>{2}</a>", item.FamilyId.Value, item.MemberId.Value, item.MemberName);
                        }

                        builder.AppendLine(string.Format(baseString, family, member));
                    }
                }

                string placeholder = "{{" + string.Format("audit_{0}", auditType) + "}}";
                string textResult  = builder.ToString();
                if (string.IsNullOrWhiteSpace(textResult))
                {
                    textResult = "No discrepancy found on this audit.";
                }

                html = html.Replace(placeholder, textResult);
            }
        }