void Create(int n) { bool flag = false; switch (n) { case 0: BillWindow bw = new BillWindow(db); flag = bw.ShowDialog(); break; case 1: EntryWindow ew = new EntryWindow(db); flag = ew.ShowDialog(); break; case 2: ProductWindow pw = new ProductWindow(db); flag = pw.ShowDialog(); break; case 3: ServiceWindow sw = new ServiceWindow(db); flag = sw.ShowDialog(); break; case 4: ClientWindow cw = new ClientWindow(db); flag = cw.ShowDialog(); break; case 5: CarWashWindow cww = new CarWashWindow(db); flag = cww.ShowDialog(); break; } if (flag) { Refresh(n); } }
public MainViewModel() { //Login LoadedViewConmand = new RelayCommand <Window>((p) => { return(true); }, (p) => { IsLoaded = true; if (p == null) { return; } p.Hide(); LoginWindow loginWindow = new LoginWindow(); loginWindow.ShowDialog(); if (loginWindow.DataContext == null) { return; } var loginVM = loginWindow.DataContext as LoginViewModel; if (loginVM.IsLogin) { p.Show(); } else { p.Close(); } }); //Benh Nhan comboGioiTinh = new ObservableCollection <String>(); comboGioiTinh.Add("Nam"); comboGioiTinh.Add("Nữ"); ListBenhNhan = new ObservableCollection <BenhNhan>(DataProvider.Ins.DB.BenhNhans); AddCommandBenhNhan = new RelayCommand <object>((p) => { if (HoVaTen == null || GioiTinh == null || NamSinh < 0 || NamSinh == 0 || DiaChi == null) { return(false); } return(true); }, (p) => { var Patient = new BenhNhan() { HoVaTen = HoVaTen, GioiTinh = GioiTinh, NamSinh = NamSinh, DiaChi = DiaChi }; DataProvider.Ins.DB.BenhNhans.Add(Patient); DataProvider.Ins.DB.SaveChanges(); ListBenhNhan = new ObservableCollection <BenhNhan>(DataProvider.Ins.DB.BenhNhans); }); EditCommandBenhNhan = new RelayCommand <object>((p) => { if (SelectedItemBenhNhan == null) { return(false); } var IdList = DataProvider.Ins.DB.BenhNhans.Where(x => x.MaBN == SelectedItemBenhNhan.MaBN); if (IdList != null || IdList.Count() != 0) { return(true); } return(false); }, (p) => { var Patient = DataProvider.Ins.DB.BenhNhans.Where(x => x.MaBN == SelectedItemBenhNhan.MaBN).SingleOrDefault(); Patient.HoVaTen = HoVaTen; Patient.GioiTinh = GioiTinh; Patient.NamSinh = NamSinh; Patient.DiaChi = DiaChi; DataProvider.Ins.DB.SaveChanges(); ListBenhNhan = new ObservableCollection <BenhNhan>(DataProvider.Ins.DB.BenhNhans); }); closeCommandBenhNhan = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { p.Text = ""; }); IsOnCommandBenhNhan = new RelayCommand <Button>((p) => { return(IsOnBenhNhan); }, (p) => { }); TextChangedCommandBenhNhan = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { _TimHoVaTen = p.Text; if (_TimHoVaTen == "") { ListBenhNhan = new ObservableCollection <BenhNhan>(DataProvider.Ins.DB.BenhNhans); IsOnBenhNhan = false; } else { IsOnBenhNhan = true; string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Search by Keyword]", conn); command.Parameters.Add("@keyword", SqlDbType.VarChar).Value = _TimHoVaTen; command.CommandType = CommandType.StoredProcedure; SqlDataAdapter adp = new SqlDataAdapter(command); DataTable dt = new DataTable(); adp.Fill(dt); if (dt.Rows.Count > 0) { ListBenhNhan = new ObservableCollection <BenhNhan>(ConvertToBenhNhan(dt)); } else { ListBenhNhan = new ObservableCollection <BenhNhan>(DataProvider.Ins.DB.BenhNhans.Where((x) => x.HoVaTen.StartsWith(_TimHoVaTen))); } } } }); ResetCommandBenhNhan = new RelayCommand <object>((p) => { return(true); }, (p) => { HoVaTen = null; GioiTinh = null; NamSinh = 0; DiaChi = null; SelectedItemBenhNhan = null; }); DeleteCommandBenhNhan = new RelayCommand <object>((p) => { if (SelectedItemBenhNhan == null) { return(false); } var IdList = DataProvider.Ins.DB.BenhNhans.Where(x => x.MaBN == SelectedItemBenhNhan.MaBN); if (IdList != null || IdList.Count() != 0) { return(true); } return(false); }, p => { string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Delete BenhNhan]", conn); command.Parameters.Add("@key", SqlDbType.Int).Value = SelectedItemBenhNhan.MaBN; command.CommandType = CommandType.StoredProcedure; command.ExecuteNonQuery(); ListBenhNhan = new ObservableCollection <BenhNhan>(DataProvider.Ins.DB.BenhNhans); } }); LapPhieuKhamBenhCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { MaBN = SelectedItemBenhNhan.MaBN; PhieuKhamBenh PhieuKhamBenhwindown = new PhieuKhamBenh(); PhieuKhamBenhwindown.ShowDialog(); }); ThanhToanCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { MaBN = SelectedItemBenhNhan.MaBN; BillWindow ThanhToanwindow = new BillWindow(); ThanhToanwindow.ShowDialog(); }); //Thuốc comboDonVi = new ObservableCollection <String>(); comboDonVi.Add("Viên"); comboDonVi.Add("Chai"); ListThuoc = new ObservableCollection <Thuoc>(DataProvider.Ins.DB.Thuocs); AddCommandThuoc = new RelayCommand <object>((p) => { if (TenThuoc == null) { return(false); } if (DonVi == null) { return(false); } if (DonGia < 0) { return(false); } return(true); }, (p) => { var Drug = new Thuoc() { TenThuoc = TenThuoc, DonVi = DonVi, DonGia = DonGia }; DataProvider.Ins.DB.Thuocs.Add(Drug); DataProvider.Ins.DB.SaveChanges(); ListThuoc = new ObservableCollection <Thuoc>(DataProvider.Ins.DB.Thuocs); }); EditCommandThuoc = new RelayCommand <object>((p) => { if (SelectedItemThuoc == null) { return(false); } var IdList = DataProvider.Ins.DB.Thuocs.Where(x => x.MaThuoc == SelectedItemThuoc.MaThuoc); if (IdList != null || IdList.Count() != 0) { return(true); } return(false); }, (p) => { var Drug = DataProvider.Ins.DB.Thuocs.Where(x => x.MaThuoc == SelectedItemThuoc.MaThuoc).SingleOrDefault(); Drug.TenThuoc = TenThuoc; Drug.DonVi = DonVi; Drug.DonGia = DonGia; DataProvider.Ins.DB.SaveChanges(); ListThuoc = new ObservableCollection <Thuoc>(DataProvider.Ins.DB.Thuocs); }); closeCommandThuoc = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { p.Text = ""; }); IsOnCommandThuoc = new RelayCommand <Button>((p) => { return(IsOnThuoc); }, (p) => { }); TextChangedCommandThuoc = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { _TimTenThuoc = p.Text; if (_TimTenThuoc == "") { ListThuoc = new ObservableCollection <Thuoc>(DataProvider.Ins.DB.Thuocs); IsOnThuoc = false; } else { IsOnThuoc = true; string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Search by Keyword Drug]", conn); command.Parameters.Add("@keyword", SqlDbType.VarChar).Value = _TimTenThuoc; command.CommandType = CommandType.StoredProcedure; SqlDataAdapter adp = new SqlDataAdapter(command); DataTable dt = new DataTable(); adp.Fill(dt); if (dt.Rows.Count > 0) { ListThuoc = new ObservableCollection <Thuoc>(ConvertToThuoc(dt)); } else { ListThuoc = new ObservableCollection <Thuoc>(DataProvider.Ins.DB.Thuocs.Where((x) => x.TenThuoc.StartsWith(_TimTenThuoc))); } } } }); ResetCommandThuoc = new RelayCommand <object>((p) => { return(true); }, (p) => { TenThuoc = null; DonVi = null; DonGia = 0; SelectedItemThuoc = null; }); DeleteCommandThuoc = new RelayCommand <object>((p) => { if (SelectedItemThuoc == null) { return(false); } var IdList = DataProvider.Ins.DB.Thuocs.Where(x => x.MaThuoc == SelectedItemThuoc.MaThuoc); if (IdList != null || IdList.Count() != 0) { return(true); } return(false); }, p => { string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Delete Thuoc]", conn); command.Parameters.Add("@key", SqlDbType.Int).Value = SelectedItemThuoc.MaThuoc; command.CommandType = CommandType.StoredProcedure; command.ExecuteNonQuery(); ListThuoc = new ObservableCollection <Thuoc>(DataProvider.Ins.DB.Thuocs); } }); //Báo Cáo Doanh Thu ClickFindCommandBaoCaoDoanhThu = new RelayCommand <ListView>((p) => { return(true); }, (p) => { string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Sales by Month]", conn); command.Parameters.Add("@month", SqlDbType.Int).Value = _ThangDoanhThu + 1; command.CommandType = CommandType.StoredProcedure; SqlDataAdapter ad = new SqlDataAdapter(command); DataTable dt = new DataTable(); ad.Fill(dt); allData = dt.DefaultView; } }); IsOnClickDoanhThu = new RelayCommand <object>((p) => { return(onClickDoanhThu); }, (p) => { }); SelectionChangedCommandBaoCaoDoanhThu = new RelayCommand <ComboBox>((p) => { return(true); }, (p) => { onClickDoanhThu = true; _ThangDoanhThu = p.SelectedIndex; }); // Báo Cáo Thuốc ClickFindCommandBaoCaoSDThuoc = new RelayCommand <ListView>((p) => { return(true); }, (p) => { string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Sales by Month Drug]", conn); command.Parameters.Add("@moth", SqlDbType.Int).Value = _ThangSDThuoc + 1; command.CommandType = CommandType.StoredProcedure; SqlDataAdapter ad = new SqlDataAdapter(command); DataTable dt = new DataTable(); ad.Fill(dt); allDataSDThuoc = dt.DefaultView; } }); IsOnClickSDThuoc = new RelayCommand <object>((p) => { return(onClickSDThuoc); }, (p) => { }); SelectionChangedCommandBaoCaoSDThuoc = new RelayCommand <ComboBox>((p) => { return(true); }, (p) => { onClickSDThuoc = true; _ThangSDThuoc = p.SelectedIndex; }); //Tài Khoản ListTaiKhoan = new ObservableCollection <TaiKhoan>(DataProvider.Ins.DB.TaiKhoans); AddCommandTaiKhoan = new RelayCommand <object>((p) => { if (username == null) { return(false); } if (password == null) { return(false); } return(true); }, (p) => { var account = new TaiKhoan() { username = username, tenhienthi = tenhienthi, password = password, TYPE = 2 }; DataProvider.Ins.DB.TaiKhoans.Add(account); DataProvider.Ins.DB.SaveChanges(); ListTaiKhoan = new ObservableCollection <TaiKhoan>(DataProvider.Ins.DB.TaiKhoans); }); EditCommandTaiKhoan = new RelayCommand <object>((p) => { if (SelectedItemTaiKhoan == null) { return(false); } var IdList = DataProvider.Ins.DB.TaiKhoans.Where(x => x.username == SelectedItemTaiKhoan.username); if (IdList != null || IdList.Count() != 0) { return(true); } return(false); }, (p) => { var account = DataProvider.Ins.DB.TaiKhoans.Where(x => x.username == SelectedItemTaiKhoan.username).SingleOrDefault(); account.username = username; account.password = password; DataProvider.Ins.DB.SaveChanges(); ListTaiKhoan = new ObservableCollection <TaiKhoan>(DataProvider.Ins.DB.TaiKhoans); }); closeCommandTaiKhoan = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { p.Text = ""; }); IsOnCommandTaiKhoan = new RelayCommand <Button>((p) => { return(IsOnTaiKhoan); }, (p) => { }); TextChangedCommandTaiKhoan = new RelayCommand <TextBox>((p) => { return(true); }, (p) => { _TimTenTaiKhoan = p.Text; if (_TimTenTaiKhoan == "") { ListTaiKhoan = new ObservableCollection <TaiKhoan>(DataProvider.Ins.DB.TaiKhoans); IsOnTaiKhoan = false; } else { IsOnTaiKhoan = true; string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Search by Keyword Account]", conn); command.Parameters.Add("@keyword", SqlDbType.VarChar).Value = _TimTenTaiKhoan; command.CommandType = CommandType.StoredProcedure; SqlDataAdapter adp = new SqlDataAdapter(command); DataTable dt = new DataTable(); adp.Fill(dt); if (dt.Rows.Count > 0) { ListTaiKhoan = new ObservableCollection <TaiKhoan>(ConvertToTaiKhoan(dt)); } else { ListTaiKhoan = new ObservableCollection <TaiKhoan>(DataProvider.Ins.DB.TaiKhoans.Where((x) => x.username.StartsWith(_TimTenTaiKhoan))); } } } }); ResetCommandTaiKhoan = new RelayCommand <object>((p) => { return(true); }, (p) => { username = null; password = null; SelectedItemTaiKhoan = null; }); DeleteCommandTaiKhoan = new RelayCommand <object>((p) => { if (SelectedItemTaiKhoan == null) { return(false); } var IdList = DataProvider.Ins.DB.TaiKhoans.Where(x => x.username == SelectedItemTaiKhoan.username); if (IdList != null || IdList.Count() != 0) { return(true); } return(false); }, p => { string ConnStr = "Data Source=(local);Initial Catalog=QLPM4;Integrated Security=true;"; using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnStr; conn.Open(); SqlCommand command = new SqlCommand("[Delete TaiKhoan]", conn); command.Parameters.Add("@key", SqlDbType.VarChar).Value = SelectedItemTaiKhoan.username; command.CommandType = CommandType.StoredProcedure; command.ExecuteNonQuery(); ListTaiKhoan = new ObservableCollection <TaiKhoan>(DataProvider.Ins.DB.TaiKhoans); } }); //Thay đổi mật khẩu ThayDoiThongTin = new RelayCommand <object>((p) => { return(true); }, (p) => { var Account = DataProvider.Ins.DB.TaiKhoans.Where(x => x.username == LoginViewModel._usename).SingleOrDefault(); Account.password = MatKhauThayDoi.ToString(); Account.tenhienthi = TenThayDoi.ToString(); DataProvider.Ins.DB.SaveChanges(); MessageBox.Show("Mật khẩu thay đổi thành công!", "Thông Báo", MessageBoxButton.OK, MessageBoxImage.Asterisk); }); }
// các xử lí của mainviewmodel public MainViewModel() { // ẩn mainWindow trước khi thực hiện đăng nhập - sử dụng truyền parameter p_Window LoadedWindowCommand = new RelayCommand <Window>((p_Window) => { return(true); }, (p_Window) => { if (p_Window == null) { return; } else { p_Window.Hide(); Isloaded = true; LoginWindow loginWindow = new LoginWindow(); loginWindow.ShowDialog(); // dùng datacontext để lấy biến islogin bên LoginViewModel if (loginWindow.DataContext == null) { return; } var login = loginWindow.DataContext as LoginViewModel; if (login.IsLogin == true) { p_Window.Show(); } else { p_Window.Close(); } } }); // các comment SellCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { SellWindow wd = new SellWindow(); wd.ShowDialog(); }); BillCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { BillWindow wd = new BillWindow(); wd.ShowDialog(); }); RegisterCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { RegisterWindow wd = new RegisterWindow(); wd.ShowDialog(); }); // những chức năng chỉ người chủ mới được thực hiện StatisticCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { StatisticWindow wd = new StatisticWindow(); wd.ShowDialog(); }); InputCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { InputWindow wd = new InputWindow(); wd.ShowDialog(); }); ShopCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { ShopWindow wd = new ShopWindow(); wd.ShowDialog(); }); QTVCommand = new RelayCommand <object>((p_Window) => { return(true); }, (p_Window) => { QTVWindow wd = new QTVWindow(); wd.ShowDialog(); }); }
public MainViewModel() { LoadedWindowCommand = new RelayCommand <Window>((p) => { return(true); }, (p) => { Isloaded = true; if (p == null) { return; } p.Hide(); LoginWindow loginWindow = new LoginWindow(); loginWindow.ShowDialog(); if (loginWindow.DataContext == null) { return; } var loginVM = loginWindow.DataContext as LoginViewModel; if (loginVM.IsLogin) { p.Show(); } else { p.Close(); } } ); LogoutCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { System.Windows.Application.Current.Shutdown(); }); ProductCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { ProductDetailPage wd = new ProductDetailPage(); wd.ShowDialog(); }); SettingsCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { SettingsWindow wd = new SettingsWindow(); wd.ShowDialog(); }); EmployeeCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { NhanVienWindow wd = new NhanVienWindow(); wd.ShowDialog(); }); KhuyenMaiCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { KhuyenMaiWindow wd = new KhuyenMaiWindow(); wd.ShowDialog(); }); StoreCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { StoreWindow wd = new StoreWindow(); wd.ShowDialog(); }); KhachHangCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { KhachHangWindow wd = new KhachHangWindow(); wd.ShowDialog(); }); ProducerCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { NSXWindow wd = new NSXWindow(); wd.ShowDialog(); }); OrderCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { BillWindow wd = new BillWindow(); wd.ShowDialog(); }); }
public MainViewModel() { ImportWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } ImportWindow wd = new ImportWindow(); wd.ShowDialog(); }); SellWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { SellWindow wd = new SellWindow(); wd.ShowDialog(); }); CustomerWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } CustomerWindow wd = new CustomerWindow(); wd.ShowDialog(); }); ProductWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } ProductWindow wd = new ProductWindow(); wd.ShowDialog(); }); SupplierWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } SupplierWindow wd = new SupplierWindow(); wd.ShowDialog(); }); StatisticalWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } StatisticalWindow wd = new StatisticalWindow(); wd.ShowDialog(); }); UnitWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } UnitWindow wd = new UnitWindow(); wd.ShowDialog(); }); UserListWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } UserListWindow wd = new UserListWindow(); wd.ShowDialog(); }); AccountCreateWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } AccountCreateWindow wd = new AccountCreateWindow(); wd.ShowDialog(); }); BillWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (_UserIDRole != 1) { LoadDialogErrorNotPermission(); return; } BillWindow wd = new BillWindow(); wd.ShowDialog(); }); LoadMainWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { if (!isLoaded) { isLoaded = true; if (p == null) { return; } p.Hide(); LoginWindow wd = new LoginWindow(); wd.ShowDialog(); var loginViewModel = wd.DataContext as LoginViewModel; if (loginViewModel == null) { return; } if (loginViewModel.isLogin) { loadUserCurrentLogin(); p.Show(); } else { p.Close(); } } }); LoadEditCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { LoadDialogAccountEdit(); }); }
public SellViewModel() { loadUserCurrentLogin(); TotalPrice = 0; IsEnableName = false; List = new List <ProductTable>(DataProvider.Ins.Entities.ProductTable); ListSupplier = new List <SupplierTable>(DataProvider.Ins.Entities.SupplierTable); ListUnit = new List <UnitTable>(DataProvider.Ins.Entities.UnitTable); ListBill = new List <BillModel>(); _ListTemp = new List <BillModel>(); LoadEditCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { LoadDialogAccountEdit(); }); AddBillCommand = new RelayCommand <object>((p) => { if (SelectedItems == null) { return(false); } SelectedItemsBill = null; return(true); }, (p) => { BillModel bill = new BillModel(); ProductTable billProduct = new ProductTable(); billProduct.ID = SelectedItems.ID; billProduct.DisplayName = SelectedItems.DisplayName; billProduct.SupplierTable = SelectedItems.SupplierTable; billProduct.UnitTable = SelectedItems.UnitTable; int Price = 0; var listPrice = DataProvider.Ins.Entities.ProductTable.Where(x => x.ID == SelectedItems.ID).Select(x => x.Price); foreach (var item in listPrice) { Price = item; } bill.product = billProduct; bill.Price = Price; bill.Amount = 1; bill.PriceItems = Price; bill.AmountChange = AmountChange; if (LoadInventory(bill.product.ID) <= 0) { LoadDialogError("Sản Phẩm Không Còn Trong Kho! Vui Lòng Liên Hệ Quản Trị Viên!"); return; } TotalPrice += Price; var listCheckDuplicate = _ListTemp.Where(x => x.product.ID == bill.product.ID); if (listCheckDuplicate.Count() != 0) { int DuplicateProduct = _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().Amount; _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().Amount = DuplicateProduct + 1; _ListTemp.Where(x => x.product.ID == bill.product.ID).FirstOrDefault().PriceItems += Price; ListBill = new List <BillModel>(_ListTemp); SelectedItems = null; return; } _ListTemp.Add(bill); ListBill = new List <BillModel>(_ListTemp); SelectedItems = null; }); DeleteItemInBill = new RelayCommand <object>((p) => { if (SelectedItemsBill == null) { return(false); } SelectedItems = null; return(true); }, (p) => { var FindToDelete = _ListTemp.Where(x => x.product.ID == SelectedItemsBill.product.ID).FirstOrDefault(); TotalPrice -= FindToDelete.PriceItems; _ListTemp.Remove(FindToDelete); ListBill = new List <BillModel>(_ListTemp); SelectedItemsBill = null; }); AmountChange = new RelayCommand <object>((p) => { return(true); }, (p) => { try { var FindToEdit = _ListTemp.Where(x => x.product.ID == SelectedItemsBill.product.ID).FirstOrDefault(); TotalPrice -= FindToEdit.PriceItems; FindToEdit.Amount = SelectedItemsBill.Amount; FindToEdit.PriceItems = FindToEdit.Amount * FindToEdit.Price; TotalPrice += FindToEdit.PriceItems; ListBill = new List <BillModel>(_ListTemp); } catch { MessageBox.Show(Message); } }); PhoneCustomerChange = new RelayCommand <object>((p) => { if (PhoneCustomer.ToString().Length < 9) { return(false); } return(true); }, (p) => { var Customer = DataProvider.Ins.Entities.CustomerTable.Where(x => x.Phone.ToLower().Contains(PhoneCustomer.ToString())).FirstOrDefault(); if (Customer != null) { NameCustomer = Customer.FullName; IsEnableName = false; return; } NameCustomer = ""; IsEnableName = true; }); CreateBill = new RelayCommand <object>((p) => { if (TotalPrice <= 0 || NameCustomer == null || PhoneCustomer.ToString().Length < 9) { return(false); } return(true); }, (p) => { foreach (var item in _ListTemp) { if (LoadInventory(item.product.ID) - item.Amount < 0) { LoadDialogError("Số Lượng Sản Phẩm Không Đủ Đáp Ứng Nhu Cầu!"); return; } } if (IsEnableName) { CustomerTable customer = new CustomerTable(); customer.FullName = NameCustomer; customer.Phone = "0" + PhoneCustomer.ToString(); customer.Address = ""; DataProvider.Ins.Entities.CustomerTable.Add(customer); DataProvider.Ins.Entities.SaveChanges(); } var ID_Customer = DataProvider.Ins.Entities.CustomerTable.Where(x => x.Phone.ToLower().Contains(PhoneCustomer.ToString())).FirstOrDefault(); OutputTable output = new OutputTable(); output.ID_User = (int)App.Current.Properties["UserID"]; output.DateOutput = DateTime.Now; output.ID_Customer = ID_Customer.ID; DataProvider.Ins.Entities.OutputTable.Add(output); DataProvider.Ins.Entities.SaveChanges(); var ID_Output = DataProvider.Ins.Entities.OutputTable.Where(x => x.ID_User == output.ID_User && x.ID_Customer == output.ID_Customer && x.DateOutput == output.DateOutput.Date).FirstOrDefault(); int ID = ID_Output.ID; OutPutDetailTable outPutDetail = new OutPutDetailTable(); foreach (var item in _ListTemp) { outPutDetail.Count = item.Amount; outPutDetail.ID_Product = item.product.ID; outPutDetail.ID_Output = ID; outPutDetail.Price = item.Price; outPutDetail.TotalPrice = item.PriceItems; DataProvider.Ins.Entities.OutPutDetailTable.Add(outPutDetail); DataProvider.Ins.Entities.SaveChanges(); } LoadDialogSuccessSale(); TotalPrice = 0; _ListBill = null; ListBill = null; NameCustomer = null; PhoneCustomer = 0; IsEnableName = false; }); DestroyCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { TotalPrice = 0; ListBill = null; _ListBill = null; NameCustomer = null; PhoneCustomer = 0; IsEnableName = false; LoadDialogDeleted(); }); SearchCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { if (SearchTerm == null) { return; } List = new List <ProductTable>(DataProvider.Ins.Entities.ProductTable.Where( x => x.DisplayName.ToLower().Contains(SearchTerm) || x.SupplierTable.DisplayName.ToLower().Contains(SearchTerm) || x.UnitTable.Descriptions.ToLower().Contains(SearchTerm))); }); OpenBillWindow = new RelayCommand <Window>((p) => { return(true); }, (p) => { p.Close(); BillWindow wd = new BillWindow(); wd.ShowDialog(); }); }
// mọi thứ xử lý sẽ nằm trong này public MainViewModel() { LoadedWindowCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { Isloaded = true; LoginWindow loginWindow = new LoginWindow(); loginWindow.ShowDialog(); }); StaffCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { StaffWindow wd = new StaffWindow(); wd.ShowDialog(); }); FoodCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { FoodWindow wd = new FoodWindow(); wd.ShowDialog(); }); BillCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { BillWindow wd = new BillWindow(); wd.ShowDialog(); }); FoodTypeCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { FoodTypeWindow wd = new FoodTypeWindow(); wd.ShowDialog(); }); }