Exemple #1
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);
        }
Exemple #2
0
        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);
            }
        }