暫無描述

ChooseRecord3.xaml.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.Data.Sql;
  14. using System.Data.SqlClient;
  15. using System.Collections.ObjectModel;
  16. using System.Windows.Interop;
  17. using System.Runtime.InteropServices;
  18. namespace WpfApplication19
  19. {
  20. /// <summary>
  21. /// Interaction logic for ChooseRecord2.xaml
  22. /// </summary>
  23. public partial class ChooseRecord3 : Window
  24. {
  25. private string _lotNo;
  26. private SqlConnection _proConn;
  27. private ObservableCollection<RecordSelection> _recordList = new ObservableCollection<RecordSelection>();
  28. private const int GWL_STYLE = -16;
  29. private const int WS_SYSMENU = 0x80000;
  30. [DllImport("user32.dll", SetLastError = true)]
  31. private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
  32. [DllImport("user32.dll")]
  33. private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
  34. public ChooseRecord3(string lotNo)
  35. {
  36. InitializeComponent();
  37. _lotNo = lotNo;
  38. try
  39. {
  40. _proConn = Utils.createSqlConnection("productionDbCS");
  41. }
  42. catch (SqlException se)
  43. {
  44. MessageBox.Show("productionDbCS : ", se.Message);
  45. }
  46. setUpGrid();
  47. }
  48. private void setUpGrid(){
  49. /*
  50. SqlDataReader reader = Utils.Query(_proConn, "select * from data where lot_no = '" + this.LotNo + "' group by updated_at");
  51. while (reader.Read())
  52. {
  53. DateTimeCB.Items.Add(new ComboBoxItem() { Tag = "a", Content = reader["updated_at"].ToString() });
  54. }
  55. reader.Close();*/
  56. SqlDataReader reader = Utils.Query(_proConn, "select * from lot_summary_rl where lot_no = '"+_lotNo+"' order by created_at desc");
  57. while(reader.Read()){
  58. _recordList.Add(new RecordSelection(){ lotNo = reader["lot_no"].ToString(),
  59. code = reader["code"].ToString(),
  60. date = Convert.ToDateTime(reader["created_at"]),
  61. avg = Convert.ToDouble(reader["avg"])});
  62. }
  63. chooseGrid.ItemsSource = _recordList;
  64. reader.Close();
  65. }
  66. private void selectBtn_Click(object sender, RoutedEventArgs e)
  67. {
  68. RecordSelection r = chooseGrid.SelectedItem as RecordSelection;
  69. var w = (MainWindow)Application.Current.MainWindow;
  70. try{
  71. w._rlWindow.setFilterLogData(r.date.ToString());
  72. Close();
  73. }catch{
  74. MessageBox.Show("Please Select A Record");
  75. }
  76. }
  77. private void Window_Loaded(object sender, RoutedEventArgs e)
  78. {
  79. var hwnd = new WindowInteropHelper(this).Handle;
  80. SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) & ~WS_SYSMENU);
  81. }
  82. private void cancel_Click(object sender, RoutedEventArgs e)
  83. {
  84. Close();
  85. }
  86. }
  87. /*
  88. class RecordSelection{
  89. public string lotNo { get; set; }
  90. public string code { get; set; }
  91. public DateTime date { get; set; }
  92. public double avg { get; set; }
  93. }*/
  94. }