SavingDialog.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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 partial class SavingDialog : 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.Text = PdnResources.GetString("Menu.File.Save.Text");
  37. this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Sampletype.text") + ":";
  38. this.label1.Text = PdnResources.GetString("Menu.Measuringtime.text") + ":";
  39. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  40. this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  41. this.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  42. this.groupBox2.Text = PdnResources.GetString("Menu.Organizationinformation.text");
  43. this.label5.Text = PdnResources.GetString("Menu.Remark.text") + ":";
  44. this.label6.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Samplingtime.text") + ":";
  45. this.label4.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.filename.text") + ":";
  46. this.label3.Text = PdnResources.GetString("Menu.samplename.text") + ":";
  47. }
  48. /// <summary>
  49. /// Required method for Designer support - do not modify
  50. /// the contents of this method with the code editor.
  51. /// </summary>
  52. private void InitializeComponent()
  53. {
  54. this.groupBox1 = new System.Windows.Forms.GroupBox();
  55. this.btnClose = new System.Windows.Forms.Button();
  56. this.btnSave = new System.Windows.Forms.Button();
  57. this.groupBox2 = new System.Windows.Forms.GroupBox();
  58. this.dtpSamplingTime = new System.Windows.Forms.DateTimePicker();
  59. this.dtpAssayTime = new System.Windows.Forms.DateTimePicker();
  60. this.txtNotes = new System.Windows.Forms.TextBox();
  61. this.txtFileName = new System.Windows.Forms.TextBox();
  62. this.txtName = new System.Windows.Forms.TextBox();
  63. this.txtType = new System.Windows.Forms.TextBox();
  64. this.label5 = new System.Windows.Forms.Label();
  65. this.label6 = new System.Windows.Forms.Label();
  66. this.label4 = new System.Windows.Forms.Label();
  67. this.label3 = new System.Windows.Forms.Label();
  68. this.label2 = new System.Windows.Forms.Label();
  69. this.label1 = new System.Windows.Forms.Label();
  70. this.groupBox1.SuspendLayout();
  71. this.groupBox2.SuspendLayout();
  72. this.SuspendLayout();
  73. //
  74. // groupBox1
  75. //
  76. this.groupBox1.Controls.Add(this.btnClose);
  77. this.groupBox1.Controls.Add(this.btnSave);
  78. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  79. this.groupBox1.Name = "groupBox1";
  80. this.groupBox1.Size = new System.Drawing.Size(445, 71);
  81. this.groupBox1.TabIndex = 0;
  82. this.groupBox1.TabStop = false;
  83. this.groupBox1.Text = "操作";
  84. //
  85. // btnClose
  86. //
  87. this.btnClose.Location = new System.Drawing.Point(248, 24);
  88. this.btnClose.Name = "btnClose";
  89. this.btnClose.Size = new System.Drawing.Size(84, 31);
  90. this.btnClose.TabIndex = 1;
  91. this.btnClose.Text = "关闭";
  92. this.btnClose.UseVisualStyleBackColor = true;
  93. this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
  94. //
  95. // btnSave
  96. //
  97. this.btnSave.Location = new System.Drawing.Point(338, 24);
  98. this.btnSave.Name = "btnSave";
  99. this.btnSave.Size = new System.Drawing.Size(84, 31);
  100. this.btnSave.TabIndex = 0;
  101. this.btnSave.Text = "保存";
  102. this.btnSave.UseVisualStyleBackColor = true;
  103. this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  104. //
  105. // groupBox2
  106. //
  107. this.groupBox2.Controls.Add(this.dtpSamplingTime);
  108. this.groupBox2.Controls.Add(this.dtpAssayTime);
  109. this.groupBox2.Controls.Add(this.txtNotes);
  110. this.groupBox2.Controls.Add(this.txtFileName);
  111. this.groupBox2.Controls.Add(this.txtName);
  112. this.groupBox2.Controls.Add(this.txtType);
  113. this.groupBox2.Controls.Add(this.label5);
  114. this.groupBox2.Controls.Add(this.label6);
  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(12, 89);
  120. this.groupBox2.Name = "groupBox2";
  121. this.groupBox2.Size = new System.Drawing.Size(445, 414);
  122. this.groupBox2.TabIndex = 1;
  123. this.groupBox2.TabStop = false;
  124. this.groupBox2.Text = "组织信息";
  125. //
  126. // dtpSamplingTime
  127. //
  128. this.dtpSamplingTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  129. this.dtpSamplingTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
  130. this.dtpSamplingTime.Location = new System.Drawing.Point(130, 185);
  131. this.dtpSamplingTime.Name = "dtpSamplingTime";
  132. this.dtpSamplingTime.Size = new System.Drawing.Size(290, 21);
  133. this.dtpSamplingTime.TabIndex = 13;
  134. //
  135. // dtpAssayTime
  136. //
  137. this.dtpAssayTime.CustomFormat = "yyyy-MM-dd HH:mm:ss";
  138. this.dtpAssayTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
  139. this.dtpAssayTime.Location = new System.Drawing.Point(130, 37);
  140. this.dtpAssayTime.Name = "dtpAssayTime";
  141. this.dtpAssayTime.Size = new System.Drawing.Size(290, 21);
  142. this.dtpAssayTime.TabIndex = 12;
  143. //
  144. // txtNotes
  145. //
  146. this.txtNotes.Location = new System.Drawing.Point(130, 228);
  147. this.txtNotes.Multiline = true;
  148. this.txtNotes.Name = "txtNotes";
  149. this.txtNotes.Size = new System.Drawing.Size(290, 164);
  150. this.txtNotes.TabIndex = 11;
  151. //
  152. // txtFileName
  153. //
  154. this.txtFileName.Location = new System.Drawing.Point(130, 148);
  155. this.txtFileName.Name = "txtFileName";
  156. this.txtFileName.Size = new System.Drawing.Size(290, 21);
  157. this.txtFileName.TabIndex = 9;
  158. //
  159. // txtName
  160. //
  161. this.txtName.Location = new System.Drawing.Point(130, 111);
  162. this.txtName.Name = "txtName";
  163. this.txtName.Size = new System.Drawing.Size(290, 21);
  164. this.txtName.TabIndex = 8;
  165. //
  166. // txtType
  167. //
  168. this.txtType.Location = new System.Drawing.Point(130, 74);
  169. this.txtType.Name = "txtType";
  170. this.txtType.Size = new System.Drawing.Size(290, 21);
  171. this.txtType.TabIndex = 7;
  172. //
  173. // label5
  174. //
  175. this.label5.AutoSize = true;
  176. this.label5.Location = new System.Drawing.Point(23, 228);
  177. this.label5.Name = "label5";
  178. this.label5.Size = new System.Drawing.Size(41, 12);
  179. this.label5.TabIndex = 5;
  180. this.label5.Text = "备注:";
  181. //
  182. // label6
  183. //
  184. this.label6.AutoSize = true;
  185. this.label6.Location = new System.Drawing.Point(23, 191);
  186. this.label6.Name = "label6";
  187. this.label6.Size = new System.Drawing.Size(65, 12);
  188. this.label6.TabIndex = 4;
  189. this.label6.Text = "取样时间:";
  190. //
  191. // label4
  192. //
  193. this.label4.AutoSize = true;
  194. this.label4.Location = new System.Drawing.Point(23, 154);
  195. this.label4.Name = "label4";
  196. this.label4.Size = new System.Drawing.Size(65, 12);
  197. this.label4.TabIndex = 3;
  198. this.label4.Text = "文件名称:";
  199. //
  200. // label3
  201. //
  202. this.label3.AutoSize = true;
  203. this.label3.Location = new System.Drawing.Point(23, 117);
  204. this.label3.Name = "label3";
  205. this.label3.Size = new System.Drawing.Size(65, 12);
  206. this.label3.TabIndex = 2;
  207. this.label3.Text = "样品名称:";
  208. //
  209. // label2
  210. //
  211. this.label2.AutoSize = true;
  212. this.label2.Location = new System.Drawing.Point(23, 80);
  213. this.label2.Name = "label2";
  214. this.label2.Size = new System.Drawing.Size(65, 12);
  215. this.label2.TabIndex = 1;
  216. this.label2.Text = "样品类型:";
  217. //
  218. // label1
  219. //
  220. this.label1.AutoSize = true;
  221. this.label1.Location = new System.Drawing.Point(23, 43);
  222. this.label1.Name = "label1";
  223. this.label1.Size = new System.Drawing.Size(65, 12);
  224. this.label1.TabIndex = 0;
  225. this.label1.Text = "测定时间:";
  226. //
  227. // SavingDialog
  228. //
  229. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  230. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  231. this.ClientSize = new System.Drawing.Size(472, 517);
  232. this.Controls.Add(this.groupBox2);
  233. this.Controls.Add(this.groupBox1);
  234. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  235. this.MaximizeBox = false;
  236. this.Name = "SavingDialog";
  237. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  238. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SavingDialog_FormClosing);
  239. this.Controls.SetChildIndex(this.groupBox1, 0);
  240. this.Controls.SetChildIndex(this.groupBox2, 0);
  241. this.groupBox1.ResumeLayout(false);
  242. this.groupBox2.ResumeLayout(false);
  243. this.groupBox2.PerformLayout();
  244. this.ResumeLayout(false);
  245. }
  246. #endregion
  247. private System.Windows.Forms.GroupBox groupBox1;
  248. private System.Windows.Forms.GroupBox groupBox2;
  249. private System.Windows.Forms.TextBox txtNotes;
  250. private System.Windows.Forms.TextBox txtFileName;
  251. private System.Windows.Forms.TextBox txtName;
  252. private System.Windows.Forms.TextBox txtType;
  253. private System.Windows.Forms.Label label5;
  254. private System.Windows.Forms.Label label6;
  255. private System.Windows.Forms.Label label4;
  256. private System.Windows.Forms.Label label3;
  257. private System.Windows.Forms.Label label2;
  258. private System.Windows.Forms.Label label1;
  259. private System.Windows.Forms.Button btnSave;
  260. private System.Windows.Forms.Button btnClose;
  261. private System.Windows.Forms.DateTimePicker dtpSamplingTime;
  262. private System.Windows.Forms.DateTimePicker dtpAssayTime;
  263. #endregion
  264. private SQLiteHelper m_sqlHelper;
  265. private string m_tissuesId;
  266. private string m_tissuesName;
  267. private DataTable m_assayList;
  268. public SavingDialog(string tissuesId, DataTable data)
  269. {
  270. m_tissuesId = tissuesId;
  271. m_assayList = data;
  272. InitializeData();
  273. InitializeComponent();
  274. InitializeLanguageText();
  275. }
  276. private void InitializeData()
  277. {
  278. m_sqlHelper = new SQLiteHelper(); //连接数据库
  279. m_sqlHelper.Connect();
  280. // 组织信息
  281. string select_sql1 = "select * from mic_tissues where delete_flag = 0 and id = '" + m_tissuesId + "'"; //查询的SQL语句
  282. DataTable tissuesList = m_sqlHelper.ExecuteDataTable(select_sql1, null); //执行查询操作,结果存放在dt中
  283. m_tissuesName = tissuesList.Rows[0]["tissue_name"].ToString();
  284. }
  285. private void btnClose_Click(object sender, EventArgs e)
  286. {
  287. this.Close();
  288. }
  289. private void btnSave_Click(object sender, EventArgs e)
  290. {
  291. try
  292. {
  293. DateTime assayTime = dtpAssayTime.Value;
  294. string samplingType = txtType.Text.Trim();
  295. string samplingName = txtName.Text.Trim();
  296. string fileName = txtFileName.Text.Trim();
  297. DateTime samplingTime = dtpSamplingTime.Value;
  298. string notes = txtNotes.Text.Trim();
  299. if(string.IsNullOrEmpty(samplingType) || string.IsNullOrWhiteSpace(samplingType))
  300. {
  301. MessageBox.Show(PdnResources.GetString("Menu.Pleasepletype.text"));
  302. return;
  303. }
  304. if (string.IsNullOrEmpty(samplingName) || string.IsNullOrWhiteSpace(samplingName))
  305. {
  306. MessageBox.Show(PdnResources.GetString("Menu.Pleasefillintlename.text"));
  307. return;
  308. }
  309. if (string.IsNullOrEmpty(fileName) || string.IsNullOrWhiteSpace(fileName))
  310. {
  311. MessageBox.Show(PdnResources.GetString("Menu.Pleasefillname.text"));
  312. return;
  313. }
  314. // TODO 需要保存成文件?
  315. string id = System.Guid.NewGuid().ToString("N");
  316. string insert_sql = "insert into mic_assay_history(id, tissue_id, tissue_name, assay_time, sampling_type, sampling_name, file_name, sampling_time, notes, delete_flag) values(?,?,?,?,?,?,?,?,?,?)"; //插入的SQL语句(带参数)
  317. SQLiteParameter[] para = new SQLiteParameter[10]; //构造并绑定参数
  318. string[] tag = {"id", "tissue_id", "tissue_name", "assay_time", "sampling_type", "sampling_name", "file_name", "sampling_time", "notes", "delete_flag" };
  319. Object[] value = { id, m_tissuesId, m_tissuesName, assayTime, samplingType, samplingName, fileName, samplingTime, notes, 0 };
  320. for (int i = 0; i < 10; i++)
  321. {
  322. para[i] = new SQLiteParameter(tag[i], value[i]);
  323. }
  324. int ret = m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  325. if (ret > 0)
  326. {
  327. for(int i=0;i< m_assayList.Rows.Count; ++i)
  328. {
  329. insert_sql = "insert into mic_assay_history_info (history_id, name, hot_key, color, count, ratio) values(?,?,?,?,?,?)"; //插入的SQL语句(带参数)
  330. para = new SQLiteParameter[6]; //构造并绑定参数
  331. string[] tag2 = { "history_id", "name", "hot_key", "color", "count", "ratio"};
  332. Object[] value2 = { id, m_assayList.Rows[i]["name"], m_assayList.Rows[i]["hot_key"], m_assayList.Rows[i]["color"], m_assayList.Rows[i]["count"], m_assayList.Rows[i]["ratio"] };
  333. for (int t = 0; t < 6; t++)
  334. {
  335. para[t] = new SQLiteParameter(tag2[t], value2[t]);
  336. }
  337. m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  338. }
  339. }
  340. MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
  341. this.Close();
  342. }catch(Exception ex)
  343. {
  344. MessageBox.Show(ex.Message);
  345. }
  346. }
  347. private void SavingDialog_FormClosing(object sender, FormClosingEventArgs e)
  348. {
  349. m_sqlHelper.DisConnect();
  350. }
  351. }
  352. }