SpecialDialog.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 class SpecialDialog : 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.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  37. this.label1.Text = PdnResources.GetString("Menu.name.text") + ":";
  38. }
  39. /// <summary>
  40. /// Required method for Designer support - do not modify
  41. /// the contents of this method with the code editor.
  42. /// </summary>
  43. private void InitializeComponent()
  44. {
  45. this.btnSave = new System.Windows.Forms.Button();
  46. this.txtName = new System.Windows.Forms.TextBox();
  47. this.label1 = new System.Windows.Forms.Label();
  48. this.SuspendLayout();
  49. //
  50. // btnSave
  51. //
  52. this.btnSave.Location = new System.Drawing.Point(128, 76);
  53. this.btnSave.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
  54. this.btnSave.Name = "btnSave";
  55. this.btnSave.Size = new System.Drawing.Size(66, 26);
  56. this.btnSave.TabIndex = 5;
  57. this.btnSave.Text = "保存";
  58. this.btnSave.UseVisualStyleBackColor = true;
  59. this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  60. //
  61. // txtName
  62. //
  63. this.txtName.Location = new System.Drawing.Point(102, 39);
  64. this.txtName.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
  65. this.txtName.MaxLength = 15;
  66. this.txtName.Name = "txtName";
  67. this.txtName.Size = new System.Drawing.Size(158, 21);
  68. this.txtName.TabIndex = 4;
  69. //
  70. // label1
  71. //
  72. this.label1.AutoSize = true;
  73. this.label1.Location = new System.Drawing.Point(51, 42);
  74. this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  75. this.label1.Name = "label1";
  76. this.label1.Size = new System.Drawing.Size(41, 12);
  77. this.label1.TabIndex = 3;
  78. this.label1.Text = "名称:";
  79. //
  80. // SpecialDialog
  81. //
  82. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  83. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  84. this.ClientSize = new System.Drawing.Size(324, 135);
  85. this.Controls.Add(this.btnSave);
  86. this.Controls.Add(this.txtName);
  87. this.Controls.Add(this.label1);
  88. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  89. this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
  90. this.MaximizeBox = false;
  91. this.MinimizeBox = false;
  92. this.Name = "SpecialDialog";
  93. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  94. this.Text = "新增专项数据";
  95. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpecialDialog_FormClosing);
  96. this.ResumeLayout(false);
  97. this.PerformLayout();
  98. }
  99. #endregion
  100. private System.Windows.Forms.Button btnSave;
  101. private System.Windows.Forms.TextBox txtName;
  102. private System.Windows.Forms.Label label1;
  103. #endregion
  104. private bool m_isAdd;
  105. private SQLiteHelper m_sqlHelper;
  106. private string m_id;
  107. private DataTable m_specialList;
  108. private Form m_parentForm;
  109. private SpecialItem m_item;
  110. public SpecialDialog(Form form, bool isAdd, string id, SpecialItem item)
  111. {
  112. m_parentForm = form;
  113. m_id = id;
  114. m_isAdd = isAdd;
  115. m_item = item;
  116. InitializeComponent();
  117. InitializeLanguageText();
  118. InitializeData();
  119. }
  120. private void InitializeData()
  121. {
  122. m_sqlHelper = new SQLiteHelper(); //连接数据库
  123. m_sqlHelper.Connect();
  124. if (m_isAdd)
  125. {
  126. this.Text = PdnResources.GetString("Menu.Addspecialdata.text");
  127. }
  128. else
  129. {
  130. this.Text = PdnResources.GetString("Menu.Modifyspecificdata.text");
  131. if (m_id != null)
  132. {
  133. string select_sql = "select * from mic_special_definition where id = '" + m_id +"'"; //查询的SQL语句
  134. m_specialList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  135. txtName.Text = m_specialList.Rows[0]["special_name"].ToString();
  136. }
  137. }
  138. }
  139. private void btnSave_Click(object sender, EventArgs e)
  140. {
  141. string name = txtName.Text.Trim();
  142. if (string.IsNullOrWhiteSpace(name) || string.IsNullOrEmpty(name))
  143. {
  144. MessageBox.Show(PdnResources.GetString("Menu.namecannotbeEmpty.text"));
  145. return;
  146. }
  147. if (m_isAdd)
  148. {
  149. string id = System.Guid.NewGuid().ToString("N");
  150. string insert_sql = "insert into mic_special_definition(id,special_type, special_name, delete_flag) values(?,?,?,0)"; //插入的SQL语句(带参数)
  151. SQLiteParameter[] para = new SQLiteParameter[3]; //构造并绑定参数
  152. string[] tag = { "id", "special_type", "special_name" };
  153. Object[] value = { id, m_item, name };
  154. for (int i = 0; i < 3; i++)
  155. {
  156. para[i] = new SQLiteParameter(tag[i], value[i]);
  157. }
  158. m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  159. //MessageBox.Show(PdnResources.GetString("Menu.Addsuccessfully.text"));
  160. }
  161. else
  162. {
  163. string update_sql = "update mic_special_definition set special_name = ? where id = '" + m_id + "'"; //SQL语句(带参数)
  164. SQLiteParameter[] para = new SQLiteParameter[1]; //构造并绑定参数
  165. string[] tag = { "special_name" };
  166. Object[] value = { name };
  167. for (int i = 0; i < 1; i++)
  168. {
  169. para[i] = new SQLiteParameter(tag[i], value[i]);
  170. }
  171. int ret = m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更新操作
  172. if (ret < 0)
  173. {
  174. //MessageBox.Show(PdnResources.GetString("Menu.Successfullymodified.text"));
  175. MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
  176. }
  177. //else
  178. //{
  179. // MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
  180. //}
  181. }
  182. ((SpecialDefinitionDialog)m_parentForm).SpecialListLoad();
  183. this.Close();
  184. }
  185. private void SpecialDialog_FormClosing(object sender, FormClosingEventArgs e)
  186. {
  187. m_sqlHelper.DisConnect();
  188. }
  189. }
  190. }