private void BtnAddUser_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(TxtFirstName.Text) && !string.IsNullOrEmpty(TxtLastName.Text) && !string.IsNullOrEmpty(TxtPassword.Text) && (dateEnrollmentDate.Checked || dateHireDate.Checked) && comboBoxDisc.Text != null)
            {
                using (var db = new SchoolEntities())
                {
                    DateTime?dt         = null;
                    var      hireDate   = (dateHireDate.Enabled == true) ? dateHireDate.Value : dt;
                    var      enrollDate = (dateEnrollmentDate.Enabled == true) ? dateEnrollmentDate.Value : dt;

                    var person = new Person()
                    {
                        LastName = TxtLastName.Text, FirstName = TxtFirstName.Text, HireDate = hireDate, EnrollmentDate = enrollDate, Discriminator = comboBoxDisc.SelectedItem.ToString(), Password = TxtPassword.Text
                    };

                    db.Person.Add(person);
                    db.SaveChanges();

                    dataGridView1.DataSource = db.Person.ToList();
                    dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
                    dataGridView1.FirstDisplayedCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[0];
                }

                TxtFirstName.ResetText();
                TxtLastName.ResetText();
                TxtPassword.ResetText();
                dateHireDate.ResetText();
                dateEnrollmentDate.ResetText();
                comboBoxDisc.SelectedItem = null;
            }
            else
            {
                MessageBox.Show("You havent entered every needed information.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #2
0
 // Reset Text Boxes and radio buttons. Set Id and row index 0 and -1
 private void Reset()
 {
     TxtName.ResetText();
     TxtSurname.ResetText();
     TxtUsername.ResetText();
     TxtPassword.ResetText();
     TxtPhone.ResetText();
     RbtnIsBoss.Checked    = false;
     RbtnNotBoss.Checked   = false;
     BtnDeleteUser.Visible = false;
     BtnUpdateUser.Visible = false;
     clickedId             = 0;
     clickedRow            = -1;
 }
        private void button1_Click(object sender, EventArgs e)
        {
            objBll.UserName = txtUserName.Text;
            objBll.Password = TxtPassword.Text;
            objBll.Returndatatable(2);
            dt = objBll.Returndatatable(1);

            dt.AcceptChanges();
            //txtUserName.ResetText();
            //TxtPassword.ResetText();

            if (dt.Rows.Count > 0)
            {
                string Criteria = "UserName ='******'and Password='******'";
                dv = new DataView(dt, Criteria, "", DataViewRowState.OriginalRows);
            }
            //this.Close();
            if (dv.ToTable().Rows.Count > 0)
            {
                CRM ff = new CRM(this);
                ff.Show();
                txtUserName.Focus();
                this.Hide();

                PrchaseForm t = new PrchaseForm();
                t.Show();

                t.label1.Text = txtUserName.Text;
                TxtPassword.ResetText();
                txtUserName.ResetText();
            }

            else
            {
                MessageBox.Show("Invalid UserName and Password");
            }
        }
 private void ResetTextboxes()
 {
     TxtUsername.ResetText();
     TxtPassword.ResetText();
 }