Exemple #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (flag == true)
            {
                if (String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtLastName1.Text) || String.IsNullOrEmpty(txtLastName2.Text) ||
                    String.IsNullOrEmpty(txtEmail.Text) || String.IsNullOrEmpty(txtDNI.Text) || String.IsNullOrEmpty(txtSalary.Text) || String.IsNullOrEmpty(txtPassword.Text) ||
                    cboPrivilege.SelectedIndex == -1 || (rbWoman.Checked == false && rbMan.Checked == false))
                {
                    frmMessageBoxFillNull frm = new frmMessageBoxFillNull();
                    frm.ShowDialog();
                }
                else
                {
                    AlmacenDisecWS.employee emp = new AlmacenDisecWS.employee();

                    frmMessageBoxSave frm = new frmMessageBoxSave();
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        string name   = txtName.Text;
                        string apP    = txtLastName1.Text;
                        string apM    = txtLastName2.Text;
                        string DNI    = txtDNI.Text;
                        string email  = txtEmail.Text;
                        string pass   = txtPassword.Text;
                        Double sueldo = Double.Parse(txtSalary.Text);

                        emp.employee_name    = name;
                        emp.last_name        = apP;
                        emp.second_last_name = apM;
                        emp.dni            = DNI;
                        emp.email_employee = email;
                        emp.salary         = sueldo;
                        emp.password       = pass;
                        int a = 0;

                        if (cboPrivilege.SelectedValue.ToString() == "MANAGER")
                        {
                            a = 1;
                        }
                        else if (cboPrivilege.SelectedValue.ToString() == "STOREKEEPER")
                        {
                            a = 2;
                        }
                        else
                        {
                            a = 3;
                        }

                        if (rbMan.Checked == true)
                        {
                            emp.gender = "M";
                        }
                        else
                        {
                            emp.gender = "F";
                        }
                        int result = serviceDA.insertEmployee(emp, a);
                    }
                    frmSearchUser fm = Owner as frmSearchUser;
                    fm.dgvSearch.AutoGenerateColumns = false;
                    fm.dgvSearch.DataSource          = serviceDA.queryAllEmployee();

                    this.Close();
                }
            }
            else
            {
                if (String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtLastName1.Text) || String.IsNullOrEmpty(txtLastName2.Text) ||
                    String.IsNullOrEmpty(txtEmail.Text) || String.IsNullOrEmpty(txtDNI.Text) || String.IsNullOrEmpty(txtSalary.Text) ||
                    (rbWoman.Checked == false && rbMan.Checked == false))
                {
                    frmMessageBoxFillNull frm = new frmMessageBoxFillNull();
                    frm.ShowDialog();
                }
                else
                {
                    AlmacenDisecWS.employee emp = new AlmacenDisecWS.employee();

                    frmMessageBoxSave frm = new frmMessageBoxSave();
                    if (frm.ShowDialog() == DialogResult.OK)
                    {
                        string name  = txtName.Text;
                        string apP   = txtLastName1.Text;
                        string apM   = txtLastName2.Text;
                        string DNI   = txtDNI.Text;
                        string email = txtEmail.Text;

                        Double sueldo = Double.Parse(txtSalary.Text);
                        emp.employee_id      = Int32.Parse(lblId.Text);
                        emp.employee_name    = name;
                        emp.last_name        = apP;
                        emp.second_last_name = apM;
                        emp.dni            = DNI;
                        emp.salary         = sueldo;
                        emp.email_employee = email;
                        if (rbMan.Checked == true)
                        {
                            emp.gender = "M";
                        }
                        else
                        {
                            emp.gender = "F";
                        }
                        int result = serviceDA.updateEmployee(emp);
                    }
                }
                frmSearchUser fm = Owner as frmSearchUser;
                fm.dgvSearch.AutoGenerateColumns = false;
                fm.dgvSearch.DataSource          = serviceDA.queryAllEmployee();

                this.Close();
            }
        }