Class: | SampleAppPlus.MainWindow |
---|---|
Assembly: | SampleAppPlus |
File(s): | C:\SampleAppPlus\SampleAppPlus\MainWindow.xaml C:\SampleAppPlus\SampleAppPlus\MainWindow.xaml.cs |
Covered lines: | 70 |
Uncovered lines: | 7 |
Coverable lines: | 77 |
Total lines: | 165 |
Line coverage: | 90.9% |
Branch coverage: | 75% |
Method | Cyclomatic Complexity | Sequence Coverage | Branch Coverage |
---|---|---|---|
.ctor() | 1 | 100 | 100 |
buttonBrowse_Click(...) | 3 | 72 | 60 |
buttonAdd_Click(...) | 2 | 100 | 100 |
buttonEdit_Click(...) | 2 | 100 | 100 |
.cctor() | 1 | 100 | 100 |
InitializeComponent() | 2 | 100 | 100 |
System.Windows.Markup.IComponentConnector.Connect(...) | 9 | 100 | 100 |
# | Line | Line coverage | ||
---|---|---|---|---|
2 | 1 | <Window x:Class="SampleAppPlus.MainWindow" | ||
2 | xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
3 | xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
4 | xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" | |||
5 | xmlns:my="clr-namespace:SampleAppPlus" | |||
6 | Title="MainWindow" Height="500" Width="550"> | |||
7 | <Grid x:Name="mainGrid"> | |||
8 | <Button Content="Browse" | |||
9 | Height="30" | |||
10 | Width="140" | |||
11 | HorizontalAlignment="Left" | |||
12 | VerticalAlignment="Top" | |||
2 | 13 | Click="buttonBrowse_Click" | ||
14 | Name="buttonBrowse" | |||
15 | Margin="20,20,0,0" /> | |||
16 | <Image Name="MyImage" | |||
17 | Width="230" | |||
18 | Height="230" | |||
19 | HorizontalAlignment="Left" | |||
20 | VerticalAlignment="Top" | |||
21 | Stretch="Fill" | |||
22 | Margin="20,70,0,0" /> | |||
23 | <Grid Width="230" | |||
24 | Height="230" | |||
25 | HorizontalAlignment="Right" | |||
26 | VerticalAlignment="Top" | |||
27 | Margin="0,70,20,0"> | |||
28 | <WindowsFormsHost x:Name="myHost" /> | |||
29 | </Grid> | |||
30 | <Polyline Stroke="Black" | |||
31 | StrokeThickness="2" | |||
32 | Points="20,320,530,320" /> | |||
33 | <my:CustomControl x:Name="CustomControl" | |||
34 | Width="510" | |||
35 | Height="50" | |||
36 | HorizontalAlignment="Left" | |||
37 | VerticalAlignment="Bottom" | |||
38 | Margin="20,20,20,70" /> | |||
39 | <Button Content="Add Text" | |||
40 | Height="30" | |||
41 | Width="140" | |||
42 | HorizontalAlignment="Left" | |||
43 | VerticalAlignment="Bottom" | |||
2 | 44 | Click="buttonAdd_Click" | ||
45 | Name="buttonAdd" | |||
46 | Margin="20,0,0,20" /> | |||
47 | <Button Content="Edit Text" | |||
48 | Height="30" | |||
49 | Width="140" | |||
50 | HorizontalAlignment="Right" | |||
51 | VerticalAlignment="Bottom" | |||
2 | 52 | Click="buttonEdit_Click" | ||
53 | Name="buttonEdit" | |||
54 | Margin="0,0,20,20" /> | |||
55 | </Grid> | |||
56 | </Window> |
# | Line | Line coverage | ||
---|---|---|---|---|
1 | using System; | |||
2 | using System.IO; | |||
3 | using System.Windows; | |||
4 | using System.Windows.Forms; | |||
5 | using System.Windows.Forms.Integration; | |||
6 | using System.Windows.Media.Imaging; | |||
7 |
| |||
8 | namespace SampleAppPlus | |||
9 | { | |||
10 | /// <summary> | |||
11 | /// Interaction logic for MainWindow.xaml | |||
12 | /// </summary> | |||
13 | public partial class MainWindow : Window | |||
14 | { | |||
2 | 15 | private static Action EmptyDelegate = delegate() { }; | ||
16 | private DataGridView dataGridView; | |||
17 |
| |||
2 | 18 | public MainWindow() | ||
2 | 19 | { | ||
2 | 20 | InitializeComponent(); | ||
21 | // Initialize host | |||
2 | 22 | myHost = new WindowsFormsHost(); | ||
2 | 23 | myHost.Width = 230; | ||
2 | 24 | myHost.Height = 230; | ||
2 | 25 | myHost.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; | ||
2 | 26 | myHost.VerticalAlignment = System.Windows.VerticalAlignment.Top; | ||
2 | 27 | myHost.Margin = new Thickness(0, 70, 20, 0); | ||
28 | // Initialize grid | |||
2 | 29 | dataGridView = new DataGridView(); | ||
2 | 30 | dataGridView.ReadOnly = true; | ||
2 | 31 | dataGridView.AllowUserToAddRows = false; | ||
2 | 32 | dataGridView.RowHeadersVisible = false; | ||
33 | // Add columnt to grid | |||
34 | DataGridViewColumn col; | |||
2 | 35 | col = new DataGridViewColumn(); | ||
2 | 36 | col.CellTemplate = new DataGridViewTextBoxCell(); | ||
2 | 37 | col.Name = "File Name"; | ||
2 | 38 | col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; | ||
2 | 39 | dataGridView.Columns.Add(col); | ||
40 | // Add grid to host | |||
2 | 41 | myHost.Child = dataGridView; | ||
42 | // Add host to window main grid | |||
2 | 43 | mainGrid.Children.Add(myHost); | ||
44 | // Redraw window | |||
2 | 45 | WindowStyle = WindowStyle.ThreeDBorderWindow; | ||
46 | // Initialise custom control | |||
2 | 47 | CustomControl.Message = "No file..."; | ||
2 | 48 | } | ||
49 |
| |||
50 | private void buttonBrowse_Click(object sender, RoutedEventArgs e) | |||
2 | 51 | { | ||
2 | 52 | Stream checkStream = null; | ||
2 | 53 | Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); | ||
2 | 54 | openFileDialog.Multiselect = false; | ||
2 | 55 | openFileDialog.Filter = "All Image Files | *.*"; | ||
56 |
| |||
2 | 57 | if ((bool)openFileDialog.ShowDialog()) | ||
2 | 58 | { | ||
59 | try | |||
2 | 60 | { | ||
2 | 61 | if ((checkStream = openFileDialog.OpenFile()) != null) | ||
2 | 62 | { | ||
2 | 63 | MyImage.Source = new BitmapImage(new Uri(openFileDialog.FileName, UriKind.Absolute)); | ||
2 | 64 | CustomControl.Message = openFileDialog.FileName; | ||
2 | 65 | dataGridView.Rows.Add(new object[] { openFileDialog.FileName }); | ||
2 | 66 | System.Windows.MessageBox.Show("Successfully done"); | ||
2 | 67 | } | ||
2 | 68 | } | ||
0 | 69 | catch (Exception ex) | ||
0 | 70 | { | ||
0 | 71 | System.Windows.MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message | ||
0 | 72 | } | ||
73 |
| |||
2 | 74 | } | ||
75 | else | |||
0 | 76 | { | ||
0 | 77 | System.Windows.MessageBox.Show("Problem occured, try again later"); | ||
0 | 78 | } | ||
2 | 79 | } | ||
80 |
| |||
81 | private void buttonAdd_Click(object sender, RoutedEventArgs e) | |||
3 | 82 | { | ||
3 | 83 | AddText form = new AddText(); | ||
3 | 84 | form.text.Focus(); | ||
3 | 85 | bool? result = form.ShowDialog(); | ||
3 | 86 | if (result.Value) | ||
2 | 87 | { | ||
2 | 88 | CustomControl.Message = form.text.Text; | ||
2 | 89 | dataGridView.Rows.Add(new object[] { form.text.Text }); | ||
2 | 90 | dataGridView.ClearSelection(); | ||
2 | 91 | } | ||
3 | 92 | } | ||
93 |
| |||
94 | private void buttonEdit_Click(object sender, RoutedEventArgs e) | |||
3 | 95 | { | ||
3 | 96 | EditText form = new EditText(); | ||
3 | 97 | form.text.Focus(); | ||
3 | 98 | form.text.Text = dataGridView.Rows[dataGridView.CurrentCell.RowIndex].Cells[0].Value as string; | ||
3 | 99 | form.currentText.Text = CustomControl.Message; | ||
3 | 100 | bool? result = form.ShowDialog(); | ||
3 | 101 | if (result.Value) | ||
2 | 102 | { | ||
2 | 103 | CustomControl.Message = form.text.Text; | ||
2 | 104 | dataGridView.Rows[dataGridView.CurrentCell.RowIndex].SetValues(form.text.Text); | ||
2 | 105 | dataGridView.ClearSelection(); | ||
2 | 106 | } | ||
3 | 107 | } | ||
108 | } | |||
109 | } |