public AddOrEditChannelWnd(ProxyChannelItem pi, bool isEdit) { InitializeComponent(); IsEdit = isEdit; _uiContext = pi.Clone(); _orgItem = pi; this.DataContext = _uiContext; this.Title = isEdit ? "Edit Channel" : "New Channel"; }
private void BtnNew_Click(object sender, RoutedEventArgs e) { ProxyChannelItem pi = new ProxyChannelItem(); AddOrEditChannelWnd addOrEditWnd = new AddOrEditChannelWnd(pi, false); if (addOrEditWnd.ShowDialog().Value) { _channelVMList.Add(pi); SaveConfig(); } }
private void btnStopService_Click(object sender, RoutedEventArgs e) { ProxyChannelItem pi = (sender as FrameworkElement).DataContext as ProxyChannelItem; try { pi.StopService(); } catch (Exception ex) { LocalMsgBox(ex.Message); } }
private void LoadConfig() { _channelVMList = new ObservableCollection <ProxyChannelItem>(); if (File.Exists(_configFilePath)) { string strJson = File.ReadAllText(_configFilePath, Encoding.UTF8); List <ProxyChannel> channelList = JsonConvert.DeserializeObject <List <ProxyChannel> >(strJson); foreach (ProxyChannel channel in channelList) { ProxyChannelItem pi = ProxyChannelItem.FromModel(channel); _channelVMList.Add(pi); } } }
private void BtnDelete_Click(object sender, RoutedEventArgs e) { ProxyChannelItem selItem = dgChannel.SelectedItem as ProxyChannelItem; if (selItem == null) { LocalMsgBox("Please select the channel that you want to delete."); return; } if (selItem.IsRunning) { LocalMsgBox("Can not delete channel during running time."); return; } if (QuestionOKCancel("Are you sure to delete the channel?") == MessageBoxResult.Cancel) { return; } _channelVMList.Remove(selItem); SaveConfig(); }
private void BtnEdit_Click(object sender, RoutedEventArgs e) { ProxyChannelItem selItem = dgChannel.SelectedItem as ProxyChannelItem; if (selItem == null) { LocalMsgBox("Please select the channel that you want to edit."); return; } if (selItem.IsRunning) { LocalMsgBox("Can not edit channel during running time."); return; } AddOrEditChannelWnd addOrEditWnd = new AddOrEditChannelWnd(selItem, false); if (addOrEditWnd.ShowDialog().Value) { SaveConfig(); } }