/// <summary> /// Used to print over the voucher image /// </summary> /// <returns></returns> public static VoucherProcessDelegate CreatePrintOnImageDelegate() { var method = new VoucherProcessDelegate((Voucher data, StateObj state) => { var printLocation = SettingsTable.Get <Point>(Strings.VScan_PrintAreaLocation, Point.Empty); if (printLocation == Point.Empty) { var ex = new ApplicationException("Cannot find 'print on image' configuration."); ex.AddNext(new MethodInvoker(() => { string id = Strings.VScan_EditItem.Uniqueue(); data.Message = ex.Message; DataSlot.Set(id, data); WinMsg.SendText(state.Scan, state.Main, id); })); throw ex; } var aliases = new Hashtable(StringComparer.InvariantCultureIgnoreCase); aliases["[DATE]"] = new Func <string>(() => DateTime.Now.ToString()); aliases["[OPERATOR]"] = new Func <string>(() => SettingsTable.Get <UserAuth>(Strings.Transferring_AuthObject, UserAuth.Default).Name); aliases["[PCNAME]"] = new Func <string>(() => PTFUtils.GetMachine()); aliases["[SITEID]"] = new Func <string>(() => data.SiteCode); aliases["[NUMBER]"] = new Func <string>(() => Convert.ToString(SettingsTable.Get <int>(Strings.VScan_ScanCount, 0))); string voucherTemplate = SettingsTable.Get <string>(Strings.VScan_ImPrinterTemplate, Strings.VScan_ImPrinterTemplateDefault); string voucherText = voucherTemplate.format(aliases); using (var g = Graphics.FromImage(data.VoucherImage)) g.DrawString(voucherText, SystemFonts.CaptionFont, Brushes.Red, printLocation); }); return(method); }
/// <summary> /// Sets messages as exported to the client database asynchronously /// </summary> /// <param name="messageId"></param> public static void SetMessageExportedAsync(int messageId) { SQLWorker.Default.Add(CreateSetMessageExportedCommand(messageId), null, // Skip error messages PTFUtils.EmptyThreadExceptionEventHandler()); }
/// <summary> /// Insert message to the database. Do not fire errors. /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="stacktrase"></param> /// <param name="onServer"></param> public static void InsertMessageAsync(string message, int clientID, eSources source, eMessageTypes type, string stackTrase, DateTime dateGenerated) { // Do not refire errors SQLWorker.Default.Add(CreateInsertMessage(message, clientID, source, type, stackTrase, dateGenerated), //No Errors! PTFUtils.EmptyThreadExceptionEventHandler()); }
static ScanForm() { ms_Aliases["[DATE]"] = new Func <string>(() => DateTime.Now.ToString()); ms_Aliases["[OPERATOR]"] = new Func <string>(() => SettingsTable.Get <UserAuth>(Strings.Transferring_AuthObject, UserAuth.Default).Name); ms_Aliases["[PCNAME]"] = new Func <string>(() => PTFUtils.GetMachine()); ms_Aliases["[SITEID]"] = new Func <string>(() => { Debug.Assert(ms_Current != null && ms_Current.VoucherData != null); return(ms_Current.VoucherData.SiteCode); }); ms_Aliases["[NUMBER]"] = new Func <string>(() => Convert.ToString(SettingsTable.Get <int>(Strings.VScan_ScanCount, 0))); }
/// <summary> /// Used to insert voucher data to the database /// </summary> /// <returns></returns> public static VoucherProcessDelegate CreateInsertVoucherDelegate() { var method = new VoucherProcessDelegate((Voucher data, StateObj state) => { Debug.Assert(state.Dib != IntPtr.Zero); Debug.Assert(state.Main != IntPtr.Zero); Debug.Assert(state.Scan != IntPtr.Zero); Debug.Assert(data != null); try { data.Validate(); ClientDataAccess.UpdateFileAsync((DbClientVoucher)data, new EventHandler((o, e) => { string fileName = Path.ChangeExtension( string.Format("{0}{1}", PTFUtils.GetMachine(), DateTime.Now).ReplaceAll(new char[] { '.', '/', '\\', '-' }, '_'), ".xml"); //Data has been saved successfully. Show message string id = string.Concat(Strings.VScan_ItemSaved, fileName); DataSlot.Set(id, data); WinMsg.SendText(state.Main, id); }), new ThreadExceptionEventHandler((o, e) => { //Data has failed to save. var ex = new ApplicationException("Can't insert: ".concat(e.Exception.Message), e.Exception); ex.AddNext(new MethodInvoker(() => { string id = Strings.VScan_EditItem.Uniqueue(); data.Message = ex.Message; DataSlot.Set(id, data); WinMsg.SendText(state.Scan, state.Main, id); })); throw ex; })); } catch (Exception e) { var ex = new ApplicationException("Err: ".concat(e.Message), e); ex.AddNext(new MethodInvoker(() => { string id = Strings.VScan_EditItem.Uniqueue(); data.Message = ex.Message; DataSlot.Set(id, data); WinMsg.SendText(state.Main, id); })); throw ex; } }); return(method); }
private void CreateRemoteClient_Click(object sender, System.EventArgs e) { new MethodInvoker(() => { this.BeginInvokeSafe(new MethodInvoker(() => errorProvider.SetError(btnCreateClient, null))); try { string url = SettingsTable.Get <string>(Strings.All_CentralServerUrl, Strings.All_CentralServerUrlPathDefault); string machineName = PTFUtils.GetMachine(); var clientId = DataServiceClient.CallCreateClient(machineName); } catch (Exception ex) { this.BeginInvokeSafe(new MethodInvoker(() => errorProvider.SetError(btnCreateClient, ex.Message))); throw; } }).FireAndForget(); }
public void ExportAndCloseAsync() { if (this.Parent != null) { IntPtr main = this.Parent.Handle; Voucher bData = Canvas.Data; bData.VoucherImage = (Bitmap)Canvas.BackgroundImage; var cnts = Canvas.Controls.Find(ManualInsertDataControl.MANUALINSERT_DATACONTROL_NAME, true); if (cnts != null && cnts.Length != 0) { ManualInsertDataControl cnt = (ManualInsertDataControl)cnts[0]; if (!string.IsNullOrEmpty(cnt.BarCodeString)) { bData.Parse(cnt.BarCodeString); } else { string[] str = cnt.BarCodeNumberGroups; bData.CountryID = int.Parse(str[0]); //bData.Business = int.Parse(str[1]); bData.RetailerID = int.Parse(str[2]); bData.VoucherID = str[3]; bData.BarCodeString = string.Format("{0:000}{1:00}{2:000000}{3:000000000}", bData.CountryID, "na", bData.RetailerID, bData.VoucherID); } } new Action <Voucher>((data) => { Debug.Assert(data != null); Debug.Assert(data.VoucherImage != null); lock (data.VoucherImage) { try { DelegateUtils.CreateAuditIdReloadDelegate().FireAndForget(); data.SiteCode = AuditIDSTable.SelectRemoveFirstOrEmpty().ThrowIfDefault <string, AppExclamationException>(); data.Validate(); ClientDataAccess.UpdateFileAsync((DbClientVoucher)data, new EventHandler((o, s) => { string fileName = Path.ChangeExtension( string.Format("{0}{1}", PTFUtils.GetMachine(), DateTime.Now).ReplaceAll(new char[] { '.', '/', '\\', '-' }, '_'), ".xml"); //Data has been saved successfully. string text = string.Concat(Strings.VScan_ItemSaved, fileName); WinMsg.SendText(main, text); this.InvokeSf(() => { //Set DialogResult OK //Or else the form will resign to close this.DialogResult = DialogResult.OK; this.Close(); }); }), //No error handling. //General processing handler. null); } catch (Exception ee) { ee.AddNext(new MethodInvoker(() => { Canvas.InvokeSf(() => { Canvas.ShowInputControl(ee.Message); }); })); throw; } } }).FireAndForget(bData); } }