public List <Product> StatisticByProduct(DTO.RevenueStatistic statistic) { SqlCommand cmd = new SqlCommand("sp_statisticByProduct", DBConnection.connectDB()); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@NgayBD", statistic.StartDate); cmd.Parameters.AddWithValue("@NgayKT", statistic.EndDate); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); List <Product> product_list = new List <Product>(); foreach (DataRow row in dt.Rows) { Product product = new Product(); product.ID = row.Field <int>("Mã SP").ToString(); product.Name = row.Field <string>("Tên SP").ToString(); product.Quantity = row.Field <int>("Số lượng bán ra"); //Dùng tạm tt Price để lưu doanh thu bán được của sản phảm, Price thực chất là đơn giá. product.Price = row.Field <int>("Doanh thu"); product.Type = row.Field <string>("Loại SP"); product_list.Add(product); } return(product_list); }
public List <Bill> StatisticByBill(DTO.RevenueStatistic statistic) { SqlCommand cmd = new SqlCommand("sp_StatisticByBill", DBConnection.connectDB()); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("@NgayBD", SqlDbType.Date).Value = statistic.StartDate; cmd.Parameters.Add("@NgayKT", SqlDbType.Date).Value = statistic.EndDate; SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); List <Bill> bill_list = new List <Bill>(); foreach (DataRow row in dt.Rows) { Bill bill = new Bill(); bill.ID = row.Field <int>("Mã HĐ").ToString(); bill.Total = row.Field <int>("Tổng giá trị"); bill.DiscountAmount = Convert.ToInt32(row.Field <double>("Tiền chiết khấu")); bill.ActualTotal = Convert.ToInt32(row.Field <double>("Thanh toán")); bill.Staff.ID = row.Field <int>("Mã NV").ToString(); bill.Customer.ID = row.Field <int>("Mã KH").ToString(); bill.CreatingTime = row.Field <DateTime>("Ngày"); bill.CreatingTime = bill.CreatingTime.Add(row.Field <TimeSpan>("Giờ")); bill_list.Add(bill); } return(bill_list); }
public DataTable[] getStatistic(DTO.RevenueStatistic statistic) { //1. Bảng thống kê theo hoá đơn List <Bill> bill_list = dao.StatisticByBill(statistic); DataTable bill_table = new DataTable(); bill_table.Columns.Add("Mã HĐ"); bill_table.Columns.Add("Tổng giá trị"); bill_table.Columns.Add("Lượng chiết khấu"); bill_table.Columns.Add("Thanh toán"); bill_table.Columns.Add("Mã NV"); bill_table.Columns.Add("Mã KH"); bill_table.Columns.Add("Thời gian"); int total = 0, discountAmount = 0, actualTotal = 0; foreach (Bill bill in bill_list) { object[] fields = new object[] { bill.ID, VNDfromNumber(bill.Total), VNDfromNumber(bill.DiscountAmount), VNDfromNumber(bill.ActualTotal), bill.Customer.ID, bill.Staff.ID, bill.CreatingTime }; bill_table.Rows.Add(fields); total += bill.Total; discountAmount += bill.DiscountAmount; actualTotal += bill.ActualTotal; } //2. Bảng thống kê theo sản phẩm List <Product> product_list = dao.StatisticByProduct(statistic); DataTable product_table = new DataTable(); product_table.Columns.Add("Mã SP"); product_table.Columns.Add("Tên SP"); product_table.Columns.Add("Số lượng bán ra"); product_table.Columns.Add("Doanh thu"); product_table.Columns.Add("Loại SP"); foreach (Product product in product_list) { object[] obj_arr = new object[] { product.ID, product.Name, product.Quantity, VNDfromNumber(product.Price), product.Type }; product_table.Rows.Add(obj_arr); } //3. Bảng thống kê tổng DataTable SummaryStatistic = new DataTable(); SummaryStatistic.Columns.Add("Tổng giá trị"); SummaryStatistic.Columns.Add("Tổng lượng chiết khấu"); SummaryStatistic.Columns.Add("Tổng thanh toán"); object[] row = new object[] { VNDfromNumber(total), VNDfromNumber(discountAmount), VNDfromNumber(actualTotal) }; SummaryStatistic.Rows.Add(row); //Mảng 3 datatable DataTable[] dt = new DataTable[3]; dt[0] = bill_table; dt[1] = product_table; dt[2] = SummaryStatistic; return(dt); }