FeildParam.xaml.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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.Shapes;
  14. using System.IO;
  15. using System.Data.SQLite;
  16. using System.Data;
  17. namespace AIRS
  18. {
  19. /// <summary>
  20. /// FeildParam.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class FeildParam : Window
  23. {
  24. public string standard = "";
  25. public string ret_shape = "";
  26. public double ret_dia = 0;
  27. public int ret_mul = 0;
  28. private string path = Directory.GetCurrentDirectory(); //程序工作目录
  29. System.Data.SQLite.SQLiteConnection conn = new System.Data.SQLite.SQLiteConnection();
  30. System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder();
  31. private string _shape = "";
  32. private string _diameter = "";
  33. private string _multiple = "";
  34. public FeildParam()
  35. {
  36. InitializeComponent();
  37. }
  38. private void rdb_circle_Checked(object sender, RoutedEventArgs e)
  39. {
  40. _shape = "Circle";
  41. }
  42. private void Window_Loaded(object sender, RoutedEventArgs e)
  43. {
  44. connstr.DataSource = path + "\\datas.db";
  45. conn.ConnectionString = connstr.ToString();
  46. conn.Open();
  47. System.Data.SQLite.SQLiteDataAdapter da = new SQLiteDataAdapter("select * from t_standard where opt_standard='" + standard + "'", conn);
  48. DataTable ds = new DataTable();
  49. da.Fill(ds);
  50. if(ds.Rows.Count>0)
  51. {
  52. if(ds.Rows[0][2].ToString().Substring(0,2)=="GB" && ds.Rows[0][4]!= DBNull.Value)
  53. {
  54. _shape = ds.Rows[0][4].ToString();
  55. if(_shape=="Circle")
  56. {
  57. rdb_circle.IsChecked = true;
  58. }
  59. else
  60. {
  61. rdb_rect.IsChecked = true;
  62. }
  63. _diameter = ds.Rows[0][5].ToString();
  64. String[] dia = _diameter.Split(',');
  65. foreach(string dd in dia)
  66. {
  67. ComboBoxItem cbbi = new ComboBoxItem();
  68. cbbi.Content = dd;
  69. cbbdiameter.Items.Add(cbbi);
  70. }
  71. cbbdiameter.SelectedIndex = 0;
  72. _multiple = ds.Rows[0][6].ToString();
  73. String[] mul = _multiple.Split(',');
  74. foreach (string mull in mul)
  75. {
  76. ComboBoxItem cbbi = new ComboBoxItem();
  77. cbbi.Content = mull;
  78. cbbmultiple.Items.Add(cbbi);
  79. }
  80. cbbmultiple.SelectedIndex = 0;
  81. }
  82. else
  83. {
  84. ComboBoxItem comboBox = new ComboBoxItem();
  85. comboBox.Content = "70";
  86. cbbdiameter.Items.Add(comboBox);
  87. comboBox = new ComboBoxItem();
  88. comboBox.Content = "80";
  89. cbbdiameter.Items.Add(comboBox);
  90. comboBox = new ComboBoxItem();
  91. comboBox.Content = "100";
  92. cbbmultiple.Items.Add(comboBox);
  93. comboBox = new ComboBoxItem();
  94. comboBox.Content = "500";
  95. cbbmultiple.Items.Add(comboBox);
  96. }
  97. }
  98. else
  99. {
  100. ComboBoxItem comboBox = new ComboBoxItem();
  101. comboBox.Content = "70";
  102. cbbdiameter.Items.Add(comboBox);
  103. comboBox = new ComboBoxItem();
  104. comboBox.Content = "80";
  105. cbbdiameter.Items.Add(comboBox);
  106. comboBox = new ComboBoxItem();
  107. comboBox.Content = "100";
  108. cbbmultiple.Items.Add(comboBox);
  109. comboBox = new ComboBoxItem();
  110. comboBox.Content = "500";
  111. cbbmultiple.Items.Add(comboBox);
  112. }
  113. }
  114. private void rdb_rect_Checked(object sender, RoutedEventArgs e)
  115. {
  116. _shape = "Rectangle";
  117. }
  118. private void BtnExit_Click(object sender, RoutedEventArgs e)
  119. {
  120. this.DialogResult = false;
  121. }
  122. private void BtnLogin_Click(object sender, RoutedEventArgs e)
  123. {
  124. ret_shape = _shape;
  125. if(!Double.TryParse(cbbdiameter.Text, out ret_dia))
  126. {
  127. MessageBox.Show("直径输入错误!", "提示");
  128. cbbdiameter.Focus();
  129. return;
  130. }
  131. if (!Int32.TryParse(cbbmultiple.Text, out ret_mul))
  132. {
  133. MessageBox.Show("放大倍数输入错误!", "提示");
  134. cbbmultiple.Focus();
  135. return;
  136. }
  137. this.DialogResult = true;
  138. }
  139. }
  140. }