OtherSelection.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace OTSMeasureApp._7_OTSProgMgrInfo
  11. {
  12. public partial class OtherSelectionForm : Form
  13. {
  14. string _OtherSelection = "";
  15. public string OtherSelection
  16. {
  17. set
  18. {
  19. _OtherSelection = value;
  20. }
  21. get
  22. {
  23. return _OtherSelection;
  24. }
  25. }
  26. public OtherSelectionForm()
  27. {
  28. InitializeComponent();
  29. }
  30. private void OtherSelection_Load(object sender, EventArgs e)
  31. {
  32. Init();
  33. }
  34. private void btn_ok_Click(object sender, EventArgs e)
  35. {
  36. if(!CheckAndSaveParams())
  37. {
  38. MessageBox.Show("Please check params!");
  39. return;
  40. }
  41. this.DialogResult = DialogResult.OK;
  42. }
  43. void Init()
  44. {
  45. string[] strit = _OtherSelection.Split(',');
  46. foreach( string str in strit)
  47. {
  48. string[] stit = str.Split(':');
  49. switch(stit[0])
  50. {
  51. case "dmax":
  52. cB_Dmax.Checked = true;
  53. string[] sit = stit[1].Split('-');
  54. tB_Dmax_min.Text = sit[0];
  55. tB_Dmax_max.Text = sit[1];
  56. break;
  57. case "dmin":
  58. cB_Dmin.Checked = true;
  59. string[] sit1 = stit[1].Split('-');
  60. tB_Dmin_min.Text = sit1[0];
  61. tB_Dmin_max.Text = sit1[1];
  62. break;
  63. case "aspect":
  64. cB_Aspect.Checked = true;
  65. string[] sit2 = stit[1].Split('-');
  66. tB_Aspect_min.Text = sit2[0];
  67. tB_Aspect_max.Text = sit2[1];
  68. break;
  69. case "orientation":
  70. cB_orientation.Checked = true;
  71. string[] sit3 = stit[1].Split('-');
  72. tB_orientation_min.Text = sit3[0];
  73. tB_orientation_max.Text = sit3[1];
  74. break;
  75. default:
  76. break;
  77. }
  78. }
  79. }
  80. bool CheckAndSaveParams()
  81. {
  82. _OtherSelection = "";
  83. double dia;
  84. if (cB_Dmax.Checked)
  85. {
  86. if (!double.TryParse(tB_Dmax_min.Text, out dia))
  87. {
  88. return false;
  89. }
  90. _OtherSelection += "dmax:" + dia.ToString() + "-";
  91. if (!double.TryParse(tB_Dmax_max.Text, out dia))
  92. {
  93. return false;
  94. }
  95. if(double.Parse(tB_Dmax_min.Text)>=dia)
  96. {
  97. return false;
  98. }
  99. _OtherSelection += dia.ToString() + ",";
  100. }
  101. if (cB_Dmin.Checked)
  102. {
  103. if (!double.TryParse(tB_Dmin_min.Text, out dia))
  104. {
  105. return false;
  106. }
  107. _OtherSelection += "dmin:" + dia.ToString() + "-";
  108. if (!double.TryParse(tB_Dmin_max.Text, out dia))
  109. {
  110. return false;
  111. }
  112. if (double.Parse(tB_Dmin_min.Text) >= dia)
  113. {
  114. return false;
  115. }
  116. _OtherSelection += dia.ToString() + ",";
  117. }
  118. if (cB_Aspect.Checked)
  119. {
  120. if (!double.TryParse(tB_Aspect_min.Text, out dia))
  121. {
  122. return false;
  123. }
  124. _OtherSelection += "aspect:" + dia.ToString() + "-";
  125. if (!double.TryParse(tB_Aspect_max.Text, out dia))
  126. {
  127. return false;
  128. }
  129. if (double.Parse(tB_Aspect_min.Text) >= dia)
  130. {
  131. return false;
  132. }
  133. _OtherSelection += dia.ToString() + ",";
  134. }
  135. if (cB_orientation.Checked)
  136. {
  137. if (!double.TryParse(tB_orientation_min.Text, out dia))
  138. {
  139. return false;
  140. }
  141. _OtherSelection += "orientation:" + dia.ToString() + "-";
  142. if (!double.TryParse(tB_orientation_max.Text, out dia))
  143. {
  144. return false;
  145. }
  146. if (double.Parse(tB_orientation_min.Text) >= dia)
  147. {
  148. return false;
  149. }
  150. _OtherSelection += dia.ToString() +",";
  151. }
  152. if(_OtherSelection!="")
  153. {
  154. _OtherSelection=_OtherSelection.Substring(0, _OtherSelection.Length - 1);
  155. }
  156. return true;
  157. }
  158. private void btn_cancel_Click(object sender, EventArgs e)
  159. {
  160. this.DialogResult = DialogResult.Cancel;
  161. }
  162. }
  163. }