You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

321 lines
12 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using Swift.web.Library;
  8. using System.Data;
  9. using System.Text;
  10. using Swift.DAL.SwiftDAL;
  11. using System.IO;
  12. using Swift.DAL.BL.System.Utility;
  13. using Swift.DAL.BL.System.GeneralSettings;
  14. namespace Swift.web.SwiftSystem.GeneralSetting.MessageSetting
  15. {
  16. public partial class DynamicPopupManage : System.Web.UI.Page
  17. {
  18. private const string ViewFunctionId = "10111100";
  19. private readonly StaticDataDdl _sl = new StaticDataDdl();
  20. private readonly RemittanceLibrary sl = new RemittanceLibrary();
  21. private readonly DynamicPopupMessageDao _dpMDao = new DynamicPopupMessageDao();
  22. protected void Page_Load(object sender, EventArgs e)
  23. {
  24. _sl.CheckSession();
  25. fromDate.ReadOnly = true;
  26. toDate.ReadOnly = true;
  27. if (!IsPostBack)
  28. {
  29. Authenticate();
  30. if (GetId() > 0)
  31. {
  32. hdnRowId.Value = GetId().ToString();
  33. PupulateDataById();
  34. }
  35. else {
  36. fromDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
  37. toDate.Text = DateTime.Now.ToString("MM/dd/yyyy");
  38. }
  39. DispalyDocs(hdnRowId.Value);
  40. }
  41. DispalyDocs(hdnRowId.Value);
  42. }
  43. private void PupulateDataById()
  44. {
  45. DataRow dr = _dpMDao.SelectById(GetId().ToString(), GetStatic.GetUser());
  46. if (dr == null)
  47. return;
  48. RequiredFieldValidator6.Enabled = false;
  49. //scope.SelectedValue = dr["scope"].ToString();
  50. var scope = dr["scope"].ToString();
  51. if (scope == "admin")
  52. chkAdmin.Checked = true;
  53. else if (scope == "agent")
  54. chkAgent.Checked = true;
  55. else if (scope == "agentIntl")
  56. chkAgentIntl.Checked = true;
  57. else if (scope == "agentAgentIntl")
  58. {
  59. chkAgent.Checked = true;
  60. chkAgentIntl.Checked = true;
  61. }
  62. else if (scope == "adminAgentIntl")
  63. {
  64. chkAdmin.Checked = true;
  65. chkAgentIntl.Checked = true;
  66. }
  67. else if (scope == "adminAgent")
  68. {
  69. chkAdmin.Checked = true;
  70. chkAgent.Checked = true;
  71. }
  72. else if (scope == "all")
  73. {
  74. chkAdmin.Checked = true;
  75. chkAgent.Checked = true;
  76. chkAgentIntl.Checked = true;
  77. }
  78. else
  79. {
  80. chkAdmin.Checked = false;
  81. chkAgent.Checked = false;
  82. chkAgentIntl.Checked = false;
  83. }
  84. fileDescription.Text = dr["fileDescription"].ToString();
  85. imageLink.Text = dr["imageLink"].ToString();
  86. fromDate.Text = dr["fromDate"].ToString();
  87. toDate.Text = dr["toDate"].ToString();
  88. var enable = dr["isEnable"].ToString();
  89. if (enable == "Y")
  90. {
  91. isEnable.Checked = true;
  92. }
  93. else
  94. isEnable.Checked = false;
  95. }
  96. private void Authenticate()
  97. {
  98. sl.CheckAuthentication(ViewFunctionId);
  99. }
  100. public void DispalyDocs(string rowId)
  101. {
  102. var dt = _dpMDao.DisplayDocs(GetStatic.GetUser(), rowId);
  103. if (dt == null)
  104. {
  105. docDisplay.InnerHtml = "";
  106. return;
  107. }
  108. var sb = new StringBuilder();
  109. sb.Append(" <div class=\"table-responsive\"><table class=\"TBLData table table-striped table-bordered\" cellspacing=\"0\" cellpadding=\"0\" >");
  110. sb.Append("<tr>");
  111. sb.Append("<th>S.N.</th>");
  112. sb.Append("<th>File For</th>");
  113. sb.Append("<th>File Description</th>");
  114. sb.Append("<th>View</th>");
  115. sb.Append("</tr>");
  116. int cnt = 0;
  117. foreach (DataRow dr in dt.Rows)
  118. {
  119. cnt = cnt + 1;
  120. sb.Append("<tr>");
  121. sb.Append("<td>" + cnt + "</td>");
  122. sb.Append("<td>" + dr["scope"].ToString() + "</td>");
  123. sb.Append("<td>" + dr["fileDescription"].ToString() + "</td>");
  124. string fileLink = "id=" + dr["rowId"] + "&functionId=10111100";
  125. string filePage = GetStatic.GetUrlRoot() + "/ShowFile.aspx?" + fileLink;
  126. string PopUpParam = "dialogHeight:800px;dialogWidth:1000px;dialogLeft:300;dialogTop:100;center:yes";
  127. string jsText = "onclick = \"OpenInNewWindow('" + filePage + "','" + PopUpParam + "');\"";
  128. sb.Append("<td nowrap='nowrapnowrap'><a title = \"View File\" href=\"javascript:void(0)\" " + jsText + "\">" + Misc.GetIcon("info") + " </a>&nbsp;<span onclick=DeleteDoc('" + dr["rowId"].ToString() + "','temp')>" + Misc.GetIcon("delete") + "</span></td>");
  129. sb.Append("</tr>");
  130. }
  131. sb.Append("</table></div>");
  132. docDisplay.InnerHtml = sb.ToString();
  133. }
  134. private void Upload(string rowId)
  135. {
  136. var thisFile = fileUpload;
  137. var enable = "";
  138. var scope = "";
  139. if (chkAdmin.Checked == true)
  140. scope = "admin";
  141. if (chkAgent.Checked == true)
  142. scope = "agent";
  143. if (chkAgentIntl.Checked == true)
  144. scope = "agentIntl";
  145. if (chkAgentIntl.Checked == true && chkAgent.Checked == true)
  146. scope = "agentAgentIntl";
  147. if (chkAgentIntl.Checked == true && chkAdmin.Checked == true)
  148. scope = "adminAgentIntl";
  149. if (chkAgent.Checked == true && chkAdmin.Checked == true)
  150. scope = "adminAgent";
  151. if (chkAgentIntl.Checked == true && chkAgent.Checked == true && chkAdmin.Checked == true)
  152. scope = "all";
  153. if (isEnable.Checked == true)
  154. {
  155. enable = "Y";
  156. }
  157. else
  158. enable = "N";
  159. if (!string.IsNullOrWhiteSpace(thisFile.PostedFile.FileName))
  160. {
  161. string pFile = thisFile.PostedFile.FileName.Replace("\\", "/");
  162. var type = "";
  163. int pos = pFile.LastIndexOf(".");
  164. if (pos < 0)
  165. type = "";
  166. else
  167. type = pFile.Substring(pos + 1, pFile.Length - pos - 1);
  168. var root = GetStatic.GetFilePath();
  169. var info = UploadFile(rowId);
  170. if (info.Substring(0, 5) == "error")
  171. {
  172. GetStatic.AlertMessage(this, info);
  173. return;
  174. }
  175. DbResult dbResult = _dpMDao.Update(GetId().ToString(), GetStatic.GetUser(), scope, fileDescription.Text, type, enable, fromDate.Text, toDate.Text, imageLink.Text);
  176. if (dbResult.ErrorCode == "1")
  177. {
  178. GetStatic.AlertMessage(this, dbResult.Msg);
  179. return;
  180. }
  181. string locationToMove = root + "PopupMessage";
  182. string fileToCreate = locationToMove + "\\" + dbResult.Id;
  183. if (File.Exists(fileToCreate))
  184. File.Delete(fileToCreate);
  185. if (!Directory.Exists(locationToMove))
  186. Directory.CreateDirectory(locationToMove);
  187. File.Move(info, fileToCreate);
  188. lblMsg.Text = "File(s) Uploaded Successfully.";
  189. lblMsg.Attributes.Add("class", "SuccessMsg");
  190. }
  191. else
  192. {
  193. DbResult dbResult = _dpMDao.Update(GetId().ToString(), GetStatic.GetUser(), scope, fileDescription.Text, null, enable, fromDate.Text, toDate.Text,imageLink.Text);
  194. if (dbResult.ErrorCode == "1")
  195. {
  196. GetStatic.AlertMessage(this, dbResult.Msg);
  197. return;
  198. }
  199. lblMsg.Text = "Data Updated Successfully.";
  200. lblMsg.Attributes.Add("class", "SuccessMsg");
  201. }
  202. }
  203. public string UploadFile(string id)
  204. {
  205. var root = GetStatic.GetFilePath();
  206. var thisFile = fileUpload;
  207. if (thisFile.PostedFile.ContentLength == 0)
  208. {
  209. return "error:Invalid file content";
  210. }
  211. try
  212. {
  213. if (thisFile.PostedFile.ContentLength <= 2097152)
  214. {
  215. var saveFileLocation = root + "\\doc\\tmp\\";
  216. if (!Directory.Exists(saveFileLocation))
  217. Directory.CreateDirectory(saveFileLocation);
  218. var saved_file_name = saveFileLocation + id + "_" + GetStatic.GetSessionId();
  219. if (IsImage(thisFile))
  220. {
  221. var original_imagePath = root + "\\doc\\tmp\\" + id + "_org_" + GetStatic.GetSessionId();
  222. thisFile.PostedFile.SaveAs(original_imagePath);
  223. thisFile.PostedFile.SaveAs(saved_file_name);
  224. return saved_file_name;
  225. }
  226. return "error:Invalid File";
  227. }
  228. else
  229. {
  230. return "error:Unable to upload,file exceeds maximum limit";
  231. }
  232. }
  233. catch (UnauthorizedAccessException ex)
  234. {
  235. return "error:" + ex.Message + "Permission to upload file denied";
  236. }
  237. }
  238. public static bool IsImage(System.Web.UI.HtmlControls.HtmlInputFile fileUpload)
  239. {
  240. //-------------------------------------------
  241. // Check the image mime types
  242. //-------------------------------------------
  243. if (fileUpload.PostedFile.ContentType.ToLower() != "image/jpg" &&
  244. fileUpload.PostedFile.ContentType.ToLower() != "image/jpeg" &&
  245. fileUpload.PostedFile.ContentType.ToLower() != "image/pjpeg" &&
  246. fileUpload.PostedFile.ContentType.ToLower() != "image/gif" &&
  247. fileUpload.PostedFile.ContentType.ToLower() != "image/x-png" &&
  248. fileUpload.PostedFile.ContentType.ToLower() != "image/png")
  249. {
  250. return false;
  251. }
  252. //-------------------------------------------
  253. // Check the image extension
  254. //-------------------------------------------
  255. if (Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpg"
  256. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".png"
  257. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".gif"
  258. && Path.GetExtension(fileUpload.PostedFile.FileName).ToLower() != ".jpeg")
  259. {
  260. return false;
  261. }
  262. return true;
  263. }
  264. protected void uploadFIle_Click(object sender, EventArgs e)
  265. {
  266. Upload(hdnRowId.Value);
  267. DispalyDocs(hdnRowId.Value);
  268. }
  269. protected void deleteDoc_Click(object sender, EventArgs e)
  270. {
  271. var dbResult = _dpMDao.DeleteDoc(GetStatic.GetUser(), tempRowId.Value);
  272. if (dbResult.ErrorCode.Equals("0"))
  273. {
  274. lblMsg.Text = dbResult.Msg;
  275. lblMsg.Attributes.Add("class", "SuccessMsg");
  276. DispalyDocs(hdnRowId.Value);
  277. Response.Redirect("DynamicPopupList.aspx");
  278. }
  279. else
  280. {
  281. GetStatic.AlertMessage(Page, dbResult.Msg);
  282. return;
  283. }
  284. }
  285. protected long GetId()
  286. {
  287. return GetStatic.ReadNumericDataFromQueryString("rowId");
  288. }
  289. }
  290. }