Example #1
0
        public MainForm()
        {
            InitializeComponent();

            ProjectsDataSet.Update();
            projects = ProjectsDataSet.GetData();

            DepartamentsDataSet.Update();
            departaments = DepartamentsDataSet.GetData();

            EmployeesDataSet.Update();
            employees = EmployeesDataSet.GetData();

            projectsDataGridView.DataSource            = projects;
            projectsDataGridView.Columns[0].Visible    = false;
            projectsDataGridView.Columns[3].HeaderText = "departament";
            projectsDataGridView.Columns[4].HeaderText = "begin date";
            projectsDataGridView.Columns[5].HeaderText = "end date";
            projectsDataGridView.Columns[6].HeaderText = "real end date";

            projectDepartamnetComboBox.DataSource = departaments;

            departamentsDataGridView.DataSource         = departaments;
            departamentsDataGridView.Columns[0].Visible = false;

            employeesDataGridView.DataSource            = employees;
            employeesDataGridView.Columns[0].Visible    = false;
            employeesDataGridView.Columns[1].HeaderText = "first name";
            employeesDataGridView.Columns[2].HeaderText = "last name";
            employeesDataGridView.Columns[3].HeaderText = "father name";
        }
Example #2
0
        private void employeeUpdateButton_Click(object sender, EventArgs e)
        {
            if (employeeFirstNameTextBox.TextLength == 0)
            {
                MessageBox.Show("Enter first name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                employeeFirstNameTextBox.Focus();
                return;
            }
            if (employeeLastNameTextBox.TextLength == 0)
            {
                MessageBox.Show("Enter last name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                employeeLastNameTextBox.Focus();
                return;
            }
            if (employeeFatherNameTextBox.TextLength == 0)
            {
                MessageBox.Show("Enter father name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                employeeFatherNameTextBox.Focus();
                return;
            }
            if (employeePositionTextBox.TextLength == 0)
            {
                MessageBox.Show("Enter position", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                employeePositionTextBox.Focus();
                return;
            }
            using (var cn = Database.CreateConnection())
            {
                cn.Open();
                OracleCommand cmd = new OracleCommand("UPDATE employees SET first_name=:n, last_name=:ln, father_name=:fn, position=:p," +
                                                      "salary=:s WHERE id=:id", cn);
                cmd.Parameters.Add(new OracleParameter("n", employeeFirstNameTextBox.Text));
                cmd.Parameters.Add(new OracleParameter("ln", employeeLastNameTextBox.Text));
                cmd.Parameters.Add(new OracleParameter("fn", employeeFatherNameTextBox.Text));
                cmd.Parameters.Add(new OracleParameter("p", employeePositionTextBox.Text));
                cmd.Parameters.Add(new OracleParameter("s", employeeSalaryNumericUpDown.Value));
                cmd.Parameters.Add(new OracleParameter("id", employees[employeesDataGridView.CurrentCell.RowIndex].id));
                try
                {
                    cmd.ExecuteNonQuery();
                    EmployeesDataSet.Update();
                    employees = EmployeesDataSet.GetData();
                    employeesDataGridView.DataSource = employees;

                    employeeFirstNameTextBox.Text     = "";
                    employeeFatherNameTextBox.Text    = "";
                    employeeLastNameTextBox.Text      = "";
                    employeePositionTextBox.Text      = "";
                    employeeSalaryNumericUpDown.Value = 0;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #3
0
 private void employeeAddButton_Click(object sender, EventArgs e)
 {
     if (employeeFirstNameTextBox.TextLength == 0)
     {
         MessageBox.Show("Enter first name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         employeeFirstNameTextBox.Focus();
         return;
     }
     if (employeeLastNameTextBox.TextLength == 0)
     {
         MessageBox.Show("Enter last name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         employeeLastNameTextBox.Focus();
         return;
     }
     if (employeeFatherNameTextBox.TextLength == 0)
     {
         MessageBox.Show("Enter father name", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         employeeFatherNameTextBox.Focus();
         return;
     }
     if (employeePositionTextBox.TextLength == 0)
     {
         MessageBox.Show("Enter position", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         employeePositionTextBox.Focus();
         return;
     }
     using (var cn = Database.CreateConnection())
     {
         cn.Open();
         OracleCommand cmd = new OracleCommand("INSERT INTO employees (first_name, last_name, father_name, position, salary) " +
                                               "VALUES (:n, :ln, :fn, :p, :s)", cn);
         cmd.Parameters.Add(new OracleParameter("n", employeeFirstNameTextBox.Text));
         cmd.Parameters.Add(new OracleParameter("ln", employeeLastNameTextBox.Text));
         cmd.Parameters.Add(new OracleParameter("fn", employeeFatherNameTextBox.Text));
         cmd.Parameters.Add(new OracleParameter("p", employeePositionTextBox.Text));
         cmd.Parameters.Add(new OracleParameter("s", employeeSalaryNumericUpDown.Value));
         try
         {
             cmd.ExecuteNonQuery();
             EmployeesDataSet.Update();
             employees = EmployeesDataSet.GetData();
             employeesDataGridView.DataSource = employees;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Example #4
0
 private void employeeDeleteButton_Click(object sender, EventArgs e)
 {
     using (var cn = Database.CreateConnection())
     {
         cn.Open();
         OracleCommand cmd = new OracleCommand("DELETE FROM employees WHERE id=:id", cn);
         cmd.Parameters.Add(new OracleParameter("id", employees[employeesDataGridView.CurrentCell.RowIndex].id));
         try
         {
             cmd.ExecuteNonQuery();
             EmployeesDataSet.Update();
             employees = EmployeesDataSet.GetData();
             employeesDataGridView.DataSource = employees;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }