Exemplo n.º 1
0
        public int addNewLabourer(MySqlConnection conn, Labourer labourer)
        {
            string sql = "INSERT INTO labourer (name, age, gender)"
                         + " VALUES ('" + labourer.Name + "', " + labourer.Age
                         + "   , '" + labourer.Gender + "')";

            MySqlCommand sqlComm = new MySqlCommand(sql, conn);

            return(sqlComm.ExecuteNonQuery());
        }
Exemplo n.º 2
0
        private void BtnRegister_Click(object sender, EventArgs e)
        {
            DbConnector dbConn = new DbConnector();

            dbConn.connect();

            Labourer labr = new Labourer();

            labr.Name   = tbName.Text;
            labr.Age    = int.Parse(ageLabel.Text);
            labr.Gender = cbGender.Text;

            LabourerHandler labHnd    = new LabourerHandler();
            int             recordCnt = labHnd.addNewLabourer(dbConn.getConn(), labr);

            MessageBox.Show(recordCnt + " record has been inserted !!");
        }
Exemplo n.º 3
0
        private void BtnTestAdd_Click(object sender, EventArgs e)
        {
            DbConnector dbConn = new DbConnector();

            dbConn.connect();

            Labourer labr = new Labourer();

            labr.Name   = "Adam";
            labr.Age    = 30;
            labr.Gender = "male";

            LabourerHandler labHnd    = new LabourerHandler();
            int             recordCnt = labHnd.addNewLabourer(dbConn.getConn(), labr);

            MessageBox.Show(recordCnt + " record has been inserted !!");
        }
Exemplo n.º 4
0
        public List <Labourer> getAllLabourer(MySqlConnection conn)
        {
            List <Labourer> listLabr = new List <Labourer>();
            string          sql      = "SELECT * FROM labourer";
            MySqlCommand    sqlComm  = new MySqlCommand(sql, conn);
            MySqlDataReader myReader;

            myReader = sqlComm.ExecuteReader();
            while (myReader.Read())
            {
                Labourer aLabr = new Labourer();
                aLabr.Id     = (int)myReader.GetValue(0);
                aLabr.Name   = (string)myReader.GetValue(1);
                aLabr.Age    = (int)myReader.GetValue(2);
                aLabr.Gender = (string)myReader.GetValue(3);
                listLabr.Add(aLabr);
            }
            return(listLabr);
        }