private void refreshListView(HoaDonChiTietDatHang[] arrHoaDonChiTietDatHang)
        {
            this.lstViewDSThucUong.Clear();

            ListViewItem[] lstViewItem = new ListViewItem[arrHoaDonChiTietDatHang.Length];
            for (int i = 0; i < arrHoaDonChiTietDatHang.Length; i++)
            {
                HoaDonChiTietDatHang mHoaDonChiTietDatHang = arrHoaDonChiTietDatHang[i];
                ListViewItem         item = new ListViewItem(mHoaDonChiTietDatHang.MSDH);
                item.SubItems.Add(mHoaDonChiTietDatHang.MSHH);
                item.SubItems.Add(mHoaDonChiTietDatHang.TenSanPham);
                item.SubItems.Add(mHoaDonChiTietDatHang.SoLuong.ToString());
                item.SubItems.Add(mHoaDonChiTietDatHang.TiLeGiam.ToString());
                lstViewItem[i] = item;
            }

            // Create columns for the items and subitems.
            // Width of -2 indicates auto-size.
            this.lstViewDSThucUong.Columns.Add("MSDH", -2, HorizontalAlignment.Left);
            this.lstViewDSThucUong.Columns.Add("MSHH Hang", -2, HorizontalAlignment.Left);
            this.lstViewDSThucUong.Columns.Add("Ten san pham", -2, HorizontalAlignment.Left);
            this.lstViewDSThucUong.Columns.Add("So luong", -2, HorizontalAlignment.Left);
            this.lstViewDSThucUong.Columns.Add("Ti le giam", -2, HorizontalAlignment.Center);

            //Add the items to the listview.
            this.lstViewDSThucUong.Items.AddRange(lstViewItem);

            this.lstViewDSThucUong.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.ColumnContent);
            this.lstViewDSThucUong.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.HeaderSize);
            this.lstViewDSThucUong.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.ColumnContent);
            this.lstViewDSThucUong.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.HeaderSize);
            this.lstViewDSThucUong.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Пример #2
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());
                        mHoaDonChiTietDatHang.TenSanPham = reader[5].ToString();
                        arrHoaDonChiTietDatHang[i]       = mHoaDonChiTietDatHang;
                        i++;
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    // Console.WriteLine(ex.Message);
                }
                // Console.ReadLine();
            }

            return(arrHoaDonChiTietDatHang);
        }
Пример #3
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);
        }