Пример #1
0
        private void LogIn()
        {
            if (IsValidForm())
            {
                try
                {
                    Application.DoEvents();
                    Cursor = Cursors.WaitCursor;

                    string passwordHash1 = (_PasswordHash1.Length == 0 ? CryptoHelper.Encrypt(Password, ConfigurationManagerEx.Salt, HashAlgorithmType.SHA1) : _PasswordHash1);
                    string passwordHash2 = CryptoHelper.Encrypt(passwordHash1, ConfigurationManagerEx.Salt, HashAlgorithmType.SHA1);

                    var table = UserManager.LogIn(Username, passwordHash2);

                    if (table.Count > 0)
                    {
                        if (table[0].UserStatus == (byte)DatabaseStatus.Blocked)
                        {
                            throw new Exception("მომხმარებელი დაბლოკილია.");
                        }

                        if (table[0].UserStatus == (byte)DatabaseStatus.Pending)
                        {
                            throw new Exception("მომხმარებელი არ არის დადასტურებული.");
                        }

                        if (table[0].BranchStatus == (byte)DatabaseStatus.Blocked)
                        {
                            throw new Exception("ოფისი, რომელშიც იმყოფება მომხმარებელი დაბლოკილია.");
                        }

                        var loginUserName = chkSave.Checked ? Username : string.Empty;
                        var loginPassword = chkSave.Checked ? passwordHash1 : string.Empty;
                        if (ConfigurationManagerEx.LoginUserName != loginUserName || ConfigurationManagerEx.LoginPassword != loginPassword)
                        {
                            ConfigurationManagerEx.LoginUserName = loginUserName;
                            ConfigurationManagerEx.LoginPassword = loginPassword;
                            ConfigurationManagerEx.Save();
                        }

                        var permission     = UserManager.GetUserPermission(table[0].UserID);
                        var userPermission = new Dictionary <string, int>();
                        foreach (DS_User.SP_GetUserPermissionRow row in permission.Rows)
                        {
                            if (!userPermission.ContainsKey(row.ObjectID.ToString()))
                            {
                                userPermission.Add(row.ObjectID.ToString(), row.Logical);
                            }
                            else
                            {
                                userPermission[row.ObjectID.ToString()] |= row.Logical;
                            }
                        }


                        GlobalVariable.IsLogged           = true;
                        BaseGlobalVariable.UserID         = table[0].UserID;
                        GlobalVariable.Username           = Username;
                        BaseGlobalVariable.Password       = Password;
                        GlobalVariable.BranchID           = table[0].BranchID;
                        BaseGlobalVariable.ServerDateTime = table[0].ServerDateTime.AddMilliseconds(-table[0].ServerDateTime.Millisecond);
                        BaseGlobalVariable.Permissions    = userPermission;

                        //GlobalVariable.PersonID = PersonManager.FindPersonID(GlobalVariable.UserID);
                        //if (GlobalVariable.PersonID != 0)
                        //{
                        //    DS_Person.T_PersonDataTable person = PersonManager.GetPerson(GlobalVariable.PersonID);
                        //    if (person.Count > 0)
                        //    {
                        //        GlobalVariable.FullName = person[0].FullName;
                        //        GlobalVariable.JobTitle = person[0].JobTitle;
                        //    }
                        //}


                        var myCompany = PersonManager.GetMyCompany(0, !ConfigurationManagerEx.OfflineMode);
                        if (myCompany.Count > 0)
                        {
                            GlobalVariable.MyCompanyName                        = myCompany[0].MyCompanyName;
                            GlobalVariable.MyCompanyTaxCode                     = myCompany[0].TaxCode;
                            GlobalVariable.MyCompanyDirectorName                = myCompany[0].DirectorName;
                            GlobalVariable.MyCompanyCountryCode                 = myCompany[0].CountryCode;
                            GlobalVariable.MyCompanyCountryName                 = myCompany[0].CountryName;
                            GlobalVariable.MyCompanyCity                        = myCompany[0].City;
                            GlobalVariable.MyCompanyPostalCode                  = myCompany[0].PostalCode;
                            GlobalVariable.MyCompanyAddress                     = myCompany[0].Address;
                            GlobalVariable.MyCompanyPhone                       = myCompany[0].Phone;
                            GlobalVariable.MyCompanyFax                         = myCompany[0].Fax;
                            GlobalVariable.MyCompanyBankName                    = myCompany[0].BankName;
                            GlobalVariable.MyCompanyBankCode                    = myCompany[0].BankCode;
                            GlobalVariable.MyCompanyBankAccountNumber           = myCompany[0].BankAccountNumber;
                            GlobalVariable.VATPayerFlag                         = myCompany[0].VATPayerFlag;
                            GlobalVariable.MyCompanyConditionalUnitCurrencyCode = myCompany[0].ConditionalUnitCurrencyCode;
                            GlobalVariable.MyCompanyDefaultTradingCurrencyCode  = myCompany[0].DefaultTradingCurrencyCode;
                        }

                        DialogResult = DialogResult.OK;
                    }
                    else if (GlobalVariable.AdminLogIn(Username, Password))
                    {
                        DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        lblStatus.Text = "სახელი ან პაროლი არასწორია";
                        txtPassword.SelectAll();
                    }
                }
                catch (Exception ex)
                {
                    ExceptionHelper.Show(this, ex, "სისტემაში შესვლა ვერ მოხერხდა", MessageBoxIcon.Error);
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }