예제 #1
0
        public void updateEmployeePersonalDetails()
        {
            Employee employee = new Employee();

            employee.setAction_status(this.action_status.Text);
            employee.setBlood_grouph(this.blood_group.Text);
            employee.setDate_issued(this.date_issued.Text);
            employee.setEmployee_no(this.employee_no.Text);
            employee.setEmployee_type(this.employee_type.Text);
            employee.setEpf_no(this.epf_no.Text);
            employee.setFirst_name(this.first_name.Text);
            //employee.setFull_name(full_name.Text);
            //employee.setImg_url();
            employee.setInitials(this.initials.Text);
            employee.setLast_name(this.last_name.Text);
            employee.setDate_of_birth(this.dob_date.Value.Date);
            employee.setDate_of_marriage(this.marry_date.Value.Date);

            if (this.married.Checked) { employee.setMarried(1); }
            else { employee.setMarried(0); }

            employee.setNationality(this.nationality.Text);
            employee.setNic_no(this.nic_no.Text);
            employee.setOccupation(this.occupation.Text);
            employee.setOld_employee_no(this.old_employee_no.Text);
            employee.setPlace_of_birth(this.place_of_birth.Text);
            employee.setReligion(this.religion.Text);
            employee.setSalutation(this.salutation.Text);

            bool state = EmployeeHandler.updateEmployee(employee);

            Console.Write(state+"\n");
        }
        public static Employee getEmployee(string no)
        {
            //try
            //{

            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "SELECT * FROM employee WHERE employee_no=N'" + no + "'";
                cmd.Connection = dbcon.connection;

                MySqlDataReader reader = cmd.ExecuteReader();

                Employee e = null;

                if (reader.Read())
                {
                    e = new Employee();

                    Employee.employee_id = int.Parse(reader["idemployee"].ToString());
                    Employee.emp_no = reader["employee_no"].ToString();
                    Employee.employee_name = reader["full_name"].ToString();

                    Console.Write(Employee.employee_id+"\n");

                    e.setAction_status(reader["action_status"].ToString());
                    e.setBlood_grouph(reader["blood_group"].ToString());
                    e.setDate_issued(reader["date_issued"].ToString());

                    e.setDate_of_birth(Convert.ToDateTime(reader["date_of_birth"]));
                    e.setDate_of_marriage(Convert.ToDateTime(reader["date_of_marriage"]));

                    e.setEmployee_no(reader["employee_no"].ToString());
                    e.setEmployee_type(reader["employee_type"].ToString());
                    e.setEpf_no(reader["epf_no"].ToString());
                    e.setFirst_name(reader["first_name"].ToString());
                    e.setLast_name(reader["last_name"].ToString());
                    e.setFull_name(reader["full_name"].ToString());
                    e.setImg_url(reader["image_url"].ToString());
                    e.setInitials(reader["initials"].ToString());

                    if (reader["married"].ToString() == "True") { e.setMarried(1); }
                    else { e.setMarried(0); }

                    e.setNationality(reader["nationality"].ToString());
                    e.setNic_no(reader["nic_no"].ToString());
                    e.setOccupation(reader["occupation"].ToString());
                    e.setOld_employee_no(reader["old_employee_no"].ToString());
                    e.setPlace_of_birth(reader["place_of_birth"].ToString());
                    e.setReligion(reader["religion"].ToString());
                    e.setSalutation(reader["salutation"].ToString());

                }

                reader.Close();

                dbcon.closeConnection();

                return e;
            }
            else
            {

                return null;
            }

            //}
            //catch (MySqlException e)
            //{
            //int errorcode = e.Number;
            //return null;
            //}
        }
        public static Employee getEmployee()
        {
            Employee em = new Employee();

            //try
            //{

            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "SELECT * FROM employee WHERE idemployee="+Employee.employee_id;
                cmd.Connection = dbcon.connection;

                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    em.setAction_status(reader.GetString("action_status"));
                    em.setBlood_grouph(reader.GetString(""));
                    em.setDate_issued(reader.GetString(""));
                }

                reader.Close();

                dbcon.closeConnection();

                return em;
            }
            else
            {

                return null;
            }

            //}
            //catch (MySqlException e)
            //{
            //int errorcode = e.Number;
            //return false;
            //}
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            Employee employee = new Employee();

            employee.setAction_status(action_status.Text);
            employee.setBlood_grouph(blood_group.Text);
            employee.setDate_issued(date_issued.Text);
            employee.setEmployee_no(employee_no.Text);
            employee.setEmployee_type(employee_type.Text);
            employee.setEpf_no(epf_no.Text);
            employee.setFirst_name(first_name.Text);
            employee.setFull_name(full_name.Text);
            //employee.setImg_url();
            employee.setInitials(initials.Text);
            employee.setLast_name(last_name.Text);
            employee.setDate_of_birth(dob_date.Value.Date);
            employee.setDate_of_marriage(marry_date.Value.Date);

            if (married.Checked) { employee.setMarried(1); }
            else { employee.setMarried(0); }

            employee.setNationality(nationality.Text);
            employee.setNic_no(nic_no.Text);
            employee.setOccupation(occupation.Text);
            employee.setOld_employee_no(old_employee_no.Text);
            employee.setPlace_of_birth(place_of_birth.Text);
            employee.setReligion(religion.Text);
            employee.setSalutation(salutation.Text);

            //Add a new employee
            if (Employee.employee_id == 0)
            {
                bool state = EmployeeHandler.addEmployee(employee);

                if (state)
                {
                    MessageBox.Show("Employee personal details added succesfully...!");
                    //btnSave2.Enabled = true;
                    //btnSave3.Enabled = true;
                    //btnSave4.Enabled = true;
                    //btnSave5.Enabled = true;
                }
                else
                {
                    MessageBox.Show("Adding employee personal details failed...!");
                }

            }
            //Update existing employee
            else
            {
                bool state = EmployeeHandler.updateEmployee(employee);

                if (state)
                {
                    MessageBox.Show("Employee personal details updated succesfully...!");

                }
                else
                {
                    MessageBox.Show("Updating employee personal details failed...!");
                }
            }
        }