예제 #1
0
        private Boolean Login()
        {
            // BarCodeController barCodeController;
            Boolean isLoginOk   = false;
            string  userBarcode = "";


            if (Config.GetApplicationMode() == Config.ApplicationMode.Lab)
            {
                // LAB MODE
                // Enable background bar code listening.
                KeyPreview = true;

                if (!LoginDataBase())
                {
                    return(false);
                }

                do
                {
                    // Get login information.
                    MyLoginWithBarcodeDialog = new LoginWithBarcodeDialog();

                    // Login by bar code is currently not supported.
                    // barCodeController = new BarCodeController(MyLoginForm);
                    // barCodeController.BarCodeReceived += ExecuteBarCode;
                    if (MyLoginWithBarcodeDialog.ShowDialog() == DialogResult.OK)
                    {
                        userBarcode = MyLoginWithBarcodeDialog.Barcode;
                        MyLoginWithBarcodeDialog = null;
                    }
                    else
                    {
                        // The user cancelled.
                        return(false);
                    }
                }   // Try to login to the database.
                while (!SetAuthorityMappingForBarcode(userBarcode));

                UserManager.Refresh();
                Text = Config.GetDialogTitleStandard() + " - " + UserManager.GetCurrentUser().GetName();

                // Start the activity timer. It is used for automatic logout in lab mode.
                this.ActivityTimer.Enabled = true;
                MyActivityCounter          = 0;
                isLoginOk = true;
            }
            else
            {
                // OFFICE MODE
                isLoginOk = LoginDataBase();
                SetAuthorityMappingFromSysUser();
            }

            if (!UserManager.GetCurrentUser().IsAccountActive())
            {
                throw new Exception("User " + UserManager.GetCurrentUser().GetName() + " has been inactivated");
            }

            if (isLoginOk)
            {
                // Cache data.
                // This is done in order to avoid DateReader already open exception.
                ChiasmaDepData.Refresh();
                //ActivityTimer.Enabled = true;
            }

            return(isLoginOk);
        }
예제 #2
0
        public bool Login(bool versionControl)
        {
            // BarCodeController barCodeController;
            Boolean isLoginOk = false;
            String  version;
            String  applicationName;
            string  barcode;

            if (Config.GetApplicationMode() == Config.ApplicationMode.Lab)
            {
                // LAB MODE
                // Enable background bar code listening.
                KeyPreview = true;

                if (!LoginDataBase())
                {
                    return(false);
                }

                do
                {
                    // Get login information.
                    MyLoginWithBarcodeDialog = new LoginWithBarcodeDialog();

                    // Login by bar code is currently not supported.
                    // barCodeController = new BarCodeController(MyLoginForm);
                    // barCodeController.BarCodeReceived += ExecuteBarCode;
                    if (MyLoginWithBarcodeDialog.ShowDialog() == DialogResult.OK)
                    {
                        barcode = MyLoginWithBarcodeDialog.Barcode;
                        MyLoginWithBarcodeDialog = null;
                    }
                    else
                    {
                        // The user cancelled.
                        LogoutDatabase();
                        return(false);
                    }
                }   // Try to login to the database.
                while (!SetAuthorityMappingForBarcode(barcode));


                UserManager.Refresh();
                Text = Config.GetDialogTitleStandard() + " - " + UserManager.GetCurrentUser().GetName();

                // Start the activity timer. It is used for automatic logout in lab mode.
                ActivityTimer.Enabled = false;
                MyActivityCounter     = 0;
                isLoginOk             = true;
            }
            else
            {
                // OFFICE MODE
                isLoginOk = LoginDataBase();
                SetAuthorityMappingFromSysUser();
            }

            if (!UserManager.GetCurrentUser().IsAccountActive())
            {
                throw new Exception("User " + UserManager.GetCurrentUser().GetName() + " has been inactivated");
            }

            if (isLoginOk)
            {
                if (versionControl)
                {
                    // Get version number of the current assembly.
                    version = Assembly.GetExecutingAssembly().GetName().Version.Major + "." +
                              Assembly.GetExecutingAssembly().GetName().Version.Minor + "." +
                              Assembly.GetExecutingAssembly().GetName().Version.Build + "." +
                              Assembly.GetExecutingAssembly().GetName().Version.Revision;

                    // Get the name of the current assembly.
                    applicationName = Assembly.GetExecutingAssembly().GetName().Name;

                    // Make sure the current application is allowed to connect.
                    if (!ChiasmaDepData.Database.AuthenticateApplication(applicationName, version))
                    {
                        HandleError("The current version of this program is not allowed to connect to the database.", null);
                        return(false);
                    }
                }

                // Cache data.
                // This is done in order to avoid DateReader already open exception.
                ChiasmaDepData.Refresh();
            }

            return(isLoginOk);
        }