//Ф-я обработки ошибочного сохранения комплектации void complectationErrorSave(Complectation complectation) { System.Windows.MessageBox.Show(complectation.LastError); complectation.IsSaved = true; loadingProgress.Visibility = Visibility.Hidden; IsEnabled = true; }
//Клик по кнопке удаления комплектации, удаляет комплектацию void BtnDeleteRow_Click(object sender, RoutedEventArgs e) { Complectation complectation = dgvComplectation.SelectedItem as Complectation; if (complectation == null) { return; } if (System.Windows.MessageBox.Show("Удалить комплектацию из оборудования?", "Удалить комплектацию из оборудования?", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } if (complectation.Id == 0 && equipmentBid.ComplectationCollection.Contains(complectation)) { equipmentBid.ComplectationCollection.Remove(complectation); return; } if (!complectation.remove()) { System.Windows.MessageBox.Show(complectation.LastError); return; } }
//Ф-я сохранения комплектаций void complectationSave(Complectation complectation) { IsEnabled = false; loadingProgress.Visibility = Visibility.Visible; Task.Factory.StartNew(() => { if (complectation.Id_complectation_item == 0) { ComplectationItem item = new ComplectationItem(); item.Name = complectation.NewComplectationItemName; if (!item.save()) { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { complectationItemErrorSave(item); })); return; } complectation.Id_complectation_item = item.Id; } if (complectation.save()) { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { complectationSuccessSave(complectation); })); } else { Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { complectationErrorSave(complectation); })); } }); }
public Complectation GetComplectation() { Complectation result = _complectation; Reset(); return(result); }
//Ф-я валидации комплектации перед сохранением bool validate(Complectation complectation) { if (complectation.Id_complectation_item == 0 && complectation.NewComplectationItemName == "") { System.Windows.MessageBox.Show("Поле 'Наименование' не заполнено у одного или нескольких записей.\nСохранение не возможно!"); return(false); } if (complectation.Complectation_count < 1) { System.Windows.MessageBox.Show("Поле 'Количество' меньше 1 у одного или нескольких записей.\nСохранение не возможно!"); return(false); } return(true); }
public bool @remove <T>(T modelItem) { Complectation complectation = modelItem as Complectation; if (complectation == null) { complectation.LastError = "Не удалось преобразовать входные данные."; return(false); } if (!_collection.Contains(complectation)) { return(true); } return(_collection.Remove(complectation)); }
//----> Комплектации //Нажатие на кнопку добавления комплектации, создает и добавляет комплектацию в коллекцию void BtnAdd_Click(object sender, RoutedEventArgs e) { try { Complectation complectation = new Complectation(); complectation.Complectation_count = 1; complectation.Id_complectation_item = 0; complectation.IsSaved = false; equipmentBid.ComplectationCollection.Add(complectation); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); } }
public bool @add <T>(T modelItem) { Complectation complectation = modelItem as Complectation; if (complectation == null) { complectation.LastError = "Не удалось преобразовать входные данные."; return(false); } Complectation exist = getById(complectation.Id); if (exist != null || _collection.Contains(complectation)) { complectation.LastError = "Днная запись уже есть в коллекции."; return(false); } _collection.Add(complectation); complectation.loadedItemInitProperty(); return(true); }
//Ф-я подготовки комплектаций к сохранению void prepareComplectationSave() { for (int i = 0; i < equipmentBid.ComplectationCollection.Count; i++) { Complectation complectation = equipmentBid.ComplectationCollection[i]; if (!validate(complectation)) { return; } } for (int i = 0; i < equipmentBid.ComplectationCollection.Count; i++) { Complectation complectation = equipmentBid.ComplectationCollection[i]; if (complectation.IsSaved == false) { complectation.Id_equipment_bid = equipmentBid.Id; complectationSave(complectation); } } }
//Изменение наименования комплектации, устанавливает статус "Не сохранено" void DlcComplectationItem_TextChanged(object sender, TextChangedEventArgs e) { StangradCRM.Controls.DownListControl downListControl = sender as StangradCRM.Controls.DownListControl; if (downListControl == null) { return; } DataGridRow row = FindItem.FindParentItem <DataGridRow>(downListControl); if (row == null) { return; } Complectation complectation = (Complectation)row.Item; if (complectation == null) { return; } ComplectationItem citem = ComplectationItemViewModel.instance() .getByName(downListControl.Text); if (citem != null) { complectation.Id_complectation_item = citem.Id; } else { complectation.Id_complectation_item = 0; complectation.NewComplectationItemName = downListControl.Text; } complectation.IsSaved = false; }
//Обработка изменения количества комплектаций (в каждой строке) void DudCount_ValueChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { DecimalUpDown decimalUpDown = sender as DecimalUpDown; if (decimalUpDown == null) { return; } DataGridRow row = FindItem.FindParentItem <DataGridRow>(decimalUpDown); if (row == null) { return; } Complectation complectation = (Complectation)row.Item; if (complectation == null) { return; } try { if (complectation.Complectation_count == (int)decimalUpDown.Value) { complectation.IsSaved = true; return; } } catch { complectation.Complectation_count = 0; } complectation.IsSaved = false; complectation.Complectation_count = (int)decimalUpDown.Value; }
//Выбор существующего наименования из выпадающего списка void DlcComplectationItem_OnSelect(object sender, StangradCRM.Controls.SelectionChanged e) { StangradCRM.Controls.DownListControl downList = sender as StangradCRM.Controls.DownListControl; if (downList == null) { return; } DataGridRow row = FindItem.FindParentItem <DataGridRow>(downList); if (row == null) { return; } Complectation complectation = (Complectation)row.Item; if (complectation == null) { return; } if (e.Value != null) { int id_complectation_item = (int)e.Value; if (complectation.Id_complectation_item == id_complectation_item) { complectation.IsSaved = true; return; } ComplectationItem item = ComplectationItemViewModel.instance().getById(id_complectation_item); complectation.Id_complectation_item = id_complectation_item; complectation.IsSaved = false; } }
public void Reset() { _complectation = new Complectation(); }
//Статистика комплектаций private void ComplectationStatistic() { Dictionary <int, int> complectationDict = new Dictionary <int, int>(); for (int i = 0; i < archiveBid.Count; i++) { for (int j = 0; j < archiveBid[i].EquipmentBidCollection.Count; j++) { for (int k = 0; k < archiveBid[i].EquipmentBidCollection[j].ComplectationCollection.Count; k++) { Complectation complectation = archiveBid[i].EquipmentBidCollection[j].ComplectationCollection[k]; if (!complectationDict.ContainsKey(complectation.Id_complectation_item)) { complectationDict.Add(complectation.Id_complectation_item, 1); } else { complectationDict[complectation.Id_complectation_item]++; } } } } if (complectationDict.Count == 0) { return; } ReportRow rowH = new ReportRow(); rowH.Add(new ReportCell("Статистика комплектаций:")); Rows.Add(rowH); ReportRow rowT = new ReportRow(); rowT.Add(new ReportCell("Наименование") { BorderColor = System.Drawing.Color.Black, ColumnSpan = 1 }); rowT.Add(null); rowT.Add(new ReportCell("Кол-во комплектаций") { ColumnSpan = 1, BorderColor = System.Drawing.Color.Black }); Rows.Add(rowT); foreach (KeyValuePair <int, int> kv in complectationDict.OrderByDescending(x => x.Value)) { ComplectationItem citem = ComplectationItemViewModel.instance().getById(kv.Key); if (citem == null) { continue; } ReportRow row = new ReportRow(); row.Add(new ReportCell(citem.Name) { ColumnSpan = 1, BorderColor = System.Drawing.Color.Black }); row.Add(null); row.Add(new ReportCell(kv.Value.ToString()) { ColumnSpan = 1, BorderColor = System.Drawing.Color.Black }); Rows.Add(row); } }
//Фильтры отображени/сокрытия строк таблиц private void SetViewSources() { //Установка источника данных оборудования в заявке equipmentBidViewSource.Source = EquipmentBidViewModel.instance().Collection; //Установка фильтра equipmentBidViewSource.Filter += delegate(object sender, FilterEventArgs e) { EquipmentBid equipmentBid = e.Item as EquipmentBid; if (equipmentBid == null) { return; } Bid bid = dgvBid.SelectedItem as Bid; if (bid == null) { e.Accepted = false; return; } if (bid.Id == equipmentBid.Id_bid) { e.Accepted = true; } else { e.Accepted = false; } }; //Установка источника данных комплектация complectationViewSource.Source = ComplectationViewModel.instance().Collection; //Установка фильтра complectationViewSource.Filter += delegate(object sender, FilterEventArgs e) { Complectation complectation = e.Item as Complectation; if (complectation == null) { return; } EquipmentBid equipmentBid = dgvEquipmentBid.SelectedItem as EquipmentBid; if (equipmentBid == null) { e.Accepted = false; return; } if (complectation.Id_equipment_bid == equipmentBid.Id) { e.Accepted = true; } else { e.Accepted = false; } }; //Установка источника данных покупателей buyerViewSource.Source = BuyerViewModel.instance().Collection; //Установка фильтра buyerViewSource.Filter += delegate(object sender, FilterEventArgs e) { Buyer buyer = e.Item as Buyer; if (buyer == null) { return; } Bid bid = dgvBid.SelectedItem as Bid; if (bid == null) { e.Accepted = false; return; } if (buyer.Id == bid.Id_buyer) { e.Accepted = true; } else { e.Accepted = false; } }; }
//Фильтры отображени/сокрытия строк таблиц private void SetViewSources() { equipmentBidViewSource.Source = EquipmentBidViewModel.instance().Collection; equipmentBidViewSource.Filter += delegate(object sender, FilterEventArgs e) { EquipmentBid equipmentBid = e.Item as EquipmentBid; if (equipmentBid == null) { return; } Bid bid = dgvBid.SelectedItem as Bid; if (bid == null) { e.Accepted = false; return; } if (bid.Id == equipmentBid.Id_bid) { e.Accepted = true; } else { e.Accepted = false; } }; complectationViewSource.Source = ComplectationViewModel.instance().Collection; complectationViewSource.Filter += delegate(object sender, FilterEventArgs e) { Complectation complectation = e.Item as Complectation; if (complectation == null) { return; } EquipmentBid equipmentBid = dgvEquipmentBid.SelectedItem as EquipmentBid; if (equipmentBid == null) { e.Accepted = false; return; } if (complectation.Id_equipment_bid == equipmentBid.Id) { e.Accepted = true; } else { e.Accepted = false; } }; buyerViewSource.Source = BuyerViewModel.instance().Collection; buyerViewSource.Filter += delegate(object sender, FilterEventArgs e) { Buyer buyer = e.Item as Buyer; if (buyer == null) { return; } Bid bid = dgvBid.SelectedItem as Bid; if (bid == null) { e.Accepted = false; return; } if (buyer.Id == bid.Id_buyer) { e.Accepted = true; } else { e.Accepted = false; } }; }
//Ф-я обработки успешного сохранения комплектации void complectationSuccessSave(Complectation complectation) { complectation.IsSaved = true; loadingProgress.Visibility = Visibility.Hidden; IsEnabled = true; }