public MainWindowVM() { for (var i = 0; i < 100; ++i) { DataGridSource.Add(new ItemVM()); } }
private void ExecuteStartCommand(object x) { if (serialPort == null) { serialPort = new SerialPort(SelectedComPort.DeviceID, 9600, Parity.None, 8, StopBits.One); // 改行コードまでUIに反映されないよう、システムの改行コードを設定しておく serialPort.NewLine = Environment.NewLine; } serialPort.Open(); serialPort.DataReceived += (s, e) => { var readData = serialPort.ReadLine(); // ViewModelBaseのDispatcherプロパティを使って、UIスレッドに値を渡す Dispatcher.Invoke(new Action(() => { if (DataGridSource == null) { DataGridSource = new ObservableCollection <SerialPortModel>(); } DataGridSource.Add(new SerialPortModel() { ReadData = readData }); })); }; UpdateStatus(); }
public void Add() { VPersonAdd add = new VPersonAdd(PersonsTypes, CommTypes); if (add.ShowDialog() == true) { var dataContext = (add.DataContext as VMPersonAdd); PersonsCommunication.AddRange(dataContext.AddedCommunication); PersonsAddress.AddRange(dataContext.AddedAddress); var AddedPerson = dataContext.AddedPerson; var adress = PersonsAddress.Where(x => x.PeAdPerIdFk == AddedPerson.PeId).FirstOrDefault(); if (adress != null) { AddedPerson.PeAddress = $"{adress.PeAdCity.Trim()} - {adress.PeAdStreetName.Trim()}"; } AddedPerson.Type = PersonsTypes.Where(x => x.CId == AddedPerson.PeType).FirstOrDefault().CName; var communication = PersonsCommunication.Where(x => x.CoPeIdFk == AddedPerson.PeId); AddedPerson.PhoneNo = communication.Where(x => x.CoNameCfk.Equals(SystemValues.Communications.Phone)).FirstOrDefault()?.CoValue; AddedPerson.MobileNo = communication.Where(x => x.CoNameCfk.Equals(SystemValues.Communications.Mobile)).FirstOrDefault()?.CoValue; AddedPerson.Email = communication.Where(x => x.CoNameCfk.Equals(SystemValues.Communications.Emial)).FirstOrDefault()?.CoValue; Persons.Add(AddedPerson); DataGridSource.Add(dataContext.AddedPerson); } }
public void loadData() { for (int i = 1; i < 20; i++) { DataGridSource.Add(new Person() { ID = i.ToString(), Firstname = "Firstname " + i.ToString(), Lastname = "Lastname " + i.ToString(), Age = rnd.Next(20, 60).ToString(), }); } foreach (Person item in DataGridSource) { item.PropertyChanged += onPropertyChanged; } }
public void Edit() { if (SelectedDataItem != null) { var item = SelectedDataItem; for (int i = 0; i < Roles.Count; i++) { var role = GroupRolesSource.Where(x => x.RoleId == Roles[i].RoleId).FirstOrDefault(); if (role != null) { var groupRoles = GroupRoles.Where(x => x.GrolrRoleIdFk == Roles[i].RoleId && x.GrolrGIdFk == item.GId).FirstOrDefault(); Roles[i].IsChecked = true; Roles[i].GroleAdd = groupRoles.GroleAdd; Roles[i].GroleEdit = groupRoles.GroleEdit; Roles[i].GroleDelete = groupRoles.GroleDelete; Roles[i].GroleExport = groupRoles.GroleExport; Roles[i].GrolePrint = groupRoles.GrolePrint; Roles[i].GroleView = groupRoles.GroleView; } else { Roles[i].IsChecked = false; Roles[i].GroleAdd = false.ToIntState(); Roles[i].GroleEdit = false.ToIntState(); Roles[i].GroleDelete = false.ToIntState(); Roles[i].GroleExport = false.ToIntState(); Roles[i].GrolePrint = false.ToIntState(); Roles[i].GroleView = false.ToIntState(); } } VGroupsEdit edit = new VGroupsEdit(Roles, item); if (edit.ShowDialog() == true) { var dataContext = edit.DataContext as VMGroupsEdit; DataGridSource.Remove(SelectedDataItem); DataGridSource.Add(dataContext.EditGroup); GroupRoles.RemoveAll(x => x.GrolrGIdFk == item.GId); GroupRoles.AddRange(dataContext.DataGridSource.Where(x => x.RoleSelected()).Select(x => x.ToGroupRoles(item.GId))); } GroupRolesSource.Clear(); } }
public void Edit() { var person = new PersonsModel() { PeId = SelectedDataItem.PeId, PeAddress = SelectedDataItem.PeAddress, IsChecked = SelectedDataItem.IsChecked, PeIdentity = SelectedDataItem.PeIdentity, PeName = SelectedDataItem.PeName, PeType = SelectedDataItem.PeType, }; VPersonEdit edit = new VPersonEdit(person, PersonsTypes, CommTypes, PersonsCommunication.Where(x => x.CoPeIdFk == person.PeId).ToList()); if (edit.ShowDialog() == true) { var dataContext = edit.DataContext as VMPersonEdit; Persons.Remove(SelectedDataItem); DataGridSource.Remove(SelectedDataItem); PersonsCommunication.RemoveAll(x => x.CoPeIdFk == dataContext.EditedPerson.PeId); PersonsCommunication.AddRange(dataContext.AddedCommunication); PersonsAddress.RemoveAll(x => x.PeAdPerIdFk == dataContext.EditedPerson.PeId); PersonsAddress.AddRange(dataContext.AddedAddress); var adress = PersonsAddress.Where(x => x.PeAdPerIdFk == dataContext.EditedPerson.PeId).FirstOrDefault(); if (adress != null) { dataContext.EditedPerson.PeAddress = $"{adress.PeAdCity} - {adress.PeAdStreetName}"; } dataContext.EditedPerson.Type = PersonsTypes.Where(x => x.CId == dataContext.EditedPerson.PeType).FirstOrDefault().CName; var communication = PersonsCommunication.Where(x => x.CoPeIdFk == dataContext.EditedPerson.PeId); dataContext.EditedPerson.PhoneNo = communication.Where(x => x.CoNameCfk.Equals(SystemValues.Communications.Phone)).FirstOrDefault()?.CoValue; dataContext.EditedPerson.MobileNo = communication.Where(x => x.CoNameCfk.Equals(SystemValues.Communications.Mobile)).FirstOrDefault()?.CoValue; dataContext.EditedPerson.Email = communication.Where(x => x.CoNameCfk.Equals(SystemValues.Communications.Emial)).FirstOrDefault()?.CoValue; Persons.Add(dataContext.EditedPerson); DataGridSource.Add(dataContext.EditedPerson); SelectedDataItem = dataContext.EditedPerson; } }
public void Add() { foreach (var item in Roles) { item.IsChecked = false; item.GroleAdd = false.ToIntState(); item.GroleEdit = false.ToIntState(); item.GroleDelete = false.ToIntState(); item.GroleExport = false.ToIntState(); item.GrolePrint = false.ToIntState(); item.GroleView = false.ToIntState(); } VGroupsAdd add = new VGroupsAdd(Roles); if (add.ShowDialog() == true) { DataGridSource.Add((add.DataContext as VMGroupsAdd).AddedGroup); foreach (var item in (add.DataContext as VMGroupsAdd).AddedGroupRoles) { GroupRoles.Add(item); } } GroupRolesSource.Clear(); }
private void RestoreFromDB() { EventObjectModel tempModel = new EventObjectModel(); foreach (EventObjectModel eo in dbReaderWriter.eventObjects) { foreach (ResponseObjectModel rom in eo.ResponseCollection) { if (rom.ResponseObject is TelegramMessageObjectModel) { var botListQuery = DataGridSource.SelectMany( u => u.ResponseCollection.Where( v => v.ResponseObject is TelegramMessageObjectModel).Select( w => w.ResponseObject as TelegramMessageObjectModel).Select(x => x.Bot2Use).ToList() ).ToList(); var selectedBotQuery = DataGridSource.SelectMany( u => u.ResponseCollection.Where( v => v.ResponseObject is TelegramMessageObjectModel).Select( w => w.ResponseObject as TelegramMessageObjectModel).Select( x => x.Bot2Use) ).ToList(); if ((rom.ResponseObject is TelegramMessageObjectModel) && !(botListQuery.Select(y => y.Token).Contains((rom.ResponseObject as TelegramMessageObjectModel).Bot2Use.Token))) { try{ (rom.ResponseObject as TelegramMessageObjectModel).Bot2Use.CreateBot(); } catch (Exception e) { if (e.InnerException.GetType().ToString() == "System.Net.Http.HttpRequestException") { LogWriter.CreateLogEntry(string.Format("{0}\n{1}", e.Message, e.InnerException != null ? e.InnerException.Message : "")); this.Dialogs.Add(new CustomDialogViewModel { Message = e.InnerException.InnerException.Message, Caption = "Error", OnOk = (sender2) => { sender2.Close(); }, OnCancel = (sender2) => { sender2.Close(); }, OnCloseRequest = (sender2) => { sender2.Close(); } }); } } } else if (botListQuery.Select(y => y.Token).Contains((rom.ResponseObject as TelegramMessageObjectModel).Bot2Use.Token)) { (rom.ResponseObject as TelegramMessageObjectModel).Bot2Use = selectedBotQuery.Where(z => z.Token == (rom.ResponseObject as TelegramMessageObjectModel).Bot2Use.Token).FirstOrDefault(); } } else if (rom.ResponseObject is EMailResponseObjectModel) { } } DataGridSource.Add(eo); SelectedDataGridItem = eo; SelectedResponse = SelectedDataGridItem.ResponseCollection.FirstOrDefault(); } }
private void AddNewEvent() { this.Dialogs.Add(new EventEditorDialogViewModel(DataGridSource, SelectedDataGridItem) { OnOk = (sender) => { //TODO: Test for Duplicate entrys / Overwrite or create new? if (sender.HasConfiguration && sender.ObjectModel.EventType == sender.SelectedGeneralEventType) { if (selectedDataGridItem == null) { if (DataGridSource.Contains(sender.ObjectModel)) { if (new MessageBoxViewModel { Caption = resLoader.getResource("messageBoxEventAlreadyExistCaption"), Message = resLoader.getResource("messageBoxEventAlreadyExistMessage"), Buttons = MessageBoxButton.OK, Image = MessageBoxImage.Information } .Show(this.Dialogs) == MessageBoxResult.OK) { return; } } else { DataGridSource.Add(sender.ObjectModel); } } else { SelectedDataGridItem.EventName = sender.EventName; SelectedDataGridItem.EventDescription = sender.EventDescription; } sender.Close(); } else { new MessageBoxViewModel { Caption = resLoader.getResource("messageBoxMissingConfigCaption"), Message = resLoader.getResource("messageBoxMissingConfigMessage"), Buttons = MessageBoxButton.OK, Image = MessageBoxImage.Information } .Show(this.Dialogs); } RaisePropertyChanged("DataGridSource"); }, OnCancel = (sender) => { sender.Close(); }, OnCloseRequest = (sender) => { sender.Close(); } }); }