Page_FirstControl.xaml.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Data;
  16. using System.Data.SQLite;
  17. using System.IO;
  18. using System.Windows.Interop;
  19. namespace AIRS.usercontrol
  20. {
  21. /// <summary>
  22. /// Page_FirstControl.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class Page_FirstControl : UserControl
  25. {
  26. //委托事件
  27. public delegate void ShowPage(string testitem);
  28. public static event ShowPage ShowpageEvent;
  29. public Boolean inclusion = false;
  30. public List<String> lincl = new List<string>();
  31. public Page_FirstControl()
  32. {
  33. InitializeComponent();
  34. //显示试样信息
  35. //数据库
  36. connstr.DataSource = path + "\\datas.db";
  37. conn.ConnectionString = connstr.ToString();
  38. conn.Open();
  39. ShowSteel();
  40. //查询钢种
  41. Inclusion.inc_change += Show_Entry;
  42. lincl.Add("a");
  43. lincl.Add("b");
  44. lincl.Add("c");
  45. }
  46. private void Show_Entry(List<String> incl)
  47. {
  48. lincl = incl;
  49. if (lincl.Count>0)
  50. {
  51. this.txtinput.Visibility = Visibility.Visible;
  52. }
  53. else
  54. {
  55. this.txtinput.Visibility = Visibility.Hidden;
  56. }
  57. if (ShowpageEvent != null)
  58. {
  59. ShowpageEvent(testitems);
  60. }
  61. }
  62. /// <summary>
  63. /// 装载事件
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. private void userControlLoader(object sender, RoutedEventArgs e)
  68. {
  69. }
  70. private string path = Directory.GetCurrentDirectory();
  71. SQLiteConnection conn = new SQLiteConnection();
  72. SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
  73. SQLiteDataAdapter da = new SQLiteDataAdapter();
  74. List<string> liststeel_id = new List<string>();
  75. List<string> liststandard_id = new List<string>();
  76. List<string> listtestitem_id = new List<string>();
  77. List<Label> list_lblsteel = new List<Label>();//钢种
  78. List<Label> list_lblstandard = new List<Label>(); //评级标准
  79. private List<Label> list_lbltestitems = new List<Label>();//检验项目
  80. public string steel;
  81. public string standard;
  82. public string testitems;
  83. public string catagory;
  84. public string items;
  85. public string testitems_param;
  86. /// <summary>
  87. /// 更新首页显示信息
  88. /// </summary>
  89. /// <param name="steel"></param>
  90. /// <param name="standard"></param>
  91. /// <param name="testitem"></param>
  92. public void update_pagefirst_show(string _steel, string _standard, string _testitem)
  93. {
  94. if(_steel=="夹杂物")
  95. {
  96. inclusion = true;
  97. }
  98. else
  99. {
  100. inclusion = false;
  101. }
  102. //查找钢种
  103. for (int i = 0; i < list_lblsteel.Count; i++)
  104. {
  105. if (list_lblsteel[i].Content.ToString() == _steel)
  106. {
  107. list_lblsteel[i].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  108. this.steel = _steel;
  109. }
  110. else
  111. {
  112. list_lblsteel[i].Foreground = new SolidColorBrush(Colors.White);
  113. list_lblsteel[i].Background = null;
  114. }
  115. }
  116. try
  117. {
  118. da = new SQLiteDataAdapter("select * from t_steel where Isshow=1 and opt_steel='" + _steel + "'", conn);
  119. DataTable ds = new DataTable();
  120. da.Fill(ds);
  121. for (int i = 0; i < ds.Rows.Count; i++)
  122. {
  123. catagory = ds.Rows[i][3].ToString();
  124. }
  125. }
  126. catch (Exception e)
  127. {
  128. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  129. }
  130. //根据钢种查询标准
  131. string standard_id = "";
  132. try
  133. {
  134. //查询标准
  135. Can_Standard.Children.Clear();//清空显示在页面的评级标准
  136. list_lblstandard.Clear();//清空评级标准list
  137. Can_Testitems.Children.Clear();//未选择评级标准应该不显示检验项目
  138. testitems = "";//清除未选择评级标准的检验项目
  139. Can_Testitems.Height = 5; //检验项目高度变小不会有垂直滚动条
  140. // SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_standard WHERE 钢种='" + steel + "'", conn);
  141. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_standard WHERE opt_steel='" + find_steel_by_steel(_steel).Rows[0][0].ToString() + "'", conn);
  142. DataTable ds = new DataTable();
  143. dat.Fill(ds);
  144. for (int i = 0; i < ds.Rows.Count; i++)
  145. {
  146. Label lblstandard = new Label();
  147. lblstandard.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(lblstandard_Click);
  148. lblstandard.MouseEnter += Lblstandard_MouseEnter;
  149. lblstandard.MouseLeave += Lblstandard_MouseLeave;
  150. lblstandard.Content = ds.Rows[i][2].ToString();
  151. lblstandard.Foreground = new SolidColorBrush(Colors.White);
  152. lblstandard.Width = 250;
  153. lblstandard.Height = 40;
  154. lblstandard.HorizontalContentAlignment = HorizontalAlignment.Center;
  155. lblstandard.VerticalContentAlignment = VerticalAlignment.Center;
  156. lblstandard.FontSize = 22;
  157. lblstandard.SetValue(Canvas.TopProperty, 0.0 + i * 50);
  158. lblstandard.SetValue(Canvas.LeftProperty, 0.0);
  159. lblstandard.SetValue(Canvas.RightProperty, double.NaN);
  160. lblstandard.SetValue(Canvas.BottomProperty, double.NaN);
  161. lblstandard.Tag = i.ToString();
  162. lblstandard.Cursor = Cursors.Hand;
  163. if (lblstandard.Content.ToString() == _standard)
  164. {
  165. lblstandard.Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  166. standard = _standard;
  167. standard_id = ds.Rows[i][1].ToString();
  168. }
  169. list_lblstandard.Add(lblstandard);
  170. Can_Standard.Children.Add(lblstandard);
  171. }
  172. Can_Standard.Height = ds.Rows.Count * 50;
  173. }
  174. catch (Exception e)
  175. {
  176. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  177. }
  178. //根据标准查询项目
  179. try
  180. {
  181. //查询标准
  182. Can_Testitems.Children.Clear();
  183. list_lbltestitems.Clear();
  184. testitems = "";//清除未选择评级标准的检验项目
  185. // SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_testitems WHERE 评级标准='" + standard + "'and Isshow=1", conn);
  186. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_testitems WHERE opt_standard='" + find_steel_by_steel(_steel).Rows[0][0].ToString() + "'and Isshow=1", conn);
  187. DataTable ds = new DataTable();
  188. dat.Fill(ds);
  189. for (int i = 0; i < ds.Rows.Count; i++)
  190. {
  191. Label lbltestitem = new Label();
  192. lbltestitem.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(lbltestitems_Click);
  193. lbltestitem.MouseEnter += Lbltestitem_MouseEnter;
  194. lbltestitem.MouseLeave += Lbltestitem_MouseLeave;
  195. if(inclusion)
  196. {
  197. lbltestitem.Content = ds.Rows[i][2].ToString() + " ▼";
  198. }
  199. else
  200. {
  201. lbltestitem.Content = ds.Rows[i][2].ToString();
  202. }
  203. lbltestitem.Foreground = new SolidColorBrush(Colors.White);
  204. lbltestitem.Width = 270;
  205. lbltestitem.Height = 40;
  206. lbltestitem.HorizontalContentAlignment = HorizontalAlignment.Center;
  207. lbltestitem.VerticalContentAlignment = VerticalAlignment.Center;
  208. lbltestitem.FontSize = 22;
  209. lbltestitem.SetValue(Canvas.TopProperty, 0.0 + i * 50);
  210. lbltestitem.SetValue(Canvas.LeftProperty, 0.0);
  211. lbltestitem.SetValue(Canvas.RightProperty, double.NaN);
  212. lbltestitem.SetValue(Canvas.BottomProperty, double.NaN);
  213. lbltestitem.Tag = i.ToString();
  214. lbltestitem.Cursor = Cursors.Hand;
  215. if (lbltestitem.Content.ToString().IndexOf( _testitem)>-1)
  216. {
  217. // lbltestitem.Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));//字体颜色
  218. lbltestitem.Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  219. testitems = _testitem;
  220. items = find_testitems(standard_id, testitems).Rows[0][4].ToString();
  221. }
  222. list_lbltestitems.Add(lbltestitem);
  223. Can_Testitems.Children.Add(lbltestitem);
  224. }
  225. Can_Testitems.Height = ds.Rows.Count * 50;
  226. }
  227. catch (Exception e)
  228. {
  229. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  230. }
  231. IsShowTextInput();
  232. }
  233. /// <summary>
  234. /// 初始化时显示钢种
  235. /// </summary>
  236. private void ShowSteel()
  237. {
  238. try
  239. {
  240. da = new SQLiteDataAdapter("select * from t_steel where Isshow=1", conn);
  241. DataTable ds = new DataTable();
  242. da.Fill(ds);
  243. for (int i = 0; i < ds.Rows.Count; i++)
  244. {
  245. Label lblsteel = new Label();
  246. lblsteel.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(lblsteel_Click);
  247. lblsteel.MouseMove += Lblsteel_MouseMove;
  248. lblsteel.MouseLeave += Lblsteel_MouseLeave;
  249. lblsteel.Content = ds.Rows[i][1].ToString();
  250. liststeel_id.Add(ds.Rows[i][0].ToString());
  251. lblsteel.Foreground = new SolidColorBrush(Colors.White);
  252. // lblsteel.Background = new SolidColorBrush(Colors.AliceBlue);
  253. lblsteel.Width = 250;
  254. lblsteel.Height = 40;
  255. lblsteel.HorizontalContentAlignment = HorizontalAlignment.Center;
  256. lblsteel.VerticalContentAlignment = VerticalAlignment.Center;
  257. lblsteel.FontSize = 22;
  258. lblsteel.SetValue(Canvas.TopProperty, 0.0 + i * 50);
  259. lblsteel.SetValue(Canvas.LeftProperty, 0.0);
  260. lblsteel.SetValue(Canvas.RightProperty, double.NaN);
  261. lblsteel.SetValue(Canvas.BottomProperty, double.NaN);
  262. lblsteel.Tag = i.ToString();
  263. lblsteel.Cursor = Cursors.Hand;
  264. if (i == 0)
  265. {
  266. lblsteel.Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  267. //lblsteel.Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));//字体颜色
  268. // Click_Steel(ds.Rows[i][0].ToString());
  269. Click_Steel(ds.Rows[i][0].ToString());
  270. catagory = ds.Rows[i][3].ToString();
  271. steel = ds.Rows[i][1].ToString();//给钢种赋值
  272. Console.WriteLine("初始化时 steel" + steel + "Catagory" + catagory);
  273. IsShowTextInput();
  274. }
  275. list_lblsteel.Add(lblsteel);
  276. Can_Steel.Children.Add(lblsteel);
  277. //Console.WriteLine("控件的" + lblsteel);
  278. }
  279. Can_Steel.Height = ds.Rows.Count * (50);
  280. // Scrviewer_Steel.Height = ds.Rows.Count * (50) + 10;
  281. }
  282. catch (Exception e)
  283. {
  284. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  285. }
  286. }
  287. /// <summary>
  288. /// 鼠标移除钢种后颜色变回
  289. /// </summary>
  290. /// <param name="sender"></param>
  291. /// <param name="e"></param>
  292. private void Lblsteel_MouseLeave(object sender, MouseEventArgs e)
  293. {
  294. int index = int.Parse(((Label)sender).Tag.ToString());
  295. list_lblsteel[index].Background = System.Windows.Media.Brushes.Transparent;
  296. list_lblsteel[index].Foreground = System.Windows.Media.Brushes.White;
  297. list_lblsteel[index].FontSize = 22;
  298. if (list_lblsteel[index].ToString().Substring(list_lblsteel[index].ToString().IndexOf(":") + 2) == steel)
  299. {
  300. list_lblsteel[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  301. ////以下是移除后选中的那条变为啥颜色
  302. //list_lblsteel[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  303. }
  304. }
  305. /// <summary>
  306. /// 鼠标在移动在钢种上方时有颜色变化
  307. /// </summary>
  308. /// <param name="sender"></param>
  309. /// <param name="e"></param>
  310. private void Lblsteel_MouseMove(object sender, MouseEventArgs e)
  311. {
  312. int index = int.Parse(((Label)sender).Tag.ToString());
  313. //list_lblsteel[index].Background = System.Windows.Media.Brushes.Transparent;
  314. if (list_lblsteel[index].ToString().Substring(list_lblsteel[index].ToString().IndexOf(":") + 2) == steel)
  315. {
  316. list_lblsteel[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  317. list_lblsteel[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  318. list_lblsteel[index].FontSize = 24;
  319. }
  320. else
  321. {
  322. list_lblsteel[index].Background = new SolidColorBrush(Color.FromRgb(54, 62, 78));
  323. list_lblsteel[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  324. list_lblsteel[index].FontSize = 24;
  325. }
  326. }
  327. /// <summary>
  328. /// 钢种点击事件,选中行变颜色
  329. /// </summary>
  330. /// <param name="sender"></param>
  331. /// <param name="e"></param>
  332. private void lblsteel_Click(object sender, MouseButtonEventArgs e)
  333. {
  334. int index = int.Parse(((Label)sender).Tag.ToString());
  335. for (int i = 0; i < list_lblsteel.Count; i++)
  336. {
  337. list_lblsteel[i].Foreground = new SolidColorBrush(Colors.White);
  338. list_lblsteel[i].Background = null;
  339. }
  340. // list_lblsteel[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  341. list_lblsteel[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  342. if(list_lblsteel[index].Content.ToString().IndexOf("夹杂物")>-1)
  343. {
  344. inclusion = true;
  345. }
  346. else
  347. {
  348. inclusion = false;
  349. }
  350. steel = list_lblsteel[index].Content.ToString();
  351. catagory = find_steel_by_steel(steel).Rows[0][3].ToString();
  352. Console.WriteLine("点击后 steel" + steel + "Catagory" + catagory);
  353. //Click_Steel(list_lblsteel[index].ToString().Substring(list_lblsteel[index].ToString().IndexOf(":") + 2));
  354. Click_Steel(find_steel_by_steel(steel).Rows[0][0].ToString());
  355. IsShowTextInput();
  356. }
  357. /// <summary>
  358. /// 根据钢种返回一条记录
  359. /// </summary>
  360. /// <param name="steel"></param>
  361. /// <returns></returns>
  362. private DataTable find_steel_by_steel(string steel)
  363. {
  364. DataTable ds = new DataTable();
  365. try
  366. {
  367. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_steel WHERE opt_steel='" + steel + "' and Isshow=1", conn);
  368. dat.Fill(ds);
  369. }
  370. catch (Exception e)
  371. {
  372. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  373. }
  374. return ds;
  375. }
  376. /// <summary>
  377. /// 根据钢种显示标准
  378. /// </summary>
  379. /// <param name="steel"></param>
  380. public void Click_Steel(string steel)
  381. {
  382. try
  383. {
  384. //查询标准
  385. Can_Standard.Children.Clear();//清空显示在页面的评级标准
  386. list_lblstandard.Clear();//清空评级标准list
  387. Can_Testitems.Children.Clear();//未选择评级标准应该不显示检验项目
  388. testitems = "";//清除未选择评级标准的检验项目
  389. Can_Testitems.Height = 5; //检验项目高度变小不会有垂直滚动条
  390. testitems_param = "";
  391. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_standard WHERE opt_steel='" + steel + "'and Isshow=1", conn);
  392. DataTable ds = new DataTable();
  393. dat.Fill(ds);
  394. for (int i = 0; i < ds.Rows.Count; i++)
  395. {
  396. Label lblstandard = new Label();
  397. lblstandard.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(lblstandard_Click);
  398. lblstandard.MouseEnter += Lblstandard_MouseEnter;
  399. lblstandard.MouseLeave += Lblstandard_MouseLeave;
  400. lblstandard.Content = ds.Rows[i][2].ToString();
  401. lblstandard.Foreground = new SolidColorBrush(Colors.White);
  402. lblstandard.Width = 250;
  403. lblstandard.Height = 40;
  404. lblstandard.HorizontalContentAlignment = HorizontalAlignment.Center;
  405. lblstandard.VerticalContentAlignment = VerticalAlignment.Center;
  406. lblstandard.FontSize = 22;
  407. lblstandard.SetValue(Canvas.TopProperty, 0.0 + i * 50);
  408. lblstandard.SetValue(Canvas.LeftProperty, 0.0);
  409. lblstandard.SetValue(Canvas.RightProperty, double.NaN);
  410. lblstandard.SetValue(Canvas.BottomProperty, double.NaN);
  411. lblstandard.Tag = i.ToString();
  412. lblstandard.Cursor = Cursors.Hand;
  413. if (i == 0)
  414. {
  415. //lblstandard.Foreground= new SolidColorBrush(Color.FromRgb(245, 154, 35));//字体颜色
  416. lblstandard.Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  417. Click_Standard(ds.Rows[i][0].ToString());
  418. standard = ds.Rows[i][2].ToString();
  419. string stanardid = ds.Rows[i][0].ToString();
  420. Console.WriteLine(testitems);
  421. items = find_testitems(ds.Rows[i][0].ToString(), testitems).Rows[0][4].ToString();
  422. // string steelid = find_steel_by_steel(steel).Rows[0][0].ToString();
  423. // string stanardid = find_standard_bysteel_id(steelid).Rows[0][0].ToString();
  424. if (find_testitems(stanardid, testitems).Rows[0][5].ToString() != "")
  425. {
  426. testitems_param = find_testitems(stanardid, testitems).Rows[0][5].ToString();
  427. }
  428. Console.WriteLine("看这里看这里 " + testitems_param);
  429. Console.WriteLine("standard " + standard);
  430. Console.WriteLine("testitmes " + testitems + "items" + items);
  431. IsShowTextInput();
  432. }
  433. list_lblstandard.Add(lblstandard);
  434. Can_Standard.Children.Add(lblstandard);
  435. }
  436. Can_Standard.Height = ds.Rows.Count * 50;
  437. }
  438. catch (Exception e)
  439. {
  440. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  441. }
  442. }
  443. private void Lblstandard_MouseLeave(object sender, MouseEventArgs e)
  444. {
  445. int index = int.Parse(((Label)sender).Tag.ToString());
  446. list_lblstandard[index].Background = System.Windows.Media.Brushes.Transparent;
  447. list_lblstandard[index].Foreground = System.Windows.Media.Brushes.White;
  448. list_lblstandard[index].FontSize = 22;
  449. if (list_lblstandard[index].ToString().Substring(list_lblstandard[index].ToString().IndexOf(":") + 2) == standard)
  450. {
  451. list_lblstandard[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  452. // list_lblstandard[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  453. }
  454. }
  455. private void Lblstandard_MouseEnter(object sender, MouseEventArgs e)
  456. {
  457. int index = int.Parse(((Label)sender).Tag.ToString());
  458. //list_lblsteel[index].Background = System.Windows.Media.Brushes.Transparent;
  459. if (list_lblstandard[index].ToString().Substring(list_lblstandard[index].ToString().IndexOf(":") + 2) == standard)
  460. {
  461. list_lblstandard[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  462. list_lblstandard[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  463. list_lblstandard[index].FontSize = 24;
  464. }
  465. else
  466. {
  467. list_lblstandard[index].Background = new SolidColorBrush(Color.FromRgb(54, 62, 78));
  468. list_lblstandard[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  469. list_lblstandard[index].FontSize = 24;
  470. }
  471. }
  472. /// <summary>
  473. /// 评级标准点击事件
  474. /// </summary>
  475. /// <param name="sender"></param>
  476. /// <param name="e"></param>
  477. private void lblstandard_Click(object sender, MouseButtonEventArgs e)
  478. {
  479. int index = int.Parse(((Label)sender).Tag.ToString());
  480. for (int i = 0; i < list_lblstandard.Count; i++)
  481. {
  482. list_lblstandard[i].Foreground = new SolidColorBrush(Colors.White);//字体颜色
  483. list_lblstandard[i].Background = null;
  484. }
  485. //list_lblstandard[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));//字体颜色
  486. list_lblstandard[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  487. standard = list_lblstandard[index].ToString().Substring(list_lblstandard[index].ToString().IndexOf(":") + 2);
  488. //Click_Standard(list_lblstandard[index].ToString().Substring(list_lblstandard[index].ToString().IndexOf(":") + 2));
  489. //Console.WriteLine(find_steel_by_steel(steel).Rows[0][0].ToString()+"标准"+find_standard_bysteel_id(find_steel_by_steel(steel).Rows[0][0].ToString()).Rows[0][0].ToString());
  490. Click_Standard(find_standard_bysteel_id(find_steel_by_steel(steel).Rows[0][0].ToString()).Rows[0][0].ToString());
  491. IsShowTextInput();
  492. Console.WriteLine("点击standard" + standard);
  493. }
  494. /// <summary>
  495. /// 根据标准返回一条记录
  496. /// </summary>
  497. /// <param name="steel"></param>
  498. /// <returns></returns>
  499. private DataTable find_standard_bysteel_id(string steel_id)
  500. {
  501. DataTable ds = new DataTable();
  502. try
  503. {
  504. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_standard WHERE opt_steel='" + steel_id + "' and Isshow=1", conn);
  505. dat.Fill(ds);
  506. }
  507. catch (Exception e)
  508. {
  509. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  510. }
  511. return ds;
  512. }
  513. /// <summary>
  514. /// 点击标准显示检验项目
  515. /// </summary>
  516. /// <param name="steel"></param>
  517. public void Click_Standard(string standard)
  518. {
  519. try
  520. {
  521. //查询标准
  522. Can_Testitems.Children.Clear();
  523. list_lbltestitems.Clear();
  524. testitems = "";//清除未选择评级标准的检验项目
  525. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_testitems WHERE opt_standard='" + standard + "' and Isshow=1", conn);
  526. DataTable ds = new DataTable();
  527. dat.Fill(ds);
  528. for (int i = 0; i < ds.Rows.Count; i++)
  529. {
  530. Label lbltestitem = new Label();
  531. lbltestitem.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(lbltestitems_Click);
  532. lbltestitem.MouseEnter += Lbltestitem_MouseEnter;
  533. lbltestitem.MouseLeave += Lbltestitem_MouseLeave;
  534. lbltestitem.Foreground = new SolidColorBrush(Colors.White);
  535. if(inclusion)
  536. {
  537. lbltestitem.Content = ds.Rows[i][2].ToString() + " ▼";
  538. }
  539. else
  540. {
  541. lbltestitem.Content = ds.Rows[i][2].ToString();
  542. }
  543. lbltestitem.Width = 270;
  544. lbltestitem.Height = 40;
  545. lbltestitem.HorizontalContentAlignment = HorizontalAlignment.Center;
  546. lbltestitem.VerticalContentAlignment = VerticalAlignment.Center;
  547. lbltestitem.FontSize = 22;
  548. lbltestitem.SetValue(Canvas.TopProperty, 0.0 + i * 50);
  549. lbltestitem.SetValue(Canvas.LeftProperty, 0.0);
  550. lbltestitem.SetValue(Canvas.RightProperty, double.NaN);
  551. lbltestitem.SetValue(Canvas.BottomProperty, double.NaN);
  552. lbltestitem.Tag = i.ToString();
  553. lbltestitem.Cursor = Cursors.Hand;
  554. if (i == 0)
  555. {
  556. // lbltestitem.Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));//字体颜色
  557. lbltestitem.Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  558. testitems = ds.Rows[i][2].ToString();
  559. //string steelid = find_steel_by_steel(steel).Rows[0][0].ToString();
  560. //string stanardid = find_standard_bysteel_id(steelid).Rows[0][0].ToString();
  561. //Items = find_testitems(stanardid, testitems).Rows[0][4].ToString();
  562. //Console.WriteLine("testitems" + testitems);
  563. //Console.WriteLine("items" + Items);
  564. }
  565. list_lbltestitems.Add(lbltestitem);
  566. Can_Testitems.Children.Add(lbltestitem);
  567. }
  568. Can_Testitems.Height = ds.Rows.Count * 50;
  569. }
  570. catch (Exception e)
  571. {
  572. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  573. }
  574. }
  575. private void Lbltestitem_MouseLeave(object sender, MouseEventArgs e)
  576. {
  577. int index = int.Parse(((Label)sender).Tag.ToString());
  578. list_lbltestitems[index].Background = System.Windows.Media.Brushes.Transparent;
  579. list_lbltestitems[index].Foreground = System.Windows.Media.Brushes.White;
  580. list_lbltestitems[index].FontSize = 22;
  581. // list_lbltestitems[index].Width = 250;
  582. if(inclusion)
  583. {
  584. //Can_Testitems.Children.Remove(Can_Testitems.FindName("inclusion") as Inclusion);
  585. //Can_Testitems.UnregisterName("inclusion");
  586. if (list_lbltestitems[index].Content.ToString().IndexOf(testitems)>-1)
  587. {
  588. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  589. //list_lbltestitems[index].Width = 250;
  590. //list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  591. }
  592. }
  593. else
  594. {
  595. if (list_lbltestitems[index].Content.ToString() == testitems)
  596. {
  597. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  598. //list_lbltestitems[index].Width = 250;
  599. //list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  600. }
  601. }
  602. }
  603. private void Lbltestitem_MouseEnter(object sender, MouseEventArgs e)
  604. {
  605. int index = int.Parse(((Label)sender).Tag.ToString());
  606. if(inclusion)
  607. {
  608. if (list_lbltestitems[index].Content.ToString().IndexOf(testitems)>-1)
  609. {
  610. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  611. list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  612. list_lbltestitems[index].FontSize = 24;
  613. // list_lbltestitems[index].Width = 250 + 40;
  614. }
  615. else
  616. {
  617. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(54, 62, 78));
  618. list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  619. list_lbltestitems[index].FontSize = 24;
  620. // list_lbltestitems[index].Width = 250+40;
  621. }
  622. }
  623. else
  624. {
  625. if (list_lbltestitems[index].Content.ToString() == testitems)
  626. {
  627. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  628. list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  629. list_lbltestitems[index].FontSize = 24;
  630. // list_lbltestitems[index].Width = 250 + 40;
  631. }
  632. else
  633. {
  634. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(54, 62, 78));
  635. list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));
  636. list_lbltestitems[index].FontSize = 24;
  637. // list_lbltestitems[index].Width = 250+40;
  638. }
  639. }
  640. }
  641. /// <summary>
  642. /// 检测项目点击事件
  643. /// </summary>
  644. /// <param name="sender"></param>
  645. /// <param name="e"></param>
  646. private void lbltestitems_Click(object sender, MouseButtonEventArgs e)
  647. {
  648. testitems_param = "";
  649. int index = int.Parse(((Label)sender).Tag.ToString());
  650. for (int i = 0; i < list_lbltestitems.Count; i++)
  651. {
  652. list_lbltestitems[i].Foreground = new SolidColorBrush(Colors.White);//字体颜色
  653. list_lbltestitems[i].Background = null;
  654. }
  655. //list_lbltestitems[index].Foreground = new SolidColorBrush(Color.FromRgb(245, 154, 35));//字体颜色
  656. list_lbltestitems[index].Background = new SolidColorBrush(Color.FromRgb(0x43, 0x4e, 0x61));
  657. if(inclusion)
  658. {
  659. //testitems = "夹杂物评级";
  660. testitems = list_lbltestitems[index].Content.ToString();
  661. testitems = testitems.Replace("▼", "");
  662. testitems = testitems.Replace(" ", "");
  663. if (Can_Testitems.FindName("inclusion") as Inclusion == null)
  664. {
  665. Inclusion temp_inclusion = new Inclusion();
  666. lincl = temp_inclusion.inclusion;
  667. temp_inclusion.SetValue(Canvas.TopProperty, Convert.ToDouble(list_lbltestitems[index].GetValue(Canvas.TopProperty)) + list_lbltestitems[index].Height); ;
  668. temp_inclusion.SetValue(Canvas.LeftProperty, 0.0);
  669. temp_inclusion.SetValue(Canvas.BottomProperty, double.NaN);
  670. temp_inclusion.SetValue(Canvas.RightProperty, double.NaN);
  671. //temp_inclusion.MouseLeave += Inclusion_MouseLeave;
  672. Can_Testitems.Children.Add(temp_inclusion);
  673. Can_Testitems.RegisterName("inclusion", temp_inclusion);
  674. }
  675. else
  676. {
  677. Can_Testitems.Children.Remove(Can_Testitems.FindName("inclusion") as Inclusion);
  678. Can_Testitems.UnregisterName("inclusion");
  679. }
  680. }
  681. else
  682. {
  683. testitems = list_lbltestitems[index].Content.ToString();
  684. }
  685. string steelid = find_steel_by_steel(steel).Rows[0][0].ToString();
  686. string stanardid = find_standard_bysteel_id(steelid).Rows[0][0].ToString();
  687. items = find_testitems(stanardid, testitems).Rows[0][4].ToString();
  688. if (find_testitems(stanardid, testitems).Rows[0][5].ToString() != "")
  689. {
  690. testitems_param = find_testitems(stanardid, testitems).Rows[0][5].ToString();
  691. }
  692. IsShowTextInput();
  693. Console.WriteLine("微电机点击testitems" + testitems_param);
  694. Console.WriteLine("点击testitems" + testitems);
  695. Console.WriteLine("点击Items" + items);
  696. }
  697. //private void Inclusion_MouseLeave(object sender, MouseEventArgs e)
  698. //{
  699. // Can_Testitems.Children.Remove(Can_Testitems.FindName("inclusion") as Inclusion);
  700. // Can_Testitems.UnregisterName("inclusion");
  701. //}
  702. /// <summary>
  703. /// 根据评级标准与检验项目返回一条记录
  704. /// </summary>
  705. private DataTable find_testitems(string standard_id, string testitem)
  706. {
  707. DataTable ds = new DataTable();
  708. try
  709. {
  710. SQLiteDataAdapter dat = new SQLiteDataAdapter("select * from t_testitems WHERE opt_standard='" + standard_id + "'and opt_testitem='" + testitem + "' and Isshow=1", conn);
  711. dat.Fill(ds);
  712. }
  713. catch (Exception e)
  714. {
  715. System.Windows.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  716. }
  717. return ds;
  718. }
  719. /// <summary>
  720. /// 是否显示录入按钮
  721. /// </summary>
  722. private void IsShowTextInput()
  723. {
  724. if (standard != "" && testitems != "")
  725. {
  726. txtinput.Visibility = Visibility.Visible;
  727. }
  728. else
  729. {
  730. txtinput.Visibility = Visibility.Hidden;
  731. //MessageBox.Show("请选择评级标准和检验项目");
  732. }
  733. if (ShowpageEvent != null)
  734. {
  735. ShowpageEvent(testitems);
  736. }
  737. }
  738. /// <summary>
  739. /// 录入试样信息
  740. /// </summary>
  741. /// <param name="sender"></param>
  742. /// <param name="e"></param>
  743. private void Input_sample_information(object sender, MouseButtonEventArgs e)
  744. {
  745. if (standard != "" && testitems != "")
  746. {
  747. Sample_Information_Enter sample = new Sample_Information_Enter();
  748. //sample.Owner = this;
  749. HwndSource winformWindow = (HwndSource.FromDependencyObject(this) as HwndSource);
  750. if (winformWindow != null)
  751. new WindowInteropHelper(sample) { Owner = winformWindow.Handle };
  752. sample.input_Inspection_project.Content = standard + " " + testitems;
  753. sample.ShowDialog();
  754. }
  755. else
  756. {
  757. MessageBox.Show("请选择评级标准和检验项目");
  758. }
  759. }
  760. }
  761. }