Exemplo n.º 1
0
 private void btnAccepta_Click(object sender, EventArgs e)
 {
     using (var ctx = new LicitatiiDAL.LicitatiiContext())
     {
         var cumparator = ctx.Utilizatori.OfType <LicitatiiDAL.Cumparator>()
                          .Where(v => v.Username.Equals(tbUser.Text))
                          .Where(v => v.Password.Equals(tbPass.Text))
                          .FirstOrDefault();
         if (cumparator != null)
         {
             Program.Cumparator = cumparator;
             errorProvider1.SetError(btnAccepta, string.Empty);
         }
         else
         {
             Program.Cumparator = null;
             DialogResult       = System.Windows.Forms.DialogResult.None;
             errorProvider1.SetIconAlignment(btnAccepta, ErrorIconAlignment.MiddleLeft);
             errorProvider1.SetError(btnAccepta, "Utilizator sau parola gresite!");
         }
     }
 }
Exemplo n.º 2
0
        private void btnAccepta_Click(object sender, EventArgs e)
        {
            bool valid = true;

            if (string.IsNullOrWhiteSpace(numeTextBox.Text))
            {
                errorProvider1.SetError(numeTextBox, "Invalid");
                valid = false;
            }
            else
            {
                errorProvider1.SetError(numeTextBox, null);
            }
            if (string.IsNullOrWhiteSpace(prenumeTextBox.Text))
            {
                errorProvider1.SetError(prenumeTextBox, "Invalid");
                valid = false;
            }
            else
            {
                errorProvider1.SetError(prenumeTextBox, null);
            }
            if (string.IsNullOrWhiteSpace(cNPTextBox.Text))
            {
                errorProvider1.SetError(cNPTextBox, "Invalid");
                valid = false;
            }
            else
            {
                errorProvider1.SetError(cNPTextBox, null);
            }
            if (string.IsNullOrWhiteSpace(telefonTextBox.Text))
            {
                errorProvider1.SetError(telefonTextBox, "Invalid");
                valid = false;
            }
            else
            {
                errorProvider1.SetError(telefonTextBox, null);
            }
            if (string.IsNullOrWhiteSpace(usernameTextBox.Text))
            {
                errorProvider1.SetError(usernameTextBox, "Invalid");
                valid = false;
            }
            else
            {
                errorProvider1.SetError(usernameTextBox, null);
            }
            if (string.IsNullOrWhiteSpace(passwordTextBox.Text))
            {
                errorProvider1.SetError(passwordTextBox, "Invalid");
                valid = false;
            }
            else
            {
                errorProvider1.SetError(passwordTextBox, null);
            }

            if (valid)
            {
                using (var ctx = new LicitatiiDAL.LicitatiiContext())
                {
                    ctx.Utilizatori.Add(this.Cumparator);
                    ctx.SaveChanges();
                }
            }
            else
            {
                DialogResult = System.Windows.Forms.DialogResult.None;
            }
        }