CameraSettingsAddDialog.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. using PaintDotNet.Base.SettingModel;
  2. using PaintDotNet.DbOpreate.DbBll;
  3. using PaintDotNet.DbOpreate.DbModel;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace PaintDotNet.Setting
  14. {
  15. /// <summary>
  16. /// 相机维护
  17. /// </summary>
  18. public partial class CameraSettingsAddDialog : Form
  19. {
  20. #region 控件
  21. private Label label2;
  22. private Label label3;
  23. private TextBox textBox1;
  24. private TextBox textBox2;
  25. private TextBox textBox3;
  26. private Label label4;
  27. private Label label1;
  28. private Label label5;
  29. private Button button1;
  30. private Button button2;
  31. #endregion
  32. private string pointId = string.Empty;
  33. private ListView fatherListView;
  34. private int listIndex = 0;
  35. public CameraSettingsAddDialog(string id, ListView listView, int index = 0)
  36. {
  37. StartPosition = FormStartPosition.CenterScreen;
  38. InitializeComponent();
  39. InitializeLanguageText();
  40. #region [展示控件]
  41. pointId = id;
  42. fatherListView = listView;
  43. listIndex = index;
  44. if (!string.IsNullOrEmpty(pointId))
  45. {
  46. var point = mic_camerasettings_BLL.FindDefault(Convert.ToInt32(pointId));
  47. if (point == null)
  48. {
  49. MessageBox.Show(PdnResources.GetString("Menu.Abnormalinformatio.Text"));
  50. }
  51. textBox1.Text = point.camera_model;
  52. textBox2.Text = point.side_length;
  53. textBox3.Text = point.resolution;
  54. }
  55. #endregion
  56. }
  57. #region 初始化
  58. private void InitializeLanguageText()
  59. {
  60. this.label1.Text = PdnResources.GetString("Menu.Cameramodel.text") + ":";
  61. this.label2.Text = PdnResources.GetString("Menu.Set.Generalsettings.Photosenselength.text") + ":";
  62. this.label3.Text = PdnResources.GetString("Menu.Set.Generalsettings.Sidelengthresolution.text") + ":";
  63. this.label4.Text = PdnResources.GetString("Menu.Micron.text");
  64. this.button1.Text = PdnResources.GetString("Menu.ensure.text");
  65. this.button2.Text = PdnResources.GetString("Menu.cancel.text");
  66. this.Text = PdnResources.GetString("Menu.Set.Generalsettings.Cameramaintenance.text");
  67. }
  68. private void InitializeComponent()
  69. {
  70. this.label1 = new System.Windows.Forms.Label();
  71. this.label2 = new System.Windows.Forms.Label();
  72. this.label3 = new System.Windows.Forms.Label();
  73. this.textBox1 = new System.Windows.Forms.TextBox();
  74. this.textBox2 = new System.Windows.Forms.TextBox();
  75. this.textBox3 = new System.Windows.Forms.TextBox();
  76. this.label4 = new System.Windows.Forms.Label();
  77. this.label5 = new System.Windows.Forms.Label();
  78. this.button1 = new System.Windows.Forms.Button();
  79. this.button2 = new System.Windows.Forms.Button();
  80. this.SuspendLayout();
  81. //
  82. // label1
  83. //
  84. this.label1.AutoSize = true;
  85. this.label1.Location = new System.Drawing.Point(34, 20);
  86. this.label1.Name = "label1";
  87. this.label1.Size = new System.Drawing.Size(65, 12);
  88. this.label1.TabIndex = 0;
  89. this.label1.Text = "相机型号:";
  90. //
  91. // label2
  92. //
  93. this.label2.AutoSize = true;
  94. this.label2.Location = new System.Drawing.Point(10, 52);
  95. this.label2.Name = "label2";
  96. this.label2.Size = new System.Drawing.Size(89, 12);
  97. this.label2.TabIndex = 1;
  98. this.label2.Text = "感光软件边长:";
  99. //
  100. // label3
  101. //
  102. this.label3.AutoSize = true;
  103. this.label3.Location = new System.Drawing.Point(22, 83);
  104. this.label3.Name = "label3";
  105. this.label3.Size = new System.Drawing.Size(77, 12);
  106. this.label3.TabIndex = 2;
  107. this.label3.Text = "边长分辨率:";
  108. //
  109. // textBox1
  110. //
  111. this.textBox1.Location = new System.Drawing.Point(95, 17);
  112. this.textBox1.MaxLength = 10;
  113. this.textBox1.Name = "textBox1";
  114. this.textBox1.Size = new System.Drawing.Size(164, 21);
  115. this.textBox1.TabIndex = 3;
  116. //
  117. // textBox2
  118. //
  119. this.textBox2.Location = new System.Drawing.Point(95, 49);
  120. this.textBox2.Name = "textBox2";
  121. this.textBox2.Size = new System.Drawing.Size(141, 21);
  122. this.textBox2.TabIndex = 4;
  123. this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
  124. //
  125. // textBox3
  126. //
  127. this.textBox3.Location = new System.Drawing.Point(95, 80);
  128. this.textBox3.Name = "textBox3";
  129. this.textBox3.Size = new System.Drawing.Size(164, 21);
  130. this.textBox3.TabIndex = 5;
  131. this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox3_KeyPress);
  132. //
  133. // label4
  134. //
  135. this.label4.AutoSize = true;
  136. this.label4.Location = new System.Drawing.Point(242, 52);
  137. this.label4.Name = "label4";
  138. this.label4.Size = new System.Drawing.Size(29, 12);
  139. this.label4.TabIndex = 6;
  140. this.label4.Text = "微米";
  141. //
  142. // label5
  143. //
  144. this.label5.AutoSize = true;
  145. this.label5.Location = new System.Drawing.Point(-1, 136);
  146. this.label5.Name = "label5";
  147. this.label5.Size = new System.Drawing.Size(287, 12);
  148. this.label5.TabIndex = 7;
  149. this.label5.Text = "-----------------------------------------------";
  150. //
  151. // button1
  152. //
  153. this.button1.Location = new System.Drawing.Point(98, 165);
  154. this.button1.Name = "button1";
  155. this.button1.Size = new System.Drawing.Size(80, 30);
  156. this.button1.TabIndex = 8;
  157. this.button1.Text = "确定";
  158. this.button1.UseVisualStyleBackColor = true;
  159. this.button1.Click += new System.EventHandler(this.button1_Click);
  160. //
  161. // button2
  162. //
  163. this.button2.Location = new System.Drawing.Point(189, 165);
  164. this.button2.Name = "button2";
  165. this.button2.Size = new System.Drawing.Size(80, 30);
  166. this.button2.TabIndex = 9;
  167. this.button2.Text = "取消";
  168. this.button2.UseVisualStyleBackColor = true;
  169. this.button2.Click += new System.EventHandler(this.button2_Click);
  170. //
  171. // CameraSettingsAddDialog
  172. //
  173. this.ClientSize = new System.Drawing.Size(284, 208);
  174. this.Controls.Add(this.button2);
  175. this.Controls.Add(this.button1);
  176. this.Controls.Add(this.label5);
  177. this.Controls.Add(this.label4);
  178. this.Controls.Add(this.textBox3);
  179. this.Controls.Add(this.textBox2);
  180. this.Controls.Add(this.textBox1);
  181. this.Controls.Add(this.label3);
  182. this.Controls.Add(this.label2);
  183. this.Controls.Add(this.label1);
  184. this.Name = "CameraSettingsAddDialog";
  185. this.Text = "相机维护";
  186. this.ResumeLayout(false);
  187. this.PerformLayout();
  188. }
  189. #endregion
  190. /// <summary>
  191. /// 格式限制
  192. /// </summary>
  193. /// <param name="sender"></param>
  194. /// <param name="e"></param>
  195. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  196. {
  197. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  198. e.Handled = true;
  199. //小数点的处理
  200. if ((int)e.KeyChar == 46)
  201. {
  202. if (textBox2.Text.Length <= 0)
  203. e.Handled = true; //小数点不能在第一位
  204. else
  205. {
  206. float f;
  207. float oldf;
  208. bool b1 = false, b2 = false;
  209. b1 = float.TryParse(textBox2.Text, out oldf);
  210. b2 = float.TryParse(textBox2.Text + e.KeyChar.ToString(), out f);
  211. if (b2 == false)
  212. {
  213. if (b1 == true)
  214. e.Handled = true;
  215. else
  216. e.Handled = false;
  217. }
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// 格式限制
  223. /// </summary>
  224. /// <param name="sender"></param>
  225. /// <param name="e"></param>
  226. private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
  227. {
  228. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  229. e.Handled = true;
  230. //小数点的处理
  231. if ((int)e.KeyChar == 46)
  232. {
  233. if (textBox3.Text.Length <= 0)
  234. e.Handled = true; //小数点不能在第一位
  235. else
  236. {
  237. float f;
  238. float oldf;
  239. bool b1 = false, b2 = false;
  240. b1 = float.TryParse(textBox3.Text, out oldf);
  241. b2 = float.TryParse(textBox3.Text + e.KeyChar.ToString(), out f);
  242. if (b2 == false)
  243. {
  244. if (b1 == true)
  245. e.Handled = true;
  246. else
  247. e.Handled = false;
  248. }
  249. }
  250. }
  251. }
  252. ///// <summary>
  253. ///// textbox1获得焦点
  254. ///// </summary>
  255. ///// <param name="sender"></param>
  256. ///// <param name="e"></param>
  257. //private void Textbox1_Enter(object sender, EventArgs e)
  258. //{
  259. // if (textbox1HasText == false)
  260. // this.textBox1.Text = "";
  261. // this.textBox1.ForeColor = Color.Black;
  262. //}
  263. ///// <summary>
  264. ///// textbox1失去焦点
  265. ///// </summary>
  266. ///// <param name="sender"></param>
  267. ///// <param name="e"></param>
  268. //private void Textbox1_Leave(object sender, EventArgs e)
  269. //{
  270. // if (this.textBox1.Text == "")
  271. // {
  272. // this.textBox1.Text = "请输入相机型号";
  273. // this.textBox1.ForeColor = Color.LightGray;
  274. // textbox1HasText = false;
  275. // }
  276. // else
  277. // textbox1HasText = true;
  278. //}
  279. ///// <summary>
  280. ///// textbox2获得焦点
  281. ///// </summary>
  282. ///// <param name="sender"></param>
  283. ///// <param name="e"></param>
  284. //private void Textbox2_Enter(object sender, EventArgs e)
  285. //{
  286. // if (textbox2HasText == false)
  287. // this.textBox2.Text = "";
  288. // this.textBox2.ForeColor = Color.Black;
  289. //}
  290. ///// <summary>
  291. ///// textbox2失去焦点
  292. ///// </summary>
  293. ///// <param name="sender"></param>
  294. ///// <param name="e"></param>
  295. //private void Textbox2_Leave(object sender, EventArgs e)
  296. //{
  297. // if (this.textBox2.Text == "")
  298. // {
  299. // this.textBox2.Text = "请输入感光软件边长";
  300. // this.textBox2.ForeColor = Color.LightGray;
  301. // textbox2HasText = false;
  302. // }
  303. // else
  304. // textbox2HasText = true;
  305. //}
  306. ///// <summary>
  307. ///// textbox3获得焦点
  308. ///// </summary>
  309. ///// <param name="sender"></param>
  310. ///// <param name="e"></param>
  311. //private void Textbox3_Enter(object sender, EventArgs e)
  312. //{
  313. // if (textbox3HasText == false)
  314. // this.textBox3.Text = "";
  315. // this.textBox3.ForeColor = Color.Black;
  316. //}
  317. ///// <summary>
  318. ///// textbox3失去焦点
  319. ///// </summary>
  320. ///// <param name="sender"></param>
  321. ///// <param name="e"></param>
  322. //private void Textbox3_Leave(object sender, EventArgs e)
  323. //{
  324. // if (this.textBox3.Text == "")
  325. // {
  326. // this.textBox3.Text = "请输入边长分辨率";
  327. // this.textBox3.ForeColor = Color.LightGray;
  328. // textbox3HasText = false;
  329. // }
  330. // else
  331. // textbox3HasText = true;
  332. //}
  333. /// <summary>
  334. /// 确认按钮
  335. /// </summary>
  336. /// <param name="sender"></param>
  337. /// <param name="e"></param>
  338. private void button1_Click(object sender, EventArgs e)
  339. {
  340. var id = pointId;
  341. if (string.IsNullOrEmpty(textBox1.Text))
  342. {
  343. MessageBox.Show(PdnResources.GetString("Menu.Cameramodelplease.Text"));
  344. return;
  345. }
  346. else if (string.IsNullOrEmpty(textBox2.Text))
  347. {
  348. MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthsidelengthofphotosensitiveso.Text"));
  349. return;
  350. }
  351. else if (string.IsNullOrEmpty(textBox3.Text))
  352. {
  353. MessageBox.Show(PdnResources.GetString("Menu.leaseenterthesidelengthr.Text"));
  354. return;
  355. }
  356. if (string.IsNullOrEmpty(id))
  357. {
  358. var point = new mic_camerasettings();
  359. point.delete_flag = 2;
  360. point.camera_model = textBox1.Text;
  361. point.side_length = textBox2.Text;
  362. point.resolution = textBox3.Text;
  363. mic_camerasettings_BLL.Add(point);
  364. fatherListView.BeginUpdate();
  365. var lv = new ListViewItem();
  366. lv.Text = "2";
  367. lv.SubItems.Add("×");
  368. lv.SubItems.Add(point.camera_model);
  369. lv.SubItems.Add(point.side_length);
  370. lv.SubItems.Add(point.resolution);
  371. lv.Tag = point.id;
  372. fatherListView.Items.Add(lv);
  373. fatherListView.EndUpdate();
  374. }
  375. else
  376. {
  377. var point = mic_camerasettings_BLL.FindDefault(Convert.ToInt32(pointId));
  378. var screenRulesId = config.Camera;
  379. if (point == null)
  380. {
  381. MessageBox.Show(PdnResources.GetString("Menu.Abnormalinformatio.Text"));
  382. }
  383. point.camera_model = textBox1.Text;
  384. point.side_length = textBox2.Text;
  385. point.resolution = textBox3.Text;
  386. mic_camerasettings_BLL.Update(point);
  387. fatherListView.BeginUpdate();
  388. var lv = fatherListView.Items[listIndex];
  389. lv.SubItems[1].Text = screenRulesId == int.Parse(id.ToString()) ? "√" : "×";
  390. lv.SubItems[2].Text = point.camera_model;
  391. lv.SubItems[3].Text = point.side_length;
  392. lv.SubItems[4].Text = point.resolution;
  393. fatherListView.EndUpdate();
  394. }
  395. Close();
  396. }
  397. private ConfigModel config = Startup.instance.configModel;
  398. /// <summary>
  399. ///取消按钮
  400. /// </summary>
  401. /// <param name="sender"></param>
  402. /// <param name="e"></param>
  403. private void button2_Click(object sender, EventArgs e)
  404. {
  405. Hide();
  406. }
  407. }
  408. }