Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.80 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using Microsoft.LightSwitch;
  5. using Microsoft.LightSwitch.Presentation.Extensions;
  6. using System.Windows.Controls;
  7. using System.Windows;
  8. using Microsoft.LightSwitch.Threading;
  9. using System.Windows.Browser;
  10. namespace LightSwitchApplication
  11. {
  12. public partial class Active_policies
  13. {
  14. PensoftDialog dialog;
  15. PensoftDialog dlg;
  16. PensoftDialog rect;
  17. partial void View_certificates_CanExecute(ref bool result)
  18. {
  19. result = this.Active_policies1.CanEdit;
  20. }
  21.  
  22. partial void View_certificates_Execute()
  23. {
  24. this.OpenModalWindow("Group");
  25. }
  26.  
  27. partial void View_debits_CanExecute(ref bool result)
  28. {
  29. result = this.Active_policies1.CanEdit;
  30. }
  31.  
  32. partial void Print_risk_note_CanExecute(ref bool result)
  33. {
  34. result = this.NOTES.CanEdit;
  35. }
  36.  
  37. partial void Print_risk_note_Execute()
  38. {
  39. PROPOSAL pro = this.Active_policies1.SelectedItem;
  40. if (pro.RISK_CLASS_CATEGORy1.RISK_CLASS_CATEGORY_NAME == "MOTOR")
  41. {
  42. Application.ShowMotorRiskNoteReport(this.NOTES.SelectedItem.ID);
  43. }
  44. else
  45. {
  46. Application.ShowRiskNoteReport(this.NOTES.SelectedItem.ID);
  47. }
  48. }
  49.  
  50. partial void Active_policies_InitializeDataWorkspace(List<IDataService> saveChangesTo)
  51. {
  52. dialog = new PensoftDialog(this.Active_policies1, "Group2");
  53. dlg = new PensoftDialog(this.Active_policies1, "Group3");
  54. rect = new PensoftDialog(this.RECEIPTS, "Group1");
  55. }
  56.  
  57. partial void Ok1_Execute()
  58. {
  59. PROPOSAL cust = this.Active_policies1.SelectedItem;
  60. if (cust.POLICY_CANCELLATION_REASON == null)
  61. {
  62. this.ShowMessageBox("Please provide cancellation reason", "Error", MessageBoxOption.Ok);
  63. return;
  64. }
  65. dynamic mq = this.ShowMessageBox("Are you sure you want to cancel the selected policy?", "Confirm", MessageBoxOption.YesNo);
  66. if (mq == MessageBoxResult.Yes)
  67. {
  68. cust.CANCELLATION_AWAITING_APPROVAL = 1;
  69. cust.LAST_ACTION_DATE = DateTime.Now;
  70. cust.CANCELLED_BY = Application.User.Name;
  71. dialog.DialogOK();
  72. this.DataWorkspace.BancassuranceData.SaveChanges();
  73. this.Refresh();
  74. }
  75. else
  76. {
  77. return;
  78. }
  79. }
  80.  
  81. partial void Cancel1_Execute()
  82. {
  83. dialog.DialogCancel();
  84. }
  85.  
  86. partial void Cancel_policy_CanExecute(ref bool result)
  87. {
  88. result = dialog.CanEditSelected() && Application.Current.User.HasPermission(Permissions.CanRaiseCancellation);
  89. }
  90.  
  91. partial void Cancel_policy_Execute()
  92. {
  93. dialog.EditSelectedEntity();
  94. }
  95.  
  96. partial void Active_policies_Created()
  97. {
  98. var uploader = this.FindControl("Uploader");
  99. uploader.ControlAvailable += (s, e) =>
  100. {
  101. Button hbutton = e.Control as Button;
  102. hbutton.Content = "Upload...";
  103. hbutton.Click -= hbutton_Click;
  104. hbutton.Click += hbutton_Click;
  105. };
  106. this.FindControl("PAYMENT_MODE").ControlAvailable += (s, e) =>
  107. {
  108. ((AutoCompleteBox)e.Control).SelectionChanged += PayMode_SelectionChanged;
  109. };
  110. }
  111.  
  112. private void PayMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
  113. {
  114. string str = ((AutoCompleteBox)sender).Text;
  115.  
  116. if (str.Contains("BANK TRANSFER"))
  117. {
  118. this.FindControl("REFERENCE_NO").IsEnabled = false;
  119. }
  120. else
  121. {
  122. this.FindControl("REFERENCE_NO").IsEnabled = true;
  123. }
  124. }
  125.  
  126. private void hbutton_Click(object sender, RoutedEventArgs e)
  127. {
  128. if (POLICY_CANCELLATION_DOCUMENTS.SelectedItem.SUBMITTED == 1)
  129. {
  130. this.ShowMessageBox("A file associated with this record already exists", "Error", MessageBoxOption.Ok);
  131. return;
  132. }
  133. if (this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem == null)
  134. {
  135. this.ShowMessageBox("Please select a proposal document first", "No selected document", MessageBoxOption.Ok);
  136. return;
  137. }
  138. Button button = sender as Button;
  139. OpenFileDialog openFileDialog = new OpenFileDialog();
  140.  
  141. string fileName = string.Empty;
  142. byte[] binaryData = null;
  143.  
  144. if (openFileDialog.ShowDialog() == false)
  145. {
  146. SelectedFileName = string.Empty;
  147. }
  148. else
  149. {
  150. SelectedFileName = "Handling the file upload. Please wait….";
  151. IsBusy = true;
  152. try
  153. {
  154. using (FileStream fileStream = openFileDialog.File.OpenRead())
  155. {
  156. fileName = openFileDialog.File.Name;
  157. using (BinaryReader streamReader = new BinaryReader(fileStream))
  158. {
  159. binaryData = streamReader.ReadBytes((int)fileStream.Length);
  160. }
  161. fileStream.Close();
  162. }
  163. }
  164.  
  165. catch (IOException)
  166. {
  167. this.Details.Dispatcher.BeginInvoke(() =>
  168. {
  169. this.ShowMessageBox("IO error…");
  170. SelectedFileName = "An error occured";
  171. IsBusy = false;
  172. });
  173. }
  174. }
  175. if (binaryData != null)
  176. this.StartWebApiCommand<FileUploadResponseParameters>("api/File/Upload", new FileUploadRequestParameters
  177. {
  178. BinaryData = binaryData,
  179. FileName = fileName,
  180. ReferenceId = this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.ID,
  181. TableRef = "PDC"
  182. },
  183. (error, responseParams) =>
  184. {
  185. IsBusy = false;
  186. SelectedFileName = fileName;
  187. if (error == null)
  188. {
  189. this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.SUBMITTED = 1;
  190. this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.STORE_ID = responseParams.Store;
  191. }
  192. if (error != null || responseParams.UploadStatus != "ok")
  193. SelectedFileName = "Something went wrong…";
  194. });
  195. }
  196.  
  197. partial void Download_Execute()
  198. {
  199. POLICY_CANCELLATION_DOCUMENT pdoc = this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem;
  200. if (pdoc.SUBMITTED == 0)
  201. {
  202. this.ShowMessageBox("There is no such file uploaded", "File not found", MessageBoxOption.Ok);
  203. return;
  204. }
  205. int fileStoreId = Convert.ToInt32(pdoc.STORE_ID);
  206.  
  207. Dispatchers.Main.Invoke(() =>
  208. {
  209. Uri baseAddress = new Uri(new Uri(System.Windows.Application.Current.Host.Source.AbsoluteUri), "../../"); //works both in debug and deployed !
  210. string url = string.Format(@"{0}api/File/Download?Id={1}", baseAddress.AbsoluteUri, fileStoreId);
  211. HtmlPage.Window.Navigate(new Uri(url), "_blank");
  212. });
  213. }
  214.  
  215. partial void Remove_Execute()
  216. {
  217. dynamic Mesag = this.ShowMessageBox("Are you sure you want to delete the file associated with this item? Please note that once committed it cannot be undone.", "Confirm", MessageBoxOption.YesNo);
  218. if (Mesag == MessageBoxResult.Yes)
  219. {
  220. FileMetaData meta = this.DataWorkspace.ApplicationData.FileMetaDatas
  221. .Where(o => o.Id == this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.STORE_ID).FirstOrDefault();
  222. this.Details.Dispatcher.BeginInvoke(() =>
  223. {
  224. meta.Delete();
  225. this.DataWorkspace.ApplicationData.SaveChanges();
  226. });
  227. this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.SUBMITTED = 0;
  228. }
  229. else
  230. {
  231. return;
  232. }
  233. }
  234.  
  235. partial void Contra_CanExecute(ref bool result)
  236. {
  237. result = dlg.CanEditSelected() && Application.Current.User.HasPermission(Permissions.CanRaiseContra);
  238. }
  239.  
  240. partial void Contra_Execute()
  241. {
  242. dlg.EditSelectedEntity();
  243. }
  244.  
  245. partial void Ok2_Execute()
  246. {
  247. PROPOSAL policy = this.Active_policies1.SelectedItem;
  248. if (policy.POLICY_CANCELLATION_REASON1 == null)
  249. {
  250. this.ShowMessageBox("Please provide contra reason", "Error", MessageBoxOption.Ok);
  251. return;
  252. }
  253. dynamic mq = this.ShowMessageBox("Are you sure you want to raise a contra of this policy?", "Confirm", MessageBoxOption.YesNo);
  254. if (mq == MessageBoxResult.Yes)
  255. {
  256. policy.CONTRA_AWAITING_APPROVAL = 1;
  257. policy.CONTRA_BY = Application.User.Name;
  258. policy.DATE_CONTRA_RAISED = DateTime.Now;
  259. dlg.DialogOK();
  260. this.DataWorkspace.BancassuranceData.SaveChanges();
  261. this.Refresh();
  262. }
  263. else
  264. {
  265. return;
  266. }
  267. }
  268.  
  269. partial void Cancel2_Execute()
  270. {
  271. dlg.DialogCancel();
  272. }
  273.  
  274. partial void Print_CanExecute(ref bool result)
  275. {
  276. result = this.RECEIPTS.CanEdit;
  277. }
  278.  
  279. partial void Print_Execute()
  280. {
  281. Application.ShowReceipt_rpt(this.RECEIPTS.SelectedItem.ID);
  282. }
  283.  
  284. partial void Ok3_Execute()
  285. {
  286. rect.DialogOK();
  287. }
  288.  
  289. partial void Cancel3_Execute()
  290. {
  291. rect.DialogCancel();
  292. }
  293.  
  294. partial void RECEIPTSAddAndEditNew_CanExecute(ref bool result)
  295. {
  296. result = rect.CanAdd();
  297. }
  298.  
  299. partial void RECEIPTSAddAndEditNew_Execute()
  300. {
  301. rect.AddEntity();
  302. }
  303.  
  304. partial void Import_Execute()
  305. {
  306. ExcelImporter.Importer.ImportFromExcel(this.Active_policies1);
  307. }
  308.  
  309. partial void Endorse_CanExecute(ref bool result)
  310. {
  311. result = this.Active_policies1.CanEdit;
  312. }
  313.  
  314. partial void Endorse_Execute()
  315. {
  316. dynamic messag = this.ShowMessageBox("Are you sure you want to endorse this policy?", "Confirm", MessageBoxOption.YesNo);
  317. if (messag == MessageBoxResult.Yes)
  318. {
  319. Application.ShowCreateNewEndorsement(this.Active_policies1.SelectedItem.ID);
  320. }
  321. else
  322. {
  323. return;
  324. }
  325. }
  326.  
  327. partial void ViewStatement_CanExecute(ref bool result)
  328. {
  329. result = this.Active_policies1.SelectedItem != null;
  330. }
  331.  
  332. partial void ViewStatement_Execute()
  333. {
  334. Application.ShowClientStatementReport(this.Active_policies1.SelectedItem.SUBSIDIARY_LEDGER2.ID);
  335. }
  336. }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement