Пример #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!Check())
            {
                return;
            }
            if (!addNew)
            {
                return;
            }
            string name     = nameTextBox.Text;
            string quantity = quantityTexbox.Text;
            string price    = priceTexbox.Text;
            GasDTO dto      = new GasDTO(name, float.Parse(quantity), float.Parse(price));
            bool   check    = dao.InsertGas(dto);

            if (check)
            {
                MessageBox.Show("Thêm  Hàng Thành Công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Thêm  Hàng Thất Bại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            addNew = false;
            Gas_Load(sender, e);
        }
Пример #2
0
        public bool InsertGas(GasDTO dto)
        {
            bool check = false;

            using (con = new SqlConnection(connectionString))
            {
                con.Open();
                command = new SqlCommand("insert into Gas(name,quantity,price) values (@name,@quantity,@price)", con);
                command.Parameters.AddWithValue("@name", dto.Name);
                command.Parameters.AddWithValue("@quantity", dto.Quantity);
                command.Parameters.AddWithValue("@price", dto.Price);
                check = command.ExecuteNonQuery() > 0;
            }
            CloseConnection();
            return(check);
        }
Пример #3
0
        public bool UpdateGas(GasDTO dto)
        {
            bool check = false;

            using (con = new SqlConnection(connectionString))
            {
                con.Open();
                command = new SqlCommand("update Gas set name=@name,quantity=@quantity,price=@price where id=@id", con);
                command.Parameters.AddWithValue("@name", dto.Name);
                command.Parameters.AddWithValue("@quantity", dto.Quantity);
                command.Parameters.AddWithValue("@price", dto.Price);
                command.Parameters.AddWithValue("@id", dto.Id);
                check = command.ExecuteNonQuery() > 0;
            }
            CloseConnection();
            return(check);
        }
Пример #4
0
        public List <GasDTO> LoadGas()
        {
            List <GasDTO> list = new List <GasDTO>();

            using (con = new SqlConnection(connectionString))
            {
                con.Open();
                command = new SqlCommand("select id,name,price from Gas", con);
                reader  = command.ExecuteReader();
                while (reader.Read())
                {
                    int    id    = reader.GetInt32(0);
                    string name  = reader.GetString(1);
                    double price = reader.GetDouble(2);
                    GasDTO dto   = new GasDTO(id, name, (float)price);
                    list.Add(dto);
                }
            }
            CloseConnection();
            return(list);
        }