private void OnBtnApplyClick(object sender, EventArgs e) { EventHandler <InsertItemEventArgs> handler = InsertItemEvent; AbonentInfo abonentInfo = new AbonentInfo { Name = paramTxtBoxName.Text, Location = paramTxtBoxLocation.Text, Address = paramTxtBoxAddress.Text, Phone = paramTxtBoxPhone.Text, ID = paramTxtBoxID.Text, StartDate = paramTxtBoxStartDate.Text, InstallationPayment = paramTxtBoxInstallationPayment.Text, Fee = paramTxtBoxFee.Text, LastPayment = paramTxtBoxLastPayment.Text, }; handler?.Invoke(this, new InsertItemEventArgs(abonentInfo)); this.Close(); }
public InsertItemEventArgs(AbonentInfo abonent) { this.abonent = abonent; }
public WindowViewModel(MainWindow wnd, SeanseManager sm, ILogger logger) { this.logger = logger; this.window = wnd; this.seanseManager = sm; this.seanses = new ObservableCollection <Seanse>(); this.version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.notifyWhenStartActive = false; this.notifyWhenStartActive = false; this.lastSelectedPathWithLinks = ""; seanseManager.LoadingStarted += SeanseManager_LoadingStarted; seanseManager.LoadingEnded += SeanseManager_LoadingEnded; seanseManager.SeanseAdded += SeanseManager_SeanseAdded; seanseManager.SeanseRemoved += SeanseManager_SeanseRemoved; seanseManager.SeanseUpdated += SeanseManager_SeanseUpdated; seanseManager.CopyingStarted += SeanseManager_CopyingStarted; seanseManager.CopyingEnded += SeanseManager_CopyingEnded; seanseManager.UpdatingStarted += SeanseManager_UpdatingStarted; seanseManager.UpdatingEnded += SeanseManager_UpdatingEnded; #region Charts initialization Chart tuningChart = window.tuningChart; ChartArea tuningArea = new ChartArea("TuningArea"); tuningChart.ChartAreas.Add(tuningArea); Series tuningSeries = new Series("Tuning"); tuningSeries.IsXValueIndexed = true; tuningSeries.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; tuningSeries.XValueType = ChartValueType.Time; tuningSeries.XValueMember = "Time"; tuningSeries.YValueMembers = "Tuning"; tuningSeries.Color = System.Drawing.Color.Blue; tuningSeries.BorderWidth = 1; tuningChart.Series.Add(tuningSeries); Chart sizeChart = window.sizeChart; ChartArea sizeArea = new ChartArea("SizeArea"); sizeChart.ChartAreas.Add(sizeArea); Series sizeSeries = new Series("Size"); sizeSeries.IsXValueIndexed = true; sizeSeries.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; sizeSeries.XValueType = ChartValueType.Time; sizeSeries.XValueMember = "Time"; sizeSeries.YValueMembers = "Size"; sizeSeries.Color = System.Drawing.Color.Blue; sizeSeries.BorderWidth = 1; sizeChart.Series.Add(sizeSeries); Chart workingChart = window.workingChart; ChartArea workingArea = new ChartArea("WorkingArea"); workingArea.AxisX.IntervalType = DateTimeIntervalType.Auto; workingArea.AxisX.Interval = IoCContainer.Settings.WorkingChartInterval; workingArea.AxisY.Interval = 1; workingChart.ChartAreas.Add(workingArea); Series workingSeries = new Series("Working"); workingSeries.IsXValueIndexed = true; workingSeries.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.StepLine; workingSeries.XValueType = ChartValueType.Time; workingSeries.XValueMember = "Time"; workingSeries.YValueMembers = "State"; workingSeries.Color = System.Drawing.Color.Blue; workingSeries.BorderWidth = 2; workingChart.Series.Add(workingSeries); #endregion #region SettingCommands SelectDestinationPath = new RelayCommand(() => { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (Directory.Exists(IoCContainer.Settings.InitialDestPath)) { fbd.SelectedPath = IoCContainer.Settings.InitialDestPath; } DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { seanseManager.DestinationPath = fbd.SelectedPath; OnPropertyChanged("DestPath"); OnPropertyChanged("DestPathSelected"); } }); AddSeanse = new RelayCommand(async() => { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (!string.IsNullOrWhiteSpace(lastSelectedPathWithLinks)) { fbd.SelectedPath = lastSelectedPathWithLinks; } else if (Directory.Exists(IoCContainer.Settings.InitialSeansesPath)) { fbd.SelectedPath = IoCContainer.Settings.InitialSeansesPath; } DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && fbd.SelectedPath != null) { lastSelectedPathWithLinks = fbd.SelectedPath; if (!await seanseManager.AddSeanseAsync(fbd.SelectedPath)) { logger.LogMessage("Не удалось добавить сеанс: \n" + fbd.SelectedPath, LogLevel.Warning); } } }); AddSeansesFromVentur = new RelayCommand(async() => { await seanseManager.AddSeansesFromVentursFileAsync(IoCContainer.Settings.LastFiles); }); AddAllSeanses = new RelayCommand(async() => { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (Directory.Exists(IoCContainer.Settings.InitialDestPath)) { fbd.SelectedPath = IoCContainer.Settings.InitialDestPath; } DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && fbd.SelectedPath != null) { await seanseManager.AddAllSeansesFromFolderAsync(fbd.SelectedPath); } }); RemoveSeanse = new RelayCommand(async() => { try { if (SelectedSeanse != null) { await seanseManager.RemoveSeanseAsync(SelectedSeanse); } else { MessageBox.Show("Выбирете сеанс", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception e) { logger.LogMessage(e.ToString() + " " + e.Message, LogLevel.Error); } }); RemoveAllSeanses = new RelayCommand(async() => { try { DialogResult result = MessageBox.Show("Удалить все сеансы?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { await seanseManager.RemoveAllSeansesAsync(); } } catch (Exception e) { logger.LogMessage(e.ToString() + " " + e.Message, LogLevel.Error); } }); CopySeanses = new RelayCommand(async() => { if (!string.IsNullOrWhiteSpace(seanseManager.DestinationPath)) { await seanseManager.CopySeansesAsync(); } else { MessageBox.Show("Папка для накопления не выбрана", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }); UpdateSeanses = new RelayCommand(async() => { await seanseManager.UpdateSeansesAsync(); }); OpenSettings = new RelayCommand(() => { SettingsForm sf = new SettingsForm(logger); sf.ShowDialog(); seanseManager.SetConfiguration(IoCContainer.Settings.Configuration); window.workingChart.ChartAreas[0].AxisX.Interval = IoCContainer.Settings.WorkingChartInterval; window.workingChart.Invalidate(); }); About = new RelayCommand(() => { AboutBox about = new AboutBox(); about.ShowDialog(); }); OpenLog = new RelayCommand(() => { if (SelectedSeanse != null) { Process p = new Process(); p.StartInfo = new ProcessStartInfo("excel.exe", "\"" + SelectedSeanse.Directory + "\\log.txt\""); p.Start(); } }); DeleteSeanseDirectory = new RelayCommand(async() => { if (SelectedSeanse != null) { DialogResult res = MessageBox.Show("Удалить папку с сеансом?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.Yes) { SelectedSeanse.Delete(); await seanseManager.RemoveSeanseAsync(SelectedSeanse); } } }); OpenAbonentsInfo = new RelayCommand(() => { if (SelectedSeanse != null) { foreach (var ownedWin in window.OwnedWindows) { if ((ownedWin as System.Windows.Window).Tag == SelectedSeanse.Directory) { (ownedWin as System.Windows.Window).Focus(); return; } } AbonentsInfoWindow abonentsInfo = new AbonentsInfoWindow(); AbonentInfo[] abonentsInfoCopy = new AbonentInfo[SelectedSeanse.Abonents.Count]; SelectedSeanse.Abonents.CopyTo(abonentsInfoCopy); abonentsInfo.DataContext = abonentsInfoCopy; abonentsInfo.Title = SelectedSeanse.Freq.ToString() + " " + SelectedSeanse.Mode.ToString(); abonentsInfo.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner; abonentsInfo.Tag = SelectedSeanse.Directory; abonentsInfo.WindowStyle = System.Windows.WindowStyle.ToolWindow; abonentsInfo.Owner = window; abonentsInfo.Show(); } ; }); GetReport = new ParametrizedCommand(i => { if (IsSeanceSelected) { int interval = Convert.ToInt32(i); Process linkReport = new Process(); linkReport.StartInfo = new ProcessStartInfo("Link11Report.exe", interval.ToString() + " \"" + SelectedSeanse.Directory + "\""); linkReport.Start(); } }); #endregion }