Ejemplo n.º 1
0
        private void NewEmployeeSaveButton_Click(object sender, EventArgs e)
        {
            ArrayList Employee           = new ArrayList();
            string    EmployeeName       = NewEmployeeNameTextBox.Text;
            string    EmployeeAddress    = NewEmployeeAddressTextBok.Text;
            string    EmployeeEmail      = NewEmployeeEmailTextBox.Text;
            string    EmployeeID         = NewEmployeeIDTextBox.Text;
            string    EmployeePassword   = NewEmployeePasswordTextBox.Text;
            string    EmployeeRePassword = NewEmployeeRePasswordTextBox.Text;
            string    EmployeeUsername   = NewEmployeeUsernameTextBox.Text;
            string    EmployeeGender     = "";

            Boolean flag  = false;
            Boolean flag1 = false;


            if (MaleEmployee.Checked)
            {
                EmployeeGender = "Male";
            }
            if (FemaleEmployee.Checked)
            {
                EmployeeGender = "Female";
            }

            Boolean empty = string.IsNullOrEmpty(EmployeeName) || string.IsNullOrEmpty(EmployeeAddress) || string.IsNullOrEmpty(EmployeeEmail) || string.IsNullOrEmpty(EmployeeID) || string.IsNullOrEmpty(EmployeePassword) || string.IsNullOrEmpty(EmployeeRePassword) || string.IsNullOrEmpty(EmployeeUsername) || string.IsNullOrEmpty(EmployeeGender);



            string query = "select UserID  from Employee where UserID= '" + EmployeeID + "';";

            Connection.Open();
            Command = new SqlCommand(query, Connection);
            SqlDataReader result = Command.ExecuteReader();

            while (result.Read())
            {
                string id = result["UserID"].ToString();
                flag = true;
            }
            Connection.Close();
            string query1 = "select UserUsername  from Employee where UserUsername= '******';";

            Connection.Open();
            Command1 = new SqlCommand(query1, Connection);
            SqlDataReader result1 = Command1.ExecuteReader();


            while (result1.Read())
            {
                string name = result1["UserUsername"].ToString();
                flag1 = true;
            }

            Connection.Close();

            if (empty)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(1))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Please fill all the fields");
            }
            else if (!EmployeePassword.Equals(EmployeeRePassword))
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(1))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Password not matched");
            }
            else if (flag)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(1))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "ID already exist");
            }
            else if (flag1)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(1))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Username not available");
            }
            else
            {
                Employee.Add(EmployeeID);
                Employee.Add(EmployeeName);
                Employee.Add(EmployeeEmail);
                Employee.Add(EmployeeUsername);
                Employee.Add(EmployeeRePassword);
                Employee.Add(EmployeeGender);
                Employee.Add(EmployeeAddress);
                database.InsertNewEmployee(Employee);
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(2))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Employee Added successfully");
            }

            EmployeeInformation eq = new EmployeeInformation();

            eq.LoadData();
        }