Exemple #1
0
        public int addNewPesticide(Pesticide pesticide)
        {
            MySqlCommand sqlComm = new MySqlCommand("INSERT INTO" + " pesticide(name, quantity_kg, remark)" +
                                                    " VALUES" + " (@name, @quantity_kg, @remark)", MysqlDbc.Instance.getConn());

            sqlComm.Parameters.Add("@name", MySqlDbType.Text).Value          = pesticide.Name;
            sqlComm.Parameters.Add("@quantity_kg", MySqlDbType.UInt32).Value = pesticide.Quantity_kg;
            sqlComm.Parameters.Add("@remark", MySqlDbType.Text).Value        = pesticide.Remark;

            return(sqlComm.ExecuteNonQuery());
        }
Exemple #2
0
        public int updatePesticide(Pesticide pesticide)
        {
            string query = "UPDATE" + " pesticide SET name=@name, quantity_kg=@quantity_kg, remark=@remark " +
                           "WHERE id = " + pesticide.Id;
            MySqlCommand sqlComm = new MySqlCommand(query, MysqlDbc.Instance.getConn());

            sqlComm.Parameters.Add("@name", MySqlDbType.Text).Value          = pesticide.Name;
            sqlComm.Parameters.Add("@quantity_kg", MySqlDbType.UInt32).Value = pesticide.Quantity_kg;
            sqlComm.Parameters.Add("@remark", MySqlDbType.Text).Value        = pesticide.Remark;

            return(sqlComm.ExecuteNonQuery());
        }
Exemple #3
0
        public List <Pesticide> GetPesticideList() //string employee_id
        {
            List <Pesticide> pesticideLists = new List <Pesticide>();
            MySqlDataReader  rdr            = null;

            try
            {
                string       stm = "SELECT * FROM pesticide";
                MySqlCommand cmd = new MySqlCommand(stm, MysqlDbc.Instance.getConn());
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Pesticide sj1 = new Pesticide();
                    sj1.Id          = rdr.GetInt32("id");;
                    sj1.Name        = rdr.GetString("name");
                    sj1.Quantity_kg = rdr.GetInt32("quantity_kg");
                    sj1.Remark      = rdr.GetString("remark");


                    pesticideLists.Add(sj1);
                }
            }
            catch (MySqlException ex)
            {
                Console.WriteLine("Error: {0}", ex.ToString());
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }
            }

            return(pesticideLists);
        }