Exemplo n.º 1
0
        void UpdateUsers()
        {
            if (!QSMain.TestConnection())
            {
                return;
            }
            QSMain.CheckConnectionAlive();
            logger.Info("Получаем таблицу пользователей...");

            string sql = "SELECT * FROM users ";

            if (!chkShowInactive.Active)
            {
                sql += " WHERE deactivated = 0";
            }
            MySqlCommand cmd = new MySqlCommand(sql, QSMain.connectionDB);

            MySqlDataReader rdr = cmd.ExecuteReader();

            UsersListStore.Clear();
            while (rdr.Read())
            {
                bool deactivated = false;
                try {
                    deactivated = DBWorks.GetBoolean(rdr, "deactivated", false);
                } catch {
                    logger.Warn("В базе отсутствует поле deactivated!");
                }
                UsersListStore.AppendValues(int.Parse(rdr ["id"].ToString()),
                                            rdr ["login"].ToString(),
                                            rdr ["name"].ToString(),
                                            (bool)rdr ["admin"],
                                            deactivated,
                                            deactivated ? "grey" : "black");
            }
            rdr.Close();

            logger.Info("Ok");

            OnTreeviewUsersCursorChanged(null, null);
        }
Exemplo n.º 2
0
        public void UserFill(int UserId)
        {
            NewUser = false;
            logger.Info("Запрос пользователя №{0}...", UserId);
            string sql = "SELECT * FROM users WHERE users.id = @id";

            try {
                QSMain.CheckConnectionAlive();
                MySqlCommand cmd = new MySqlCommand(sql, QSMain.connectionDB);

                cmd.Parameters.AddWithValue("@id", UserId);

                MySqlDataReader rdr = cmd.ExecuteReader();

                rdr.Read();
                bool   deactivated = false;
                string email       = String.Empty;
                try {
                    deactivated = DBWorks.GetBoolean(rdr, "deactivated", false);
                    email       = DBWorks.GetString(rdr, "email", String.Empty);
                } catch {
                }

                entryID.Text    = rdr["id"].ToString();
                entryLogin.Text = rdr["login"].ToString();
                //Если SaaS - запретить редактировать логин.
                entryLogin.Sensitive       = !Session.IsSaasConnection;
                OriginLogin                = rdr["login"].ToString();
                entryName.Text             = rdr["name"].ToString();
                entryPassword.Text         = passFill;
                entryEmail.Text            = email;
                checkDeactivated.Active    = deactivated;
                checkDeactivated.Sensitive = QSMain.User.Login != OriginLogin;
                checkAdmin.Active          = rdr.GetBoolean(QSMain.AdminFieldName);

                if (deactivated && Session.IsSaasConnection)                  //FIXME Очень странное условие. Нужно разобраться. Что делает этот блок и зачем?
                {
                    entryName.Sensitive        = entryPassword.Sensitive = entryEmail.Sensitive = false;
                    checkDeactivated.Sensitive = checkAdmin.Sensitive = false;
                }

                foreach (KeyValuePair <string, CheckButton> Pair in RightCheckButtons)
                {
                    Pair.Value.Active = rdr.GetBoolean(QSMain.ProjectPermission[Pair.Key].DataBaseName);
                }

                if (permissionViews != null)
                {
                    foreach (var view in permissionViews)
                    {
                        view.DBFieldValue = DBWorks.GetString(rdr, view.DBFieldName);
                    }
                }

                textviewComments.Buffer.Text = rdr["description"].ToString();
                rdr.Close();

                this.Title = entryName.Text;
                logger.Info("Ok");
            } catch (Exception ex) {
                logger.Error(ex, "Ошибка получения информации о пользователе!");
                QSMain.ErrorMessage(this, ex);
            }
        }