private void btnTaoThongKe_Click(object sender, RoutedEventArgs e)
        {
            if (chiTietThongKes.Count() > 0)
            {
                double tongThanTien = 0;
                string maThongKe    = CServices.taoMa <ThongKe>(CThongKe.toList());

                foreach (var item in chiTietThongKes)
                {
                    tongThanTien += item.Item6;
                }

                ThongKe thongKe = new ThongKe();
                thongKe.maThongKe     = maThongKe;
                thongKe.ngayLap       = DateTime.Now;
                thongKe.tongThanhTien = tongThanTien;

                if (!CThongKe.add(thongKe))
                {
                    return;
                }

                foreach (var chiTiet in chiTietThongKes)
                {
                    ChiTietThongKe chiTietThongKe = new ChiTietThongKe();
                    chiTietThongKe.maChiTietThongKe = CServices.taoMa <ChiTietThongKe>(CChiTietThongKe.toList());
                    chiTietThongKe.maThongKe        = maThongKe;
                    chiTietThongKe.maNhanVien       = chiTiet.Item1;
                    chiTietThongKe.soLuongHoaDon    = chiTiet.Item4;
                    chiTietThongKe.soLuongBan       = chiTiet.Item5;
                    chiTietThongKe.ngayLap          = DateTime.Now;
                    chiTietThongKe.thanhTien        = chiTiet.Item6;
                    if (!CChiTietThongKe.add(chiTietThongKe))
                    {
                        return;
                    }
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Danh sách chi tiết thống kê rỗng, không thể tạo thống kê");
            }
        }
Example #2
0
 public static bool add(ChiTietThongKe chiTietThongKe)
 {
     try
     {
         quanLyQuanCoffee.ChiTietThongKes.Add(chiTietThongKe);
         quanLyQuanCoffee.SaveChanges();
     }
     catch (DbUpdateException)
     {
         MessageBox.Show("Lỗi! Không thể thêm dữ liệu");
         return(false);
     }
     catch (DbEntityValidationException)
     {
         MessageBox.Show("Lỗi! Kiểu dữ liệu được truyền vào không hợp lệ");
         return(false);
     }
     return(true);
 }