Пример #1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            DateTime asOfDate, asOfDate2;

            if (!IsValidToExport(out asOfDate, out asOfDate2))
            {
                return;
            }
            var exporter = new Exporter();

            if (this.currentReport == XEnum.ReportType.C_DQDKQK_M)
            {
                if (this.SelectedColumns1.Count == 0)
                {
                    this.SelectedColumns1.AddRange(TableMapping.GetFrozenColumnNames("ImportPublic"));
                    this.SelectedColumns1.AddRange(new string[] { "彻底从我行退出", "倒贷", "逾期", "化解方案" });
                }
                if (this.SelectedColumns2.Count == 0)
                {
                    this.SelectedColumns2.AddRange(TableMapping.GetFrozenColumnNames("ImportPrivate"));
                    this.SelectedColumns2.AddRange(new string[] { "彻底从我行退出", "倒贷", "展期", "逾期", "化解方案" });
                }
            }
            else if (this.currentReport == XEnum.ReportType.C_XZDKMX_D)
            {
                if (this.SelectedColumns.Count == 0)
                {
                    this.SelectedColumns.AddRange(TableMapping.GetFrozenColumns(Consts.C_XZDKMX_D));
                }
                exporter.AsOfDate2 = asOfDate2;
                exporter.Columns   = this.SelectedColumns;
            }
            else if (this.currentReport == XEnum.ReportType.C_JQDKMX_D)
            {
                if (this.SelectedColumns.Count == 0)
                {
                    this.SelectedColumns.AddRange(TableMapping.GetFrozenColumns(Consts.C_JQDKMX_D));
                }
                exporter.AsOfDate2 = asOfDate2;
                exporter.Columns   = this.SelectedColumns;
            }
            this.Cursor = Cursors.WaitCursor;
            try {
                var startTime = DateTime.Now;                 // Use to count time cost
                var result    = exporter.ExportData(this.currentReport, asOfDate, asOfDate2, this.SelectedColumns1, this.SelectedColumns2);
                this.Cursor = Cursors.Default;
                if (string.IsNullOrEmpty(result))
                {
                    var seconds  = Math.Round((DateTime.Now - startTime).TotalSeconds);
                    var timeSpan = seconds > 3 ? string.Format("({0}秒)", seconds) : "";                     // Show time cost if longer than 3s
                    ShowInfo(string.Format("报表导出完毕。{0}", timeSpan));
                }
                else
                {
                    ShowError(result);
                }
            }
            catch (IOException ex) {
                if (ex.Message.IndexOf("it is being used by another process") > 0)
                {
                    ShowError("报表文件已经被打开,请先从Excel里关闭该报表然后再导出。");
                }
                else
                {
                    ShowError("导出发生错误");
                }
                logger.Error(ex);
            }
            catch (Exception ex) {
                logger.Error(ex);
                ShowError("导出发生错误");
            }
            finally {
                this.Cursor = Cursors.Default;
            }
        }
Пример #2
0
 private void btnExport_Click(object sender, EventArgs e)
 {
     DateTime asOfDate, asOfDate2;
     if (!IsValidToExport(out asOfDate, out asOfDate2)) {
         return;
     }
     var exporter = new Exporter();
     if (this.currentReport == XEnum.ReportType.C_DQDKQK_M) {
         if (this.SelectedColumns1.Count == 0) {
             this.SelectedColumns1.AddRange(TableMapping.GetFrozenColumnNames("ImportPublic"));
             this.SelectedColumns1.AddRange(new string[] { "彻底从我行退出", "倒贷", "逾期", "化解方案" });
         }
         if (this.SelectedColumns2.Count == 0) {
             this.SelectedColumns2.AddRange(TableMapping.GetFrozenColumnNames("ImportPrivate"));
             this.SelectedColumns2.AddRange(new string[] { "彻底从我行退出", "倒贷", "展期", "逾期", "化解方案" });
         }
     }
     else if (this.currentReport == XEnum.ReportType.C_XZDKMX_D) {
         if (this.SelectedColumns.Count == 0) {
             this.SelectedColumns.AddRange(TableMapping.GetFrozenColumns(Consts.C_XZDKMX_D));
         }
         exporter.AsOfDate2 = asOfDate2;
         exporter.Columns = this.SelectedColumns;
     }
     else if (this.currentReport == XEnum.ReportType.C_JQDKMX_D) {
         if (this.SelectedColumns.Count == 0) {
             this.SelectedColumns.AddRange(TableMapping.GetFrozenColumns(Consts.C_JQDKMX_D));
         }
         exporter.AsOfDate2 = asOfDate2;
         exporter.Columns = this.SelectedColumns;
     }
     this.Cursor = Cursors.WaitCursor;
     try {
         var startTime = DateTime.Now; // Use to count time cost
         var result = exporter.ExportData(this.currentReport, asOfDate, asOfDate2, this.SelectedColumns1, this.SelectedColumns2);
         this.Cursor = Cursors.Default;
         if (string.IsNullOrEmpty(result)) {
             var seconds = Math.Round((DateTime.Now - startTime).TotalSeconds);
             var timeSpan = seconds > 3 ? string.Format("({0}秒)", seconds) : ""; // Show time cost if longer than 3s
             ShowInfo(string.Format("报表导出完毕。{0}", timeSpan));
         }
         else {
             ShowError(result);
         }
     }
     catch (IOException ex) {
         if (ex.Message.IndexOf("it is being used by another process") > 0) {
             ShowError("报表文件已经被打开,请先从Excel里关闭该报表然后再导出。");
         }
         else {
             ShowError("导出发生错误");
         }
         logger.Error(ex);
     }
     catch (Exception ex) {
         logger.Error(ex);
         ShowError("导出发生错误");
     }
     finally {
         this.Cursor = Cursors.Default;
     }
 }