예제 #1
0
        public HoaDonChiTietDatHang[] LietKeHoaDonChiTietVoiMSDH(string MSDH)
        {
            HoaDonChiTietDatHang[] arrHoaDonChiTietDatHang = new HoaDonChiTietDatHang[0];

            // Provide the query string with a parameter placeholder.
            string queryString =
                @"SELECT * 
                    From HDChiTietDatHang hdct
                    INNER JOIN ThucUong thucUong 
                                ON hdct.MSHH = thucUong.MSHH
                    Where MSDH=@MSDH";

            // Specify the parameter value.
            string msdh = MSDH;

            // Create and open the connection in a using block. This
            // ensures that all resources will be closed and disposed
            // when the code exits.
            using (SqlConnection connection =
                       new SqlConnection(connectionString))
            {
                // Create the Command and Parameter objects.
                SqlCommand command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("@MSDH", msdh);

                // Open the connection in a try/catch block.
                // Create and execute the DataReader, writing the result
                // set to the console window.
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    int           soLuongHoaDonChiTietDatHang = this.LietKeSoLuongHoaDonChiTietDatHangVoiMSDH(msdh);
                    arrHoaDonChiTietDatHang = new HoaDonChiTietDatHang[soLuongHoaDonChiTietDatHang];
                    int i = 0;
                    while (reader.Read())
                    {
                        // Parse data to model HoaDonChiTietDatHang
                        HoaDonChiTietDatHang mHoaDonChiTietDatHang = new HoaDonChiTietDatHang();
                        mHoaDonChiTietDatHang.MSDH     = reader[0].ToString();
                        mHoaDonChiTietDatHang.MSHH     = reader[1].ToString();
                        mHoaDonChiTietDatHang.SoLuong  = int.Parse(reader[2].ToString());
                        mHoaDonChiTietDatHang.TiLeGiam = int.Parse(reader[3].ToString());
                        arrHoaDonChiTietDatHang[i]     = mHoaDonChiTietDatHang;
                        i++;
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    // Console.WriteLine(ex.Message);
                }
                // Console.ReadLine();
            }

            return(arrHoaDonChiTietDatHang);
        }
예제 #2
0
        public HoaDonChiTietDatHang[] LietKeHoaDonChiTiet()
        {
            HoaDonChiTietDatHang[] arrHoaDonChiTietDatHang = new HoaDonChiTietDatHang[0];

            // Provide the query string with a parameter placeholder.
            string queryString =
                "SELECT * From HDChiTietDatHang";

            // Create and open the connection in a using block. This
            // ensures that all resources will be closed and disposed
            // when the code exits.
            using (SqlConnection connection =
                       new SqlConnection(connectionString))
            {
                // Create the Command and Parameter objects.
                SqlCommand command = new SqlCommand(queryString, connection);

                // Open the connection in a try/catch block.
                // Create and execute the DataReader, writing the result
                // set to the console window.
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    int           soLuongHoaDonChiTietDatHang = this.LietKeSoLuongHoaDonChiTietDatHang();
                    arrHoaDonChiTietDatHang = new HoaDonChiTietDatHang[soLuongHoaDonChiTietDatHang];
                    int i = 0;
                    while (reader.Read())
                    {
                        // Console.WriteLine("\t{0}\t\t\t{1}\t\t{2}\t\t{3}",
                        //     reader[0], reader[1], reader[2], reader[3]);
                        // Parse data to model HoaDonChiTietDatHang
                        HoaDonChiTietDatHang mHoaDonChiTietDatHang = new HoaDonChiTietDatHang();
                        mHoaDonChiTietDatHang.MSDH     = reader[0].ToString();
                        mHoaDonChiTietDatHang.MSHH     = reader[1].ToString();
                        mHoaDonChiTietDatHang.SoLuong  = int.Parse(reader[2].ToString());
                        mHoaDonChiTietDatHang.TiLeGiam = int.Parse(reader[3].ToString());
                        arrHoaDonChiTietDatHang[i]     = mHoaDonChiTietDatHang;
                        i++;
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    // Console.WriteLine(ex.Message);
                }
                // Console.ReadLine();
            }

            return(arrHoaDonChiTietDatHang);
        }