Exemplo n.º 1
0
        private void btnXacNhanThemSanPham_Click(object sender, RoutedEventArgs e)
        {
            //Kiem Tra Form Rỗng
            if ("" == txtTenSanPham.Text || "" == txtGiaNhap.Text || "" == txtGiaBan.Text || "" == txtSoLuong.Text || cmbHangSanXuat.SelectedIndex == -1 || cmbMucDich.SelectedIndex == -1)
            {
                MessageBox.Show("Vui Lòng Không Để Trống");
                return;
            }

            if (Int32.Parse(txtSoLuong.Text) < 0 || Int32.Parse(txtGiaBan.Text) < 0 || Int32.Parse(txtGiaNhap.Text) < 0)
            {
                MessageBox.Show("Vui Lòng Kiểm Tra Lại Giá Trị Nhập");
                return;
            }

            if (bitmapImageSanPham == null)
            {
                MessageBox.Show("Vui Lòng Chọn Ảnh Hiện Thị");
                return;
            }

            var db = new MyDatabaseEntities();

            //Convert Ảnh
            byte[] imageData = new byte[bitmapImageSanPham.StreamSource.Length];
            bitmapImageSanPham.StreamSource.Seek(0, System.IO.SeekOrigin.Begin);
            bitmapImageSanPham.StreamSource.Read(imageData, 0, imageData.Length);

            //Tim ID Loai San Pham
            int ID_LoaiSanPham = -1;

            foreach (var value in db.LoaiSanPhams.ToList())
            {
                if (cmbHangSanXuat.SelectedValue.ToString() == value.HangSanXuat && cmbMucDich.SelectedValue.ToString() == value.MucDich)
                {
                    ID_LoaiSanPham = value.ID;
                    break;
                }
            }
            // Lay Gia Tri Hien Thi
            int CheckHienThi = cbHienThi.IsChecked == true ? 1 : 0;

            db.SanPhams.Add(new SanPham()
            {
                HinhAnh = imageData, Ten = txtTenSanPham.Text, LoaiSanPham_ID = ID_LoaiSanPham, GiaNhap = Int32.Parse(txtGiaNhap.Text), GiaBan = Int32.Parse(txtGiaBan.Text), HienThi = CheckHienThi, SoLuong = Int32.Parse(txtSoLuong.Text)
            });
            db.SaveChanges();
            MessageBox.Show("Thêm Thành Công");

            txtTenSanPham.Text           = "";
            txtGiaNhap.Text              = "";
            txtGiaBan.Text               = "";
            txtSoLuong.Text              = "";
            cmbHangSanXuat.SelectedIndex = -1;
            cmbMucDich.SelectedIndex     = -1;
            img_SanPham.Source           = new BitmapImage(new Uri("images/device-camera-icon.png", UriKind.Relative));
            bitmapImageSanPham           = null;
        }
Exemplo n.º 2
0
 private void btnXoa_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Bạn Chắc Chắn Muốn Xóa Chứ ?", "Thông Báo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         var db      = new MyDatabaseEntities();
         var Element = db.SanPhams.Find(ID_OFItemSelected);
         Element.HienThi = 0;
         db.SaveChanges();
         DanhSachSanPham.LoadSanPham(); // Load Lai Hien Thi Danh Sach San Pham
         NavigationService.GoBack();
     }
 }
        public void LoadListView()
        {
            MyDatabaseEntities db = new MyDatabaseEntities();

            foreach (var value in db.DonHangs.ToList())
            {
                DonHangHienThi x = new DonHangHienThi();


                if (value.TinhTrang == 0)
                {
                    x.TinhTrang = new BitmapImage(new Uri(@"images/cancel-button.png", UriKind.Relative));
                }
                else
                {
                    x.TinhTrang = new BitmapImage(new Uri(@"images/checking-mark-circle.png", UriKind.Relative));
                }

                if (value.LoaiThanhDon == 0)
                {
                    x.LoaiDonHang = new BitmapImage(new Uri(@"images/online-shopping-cart.png", UriKind.Relative));
                }
                else if (value.LoaiThanhDon == 1)
                {
                    x.LoaiDonHang = new BitmapImage(new Uri(@"images/delivery-truck.png", UriKind.Relative));
                }
                else
                {
                    x.LoaiDonHang = new BitmapImage(new Uri(@"images/coins.png", UriKind.Relative));
                }

                if (value.KhachHang_CMND != null)
                {
                    x.CMND       = value.KhachHang_CMND;
                    x.HoTen      = value.KhachHang.HoTen;
                    x.SDT        = value.KhachHang.SDT;
                    x.DiaChi     = value.KhachHang.DiaChi;
                    x.TienConLai = string.Format("{0:0,0}", value.TienConLaiPhaiTra);
                }
                else
                {
                    x.TienConLai = "0";
                }
                x.ID       = value.ID;
                x.Ngay     = (DateTime)value.NgayTao;
                x.TongTien = string.Format("{0:0,0}", value.TongGiaTriBan);


                ListDHHT.data.Add(x);
            }

            ltDonHang.ItemsSource = ListDHHT.data;
        }
Exemplo n.º 4
0
        public void LoadComboBox()
        {
            var db = new MyDatabaseEntities();

            cmbHangSanXuat.Items.Clear();
            foreach (var value in db.LoaiSanPhams.ToList())
            {
                if (cmbHangSanXuat.Items.IndexOf(value.HangSanXuat) == -1)
                {
                    cmbHangSanXuat.Items.Add(value.HangSanXuat);
                }
            }
        }
Exemplo n.º 5
0
        private void btnExcelXNLoaiSanPham_Click(object sender, RoutedEventArgs e)
        {
            if (txtPathLoaiSanPham.Text == "")
            {
                MessageBox.Show("Vui Lòng Chọn Đường Dẫn", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var db = new MyDatabaseEntities();

            try
            {
                Excel excel = new Excel(txtPathLoaiSanPham.Text, 1);

                for (int i = 1;; ++i)
                {
                    string value_HangSanXuat = excel.ReadCell(i, 0);
                    string value_MucDich     = excel.ReadCell(i, 1);
                    if (value_HangSanXuat == "")
                    {
                        break;
                    }

                    //Kiểm Tra Tồn Tại
                    bool CheckTonTai = false;
                    foreach (LoaiSanPham loaiSanPham in db.LoaiSanPhams.ToList())
                    {
                        if (loaiSanPham.HangSanXuat == value_HangSanXuat && loaiSanPham.MucDich == value_MucDich)
                        {
                            CheckTonTai = true;
                            break;
                        }
                    }
                    if (CheckTonTai == false)
                    {
                        db.LoaiSanPhams.Add(new LoaiSanPham()
                        {
                            HangSanXuat = value_HangSanXuat, MucDich = value_MucDich
                        });
                        db.SaveChanges();
                    }
                }
            }
            catch
            {
                MessageBox.Show("File Không Hợp Lệ", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            MessageBox.Show("Thêm Thành Công");
        }
Exemplo n.º 6
0
        private void btnXacNhanSuaSanPham_Click(object sender, RoutedEventArgs e)
        {
            //Kiem Tra Form Rỗng
            if ("" == txtTenSanPham.Text || "" == txtGiaNhap.Text || "" == txtGiaBan.Text || "" == txtSoLuong.Text || cmbHangSanXuat.SelectedIndex == -1 || cmbMucDich.SelectedIndex == -1)
            {
                MessageBox.Show("Vui Lòng Không Để Trống");
                return;
            }

            if (Int32.Parse(txtSoLuong.Text) < 0 || Int32.Parse(txtGiaBan.Text) < 0 || Int32.Parse(txtGiaNhap.Text) < 0)
            {
                MessageBox.Show("Vui Lòng Kiểm Tra Lại Giá Trị Nhập");
                return;
            }

            var db      = new MyDatabaseEntities();
            var element = db.SanPhams.Find(ID_OFItemSelected);

            //Convert Ảnh
            byte[] imageData = new byte[bitmapImageSanPham.StreamSource.Length];
            bitmapImageSanPham.StreamSource.Seek(0, System.IO.SeekOrigin.Begin);
            bitmapImageSanPham.StreamSource.Read(imageData, 0, imageData.Length);

            //Tim ID Loai San Pham
            int ID_LoaiSanPham = -1;

            foreach (var value in db.LoaiSanPhams.ToList())
            {
                if (cmbHangSanXuat.SelectedValue.ToString() == value.HangSanXuat && cmbMucDich.SelectedValue.ToString() == value.MucDich)
                {
                    ID_LoaiSanPham = value.ID;
                    break;
                }
            }
            // Lay Gia Tri Hien Thi
            element.HinhAnh        = imageData;
            element.Ten            = txtTenSanPham.Text;
            element.LoaiSanPham_ID = ID_LoaiSanPham;
            element.GiaNhap        = Int32.Parse(txtGiaNhap.Text);
            element.GiaBan         = Int32.Parse(txtGiaBan.Text);
            element.SoLuong        = Int32.Parse(txtSoLuong.Text);

            db.SaveChanges();
            MessageBox.Show("Sữa Thành Công");
            DanhSachSanPham.LoadSanPham(); // Load Lai Sau Khi Sua
        }
Exemplo n.º 7
0
        static public void LoadSanPham()
        {
            List <SanPhamHienThi> data = new List <SanPhamHienThi>();
            var db = new MyDatabaseEntities();
            var listDatabaseSanPham = db.SanPhams.ToList();

            int CountPhanTuHienThi = 0;

            for (int i = 0; i < listDatabaseSanPham.Count; ++i)
            {
                var element = listDatabaseSanPham[i];
                if (element.HienThi == 1)
                {
                    if (CountPhanTuHienThi >= TrangHienTai * SoPhanTuTrenMotTrang && CountPhanTuHienThi < (TrangHienTai * SoPhanTuTrenMotTrang) + SoPhanTuTrenMotTrang)
                    {
                        //Convert Ảnh
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(element.HinhAnh);
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
                        BitmapImage newBitmapImage = new BitmapImage();
                        newBitmapImage.BeginInit();
                        newBitmapImage.StreamSource = ms;
                        newBitmapImage.EndInit();

                        //Add Element
                        data.Add(new SanPhamHienThi()
                        {
                            ID = element.ID, Name = element.Ten, PathImage = newBitmapImage, Price = string.Format("{0:0,0} VND", (int)element.GiaBan)
                        });
                    }
                    ++CountPhanTuHienThi;
                }
            }
            MaxTrang = (int)Math.Ceiling((double)CountPhanTuHienThi / SoPhanTuTrenMotTrang);

            if (data.Count >= 1)
            {
                for (int i = 12 - data.Count; i > 0; --i)
                {
                    data.Add(new SanPhamHienThi()
                    {
                        ID = -1
                    });
                }
            }
            ltSanPham_Temp.ItemsSource = data;
        }
Exemplo n.º 8
0
        private void cmbHangSanXuat_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Khong Xu Ly
            if (cmbHangSanXuat.SelectedIndex == -1)
            {
                return;
            }
            var db = new MyDatabaseEntities();

            cmbMucDich.Items.Clear();
            foreach (var value in db.LoaiSanPhams.ToList())
            {
                if (cmbHangSanXuat.SelectedValue.ToString() == value.HangSanXuat)
                {
                    cmbMucDich.Items.Add(value.MucDich);
                }
            }
        }
Exemplo n.º 9
0
        private void btnThanhToan_Click(object sender, RoutedEventArgs e)
        {
            int     ID_HD_Load = TrangDonHang.IDofItemSelected;
            var     db         = new MyDatabaseEntities();
            DonHang x          = db.DonHangs.Find(ID_HD_Load);

            x.TinhTrang = 1;
            db.SaveChanges();

            foreach (var value in ListDHHT.data)
            {
                if (value.ID == x.ID)
                {
                    value.TinhTrang = new BitmapImage(new Uri(@"images/checking-mark-circle.png", UriKind.Relative));
                    break;
                }
            }
            MessageBox.Show("Thành Công");
            btnThanhToan.Visibility = Visibility.Hidden;
        }
Exemplo n.º 10
0
        public ViewModel()
        {
            this.SneakersDetail = new ObservableCollection <Model>();

            if (TrangThongKe.KieuThongKe == 0)
            {
                int      YearXet        = TrangThongKe.Year;
                int      MonthXet       = TrangThongKe.Month;
                DateTime DateXet        = new DateTime(YearXet, MonthXet, 1);
                int      DaysOfMonthXet = DateTime.DaysInMonth(YearXet, MonthXet);
                for (int i = 1; i <= DaysOfMonthXet; ++i)
                {
                    DateTime date     = new DateTime(YearXet, MonthXet, i);
                    double   DoanhThu = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        DateTime ngayTao = (DateTime)DH.NgayTao;
                        if (ngayTao.Day == date.Day && ngayTao.Month == date.Month && ngayTao.Year == date.Year)
                        {
                            DoanhThu += (double)DH.TongGiaTriBan - (double)DH.TongGiaTriNhap;
                        }
                    }
                    SneakersDetail.Add(new Model()
                    {
                        Brand = "" + i, ItemsCount = DoanhThu / 1000000
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 1)
            {
                int YearXet = TrangThongKe.Year;
                for (int i = 1; i <= 12; ++i)
                {
                    DateTime datestart = new DateTime(YearXet, i, 1);
                    DateTime dateEnd;
                    if (i + 1 > 12)
                    {
                        dateEnd = new DateTime(YearXet + 1, i, 1);
                    }
                    else
                    {
                        dateEnd = new DateTime(YearXet, i + 1, 1);
                    }


                    double DoanhThu = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        if (DH.NgayTao >= datestart && DH.NgayTao < dateEnd)
                        {
                            DoanhThu += (double)DH.TongGiaTriBan - (double)DH.TongGiaTriNhap;
                        }
                    }
                    SneakersDetail.Add(new Model()
                    {
                        Brand = "" + i, ItemsCount = DoanhThu / 1000000
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 2)
            {
                int YearXet = TrangThongKe.Year;
                int i       = 1;
                while (true)
                {
                    DateTime datestart = new DateTime(YearXet, i, 1);
                    DateTime dateEnd;
                    if (i == 10)
                    {
                        dateEnd = new DateTime(YearXet + 1, 1, 1);
                    }
                    else
                    {
                        dateEnd = new DateTime(YearXet, i + 3, 1);
                    }


                    double DoanhThu = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        if (DH.NgayTao >= datestart && DH.NgayTao < dateEnd)
                        {
                            DoanhThu += (double)DH.TongGiaTriBan / 1000000 - (double)DH.TongGiaTriNhap / 1000000;
                        }
                    }

                    if (i == 1)
                    {
                        SneakersDetail.Add(new Model()
                        {
                            Brand = "Quý " + 1, ItemsCount = DoanhThu
                        });
                        i = 4;
                    }
                    else if (i == 4)
                    {
                        SneakersDetail.Add(new Model()
                        {
                            Brand = "Quý " + 2, ItemsCount = DoanhThu
                        });
                        i = 7;
                    }
                    else if (i == 7)
                    {
                        SneakersDetail.Add(new Model()
                        {
                            Brand = "Quý " + 3, ItemsCount = DoanhThu
                        });
                        i = 10;
                    }
                    else if (i == 10)
                    {
                        SneakersDetail.Add(new Model()
                        {
                            Brand = "Quý " + 4, ItemsCount = DoanhThu
                        });
                        break;
                    }
                }
            }
            else if (TrangThongKe.KieuThongKe == 3)
            {
                int YearNow = DateTime.Now.Year;
                for (int i = 2015; i <= YearNow; ++i)
                {
                    DateTime datestart = new DateTime(i, 1, 1);
                    DateTime dateEnd   = new DateTime(i + 1, 1, 1);;

                    double DoanhThu = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        if (DH.NgayTao >= datestart && DH.NgayTao < dateEnd)
                        {
                            DoanhThu += (double)DH.TongGiaTriBan - (double)DH.TongGiaTriNhap;
                        }
                    }
                    SneakersDetail.Add(new Model()
                    {
                        Brand = "" + i, ItemsCount = DoanhThu / 1000000
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 4)
            {
                DateTime datestart = TrangThongKe.DateStart;
                DateTime dateEnd   = TrangThongKe.DateEnd;
                DateTime dateNow   = datestart;
                while (true)
                {
                    double DoanhThu = 0;
                    var    db       = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        DateTime temp = (DateTime)DH.NgayTao;
                        if (temp.Month == dateNow.Month && temp.Year == dateNow.Year && temp.Day == dateNow.Day)
                        {
                            DoanhThu += (double)DH.TongGiaTriBan - (double)DH.TongGiaTriNhap;
                        }
                    }
                    SneakersDetail.Add(new Model()
                    {
                        Brand = dateNow.ToShortDateString(), ItemsCount = DoanhThu / 1000000
                    });
                    dateNow = dateNow.AddDays(1);
                    if (dateNow == dateEnd)
                    {
                        break;
                    }
                }
            }
        }
        public ViewModelHinhTronHinhTron()
        {
            this.Tax = new List <ModelHinhTron>();
            var db = new MyDatabaseEntities();



            if (TrangThongKe.KieuThongKe == 0)
            {
                int YearXet  = TrangThongKe.Year;
                int MonthXet = TrangThongKe.Month;
                int DayXet   = TrangThongKe.Day;
                //Tong SLL SP
                int TongSLDaBan = 0;

                List <GioHang> data = new List <GioHang>();
                foreach (var DH in db.DonHangs.ToList())
                {
                    DateTime dateTime = (DateTime)DH.NgayTao;
                    if (dateTime.Year == YearXet && dateTime.Month == MonthXet && dateTime.Day == DayXet)
                    {
                        foreach (var GH in db.GioHangs.ToList())
                        {
                            if (DH.GioHang.ID == GH.ID)
                            {
                                data.Add(GH);
                                TongSLDaBan += (int)GH.SoLuong;
                            }
                        }
                    }
                }

                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].SanPham_ID == 0)
                    {
                        continue;
                    }
                    int TongSL = (int)data[i].SoLuong;
                    for (int j = i + 1; j < data.Count; ++j)
                    {
                        if (data[i].SanPham_ID == data[j].SanPham_ID)
                        {
                            TongSL            += (int)data[j].SoLuong;
                            data[j].SanPham_ID = 0;
                        }
                    }
                    Tax.Add(new ModelHinhTron()
                    {
                        Category = data[i].SanPham.Ten, Percentage = (double)TongSL * 100 / TongSLDaBan
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 1)
            {
                int YearXet  = TrangThongKe.Year;
                int MonthXet = TrangThongKe.Month;

                //Tong SLL SP
                int TongSLDaBan = 0;

                List <GioHang> data = new List <GioHang>();
                foreach (var DH in db.DonHangs.ToList())
                {
                    DateTime dateTime = (DateTime)DH.NgayTao;
                    if (dateTime.Year == YearXet && dateTime.Month == MonthXet)
                    {
                        foreach (var GH in db.GioHangs.ToList())
                        {
                            if (DH.GioHang.ID == GH.ID)
                            {
                                data.Add(GH);
                                TongSLDaBan += (int)GH.SoLuong;
                            }
                        }
                    }
                }

                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].SanPham_ID == 0)
                    {
                        continue;
                    }
                    int TongSL = (int)data[i].SoLuong;
                    for (int j = i + 1; j < data.Count; ++j)
                    {
                        if (data[i].SanPham_ID == data[j].SanPham_ID)
                        {
                            TongSL            += (int)data[j].SoLuong;
                            data[j].SanPham_ID = 0;
                        }
                    }
                    Tax.Add(new ModelHinhTron()
                    {
                        Category = data[i].SanPham.Ten, Percentage = (double)TongSL * 100 / TongSLDaBan
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 2)
            {
                int YearXet = TrangThongKe.Year;

                int QuyXet     = TrangThongKe.Quy;
                int MonthStart = -1;
                int MonthEnd   = -1;
                if (QuyXet == 1)
                {
                    MonthStart = 1;
                    MonthEnd   = 3;
                }
                else if (QuyXet == 2)
                {
                    MonthStart = 4;
                    MonthEnd   = 6;
                }
                else if (QuyXet == 3)
                {
                    MonthStart = 7;
                    MonthEnd   = 9;
                }
                else if (QuyXet == 4)
                {
                    MonthStart = 10;
                    MonthEnd   = 12;
                }

                //Tong SLL SP
                int TongSLDaBan = 0;

                List <GioHang> data = new List <GioHang>();
                foreach (var DH in db.DonHangs.ToList())
                {
                    DateTime dateTime = (DateTime)DH.NgayTao;
                    if (dateTime.Year == YearXet && dateTime.Month >= MonthStart && dateTime.Month <= MonthEnd)
                    {
                        foreach (var GH in db.GioHangs.ToList())
                        {
                            if (DH.GioHang.ID == GH.ID)
                            {
                                data.Add(GH);
                                TongSLDaBan += (int)GH.SoLuong;
                            }
                        }
                    }
                }

                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].SanPham_ID == 0)
                    {
                        continue;
                    }
                    int TongSL = (int)data[i].SoLuong;
                    for (int j = i + 1; j < data.Count; ++j)
                    {
                        if (data[i].SanPham_ID == data[j].SanPham_ID)
                        {
                            TongSL            += (int)data[j].SoLuong;
                            data[j].SanPham_ID = 0;
                        }
                    }
                    Tax.Add(new ModelHinhTron()
                    {
                        Category = data[i].SanPham.Ten, Percentage = (double)TongSL * 100 / TongSLDaBan
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 3)
            {
                int YearXet = TrangThongKe.Year;

                //Tong SLL SP
                int TongSLDaBan = 0;

                List <GioHang> data = new List <GioHang>();
                foreach (var DH in db.DonHangs.ToList())
                {
                    DateTime dateTime = (DateTime)DH.NgayTao;
                    if (dateTime.Year == YearXet)
                    {
                        foreach (var GH in db.GioHangs.ToList())
                        {
                            if (DH.GioHang.ID == GH.ID)
                            {
                                data.Add(GH);
                                TongSLDaBan += (int)GH.SoLuong;
                            }
                        }
                    }
                }

                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].SanPham_ID == 0)
                    {
                        continue;
                    }
                    int TongSL = (int)data[i].SoLuong;
                    for (int j = i + 1; j < data.Count; ++j)
                    {
                        if (data[i].SanPham_ID == data[j].SanPham_ID)
                        {
                            TongSL            += (int)data[j].SoLuong;
                            data[j].SanPham_ID = 0;
                        }
                    }
                    Tax.Add(new ModelHinhTron()
                    {
                        Category = data[i].SanPham.Ten, Percentage = (double)TongSL * 100 / TongSLDaBan
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 4)
            {
                DateTime datestart = TrangThongKe.DateStart;
                DateTime dateEnd   = TrangThongKe.DateEnd;
                DateTime dateNow   = datestart;

                //Tong SLL SP
                int TongSLDaBan = 0;

                List <GioHang> data = new List <GioHang>();
                foreach (var DH in db.DonHangs.ToList())
                {
                    DateTime dateTime = (DateTime)DH.NgayTao;
                    if (dateTime >= datestart && dateTime <= dateEnd)
                    {
                        foreach (var GH in db.GioHangs.ToList())
                        {
                            if (DH.GioHang.ID == GH.ID)
                            {
                                data.Add(GH);
                                TongSLDaBan += (int)GH.SoLuong;
                            }
                        }
                    }
                }

                for (int i = 0; i < data.Count; ++i)
                {
                    if (data[i].SanPham_ID == 0)
                    {
                        continue;
                    }
                    int TongSL = (int)data[i].SoLuong;
                    for (int j = i + 1; j < data.Count; ++j)
                    {
                        if (data[i].SanPham_ID == data[j].SanPham_ID)
                        {
                            TongSL            += (int)data[j].SoLuong;
                            data[j].SanPham_ID = 0;
                        }
                    }
                    Tax.Add(new ModelHinhTron()
                    {
                        Category = data[i].SanPham.Ten, Percentage = (double)TongSL * 100 / TongSLDaBan
                    });
                }
            }
        }
Exemplo n.º 12
0
        private void btnExcelXNSanPham_Click(object sender, RoutedEventArgs e)
        {
            if (txtPathSanPham.Text == "")
            {
                MessageBox.Show("Vui Lòng Chọn Đường Dẫn", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            var db = new MyDatabaseEntities();

            try
            {
                Excel excel = new Excel(txtPathSanPham.Text, 1);

                for (int i = 1; ; ++i)
                {
                    string value_Ten = excel.ReadCell(i, 0);
                    if (value_Ten == "")
                    {
                        break;
                    }
                    string value_LinkAnh     = excel.ReadCell(i, 1);
                    string value_HangSanXuat = excel.ReadCell(i, 2);
                    string value_MucDich     = excel.ReadCell(i, 3);
                    string value_GiaNhap     = excel.ReadCell(i, 4);
                    string value_GiaBan      = excel.ReadCell(i, 5);
                    string value_SoLuong     = excel.ReadCell(i, 6);

                    //Convert Ảnh
                    string PathFolder = txtPathSanPham.Text.Substring(0, txtPathSanPham.Text.LastIndexOf('\\'));
                    bitmapImageSanPham = new BitmapImage();
                    bitmapImageSanPham.BeginInit();
                    bitmapImageSanPham.StreamSource = System.IO.File.OpenRead(PathFolder + "\\" + value_LinkAnh);
                    bitmapImageSanPham.EndInit();
                    byte[] imageData = new byte[bitmapImageSanPham.StreamSource.Length];
                    bitmapImageSanPham.StreamSource.Seek(0, System.IO.SeekOrigin.Begin);
                    bitmapImageSanPham.StreamSource.Read(imageData, 0, imageData.Length);

                    //Kiểm Tra Tồn Tại
                    bool CheckTonTai         = false;
                    int  IDLoaiSanPhamTonTai = -1;
                    foreach (LoaiSanPham loaiSanPham in db.LoaiSanPhams.ToList())
                    {
                        if (loaiSanPham.HangSanXuat == value_HangSanXuat && loaiSanPham.MucDich == value_MucDich)
                        {
                            CheckTonTai         = true;
                            IDLoaiSanPhamTonTai = loaiSanPham.ID;
                            break;
                        }
                    }
                    if (CheckTonTai == false)
                    {
                        db.LoaiSanPhams.Add(new LoaiSanPham()
                        {
                            HangSanXuat = value_HangSanXuat, MucDich = value_MucDich
                        });
                        db.SaveChanges();
                        db.SanPhams.Add(new SanPham()
                        {
                            Ten = value_Ten, HinhAnh = imageData, LoaiSanPham_ID = db.LoaiSanPhams.ToList()[db.LoaiSanPhams.ToList().Count - 1].ID, GiaNhap = Int32.Parse(value_GiaNhap), GiaBan = Int32.Parse(value_GiaBan), SoLuong = Int32.Parse(value_SoLuong), HienThi = 1
                        });
                        db.SaveChanges();
                    }
                    else
                    {
                        db.SanPhams.Add(new SanPham()
                        {
                            Ten = value_Ten, HinhAnh = imageData, LoaiSanPham_ID = IDLoaiSanPhamTonTai, GiaNhap = Int32.Parse(value_GiaNhap), GiaBan = Int32.Parse(value_GiaBan), SoLuong = Int32.Parse(value_SoLuong), HienThi = 1
                        });
                        db.SaveChanges();
                    }
                }
            }
            catch
            {
                MessageBox.Show("File Không Hợp Lệ", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            MessageBox.Show("Thêm Thành Công");
        }
Exemplo n.º 13
0
        public TrangHoaDon()
        {
            InitializeComponent();

            //Add ComboLoaiHoaDoan
            cmbLoaiHoaDon.Items.Add("Trực Tiếp"); // 0
            cmbLoaiHoaDon.Items.Add("Giao Hàng"); // 1
            cmbLoaiHoaDon.Items.Add("Đặt Cọc");   // 2
            cmbLoaiHoaDon.SelectedIndex = 0;

            //Load Thong tin Don Hang
            int     ID_HD_Load = TrangDonHang.IDofItemSelected;
            var     db         = new MyDatabaseEntities();
            DonHang x          = db.DonHangs.Find(ID_HD_Load);

            if (x.TinhTrang == 1)
            {
                btnThanhToan.Visibility = Visibility.Hidden;
            }

            lblTongTien.Content = string.Format("{0:0,0}", x.TongGiaTriBan);
            txtTienDatCoc.Text  = string.Format("{0:0,0}", (x.TongGiaTriBan - x.TienConLaiPhaiTra));
            if (x.MaKhuyenMai != null)
            {
                txtMaKhuyenMai.Text = x.MaKhuyenMai.Ten;
                if (x.MaKhuyenMai.Loai == "Tiền Cố Định")
                {
                    lblKhuyenMai.Content  = string.Format("- {0:0,0}", Int32.Parse(x.MaKhuyenMai.GiaTri));
                    lblTongGiaTri.Content = string.Format("{0:0,0}", (x.TongGiaTriBan + Int32.Parse(x.MaKhuyenMai.GiaTri)));
                }
                else
                {
                    float GiaTriKM = float.Parse(x.MaKhuyenMai.GiaTri);
                    float PhanChia = (1 - GiaTriKM / 100);
                    lblTongGiaTri.Content = string.Format("{0:0,0}", ((float)x.TongGiaTriBan / PhanChia));
                    lblKhuyenMai.Content  = string.Format("- {0:0,0}", ((float)x.TongGiaTriBan / PhanChia) * GiaTriKM / 100);
                }
            }
            else
            {
                lblTongGiaTri.Content = lblTongTien.Content;
            }


            cmbLoaiHoaDon.SelectedIndex = (int)x.LoaiThanhDon;
            if (x.KhachHang_CMND != null)
            {
                txtCMND.Text   = x.KhachHang_CMND;
                txtHoTen.Text  = x.KhachHang.HoTen;
                txtSDT.Text    = x.KhachHang.SDT;
                txtDiaChi.Text = x.KhachHang.DiaChi;
            }


            //Load ltGioHang
            List <SanPhamGioHangHienThi> Temp = new List <SanPhamGioHangHienThi>();

            foreach (var value in db.GioHangs)
            {
                if (x.GioHang.ID == value.ID)
                {
                    SanPham SP = db.SanPhams.Find(value.SanPham_ID);
                    //Convert Ảnh
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(SP.HinhAnh);
                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    BitmapImage newBitmapImage = new BitmapImage();
                    newBitmapImage.BeginInit();
                    newBitmapImage.StreamSource = ms;
                    newBitmapImage.EndInit();

                    Temp.Add(new SanPhamGioHangHienThi()
                    {
                        PathImage = newBitmapImage, Name = SP.Ten, Price = string.Format("{0}", (int)SP.GiaBan), Count = value.SoLuong.ToString()
                    });
                }
            }
            ltGioHang.ItemsSource = Temp;
        }
        public ViewModelKhachHang()
        {
            this.DataPoints = new ObservableCollection <ModelKhachHang>();

            if (TrangThongKe.KieuThongKe == 0)
            {
                int      YearXet        = TrangThongKe.Year;
                int      MonthXet       = TrangThongKe.Month;
                DateTime DateXet        = new DateTime(YearXet, MonthXet, 1);
                int      DaysOfMonthXet = DateTime.DaysInMonth(YearXet, MonthXet);
                for (int i = 1; i <= DaysOfMonthXet; ++i)
                {
                    DateTime date     = new DateTime(YearXet, MonthXet, i);
                    double   TongNhap = 0;
                    double   TongBan  = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        DateTime ngayTao = (DateTime)DH.NgayTao;
                        if (ngayTao.Day == date.Day && ngayTao.Month == date.Month && ngayTao.Year == date.Year)
                        {
                            TongNhap = (double)DH.TongGiaTriNhap;
                            TongBan  = (double)DH.TongGiaTriBan;
                        }
                    }
                    DataPoints.Add(new ModelKhachHang()
                    {
                        TimeXet = i.ToString(), TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 1)
            {
                int YearXet = TrangThongKe.Year;
                for (int i = 1; i <= 12; ++i)
                {
                    DateTime datestart = new DateTime(YearXet, i, 1);
                    DateTime dateEnd;
                    if (i + 1 > 12)
                    {
                        dateEnd = new DateTime(YearXet + 1, i, 1);
                    }
                    else
                    {
                        dateEnd = new DateTime(YearXet, i + 1, 1);
                    }

                    double TongNhap = 0;
                    double TongBan  = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        if (DH.NgayTao >= datestart && DH.NgayTao < dateEnd)
                        {
                            TongNhap += (double)DH.TongGiaTriNhap;
                            TongBan  += (double)DH.TongGiaTriBan;
                        }
                    }

                    DataPoints.Add(new ModelKhachHang()
                    {
                        TimeXet = i.ToString(), TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 2)
            {
                int YearXet = TrangThongKe.Year;
                int i       = 1;
                while (true)
                {
                    DateTime datestart = new DateTime(YearXet, i, 1);
                    DateTime dateEnd;
                    if (i == 10)
                    {
                        dateEnd = new DateTime(YearXet + 1, 1, 1);
                    }
                    else
                    {
                        dateEnd = new DateTime(YearXet, i + 3, 1);
                    }


                    double TongNhap = 0;
                    double TongBan  = 0;


                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        if (DH.NgayTao >= datestart && DH.NgayTao < dateEnd)
                        {
                            TongNhap += (double)DH.TongGiaTriNhap;
                            TongBan  += (double)DH.TongGiaTriBan;
                        }
                    }

                    if (i == 1)
                    {
                        DataPoints.Add(new ModelKhachHang()
                        {
                            TimeXet = "Quý 1", TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                        });
                        i = 4;
                    }
                    else if (i == 4)
                    {
                        DataPoints.Add(new ModelKhachHang()
                        {
                            TimeXet = "Quý 2", TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                        });
                        i = 7;
                    }
                    else if (i == 7)
                    {
                        DataPoints.Add(new ModelKhachHang()
                        {
                            TimeXet = "Quý 3", TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                        });
                        i = 10;
                    }
                    else if (i == 10)
                    {
                        DataPoints.Add(new ModelKhachHang()
                        {
                            TimeXet = "Quý 4", TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                        });
                        break;
                    }
                }
            }
            else if (TrangThongKe.KieuThongKe == 3)
            {
                int YearNow = DateTime.Now.Year;
                for (int i = 2015; i <= YearNow; ++i)
                {
                    DateTime datestart = new DateTime(i, 1, 1);
                    DateTime dateEnd   = new DateTime(i + 1, 1, 1);;

                    double TongNhap = 0;
                    double TongBan  = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        if (DH.NgayTao >= datestart && DH.NgayTao < dateEnd)
                        {
                            TongNhap += (double)DH.TongGiaTriNhap;
                            TongBan  += (double)DH.TongGiaTriBan;
                        }
                    }
                    DataPoints.Add(new ModelKhachHang()
                    {
                        TimeXet = i.ToString(), TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                    });
                }
            }
            else if (TrangThongKe.KieuThongKe == 4)
            {
                DateTime datestart = TrangThongKe.DateStart;
                DateTime dateEnd   = TrangThongKe.DateEnd;
                DateTime dateXet   = datestart;
                while (true)
                {
                    double TongNhap = 0;
                    double TongBan  = 0;

                    var db = new MyDatabaseEntities();
                    foreach (var DH in db.DonHangs.ToList())
                    {
                        DateTime ngayTao = (DateTime)DH.NgayTao;
                        if (ngayTao.Day == dateXet.Day && ngayTao.Month == dateXet.Month && ngayTao.Year == dateXet.Year)
                        {
                            TongNhap = (double)DH.TongGiaTriNhap;
                            TongBan  = (double)DH.TongGiaTriBan;
                        }
                    }
                    DataPoints.Add(new ModelKhachHang()
                    {
                        TimeXet = dateXet.ToShortDateString(), TienNhap = TongNhap / 1000000, TienBan = TongBan / 1000000,
                    });
                    dateXet = dateXet.AddDays(1);
                    if (dateXet == dateEnd)
                    {
                        break;
                    }
                }
            }
        }