using System using System Data using System Configuration using System

  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
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ReportViewer.CRM;
using Microsoft.Reporting.WebForms;
using System.Web.Services.Protocols;
using System.IO;
//using Microsoft.Crm.Sdk;
//using System.Web.Services.Protocols;
namespace ReportViewer
{
public partial class ShowReportForCurrentUser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StreamWriter w = null;
try
{
FileInfo f = new FileInfo(@"c:\temp\reportViewer.txt");
w = f.AppendText();
//FileInfo f = new FileInfo(@"c:\temp\reportViewer.txt");
//w = f.AppendText();
//w.WriteLine("start RandDNumerator Plugin");
//if (IsPostBack) return;
//ReportViewer1.Reset();
if (!IsPostBack)
{
w.WriteLine("1");
//Guid userid = new Guid("49172524-59cf-dd11-b0c9-0003ff691beb");
string errMsg;
CrmService crmService = new CrmService();
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = Properties.Settings.Default.CrmOrganization;
#if DEBUG
string userName = Properties.Settings.Default.UserName;
string domainName = Properties.Settings.Default.Domain;
string password = Properties.Settings.Default.Password;
crmService.Credentials = new System.Net.NetworkCredential(userName, password, domainName);
//crmService.Credentials = new System.Net.NetworkCredential("yurig", "181078", "sitqad");
#else
crmService.Credentials = System.Net.CredentialCache.DefaultCredentials;
#endif
crmService.CrmAuthenticationTokenValue = token;
try
{
// Retrieve logged in user details
WhoAmIRequest userRequest = new WhoAmIRequest();
w.WriteLine("2");
WhoAmIResponse user = (WhoAmIResponse)crmService.Execute(userRequest);
w.WriteLine("3");
// Retrieve Report id
ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { "new_dashboardreport" };
systemuser sysUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), user.UserId, cols);
//systemuser sysUser = (systemuser)crmService.Retrieve(EntityName.systemuser.ToString(), userid, cols);
w.WriteLine("4");
w.WriteLine("user.UserId : " + user.UserId.ToString());
if (sysUser.new_dashboardreport == null)
{
w.WriteLine("5");
w.WriteLine("sysUser.new_dashboardreport == null");
}
else
{
w.WriteLine("sysUser.new_dashboardreport NOT null");
}
if (sysUser.new_dashboardreport != null)
{
w.WriteLine("6");
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ShowCredentialPrompts = true;
ReportViewer1.ShowExportControls = true;
w.WriteLine("7");
#if DEBUG
//userName = Properties.Settings.Default.UserName;
//domainName = Properties.Settings.Default.Domain;
//password = Properties.Settings.Default.Password;
//crmService.Credentials = new System.Net.NetworkCredential(userName, password, domainName);
//ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials(crmService.Credentials);
ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();
#else
ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerNetworkCredentials();
#endif
w.WriteLine("10");
ReportViewer1.ServerReport.ReportServerUrl = new Uri(Properties.Settings.Default.ReportServerUrl);
ReportViewer1.ServerReport.ReportPath = Properties.Settings.Default.ReportServerPath + sysUser.new_dashboardreport.name;
//ReportViewer1.ServerReport.ReportPath = Properties.Settings.Default.ReportServerPath + "CSR Summary";
ReportViewer1.ServerReport.Refresh();
w.WriteLine("11 - END");
}
}
catch (SoapException ex)
{
errMsg = ex.Message + ex.Detail.InnerText;
}
catch (Exception ex)
{
errMsg = ex.Message;
}
}
}
catch (SoapException ex)
{
FileInfo f = new FileInfo(@"c:\temp\ExceptionReportViewer1.txt");
StreamWriter sw = f.AppendText();
sw.WriteLine("SoapException: " + ex.Detail.InnerText + " " + ex.TargetSite.ToString());
sw.Close();
throw new Exception("An SoapException occurred in the RandDNumerator plug-in." + ex.Detail.InnerText, ex);
}
catch (Exception ex)
{
FileInfo f = new FileInfo(@"c:\temp\ExceptionReportViewer1.txt");
StreamWriter sw = f.AppendText();
sw.WriteLine("Exception: " + ex.Message + " " + ex.Source);
sw.Close();
throw new Exception("An general Exception occurred in the RandDNumerator plug-in." + ex.Message, ex);
}
finally
{
if (w != null)
{
w.WriteLine("Finally");
w.Close();
}
}
}
}
}