123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PaintDotNet.Base.CommTool;
- namespace PaintDotNet.GeneralAnalysis.Countometer
- {
- public class TissuesDialog : PdnBaseForm
- {
- #region
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
- private void InitializeLanguageText()
- {
- this.label1.Text = PdnResources.GetString("Menu.name.text") + ":";
- this.btnDo.Text = PdnResources.GetString("Menu.Addto.text");
- this.Text = PdnResources.GetString("Menu.organization.text");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.label1 = new System.Windows.Forms.Label();
- this.txtTissuesName = new System.Windows.Forms.TextBox();
- this.btnDo = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(62, 39);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(41, 12);
- this.label1.TabIndex = 0;
- this.label1.Text = "名称:";
- //
- // txtTissuesName
- //
- this.txtTissuesName.Location = new System.Drawing.Point(130, 36);
- this.txtTissuesName.Name = "txtTissuesName";
- this.txtTissuesName.Size = new System.Drawing.Size(209, 21);
- this.txtTissuesName.TabIndex = 1;
- //
- // btnDo
- //
- this.btnDo.Location = new System.Drawing.Point(165, 82);
- this.btnDo.Name = "btnDo";
- this.btnDo.Size = new System.Drawing.Size(88, 33);
- this.btnDo.TabIndex = 2;
- this.btnDo.Text = "添加";
- this.btnDo.UseVisualStyleBackColor = true;
- this.btnDo.Click += new System.EventHandler(this.btnDo_Click);
- //
- // TissuesDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(432, 127);
- this.Controls.Add(this.btnDo);
- this.Controls.Add(this.txtTissuesName);
- this.Controls.Add(this.label1);
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "TissuesDialog";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "组织";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TissuesDialog_FormClosing);
- this.Controls.SetChildIndex(this.label1, 0);
- this.Controls.SetChildIndex(this.txtTissuesName, 0);
- this.Controls.SetChildIndex(this.btnDo, 0);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox txtTissuesName;
- private System.Windows.Forms.Button btnDo;
- #endregion
- private bool m_isAdd;
- private SQLiteHelper m_sqlHelper;
- private string m_tissuesId;
- private DataTable m_tissuesList;
- private Form m_parentForm;
- public TissuesDialog(Form form ,bool isAdd, string id)
- {
- m_parentForm = form;
- m_tissuesId = id;
- m_isAdd = isAdd;
- InitializeComponent();
- InitializeLanguageText();
- m_sqlHelper = new SQLiteHelper(); //连接数据库
- m_sqlHelper.Connect();
- if (id != null)
- {
- // 组织信息
- string select_sql1 = "select * from mic_tissues where delete_flag = 0 and id = '" + m_tissuesId + "'"; //查询的SQL语句
- m_tissuesList = m_sqlHelper.ExecuteDataTable(select_sql1, null); //执行查询操作,结果存放在dt中
- txtTissuesName.Text = m_tissuesList.Rows[0]["tissue_name"].ToString();
- }
- if (m_isAdd)
- {
- btnDo.Text = PdnResources.GetString("Menu.Addto.text");
- }
- else
- {
- btnDo.Text = PdnResources.GetString("Menu.modify.Text");
- }
- }
- private void btnDo_Click(object sender, EventArgs e)
- {
- string tissuesName = txtTissuesName.Text.Trim();
- if (string.IsNullOrWhiteSpace(tissuesName) || string.IsNullOrEmpty(tissuesName))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Organiotbeempty.text"));
- return;
- }
- if (m_isAdd)
- {
- // 保存组织名称
- string tissueId = System.Guid.NewGuid().ToString("N");
- string insert_sql = "insert into mic_tissues(id,tissue_name, delete_flag) values(?,?,0)"; //插入的SQL语句(带参数)
- SQLiteParameter[] para = new SQLiteParameter[2]; //构造并绑定参数
- string[] tag = { "id", "tissue_name" };
- Object[] value = { tissueId, tissuesName };
- for (int i = 0; i < 2; i++)
- {
- para[i] = new SQLiteParameter(tag[i], value[i]);
- }
- m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
- //MessageBox.Show(PdnResources.GetString("Menu.Addsuccessfully.text"));
- }
- else
- {
- string update_sql = "update mic_tissues set tissue_name = ? where id = '" + m_tissuesId + "'"; //SQL语句(带参数)
- SQLiteParameter[] para = new SQLiteParameter[1]; //构造并绑定参数
- string[] tag = { "tissue_name"};
- Object[] value = { tissuesName};
- for (int i = 0; i < 1; i++)
- {
- para[i] = new SQLiteParameter(tag[i], value[i]);
- }
- int ret = m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更新操作
- //if(ret >= 0)
- //{
-
- // MessageBox.Show(PdnResources.GetString("Menu.Successfullymodified.text"));
- //}
- //else
- //{
- // MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
- //}
- if (ret < 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
- }
- }
- ((GeneralCountometerDialog)m_parentForm).TissuesListLoad();
- this.Close();
- }
- private void TissuesDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- m_sqlHelper.DisConnect();
- }
- }
- }
|