private void Open_Click(object sender, RoutedEventArgs e) { ObservableCollection <Box> BoxesTmp; Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".txt"; dlg.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; Nullable <bool> result = dlg.ShowDialog(); if (result == true) { string filename = dlg.FileName; System.IO.StreamReader file = new System.IO.StreamReader(filename); string line = file.ReadToEnd(); if ((BoxesTmp = InputOutput.InitializeList(line)) == null) { MessageBox.Show("Errors in text file"); } else { Boxes.CzyscListe(); Boxes.DodajPudelka(BoxesTmp); Boxes.UstawPionowo(); fillCanvas(MyCanvas, Boxes); GridView.IsVisible = false; IsCalculated = false; } } }
public void TestLoad() { string filename = @"C:\Users\Mike\Desktop\t.txt"; System.IO.StreamReader file = new System.IO.StreamReader(filename); string line = file.ReadToEnd(); var BoxesTmp = InputOutput.InitializeList(line); var Boxes = new BoxList(); Boxes.CzyscListe(); Boxes.DodajPudelka(BoxesTmp); Boxes.UstawPionowo(); foreach (var item in Boxes.ListBox) { Assert.IsTrue(item.Width <= item.Height); } BoxList A = new BoxList(); BoxList B = new BoxList(); A.DodajPudelka(Boxes.GetBoxList()); B.DodajPudelka(Boxes.GetBoxList()); A.SortujPudelka(true); B.SortujPudelka(false); for (int i = 0; i < A.ListBox.Count - 2; i++) { Assert.IsTrue(A.ListBox[i].Height <= A.ListBox[i + 1].Height); } for (int i = 0; i < B.ListBox.Count - 2; i++) { Assert.IsTrue(B.ListBox[i].Width <= B.ListBox[i + 1].Width); } }
private void _Start_Click(object sender, RoutedEventArgs e) { if (IsCalculated) { return; } if (Boxes.GetBoxNumber() == 0) { return; } Boxes.UstawPionowo(); BoxList A = new BoxList(); BoxList B = new BoxList(); A.DodajPudelka(Boxes.GetBoxList()); B.DodajPudelka(Boxes.GetBoxList()); A.SortujPudelka(true); B.SortujPudelka(false); var watch = Stopwatch.StartNew(); var tmp = Algorithm.NajdluzszyWspolnyPodciag(A.GetBoxList(), B.GetBoxList()); watch.Stop(); IsCalculated = true; FillData(watch.ElapsedMilliseconds.ToString(), tmp); SortedBoxes.ListBox = tmp; fillCanvas(SortedCanvas, SortedBoxes); }