예제 #1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int employeeId = 0;

            panel3.Visible = false;
            //Select row from datagridview1
            if (dataGridView1.SelectedCells.Count > 0)
            {
                int             selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow      = dataGridView1.Rows[selectedrowindex];
                employeeId = Convert.ToInt32(selectedRow.Cells["employeeId"].Value);
            }
            //--Employee selected--

            //Get degrees that belong to employeeId
            DataGridView dGrid = eDegrees;

            dGrid.AllowUserToAddRows = false;
            dGrid.ReadOnly           = true;
            dGrid.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
            fillDegrees(employeeId, dGrid);
            //End of employee degrees

            //Get addresses that belong to employeeId
            DataGridView aGrid = eAddresses;

            aGrid.AllowUserToAddRows = false;
            aGrid.ReadOnly           = true;
            aGrid.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
            fillAddresses(employeeId, aGrid);
            //End of employee addresses

            //Get employee positions
            DataGridView pGrid = ePositions;

            pGrid.AllowUserToAddRows = false;
            pGrid.ReadOnly           = true;
            pGrid.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
            fillPositions(employeeId, pGrid);
            //End of employee positions

            //Get employee information
            DBConnection newC     = new DBConnection();
            var          employee = newC.Select("SELECT * FROM employees WHERE employeeId = '" + employeeId + "'");
            Employee     emp      = new Employee();

            foreach (List <string> entry in employee)
            {
                emp.employeeId = Convert.ToInt32(entry[0]);
                emp.hqName     = entry[1];
                emp.bsn        = Convert.ToInt32(entry[3]);
                emp.name       = entry[4];
                emp.surname    = entry[5];
            }
            selectedEmployee.Text = emp.name + " " + emp.surname;
            edBSN.Text            = Convert.ToString(emp.bsn);
            edName.Text           = emp.name;
            edSurname.Text        = emp.surname;
            selectedEmployee_     = emp;
            //Reset address/Degree
            selectedDegree  = new Degree();
            selectedAddress = new Address();
            //End of employee information
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Save new employee
            DBConnection  newC       = new DBConnection();
            int           bsn        = Int32.Parse(BSN.Text);
            string        name       = eName.Text;
            string        surname    = Surname.Text;
            string        country    = Country.Text;
            string        postalcode = Postalcode.Text;
            string        city       = City.Text;
            string        street     = Street.Text;
            string        number     = Number.Text;
            string        hqName     = Convert.ToString(comboBox1.SelectedValue);
            int           position   = Convert.ToInt32(comboBox2.SelectedValue);
            List <Degree> degrees    = new List <Degree>();

            if (Course1.Text.Length > 0 && School1.Text.Length > 0 && Level1.Text.Length > 0)
            {
                Degree d1 = new Degree();
                d1.course = Course1.Text;
                d1.school = School1.Text;
                d1.level  = Level1.Text;
                degrees.Add(d1);
            }
            if (Course2.Text.Length > 0 && School2.Text.Length > 0 && Level2.Text.Length > 0)
            {
                Degree d2 = new Degree();
                d2.course = Course2.Text;
                d2.school = School2.Text;
                d2.level  = Level2.Text;
                degrees.Add(d2);
            }
            if (Course3.Text.Length > 0 && School3.Text.Length > 0 && Level3.Text.Length > 0)
            {
                Degree d3 = new Degree();
                d3.course = Course3.Text;
                d3.school = School3.Text;
                d3.level  = Level3.Text;
                degrees.Add(d3);
            }
            newC.Execute("INSERT INTO addresses (country, postalcode, city, street, num)" +
                         "VALUES ('" + country + "','" + postalcode + "','" + city + "','" + street + "','" + number + "')");
            int pk = newC.ExecutePK("INSERT INTO employees (hqName, bsn, name, surname)" +
                                    "VALUES('" + hqName + "', '" + bsn + "', '" + name + "', '" + surname + "'); select last_insert_id()");
            int adrId = newC.ExecutePK("INSERT INTO eAddresses (employeeId, country, postalcode)" +
                                       "VALUES('" + pk + "', '" + country + "', '" + postalcode + "'); select last_insert_id()");

            newC.Execute("UPDATE employees SET employeeAid = '" + adrId + "' WHERE employeeId = '" + pk + "'");
            newC.Execute("INSERT INTO ePositions (posId, employeeId)" +
                         "VALUES('" + position + "', '" + pk + "')");
            foreach (Degree d in degrees)
            {
                newC.Execute("INSERT INTO degrees (employeeId, course, school, level)" +
                             "VALUES ('" + pk + "', '" + d.course + "', '" + d.school + "', '" + d.level + "')");
            }
            reloadEmployees();

            // Empty used form
            BSN.Text       = ""; eName.Text = ""; Surname.Text = ""; Country.Text = ""; Postalcode.Text = ""; City.Text = ""; Street.Text = "";
            Number.Text    = ""; Course1.Text = ""; Course2.Text = ""; Course3.Text = ""; School1.Text = ""; School2.Text = ""; School3.Text = "";
            Level1.Text    = ""; Level2.Text = ""; Level3.Text = "";
            panel1.Visible = true; panel2.Visible = true;
            // End empty used form

            // End save employee
        }