-
Notifications
You must be signed in to change notification settings - Fork 0
/
DocumentUploadDA.cs
234 lines (198 loc) · 8.19 KB
/
DocumentUploadDA.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 System;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Web;
using EPF.BusinessObjects;
using EPF.Utilities;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
//------------------------------------------------------------------------------
// DocumentUploadDA.cs
//
// This class handles all requests for the Document Upload Table
//
//------------------------------------------------------------------------------
//
// Modification Control Log
//
// Date By Description
// -------- --- -------------------------------------------------------------
// 04-28-15 JV Initial creation of program
//
//------------------------------------------------------------------------------
namespace EPF.DataAccess
{
public class DocumentUploadDA
{
#region Member Variables
// Variables
private SqlDatabase _DB = null;
#endregion
#region Constructors
public DocumentUploadDA()
{
// Initialize Variables
ErrMsg = string.Empty;
try
{
// Create an instance of the SQL Database class
_DB = new SqlDatabase(ConfigurationManager.ConnectionStrings["PROCESS360"].ToString());
}
catch (Exception err)
{
// Database Error
ErrMsg = string.Format("{0} - Connecting to Database Error - {1}",
GetType().FullName,
err.Message);
// Save the Error
CommonDA.SaveError(ErrMsg, err);
}
}
#endregion
#region Enums
#endregion
#region Properties
public string ErrMsg { get; set; }
#endregion
#region Methods
/// <summary>
/// Retrieves the Document Upload record for an Project Id
/// </summary>
/// <param name="projectId"></param>
/// <returns>documentUploadBO</returns>
public DocumentUploadBO GetByProjectId(Int32 projectId)
{
// Define Constants
const string sp = "dbo.Get_DocUpload_By_Project_Id";
// Set Stored Procedure
DbCommand dbCommand = _DB.GetStoredProcCommand(sp);
// Define Variables
DocumentUploadBO duBO = new DocumentUploadBO();
try
{
// Set Input Parameters
_DB.AddInParameter(dbCommand, "Project_Id", DbType.Int32, projectId);
using (IDataReader dr = _DB.ExecuteReader(dbCommand))
{
// Process all the records
while (dr.Read())
{
// Save the DocUpload record
duBO.Save(dr);
}
}
}
catch (InternalException err)
{
// Re-Throw the Internal Exception
throw;
}
catch (Exception err)
{
// Format the Parameters
string parms = CommonDA.FormatParmsSQL(dbCommand);
// Database Error
ErrMsg = string.Format("{0} - Get DocUpload By Project Id Error - Parameters = {1} - {2}",
GetType().FullName,
parms,
err.Message);
// Save the Error
CommonDA.SaveError(ErrMsg, err);
}
return duBO;
}
/// <summary>
/// UpdateInsert the Document Upload record
/// </summary>
/// <param name="DocumentUploadBO"></param>
/// <returns>int</returns>
public void UpdateInsert(DocumentUploadBO duBO)
{
// Define Constants
const string sp = "dbo.Update_Insert_Document_Upload";
// Set Stored Procedure
DbCommand dbCommand = _DB.GetStoredProcCommand(sp);
try
{
_DB.AddInParameter(dbCommand, "Project_Id", DbType.Int32, duBO.Project_Id);
_DB.AddInParameter(dbCommand, "Project_Name", DbType.String, duBO.Project_Name);
_DB.AddInParameter(dbCommand, "Upload_Criteria_Id", DbType.Int32, duBO.Upload_Criteria_Id);
_DB.AddInParameter(dbCommand, "Effective_Date", DbType.DateTime, duBO.Effective_Date);
_DB.AddInParameter(dbCommand, "Ack_Due_Date", DbType.DateTime, duBO.Ack_Due_Date);
_DB.AddInParameter(dbCommand, "Primary_Barcode", DbType.String, duBO.Primary_Barcode);
_DB.AddInParameter(dbCommand, "Secondary_Barcode", DbType.String, duBO.Secondary_Barcode);
_DB.AddInParameter(dbCommand, "Email_Notification", DbType.String, duBO.Email_Notification);
_DB.AddInParameter(dbCommand, "Email_Reminder", DbType.String, duBO.Email_Reminder);
_DB.AddInParameter(dbCommand, "Zip_File_Name", DbType.String, duBO.Zip_File_Name);
_DB.AddInParameter(dbCommand, "Control_File_Name", DbType.String, duBO.Control_File_Name);
_DB.AddInParameter(dbCommand, "PDF_File_Name", DbType.String, duBO.PDF_File_Name);
_DB.AddInParameter(dbCommand, "Criteria_Name", DbType.String, duBO.Criteria_Name);
_DB.AddInParameter(dbCommand, "Project_Created_By", DbType.String, duBO.Project_Created_By);
_DB.AddInParameter(dbCommand, "Modified_By", DbType.String, duBO.Modified_By);
_DB.AddOutParameter(dbCommand, "Id", DbType.Int32, 0);
_DB.ExecuteNonQuery(dbCommand);
if (duBO.Project_Id == 0)
{
HttpContext.Current.Session["ProjectId"] = Convert.ToInt32(_DB.GetParameterValue(dbCommand, "@Id"));
}
}
catch (InternalException err)
{
// Re-Throw the Internal Exception
throw;
}
catch (Exception err)
{
// Format the Parameters
string parms = CommonDA.FormatParmsSQL(dbCommand);
// Database Error
ErrMsg = string.Format("{0} - UpdateInsert Document Upload Error - Parameters = {1} - {2}",
GetType().FullName,
parms,
err.Message);
// Save the Error
CommonDA.SaveError(ErrMsg, err);
}
}
/// <summary>
/// Delete the Document Upload records for multiple row project data
/// </summary>
/// <param name="DocumentUploadBO"></param>
/// <returns>int</returns>
public void Delete(Int32 projectId)
{
// Define Constants
const string sp = "dbo.Delete_Document_Project_Id";
// Set Stored Procedure
DbCommand dbCommand = _DB.GetStoredProcCommand(sp);
try
{
_DB.AddInParameter(dbCommand, "Project_Id", DbType.Int32, projectId);
_DB.ExecuteNonQuery(dbCommand);
}
catch (InternalException err)
{
// Re-Throw the Internal Exception
throw;
}
catch (Exception err)
{
// Format the Parameters
string parms = CommonDA.FormatParmsSQL(dbCommand);
// Database Error
ErrMsg = string.Format("{0} - Delete Document Upload Project Id Error - Parameters = {1} - {2}",
GetType().FullName,
parms,
err.Message);
// Save the Error
CommonDA.SaveError(ErrMsg, err);
}
}
#endregion
}
}