No Description

RLWindow.xaml.cs 53KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  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.Shapes;
  13. using System.Globalization;
  14. using WpfLocalization;
  15. using System.Threading;
  16. using System.Data.SqlClient;
  17. using System.Data;
  18. using System.Diagnostics;
  19. using System.IO;
  20. using System.Collections;
  21. using System.IO.Ports;
  22. using System.Collections.ObjectModel;
  23. using System.Reflection;
  24. using System.Configuration;
  25. using System.Collections.Specialized;
  26. using System.Data.SqlServerCe;
  27. using System.ComponentModel;
  28. using System.Windows.Threading;
  29. using System.Data.OleDb;
  30. namespace WpfApplication19
  31. {
  32. /// <summary>
  33. /// Interaction logic for RLWindow.xaml
  34. /// </summary>
  35. public partial class RLWindow : Window
  36. {
  37. private bool isFullScreen = false;
  38. private Debug dw;
  39. public SqlConnection configConn, masterConn, transConn, proConn;
  40. private SqlCeConnection _opConn;
  41. //private SqlDataReader reader;
  42. string[] obTables = new string[] {"BEL-MAS-1", "BEL-MAS-3", "E-MAS-1", "E-MAS-3",
  43. "MG-MAS-1", "MG-MAS-3", "V-MAS-1", "V-MAS-3"};
  44. public SerialPort comport = new SerialPort();
  45. ObservableCollection<MeasurePoint> mps;
  46. int nextCol = 3;
  47. bool isMiddle = false, _haveMiddle = false;
  48. bool _isIn = false;
  49. public string inStarGS = "";
  50. public string midGS = "";
  51. string sMi16, sMi20, kind;
  52. enum RecordTypes { TopUnder, InOut }
  53. string[] masViews = new string[] { "bel_master_view", "e_master_view", "mg_master_view", "v_master_view" };
  54. List<string> list;
  55. string header;
  56. Stack<string> _lastAction = new Stack<string>();
  57. bool _isTkx = false;
  58. DateTime _lastTimeDataPort;
  59. bool _isCheck = false;
  60. DailyCheck _dc;
  61. RLWindow _rlWindow;
  62. Encoding encAscii = Encoding.ASCII;
  63. Dictionary<string, string> rolesDescription = new Dictionary<string, string>
  64. {
  65. {"qa_staff", "QA Staff"},{"user","User"}, {"admin", "Administrator"}, {"qa_man", "QA Ass't Manager"}
  66. };
  67. Dictionary<string, string> _sideMap = new Dictionary<string, string>
  68. {
  69. {"out", "in"},{"in","under"}, {"rim", "base"}, {"top", "under"}, {"outer", "inner"}
  70. };
  71. private double out0, out1;
  72. private double in0, in1;
  73. MeasurePoint currentMP;
  74. string currentColumn;
  75. Debug _debugWindow;
  76. Thread _aThread, _bThread;
  77. bool _clearThread = false, _canSent = true;
  78. int _pattern = 1;
  79. string _updated_at;
  80. private int _obLimit, _obCount, _ocLimit, _ocCount, _rhLimit, _rhCount;
  81. bool _isOver = false;
  82. bool _isFirstMeasure = true;
  83. DateTime _startUsing = new DateTime();
  84. int _usingTime;
  85. bool _isExisting = false;
  86. private List<string> _agreementList = new List<string>();
  87. string _currentValue, _prevValue = null;
  88. double _lower1, _upper1, _lower2, _upper2;
  89. string strAccessConnEMASTER = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.0.253\\mgt\\master\\E-Master.mdb;Mode=Share Deny None";
  90. string strAccessConnBELMASTER = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.0.253\\mgt\\master\\BEL-Master.mdb;Mode=Share Deny None";
  91. string strAccessConnMGMASTER = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.0.253\\mgt\\master\\MG-Master.mdb;Mode=Share Deny None";
  92. string strAccessConnVMASTER = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\192.168.0.253\\mgt\\master\\V-Master.mdb;Mode=Share Deny None";
  93. OleDbConnection accessConnEMASTER = null;
  94. OleDbConnection accessConnBELMASTER = null;
  95. OleDbConnection accessConnMGMASTER = null;
  96. OleDbConnection accessConnVMASTER = null;
  97. OleDbConnection tempConn = null;
  98. RLAlert rlAlert;
  99. public RLWindow()
  100. {
  101. InitializeComponent();
  102. lotNo.Focus();
  103. initDatabaseConnection();
  104. }
  105. public void closeFromAlert()
  106. {
  107. this.rlAlert.Close();
  108. this.Close();
  109. }
  110. private void initDatabaseConnection()
  111. {
  112. try
  113. {
  114. _opConn = Utils.createSqlCeConnection("operatingDbCS");
  115. // Sample usage
  116. /*
  117. SqlCeDataReader reader;
  118. reader = Utils.Query(_opConn, "select * from UsingTime");
  119. while(reader.Read()){
  120. Console.WriteLine("hello");
  121. }
  122. reader.Close();
  123. */
  124. }
  125. catch (SqlCeException se)
  126. {
  127. MessageBox.Show("operatingDbCS : ", se.Message);
  128. }
  129. /*
  130. try
  131. {
  132. configConn = Utils.createSqlConnection("configDbCS");
  133. }
  134. catch (SqlException se)
  135. {
  136. MessageBox.Show("configDbCS : ", se.Message);
  137. }
  138. try
  139. {
  140. masterConn = Utils.createSqlConnection("masterDbCS");
  141. }
  142. catch (SqlException se)
  143. {
  144. MessageBox.Show("masterDbCS : ", se.Message);
  145. }
  146. try
  147. {
  148. transConn = Utils.createSqlConnection("tranDbCS");
  149. }
  150. catch (SqlException se)
  151. {
  152. MessageBox.Show("tranDbCS : ", se.Message);
  153. }
  154. */
  155. try
  156. {
  157. proConn = Utils.createSqlConnection("productionDbCS");
  158. transConn = Utils.createSqlConnection("productionDbCS");
  159. masterConn = Utils.createSqlConnection("productionDbCS");
  160. configConn = Utils.createSqlConnection("productionDbCS");
  161. }
  162. catch (SqlException se)
  163. {
  164. MessageBox.Show("productionDbCS : ", se.Message);
  165. }
  166. //mod: change config by move every table alias
  167. //transConn = masterConn = configConn = proConn;
  168. /*
  169. try
  170. {
  171. accessConnEMASTER = new OleDbConnection(strAccessConnEMASTER);
  172. accessConnEMASTER.Open();
  173. }
  174. catch (Exception ex)
  175. {
  176. MessageBox.Show("Error: Failed to create e-master connection. \n{0}", ex.Message);
  177. }
  178. try
  179. {
  180. accessConnBELMASTER = new OleDbConnection(strAccessConnBELMASTER);
  181. accessConnBELMASTER.Open();
  182. }
  183. catch (Exception ex)
  184. {
  185. MessageBox.Show("Error: Failed to create e-master connection. \n{0}", ex.Message);
  186. }
  187. try
  188. {
  189. accessConnMGMASTER = new OleDbConnection(strAccessConnMGMASTER);
  190. accessConnMGMASTER.Open();
  191. }
  192. catch (Exception ex)
  193. {
  194. MessageBox.Show("Error: Failed to create e-master connection. \n{0}", ex.Message);
  195. }
  196. try
  197. {
  198. accessConnVMASTER = new OleDbConnection(strAccessConnVMASTER);
  199. accessConnVMASTER.Open();
  200. }
  201. catch (Exception ex)
  202. {
  203. MessageBox.Show("Error: Failed to create e-master connection. \n{0}", ex.Message);
  204. }*/
  205. }
  206. private void addRow_Click(object sender, RoutedEventArgs e)
  207. {
  208. if (measureGrid.ItemsSource == null)
  209. return;
  210. _lastAction.Push("row");
  211. MeasurePoint m = mps.Last();
  212. int count = 1;
  213. foreach (var l in list)
  214. {
  215. mps.Add(new MeasurePoint() { Count = m.Count + 1, Type = l, SubOrder = count });
  216. count++;
  217. }
  218. }
  219. private void addMeasureColumn_Click(object sender, RoutedEventArgs e)
  220. {
  221. _lastAction.Push("column");
  222. if (nextCol <= 10)
  223. {
  224. measureGrid.Columns.ElementAt(++nextCol).Visibility = Visibility.Visible;
  225. foreach (var item in measureGrid.Items)
  226. {
  227. //Console.WriteLine(item);
  228. MeasurePoint c = item as MeasurePoint;
  229. c.Avg = (c.P1 + c.P2 + c.P3 + c.P4 + c.P6 + c.P7 + c.P8 + c.P9 + c.P10) / nextCol;
  230. c.Avg = Math.Round(c.Avg, 2);
  231. if (c.SubOrder == 1)
  232. {
  233. c.Grade = computeGrade(sMi16, c.Avg, kind, "-", c.Type);
  234. }
  235. else if (c.SubOrder != 1 && c.Type != "MID" && c.Type != "IN*")
  236. {
  237. if (sMi20 != "0")
  238. c.Grade = computeGrade(sMi20, c.Avg, kind, "-", c.Type);
  239. else
  240. c.Grade = computeGrade(sMi16, c.Avg, kind, "-", c.Type);
  241. }
  242. }
  243. measureGrid.Items.Refresh();
  244. }
  245. }
  246. private void removeMeasureColumn_Click(object sender, RoutedEventArgs e)
  247. {
  248. _lastAction.Push("remove_column");
  249. measureGrid.Columns.ElementAt(nextCol).Visibility = Visibility.Hidden;
  250. if (nextCol <= 10)
  251. {
  252. measureGrid.Columns.ElementAt(--nextCol).Visibility = Visibility.Visible;
  253. foreach (var item in measureGrid.Items)
  254. {
  255. //Console.WriteLine(item);
  256. MeasurePoint c = item as MeasurePoint;
  257. c.setValue((nextCol + 1).ToString(), 0);
  258. computeValues(c, true);
  259. }
  260. measureGrid.Items.Refresh();
  261. }
  262. }
  263. private void addMiddleBtn_Click(object sender, RoutedEventArgs e)
  264. {
  265. if (measureGrid.ItemsSource == null)
  266. return;
  267. _lastAction.Push("middle");
  268. this.isMiddle = !this.isMiddle;
  269. if (this.isMiddle == false)
  270. {
  271. middleText.Text = "Add Middle";
  272. RemoveMid();
  273. }
  274. else
  275. {
  276. middleText.Text = "Remove Middle";
  277. EditMIDWindow w = new EditMIDWindow();
  278. w.ShowDialog();
  279. AddMid();
  280. }
  281. //this.measureGrid.CommitEdit();
  282. measureGrid.Items.Refresh();
  283. }
  284. private void RemoveMid()
  285. {
  286. list.Remove("MID");
  287. ObservableCollection<MeasurePoint> temp = new ObservableCollection<MeasurePoint>();
  288. foreach (var m in mps)
  289. {
  290. if (m.Type != "MID")
  291. {
  292. temp.Add(m);
  293. }
  294. }
  295. mps = temp;
  296. measureGrid.ItemsSource = null;
  297. measureGrid.ItemsSource = mps;
  298. }
  299. private void AddMid()
  300. {
  301. list.Insert(1, "MID");
  302. ObservableCollection<MeasurePoint> temp = new ObservableCollection<MeasurePoint>();
  303. foreach (var m in mps)
  304. {
  305. temp.Add(m);
  306. if (m.SubOrder == 1)
  307. {
  308. temp.Add(new MeasurePoint() { Type = "MID", SubOrder = m.SubOrder + 1, Count = m.Count });
  309. }
  310. }
  311. mps = temp;
  312. measureGrid.ItemsSource = null;
  313. measureGrid.ItemsSource = mps;
  314. }
  315. private void AddIn()
  316. {
  317. list.Insert(1, "IN*");
  318. ObservableCollection<MeasurePoint> temp = new ObservableCollection<MeasurePoint>();
  319. foreach (var m in mps)
  320. {
  321. temp.Add(m);
  322. if (m.SubOrder == 1)
  323. {
  324. temp.Add(new MeasurePoint() { Type = "IN*", SubOrder = m.SubOrder + 1, Count = m.Count });
  325. }
  326. }
  327. mps = temp;
  328. measureGrid.ItemsSource = null;
  329. measureGrid.ItemsSource = mps;
  330. }
  331. public void setFilterLogData(string q)
  332. {
  333. //MessageBox.Show("RL Called");
  334. _isExisting = true;
  335. this._updated_at = q;
  336. }
  337. private void addInBtn_Click(object sender, RoutedEventArgs e)
  338. {
  339. //measureGrid.ItemsSource = null;
  340. if (measureGrid.ItemsSource == null)
  341. return;
  342. _isIn = !_isIn;
  343. if (_isIn == false)
  344. {
  345. inText.Text = "Add IN*";
  346. RemoveIn();
  347. }
  348. else
  349. {
  350. inText.Text = "Remove IN*";
  351. EditINWindow w = new EditINWindow();
  352. w.ShowDialog();
  353. AddIn();
  354. }
  355. //ObservableCollection<MeasurePoint> temp = new ObservableCollection<MeasurePoint>();
  356. _lastAction.Push("in");
  357. measureGrid.Items.Refresh();
  358. /*
  359. for(int i = 0; i < mps.Count; i++){
  360. var mp = mps[i];
  361. if(mp.SubOrder == 1){
  362. mps.Insert(mps.IndexOf(mp) + 1, new MeasurePoint() { Count = mp.Count, Type = "IN*", SubOrder = 3});
  363. }
  364. }
  365. measureGrid.ItemsSource = mps;
  366. */
  367. //measureGrid.ItemsSource = null;
  368. //measureGrid.Items.Add(0, new MeasurePoint() { Count = 1, Type = "In"});
  369. }
  370. private void RemoveIn()
  371. {
  372. list.Remove("IN*");
  373. ObservableCollection<MeasurePoint> temp = new ObservableCollection<MeasurePoint>();
  374. foreach (var m in mps)
  375. {
  376. if (m.Type != "IN*")
  377. {
  378. temp.Add(m);
  379. }
  380. }
  381. mps = temp;
  382. measureGrid.ItemsSource = null;
  383. measureGrid.ItemsSource = mps;
  384. }
  385. private void deleteData_Click(object sender, RoutedEventArgs e)
  386. {
  387. this.currentMP.setValue(currentColumn, 0);
  388. this.computeValues(currentMP, true);
  389. measureGrid.Items.Refresh();
  390. }
  391. private void computeValues(MeasurePoint c, bool isCompGrade = false)
  392. {
  393. c.Avg = (c.P1 + c.P2 + c.P3 + c.P4 + c.P5 + c.P6 + c.P7 + c.P8 + c.P9 + c.P10) / nextCol;
  394. c.Avg = Math.Round(c.Avg, 2);
  395. if (isCompGrade == true)
  396. {
  397. if (c.SubOrder == 1)
  398. {
  399. c.Grade = computeGrade(sMi16, c.Avg, kind, "-", c.Type);
  400. }
  401. else if (c.SubOrder != 1 && c.Type != "MID" && c.Type != "IN*")
  402. {
  403. if (sMi20 != "0")
  404. c.Grade = computeGrade(sMi20, c.Avg, kind, "-", c.Type);
  405. else
  406. c.Grade = computeGrade(sMi16, c.Avg, kind, "-", c.Type);
  407. }
  408. else if (c.Type == "MID" || c.Type == "IN*")
  409. {
  410. c.Grade = computeGrade("0", c.Avg, kind, "-", c.Type);
  411. }
  412. }
  413. if (c.SubOrder == 1 || c.Type == "IN*" || c.Type == "MID" || c.Type == "FA1" || c.Type == "FA2")
  414. {
  415. if (this.header == "OB" || this.header == "OC")
  416. {
  417. if (c.Avg >= this.out0 && c.Avg <= this.out1)
  418. {
  419. c.ResultGrade = "OK";
  420. }
  421. else if (c.Avg < this.out0)
  422. {
  423. c.ResultGrade = "Hard";
  424. }
  425. else if (c.Avg > this.out1)
  426. {
  427. c.ResultGrade = "Soft";
  428. }
  429. }
  430. else
  431. {
  432. if (c.Avg >= this.out0 && c.Avg <= this.out1)
  433. {
  434. c.ResultGrade = "OK";
  435. }
  436. else if (c.Avg < this.out0)
  437. {
  438. c.ResultGrade = "Soft";
  439. }
  440. else if (c.Avg > this.out1)
  441. {
  442. c.ResultGrade = "Hard";
  443. }
  444. }
  445. }
  446. else if (c.SubOrder != 1)
  447. {
  448. if (this.header == "OB" || this.header == "OC")
  449. {
  450. if (c.Avg >= this.in0 && c.Avg <= this.in1)
  451. {
  452. c.ResultGrade = "OK";
  453. }
  454. else if (c.Avg < this.in0)
  455. {
  456. c.ResultGrade = "Hard";
  457. }
  458. else if (c.Avg > this.in1)
  459. {
  460. c.ResultGrade = "Soft";
  461. }
  462. }
  463. else
  464. {
  465. if (c.Avg >= this.in0 && c.Avg <= this.in1)
  466. {
  467. c.ResultGrade = "OK";
  468. }
  469. else if (c.Avg < this.in0)
  470. {
  471. c.ResultGrade = "Soft";
  472. }
  473. else if (c.Avg > this.in1)
  474. {
  475. c.ResultGrade = "Hard";
  476. }
  477. }
  478. }
  479. }
  480. private string computeGrade(string size, double lower, string kind, string defValue, string type)
  481. {
  482. double rlMin = double.Parse(RLMin.Text);
  483. double rlMax = double.Parse(RLMax.Text);
  484. if ((rlMin <= lower) && (rlMax >= lower))
  485. {
  486. return "OK";
  487. }
  488. else
  489. {
  490. return "Fail";
  491. }
  492. //return value;
  493. }
  494. //int row;
  495. private void saveCellBtn_Click(object sender, RoutedEventArgs e)
  496. {
  497. measureGrid.Focus();
  498. if (currentColumn == null)
  499. return;
  500. if (_isOver == true)
  501. return;
  502. /*
  503. if(_isFirstMeasure == true){
  504. _startUsing = DateTime.Now;
  505. _isFirstMeasure = false;
  506. }*/
  507. if (currentColumn != "Average" && currentColumn != "Grade" && currentColumn != "Result Grade")
  508. {
  509. this.currentMP.setValue(currentColumn, Convert.ToDouble(readingBox.Text));
  510. //var c = measureGrid.SelectedValue;
  511. this.computeValues(currentMP, true);
  512. }
  513. try
  514. {
  515. var info = measureGrid.CurrentColumn;
  516. var item = measureGrid.CurrentItem as MeasurePoint;
  517. int col = info.DisplayIndex;
  518. var mp = (MeasurePoint)measureGrid.CurrentItem;
  519. int row = mps.IndexOf(mp);
  520. //measureGrid.RaiseEvent(new RoutedEventArgs(DataGrid.rowediten));
  521. //MessageBox.Show("row " + item.Count.ToString());
  522. //MessageBox.Show("row " + mps.IndexOf(mp).ToString());
  523. //MessageBox.Show("col " + info.DisplayIndex.ToString());
  524. measureGrid.Items.Refresh();
  525. measureGrid.Focus();
  526. if (col < nextCol)
  527. {
  528. measureGrid.CurrentCell = new DataGridCellInfo(
  529. measureGrid.Items[row], measureGrid.Columns[col + 1]);
  530. measureGrid.BeginEdit();
  531. }
  532. else
  533. {
  534. try
  535. {
  536. //this.computeValues(currentMP, true);
  537. measureGrid.CurrentCell = new DataGridCellInfo(
  538. measureGrid.Items[row + 1], measureGrid.Columns[1]);
  539. measureGrid.SelectedItem = measureGrid.Items[row + 1];
  540. measureGrid.BeginEdit();
  541. }
  542. catch
  543. {
  544. measureGrid.CurrentCell = new DataGridCellInfo(
  545. measureGrid.Items[0], measureGrid.Columns[1]);
  546. measureGrid.SelectedItem = measureGrid.Items[0];
  547. measureGrid.BeginEdit();
  548. }
  549. }
  550. }
  551. catch
  552. {
  553. ;
  554. }
  555. }
  556. private void PrintLabel(string lotNo, DateTime dt)
  557. {
  558. string sql = string.Format("select * from data_rl where lot_no = '{0}' and created_at = '{1}' order by id", lotNo, dt);
  559. SqlDataReader reader = Utils.Query(proConn, sql);
  560. string s = "";
  561. int n = 0;
  562. List<double> outs = new List<double>();
  563. List<double> ins = new List<double>();
  564. bool outValid = false;
  565. bool inValid = false;
  566. string inAvg = "";
  567. string outAvg = "";
  568. int row = 0;
  569. int nrow = 0;
  570. while (reader.Read())
  571. {
  572. nrow++;
  573. n = Convert.ToInt32(reader["ndata"]);
  574. string r_type = reader["r_type"].ToString();
  575. try
  576. {
  577. r_type = r_type.Substring(0, 3);
  578. }
  579. catch
  580. {
  581. ;
  582. }
  583. s += string.Format("{0,3}", r_type.ToUpper()) + " ";
  584. for (int i = 1; i <= n; i++)
  585. {
  586. if (n > 3)
  587. {
  588. s += string.Format("{0,-3:0.00}", Convert.ToDouble(reader["p" + i])) + " ";
  589. }
  590. else
  591. {
  592. s += string.Format("{0,-3:0.00}", Convert.ToDouble(reader["p" + i])) + " ";
  593. }
  594. row++;
  595. }
  596. //s = s.Trim();
  597. var grade = reader["grade"].ToString().Trim();
  598. var rgrade = reader["rgrade"].ToString().Trim();
  599. try
  600. {
  601. if (n >= 5)
  602. rgrade = rgrade.Substring(0, 2);
  603. }
  604. catch
  605. {
  606. ;
  607. }
  608. //if (reader["rgrade"].ToString().ToLower() != "ok")
  609. //{
  610. // s += string.Format(" {0,-6:*0.00*}", Convert.ToDouble(reader["avg"])) + " " + string.Format("{0,-2}",grade) + " " + rgrade;
  611. //}
  612. //else
  613. //{
  614. if (n >= 5)
  615. {
  616. s += string.Format("{0,5:0.00}", Convert.ToDouble(reader["avg"])) + " " + string.Format("{0,-2}", grade);
  617. }
  618. else
  619. {
  620. s += string.Format("{0,7:0.00}", Convert.ToDouble(reader["avg"])) + " " + string.Format("{0,-2}", grade);
  621. }
  622. //}
  623. //s = s.Trim();
  624. s += "\n";
  625. /*
  626. UPP,UPPE = Out
  627. LOW,LOWE = In
  628. Rim = Out
  629. Base =In
  630. Soko = In
  631. IN* = In
  632. */
  633. if (r_type.ToUpper() == "OUT" || r_type.ToUpper() == "TOP" || r_type.ToUpper() == "FA1" || r_type.ToUpper() == "UPP" || r_type.ToUpper() == "UPPE" || r_type.ToUpper() == "RIM")
  634. {
  635. outs.Add(Convert.ToDouble(reader["avg"]));
  636. }
  637. if (r_type.ToUpper() == "IN" || r_type.ToUpper() == "UNDER" || r_type.ToUpper() == "UND" || r_type.ToUpper() == "FA2" || r_type.ToUpper() == "LOW" || r_type.ToUpper() == "LOWE" || r_type.ToUpper() == "BASE" || r_type.ToUpper() == "SOKO" || r_type.ToUpper() == "IN*")
  638. {
  639. ins.Add(Convert.ToDouble(reader["avg"]));
  640. }
  641. }
  642. //string avg = string.Format("{0.00}", Convert.ToDouble(reader["avg"]));
  643. double[] inArray = new double[] {
  644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  647. double[] outArray = new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  650. double sumIns = 0;
  651. double sumOuts = 0;
  652. for (int i = 0; i < ins.Count; i++)
  653. {
  654. inArray[i] = ins[i];
  655. sumIns += ins[i];
  656. }
  657. for (int i = 0; i < outs.Count; i++)
  658. {
  659. outArray[i] = outs[i];
  660. sumOuts += outs[i];
  661. }
  662. double avgIns = 0;
  663. if (ins.Count == 0)
  664. avgIns = 0;
  665. else
  666. avgIns = sumIns / ins.Count;
  667. double avgOut = 0;
  668. if (outs.Count == 0)
  669. avgOut = 0;
  670. else
  671. avgOut = sumOuts / outs.Count;
  672. reader.Close();
  673. sql = string.Format("select m.name , ls.avg, ls.grade, ls.start_time, ls.end_time, ls.code from lot_summary_rl ls, machines m where ls.lot_no = '{0}' and ls.created_at = '{1}' and ls.machine_id = m.id", lotNo, dt);
  674. reader = Utils.Query(proConn, sql);
  675. var temp = list;
  676. var types = string.Join("/", temp.ToArray());
  677. string code = "";
  678. string et = "";
  679. var w = (MainWindow)Application.Current.MainWindow;
  680. while (reader.Read())
  681. {
  682. code = reader["code"].ToString();
  683. s += string.Format("{0}(RL) {1} Times {2} AVG {3:0.00} \n", reader["name"].ToString(), w.UsingTimeTB.Text, types, Convert.ToDouble(reader["avg"]));
  684. var startTime = Convert.ToDateTime(reader["start_time"]);
  685. var endTime = Convert.ToDateTime(reader["end_time"]);
  686. et = string.Format("{0:dd/MM/yyyy HH:mm:ss}", endTime);
  687. s += string.Format("{0:dd/MM/yyyy} {1:HH:mm:ss}-{2:HH:mm:ss}\n", startTime, startTime, endTime);
  688. }
  689. code = code.Replace("-", "");
  690. string tableName = "";
  691. reader.Close();
  692. //Utils.Query(proConn, "select P1, P2, P3, P4, P5, P6, P7, P8, P9, P10 from lot_summary where lot_no =
  693. Printer.Print(s, n);
  694. //Printer.Print(s);
  695. //var p = new Printer();
  696. }
  697. private void printBtn_Click(object sender, RoutedEventArgs e)
  698. {
  699. if (_isExisting == true)
  700. {
  701. PrintLabel(lotNo.Text, Convert.ToDateTime(_updated_at));
  702. }
  703. else
  704. {
  705. MessageBox.Show("You can print when you have commited data");
  706. }
  707. }
  708. private void commitBtn_Click(object sender, RoutedEventArgs e)
  709. {
  710. if (measureGrid.ItemsSource == null)
  711. return;
  712. var now = DateTime.Now;
  713. var w = (MainWindow)Application.Current.MainWindow;
  714. var id = Utils.getSetting("currentMachine");
  715. double sum = 0;
  716. int count = 0;
  717. List<List<float>> s = new List<List<float>>();
  718. _isExisting = true;
  719. Dictionary<string, List<double>> sumType = new Dictionary<string, List<double>>();
  720. foreach (var item in measureGrid.Items)
  721. {
  722. //Console.WriteLine(item);
  723. MeasurePoint mp = item as MeasurePoint;
  724. if (mp.Avg == null)
  725. {
  726. mp.Avg = 0;
  727. }
  728. if (mp.Avg == 0)
  729. continue;
  730. if (mp.Grade == null)
  731. {
  732. mp.Grade = "-";
  733. }
  734. if (mp.ResultGrade == null)
  735. {
  736. mp.ResultGrade = "-";
  737. }
  738. /*
  739. if (mp.Type == "MID" && this.isMiddle == false)
  740. continue;
  741. if (mp.Type == "IN*" && _isIn == false)
  742. continue;
  743. */
  744. if (sumType.ContainsKey(mp.Type.Trim()) == false)
  745. {
  746. sumType[mp.Type.Trim()] = new List<double>();
  747. }
  748. (sumType[mp.Type.Trim()] as List<double>).Add(mp.Avg);
  749. string sql = string.Format(" insert into data_rl(lot_no, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, row_no, avg, grade, rgrade, r_type, created_at, updated_at, ndata, sub_order, machine_id, code, header) " +
  750. " values ('{0}', {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, '{13}', '{14}', '{15}', '{16}', '{17}', {18}, {19}, {20}, '{21}', '{22}' )"
  751. , lotNo.Text.Trim(), mp.P1, mp.P2, mp.P3, mp.P4, mp.P5, mp.P6, mp.P7, mp.P8, mp.P9, mp.P10, mp.Count, mp.Avg, mp.Grade.Trim(), mp.ResultGrade.Trim(), mp.Type.Trim(), now, now, nextCol, mp.SubOrder, id, w.code.Text.Trim(), this.header);
  752. sum += mp.Avg;
  753. //var s0 = lotNo.Text.Trim();
  754. /*
  755. var tempList = new List<float>();
  756. for(int i = 1; i < nextCol; i++){
  757. tempList.Add(mp.GetValue("P"+i));
  758. }
  759. s.Add(tempList);
  760. */
  761. count++;
  762. using (SqlCommand command = new SqlCommand(sql, proConn))
  763. {
  764. command.ExecuteNonQuery();
  765. }
  766. }
  767. //Math.Round(
  768. int i = 0;
  769. string[] keys = new string[sumType.Keys.Count];
  770. sumType.Keys.CopyTo(keys, 0);
  771. for (int k = 0; k < keys.Length; k++)
  772. {
  773. keys[k] = "'" + keys[k] + "'";
  774. }
  775. //List<string> avgValues = new List<string>();
  776. string[] values = new string[sumType.Keys.Count];
  777. int j = 0;
  778. string[] columns = new string[sumType.Keys.Count];
  779. string[] columnValues = new string[sumType.Keys.Count];
  780. foreach (var name in sumType)
  781. {
  782. var temp = name.Value as List<double>;
  783. double st = 0.0;
  784. foreach (double n in temp)
  785. {
  786. st += n;
  787. }
  788. values[j] = Math.Round((double)(st / temp.Count), 2).ToString();
  789. columns[j] = "avg" + j + "_name";
  790. columnValues[j] = "avg" + j;
  791. j++;
  792. }
  793. double avg = Math.Round(sum / count, 2);
  794. string grade = "-";
  795. if (Convert.ToInt32(sMi16) <= Convert.ToInt32(sMi20))
  796. {
  797. grade = computeGrade(sMi16, avg, kind, "-", "OUT");
  798. }
  799. else
  800. {
  801. if (Convert.ToInt32(sMi20) == 0)
  802. grade = computeGrade(sMi16, avg, kind, "-", "OUT");
  803. else
  804. grade = computeGrade(sMi20, avg, kind, "-", "OUT");
  805. }
  806. try
  807. {
  808. string sql2 = string.Format("insert into lot_summary_rl(lot_no, created_at, avg, code, start_time, end_time, grade, machine_id, " + String.Join(",", columns) + "," + String.Join(",", columnValues) + ") values('{0}', '{1}', {2}, '{3}', '{4}', '{5}', '{6}', {7}, {8}, {9})",
  809. lotNo.Text.Trim(), now, avg, w.code.Text.Trim(), _startUsing, now, grade.Trim(), id, String.Join(",", keys), String.Join(",", values
  810. ));
  811. using (SqlCommand command = new SqlCommand(sql2, proConn))
  812. {
  813. command.ExecuteNonQuery();
  814. }
  815. _updated_at = now.ToString();
  816. PrintLabel(lotNo.Text, now);
  817. MessageBox.Show("Commit Complete");
  818. lotNo.Focus();
  819. lotNo.SelectAll();
  820. }
  821. catch (Exception ex)
  822. {
  823. MessageBox.Show("Data Input Error " + ex.Message);
  824. }
  825. }
  826. private void undoBtn_Click(object sender, RoutedEventArgs e)
  827. {
  828. if (_lastAction.Count == 0)
  829. return;
  830. string action = _lastAction.Pop();
  831. if (action == "middle")
  832. {
  833. this.isMiddle = !this.isMiddle;
  834. if (this.isMiddle == false)
  835. {
  836. middleText.Text = "Add Middle";
  837. RemoveMid();
  838. }
  839. else
  840. {
  841. middleText.Text = "Remove Middle";
  842. AddMid();
  843. }
  844. }
  845. if (action == "in")
  846. {
  847. _isIn = !_isIn;
  848. if (_isIn == false)
  849. {
  850. inText.Text = "Add IN*";
  851. RemoveIn();
  852. }
  853. else
  854. {
  855. inText.Text = "Remove IN*";
  856. AddIn();
  857. }
  858. }
  859. else if (action == "row")
  860. {
  861. for (int i = 0; i < list.Count; i++)
  862. {
  863. mps.RemoveAt(mps.Count - 1);
  864. }
  865. }
  866. else if (action == "column")
  867. {
  868. measureGrid.Columns.ElementAt(nextCol--).Visibility = Visibility.Hidden;
  869. foreach (var item in measureGrid.Items)
  870. {
  871. //Console.WriteLine(item);
  872. MeasurePoint c = item as MeasurePoint;
  873. c.setValue((nextCol + 1).ToString(), (float)0.0);
  874. c.Avg = (c.P1 + c.P2 + c.P3 + c.P4 + c.P6 + c.P7 + c.P8 + c.P9 + c.P10) / (nextCol);
  875. c.Avg = Math.Round(c.Avg, 2);
  876. if (c.SubOrder == 1)
  877. {
  878. c.Grade = computeGrade(sMi16, c.Avg, kind, "-", c.Type);
  879. }
  880. else if (c.SubOrder != 1 && c.Type != "MID" && c.Type != "IN*")
  881. {
  882. if (sMi20 != "0")
  883. c.Grade = computeGrade(sMi20, c.Avg, kind, "-", c.Type);
  884. else
  885. c.Grade = computeGrade(sMi16, c.Avg, kind, "-", c.Type);
  886. }
  887. }
  888. }
  889. else if (action == "remove_column")
  890. {
  891. measureGrid.Columns.ElementAt(++nextCol).Visibility = Visibility.Visible;
  892. foreach (var item in measureGrid.Items)
  893. {
  894. //Console.WriteLine(item);
  895. MeasurePoint c = item as MeasurePoint;
  896. c.setValue((nextCol).ToString(), (float)0.0);
  897. computeValues(c, true);
  898. }
  899. }
  900. measureGrid.Items.Refresh();
  901. }
  902. private void Window_Loaded(object sender, RoutedEventArgs e)
  903. {
  904. //measureGrid.ItemsSource = null;
  905. RLMin.Text = Utils.getSetting("RLMin");
  906. RLMax.Text = Utils.getSetting("RLMax");
  907. this.rlAlert = new RLAlert();
  908. this.rlAlert.setRLWindow(this);
  909. this.rlAlert.ShowDialog();
  910. }
  911. private bool isAlreadyCheck(string ln)
  912. {
  913. SqlCommand catCMD = proConn.CreateCommand();
  914. string sql = @"SELECT * FROM lot_summary_rl where lot_no = '" + ln + "'";
  915. catCMD.CommandText = sql;
  916. SqlDataReader reader = catCMD.ExecuteReader();
  917. bool r = reader.HasRows;
  918. reader.Close();
  919. return r;
  920. }
  921. private List<string> GetRecordType(string pro2)
  922. {
  923. List<string> tempList = new List<string>();
  924. tempList.Add("FA1");
  925. tempList.Add("FA2");
  926. //rList.Add("MID");
  927. //rList.Add("IN*");
  928. return tempList;
  929. foreach (var view in masViews)
  930. {
  931. SqlCommand cmd = proConn.CreateCommand();
  932. string sql = @"
  933. select * from [" + view + "] v where v.PRO2='" + pro2 + "'";
  934. cmd.CommandText = sql;
  935. //Console.WriteLine(sql);
  936. SqlDataReader reader = cmd.ExecuteReader();
  937. if (!reader.HasRows)
  938. {
  939. reader.Close();
  940. continue;
  941. }
  942. bool hasIn, hasOut;
  943. while (reader.Read())
  944. {
  945. var mi17 = reader["MI17"].ToString();
  946. if (string.IsNullOrEmpty(mi17) || mi17 == "NULL")
  947. {
  948. hasOut = false;
  949. }
  950. else
  951. {
  952. hasOut = true;
  953. }
  954. string mi21 = reader["MI21"].ToString();
  955. if (string.IsNullOrEmpty(mi21) || mi21 == "NULL")
  956. {
  957. hasIn = false;
  958. }
  959. else
  960. {
  961. hasIn = true;
  962. }
  963. List<string> rList = new List<string>();
  964. if (_isTkx == true)
  965. {
  966. rList.Add("FA1");
  967. rList.Add("FA2");
  968. //rList.Add("MID");
  969. //rList.Add("IN*");
  970. reader.Close();
  971. return rList;
  972. }
  973. if (view == "bel_master_view" || view == "e_master_view" || view == "mg_master_view")
  974. {
  975. if (reader["MP45"].ToString() != "NULL" && !string.IsNullOrEmpty(reader["MP45"].ToString().Trim()))
  976. {
  977. rList.Add(reader["MP45"].ToString().ToUpper());
  978. }
  979. //rList.Add("MID");
  980. //rList.Add("IN*");
  981. if (reader["MP49"].ToString() != "NULL" && !string.IsNullOrEmpty(reader["MP49"].ToString().Trim()))
  982. {
  983. rList.Add(reader["MP49"].ToString().ToUpper());
  984. }
  985. else
  986. {
  987. if (hasIn == true)
  988. {
  989. var side = reader["MP45"].ToString().ToLower();
  990. rList.Add(_sideMap[side].ToUpper());
  991. }
  992. }
  993. reader.Close();
  994. return rList;
  995. }
  996. else
  997. {
  998. if (reader["MP34"].ToString() != "NULL" && !string.IsNullOrEmpty(reader["MP34"].ToString().Trim()))
  999. {
  1000. rList.Add(reader["MP34"].ToString().ToUpper());
  1001. }
  1002. //rList.Add("MID");
  1003. //rList.Add("IN*");
  1004. if (reader["MP39"].ToString() != "NULL" && !string.IsNullOrEmpty(reader["MP39"].ToString().Trim()))
  1005. {
  1006. rList.Add(reader["MP39"].ToString().ToUpper());
  1007. }
  1008. else
  1009. {
  1010. if (hasIn == true)
  1011. {
  1012. var side = reader["MP34"].ToString().ToLower();
  1013. rList.Add(_sideMap[side].ToUpper());
  1014. }
  1015. }
  1016. reader.Close();
  1017. return rList;
  1018. }
  1019. }
  1020. }
  1021. return null;
  1022. }
  1023. private bool fillProData(string ln, string viewName)
  1024. {
  1025. /*
  1026. join [V-MAS-3] v
  1027. on p.PRO1 = v.TC
  1028. left outer join [TABLE_TI-T4] t4
  1029. on v.MI5 = t4.TIT4
  1030. */
  1031. string sql = @"
  1032. SELECT * FROM " + viewName + " p " +
  1033. "where p.PRO2 = '" + ln + "'";
  1034. SqlDataReader reader = Utils.Query(proConn, sql);
  1035. string pro1 = "";
  1036. if (!reader.HasRows)
  1037. {
  1038. reader.Close();
  1039. return false;
  1040. }
  1041. else
  1042. {
  1043. reader.Close();
  1044. return true;
  1045. //return pro1;
  1046. }
  1047. }
  1048. private void find_Click(object sender, RoutedEventArgs e)
  1049. {
  1050. string ln = lotNo.Text;
  1051. _startUsing = DateTime.Now;
  1052. bool isFound = false;
  1053. isMiddle = _isIn = false;
  1054. _isExisting = false;
  1055. _isCheck = false;
  1056. _isTkx = false;
  1057. midGS = "";
  1058. inStarGS = "";
  1059. measureGrid.ItemsSource = null;
  1060. measureGrid.Items.Clear();
  1061. nextCol = 3;
  1062. foreach (var view in masViews)
  1063. {
  1064. isFound = fillProData(ln, view);
  1065. if (isFound == true)
  1066. break;
  1067. }
  1068. if (isFound == false)
  1069. {
  1070. MessageBox.Show("Lot No.:" + ln + " Not Founded");
  1071. return;
  1072. }
  1073. //MessageBox.Show("after fill prodata");
  1074. mps = new ObservableCollection<MeasurePoint>();
  1075. list = GetRecordType(ln);
  1076. if (list.Count == 0)
  1077. {
  1078. list.Add("FA1");
  1079. list.Add("FA2");
  1080. }
  1081. if (isAlreadyCheck(ln))
  1082. {
  1083. //ChooseRecord cr = new ChooseRecord(ln);
  1084. //cr.ShowDialog();
  1085. _isCheck = true;
  1086. ChooseRecord3 cr = new ChooseRecord3(ln);
  1087. cr.ShowDialog();
  1088. SqlDataReader reader = Utils.Query(proConn, "select * from data_rl where lot_no = '" + ln + "' and updated_at = '" + this._updated_at + "' order by id");
  1089. isMiddle = false;
  1090. _haveMiddle = false;
  1091. while (reader.Read())
  1092. {
  1093. var mp = new MeasurePoint();
  1094. nextCol = Convert.ToInt32(reader["ndata"]);
  1095. mp.Count = Convert.ToInt16(reader["row_no"]);
  1096. mp.Type = reader["r_type"].ToString();
  1097. if (mp.Type == "MID")
  1098. {
  1099. isMiddle = true;
  1100. _haveMiddle = true;
  1101. }
  1102. mp.SubOrder = Convert.ToInt16(reader["sub_order"]);
  1103. mp.P1 = Math.Round(Convert.ToDouble(reader["p1"]), 2);
  1104. mp.P2 = Math.Round(Convert.ToDouble(reader["p2"]), 2);
  1105. mp.P3 = Math.Round(Convert.ToDouble(reader["p3"]), 2);
  1106. mp.P4 = Math.Round(Convert.ToDouble(reader["p4"]), 2);
  1107. mp.P5 = Math.Round(Convert.ToDouble(reader["p5"]), 2);
  1108. mp.P6 = Math.Round(Convert.ToDouble(reader["p6"]), 2);
  1109. mp.P7 = Math.Round(Convert.ToDouble(reader["p7"]), 2);
  1110. mp.P8 = Math.Round(Convert.ToDouble(reader["p8"]), 2);
  1111. mp.P9 = Math.Round(Convert.ToDouble(reader["p9"]), 2);
  1112. mp.P10 = Math.Round(Convert.ToDouble(reader["p10"]), 2);
  1113. mp.Avg = Math.Round(Convert.ToDouble(reader["avg"]), 2);
  1114. mp.Grade = reader["grade"].ToString();
  1115. mp.ResultGrade = reader["rgrade"].ToString();
  1116. mp.Type = reader["r_type"].ToString();
  1117. mps.Add(mp);
  1118. // if row['sub_order'] == 1 and not have middle
  1119. //add dummy mid row
  1120. //if (Convert.ToInt32(reader["sub_order"]) == 1 && _haveMiddle == false)
  1121. // mps.Add(new MeasurePoint() { Count = mp.Count, Type = "MID", SubOrder = 2 });
  1122. }
  1123. reader.Close();
  1124. }
  1125. else
  1126. {
  1127. for (int i = 0; i < 3; i++)
  1128. {
  1129. int count = 1;
  1130. foreach (var l in list)
  1131. {
  1132. mps.Add(new MeasurePoint() { Count = i + 1, Type = l, SubOrder = count });
  1133. count++;
  1134. }
  1135. }
  1136. if (_isTkx == true)
  1137. {
  1138. measureGrid.Columns.ElementAt(nextCol--).Visibility = Visibility.Hidden;
  1139. }
  1140. }
  1141. measureGrid.ItemsSource = mps;
  1142. for (int i = 1; i < 10; i++)
  1143. {
  1144. measureGrid.Columns.ElementAt(i).Visibility = Visibility.Hidden;
  1145. }
  1146. for (int i = 1; i <= nextCol; i++)
  1147. {
  1148. measureGrid.Columns.ElementAt(i).Visibility = Visibility.Visible;
  1149. }
  1150. measureGrid.Focus();
  1151. try
  1152. {
  1153. measureGrid.SelectedItem = measureGrid.Items[0];
  1154. measureGrid.CurrentCell = new DataGridCellInfo(
  1155. measureGrid.Items[0], measureGrid.Columns[1]);
  1156. measureGrid.BeginEdit();
  1157. }
  1158. catch { }
  1159. }
  1160. private void measureGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
  1161. {
  1162. this.currentColumn = e.Column.Header.ToString();
  1163. this.currentMP = (MeasurePoint)e.Row.Item;
  1164. cellIndicattor.Text = "(" + currentMP.Type + "-" + currentMP.Count + ", " + currentColumn + ")";
  1165. }
  1166. private void measureGrid_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
  1167. {
  1168. //this.currentMP = (MeasurePoint)measureGrid.CurrentItem;
  1169. //this.currentColumn = measureGrid.CurrentColumn.Header.ToString();
  1170. //cellIndicattor.Text = "("+currentMP.Type + "-" +currentMP.Count+", "+currentColumn+")";
  1171. }
  1172. private void measureGrid_CurrentCellChanged(object sender, EventArgs e)
  1173. {
  1174. try
  1175. {
  1176. this.currentColumn = measureGrid.CurrentColumn.Header.ToString();
  1177. this.currentMP = (MeasurePoint)measureGrid.CurrentItem;
  1178. cellIndicattor.Text = "(" + currentMP.Type + "-" + currentMP.Count + ", " + currentColumn + ")";
  1179. //this.computeValues(currentMP);
  1180. }
  1181. catch (NullReferenceException ne) { }
  1182. }
  1183. private void measureGrid_KeyDown(object sender, KeyEventArgs e)
  1184. {
  1185. }
  1186. private void measureGrid_Loaded(object sender, RoutedEventArgs e)
  1187. {
  1188. //MessageBox.Show("Refresh Finish");
  1189. }
  1190. private void measureGrid_SourceUpdated(object sender, DataTransferEventArgs e)
  1191. {
  1192. MessageBox.Show("refresh finish");
  1193. }
  1194. private void measureGrid_ColumnDisplayIndexChanged(object sender, DataGridColumnEventArgs e)
  1195. {
  1196. }
  1197. private void measureGrid_PreviewKeyDown(object sender, KeyEventArgs e)
  1198. {
  1199. }
  1200. private void measureGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
  1201. {
  1202. //MessageBox.Show("refresh");
  1203. int row = e.Row.GetIndex();
  1204. (sender as DataGrid).RowEditEnding -= measureGrid_RowEditEnding;
  1205. (sender as DataGrid).CommitEdit();
  1206. var c = mps[row];
  1207. computeValues(c, true);
  1208. measureGrid.Items.Refresh();
  1209. (sender as DataGrid).RowEditEnding += measureGrid_RowEditEnding;
  1210. }
  1211. private void measureGrid_KeyUp(object sender, KeyEventArgs e)
  1212. {
  1213. Console.WriteLine("hello");
  1214. //MessageBox.Show(e.Key.ToString());
  1215. var info = measureGrid.CurrentColumn;
  1216. var item = measureGrid.CurrentItem as MeasurePoint;
  1217. int col = info.DisplayIndex;
  1218. var mp = (MeasurePoint)measureGrid.CurrentItem;
  1219. int row = mps.IndexOf(mp);
  1220. if (e.Key == Key.Tab)
  1221. {
  1222. //measureGrid.RaiseEvent(new RoutedEventArgs(DataGrid.rowediten));
  1223. //MessageBox.Show("row " + item.Count.ToString());
  1224. //MessageBox.Show("row " + mps.IndexOf(mp).ToString());
  1225. //MessageBox.Show("col " + info.DisplayIndex.ToString());
  1226. if (col < nextCol)
  1227. {
  1228. measureGrid.CurrentCell = new DataGridCellInfo(
  1229. measureGrid.Items[row], measureGrid.Columns[col + 1]);
  1230. measureGrid.BeginEdit();
  1231. }
  1232. else
  1233. {
  1234. try
  1235. {
  1236. measureGrid.CurrentCell = new DataGridCellInfo(
  1237. measureGrid.Items[row + 1], measureGrid.Columns[1]);
  1238. measureGrid.BeginEdit();
  1239. }
  1240. catch
  1241. {
  1242. measureGrid.CurrentCell = new DataGridCellInfo(
  1243. measureGrid.Items[0], measureGrid.Columns[1]);
  1244. measureGrid.BeginEdit();
  1245. }
  1246. }
  1247. }
  1248. if (e.Key == Key.Return)
  1249. {
  1250. if (isMiddle == false)
  1251. row += 2;
  1252. if (row > measureGrid.Items.Count)
  1253. {
  1254. measureGrid.CurrentCell = new DataGridCellInfo(
  1255. measureGrid.Items[0], measureGrid.Columns[1]);
  1256. measureGrid.BeginEdit();
  1257. }
  1258. }
  1259. }
  1260. private void measureGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
  1261. {
  1262. /*
  1263. row = e.Row.GetIndex();
  1264. (sender as DataGrid).CellEditEnding -= measureGrid_CellEditEnding;
  1265. (sender as DataGrid).CommitEdit();
  1266. var c = mps[row];
  1267. c.Avg = (c.P1 + c.P2 + c.P3 + c.P4 + c.P6 + c.P7 + c.P8 + c.P9 + c.P10) / (nextCol - 1);
  1268. c.Grade = computeGrade(sMi16, c.Avg, kind, "-");
  1269. (sender as DataGrid).CellEditEnding += measureGrid_CellEditEnding;
  1270. */
  1271. }
  1272. private void measureGrid_LostFocus(object sender, RoutedEventArgs e)
  1273. {
  1274. /*
  1275. measureGrid.LostFocus -= measureGrid_LostFocus;
  1276. measureGrid.Items.Refresh();
  1277. measureGrid.LostFocus += measureGrid_LostFocus;
  1278. */
  1279. }
  1280. private void measureGrid_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
  1281. {
  1282. //measureGrid.Items.Refresh();
  1283. }
  1284. private void measureGrid_LoadingRow(object sender, DataGridRowEventArgs e)
  1285. {
  1286. /*
  1287. DataGridRow c = e.Row;
  1288. MeasurePoint mp = e.Row.Item as MeasurePoint;
  1289. if (mp.Type == "MID" && this.isMiddle == false)
  1290. {
  1291. c.Visibility = Visibility.Collapsed;
  1292. }
  1293. if (mp.Type == "IN*" && _isIn == false)
  1294. {
  1295. c.Visibility = Visibility.Collapsed;
  1296. }
  1297. */
  1298. }
  1299. private void RLMin_TextChanged(object sender, TextChangedEventArgs e)
  1300. {
  1301. Utils.UpdateSetting("rlMin", RLMin.Text.ToString());
  1302. }
  1303. private void RLMax_TextChanged(object sender, TextChangedEventArgs e)
  1304. {
  1305. Utils.UpdateSetting("rlMax", RLMax.Text.ToString());
  1306. }
  1307. }
  1308. }