示例#1
0
 private void cmdAddNew_Click(object sender, EventArgs e)
 {
     using (var dlg = new dlgUser())
     {
         dlg.IsNewMode         = true;
         dlg.cbRola.DataSource = Enum.GetNames(typeof(User.UserRole));
         dlg.txtLogin.Select();
         dlg.NewRecordAdded += NewRecord;
         dlg.ShowDialog();
         dlg.NewRecordAdded -= NewRecord;
     }
 }
示例#2
0
        void FillDialog(dlgUser dlg, User U)
        {
            dlg.IsNewMode               = false;
            dlg.Text                    = "Edycja danych użytkownika";
            dlg.txtPassword.Enabled     = false;
            dlg.txtPassword2.Enabled    = false;
            dlg.cmdPwdGen.Enabled       = false;
            dlg.chkShowPassword.Enabled = false;
            dlg.txtLogin.Enabled        = false;

            dlg.cbRola.DataSource = Enum.GetNames(typeof(User.UserRole));
            dlg.txtLogin.Text     = U.Login;
            dlg.cbRola.Text       = U.Role.ToString();
            dlg.chkStatus.Checked = (int)U.Status > 0;
            dlg.txtNazwisko.Text  = U.LastName;
            dlg.txtImie.Text      = U.FirstName;
            dlg.chkSex.Checked    = (int)U.Sex > 0;
            dlg.txtEmail.Text     = U.Email;
            dlg.pbFaximile.Image  = U.Faximile;

            dlg.txtLogin.Select();
        }
示例#3
0
        private async Task <int> UpdateUserAsync(dlgUser dlg, string login)
        {
            User.UserRole R = User.UserRole.Rodzic; // = (User.UserRole)Enum.Parse(typeof(User.UserRole), dlg.cbRola.SelectedValue.ToString());
            Enum.TryParse(dlg.cbRola.SelectedValue.ToString(), out R);
            var sqlParamWithValue = new Dictionary <string, object>()
            {
                { "@Login", login },
                { "@Nazwisko", dlg.txtNazwisko.Text.Trim() },
                { "@Imie", dlg.txtImie.Text.Trim() },
                { "@Rola", R },
                { "@Email", dlg.txtEmail.Text.Trim() },
                { "@Status", dlg.chkStatus.Checked },
                { "@Sex", dlg.chkSex.Checked },
                { "@User", UserSession.User.Login },
                { "@IP", AppSession.HostIP }
            };

            using (var scope = AppSession.TypeContainer.BeginLifetimeScope())
            {
                var dbs = scope.Resolve <IDataBaseService>();
                return(await dbs.UpdateRecordAsync(UserSQL.UpdateUser(), sqlParamWithValue));
            }
        }
示例#4
0
 private void EditUser()
 {
     try
     {
         var U = olvUser.SelectedObject as User;
         using (var dlg = new dlgUser())
         {
             FillDialog(dlg, U);
             if (dlg.ShowDialog() == DialogResult.OK)
             {
                 if (UpdateUserAsync(dlg, U.Login).Result > 0)
                 {
                     NewRecord(U.Login);
                     return;
                 }
                 throw new Exception("Aktualizacja danych nie powiodła się!");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }