public WorkViewModel(Orders orders) { _orders = orders; Delete = new SimpleCommand(id => { SQL.Delete(SQL.GetWork().First(w => w.Id == (int)id)); SQL.AddHistory(_orders.IdOrder, String.Format("Удаление работы: {0}", WorkName)); Load(); }); Edit = new SimpleCommand(id => { var a = ShowWin.AddedWork(SQL.GetWork().First(w => w.Id == (int)id)); a.OnClose += Load; }); AddWork = new SimpleCommand(() => { if (!SQL.GetDicWork().Contains(WorkName)) { SQL.Add(new DicWork() { Work = WorkName, Price = Price }); } SQL.Add(new Works() { IdOrder = _orders.IdOrder, IdWork = SQL.GetIdWork(WorkName), Count = Count == 0 ? 1 : Count, Price = Price }); SQL.AddHistory(_orders.IdOrder, String.Format("Добавлена работа: {0}", WorkName)); Load(); }); Load(); DicWorkEntries.CurrentChanged += (u, e) => { if (DicWorkEntries.CurrentItem != null) { Price = SQL.GetAllDicWork() .First(w => w.IdWork == SQL.GetIdWork(DicWorkEntries.CurrentItem.ToString())) .Price; } }; }
public OrdersViewModel() { var fab = SQL.GetFabricator(); var mod = SQL.GetModel(); var cli = SQL.GetClientses(); var states = SQL.GetState(); OrdersEntries = new CollectionView(SQL.GetOrders().Select(o => { var client = cli.FirstOrDefault(c => c.IdClient == o.IdClient); return(new Order() { Id = o.IdOrder, State = states.First(f => f.Id == o.IdState).State, Number = o.Number ?? "", NameClient = client != null? client.Name: "", PhoneClient = client != null ? client.Phone : "", Model = String.Format("{0} {1}", fab.First(f => f.IdFabricator == o.IdFabricator).Fabricator, mod.First(m => m.IdModel == o.IdModel).Model), DateReceipt = o.DateReceipt.Date, AvailabilityDate = o.AvailabilityDate.Date, NameExecutor = SQL.GetExecutors(o.IdExecutor), EditOrder = new SimpleCommand((_) => ShowWin.ShowWork(o)) }); })); EditOrder = new SimpleCommand(() => { if (OrdersEntries.CurrentItem != null) { var o = SQL.GetOrders().FirstOrDefault(f => f.IdOrder == (OrdersEntries.CurrentItem as Order).Id); if (o.IdState == 1) { o.IdState = 2; SQL.Update(o); } ShowWin.ShowWork(o); } }); NewOrder = new SimpleCommand(() => ShowWin.ShowNewOrder(null)); LoadFilterEntries(); }
public void Create() { //Если клиента нет в базе он добавляется if (SQL.GetClientses().Find(t => t.Name == Name && t.Phone == Phone) == null) { SQL.Add(new Clients() { Name = Name, Address = Address, Phone = Phone, Email = Email }); } //Если типа устройства нет в базе он добавляется if (TypesDevices != String.Empty) { if (!SQL.GetTypesDevices().Select(s => s.Type).Contains(TypesDevices)) { SQL.Add(new DicTypesDevices() { Type = TypesDevices }); } } if (Fabricator != String.Empty) { if (!SQL.GetFabricator().Select(f => f.Fabricator).Contains(Fabricator)) { SQL.Add(new DicFabricator() { Fabricator = Fabricator }); } } if (Model != String.Empty) { if (!SQL.GetModelInFabricator(SQL.GetIdFabricator(Fabricator)).Contains(Model)) { SQL.Add(new DicModel() { Model = Model, IdFabricator = SQL.GetIdFabricator(Fabricator) }); } } var o = new Orders() { IdClient = SQL.GetClientses().First(t => t.Name == Name && t.Phone == Phone).IdClient, Number = Number, IdTypeDevice = SQL.GetIdTypeDevice(TypesDevices), IdFabricator = SQL.GetIdFabricator(Fabricator), IdModel = SQL.GetIdModel(Model, SQL.GetIdFabricator(Fabricator)), SerialNumber = SerialNumber, Appearance = Appearance, Equipment = Equipment, Malfunction = Malfunction, NotesOnAdmission = NotesOnAdmission, AvailabilityDate = AvailabilityDate, DateReceipt = DateTime.Now, EstimatedPrice = EstimatedPrice, Prepayment = Prepayment, IdExecutor = SQL.GetIdExecutor(Executors) }; if (_orders == null) { o.IdState = 1; SQL.Add(o); SQL.AddHistory(SQL.GetOrders().OrderByDescending(o1 => o1.IdOrder).First().IdOrder, "Заказ принят"); ShowWin.ShowOrders(); } else { o.IdState = _orders.IdState; o.IdOrder = _orders.IdOrder; SQL.AddHistory(o.IdOrder, "Редактирование заказа"); SQL.Update(o); ShowWin.ShowWork(o); } }
public NewOrderViewModel(Orders orders = null) { _orders = orders; AddOrder = new SimpleCommand(Create); EditOrder = new SimpleCommand(() => ShowWin.ShowNewOrder(_orders)); Back = new SimpleCommand(() => { if (orders == null) { ShowWin.ShowOrders(); } else { ShowWin.ShowWork(orders); } }); SetState = new SimpleCommand((state) => { _orders.IdState = Int32.Parse(state.ToString()); SQL.Update(_orders); State = _orders == null ? "" : SQL.GetState().First(w => w.Id == _orders.IdState).State; }); OpenOrders = new SimpleCommand((_) => ShowWin.ShowOrders()); if (orders != null) { Number = orders.Number; Malfunction = orders.Malfunction; Appearance = orders.Appearance; Equipment = orders.Equipment; NotesOnAdmission = orders.NotesOnAdmission; SerialNumber = orders.SerialNumber; Fabricator = SQL.GetFabricator(orders.IdFabricator); Model = SQL.GetModel(orders.IdModel); AvailabilityDate = orders.AvailabilityDate; EstimatedPrice = orders.EstimatedPrice; Prepayment = orders.Prepayment; TypesDevices = SQL.GetTypesDevices(orders.IdTypeDevice); Name = SQL.GetClientses(orders.IdClient).Name; Phone = SQL.GetClientses(orders.IdClient).Phone; Email = SQL.GetClientses(orders.IdClient).Email; Address = SQL.GetClientses(orders.IdClient).Address; DateReceipt = orders.DateReceipt; } else { var firstOrDefault = SQL.GetOrders().OrderByDescending(o => o.Number).FirstOrDefault(); if (firstOrDefault != null) { var n = firstOrDefault.Number; int res; if (Int32.TryParse(n, out res)) { Number = (res + 1).ToString(); } } } ClientNameEntries = new CollectionView(SQL.GetClientses().Select(c => c.Name + " " + c.Phone)); var e = new List <string> { "" }; e.AddRange(SQL.GetExecutors().Select(s => s.Name)); ExecutorsEntries = new CollectionView(e); State = _orders == null ? "" : SQL.GetState().First(w => w.Id == _orders.IdState).State; DeleteOrder = new SimpleCommand(() => { var res = MessageBox.Show("Вы действительно хотите удалить заказ", "Удалить заказ", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.GetHistory().Where(w => w.IdOrder == _orders.IdOrder).ToList().ForEach(f => SQL.Delete(f)); SQL.GetWork().Where(w => w.IdOrder == _orders.IdOrder).ToList().ForEach(f => SQL.Delete(f)); SQL.Delete(_orders); ShowWin.ShowOrders(); } }); }
public DictionariesViewModel() { var fab = SQL.GetFabricator(); fab.Add(new DicFabricator() { Fabricator = "", IdFabricator = 0 }); fab.Add(new DicFabricator() { Fabricator = "" }); var mod = SQL.GetModel(); var cli = SQL.GetClientses(); var states = SQL.GetState(); OrdersEntries = new CollectionView(SQL.GetOrders().Select(o => { var client = cli.FirstOrDefault(c => c.IdClient == o.IdClient); return(new Order() { Id = o.IdOrder, State = states.First(f => f.Id == o.IdState).State, Number = o.Number ?? "", NameClient = client != null ? client.Name : "", PhoneClient = client != null ? client.Phone : "", Model = String.Format("{0} {1}", fab.First(f => f.IdFabricator == o.IdFabricator).Fabricator, mod.First(m => m.IdModel == o.IdModel).Model), DateReceipt = o.DateReceipt.Date, AvailabilityDate = o.AvailabilityDate.Date, NameExecutor = SQL.GetExecutors(o.IdExecutor), EditOrder = new SimpleCommand((_) => ShowWin.ShowWork(o)) }); })); #region Тип устройств TypesDevicesEntries = new CollectionView(SQL.GetTypesDevices()); AddTypeDevices = new SimpleCommand((edit) => { AddedView a = bool.Parse(edit.ToString()) ? ShowWin.AddedTypeDevice(TypesDevicesEntries.CurrentItem as DicTypesDevices) : ShowWin.AddedTypeDevice(null); a.OnClose += () => { TypesDevicesEntries = new CollectionView(SQL.GetTypesDevices()); TypesDevicesEntries.Refresh(); }; }); DeleteTypeDevices = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить тип устройств", "Удалить тип устройств", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(TypesDevicesEntries.CurrentItem as DicTypesDevices); TypesDevicesEntries = new CollectionView(SQL.GetTypesDevices()); } }); #endregion #region Производители FabricatorEntries = new CollectionView(SQL.GetFabricator()); AddFabricator = new SimpleCommand((edit) => { AddedView a = bool.Parse(edit.ToString()) ? ShowWin.AddedFabricator(FabricatorEntries.CurrentItem as DicFabricator) : ShowWin.AddedFabricator(null); a.OnClose += () => FabricatorEntries = new CollectionView(SQL.GetFabricator()); }); DeleteFabricator = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить производителя", "Удалить производителя", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(TypesDevicesEntries.CurrentItem as DicFabricator); FabricatorEntries = new CollectionView(SQL.GetFabricator()); } }); #endregion #region Модель ModelEntries = new CollectionView(SQL.GetModel().OrderBy(o => o.IdFabricator)); AddModel = new SimpleCommand((edit) => { var a = bool.Parse(edit.ToString()) ? ShowWin.AddedModel(ModelEntries.CurrentItem as DicModel) : ShowWin.AddedModel(null); a.OnClose += () => ModelEntries = new CollectionView(SQL.GetModel().OrderBy(o => o.IdFabricator)); }); DeleteModel = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить модель", "Удалить модель", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(ModelEntries.CurrentItem as DicModel); ModelEntries = new CollectionView(SQL.GetModel().OrderBy(o => o.IdFabricator)); } }); #endregion #region аботы WorkEntries = new CollectionView(SQL.GetAllDicWork()); AddWork = new SimpleCommand((edit) => { var a = bool.Parse(edit.ToString()) ? ShowWin.AddedDicWork(WorkEntries.CurrentItem as DicWork) : ShowWin.AddedDicWork(null); a.OnClose += () => WorkEntries = new CollectionView(SQL.GetAllDicWork()); }); DeleteWork = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить работу", "Удалить работу", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(WorkEntries.CurrentItem as DicWork); WorkEntries = new CollectionView(SQL.GetAllDicWork()); } }); #endregion #region Неисправность MalfunctionEntries = new CollectionView(SQL.GetMalfunction()); AddMalfunction = new SimpleCommand((edit) => { var a = bool.Parse(edit.ToString()) ? ShowWin.AddedMalfunction(MalfunctionEntries.CurrentItem as DicMalfunction) : ShowWin.AddedMalfunction(null); a.OnClose += () => MalfunctionEntries = new CollectionView(SQL.GetMalfunction()); }); DeleteMalfunction = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить неисправность", "Удалить неисправность", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(MalfunctionEntries.CurrentItem as DicMalfunction); MalfunctionEntries = new CollectionView(SQL.GetMalfunction()); } }); #endregion #region Состояние AppearanceEntries = new CollectionView(SQL.GetAppearance()); AddAppearance = new SimpleCommand((edit) => { var a = bool.Parse(edit.ToString()) ? ShowWin.AddedAppearance(AppearanceEntries.CurrentItem as DicAppearance) : ShowWin.AddedAppearance(null); a.OnClose += () => AppearanceEntries = new CollectionView(SQL.GetAppearance()); }); DeleteAppearance = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить состояние", "Удалить состояние", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(AppearanceEntries.CurrentItem as DicAppearance); AppearanceEntries = new CollectionView(SQL.GetAppearance()); } }); #endregion #region Комплектация EquipmentEntries = new CollectionView(SQL.GetEquipment()); AddEquipment = new SimpleCommand((edit) => { var a = bool.Parse(edit.ToString()) ? ShowWin.AddedEquipment(EquipmentEntries.CurrentItem as DicEquipment) : ShowWin.AddedEquipment(null); a.OnClose += () => EquipmentEntries = new CollectionView(SQL.GetEquipment()); }); DeleteEquipment = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить комплектацию", "Удалить комплектацию", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(EquipmentEntries.CurrentItem as DicEquipment); EquipmentEntries = new CollectionView(SQL.GetEquipment()); } }); #endregion #region Исполнитель ExecutorsEntries = new CollectionView(SQL.GetExecutors()); AddExecutors = new SimpleCommand((edit) => { var a = bool.Parse(edit.ToString()) ? ShowWin.AddedExecutors(ExecutorsEntries.CurrentItem as Executors) : ShowWin.AddedExecutors(null); a.OnClose += () => ExecutorsEntries = new CollectionView(SQL.GetExecutors()); }); DeleteExecutors = new SimpleCommand((_) => { var res = MessageBox.Show("Вы действительно хотите удалить исполнителя", "Удалить исполнителя", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (res == MessageBoxResult.OK) { SQL.Delete(ExecutorsEntries.CurrentItem as Executors); ExecutorsEntries = new CollectionView(SQL.GetExecutors()); } }); #endregion }