Mercurial > defical
comparison defical-sharp/defical-gui/main.xaml.cs @ 0:ebed2bd0d300
Initial import from svn. History be damned.
author | Edho P. Arief <me@myconan.net> |
---|---|
date | Fri, 02 Apr 2010 23:11:57 +0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ebed2bd0d300 |
---|---|
1 using System; | |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using System.Text; | |
5 using System.Windows; | |
6 using System.Windows.Controls; | |
7 using System.Windows.Data; | |
8 using System.Windows.Documents; | |
9 using System.Windows.Input; | |
10 using System.Windows.Media; | |
11 using System.Windows.Media.Imaging; | |
12 using System.Windows.Navigation; | |
13 using System.Windows.Shapes; | |
14 using System.IO; | |
15 | |
16 namespace defical_gui | |
17 { | |
18 /// <summary> | |
19 /// Interaction logic for Window1.xaml | |
20 /// </summary> | |
21 public partial class main : Window | |
22 { | |
23 public main() | |
24 { | |
25 InitializeComponent(); | |
26 initBoxes(); | |
27 txtNumN.Focus(); | |
28 } | |
29 private delegate void StringDelegate(int errCode,string message); | |
30 private void printMessage(int errCode,string message) | |
31 { | |
32 switch (errCode) | |
33 { | |
34 case 0: | |
35 { | |
36 txtResult.Text += message; | |
37 break; | |
38 } | |
39 default: | |
40 { | |
41 switch (errCode) | |
42 { | |
43 case 200: | |
44 { | |
45 message = "Started"; | |
46 break; | |
47 } | |
48 case 201: | |
49 { | |
50 message = "Stopped"; | |
51 break; | |
52 } | |
53 case 400: | |
54 { | |
55 message = "Found"; | |
56 break; | |
57 } | |
58 case 401: | |
59 { | |
60 message = "SEMT Labeing can't be constructed with first label of " + message; | |
61 break; | |
62 } | |
63 | |
64 } | |
65 txtResult.Text += "[" + errCode.ToString() + "] " + DateTime.Now.ToString("[yyyy-MM-dd hh:mm:ss]") + ": " + message+"\n"; | |
66 break; | |
67 } | |
68 } | |
69 } | |
70 private void initBoxes() | |
71 { | |
72 this.isProcessing = false; | |
73 txtResult.Text = | |
74 txtNumDef.Text = | |
75 txtNumN.Text = ""; | |
76 validateInput(); | |
77 } | |
78 private void txtResult_TextChanged(object sender, TextChangedEventArgs e) | |
79 { | |
80 switchControls(this.isProcessing); | |
81 if (txtResult.Text == "") { btnSave.IsEnabled = false; } else { btnSave.IsEnabled = true; } | |
82 txtResult.ScrollToEnd(); | |
83 } | |
84 private bool validateInput() | |
85 { | |
86 btnStart.IsEnabled = false; | |
87 if (txtNumN.Text == "" || txtNumDef.Text == "") { return false; } | |
88 try | |
89 { | |
90 int numN = Convert.ToInt32(txtNumN.Text); | |
91 int numDef = Convert.ToInt32(txtNumDef.Text); | |
92 if (numN.ToString() == txtNumN.Text | |
93 && numDef.ToString() == txtNumDef.Text | |
94 && numN >= 3 | |
95 && numDef >= 0) | |
96 { | |
97 btnStart.IsEnabled = true; | |
98 return true; | |
99 } | |
100 } | |
101 catch { return false; } | |
102 return false; | |
103 } | |
104 private void switchControls(bool isWorking) | |
105 { | |
106 grpGraph.IsEnabled = | |
107 grpLabels.IsEnabled = | |
108 btnStart.IsEnabled = !isWorking; | |
109 btnStop.IsEnabled = | |
110 barProgress.IsIndeterminate = isWorking; | |
111 } | |
112 | |
113 private void txtNumN_TextChanged(object sender, TextChangedEventArgs e) | |
114 { | |
115 validateInput(); | |
116 } | |
117 | |
118 private void txtNumDef_TextChanged(object sender, TextChangedEventArgs e) | |
119 { | |
120 validateInput(); | |
121 } | |
122 | |
123 private void btnStart_Click(object sender, RoutedEventArgs e) | |
124 { | |
125 if (!validateInput()) { return; } | |
126 switchControls(true); | |
127 try | |
128 { | |
129 this.isFindEverything = (bool)chkIsFindAll.IsChecked; | |
130 switch (cmbGraphType.Text) | |
131 { | |
132 case "Wheel": | |
133 this.graphType= "wheel"; | |
134 break; | |
135 case "Fan": | |
136 this.graphType = "fan"; | |
137 break; | |
138 case "Double Fan": | |
139 this.graphType = "doublefan"; | |
140 break; | |
141 default: | |
142 throw new NotImplementedException(); | |
143 } | |
144 this.numVerDef = Convert.ToInt32(txtNumDef.Text); | |
145 int numExtraVer = 0; | |
146 switch (this.graphType) | |
147 { | |
148 case "wheel": | |
149 case "fan": | |
150 { | |
151 numExtraVer = 1; | |
152 break; | |
153 } | |
154 case "doublefan": | |
155 { | |
156 numExtraVer = 2; | |
157 break; | |
158 } | |
159 default: | |
160 throw new NotImplementedException(); | |
161 } | |
162 this.numVerMain = numExtraVer + Convert.ToInt32(txtNumN.Text); | |
163 mainThread = new System.Threading.Thread(go); | |
164 mainThread.IsBackground = true; | |
165 mainThread.Start(); | |
166 } | |
167 catch | |
168 { | |
169 switchControls(false); | |
170 } | |
171 } | |
172 | |
173 private void btnStop_Click(object sender, RoutedEventArgs e) | |
174 { | |
175 this.isProcessing = false; | |
176 switchControls(false); | |
177 } | |
178 | |
179 private void btnSave_Click(object sender, RoutedEventArgs e) | |
180 { | |
181 try | |
182 { | |
183 System.Windows.Forms.SaveFileDialog dialogSave = new System.Windows.Forms.SaveFileDialog(); | |
184 dialogSave.DefaultExt = "txt"; | |
185 dialogSave.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*"; | |
186 dialogSave.AddExtension = true; | |
187 dialogSave.RestoreDirectory = true; | |
188 dialogSave.Title = "Save result"; | |
189 dialogSave.InitialDirectory = Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"); | |
190 dialogSave.FileName = "result-" + cmbGraphType.Text + "-" + txtNumN.Text + "," + txtNumDef.Text; | |
191 if (dialogSave.ShowDialog() == System.Windows.Forms.DialogResult.OK) | |
192 { | |
193 StreamWriter fileWriter = null; | |
194 if (File.Exists(dialogSave.FileName)) { fileWriter = File.AppendText(dialogSave.FileName); } | |
195 else { fileWriter = File.CreateText(dialogSave.FileName); } | |
196 fileWriter.Write(txtResult.Text); | |
197 fileWriter.Close(); | |
198 } | |
199 } | |
200 catch { } | |
201 } | |
202 | |
203 private void btnClear_Click(object sender, RoutedEventArgs e) | |
204 { | |
205 txtResult.Text = ""; | |
206 } | |
207 private void btnExit_Click(object sender, RoutedEventArgs e) | |
208 { | |
209 this.Close(); | |
210 } | |
211 } | |
212 } |