123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- 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.Special
- {
- public class SpecialDialog : Form
- {
- #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.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text");
- this.label1.Text = PdnResources.GetString("Menu.name.text") + ":";
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.btnSave = new System.Windows.Forms.Button();
- this.txtName = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // btnSave
- //
- this.btnSave.Location = new System.Drawing.Point(128, 76);
- this.btnSave.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
- this.btnSave.Name = "btnSave";
- this.btnSave.Size = new System.Drawing.Size(66, 26);
- this.btnSave.TabIndex = 5;
- this.btnSave.Text = "保存";
- this.btnSave.UseVisualStyleBackColor = true;
- this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
- //
- // txtName
- //
- this.txtName.Location = new System.Drawing.Point(102, 39);
- this.txtName.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
- this.txtName.MaxLength = 15;
- this.txtName.Name = "txtName";
- this.txtName.Size = new System.Drawing.Size(158, 21);
- this.txtName.TabIndex = 4;
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(51, 42);
- this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(41, 12);
- this.label1.TabIndex = 3;
- this.label1.Text = "名称:";
- //
- // SpecialDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(324, 135);
- this.Controls.Add(this.btnSave);
- this.Controls.Add(this.txtName);
- this.Controls.Add(this.label1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
- this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "SpecialDialog";
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "新增专项数据";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpecialDialog_FormClosing);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- #endregion
- private System.Windows.Forms.Button btnSave;
- private System.Windows.Forms.TextBox txtName;
- private System.Windows.Forms.Label label1;
- #endregion
- private bool m_isAdd;
- private SQLiteHelper m_sqlHelper;
- private string m_id;
- private DataTable m_specialList;
- private Form m_parentForm;
- private SpecialItem m_item;
- public SpecialDialog(Form form, bool isAdd, string id, SpecialItem item)
- {
- m_parentForm = form;
- m_id = id;
- m_isAdd = isAdd;
- m_item = item;
- InitializeComponent();
- InitializeLanguageText();
- InitializeData();
- }
- private void InitializeData()
- {
- m_sqlHelper = new SQLiteHelper(); //连接数据库
- m_sqlHelper.Connect();
- if (m_isAdd)
- {
- this.Text = PdnResources.GetString("Menu.Addspecialdata.text");
- }
- else
- {
- this.Text = PdnResources.GetString("Menu.Modifyspecificdata.text");
- if (m_id != null)
- {
- string select_sql = "select * from mic_special_definition where id = '" + m_id +"'"; //查询的SQL语句
- m_specialList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
- txtName.Text = m_specialList.Rows[0]["special_name"].ToString();
- }
- }
- }
- private void btnSave_Click(object sender, EventArgs e)
- {
- string name = txtName.Text.Trim();
- if (string.IsNullOrWhiteSpace(name) || string.IsNullOrEmpty(name))
- {
- MessageBox.Show(PdnResources.GetString("Menu.namecannotbeEmpty.text"));
- return;
- }
- if (m_isAdd)
- {
- string id = System.Guid.NewGuid().ToString("N");
- string insert_sql = "insert into mic_special_definition(id,special_type, special_name, delete_flag) values(?,?,?,0)"; //插入的SQL语句(带参数)
- SQLiteParameter[] para = new SQLiteParameter[3]; //构造并绑定参数
- string[] tag = { "id", "special_type", "special_name" };
- Object[] value = { id, m_item, name };
- for (int i = 0; i < 3; 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_special_definition set special_name = ? where id = '" + m_id + "'"; //SQL语句(带参数)
- SQLiteParameter[] para = new SQLiteParameter[1]; //构造并绑定参数
- string[] tag = { "special_name" };
- Object[] value = { name };
- 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"));
- MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
- }
- //else
- //{
- // MessageBox.Show(PdnResources.GetString("Menu.failtoedit.text"));
- //}
- }
- ((SpecialDefinitionDialog)m_parentForm).SpecialListLoad();
- this.Close();
- }
- private void SpecialDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- m_sqlHelper.DisConnect();
- }
- }
- }
|