SpecialInfoDialog.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SQLite;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using PaintDotNet.Base.CommTool;
  12. namespace PaintDotNet.GeneralAnalysis.Special
  13. {
  14. public partial class SpecialInfoDialog : Form
  15. {
  16. #region
  17. /// <summary>
  18. /// Required designer variable.
  19. /// </summary>
  20. private System.ComponentModel.IContainer components = null;
  21. /// <summary>
  22. /// Clean up any resources being used.
  23. /// </summary>
  24. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  25. protected override void Dispose(bool disposing)
  26. {
  27. if (disposing && (components != null))
  28. {
  29. components.Dispose();
  30. }
  31. base.Dispose(disposing);
  32. }
  33. #region Windows Form Designer generated code
  34. private void InitializeLanguageText()
  35. {
  36. this.label1.Text = PdnResources.GetString("Menu.name.text") + ":";
  37. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  38. this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  39. this.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  40. this.groupBox2.Text = PdnResources.GetString("Menu.Levelinformation.text");
  41. this.label4.Text = PdnResources.GetString("Menu.Endvalue.text") + ":";
  42. this.label3.Text = PdnResources.GetString("Menu.Startingvalue.text") + ":";
  43. this.label2.Text = PdnResources.GetString("Menu.instruction.text") + ":";
  44. }
  45. /// <summary>
  46. /// Required method for Designer support - do not modify
  47. /// the contents of this method with the code editor.
  48. /// </summary>
  49. private void InitializeComponent()
  50. {
  51. this.groupBox1 = new System.Windows.Forms.GroupBox();
  52. this.btnClose = new System.Windows.Forms.Button();
  53. this.btnSave = new System.Windows.Forms.Button();
  54. this.groupBox2 = new System.Windows.Forms.GroupBox();
  55. this.txtMaxValue = new System.Windows.Forms.TextBox();
  56. this.txtMinValue = new System.Windows.Forms.TextBox();
  57. this.txtDescription = new System.Windows.Forms.TextBox();
  58. this.txtName = new System.Windows.Forms.TextBox();
  59. this.label4 = new System.Windows.Forms.Label();
  60. this.label3 = new System.Windows.Forms.Label();
  61. this.label2 = new System.Windows.Forms.Label();
  62. this.label1 = new System.Windows.Forms.Label();
  63. this.groupBox1.SuspendLayout();
  64. this.groupBox2.SuspendLayout();
  65. this.SuspendLayout();
  66. //
  67. // groupBox1
  68. //
  69. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  70. | System.Windows.Forms.AnchorStyles.Right)));
  71. this.groupBox1.Controls.Add(this.btnClose);
  72. this.groupBox1.Controls.Add(this.btnSave);
  73. this.groupBox1.Location = new System.Drawing.Point(9, 10);
  74. this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
  75. this.groupBox1.Name = "groupBox1";
  76. this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
  77. this.groupBox1.Size = new System.Drawing.Size(324, 66);
  78. this.groupBox1.TabIndex = 0;
  79. this.groupBox1.TabStop = false;
  80. this.groupBox1.Text = "操作";
  81. //
  82. // btnClose
  83. //
  84. this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  85. this.btnClose.Location = new System.Drawing.Point(238, 22);
  86. this.btnClose.Margin = new System.Windows.Forms.Padding(2);
  87. this.btnClose.Name = "btnClose";
  88. this.btnClose.Size = new System.Drawing.Size(61, 29);
  89. this.btnClose.TabIndex = 1;
  90. this.btnClose.Text = "关闭";
  91. this.btnClose.UseVisualStyleBackColor = true;
  92. this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
  93. //
  94. // btnSave
  95. //
  96. this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  97. this.btnSave.Location = new System.Drawing.Point(164, 22);
  98. this.btnSave.Margin = new System.Windows.Forms.Padding(2);
  99. this.btnSave.Name = "btnSave";
  100. this.btnSave.Size = new System.Drawing.Size(61, 29);
  101. this.btnSave.TabIndex = 0;
  102. this.btnSave.Text = "保存";
  103. this.btnSave.UseVisualStyleBackColor = true;
  104. this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  105. //
  106. // groupBox2
  107. //
  108. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  109. | System.Windows.Forms.AnchorStyles.Left)
  110. | System.Windows.Forms.AnchorStyles.Right)));
  111. this.groupBox2.Controls.Add(this.txtMaxValue);
  112. this.groupBox2.Controls.Add(this.txtMinValue);
  113. this.groupBox2.Controls.Add(this.txtDescription);
  114. this.groupBox2.Controls.Add(this.txtName);
  115. this.groupBox2.Controls.Add(this.label4);
  116. this.groupBox2.Controls.Add(this.label3);
  117. this.groupBox2.Controls.Add(this.label2);
  118. this.groupBox2.Controls.Add(this.label1);
  119. this.groupBox2.Location = new System.Drawing.Point(9, 80);
  120. this.groupBox2.Margin = new System.Windows.Forms.Padding(2);
  121. this.groupBox2.Name = "groupBox2";
  122. this.groupBox2.Padding = new System.Windows.Forms.Padding(2);
  123. this.groupBox2.Size = new System.Drawing.Size(324, 221);
  124. this.groupBox2.TabIndex = 1;
  125. this.groupBox2.TabStop = false;
  126. this.groupBox2.Text = "级别信息";
  127. //
  128. // txtMaxValue
  129. //
  130. this.txtMaxValue.Location = new System.Drawing.Point(89, 163);
  131. this.txtMaxValue.Margin = new System.Windows.Forms.Padding(2);
  132. this.txtMaxValue.Name = "txtMaxValue";
  133. this.txtMaxValue.Size = new System.Drawing.Size(206, 21);
  134. this.txtMaxValue.TabIndex = 7;
  135. this.txtMaxValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtMaxValue_KeyPress);
  136. //
  137. // txtMinValue
  138. //
  139. this.txtMinValue.Location = new System.Drawing.Point(89, 122);
  140. this.txtMinValue.Margin = new System.Windows.Forms.Padding(2);
  141. this.txtMinValue.Name = "txtMinValue";
  142. this.txtMinValue.Size = new System.Drawing.Size(206, 21);
  143. this.txtMinValue.TabIndex = 6;
  144. this.txtMinValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtMinValue_KeyPress);
  145. //
  146. // txtDescription
  147. //
  148. this.txtDescription.Location = new System.Drawing.Point(89, 80);
  149. this.txtDescription.Margin = new System.Windows.Forms.Padding(2);
  150. this.txtDescription.Name = "txtDescription";
  151. this.txtDescription.Size = new System.Drawing.Size(206, 21);
  152. this.txtDescription.TabIndex = 5;
  153. //
  154. // txtName
  155. //
  156. this.txtName.Location = new System.Drawing.Point(89, 38);
  157. this.txtName.Margin = new System.Windows.Forms.Padding(2);
  158. this.txtName.MaxLength = 10;
  159. this.txtName.Name = "txtName";
  160. this.txtName.Size = new System.Drawing.Size(206, 21);
  161. this.txtName.TabIndex = 4;
  162. //
  163. // label4
  164. //
  165. this.label4.AutoSize = true;
  166. this.label4.Location = new System.Drawing.Point(23, 169);
  167. this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  168. this.label4.Name = "label4";
  169. this.label4.Size = new System.Drawing.Size(53, 12);
  170. this.label4.TabIndex = 3;
  171. this.label4.Text = "终止值:";
  172. //
  173. // label3
  174. //
  175. this.label3.AutoSize = true;
  176. this.label3.Location = new System.Drawing.Point(23, 127);
  177. this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  178. this.label3.Name = "label3";
  179. this.label3.Size = new System.Drawing.Size(53, 12);
  180. this.label3.TabIndex = 2;
  181. this.label3.Text = "起始值:";
  182. //
  183. // label2
  184. //
  185. this.label2.AutoSize = true;
  186. this.label2.Location = new System.Drawing.Point(23, 86);
  187. this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  188. this.label2.Name = "label2";
  189. this.label2.Size = new System.Drawing.Size(41, 12);
  190. this.label2.TabIndex = 1;
  191. this.label2.Text = "说明:";
  192. //
  193. // label1
  194. //
  195. this.label1.AutoSize = true;
  196. this.label1.Location = new System.Drawing.Point(23, 44);
  197. this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  198. this.label1.Name = "label1";
  199. this.label1.Size = new System.Drawing.Size(41, 12);
  200. this.label1.TabIndex = 0;
  201. this.label1.Text = "名称:";
  202. //
  203. // SpecialInfoDialog
  204. //
  205. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  206. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  207. this.ClientSize = new System.Drawing.Size(341, 310);
  208. this.Controls.Add(this.groupBox2);
  209. this.Controls.Add(this.groupBox1);
  210. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  211. this.Margin = new System.Windows.Forms.Padding(2);
  212. this.MaximizeBox = false;
  213. this.MinimizeBox = false;
  214. this.Name = "SpecialInfoDialog";
  215. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  216. this.Text = "新增级别数据";
  217. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpecialInfoDialog_FormClosing);
  218. this.groupBox1.ResumeLayout(false);
  219. this.groupBox2.ResumeLayout(false);
  220. this.groupBox2.PerformLayout();
  221. this.ResumeLayout(false);
  222. }
  223. #endregion
  224. private System.Windows.Forms.GroupBox groupBox1;
  225. private System.Windows.Forms.Button btnClose;
  226. private System.Windows.Forms.Button btnSave;
  227. private System.Windows.Forms.GroupBox groupBox2;
  228. private System.Windows.Forms.Label label4;
  229. private System.Windows.Forms.Label label3;
  230. private System.Windows.Forms.Label label2;
  231. private System.Windows.Forms.Label label1;
  232. private System.Windows.Forms.TextBox txtMaxValue;
  233. private System.Windows.Forms.TextBox txtMinValue;
  234. private System.Windows.Forms.TextBox txtDescription;
  235. private System.Windows.Forms.TextBox txtName;
  236. #endregion
  237. private bool m_isAdd;
  238. private SQLiteHelper m_sqlHelper;
  239. private string m_id;
  240. private DataTable m_specialList;
  241. private Form m_parentForm;
  242. private string m_specialId;
  243. public SpecialInfoDialog(Form form, string specialId, bool isAdd, string id)
  244. {
  245. m_parentForm = form;
  246. m_id = id;
  247. m_isAdd = isAdd;
  248. m_specialId = specialId;
  249. InitializeComponent();
  250. InitializeLanguageText();
  251. InitializeData();
  252. }
  253. private void InitializeData()
  254. {
  255. m_sqlHelper = new SQLiteHelper(); //连接数据库
  256. m_sqlHelper.Connect();
  257. if (m_isAdd)
  258. {
  259. this.Text = PdnResources.GetString("Menu.Newleveldata.text");
  260. }
  261. else
  262. {
  263. this.Text = PdnResources.GetString("Menu.Modifyleveldata.text");
  264. if (m_id != null)
  265. {
  266. string select_sql = "select * from mic_special_definition_info where id = '" + m_id + "'"; //查询的SQL语句
  267. m_specialList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  268. txtName.Text = m_specialList.Rows[0]["name"].ToString();
  269. txtDescription.Text = m_specialList.Rows[0]["description"].ToString();
  270. txtMinValue.Text = m_specialList.Rows[0]["minValue"].ToString();
  271. txtMaxValue.Text = m_specialList.Rows[0]["maxValue"].ToString();
  272. }
  273. }
  274. }
  275. private void SpecialInfoDialog_FormClosing(object sender, FormClosingEventArgs e)
  276. {
  277. m_sqlHelper.DisConnect();
  278. }
  279. private void btnClose_Click(object sender, EventArgs e)
  280. {
  281. this.Close();
  282. }
  283. private void btnSave_Click(object sender, EventArgs e)
  284. {
  285. string name = txtName.Text.Trim();
  286. if (string.IsNullOrWhiteSpace(name) || string.IsNullOrEmpty(name))
  287. {
  288. MessageBox.Show(PdnResources.GetString("Menu.Pleasefillinthename.Text"));
  289. return;
  290. }
  291. string description = txtDescription.Text.Trim();
  292. if (string.IsNullOrWhiteSpace(txtMinValue.Text.Trim()) || string.IsNullOrEmpty(txtMinValue.Text.Trim()))
  293. {
  294. MessageBox.Show(PdnResources.GetString("Menu.Pleasefillinthestartingvalue.Text"));
  295. return;
  296. }
  297. if (string.IsNullOrWhiteSpace(txtMaxValue.Text.Trim()) || string.IsNullOrEmpty(txtMaxValue.Text.Trim()))
  298. {
  299. MessageBox.Show(PdnResources.GetString("Menu.Pleasefillintheterminationvalue.Text"));
  300. return;
  301. }
  302. decimal minValue = 0;
  303. decimal maxValue = 0;
  304. try
  305. {
  306. minValue = decimal.Parse(txtMinValue.Text.Trim());
  307. maxValue = decimal.Parse(txtMaxValue.Text.Trim());
  308. if (minValue >= maxValue)
  309. {
  310. MessageBox.Show(PdnResources.GetString("Menu.ationvaluemusbegreaterthanthestartingvalue.Text"));
  311. return;
  312. }
  313. }
  314. catch(Exception)
  315. {
  316. MessageBox.Show(PdnResources.GetString("Menu.estartingorendingvaluesaretoolar.Text"));
  317. return;
  318. }
  319. if (m_isAdd)
  320. {
  321. string select_sql = "select * from mic_special_definition_info where ((minValue <= " + minValue + " and maxValue > " + minValue + ") or (minValue <= " + maxValue + " and maxValue > " + maxValue + ")) and special_id ='"+ m_specialId +"'"; //查询的SQL语句
  322. DataTable list = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  323. if (list.Rows.Count > 0)
  324. {
  325. MessageBox.Show(PdnResources.GetString("Menu.hestartandendvaluescannotrecor.Text"));
  326. return;
  327. }
  328. string id = System.Guid.NewGuid().ToString("N");
  329. string insert_sql = "insert into mic_special_definition_info(id, special_id, name, description, minValue, maxValue) values(?,?,?,?,?,?)"; //插入的SQL语句(带参数)
  330. SQLiteParameter[] para = new SQLiteParameter[6]; //构造并绑定参数
  331. string[] tag = { "id", "special_id", "name", "description", "minValue", "maxValue" };
  332. Object[] value = { id, m_specialId, name, description, minValue, maxValue };
  333. for (int i = 0; i < 6; i++)
  334. {
  335. para[i] = new SQLiteParameter(tag[i], value[i]);
  336. }
  337. m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  338. //MessageBox.Show(PdnResources.GetString("Menu.Addsuccessfully.text"));
  339. }
  340. else
  341. {
  342. string select_sql = "select * from mic_special_definition_info where ((minValue <= " + minValue + " and maxValue > " + minValue + ") or (minValue <= " + maxValue + " and maxValue > " + maxValue + ")) and id <> '" + m_id + "' and special_id ='" + m_specialId + "'"; //查询的SQL语句
  343. DataTable list = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  344. if (list.Rows.Count > 0)
  345. {
  346. MessageBox.Show(PdnResources.GetString("Menu.hestartandendvaluescannotrecor.Text"));
  347. return;
  348. }
  349. string update_sql = "update mic_special_definition_info set name = ?, description= ?, minValue = ?, maxValue = ? where id = '" + m_id + "'"; //SQL语句(带参数)
  350. SQLiteParameter[] para = new SQLiteParameter[4]; //构造并绑定参数
  351. string[] tag = { "name", "description", "minValue", "maxValue" };
  352. Object[] value = { name, description, minValue, maxValue };
  353. for (int i = 0; i < 4; i++)
  354. {
  355. para[i] = new SQLiteParameter(tag[i], value[i]);
  356. }
  357. int ret = m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更新操作
  358. if (ret < 0)
  359. {
  360. //MessageBox.Show(PdnResources.GetString("Menu.Successfullymodified.text"));
  361. MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
  362. }
  363. //else
  364. //{
  365. // MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
  366. //}
  367. }
  368. ((SpecialDefinitionDialog)m_parentForm).UpdateInfoCatalog();
  369. this.Close();
  370. }
  371. private void txtMinValue_KeyPress(object sender, KeyPressEventArgs e)
  372. {
  373. ChkKeyPress(sender, e);
  374. }
  375. private void txtMaxValue_KeyPress(object sender, KeyPressEventArgs e)
  376. {
  377. ChkKeyPress(sender, e);
  378. }
  379. /// <summary>
  380. /// 只能是数值
  381. /// </summary>
  382. /// <param name="sender"></param>
  383. /// <param name="e"></param>
  384. private void ChkKeyPress(object sender, KeyPressEventArgs e)
  385. {
  386. string value = ((TextBox)sender).Text;
  387. //判断按键是不是要输入的类型。
  388. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
  389. e.Handled = true;
  390. //小数点的处理。
  391. if ((int)e.KeyChar == 46) //小数点
  392. {
  393. if (value.Length <= 0)
  394. e.Handled = true; //小数点不能在第一位
  395. else
  396. {
  397. float f;
  398. float oldf;
  399. bool b1 = false, b2 = false;
  400. b1 = float.TryParse(value, out oldf);
  401. b2 = float.TryParse(value + e.KeyChar.ToString(), out f);
  402. if (b2 == false)
  403. {
  404. if (b1 == true)
  405. e.Handled = true;
  406. else
  407. e.Handled = false;
  408. }
  409. }
  410. }
  411. }
  412. }
  413. }