CameraSettingsAddDialog.cs 15 KB

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