Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using Microsoft.LightSwitch;
- using Microsoft.LightSwitch.Presentation.Extensions;
- using System.Windows.Controls;
- using System.Windows;
- using Microsoft.LightSwitch.Threading;
- using System.Windows.Browser;
- namespace LightSwitchApplication
- {
- public partial class Active_policies
- {
- PensoftDialog dialog;
- PensoftDialog dlg;
- PensoftDialog rect;
- partial void View_certificates_CanExecute(ref bool result)
- {
- result = this.Active_policies1.CanEdit;
- }
- partial void View_certificates_Execute()
- {
- this.OpenModalWindow("Group");
- }
- partial void View_debits_CanExecute(ref bool result)
- {
- result = this.Active_policies1.CanEdit;
- }
- partial void Print_risk_note_CanExecute(ref bool result)
- {
- result = this.NOTES.CanEdit;
- }
- partial void Print_risk_note_Execute()
- {
- PROPOSAL pro = this.Active_policies1.SelectedItem;
- if (pro.RISK_CLASS_CATEGORy1.RISK_CLASS_CATEGORY_NAME == "MOTOR")
- {
- Application.ShowMotorRiskNoteReport(this.NOTES.SelectedItem.ID);
- }
- else
- {
- Application.ShowRiskNoteReport(this.NOTES.SelectedItem.ID);
- }
- }
- partial void Active_policies_InitializeDataWorkspace(List<IDataService> saveChangesTo)
- {
- dialog = new PensoftDialog(this.Active_policies1, "Group2");
- dlg = new PensoftDialog(this.Active_policies1, "Group3");
- rect = new PensoftDialog(this.RECEIPTS, "Group1");
- }
- partial void Ok1_Execute()
- {
- PROPOSAL cust = this.Active_policies1.SelectedItem;
- if (cust.POLICY_CANCELLATION_REASON == null)
- {
- this.ShowMessageBox("Please provide cancellation reason", "Error", MessageBoxOption.Ok);
- return;
- }
- dynamic mq = this.ShowMessageBox("Are you sure you want to cancel the selected policy?", "Confirm", MessageBoxOption.YesNo);
- if (mq == MessageBoxResult.Yes)
- {
- cust.CANCELLATION_AWAITING_APPROVAL = 1;
- cust.LAST_ACTION_DATE = DateTime.Now;
- cust.CANCELLED_BY = Application.User.Name;
- dialog.DialogOK();
- this.DataWorkspace.BancassuranceData.SaveChanges();
- this.Refresh();
- }
- else
- {
- return;
- }
- }
- partial void Cancel1_Execute()
- {
- dialog.DialogCancel();
- }
- partial void Cancel_policy_CanExecute(ref bool result)
- {
- result = dialog.CanEditSelected() && Application.Current.User.HasPermission(Permissions.CanRaiseCancellation);
- }
- partial void Cancel_policy_Execute()
- {
- dialog.EditSelectedEntity();
- }
- partial void Active_policies_Created()
- {
- var uploader = this.FindControl("Uploader");
- uploader.ControlAvailable += (s, e) =>
- {
- Button hbutton = e.Control as Button;
- hbutton.Content = "Upload...";
- hbutton.Click -= hbutton_Click;
- hbutton.Click += hbutton_Click;
- };
- this.FindControl("PAYMENT_MODE").ControlAvailable += (s, e) =>
- {
- ((AutoCompleteBox)e.Control).SelectionChanged += PayMode_SelectionChanged;
- };
- }
- private void PayMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- string str = ((AutoCompleteBox)sender).Text;
- if (str.Contains("BANK TRANSFER"))
- {
- this.FindControl("REFERENCE_NO").IsEnabled = false;
- }
- else
- {
- this.FindControl("REFERENCE_NO").IsEnabled = true;
- }
- }
- private void hbutton_Click(object sender, RoutedEventArgs e)
- {
- if (POLICY_CANCELLATION_DOCUMENTS.SelectedItem.SUBMITTED == 1)
- {
- this.ShowMessageBox("A file associated with this record already exists", "Error", MessageBoxOption.Ok);
- return;
- }
- if (this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem == null)
- {
- this.ShowMessageBox("Please select a proposal document first", "No selected document", MessageBoxOption.Ok);
- return;
- }
- Button button = sender as Button;
- OpenFileDialog openFileDialog = new OpenFileDialog();
- string fileName = string.Empty;
- byte[] binaryData = null;
- if (openFileDialog.ShowDialog() == false)
- {
- SelectedFileName = string.Empty;
- }
- else
- {
- SelectedFileName = "Handling the file upload. Please wait….";
- IsBusy = true;
- try
- {
- using (FileStream fileStream = openFileDialog.File.OpenRead())
- {
- fileName = openFileDialog.File.Name;
- using (BinaryReader streamReader = new BinaryReader(fileStream))
- {
- binaryData = streamReader.ReadBytes((int)fileStream.Length);
- }
- fileStream.Close();
- }
- }
- catch (IOException)
- {
- this.Details.Dispatcher.BeginInvoke(() =>
- {
- this.ShowMessageBox("IO error…");
- SelectedFileName = "An error occured";
- IsBusy = false;
- });
- }
- }
- if (binaryData != null)
- this.StartWebApiCommand<FileUploadResponseParameters>("api/File/Upload", new FileUploadRequestParameters
- {
- BinaryData = binaryData,
- FileName = fileName,
- ReferenceId = this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.ID,
- TableRef = "PDC"
- },
- (error, responseParams) =>
- {
- IsBusy = false;
- SelectedFileName = fileName;
- if (error == null)
- {
- this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.SUBMITTED = 1;
- this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.STORE_ID = responseParams.Store;
- }
- if (error != null || responseParams.UploadStatus != "ok")
- SelectedFileName = "Something went wrong…";
- });
- }
- partial void Download_Execute()
- {
- POLICY_CANCELLATION_DOCUMENT pdoc = this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem;
- if (pdoc.SUBMITTED == 0)
- {
- this.ShowMessageBox("There is no such file uploaded", "File not found", MessageBoxOption.Ok);
- return;
- }
- int fileStoreId = Convert.ToInt32(pdoc.STORE_ID);
- Dispatchers.Main.Invoke(() =>
- {
- Uri baseAddress = new Uri(new Uri(System.Windows.Application.Current.Host.Source.AbsoluteUri), "../../"); //works both in debug and deployed !
- string url = string.Format(@"{0}api/File/Download?Id={1}", baseAddress.AbsoluteUri, fileStoreId);
- HtmlPage.Window.Navigate(new Uri(url), "_blank");
- });
- }
- partial void Remove_Execute()
- {
- 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);
- if (Mesag == MessageBoxResult.Yes)
- {
- FileMetaData meta = this.DataWorkspace.ApplicationData.FileMetaDatas
- .Where(o => o.Id == this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.STORE_ID).FirstOrDefault();
- this.Details.Dispatcher.BeginInvoke(() =>
- {
- meta.Delete();
- this.DataWorkspace.ApplicationData.SaveChanges();
- });
- this.POLICY_CANCELLATION_DOCUMENTS.SelectedItem.SUBMITTED = 0;
- }
- else
- {
- return;
- }
- }
- partial void Contra_CanExecute(ref bool result)
- {
- result = dlg.CanEditSelected() && Application.Current.User.HasPermission(Permissions.CanRaiseContra);
- }
- partial void Contra_Execute()
- {
- dlg.EditSelectedEntity();
- }
- partial void Ok2_Execute()
- {
- PROPOSAL policy = this.Active_policies1.SelectedItem;
- if (policy.POLICY_CANCELLATION_REASON1 == null)
- {
- this.ShowMessageBox("Please provide contra reason", "Error", MessageBoxOption.Ok);
- return;
- }
- dynamic mq = this.ShowMessageBox("Are you sure you want to raise a contra of this policy?", "Confirm", MessageBoxOption.YesNo);
- if (mq == MessageBoxResult.Yes)
- {
- policy.CONTRA_AWAITING_APPROVAL = 1;
- policy.CONTRA_BY = Application.User.Name;
- policy.DATE_CONTRA_RAISED = DateTime.Now;
- dlg.DialogOK();
- this.DataWorkspace.BancassuranceData.SaveChanges();
- this.Refresh();
- }
- else
- {
- return;
- }
- }
- partial void Cancel2_Execute()
- {
- dlg.DialogCancel();
- }
- partial void Print_CanExecute(ref bool result)
- {
- result = this.RECEIPTS.CanEdit;
- }
- partial void Print_Execute()
- {
- Application.ShowReceipt_rpt(this.RECEIPTS.SelectedItem.ID);
- }
- partial void Ok3_Execute()
- {
- rect.DialogOK();
- }
- partial void Cancel3_Execute()
- {
- rect.DialogCancel();
- }
- partial void RECEIPTSAddAndEditNew_CanExecute(ref bool result)
- {
- result = rect.CanAdd();
- }
- partial void RECEIPTSAddAndEditNew_Execute()
- {
- rect.AddEntity();
- }
- partial void Import_Execute()
- {
- ExcelImporter.Importer.ImportFromExcel(this.Active_policies1);
- }
- partial void Endorse_CanExecute(ref bool result)
- {
- result = this.Active_policies1.CanEdit;
- }
- partial void Endorse_Execute()
- {
- dynamic messag = this.ShowMessageBox("Are you sure you want to endorse this policy?", "Confirm", MessageBoxOption.YesNo);
- if (messag == MessageBoxResult.Yes)
- {
- Application.ShowCreateNewEndorsement(this.Active_policies1.SelectedItem.ID);
- }
- else
- {
- return;
- }
- }
- partial void ViewStatement_CanExecute(ref bool result)
- {
- result = this.Active_policies1.SelectedItem != null;
- }
- partial void ViewStatement_Execute()
- {
- Application.ShowClientStatementReport(this.Active_policies1.SelectedItem.SUBSIDIARY_LEDGER2.ID);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement