-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReportManager.cs
234 lines (207 loc) · 9.69 KB
/
ReportManager.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
using Denial_Coding.BAL.Generics;
using Denial_Coding.BAL.ViewModels;
using DC.DAL;
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.Data;
//using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
//using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Data.Entity;
using System.Data.Entity.SqlServer;
using System.IO;
using System.Threading.Tasks;
using ClosedXML;
namespace Denial_Coding.BAL.Managers
{
public class ReportManager : IReportService
{
#region Get Practice Names
public List<SelectListItem> GetPracticeList()
{
try
{
using (McKesson_GVLEntities _context = new McKesson_GVLEntities())
{
//ImportModel model = new ImportModel();
string userName = System.Environment.UserName.ToString();
int Project_id = Convert.ToInt32(HttpContext.Current.Session[Constants.ProjectId].ToString());
var list = (from practice in _context.tbl_PRACTICE_MASTER
join project in _context.tbl_PROJECT_MASTER on practice.PROJECT_ID equals project.PROJECT_ID
where project.PROJECT_ID == Project_id
select new SelectListItem
{
Text = practice.PRACTICE,
Value = SqlFunctions.StringConvert((double)practice.PRACTICE_ID).Trim()
}).Distinct().ToList();
return list;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region Get Client Names
public List<SelectListItem> GetClientList()
{
try
{
using (McKesson_GVLEntities _context = new McKesson_GVLEntities())
{
//ImportModel model = new ImportModel();
string userName = System.Environment.UserName.ToString();
int Project_id = Convert.ToInt32(HttpContext.Current.Session[Constants.ProjectId].ToString());
var list = (from client in _context.tbl_CLIENT_TABLE
//join project in _context.tbl_PROJECT_MASTER on practice.PROJECT_ID equals project.PROJECT_ID
//where project.PROJECT_ID == Project_id
select new SelectListItem
{
Text = SqlFunctions.StringConvert((double)client.Client_ID).Trim(),
Value = SqlFunctions.StringConvert((double)client.Client_ID).Trim()
}).Distinct().ToList();
return list;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region Get Coder Names
public List<SelectListItem> getCoderNames(int tl, int user)
{
try
{
using (McKesson_GVLEntities _context = new McKesson_GVLEntities())
{
int projectId = Convert.ToInt32(HttpContext.Current.Session[Constants.ProjectId]);
string userName = Convert.ToString(HttpContext.Current.Session[Constants.UserName]);
int locationid = Convert.ToInt32(HttpContext.Current.Session[Constants.LocationId]);
var list = (from coder in _context.tbl_USER_ACCESS
where coder.PROJECT_ID == projectId && (coder.ACCESS_ID == tl || coder.ACCESS_ID == user) && coder.LOCATION_ID == locationid && (coder.TL_NTLG == userName || coder.USER_NTLG == userName)
&& coder.LOCATION_ID == locationid
select new SelectListItem
{
Text = coder.USER_NTLG,
Value = SqlFunctions.StringConvert((double)coder.USER_ID).Trim()
}).Distinct().ToList();
return list;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region GetCodingStatusList
public List<SelectListItem> GetCodingStatusList()
{
try
{
using (McKesson_GVLEntities _context = new McKesson_GVLEntities())
{
//ImportModel model = new ImportModel();
string userName = System.Environment.UserName.ToString();
int Project_id = Convert.ToInt32(HttpContext.Current.Session[Constants.ProjectId].ToString());
var list = (from tran in _context.tbl_TRANSACTION_DETAILS
//join project in _context.tbl_PROJECT_MASTER on practice.PROJECT_ID equals project.PROJECT_ID
//where project.PROJECT_ID == Project_id
select new SelectListItem
{
Text = tran.CODED_STATUS.Trim(),
Value = tran.CODED_STATUS.Trim()
}).Distinct().ToList();
return list;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
public void ExportData()
{
DataTable table = new DataTable();
table = HttpContext.Current.Session["denial_export"] as DataTable;
ClosedXML.Excel.XLWorkbook wbook = new ClosedXML.Excel.XLWorkbook();
wbook.Worksheets.Add(table, "tab1");
// Prepare the response
HttpResponse httpResponse = HttpContext.Current.Response;
httpResponse.Clear();
httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
//Provide you file name here
httpResponse.AddHeader("content-disposition", "attachment;filename=\"ProductionReport.csv\"");
// Flush the workbook to the Response.OutputStream
using (MemoryStream memoryStream = new MemoryStream())
{
wbook.SaveAs(memoryStream);
memoryStream.WriteTo(httpResponse.OutputStream);
memoryStream.Close();
}
httpResponse.End();
}
#region Get Production Details (Paremeter)
public DataTable GetProductionReportDetails(string fromDos, string toDos, int Practice, string Client, string Denial, string Status, string Coder)
{
int projectId = Convert.ToInt32(HttpContext.Current.Session[Constants.ProjectId]);
string userName = HttpContext.Current.Session[Constants.UserName].ToString();
DataSet dsCommon = new DataSet();
//DataSet dsReport = new DataSet();
using (McKesson_GVLEntities _context = new McKesson_GVLEntities())
{
try
{
var access_id = (from use in _context.tbl_USER_ACCESS where use.USER_NTLG == userName select new { use.ACCESS_ID }).Single();
int acc_id = Convert.ToInt32(access_id.ACCESS_ID.ToString());
HttpContext.Current.Session[Constants.AccessID] = acc_id;
dsCommon.Clear();
SqlConnection conObj = new SqlConnection(Constants.ConnectionString);
conObj.Open();
SqlCommand cmdObj = new SqlCommand(Constants.ProductionTransDetails, conObj);
cmdObj.CommandType = CommandType.StoredProcedure;
cmdObj.Parameters.AddWithValue("@FromDate", fromDos);
cmdObj.Parameters.AddWithValue("@ToDate", toDos);
cmdObj.Parameters.AddWithValue("@Project_Id", projectId);
cmdObj.Parameters.AddWithValue("@Practice_Id", Practice);
cmdObj.Parameters.AddWithValue("@CLIENT_ID", Client);
cmdObj.Parameters.AddWithValue("@DENIAL_TYPE", Denial);
cmdObj.Parameters.AddWithValue("@CODED_STATUS", Status);
cmdObj.Parameters.AddWithValue("@CODED_TO", Coder);
cmdObj.Parameters.AddWithValue("@USER_NTLG", userName);
cmdObj.Parameters.AddWithValue("@access_id", acc_id);
SqlDataAdapter adapter1 = new SqlDataAdapter(cmdObj);
adapter1.Fill(dsCommon);
conObj.Close();
if (dsCommon.Tables[0].Rows.Count > 0)
{
HttpContext.Current.Session["denial_export"] = dsCommon.Tables[0];
return dsCommon.Tables[0];
}
else
{
return null;
}
}
catch (Exception e)
{
throw e;
}
}
}
#endregion
}
}