private void SaveAction(object obj) { if (this.status == ChangeStatus.New) { var item = this; item.ProducentName = ProducentSelected.Name; var coll = new ComputerCollections(); var res = coll.Add(item); if (res > 0) { item.Id = res; MessageBox.Show("Data Berhasil Disimpan"); this.source.Add(item); this.sourceView.Refresh(); this.selectedItem = item; WindowClose(); } else { MessageBox.Show("Data Gagal Disimpan"); } } else if (this.status == ChangeStatus.Edit) { var item = this; item.ProducentName = ProducentSelected.Name; var coll = new ComputerCollections(); var isUpdated = coll.Update(item); if (isUpdated) { MessageBox.Show("Data Berhasil Disimpan"); this.sourceView.Refresh(); this.selectedItem = item; } else { MessageBox.Show("Data Gagal Disimpan"); } } }
private void SearchAction(object obj) { if (this.SelectedItem != null) { this.SelectedItem = null; } this.Source.Clear(); this.Alternatives = new List <Alternatif>(); IDataCollection <computer> pr = new ComputerCollections(); var datas = pr.GetData(); ICollectionView collection = (CollectionView)CollectionViewSource.GetDefaultView(datas); IEqualityComparer <string> compare = StringComparer.InvariantCultureIgnoreCase; collection.Filter = O => { var c = O as computer; if (this.ProducentId == 0) { return(c.Hardisk.Equals(this.Hardisk) || c.LCD.Equals(this.LCD) || c.Memory.Equals(this.Memory) || c.Price.Equals(this.Price) || c.Proccesor.Equals(this.Proccesor)); } else { return(c.ProducentId.Equals(this.ProducentId) && (c.Hardisk.Equals(this.Hardisk) || c.LCD.Equals(this.LCD) || c.Memory.Equals(this.Memory) || c.Price.Equals(this.Price) || c.Proccesor.Equals(this.Proccesor))); } }; collection.Refresh(); int id = 1; foreach (var item in collection) { var i = item as computer; var ha = dal.Hardisks.Where(O => O.Name == i.Hardisk).FirstOrDefault().Rangking; var proc = dal.Proccessors.Where(O => O.Name == i.Proccesor).FirstOrDefault().Rangking; var ram = dal.Rams.Where(O => O.Name == i.Memory).FirstOrDefault().Rangking; var pric = dal.Prices.Where(O => O.StartPrice <= i.Price && O.EndPrice > i.Price).FirstOrDefault().Rangking; var lc = dal.Lcds.Where(O => O.Name == i.LCD).FirstOrDefault().Rangking; var alternatif = new Alternatif { Hardisk = ha, Harga = pric, LCD = lc, ProccesorCode = proc, RAMCode = ram, Name = i.Name, Id = i.Id, Code = "A" + id }; this.Alternatives.Add(alternatif); id++; } var dataProccess = new DataProccessModel(dal.Criterias, this.Alternatives); Source.Clear(); foreach (var item in this.Alternatives.OrderByDescending(O => O.Value)) { var i = datas.Where(O => O.Id == item.Id).FirstOrDefault(); i.Score = item.Value; Source.Add(i); } SourceView.Refresh(); }