Esempio n. 1
0
 private void Window_Closing(object sender, CancelEventArgs e)
 {
     if (!AllowClose)
     {
         e.Cancel = true;
     }
     else
     {
         DeviceManager.ClosePosDevices();
         DataModelBase.CloseAll();
     }
 }
Esempio n. 2
0
        void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;

            // Stop the auto-logoof timer
            LoginControl.StopAutoLogoutTimer();

            // Close all database connections
            DataModelBase.CloseAll();

#if !DEMO
            // Send the exception to the upgrade server
            Updater.StartCrashReport(e.Exception);
#endif
            // Save the exception, serialized to the AppData folder
            try
            {
                DateTime now           = DateTime.Now;
                string   rootDirectory =
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) +
                    Path.DirectorySeparatorChar + "TemPOS";
                if (!Directory.Exists(rootDirectory))
                {
                    Directory.CreateDirectory(rootDirectory);
                }
                string path = rootDirectory + Path.DirectorySeparatorChar + "crashdata-" +
                              now.Year + now.Month.ToString("D2") + now.Day.ToString("D2") + "-" +
                              now.Hour.ToString("D2") + now.Minute.ToString("D2") + now.Second.ToString("D2") +
                              ".bin";
                using (FileStream fileStream = new FileStream(path, FileMode.CreateNew))
                {
                    byte[] serialData = e.Exception.SerializeObject();
                    using (BinaryWriter writer = new BinaryWriter(fileStream))
                    {
                        writer.Write(serialData);
                    }
                }
            }
            catch { }

            // Display the exception message
            DisplayExceptionDialog(e.Exception);

            // Remove employee table lock (that prevents simultaneous login)
            if (SessionManager.ActiveEmployee != null)
            {
                PosHelper.Unlock(TableName.Employee, SessionManager.ActiveEmployee.Id);
            }

            // Close this app
            if (_mainWindow != null)
            {
                _mainWindow.AllowClose = true;
                _mainWindow.Close();
            }

            // Disable user control crap
            if (ConfigurationManager.UseKeyboardHook)
            {
                UserControlManager.Disable();
            }

            UserControlManager.ShowTaskbar(true);
#if !DEBUG
            if (PastRestartPoint)
            {
                // Restart application
                Process.Start(Application.ResourceAssembly.Location, "/RESTART");
                App.SwitchToDefaultDesktopOnClose = false;
            }
            else
            {
                App.SwitchToDefaultDesktopOnClose = true;
            }
#else
            App.SwitchToDefaultDesktopOnClose = true;
#endif
            // Shutdown current application
            Application.Current.Shutdown();
            Process.GetCurrentProcess().Kill();
        }