TissuesDialog.cs 7.8 KB

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