Beispiel #1
0
        private ChiTietHoaDon LoopData(int STT)
        {
            var CT = new ChiTietHoaDon();

            using (var BH = new Models.BanLapTopEntities())
            {
                var GioHang = (from h in BLT.DonHangTemps
                               where h.STT == STT
                               select h);

                foreach (var Temp in GioHang)
                {
                    CT.MaKhacHang   = Temp.MaKhacHang;
                    CT.TenKhachHang = Temp.TenKhachHang;
                    CT.MaDonHang    = Temp.MaDonHang;
                    CT.MaSP         = Temp.MaSP;
                    CT.TenSP        = Temp.TenSP;
                    CT.SoLuongMua   = Temp.SoLuongMua;
                    CT.GiaSP        = Temp.GiaSP;
                    CT.HinhSP       = Temp.HinhSP;
                    CT.ThanhTien    = Temp.ThanhTien;
                }
            }

            return(CT);
        }
        private void btnXoa_Click(object sender, RoutedEventArgs e)
        {
            int ID = (ListGioHang.SelectedItem as HangSanXuat).MaHangSX;

            if (ConKinhDoanh(ID))
            {
                MessageBox.Show("Vẫn Còn Sản Phẩm Thuộc Hãng Này => Không Thể Xóa", "Delete Selected", MessageBoxButton.OK, MessageBoxImage.Stop);
            }
            else if (MessageBox.Show("Are you sure ?", "Delete Selected", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                try
                {
                    using (var BH = new Models.BanLapTopEntities())
                    {
                        var sql = BH.HangSanXuats.Where(m => m.MaHangSX == ID).Single() as HangSanXuat;
                        sql.ConKinhDoanh = false;
                        BH.SaveChanges();
                    }
                    Load();
                }
                catch (Exception)
                {
                    MessageBox.Show("Vẫn Còn Sản Phẩm Thuộc Hãng Này => Không Thể Xóa", "Delete Selected", MessageBoxButton.OK, MessageBoxImage.Stop);
                }
            }
        }
Beispiel #3
0
 private List <int> LaySTT()
 {
     using (var BH = new Models.BanLapTopEntities())
     {
         return((from i in BH.DonHangTemps
                 select i.STT).ToList());
     }
 }
 private int LayMaHSX()
 {
     using (var BanHang = new Models.BanLapTopEntities())
     {
         return((from i in BanHang.HangSanXuats
                 select i.MaHangSX).Max() + 1);
     }
 }
 private int GetMaLoaiSP()
 {
     using (var BH = new Models.BanLapTopEntities())
     {
         return((from i in BH.LoaiSanPhams
                 select i.MaLoaiSP).Max() + 1);
     }
 }
Beispiel #6
0
 private int LayMaSp(int STT)
 {
     using (var BH = new Models.BanLapTopEntities())
     {
         return((from i in BH.DonHangTemps
                 where i.STT == STT
                 select i.MaSP).SingleOrDefault());
     }
 }
Beispiel #7
0
 private int SoLuongMua(int MaSp)
 {
     using (var BH = new Models.BanLapTopEntities())
     {
         return((from i in BH.DonHangTemps
                 where i.MaSP == MaSp
                 select i.SoLuongMua).SingleOrDefault());
     }
 }
Beispiel #8
0
        private void btnthanhtoan_Click(object sender, RoutedEventArgs e)
        {
            if (ListGioHang.Items.Count > 0)
            {
                using (var BH = new Models.BanLapTopEntities())
                {
                    foreach (var i in LaySTT())
                    {
                        if (KiemTraConHang(LayMaSp(i)) == false)
                        {
                            var Name = (from lt in BH.DonHangTemps
                                        where lt.STT == i
                                        select lt.TenSP).SingleOrDefault();
                            var SL = (from lt in BH.DonHangTemps
                                      where lt.STT == i
                                      select lt.SoLuongMua).SingleOrDefault();
                            MessageBox.Show("LapTop " + Name + " Số Tồn Kho < " + SL + " Cái", "Không Đủ Mặt Hàng Cần Mua", MessageBoxButton.OK, MessageBoxImage.Hand);

                            return;
                        }
                    }

                    var sql = new HoaDon();

                    sql.MaKhachHang = (from t in BH.DonHangTemps
                                       select t.MaKhacHang).FirstOrDefault();
                    sql.NgayLap  = DateTime.Now;
                    sql.TongTien = Convert.ToDecimal((from h in BLT.DonHangTemps
                                                      select h.ThanhTien).Sum().ToString());

                    sql.DaThanhToan = false;

                    BH.HoaDons.Add(sql);
                    BH.SaveChanges();//lưu thay doi


                    foreach (var i in LaySTT())
                    {
                        using (var BL = new Models.BanLapTopEntities())
                        {
                            var ChiTiet = new ChiTietHoaDon();
                            ChiTiet = LoopData(i);
                            BL.ChiTietHoaDons.Add(ChiTiet);

                            BL.SaveChanges();//lưu thay doi
                            UpdateSoLuongSP(LayMaSp(i));
                        }
                    }

                    BH.Database.ExecuteSqlCommand("TRUNCATE TABLE DonHangTemp");
                    Load();
                    MessageBox.Show("Thanh Toán Thành Công", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    Cart?.Invoke("2");
                }
            }
        }
 private void UserControl_Loaded(object sender, RoutedEventArgs e)
 {
     using (var BH = new Models.BanLapTopEntities())
     {
         var Sour = (from l in BH.ChiTietHoaDons
                     where l.MaDonHang == MaDonHang
                     select l).ToList();
         ListChiTiet.ItemsSource = Sour;
     }
 }
Beispiel #10
0
        void Share(string t)
        {
            ShowView();
            Loged = t;

            BLT = new BanLapTopEntities();

            var User = (from n in BLT.TaiKhoans
                        where n.IdNguoiDung == Loged
                        select n).FirstOrDefault();

            if (User != null)
            {
                txtNameUser.Text = User.HoTen;


                if (txtNameUser.Text.Length > 12)
                {
                    txtNameUser.FontSize = 14;
                }

                byte[] bitImage = User.Avatar;


                if (bitImage != null)
                {
                    eliUser.Fill = new ImageBrush(ToImage(bitImage));
                }
                else
                {
                    eliUser.Fill = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Image/User.png", UriKind.Absolute)));
                }

                if (User.MaLoaiTK == 0)
                {
                    eliUser.ToolTip = "Người dùng";
                }
                else
                {
                    eliUser.ToolTip = "Admin";
                    Admin AD = new Admin();
                    AD.IdAdmin = Loged;
                    Hide();
                    AD.ShowDialog();
                    LogOut();
                    //Load 30 SP trang chu
                    LoadSP();
                    //Load Danh loai sach san pham va nha san xuat

                    DSLSP_DSNSX();
                    Show();
                }
            }
        }
Beispiel #11
0
        private void UpdateSoLuongSP(int MaSP)
        {
            using (var BH = new Models.BanLapTopEntities())
            {
                var sql = BH.SanPhams.Where(m => m.MaSP == MaSP).Single() as SanPham;
                int SLB = SoLuongMua(MaSP);
                sql.SoLuongBan = sql.SoLuongBan + SLB;
                sql.SoLuongTon = sql.SoLuongTon - SLB;

                BH.SaveChanges();//lưu thay doi
            }
        }
Beispiel #12
0
        private void txtTimKiem_KeyDown(object sender, KeyEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(txtTimKiem.Text))
            {
                decimal Gold = 5000000;
                decimal search;
                if (decimal.TryParse(txtTimKiem.Text, out search))
                {
                    using (var BH = new Models.BanLapTopEntities())
                    {
                        var sql = (from timkiem in BH.SanPhams
                                   where timkiem.GiaSP >= search
                                   where timkiem.GiaSP <= search + Gold
                                   where timkiem.ConKinhDoanh != false
                                   select timkiem).ToList().Take(5);

                        ListTimKiemSP.ItemsSource = sql;
                    }
                }
                else
                {
                    using (var BH = new Models.BanLapTopEntities())
                    {
                        var sql = (from timkiem in BH.SanPhams
                                   from tk in BH.LoaiSanPhams
                                   from tk1 in BH.HangSanXuats
                                   where (timkiem.MaLoaiSP == tk.MaLoaiSP && timkiem.MaHangSX == tk1.MaHangSX && timkiem.TenSP.Contains(txtTimKiem.Text)) ||
                                   (timkiem.MaLoaiSP == tk.MaLoaiSP && timkiem.MaHangSX == tk1.MaHangSX && tk.TenLoaiSP.Contains(txtTimKiem.Text)) ||
                                   (timkiem.MaHangSX == tk1.MaHangSX && timkiem.MaLoaiSP == tk.MaLoaiSP && tk1.TenHangSX.Contains(txtTimKiem.Text))
                                   where timkiem.ConKinhDoanh != false
                                   where tk.ConKinhDoanh != false
                                   where tk1.ConKinhDoanh != false
                                   select timkiem).ToList().Take(5);

                        ListTimKiemSP.ItemsSource = sql;
                    }
                }
            }
            else
            {
                ListTimKiemSP.ItemsSource = null;
            }

            if (e.Key == Key.Enter)
            {
                btnSearch_Click(sender, e);
            }
            if (e.Key == Key.Escape)
            {
                txtTimKiem.Clear();
            }
        }
Beispiel #13
0
 void FiterView(int i, int j)
 {
     if (j == 1)
     {
         UserControlView.Children.Clear();
         HidenView();
         hidden1.Width       = 0;
         hidden4.Visibility  = Visibility.Visible;
         hidden4.Width       = Double.NaN;
         ChiTiet.Visibility  = Visibility.Visible;
         ChiTiet.MaSanPham   = i;
         ChiTiet.MaNguoiDung = Loged;
         UserControlView.Children.Add(ChiTiet);
     }
     if (j == 2)
     {
         if (Loged == "")
         {
             MessageBox.Show("Cần đăng nhập để mua sản phẩm", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning);
         }
         else
         {
             int MaSp = i;
             using (var BH = new Models.BanLapTopEntities())
             {
                 if (TonTaiHang(MaSp))
                 {
                     var sql   = BH.DonHangTemps.Where(m => m.MaSP == MaSp).Single() as DonHangTemp;
                     int SLMua = sql.SoLuongMua + 1;
                     sql.SoLuongMua = SLMua;
                     sql.ThanhTien  = sql.ThanhTien + GiaSP(MaSp);
                     BH.SaveChanges();//lưu thay doi
                 }
                 else
                 {
                     var sql = new DonHangTemp();
                     sql.SoLuongMua   = 1;
                     sql.MaDonHang    = MaDonHangNext();
                     sql.MaKhacHang   = Loged;
                     sql.TenKhachHang = NameUser(Loged);
                     sql.MaSP         = MaSp;
                     sql.TenSP        = NameProduct(MaSp);
                     sql.GiaSP        = GiaSP(MaSp);
                     sql.HinhSP       = ImageProduct(MaSp);
                     sql.ThanhTien    = GiaSP(MaSp);
                     BH.DonHangTemps.Add(sql);
                     BH.SaveChanges();//lưu thay doi
                 }
             }
         }
     }
 }
        private int LayMaSP(object sender, RoutedEventArgs e)
        {
            Button  temp       = sender as Button;
            SanPham D          = temp.DataContext as  SanPham;
            int     NumberView = D.LuotXem + 1;
            int     Id         = D.MaSP;

            BLT = new Models.BanLapTopEntities();
            var sql = BLT.SanPhams.Where(m => m.MaSP == Id).FirstOrDefault();

            sql.LuotXem = NumberView;
            BLT.SaveChanges();//lưu thây đổi lượt xem
            return(Id);
        }
Beispiel #15
0
 private void btnxoa_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure ?", "Delete Products", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         int ID = (ListGioHang.SelectedItem as DonHangTemp).STT;
         using (var BH = new Models.BanLapTopEntities())
         {
             var sql = BH.DonHangTemps.Where(m => m.STT == ID).Single() as DonHangTemp;
             BH.DonHangTemps.Remove(sql);
             BH.SaveChanges();
         }
         Load();
     }
 }
Beispiel #16
0
 private void btnChuyenThanhToan_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Xác Nhận ?", "Giao Hàng", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         int ID = (ListGioHang.SelectedItem as HoaDon).MaHoaDon;
         using (var BH = new Models.BanLapTopEntities())
         {
             var sql = BH.HoaDons.Where(m => m.MaHoaDon == ID).Single() as HoaDon;
             sql.DaThanhToan = true;
             BH.SaveChanges();
         }
         Load();
     }
 }
 private void btnxoa_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure ?", "Delete Selected", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
     {
         int ID = (ListGioHang.SelectedItem as SanPham).MaSP;
         using (var BH = new Models.BanLapTopEntities())
         {
             var sql = BH.SanPhams.Where(m => m.MaSP == ID).Single() as SanPham;
             sql.ConKinhDoanh = false;
             BH.SaveChanges();
         }
         Load();
     }
 }
        private bool ConKinhDoanh(int ID)
        {
            using (var BH = new Models.BanLapTopEntities())
            {
                int C = (from i in BH.SanPhams
                         where i.MaHangSX == ID && i.ConKinhDoanh != false
                         select i).Count();

                if (C > 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #19
0
 private bool KiemTraConHang(int MaSP)
 {
     using (var BH = new Models.BanLapTopEntities())
     {
         if ((from i in BH.DonHangTemps
              where i.MaSP == MaSP
              select i.SoLuongMua).SingleOrDefault() > (from i in BH.SanPhams
                                                        where i.MaSP == MaSP
                                                        select i.SoLuongTon).SingleOrDefault())
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #20
0
        private void DSLSP_DSNSX()
        {
            BLT = new BanLapTopEntities();
            var DSLSP = (from h in BLT.LoaiSanPhams
                         where h.ConKinhDoanh != false
                         select h);

            ListDSLSP.ItemsSource = DSLSP.ToList();


            var DSNSX = (from h in BLT.HangSanXuats
                         where h.ConKinhDoanh != false
                         select h);

            ListDSNSX.ItemsSource = DSNSX.ToList();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text == "" || DuongDan == "")
            {
                MessageBox.Show("Chưa Điền Đầy Đủ Thông Tin", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                // string folderpath = System.IO.Directory.GetParent(Environment.CurrentDirectory).Parent.FullName + "\\ContactImages\\";
                string folderpath = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory) + "\\Image\\";
                string FileName   = txtName.Text + "." + LayDuoi(DuongDan);
                if (!Directory.Exists(folderpath))
                {
                    DirectoryInfo di = Directory.CreateDirectory(folderpath);
                    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                }
                string filePath = folderpath + System.IO.Path.GetFileName(FileName);


                var HSX = new HangSanXuat {
                    MaHangSX = LayMaHSX(), TenHangSX = txtName.Text, Logo = @"pack://siteoforigin:,,,/Image\" + FileName
                };
                using (var BanHang = new Models.BanLapTopEntities())
                {
                    BanHang.HangSanXuats.Add(HSX);
                    if (BanHang.SaveChanges() > 0)
                    {
                        if (!File.Exists(filePath))
                        {
                            System.IO.File.Copy(DuongDan, filePath, true);
                        }

                        MessageBox.Show("Success!");

                        Img.Source = null;
                        txtUri.Clear();
                        txtName.Clear();
                        Load();
                    }
                    else
                    {
                        MessageBox.Show("Error Please record");
                    }
                }
            }
        }
Beispiel #22
0
        private void ListGioHang_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            DonHangTemp D = ListGioHang.SelectedItem as DonHangTemp;

            using (var BH = new Models.BanLapTopEntities())
            {
                var sql = BH.DonHangTemps.Where(m => m.MaSP == D.MaSP).Single() as DonHangTemp;
                sql.SoLuongMua = D.SoLuongMua;
                sql.ThanhTien  = D.SoLuongMua * D.GiaSP;
                BH.SaveChanges();//lưu thay doi

                if (KiemTraConHang(D.MaSP) == false)
                {
                    MessageBox.Show("LapTop " + D.TenSP + " Số Tồn Kho < " + D.SoLuongMua + " Cái", "Không Đủ Mặt Hàng", MessageBoxButton.OK, MessageBoxImage.Hand);
                }

                Load();
            }
        }
        private void LoadChiTiet()
        {
            BLT = new Models.BanLapTopEntities();
            var CT = (from h in BLT.SanPhams
                      where h.MaSP == MaSanPham
                      select h);

            DataContext = CT.ToList();

            var SLB = (from h in BLT.SanPhams
                       where h.MaSP == MaSanPham
                       select h.SoLuongBan).SingleOrDefault();

            txtSLB.Text = SLB.ToString();

            var SLX = (from h in BLT.SanPhams
                       where h.MaSP == MaSanPham
                       select h.LuotXem).SingleOrDefault();

            txtSLX.Text = SLX.ToString();


            var LSP = (from h in BLT.LoaiSanPhams
                       from k in BLT.SanPhams
                       where h.MaLoaiSP == k.MaLoaiSP && k.MaSP == MaSanPham
                       select h.TenLoaiSP).SingleOrDefault();

            txtLoaiSP.Text = LSP;

            var Logo = (from h in BLT.HangSanXuats
                        from k in BLT.SanPhams
                        where h.MaHangSX == k.MaHangSX && k.MaSP == MaSanPham
                        select h.Logo).SingleOrDefault();


            BitmapImage bi3 = new BitmapImage();

            bi3.BeginInit();
            bi3.UriSource = new Uri(Logo, UriKind.RelativeOrAbsolute);
            bi3.EndInit();
            ImgHang.Source = bi3;
        }
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (txtAdd.Text.Length <= 5)
     {
         MessageBox.Show("Loại Sản Phẩm Chưa Nhập hoặc không chính xác", "?????", MessageBoxButton.OK, MessageBoxImage.Hand);
     }
     else
     {
         using (var BH = new Models.BanLapTopEntities())
         {
             var sql = new LoaiSanPham();
             sql.MaLoaiSP  = GetMaLoaiSP();
             sql.TenLoaiSP = txtAdd.Text;
             BH.LoaiSanPhams.Add(sql);
             BH.SaveChanges();//lưu thay doi
             txtAdd.Clear();
         }
         Load();
     }
 }
Beispiel #25
0
        void Load()
        {
            using (var BH = new Models.BanLapTopEntities())
            {
                var Sour = (from l in BH.ChiTietHoaDons
                            where l.MaDonHang == MaHoaDon
                            select l).ToList();
                ListChiTiet.ItemsSource = Sour;

                int TSP = (from l in BH.ChiTietHoaDons
                           where l.MaDonHang == MaHoaDon
                           select l.SoLuongMua).Sum();

                txtTSP.Text = TSP.ToString();
                string Okane = (from l in BH.ChiTietHoaDons
                                where l.MaDonHang == MaHoaDon
                                select l.ThanhTien).Sum().ToString();

                txtTong.Text = string.Format("{0:0,0 VNĐ}", double.Parse(Okane));
            }
        }
        private void btnThemSP_Click(object sender, RoutedEventArgs e)
        {
            if (Compelete())
            {
                // string folderpath = System.IO.Directory.GetParent(Environment.CurrentDirectory).Parent.FullName + "\\ContactImages\\";
                string folderpath = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory) + "\\Images\\";
                string FileName   = txtNameSP.Text + "." + LayDuoi(DuongDan);
                if (!Directory.Exists(folderpath))
                {
                    DirectoryInfo di = Directory.CreateDirectory(folderpath);
                    di.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                }
                string filePath = folderpath + System.IO.Path.GetFileName(FileName);

                string MoTaNgan = txtMoTaNgan.Text;
                string CauHinh  = txtCauHinh.Text;
                string ChiTiet  = txtChiTiet.Text;
                var    NewSP    = new SanPham {
                    TenSP = txtNameSP.Text.Trim(), GiaSP = Convert.ToDecimal(txtGiaSP.Text), LuotXem = 0, SoLuongBan = 0, SoLuongTon = (int)udNhapKho.Value, NgayNhapKho = DateTime.Now, MoTaNgan = @MoTaNgan, CauHinh = @CauHinh, MoTa = @ChiTiet, XuatXu = txtXuatSu.Text.Trim(), MaLoaiSP = Convert.ToInt32(cbLoaiSP.SelectedValue), MaHangSX = Convert.ToInt32(cbHangSX.SelectedValue), HinhSP = @"pack://siteoforigin:,,,/Images\" + FileName
                };
                using (var BanHang = new Models.BanLapTopEntities())
                {
                    BanHang.SanPhams.Add(NewSP);
                    if (BanHang.SaveChanges() > 0)
                    {
                        if (!File.Exists(filePath))
                        {
                            System.IO.File.Copy(DuongDan, filePath, true);
                        }

                        MessageBox.Show("Success!");
                        Clears();
                    }
                    else
                    {
                        MessageBox.Show("Error Please record");
                    }
                }
            }
        }
Beispiel #27
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DelTableTemp();
            CaiDat();
            BLT = new BanLapTopEntities();

            txtDate.ToolTip = DateTime.Now.ToLongDateString() + "\n" + DateTime.Now.DayOfWeek;
            DispatcherTimer RunTime = new DispatcherTimer();

            RunTime.Tick    += new EventHandler(RunTime_Clock);
            RunTime.Interval = new TimeSpan(0, 0, 1);
            RunTime.Start();


            //LoadForm Sau 0.1 s
            DispatcherTimer TimeLoad = new DispatcherTimer();

            TimeLoad.Tick    += new EventHandler(TimeLoad_Clock);
            TimeLoad.Interval = new TimeSpan(0, 0, 1);
            TimeLoad.Start();



            //Da từ InfoUser
            info.InfoUser += new ThongTinNguoiDung.PassData(UserInfo_Share);


            //Gửi Data Login
            login.share         += new DangNhap.PassData(Share);
            login._Registration += new DangNhap.PassData(IsRegis);

            //Gửi Data Regist
            Regist.Share += new DangKy.PassData(IsLogin);

            //Load 30 SP trang chu
            LoadSP();
            //Load Danh loai sach san pham va nha san xuat

            DSLSP_DSNSX();
        }
Beispiel #28
0
 private void Mua_Click(object sender, RoutedEventArgs e)
 {
     if (Loged == "")
     {
         MessageBox.Show("Cần đăng nhập để mua sản phẩm", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
     else
     {
         Button  temp = sender as Button;
         SanPham D    = temp.DataContext as SanPham;
         int     MaSp = D.MaSP;
         using (var BH = new Models.BanLapTopEntities())
         {
             if (TonTaiHang(MaSp))
             {
                 var sql   = BH.DonHangTemps.Where(m => m.MaSP == MaSp).Single() as DonHangTemp;
                 int SLMua = sql.SoLuongMua + 1;
                 sql.SoLuongMua = SLMua;
                 sql.ThanhTien  = sql.ThanhTien + GiaSP(MaSp);
                 BH.SaveChanges();//lưu thay doi
             }
             else
             {
                 var sql = new DonHangTemp();
                 sql.SoLuongMua   = 1;
                 sql.MaDonHang    = MaDonHangNext();
                 sql.MaKhacHang   = Loged;
                 sql.TenKhachHang = NameUser(Loged);
                 sql.MaSP         = MaSp;
                 sql.TenSP        = NameProduct(MaSp);
                 sql.GiaSP        = GiaSP(MaSp);
                 sql.HinhSP       = ImageProduct(MaSp);
                 sql.ThanhTien    = GiaSP(MaSp);
                 BH.DonHangTemps.Add(sql);
                 BH.SaveChanges();//lưu thay doi
             }
         }
     }
 }
 private void btnBuy_Click(object sender, RoutedEventArgs e)
 {
     if (MaNguoiDung == "")
     {
         MessageBox.Show("Cần đăng nhập để mua sản phẩm", "Thông báo", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
     else
     {
         int SLM  = Convert.ToInt32(txtSL.Value);
         int MaSp = MaSanPham;
         using (var BH = new Models.BanLapTopEntities())
         {
             if (TonTaiHang(MaSp))
             {
                 var sql   = BH.DonHangTemps.Where(m => m.MaSP == MaSp).Single() as DonHangTemp;
                 int SLMua = sql.SoLuongMua + SLM;
                 sql.SoLuongMua = SLMua;
                 sql.ThanhTien  = sql.ThanhTien + (GiaSP(MaSp) * SLM);
                 BH.SaveChanges();//lưu thay doi
             }
             else
             {
                 var sql = new DonHangTemp();
                 sql.SoLuongMua   = SLM;
                 sql.MaDonHang    = MaDonHangNext();
                 sql.MaKhacHang   = MaNguoiDung;
                 sql.TenKhachHang = NameUser(MaNguoiDung);
                 sql.MaSP         = MaSp;
                 sql.TenSP        = NameProduct(MaSp);
                 sql.HinhSP       = ImageProduct(MaSp);
                 sql.GiaSP        = GiaSP(MaSp);
                 sql.ThanhTien    = GiaSP(MaSp);
                 BH.DonHangTemps.Add(sql);
                 BH.SaveChanges();//lưu thay doi
             }
         }
     }
 }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            BLT = new BanLapTopEntities();

            LoadChiTiet();

            ReplateView();
            LoadSanPham();
            expan1.IsExpanded = false;
            expan2.IsExpanded = false;
            expan3.IsExpanded = false;

            RunTime = new DispatcherTimer();

            RunTime.Tick    += new EventHandler(TimeLoad_Clock);
            RunTime.Interval = new TimeSpan(0, 0, 1);
            RunTime.Start();

            RunTime1          = new DispatcherTimer();
            RunTime1.Tick    += new EventHandler(TimeLoad1_Clock);
            RunTime1.Interval = new TimeSpan(0, 0, 0);
            RunTime1.Start();
        }