Пример #1
0
 //подгружаем данные
 private async void LoadData()
 {
     var queryCredential=await (from c in context.Credentials
                         where c.CredentialName==prevCredential
                         select c).FirstOrDefaultAsync();
     currentCredential = queryCredential;
     //подгружаем данные 
     textBoxUsername.Text = queryCredential.Username;
     textBoxDomain.Text = queryCredential.Domain;
     textBoxPaassword.Text = queryCredential.Password;
     textBoxEnablePassword.Text = queryCredential.EnablePassword;
 }
Пример #2
0
 //подтверждение операции
 private void buttonOK_Click(object sender, EventArgs e)
 {
     if (CheckData())
     {
         switch (mode)
         {
             case WindowsMode.ADD:
                 currentCredential = new Credential();
                 currentCredential.CredentialName = textBoxCredName.Text.Trim();
                 currentCredential.Username = textBoxUsername.Text.Trim();
                 currentCredential.Domain = textBoxDomain.Text.Trim();
                 currentCredential.Password = textBoxPaassword.Text.Trim();
                 currentCredential.EnablePassword = textBoxEnablePassword.Text.Trim();
                 context.Credentials.Add(currentCredential);
                 context.SaveChanges();
                 break;
             case WindowsMode.EDIT:
                 currentCredential.CredentialName = textBoxCredName.Text.Trim();
                 currentCredential.Username = textBoxUsername.Text.Trim();
                 currentCredential.Domain = textBoxDomain.Text.Trim();
                 currentCredential.Password = textBoxPaassword.Text.Trim();
                 currentCredential.EnablePassword = textBoxEnablePassword.Text.Trim();
                 context.Entry(currentCredential).State = System.Data.Entity.EntityState.Modified;
                 context.SaveChanges();
                 break;
         }
         this.DialogResult = DialogResult.OK;
     }
     else
     {
         switch (validateInput)
         {
             case CredentialInputValidate.CredentialNameEmpty: NotifyWarning("Credential name is empty!");  break;
             case CredentialInputValidate.CredentialNotUnique: NotifyWarning("Credential name is already exist!"); break;
             case CredentialInputValidate.UsernameEmpty: NotifyWarning("Username is empty!"); break;
             case CredentialInputValidate.PasswordEmpty: NotifyWarning("Password is empty!"); break;
         }
     }
 }