[CustomAuthorize]
        public FileResult ExportCustomerManagerVisitExcel(string dateType, string realVisitDate, string isRenew)
        {
            string dateFormat = "yyyy-MM-dd";
            switch (dateType)
            {
                case "0": dateFormat = "yyyy-MM-dd"; break;
                case "1": dateFormat = "yyyy-MM"; break;
                case "2": dateFormat = "yyyy"; break;
                default: dateFormat = "yyyy-MM-dd"; break;
            }

IList<CustomerManagerVisitStatistics> listTotal = orderitemManager.GetCustomerManagerVisitStatistics(dateFormat, realVisitDate, isRenew);

StringWriter strWriter = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(strWriter);

if (listTotal.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
                sb.Append("<thead>");
                sb.Append("<tr>");
                sb.Append("<th>组名</th>");
                sb.Append("<th>姓名</th>");
                sb.Append("<th>日期</th>");
                sb.Append("<th>回访总数</th>");
                sb.Append("<th>意向客户总数</th>");
                sb.Append("<th>意向客户占比(%)</th>");
                sb.Append("<th>小组回访总数</th>");
                sb.Append("<th>小组意向客户总数</th>");
                sb.Append("<th>小组平均值(%)</th>");
                sb.Append("</tr>");
                sb.Append("</thead>");
                sb.Append("<tbody>");

string html = "";
                string groupFirstRow = "";
                string groupOtherRow = "";
                string displayGroupName = "";
                string groupName = "";
                int groupRowspan = 0;
                int groupVisitCount = 0;
                int groupIntentionCount = 0;

foreach (CustomerManagerVisitStatistics item in listTotal)
                {
                    if (item.ParentId == "0")
                    {
                        if (groupRowspan > 0 && groupFirstRow != "")
                        {
                            groupFirstRow = "<tr><td rowspan='" + groupRowspan.ToString() + "'>" + displayGroupName + "</td>" + groupFirstRow + "<td rowspan='" + groupRowspan.ToString() + "'>" + groupVisitCount
                            + "</td><td rowspan='" + groupRowspan.ToString() + "'>" + groupIntentionCount + "</td><td rowspan='" + groupRowspan.ToString() + "'>";
                            if (groupVisitCount == 0)
                            {
                                groupFirstRow = groupFirstRow + "0</td></tr>";
                            }
                            else
                            {
                                groupFirstRow = groupFirstRow + Math.Round(decimal.Parse(((decimal)groupIntentionCount / groupVisitCount * 100).ToString()), 2).ToString() + "</td></tr>";
                            }

html = html + groupFirstRow + groupOtherRow;
                        }
                        groupName = item.GroupName;
                        displayGroupName = item.GroupName + "(" + item.CustomerManagerName + ")";
                        groupRowspan = 0;
                        groupVisitCount = 0;
                        groupIntentionCount = 0;
                        groupFirstRow = "";
                        groupOtherRow = "";
                    }
                    else
                    {
                        groupRowspan = groupRowspan + 1;
                        groupVisitCount = groupVisitCount + item.VisitCount;
                        groupIntentionCount = groupIntentionCount + item.IntentionCount;

if (groupRowspan == 1)
                        {
                            groupFirstRow = "<td>" + item.CustomerManagerName + "</td>" + "<td>" + item.RealVisitDate + "</td>" + "<td>" + item.VisitCount + "</td>" + "<td>" + item.IntentionCount + "<td>" + item.IntentionRate + "</td>";
                        }
                        else
                        {
                            groupOtherRow = groupOtherRow + "<tr><td>" + item.CustomerManagerName + "</td>" + "<td>" + item.RealVisitDate + "</td>" + "<td>" + item.VisitCount + "</td>" + "<td>" + item.IntentionCount + "<td>" + item.IntentionRate + "</td></tr>";
                        }

}

}

if (groupRowspan > 0 && groupFirstRow != "")
                {
                    groupFirstRow = "<tr><td rowspan='" + groupRowspan.ToString() + "'>" + displayGroupName + "</td>" + groupFirstRow + "<td rowspan='" + groupRowspan.ToString() + "'>" + groupVisitCount
                            + "</td><td rowspan='" + groupRowspan.ToString() + "'>" + groupIntentionCount + "</td><td rowspan='" + groupRowspan.ToString() + "'>";
                    if (groupVisitCount == 0)
                    {
                        groupFirstRow = groupFirstRow + "0</td></tr>";
                    }
                    else
                    {
                        groupFirstRow = groupFirstRow + Math.Round(decimal.Parse(((decimal)groupIntentionCount / groupVisitCount * 100).ToString()), 2).ToString() + "</td></tr>";
                    }

html = html + groupFirstRow + groupOtherRow;
                }

sb.Append(html);
                sb.Append("</tbody>");
                sb.Append("</table>");

strWriter.Write(sb.ToString());
            }
            else
            {
                strWriter.WriteLine("没有数据!");
            }

byte[] fileContents = Encoding.GetEncoding("gb2312").GetBytes("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=gb2312\">" + strWriter.ToString() + "</body></html>");
            return File(fileContents, "application/vnd.ms-excel", string.Format("{0}.xls", "回访统计汇总" + DateTime.Now.Date.ToString("yyyyMMdd")));
        }

最新文章

  1. C和指针 第十二章 使用结构和指针 双链表和语句提炼
  2. if、if elif判断
  3. Windows 8 一起学习
  4. li标签包含img的问题
  5. Android studio 签名使用转
  6. finally 语句
  7. Java调用ASP.NET的webservice故障排除
  8. EF Code First教程-02.1 Fluent API约定配置
  9. IOS设置button 图片 文字 上下、左右
  10. PC-XP系统忘记密码怎么办
  11. 64位 CentOS NDK 编译 FFMPEG
  12. SendMessage API
  13. [转] GMT、UTC与24时区 等时间概念
  14. BZOJ 3207: 花神的嘲讽计划Ⅰ( hash + 可持久化线段树 )
  15. (一个)kafka-jstorm集群实时日志分析 它 ---------kafka实时日志处理
  16. mysql 学习心得5
  17. Zookeeper笔记3——原理及其安装使用
  18. 设置RHEL-7.0的运行级别
  19. &lt;input &gt; -- radio
  20. 从GitHub远程仓库中删除文件夹或文件

热门文章

  1. 『ACM C++』 PTA 天梯赛练习集L1 | 007-011
  2. Linux中Kibana部署
  3. Elasticsearch 数据操作
  4. 电子相册之bitmap
  5. Anaconda下的python如何写入环境变量中
  6. 472. Concatenated Words
  7. Kylin 几个sql报错原因 汇总
  8. pascal 的字符串操作
  9. [Real World Haskell翻译]第24章 并发和多核编程 第一部分并发编程
  10. 【SQL】字符串去空格解决方法