예제 #1
0
        public void getPriceFromDB(price_DTO price)                                                 // Lấy thông tin giá từ DB
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString.connectionString)) // khởi tạo kết nối đến database
            {
                connection.Open();                                                                  // Mở kết nối đến database

                string Select_all = "SELECT * from PhiGuiXe";

                SqlCommand    sqlcmd      = new SqlCommand(Select_all, connection); // Truy xuất dữ liệu từ database
                SqlDataReader Data_reader = sqlcmd.ExecuteReader();                 // biến để đọc dữ liệu truy xuất và lưu vào list

                while (Data_reader.Read())
                {
                    price.ID         = (int)Data_reader["ID"];
                    price.PRICEDAY   = (Decimal)Data_reader["PhiNgay"];
                    price.PRICENIGHT = (Decimal)Data_reader["PhiQuaDem"];
                }
                connection.Close(); // Đóng kết nối đến database
            }
        }
예제 #2
0
        public bool Update_PRICE(price_DTO price)
        {
            string Update_set = "UPDATE PhiGuiXe SET PhiNgay= @phingay,PhiQuaDem = @phiquadem  WHERE ID=@ID";

            using (SqlConnection connection = new SqlConnection(ConnectionString.connectionString))
            {
                try
                {
                    connection.Open();
                    SqlCommand cmdInsert = new SqlCommand(Update_set, connection);
                    cmdInsert.Parameters.Add("@ID", SqlDbType.Int).Value            = price.ID;
                    cmdInsert.Parameters.Add("@phingay", SqlDbType.Decimal).Value   = price.PRICEDAY;
                    cmdInsert.Parameters.Add("@phiquadem", SqlDbType.Decimal).Value = price.PRICENIGHT;
                    cmdInsert.ExecuteNonQuery();
                    connection.Close();
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.ToString());
                    return(false);
                }
            }
            return(true);
        }
 public bool Update_Price(price_DTO priceDTO)
 {
     return(price.Update_PRICE(priceDTO));
 }
 public void displayPrice(price_DTO priceDTO)
 {
     price.getPriceFromDB(priceDTO);
 }
 void getPriceFromDB(price_DTO priceDTO)
 {
     priceBUS.displayPrice(priceDTO);
     priceDay_TxtB.Text   = priceDTO.PRICEDAY.ToString();
     priceNight_TxtB.Text = priceDTO.PRICENIGHT.ToString();
 }