void ManageDiagrams(TimeRow row, double epsilon, ref Image diagramRasterized, ref Image diagramDistance, ref Image scaleDistance, ref Chart pointDiagram, ref Chart lineDiagram, ref string AnalysisResult) { DiagramManager diagram = new DiagramManager(row, (float)epsilon); diagram.GenerateReccurentMatrix(); diagramRasterized = diagram.GetReccurentDiagram(_view.DiagramBox.Width, _view.DiagramBox.Height); diagramDistance = diagram.GetDistanceDiagram(_view.DistanceBox.Width, _view.DistanceBox.Height); scaleDistance = diagram.GetDistancePalette(_view.DistanceScaleBox.Width); bool[,] matrix = diagram.GetReccurentMatrix(); int side = matrix.GetLength(0); pointDiagram.Series[0].MarkerSize = side > 100 ? 2 : (int)(pointDiagram.Height / side * 0.9); pointDiagram.Series[0].Points.Clear(); int move = 0; int max = side * side + row.Row.Length - 1; int invokeVal = max / 10; for (int i = 0; i < side; i++) { for (int j = 0; j < side; j++) { if (matrix[i, j] == true) { pointDiagram.Series[0].Points.AddXY(i + 1, j + 1); } if ((move % invokeVal) == 0) { ProgressAction?.Invoke(10, move / invokeVal); } move++; } } lineDiagram.Series[0].Points.Clear(); for (int i = 0; i < row.Row.Length - 1; i++) { lineDiagram.Series[0].Points.AddXY((row[i]), row[i + 1]); if ((move % invokeVal) == 0) { ProgressAction?.Invoke(10, move / invokeVal); } move++; } //if (move < max) ProgressAction?.Invoke(10, move / invokeVal); AnalysisResult = "\n Analysis: \n RR: " + diagram.RR.ToString() + "\n DET: " + diagram.DET.ToString() + "\n L: " + diagram.L.ToString() + "\n DIV: " + diagram.DIV.ToString() + "\n ENTR: " + diagram.ENTR.ToString() + "\n RATIO: " + diagram.RATIO.ToString(); row.Dispose(); diagram.Dispose(); matrix = null; GC.Collect(); }
private void StartButton_Click(object sender, RoutedEventArgs e) { if (DayRegister.Controls.Any(x => x.Timer.IsEnabled)) { DayRegister.Controls.Single(x => x.Timer.IsEnabled).StopTimer(); } DayRegister.Controls.Move(DayRegister.Controls.IndexOf(this), 0); Timer.Start(); //TimerLabel.Foreground = new SolidColorBrush(Colors.Black); //TimerLabel.Background = new SolidColorBrush(Colors.White); this.Background = new SolidColorBrush(Colors.Green); ActiveTimeRow = new TimeRow() { Start = DateTime.Now, IsAddedManually = false, TaskName = this.TaskName, DesignerCode = this.DesignerCode, MainDesignerCode = this.MainDesignerCode, ClientCode = this.ClientCode, TraderCode = this.TraderCode }; Widget = new MCTMWidget.MainWindow(Timer, TaskName, ClientCode, Counter); Window.GetWindow(this).WindowState = WindowState.Minimized; Widget.Topmost = true; this.Visibility = System.Windows.Visibility.Hidden; Widget.ShowDialog(); this.Visibility = System.Windows.Visibility.Visible; Window.GetWindow(this).WindowState = WindowState.Normal; }
private void ChangeMinutes(bool isMinus) { try { var numberTimeSpan = isMinus ? -new TimeSpan(0, Convert.ToInt32(MinutesTextBox.Text), 0) : new TimeSpan(0, Convert.ToInt32(MinutesTextBox.Text), 0); if (this.Timer.IsEnabled != false) { ActiveTimeRow.DurationAddedManually += numberTimeSpan; ActiveTimeRow.IsAddedManually = true; Counter += numberTimeSpan; } else { var tr = new TimeRow() { Duration = numberTimeSpan, DurationAddedManually = numberTimeSpan, IsAddedManually = true, Start = DateTime.Now, End = DateTime.Now, TaskName = this.TaskName }; Counter += numberTimeSpan; ActiveTimeRow = tr; this.StopTimer(); } MinutesTextBox.Text = ""; TimerLabel.Content = Duration; } catch (Exception e) { MessageBoxResult result = MessageBox.Show("Nie wpisano ilości minut!"); //throw; } }
private async void _view_InsertButtonClick(object sender, EventArgs e) { _view.Status = "Виконується формування ряду. Будь ласка, зачекайте..."; string Row = _view.TextRow; DataGridView datagrid = _view.RowGrid; TimeRow rowtable = new TimeRow(); _view.StatusProgress.Visible = true; Func <bool> func = () => { try { char spliter = ' '; for (int i = 0; i < Row.Length; i++) { if (!(Char.IsDigit(Row[i])) && Row[i] != ',' && Row[i] != '-') { if (Row[i - 1] != ' ') { Row = Row.Replace(Row[i], ' '); } else { Row = Row.Remove(i, 1); i--; } } } if (!(Char.IsDigit(Row[Row.Length - 1]))) { Row = Row.Remove(Row.Length - 1, 1); } float[] array = Row.Split(spliter).Select((x) => (float)Convert.ToDouble(x)).ToArray(); rowtable.Row = array; return(true); } catch (Exception exception) { _message.ShowMessage(exception.Message); return(false); } }; bool task = await Task <bool> .Factory.StartNew(func); string message = task ? "Готово!" : "Невдача!"; _view.StatusProgress.Visible = false; _view.Status = message; _view.TextRow = Row; _view.SetRowGrid(rowtable.Row); RowGridDataChanged?.Invoke(this, EventArgs.Empty); _view.StartBtnEnable = task; rowtable.Dispose(); datagrid = null; Row = null; GC.Collect(); }
private async void _view_RandomRowClick(object sender, EventArgs e) { _view.Status = "Генерується ряд випадкових чисел. Будь ласка, зачекайте..."; string N = _view.N; string Row = ""; TimeRow rowtable = new TimeRow(); _view.StatusProgress.Visible = true; Func <bool> func = () => { try { TimeRow row = new TimeRow(Convert.ToInt32(N), 100); int max = row.GetSize(); int move = 0; int invokeVal = max / 10; rowtable = row; for (int i = 0; i < row.GetSize(); i++) { Row += Math.Round(row[i], 4); if (i < row.GetSize() - 1) { Row += '\r'; Row += '\n'; } move++; if (move % invokeVal == 0) { ProgressAction?.Invoke(10, move / invokeVal); } } row.Dispose(); return(true); } catch (Exception exception) { //_message.ShowError("Невірно задані параметри."); _message.ShowError(exception.Message); return(false); } }; bool task = await Task <bool> .Factory.StartNew(func); string message = task ? "Готово!" : "Невдача!"; _view.StatusProgress.Visible = false; _view.Status = message; _view.TextRow = Row; _view.SetRowGrid(rowtable.Row); RowGridDataChanged?.Invoke(this, EventArgs.Empty); _view.StartBtnEnable = task; Row = null; rowtable.Dispose(); GC.Collect(); }
private async void _view_ExceptClick(object sender, EventArgs e) { GC.Collect(); _view.Status = "Будується рекурентна діаграма за заданим числовим рядом. Будь ласка, зачекайте..."; string Row = _view.TextRow; DataGridView datagrid = _view.RowGrid; string E = _view.E; string AnalysisResult = ""; Image diagramRasterized = new Bitmap(_view.DiagramBox.Width, _view.DiagramBox.Height); Image diagramDistance = new Bitmap(_view.DistanceBox.Width, _view.DistanceBox.Height); Image scaleDistance = new Bitmap(_view.DistanceScaleBox.Width, _view.DistanceScaleBox.Height); _view.PointDiagram.Series[0].Points.Clear(); _view.SplineDiagram.Series[0].Points.Clear(); Chart pointDiagram = _view.PointDiagram.Copy(); Chart lineDiagram = _view.SplineDiagram.Copy(); _view.StartBtnEnable = false; _view.StopBtnEnable = true; _view.StatusProgress.Visible = true; Func <bool> func = () => { try { float[] array = new float[datagrid.RowCount - 1]; for (short i = 0; i < datagrid.RowCount - 1; i++) { array[i] = (float)Convert.ToDouble((datagrid.Rows[i].Cells[1].Value)); } TimeRow row = new TimeRow(array); double epsilon = Convert.ToDouble(E); ManageDiagrams(row, epsilon, ref diagramRasterized, ref diagramDistance, ref scaleDistance, ref pointDiagram, ref lineDiagram, ref AnalysisResult); return(true); } catch (Exception exception) { _message.ShowError(exception.Message); return(false); } }; bool task = await Task <bool> .Factory.StartNew(func); string message = task ? "Готово!" : "Невдача!"; _view.StatusProgress.Visible = false; _view.Status = message; _view.PointDiagram.Series[0] = pointDiagram.Series[0]; _view.SplineDiagram.Series[0] = lineDiagram.Series[0]; _view.DiagramBox.Image = diagramRasterized; _view.DistanceBox.Image = diagramDistance; _view.DistanceScaleBox.Image = scaleDistance; _view.Analysis = AnalysisResult; _view.StartBtnEnable = true; _view.StopBtnEnable = false; Row = null; datagrid = null; E = null; AnalysisResult = null; diagramRasterized = null; diagramDistance = null; scaleDistance = null; pointDiagram = null; lineDiagram = null; GC.Collect(); }