コード例 #1
0
        public static bool addEmployee(Employee em)
        {
            //try
            //{

                DBConnector dbcon = new DBConnector();

                if (dbcon.openConnection())
                {

                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = "INSERT INTO employee (employee_no, full_name, image_url, old_employee_no, employee_type, epf_no, salutation, occupation, initials, first_name, last_name, nic_no, date_issued, nationality, religion, date_of_birth, place_of_birth, married, date_of_marriage, action_status, blood_group) VALUES (N'" + em.getEmployee_no() + "', N'" + em.getFull_name() + "', N'" + em.getImg_url() + "', N'" + em.getOld_employee_no() + "', N'" + em.getEmployee_type() + "', N'" + em.getEpf_no() + "', N'" + em.getSalutation() + "', N'" + em.getOccupation() + "', N'" + em.getInitials() + "', N'" + em.getFirst_name() + "', N'" + em.getLast_name() + "', N'" + em.getNic_no() + "', '" + em.getDate_issued() + "', N'" + em.getNationality() + "', N'" + em.getReligion() + "', '" + em.getDate_of_birth().ToString("yyyy-MM-dd") + "', N'" + em.getPlace_of_birth() + "', " + em.getMarried() + ", '" + em.getDate_of_marriage().ToString("yyyy-MM-dd") + "', N'" + em.getAction_status() + "', N'" + em.getBlood_group() + "')";
                    cmd.Connection = dbcon.connection;
                    cmd.Prepare();
                    cmd.ExecuteNonQuery();

                    cmd.CommandText = "SELECT * FROM employee ORDER BY idemployee DESC LIMIT 1";
                    cmd.Connection = dbcon.connection;

                    MySqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        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  "+Employee.emp_no+"\n  "+Employee.employee_name+"\n  ");
                    }

                    reader.Close();

                    dbcon.closeConnection();

                    return true;
                }
                else
                {

                    return false;
                }

            //}
            //catch (MySqlException e)
            //{
                //int errorcode = e.Number;
                //return false;
            //}
        }
コード例 #2
0
        public static bool updateEmployee(Employee em)
        {
            //try
            //{

            DBConnector dbcon = new DBConnector();

            if (dbcon.openConnection())
            {

                MySqlCommand cmd = new MySqlCommand();
                cmd.CommandText = "UPDATE employee SET employee_no=N'" + em.getEmployee_no() + "', old_employee_no=N'" + em.getOld_employee_no() + "', employee_type=N'" + em.getEmployee_type() + "', epf_no=N'" + em.getEpf_no() + "', salutation=N'" + em.getSalutation() + "', occupation=N'" + em.getOccupation() + "', initials=N'" + em.getInitials() + "', first_name=N'" + em.getFirst_name() + "', last_name=N'" + em.getLast_name() + "', nic_no=N'" + em.getNic_no() + "', date_issued='" + em.getDate_issued() + "', nationality=N'" + em.getNationality() + "', religion=N'" + em.getReligion() + "', date_of_birth='" + em.getDate_of_birth().ToString("yyyy-MM-dd") + "', place_of_birth=N'" + em.getPlace_of_birth() + "', married=" + em.getMarried() + ", date_of_marriage='" + em.getDate_of_marriage().ToString("yyyy-MM-dd") + "', action_status=N'" + em.getAction_status() + "', blood_group=N'" + em.getBlood_group() + "' WHERE idemployee=" + Employee.employee_id;
                cmd.Connection = dbcon.connection;
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                dbcon.closeConnection();

                return true;
            }
            else
            {

                return false;
            }

            //}
            //catch (MySqlException e)
            //{
            //int errorcode = e.Number;
            //return false;
            //}
        }