-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActiveXViewer.aspx.cs
849 lines (690 loc) · 31.7 KB
/
ActiveXViewer.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Document;
using Microsoft.Reporting.WebForms;
using EPolicy.Login;
using EPolicy2.Reports;
using System.Configuration;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using System.Text;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System.Xml;
using System.Xml.Linq;
using System.Linq;
namespace EPolicy
{
/// <summary>
/// Summary description for ActiveXExport.
/// </summary>
public partial class ActiveXViewer : System.Web.UI.Page
{
ActiveReport3 rpt = null;
static bool renewal = false;
protected void Page_Load(object sender, System.EventArgs e)
{
this.litPopUp.Visible = false;
Login.Login cp = HttpContext.Current.User as Login.Login;
if (cp == null)
{
Response.Redirect("Default.aspx?001");
}
else
{
if (!cp.IsInRole("REPORTVIEWER") && !cp.IsInRole("ADMINISTRATOR"))
{
Response.Redirect("Default.aspx?001");
}
}
if(!IsPostBack)
{
this.SetReferringPage();
string sReturnReport = this.Page.Request.QueryString["ReturnReport"];
if (this.Request.QueryString.ToString().Trim() == "true" ) //Es renovacion poliza PP o PE.
{
TaskControl.Policy taskControl = (TaskControl.Policy)Session["TaskControl"];
if(taskControl.PolicyType.Trim() != "CP" && taskControl.PolicyType.Trim() != "CE")
renewal = true;
}
if ( (sReturnReport != null) && (sReturnReport.Trim() != string.Empty) )
{
this.Page.Response.Buffer = true;
try
{
rpt = (ActiveReport3) Session["Report"];
//Session.Remove("Report");
//rpt.Run(false);
}
catch (Exception eRunReport)
{
this.Trace.Warn("Report failed to run:\n" + eRunReport.ToString());
}
MemoryStream outStream = new MemoryStream();
rpt.Document.Save(outStream,DataDynamics.ActiveReports.Document.RdfFormat.AR20);
outStream.Seek(0, SeekOrigin.Begin);
byte[] bytes = new byte[outStream.Length];
outStream.Read(bytes, 0, (int)outStream.Length);
this.Page.Response.ClearContent();
this.Page.Response.ClearHeaders();
this.Page.Response.BinaryWrite(bytes);
this.Page.Response.End();
}
}
}
private string ReferringPage
{
get
{
return ((ViewState["referringPage"] != null)?
ViewState["referringPage"].ToString():"");
}
set
{
ViewState["referringPage"] = value;
}
}
private void SetReferringPage()
{
if((Session["FromPage"] != null) && (Session["FromPage"].ToString() != ""))
{
this.ReferringPage = Session["FromPage"].ToString();
Session.Remove("FromPage");
}
}
private void ReturnToReferringPage()
{
if(this.ReferringPage != "")
{
Response.Redirect(this.ReferringPage);
}
Response.Redirect("Default.aspx");
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
this.InitializeComponent();
base.OnInit(e);
System.Web.UI.Control Banner = new System.Web.UI.Control();
Banner = LoadControl(@"TopBanner.ascx");
this.Placeholder1.Controls.Add(Banner);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
private void btnPrint_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Valid())
{
ExportFile(true);
}
else
{
this.litPopUp.Text = Utilities.MakeLiteralPopUpString("Please select one report format.");
this.litPopUp.Visible = true;
}
}
private bool Valid()
{
if (!rblReports.Items[0].Selected && !rblReports.Items[1].Selected && !rblReports.Items[2].Selected)
return false;
else
return true;
}
private void ExportFile(bool isEmail)
{
Login.Login cp = HttpContext.Current.User as Login.Login;
string _userID = cp.Identity.Name.Split("|".ToCharArray())[0].ToString();
string _file = _userID.ToString().Replace(" ","");
string _FileName = ConfigurationSettings.AppSettings["ExportsFilesPathName"];
TaskControl.TaskControl taskControl = (TaskControl.TaskControl)Session["TaskControl"];
TaskControl.Policy task = new TaskControl.Policy();
if(taskControl != null)
if(taskControl.TaskControlTypeID == 12 || taskControl.TaskControlTypeID == 18)
task = (TaskControl.Policy)Session["TaskControl"];
_FileName= _FileName + _file;
ActiveReport3 doc = (ActiveReport3)Session["Report"];
if (rblReports.Items[0].Selected)
{
ExportFile expFile = new ExportFile();
try
{
List<string> mergePaths = new List<string>();
string ProcessedPath = System.Configuration.ConfigurationSettings.AppSettings["ExportsFilesPathName"];
_FileName = _FileName + ".PDF";
expFile.ExportToPDF(doc.Document,_FileName);
if ((task.PolicyType.Trim() == "PP" || task.PolicyType.Trim() == "PE") && task.Anniversary != "01")
{
_FileName = PrintRegistryDocument(_FileName);
}
if (int.Parse(task.Suffix) > 0)
{
mergePaths.Add(_FileName);
if(task.InsuranceCompany != "002")
mergePaths.Add(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + ImprimirCartaDeptDefensa());
if (task.Anniversary != "01")
{
if (DateTime.Parse(task.EffectiveDate) >= DateTime.Parse("01/01/2015") && task.InsuranceCompany != "002")
{
mergePaths.Add(imprimirF102B("F102BA"));
mergePaths.Add(imprimirF102B("F102BB"));
mergePaths.Add(imprimirF102B("F102BC"));
mergePaths.Add(imprimirF102B("F102BD"));
}
}
if (task.Charge > 0)//TxtCharge.Text != ".00")
{
var currentApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath.ToString();
string fullFilePath = currentApplicationPath + "Reports\\Word\\Files\\CN-2021-299-D_ENDOSO_DERRAMAS.pdf";
string copyToPath = System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + "CN-2021-299-D_ENDOSO_DERRAMAS.pdf";
File.Copy(fullFilePath, copyToPath, true);
mergePaths.Add(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + "CN-2021-299-D_ENDOSO_DERRAMAS.pdf");
}
CreatePDFBatch mergeFinal = new CreatePDFBatch();
string FinalFile = "";
FinalFile = mergeFinal.MergePDFFiles(mergePaths, ProcessedPath, _file + "-" + taskControl.TaskControlID.ToString());
FinalFile = System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + FinalFile;
if (isEmail)
SendEmail(FinalFile);
else
DownLoadFile(FinalFile);
}
else
{
if (isEmail)
SendEmail(_FileName);
else
DownLoadFile(_FileName);
}
}
catch (Exception exp)
{
this.litPopUp.Text = Utilities.MakeLiteralPopUpString("" + exp.Message);
this.litPopUp.Visible = true;
return;
}
}
else if (rblReports.Items[2].Selected)
{
_FileName = _FileName + ".xlsx";
System.Data.DataTable dt = new System.Data.DataTable();
dt = null;
dt = (DataTable)doc.DataSource;
System.Data.DataSet ds = new DataSet();
if (doc.Name == "PremiumWritten")
{
int CanAmOrdinal = 0;
CanAmOrdinal = dt.Columns["CancellationAmount"].Ordinal;
dt.Columns["PremNet"].SetOrdinal(CanAmOrdinal + 1);
int desiredSize = dt.Columns["OtherSpecialty2"].Ordinal + 1; //se supone que sean 31 columnas. El final siendo OtherSpecialty2
while (dt.Columns.Count > desiredSize)
{
dt.Columns.RemoveAt(desiredSize);
}
while (ds.Tables.Count > 0)
{
DataTable table = ds.Tables[0];
if (ds.Tables.CanRemove(table))
{
ds.Tables.Remove(table);
}
}
}
ds.Tables.Add(dt.Copy());
//CreateCSV(dt, _FileName,doc.Name);
ExportDataSet(ds, _FileName);
if (isEmail)
SendEmail(_FileName);
else
DownLoadFile(_FileName);
ds.Clear();
dt = null;
dt.Clear();
}
else
{
ExportFile expFile = new ExportFile();
try
{
_FileName= _FileName + ".XLS";
//_FileName = _FileName + ".xlsx";
expFile.ExportToExcel(doc.Document,_FileName);
if(isEmail)
SendEmail(_FileName);
else
DownLoadFile(_FileName);
}
catch (Exception exp)
{
this.litPopUp.Text = Utilities.MakeLiteralPopUpString("" + exp.Message);
this.litPopUp.Visible = true;
return;
}
}
//this.litPopUp.Text = Utilities.MakeLiteralPopUpString("Export File Sucessffully...");
//this.litPopUp.Visible = true;
return;
}
private string PrintRegistryDocument(string fileName)
{
Login.Login cp = HttpContext.Current.User as Login.Login;
string _userID = cp.Identity.Name.Split("|".ToCharArray())[0].ToString();
string _file = _userID.ToString().Replace(" ", "");
TaskControl.TaskControl taskControl = (TaskControl.TaskControl)Session["TaskControl"];
Customer.Registry registry = Customer.Registry.GetRegistryByCustomerNo(int.Parse(taskControl.CustomerNo));
TaskControl.Policy policy = new TaskControl.Policy();
policy = TaskControl.Policy.GetPolicyByTaskControlID(taskControl.TaskControlID, policy);
List<string> mergePaths = new List<string>();
string ProcessedPath = System.Configuration.ConfigurationSettings.AppSettings["ExportsFilesPathName"];
mergePaths = imprimirRegister(mergePaths);
//FileInfo mFileIndex = new FileInfo("C:\\Inetpub\\wwwroot\\PRMDic\\Reports\\Registry.pdf");
mergePaths.Add(fileName);
//if (DateTime.Parse(policy.EffectiveDate) >= DateTime.Parse("01/01/2015"))
//{
// mergePaths.Add(imprimirF102B("F102BA"));
// mergePaths.Add(imprimirF102B("F102BB"));
// mergePaths.Add(imprimirF102B("F102BC"));
// mergePaths.Add(imprimirF102B("F102BD"));
//}
CreatePDFBatch mergeFinal = new CreatePDFBatch();
string FinalFile = "";
FinalFile = mergeFinal.MergePDFFiles(mergePaths, ProcessedPath, "F102B");
return System.Configuration.ConfigurationSettings.AppSettings["ExportsFilesPathName"] + FinalFile;
}
private List<string> imprimirRegister(List<string> mergePaths)
{
int compareResultASSMCA = 0;
int compareResultTribunal = 0;
int compareResultCDM = 0;
int compareResultGS = 0;
int compareResultLicense = 0;
int compareResultDEA = 0;
string tp6 = "";
string assmcadate = "";
string juntaLicenciamiento = "";
string cdmdate = "";
string gstandingdate = "";
string licenseexpdate = "";
string deadate = "";
try
{
TaskControl.Policy taskControl = (TaskControl.Policy)Session["TaskControl"];
Customer.Registry registry = Customer.Registry.GetRegistryByCustomerNo(int.Parse(taskControl.CustomerNo));
ReportViewer viewer = new ReportViewer();
viewer.LocalReport.DataSources.Clear();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = Server.MapPath("Reports/Report2.rdlc");
#region values for parameters
if (registry.ASSMCAExpDate != "")
{
compareResultASSMCA = DateTime.Compare(DateTime.Parse(registry.ASSMCAExpDate.Trim()), DateTime.Now);
if (compareResultASSMCA < 0)
{
assmcadate = "(EXP) " + registry.ASSMCAExpDate.Trim();
}
}
else
assmcadate = "X";
//if (registry.TribunalExpDate != "")
//{
// compareResultTribunal = DateTime.Compare(DateTime.Parse(registry.TribunalExpDate.Trim()), DateTime.Now);
// if (compareResultTribunal < 0)
// {
// tribunaldate = "(EXP) " + registry.TribunalExpDate.Trim();
// }
//}
//else
// tribunaldate = "X";
if (registry.JuntaLicenciamiento == true)
{
juntaLicenciamiento = "";
}
else
{
juntaLicenciamiento = "X";
}
if (registry.CDMExpDate != "")
{
compareResultCDM = DateTime.Compare(DateTime.Parse(registry.CDMExpDate.Trim()), DateTime.Now);
if (compareResultCDM < 0)
{
cdmdate = "(EXP) " + registry.CDMExpDate.Trim();
}
}
else
cdmdate = "X";
if (registry.GoodStandingExpDate != "")
{
compareResultGS = DateTime.Compare(DateTime.Parse(registry.GoodStandingExpDate.Trim()), DateTime.Now);
if (compareResultGS < 0)
{
gstandingdate = "(EXP) " + registry.GoodStandingExpDate.Trim();
}
}
else
gstandingdate = "X";
if (registry.LicenseExpDate != "")
{
compareResultLicense = DateTime.Compare(DateTime.Parse(registry.LicenseExpDate.Trim()), DateTime.Now);
if (compareResultLicense < 0)
{
licenseexpdate = "(EXP) " + registry.LicenseExpDate.Trim();
}
}
else
licenseexpdate = "X";
if (registry.DEAExpDate != "")
{
compareResultDEA = DateTime.Compare(DateTime.Parse(registry.DEAExpDate.Trim()), DateTime.Now);
if (compareResultDEA < 0)
{
deadate = "(EXP) " + registry.DEAExpDate.Trim();
}
}
else
deadate = "X";
if (!registry.CV)
{
tp6 = "X";
}
if (compareResultASSMCA > 0 && compareResultTribunal > 0 && compareResultCDM > 0 && compareResultGS > 0 && compareResultLicense > 0 && compareResultDEA > 0)
return mergePaths;
#endregion
ReportParameter p1 = new ReportParameter("ASSMCADate", assmcadate);
ReportParameter p2 = new ReportParameter("JuntaLicenciamiento", juntaLicenciamiento);
ReportParameter p3 = new ReportParameter("CDMDate", cdmdate);
ReportParameter p4 = new ReportParameter("GStandingDate", gstandingdate);
ReportParameter p5 = new ReportParameter("LicenseExpDate", licenseexpdate);
ReportParameter p6 = new ReportParameter("CVDate", tp6);
ReportParameter p7 = new ReportParameter("DEADate", deadate);
ReportParameter p8 = new ReportParameter("Asegurado", taskControl.Customer.FirstName + " " + taskControl.Customer.Initial + " " + taskControl.Customer.LastName1 + " " + taskControl.Customer.LastName2);
ReportParameter p9 = new ReportParameter("PolizaNo", taskControl.PolicyType.Trim() + "-" + taskControl.PolicyNo);
LookupTables.Agency agency = new LookupTables.Agency();
agency = agency.GetAgency(taskControl.Agency);
ReportParameter p10 = new ReportParameter("Agency", agency.AgencyDesc);
LookupTables.Agent agent = new LookupTables.Agent();
agent = agent.GetAgent(taskControl.Agent);
ReportParameter p11 = new ReportParameter("Productor", agent.AgentDesc);
ReportParameter p12 = new ReportParameter("EffDt", taskControl.EffectiveDate);
DataTable DtTask = TaskControl.TaskControl.GetTaskControlByCustomerNo(taskControl.Customer.CustomerNo);
bool validate = true;
for (int i = 0; i < DtTask.Rows.Count; i++)
{
if (DtTask.Rows[i][1].ToString().Trim() == "PP")
validate = false;
}
ReportParameter p13 = new ReportParameter();
if (validate)
p13 = new ReportParameter("EntryDt", "X");
else
p13 = new ReportParameter("EntryDt", "");
agent = agent.GetAgent(taskControl.Agent);
viewer.LocalReport.SetParameters(new ReportParameter[] { p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13 });
viewer.LocalReport.Refresh();
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType;
string encoding = string.Empty;
string extension;
string _FileName = "Registry-" + registry.RegistryID.ToString().Trim() + ".pdf";
if (File.Exists(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName))
File.Delete(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName);
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
using (FileStream fs = new FileStream(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
mergePaths.Add(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName);
return mergePaths;
}
catch (Exception ex)
{
this.litPopUp.Text = Utilities.MakeLiteralPopUpString(ex.Message + " " + ex.InnerException + " " + ex.Source);
this.litPopUp.Visible = true;
return mergePaths;
}
}
private string ImprimirCartaDeptDefensa()
{
try
{
TaskControl.Policy taskControl = (TaskControl.Policy)Session["TaskControl"];
Customer.Registry registry = Customer.Registry.GetRegistryByCustomerNo(int.Parse(taskControl.CustomerNo));
ReportViewer viewer = new ReportViewer();
viewer.LocalReport.DataSources.Clear();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = Server.MapPath("Reports/Carta_Dept_Defensa.rdlc");
// Variables
Warning[] warnings;
string[] streamIds;
string mimeType;
string encoding = string.Empty;
string extension;
string _FileName = "CDD-" + registry.RegistryID.ToString().Trim() + ".pdf";
if (File.Exists(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName))
File.Delete(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName);
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
using (FileStream fs = new FileStream(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
return _FileName;
}
catch (Exception exp)
{
return "";
}
}
private void DownLoadFile(string filename)
{
string FileNameOf = filename;//Request.MapPath("ExportFiles")+"/"+filename;
FileInfo myFile = new FileInfo(FileNameOf);
Response.ClearHeaders();
Response.Expires = 0;
Response.Buffer = true;
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename="+ myFile.Name.Replace(".resources",""));
Response.AddHeader("Content-Length", myFile.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(myFile.FullName);
Response.Flush();
Response.End();
}
private void SendEmail(string filename)
{
Session.Add("FileNameEmail",filename);
string js = "<script language=javascript> javascript:popwindow=window.open('FollowUp.aspx','popwindow','toolbar=no,location=center,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=734,height=425');popwindow.focus(); </script>";
Response.Write(js);
}
protected void rblReports_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
protected void BtnExit_Click(object sender, System.EventArgs e)
{
Session.Remove("Report");
Session.Remove("FromPage");
ReturnToReferringPage();
}
protected void Button1_Click(object sender, System.EventArgs e)
{
if(Valid())
{
ExportFile(false);
}
else
{
this.litPopUp.Text = Utilities.MakeLiteralPopUpString("Please select one report format.");
this.litPopUp.Visible = true;
}
}
private void btn_Download_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
}
protected void btnEMail_Click(object sender, System.EventArgs e)
{
if(Valid())
{
ExportFile(true);
}
else
{
this.litPopUp.Text = Utilities.MakeLiteralPopUpString("Please select one report format.");
this.litPopUp.Visible = true;
}
}
private string imprimirF102B(string rdlcReport)
{
TaskControl.TaskControl taskControl = (TaskControl.TaskControl)Session["TaskControl"];
ReportViewer viewer = new ReportViewer();
viewer.LocalReport.DataSources.Clear();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = Server.MapPath("Reports/" + rdlcReport + ".rdlc");
viewer.LocalReport.Refresh();
Warning[] warnings;
string[] streamIds;
string mimeType;
string encoding = string.Empty;
string extension;
string _FileName = rdlcReport + taskControl.TaskControlID + ".pdf";
if (File.Exists(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName))
File.Delete(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName);
byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
using (FileStream fs = new FileStream(System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
return System.Configuration.ConfigurationManager.AppSettings["ExportsFilesPathName"] + _FileName;
}
private void CreateCSV(DataTable dt, string filename,string report)
{
if (report == "PremiumWritten")
{
dt.Columns.Add("Net", typeof(string));
dt.Columns[dt.Columns.Count - 1].SetOrdinal(21);
}
StringBuilder sb = new StringBuilder();
DataTable dtPolicyClass = LookupTables.LookupTables.GetTable("PolicyClass");
DataColumnCollection Colums = dt.Columns;
string[] columnNames= new string[Colums.Count];
int Ending_Index = 0;
for (int i = 0; i < Colums.Count; i++)
{
if (Colums[i].ColumnName.ToUpper().Trim() == "POLICYCLASSID" && report == "PremiumWritten")
{
Ending_Index = i;
i = Colums.Count;
}
else
{
columnNames[i] = Colums[i].ColumnName;
Ending_Index = i;
}
}
if (report != "PremiumWritten")
{
Ending_Index += 1;
}
sb.AppendLine(string.Join(",", columnNames));
for (int i = 0; i < dt.Rows.Count; i++)
{
string[] fields = new string[Ending_Index]; //Ending_Index = solo hasta la ultima olumna del reporte // dt.Columns.Count el data set completo
for (int j = 0; j < Ending_Index; j++) //Ending_Index = solo hasta la ultima olumna del reporte // dt.Columns.Count el data set completo
{
//if (PolicyClassID_Index == j)
//{
// for (int x = 0; x < dtPolicyClass.Rows.Count; x++)
// {
// if (dtPolicyClass.Rows[x]["PolicyClassID"].ToString() == dt.Rows[i][j].ToString().Trim().Replace(",", ""))
// {
// fields[j] = dtPolicyClass.Rows[x]["PolicyClassDesc"].ToString().Trim();
// }
// }
//}
//else
{
fields[j] = dt.Rows[i][j].ToString().Trim().Replace(",", "");
}
}
sb.AppendLine(string.Join(",", fields));
}
File.WriteAllText(filename, sb.ToString());
}
private void ExportDataSet(DataSet ds, string destination)
{
using (var workbook = SpreadsheetDocument.Create(destination, DocumentFormat.OpenXml.SpreadsheetDocumentType.Workbook))
//using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(destination, true)) //To open existing file
{
var workbookPart = workbook.AddWorkbookPart(); //Comment line if using existing file
workbook.WorkbookPart.Workbook = new DocumentFormat.OpenXml.Spreadsheet.Workbook();
workbook.WorkbookPart.Workbook.Sheets = new DocumentFormat.OpenXml.Spreadsheet.Sheets();
foreach (System.Data.DataTable table in ds.Tables)
{
var sheetPart = workbook.WorkbookPart.AddNewPart<WorksheetPart>();
var sheetData = new DocumentFormat.OpenXml.Spreadsheet.SheetData();
sheetPart.Worksheet = new DocumentFormat.OpenXml.Spreadsheet.Worksheet(sheetData);
DocumentFormat.OpenXml.Spreadsheet.Sheets sheets = workbook.WorkbookPart.Workbook.GetFirstChild<DocumentFormat.OpenXml.Spreadsheet.Sheets>();
string relationshipId = workbook.WorkbookPart.GetIdOfPart(sheetPart);
uint sheetId = 1;
if (sheets.Elements<DocumentFormat.OpenXml.Spreadsheet.Sheet>().Count() > 0)
{
sheetId =
sheets.Elements<DocumentFormat.OpenXml.Spreadsheet.Sheet>().Select(s => s.SheetId.Value).Max() + 1;
}
DocumentFormat.OpenXml.Spreadsheet.Sheet sheet = new DocumentFormat.OpenXml.Spreadsheet.Sheet() { Id = relationshipId, SheetId = sheetId, Name = table.TableName };
sheets.Append(sheet);
DocumentFormat.OpenXml.Spreadsheet.Row headerRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
List<String> columns = new List<string>();
foreach (System.Data.DataColumn column in table.Columns)
{
columns.Add(column.ColumnName);
DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(column.ColumnName);
headerRow.AppendChild(cell);
}
sheetData.AppendChild(headerRow);
foreach (System.Data.DataRow dsrow in table.Rows)
{
DocumentFormat.OpenXml.Spreadsheet.Row newRow = new DocumentFormat.OpenXml.Spreadsheet.Row();
//foreach (String col in columns)
for (int i = 0; i < table.Columns.Count; i++)
{
DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell();
cell.DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String;
if (table.Columns[i].ColumnName == "TotalPremium" || table.Columns[i].ColumnName == "CyberEndorsementPremium" || table.Columns[i].ColumnName == "PaidAmount" || table.Columns[i].ColumnName == "CancellationAmount")
{
cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue((string.Format("{0:C}", decimal.Parse(dsrow[i].ToString()))).Replace("$","")); //
}
else
cell.CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(dsrow[i].ToString());
newRow.AppendChild(cell);
}
sheetData.AppendChild(newRow);
}
}
}
}
}
}