Nav apraksta

EditUsingTime.xaml.cs 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.Globalization;
  15. using WpfLocalization;
  16. using System.Threading;
  17. using System.Data.SqlClient;
  18. using System.Data;
  19. using System.Diagnostics;
  20. using System.IO;
  21. using System.Collections;
  22. using System.IO.Ports;
  23. using System.Collections.ObjectModel;
  24. using System.Reflection;
  25. using System.Configuration;
  26. using System.Collections.Specialized;
  27. using System.Data.SqlServerCe;
  28. using System.ComponentModel;
  29. using System.Windows.Threading;
  30. namespace WpfApplication19
  31. {
  32. /// <summary>
  33. /// Interaction logic for EditUsingTime.xaml
  34. /// </summary>
  35. public partial class EditUsingTime : Window
  36. {
  37. SqlCeConnection _opConn;
  38. public EditUsingTime()
  39. {
  40. InitializeComponent();
  41. initDatabase();
  42. initUI();
  43. }
  44. void initDatabase()
  45. {
  46. try
  47. {
  48. _opConn = Utils.createSqlCeConnection("operatingDbCS");
  49. }
  50. catch (SqlCeException se)
  51. {
  52. MessageBox.Show("operatingDbCS : ", se.Message);
  53. }
  54. }
  55. void initUI()
  56. {
  57. obInput.Text = getUsingTime("OB").ToString();
  58. ocInput.Text = getUsingTime("OC").ToString();
  59. rhInput.Text = getUsingTime("RH").ToString();
  60. }
  61. private int getUsingTime(string header)
  62. {
  63. var reader = Utils.Query(_opConn, "select * from UsingTime");
  64. reader.Read();
  65. int v = 0;
  66. switch (header)
  67. {
  68. case "OB":
  69. v = Convert.ToInt32(reader["ob"]);
  70. break;
  71. case "OC":
  72. v = Convert.ToInt32(reader["oc"]);
  73. break;
  74. case "RH":
  75. v = Convert.ToInt32(reader["rh"]);
  76. break;
  77. default:
  78. MessageBox.Show("Bad Header Name");
  79. break;
  80. }
  81. reader.Close();
  82. return v;
  83. }
  84. private void saveBtn_Click(object sender, RoutedEventArgs e)
  85. {
  86. updateUsingTime("OB", Convert.ToInt32(obInput.Text));
  87. updateUsingTime("OC", Convert.ToInt32(ocInput.Text));
  88. updateUsingTime("RH", Convert.ToInt32(rhInput.Text));
  89. //Application.Current.MainWindow.Show();
  90. var w = (MainWindow)Application.Current.MainWindow;
  91. w.refreshUsingTime();
  92. Close();
  93. }
  94. private void updateUsingTime(string p, int n = -1)
  95. {
  96. switch (p)
  97. {
  98. case "OB":
  99. Utils.Query(_opConn, "update UsingTime set ob = " + n);
  100. break;
  101. case "OC":
  102. Utils.Query(_opConn, "update UsingTime set oc = " + n);
  103. break;
  104. case "RH":
  105. Utils.Query(_opConn, "update UsingTime set rh = " + n);
  106. break;
  107. default:
  108. MessageBox.Show("Header Name Error");
  109. break;
  110. }
  111. }
  112. }
  113. }