예제 #1
0
        private async void btnSavePermissions_Click(object sender, EventArgs e)
        {
            if (dgvUsers.SelectedRows.Count == 1 && dgvUsers.SelectedRows[0] != null)
            {
                CommonUser selectedItem = (CommonUser)dgvUsers.SelectedRows[0].DataBoundItem;
                Dictionary <string, bool> newPermissions = new Dictionary <string, bool>();
                foreach (TreeNode node in allNodes)
                {
                    if (node.Tag == null)
                    {
                        continue;
                    }
                    newPermissions.Add(node.Tag.ToString(), node.Checked);
                }

                var  output  = Newtonsoft.Json.JsonConvert.SerializeObject(newPermissions);
                bool success = await SAUsers.PostUpdateUserPermissions(selectedItem.UserId, output);

                if (success)
                {
                    labelError.Text      = "success_error_settings";
                    labelError.ForeColor = Color.Green;
                    labelError.Visible   = true;
                    LoadData();
                }
                else
                {
                    labelError.Text      = "fail_error_settings";
                    labelError.ForeColor = Color.Red;
                    labelError.Visible   = true;
                }
            }
        }
예제 #2
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (cbPasswordChange.Checked)
            {
                if (!string.IsNullOrWhiteSpace(tbPassword.Text) && !string.IsNullOrWhiteSpace(tbPassword2.Text) && tbPassword.Text != tbPassword2.Text)
                {
                    labelError.Text    = "password_mismatch";
                    labelError.Visible = true;
                }
                else if (!string.IsNullOrEmpty(tbPassword.Text) && !string.IsNullOrEmpty(tbPassword2.Text) && tbPassword.Text == tbPassword2.Text)
                {
                    CommonUser newUser = new CommonUser();
                    newUser.Password   = tbPassword.Text;
                    newUser.AssignedTo = tbAssignedTo.Text;
                    newUser.OwnerId    = DataHolder.Owner.OwnerId;
                    Enums.UserRoles role;
                    Enum.TryParse(cbUserRole.SelectedValue.ToString(), out role);
                    newUser.Role   = (int)role;
                    newUser.UserId = OldUser.UserId;
                    var success = await SAUsers.PostEditUser(newUser);

                    if (success)
                    {
                        DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        labelError.Text    = "invalid_user";
                        labelError.Visible = true;
                    }
                }
                else
                {
                    labelError.Text    = "empty_username_or_password";
                    labelError.Visible = true;
                }
            }
            else
            {
                CommonUser newUser = new CommonUser();
                newUser.AssignedTo = tbAssignedTo.Text;
                newUser.OwnerId    = DataHolder.Owner.OwnerId;
                Enums.UserRoles role;
                Enum.TryParse(cbUserRole.SelectedValue.ToString(), out role);
                newUser.Role   = (int)role;
                newUser.UserId = OldUser.UserId;
                var success = await SAUsers.PostEditUser(newUser);

                if (success)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    labelError.Text    = "invalid_user";
                    labelError.Visible = true;
                }
            }
        }
예제 #3
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(tbPassword.Text) && !string.IsNullOrEmpty(tbPassword2.Text) && tbPassword.Text != tbPassword2.Text)
            {
                labelError.Text    = "password_mismatch";
                labelError.Visible = true;
            }
            else if (!string.IsNullOrEmpty(tbPassword.Text) && !string.IsNullOrEmpty(tbPassword2.Text) && tbPassword.Text == tbPassword2.Text)
            {
                CommonUser newUser = new CommonUser();
                newUser.Username   = tbUsername.Text;
                newUser.Password   = tbPassword.Text;
                newUser.AssignedTo = tbAssignedTo.Text;
                newUser.OwnerId    = DataHolder.Owner.OwnerId;
                Enums.UserRoles role;
                Enum.TryParse(cbUserRole.SelectedValue.ToString(), out role);
                newUser.Role = (int)role;
                // switch between new user and existing user
                var success = await SAUsers.PostCreateUser(newUser);

                if (success)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    labelError.Text    = "user_already_exist";
                    labelError.Visible = true;
                }
            }
            else
            {
                labelError.Text    = "empty_username_or_password";
                labelError.Visible = true;
            }
        }
예제 #4
0
        private async void btnDeleteUser_Click(object sender, EventArgs e)
        {
            if (dgvUsers.SelectedRows.Count == 1 && dgvUsers.SelectedRows[0] != null)
            {
                CommonUser selectedItem = (CommonUser)dgvUsers.SelectedRows[0].DataBoundItem;
                if (selectedItem.UserId != DataHolder.CurrnetUserId)
                {
                    bool success = await SAUsers.PostDeleteUser(selectedItem.UserId);

                    if (success)
                    {
                        LoadData();
                    }
                    else
                    {
                        MessageBox.Show(DataHolder.GetString("error_deleting_user"), DataHolder.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show(DataHolder.GetString("error_deleting_user"), DataHolder.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #5
0
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            if (Trigger)
            {
                Trigger = false;
                DataHolder.Init();
                switch (cbLanguage.SelectedValue.ToString())
                {
                case "Български":
                    DataHolder.UserCulture = new CultureInfo("bg-BG");
                    break;

                case "English":
                    DataHolder.UserCulture = new CultureInfo("en-US");
                    break;

                default:
                    DataHolder.UserCulture = new CultureInfo("en-US");
                    break;
                }

                if (!string.IsNullOrEmpty(tbUsername.Text) && !string.IsNullOrEmpty(tbPassword.Text))
                {
                    DataHolder.ServerAddress = cbServer.Text;
                    CommonUser user = await SAUsers.Login(tbUsername.Text, tbPassword.Text);

                    if (user != null)
                    {
                        DataHolder.CurrnetUserId   = user.UserId;
                        DataHolder.OwnerId         = user.OwnerId;
                        DataHolder.Username        = user.Username;
                        DataHolder.UserType        = user.Role;
                        DataHolder.UserPermissions = user.Permissions;
                        DataHolder.Settings        = await SASettings.getUserSettings();

                        List <CommonMol> allMols = await SAOwner.getAllMols(user.OwnerId);

                        foreach (var mol in allMols)
                        {
                            if (mol.IsPrimery)
                            {
                                DataHolder.PrimeryMol = mol;
                                break;
                            }
                        }

                        MainForm form = new MainForm();
                        Hide();

                        if (form.ShowDialog() == DialogResult.Cancel)
                        {
                            Trigger            = true;
                            labelError.Visible = false;
                            Show();
                            tbPassword.Text = string.Empty;
                            tbUsername.Text = DataHolder.Username;

                            //clear previus data
                            DataHolder.CurrnetUserId   = Guid.Empty;
                            DataHolder.OwnerId         = Guid.Empty;
                            DataHolder.ServerAddress   = string.Empty;
                            DataHolder.Username        = string.Empty;
                            DataHolder.UserType        = 99;
                            DataHolder.UserCulture     = new CultureInfo("en-US");
                            DataHolder.PrimeryMol      = null;
                            DataHolder.UserPermissions = "";
                            DataHolder.Settings        = new CommonSettings();
                        }
                    }
                    else
                    {
                        labelError.Visible = true;
                        labelError.Text    = DataHolder.GetString("invalid_username_or_password");
                        Trigger            = true;
                    }
                }
                else
                {
                    labelError.Visible = true;
                    labelError.Text    = DataHolder.GetString("invalid_username_or_password");
                    Trigger            = true;
                }
            }
        }
예제 #6
0
        public async void LoadData()
        {
            AllUsers = await SAUsers.GetAllUsers(DataHolder.Owner.OwnerId);

            dgvUsers.DataSource = string.IsNullOrWhiteSpace(tbSearchUser.Text) ? AllUsers : AllUsers.Where(p => p.Username.Contains(tbSearchUser.Text)).ToList();
        }