public static void Update(Model.NHACUNGCAP item, string id) { Model.NHACUNGCAP getdt = Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.ma_nhacungcap == id).SingleOrDefault(); getdt.ten_nhacungcap = item.ten_nhacungcap; getdt.sodienthoai = item.sodienthoai; getdt.diachi = item.diachi; Model.DataProvider.Ins.DB.SaveChanges(); }
public static void Insert(Model.NHACUNGCAP item) { Model.DataProvider.Ins.DB.NHACUNGCAPs.Add(item); Model.DataProvider.Ins.DB.SaveChanges(); }
public static void Delete(Model.NHACUNGCAP item) { Model.DataProvider.Ins.DB.NHACUNGCAPs.Remove(item); }
public Nhacungcap_ViewModel() { List = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false)); DeleteList = new ObservableCollection <Model.NHACUNGCAP>(); Active = false; IsOpen = false; Active_Command = new RelayCommand <object>(p => { if (Active == false) { return(false); } return(true); }, p => { Active = false; }); CloseDialog_Command = new RelayCommand <object>(p => { return(true); }, p => { IsOpen = false; }); Load_Command = new RelayCommand <object>(p => { return(true); }, p => { List = new ObservableCollection <Model.NHACUNGCAP>(Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.IsDeleted == false)); DeleteList = new ObservableCollection <Model.NHACUNGCAP>(); Active = false; IsOpen = false; }); #region Phan them Insert_Command = new RelayCommand <object>(p => { if (string.IsNullOrEmpty(Tennhacungcap) || string.IsNullOrEmpty(Sodienthoai) || string.IsNullOrEmpty(Diachi)) { return(false); } int i = 0; if (!Int32.TryParse(Sodienthoai, out i)) { return(false); } var check = Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.ten_nhacungcap == Tennhacungcap); if (check == null || check.Count() != 0) { return(false); } return(true); }, p => { SelectedItem = null; Model.NHACUNGCAP newItem = new Model.NHACUNGCAP() { ma_nhacungcap = Guid.NewGuid().ToString(), ten_nhacungcap = Tennhacungcap, diachi = Diachi, sodienthoai = Sodienthoai, IsDeleted = false }; Model.Nhacungcap_Service.Insert(newItem); List.Insert(0, newItem); SelectedItem = newItem; Active = true; Message = "Thêm mới thành công !!!"; }); #endregion #region Phan sua Update_Command = new RelayCommand <object>(p => { if (SelectedItem == null) { return(false); } int i = 0; if (!Int32.TryParse(Sodienthoai, out i)) { return(false); } if (string.IsNullOrEmpty(Tennhacungcap) || string.IsNullOrEmpty(Sodienthoai) || string.IsNullOrEmpty(Diachi)) { return(false); } var check = Model.DataProvider.Ins.DB.NHACUNGCAPs.Where(x => x.ten_nhacungcap == Tennhacungcap && x.diachi == Diachi && x.sodienthoai == Sodienthoai); if (check == null || check.Count() != 0) { return(false); } return(true); }, p => { Model.NHACUNGCAP UpdateItem = new Model.NHACUNGCAP() { ten_nhacungcap = Tennhacungcap, sodienthoai = Sodienthoai, diachi = Diachi }; Model.Nhacungcap_Service.Update(UpdateItem, Manhacungcap); for (int i = 0; i < List.Count(); i++) { if (List[i] == SelectedItem) { List[i] = new Model.NHACUNGCAP() { ma_nhacungcap = Manhacungcap, ten_nhacungcap = Tennhacungcap, diachi = Diachi, sodienthoai = Sodienthoai }; break; } } //MessageBox.Show("Chỉnh sửa thành công", "THÔNG BÁO"); SelectedItem = null; Tennhacungcap = ""; Sodienthoai = ""; Diachi = ""; Active = true; Message = "Chỉnh sửa thành công !!!"; }); #endregion #region Phan xoa DeleteShow_Command = new RelayCommand <object>(p => { if (DeleteList.Count() == 0) { return(false); } return(true); }, p => { IsOpen = true; Content = " Xóa các bản ghi được chọn ???"; }); AddDeleteList_Command = new RelayCommand <CheckBox>(p => { return(true); }, p => { DeleteList.Add(List.Where(x => x.ma_nhacungcap == p.Uid.ToString()).SingleOrDefault()); }); RemoveDeleteList_Command = new RelayCommand <CheckBox>(p => { return(true); }, p => { DeleteList.Remove(List.Where(x => x.ma_nhacungcap == p.Uid.ToString()).SingleOrDefault()); }); Delete_Command = new RelayCommand <object>(p => { if (DeleteList.Count() == 0) { return(false); } return(true); }, p => { RemoveIteminDb(); RemoveIteminList(); DeleteList = new ObservableCollection <Model.NHACUNGCAP>(); IsOpen = false; SelectedItem = null; }); #endregion #region Tao moi Reset_Command = new RelayCommand <object>(p => { return(true); }, p => { SelectedItem = null; Tennhacungcap = ""; Diachi = ""; Sodienthoai = ""; }); #endregion #region Phan sap xep Sort_Command = new RelayCommand <object>(p => { if (List.Count() == 0) { return(false); } return(true); }, p => { ObservableCollection <Model.NHACUNGCAP> chkList = new ObservableCollection <Model.NHACUNGCAP>(List.OrderByDescending(x => x.ten_nhacungcap)); if (List[0] == chkList[0]) { List = new ObservableCollection <Model.NHACUNGCAP>(List.OrderBy(x => x.ten_nhacungcap)); } else { List = new ObservableCollection <Model.NHACUNGCAP>(chkList); } }); SortbyDiachi_Command = new RelayCommand <object>(p => { if (List.Count() == 0) { return(false); } return(true); }, p => { ObservableCollection <Model.NHACUNGCAP> chkList = new ObservableCollection <Model.NHACUNGCAP>(List.OrderByDescending(x => x.diachi)); if (List[0] == chkList[0]) { List = new ObservableCollection <Model.NHACUNGCAP>(List.OrderBy(x => x.diachi)); } else { List = new ObservableCollection <Model.NHACUNGCAP>(chkList); } }); #endregion }