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 partial class SpecialInfoDialog : Form { #region /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. 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.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text"); this.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text"); this.groupBox2.Text = PdnResources.GetString("Menu.Levelinformation.text"); this.label4.Text = PdnResources.GetString("Menu.Endvalue.text") + ":"; this.label3.Text = PdnResources.GetString("Menu.Startingvalue.text") + ":"; this.label2.Text = PdnResources.GetString("Menu.instruction.text") + ":"; } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.groupBox1 = new System.Windows.Forms.GroupBox(); this.btnClose = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.txtMaxValue = new System.Windows.Forms.TextBox(); this.txtMinValue = new System.Windows.Forms.TextBox(); this.txtDescription = new System.Windows.Forms.TextBox(); this.txtName = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.btnClose); this.groupBox1.Controls.Add(this.btnSave); this.groupBox1.Location = new System.Drawing.Point(9, 10); this.groupBox1.Margin = new System.Windows.Forms.Padding(2); this.groupBox1.Name = "groupBox1"; this.groupBox1.Padding = new System.Windows.Forms.Padding(2); this.groupBox1.Size = new System.Drawing.Size(324, 66); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // btnClose // this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnClose.Location = new System.Drawing.Point(238, 22); this.btnClose.Margin = new System.Windows.Forms.Padding(2); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(61, 29); this.btnClose.TabIndex = 1; this.btnClose.Text = "关闭"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // btnSave // this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnSave.Location = new System.Drawing.Point(164, 22); this.btnSave.Margin = new System.Windows.Forms.Padding(2); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(61, 29); this.btnSave.TabIndex = 0; this.btnSave.Text = "保存"; this.btnSave.UseVisualStyleBackColor = true; this.btnSave.Click += new System.EventHandler(this.btnSave_Click); // // groupBox2 // this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.txtMaxValue); this.groupBox2.Controls.Add(this.txtMinValue); this.groupBox2.Controls.Add(this.txtDescription); this.groupBox2.Controls.Add(this.txtName); this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Location = new System.Drawing.Point(9, 80); this.groupBox2.Margin = new System.Windows.Forms.Padding(2); this.groupBox2.Name = "groupBox2"; this.groupBox2.Padding = new System.Windows.Forms.Padding(2); this.groupBox2.Size = new System.Drawing.Size(324, 221); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "级别信息"; // // txtMaxValue // this.txtMaxValue.Location = new System.Drawing.Point(89, 163); this.txtMaxValue.Margin = new System.Windows.Forms.Padding(2); this.txtMaxValue.Name = "txtMaxValue"; this.txtMaxValue.Size = new System.Drawing.Size(206, 21); this.txtMaxValue.TabIndex = 7; this.txtMaxValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtMaxValue_KeyPress); // // txtMinValue // this.txtMinValue.Location = new System.Drawing.Point(89, 122); this.txtMinValue.Margin = new System.Windows.Forms.Padding(2); this.txtMinValue.Name = "txtMinValue"; this.txtMinValue.Size = new System.Drawing.Size(206, 21); this.txtMinValue.TabIndex = 6; this.txtMinValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtMinValue_KeyPress); // // txtDescription // this.txtDescription.Location = new System.Drawing.Point(89, 80); this.txtDescription.Margin = new System.Windows.Forms.Padding(2); this.txtDescription.Name = "txtDescription"; this.txtDescription.Size = new System.Drawing.Size(206, 21); this.txtDescription.TabIndex = 5; // // txtName // this.txtName.Location = new System.Drawing.Point(89, 38); this.txtName.Margin = new System.Windows.Forms.Padding(2); this.txtName.MaxLength = 10; this.txtName.Name = "txtName"; this.txtName.Size = new System.Drawing.Size(206, 21); this.txtName.TabIndex = 4; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(23, 169); this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(53, 12); this.label4.TabIndex = 3; this.label4.Text = "终止值:"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(23, 127); this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(53, 12); this.label3.TabIndex = 2; this.label3.Text = "起始值:"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(23, 86); this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(41, 12); this.label2.TabIndex = 1; this.label2.Text = "说明:"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(23, 44); 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 = 0; this.label1.Text = "名称:"; // // SpecialInfoDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(341, 310); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Margin = new System.Windows.Forms.Padding(2); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "SpecialInfoDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "新增级别数据"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SpecialInfoDialog_FormClosing); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btnClose; private System.Windows.Forms.Button btnSave; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtMaxValue; private System.Windows.Forms.TextBox txtMinValue; private System.Windows.Forms.TextBox txtDescription; private System.Windows.Forms.TextBox txtName; #endregion private bool m_isAdd; private SQLiteHelper m_sqlHelper; private string m_id; private DataTable m_specialList; private Form m_parentForm; private string m_specialId; public SpecialInfoDialog(Form form, string specialId, bool isAdd, string id) { m_parentForm = form; m_id = id; m_isAdd = isAdd; m_specialId = specialId; InitializeComponent(); InitializeLanguageText(); InitializeData(); } private void InitializeData() { m_sqlHelper = new SQLiteHelper(); //连接数据库 m_sqlHelper.Connect(); if (m_isAdd) { this.Text = PdnResources.GetString("Menu.Newleveldata.text"); } else { this.Text = PdnResources.GetString("Menu.Modifyleveldata.text"); if (m_id != null) { string select_sql = "select * from mic_special_definition_info where id = '" + m_id + "'"; //查询的SQL语句 m_specialList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中 txtName.Text = m_specialList.Rows[0]["name"].ToString(); txtDescription.Text = m_specialList.Rows[0]["description"].ToString(); txtMinValue.Text = m_specialList.Rows[0]["minValue"].ToString(); txtMaxValue.Text = m_specialList.Rows[0]["maxValue"].ToString(); } } } private void SpecialInfoDialog_FormClosing(object sender, FormClosingEventArgs e) { m_sqlHelper.DisConnect(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } 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.Pleasefillinthename.Text")); return; } string description = txtDescription.Text.Trim(); if (string.IsNullOrWhiteSpace(txtMinValue.Text.Trim()) || string.IsNullOrEmpty(txtMinValue.Text.Trim())) { MessageBox.Show(PdnResources.GetString("Menu.Pleasefillinthestartingvalue.Text")); return; } if (string.IsNullOrWhiteSpace(txtMaxValue.Text.Trim()) || string.IsNullOrEmpty(txtMaxValue.Text.Trim())) { MessageBox.Show(PdnResources.GetString("Menu.Pleasefillintheterminationvalue.Text")); return; } decimal minValue = 0; decimal maxValue = 0; try { minValue = decimal.Parse(txtMinValue.Text.Trim()); maxValue = decimal.Parse(txtMaxValue.Text.Trim()); if (minValue >= maxValue) { MessageBox.Show(PdnResources.GetString("Menu.ationvaluemusbegreaterthanthestartingvalue.Text")); return; } } catch(Exception) { MessageBox.Show(PdnResources.GetString("Menu.estartingorendingvaluesaretoolar.Text")); return; } if (m_isAdd) { string select_sql = "select * from mic_special_definition_info where ((minValue <= " + minValue + " and maxValue > " + minValue + ") or (minValue <= " + maxValue + " and maxValue > " + maxValue + ")) and special_id ='"+ m_specialId +"'"; //查询的SQL语句 DataTable list = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中 if (list.Rows.Count > 0) { MessageBox.Show(PdnResources.GetString("Menu.hestartandendvaluescannotrecor.Text")); return; } string id = System.Guid.NewGuid().ToString("N"); string insert_sql = "insert into mic_special_definition_info(id, special_id, name, description, minValue, maxValue) values(?,?,?,?,?,?)"; //插入的SQL语句(带参数) SQLiteParameter[] para = new SQLiteParameter[6]; //构造并绑定参数 string[] tag = { "id", "special_id", "name", "description", "minValue", "maxValue" }; Object[] value = { id, m_specialId, name, description, minValue, maxValue }; for (int i = 0; i < 6; i++) { para[i] = new SQLiteParameter(tag[i], value[i]); } m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作 //MessageBox.Show(PdnResources.GetString("Menu.Addsuccessfully.text")); } else { string select_sql = "select * from mic_special_definition_info where ((minValue <= " + minValue + " and maxValue > " + minValue + ") or (minValue <= " + maxValue + " and maxValue > " + maxValue + ")) and id <> '" + m_id + "' and special_id ='" + m_specialId + "'"; //查询的SQL语句 DataTable list = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中 if (list.Rows.Count > 0) { MessageBox.Show(PdnResources.GetString("Menu.hestartandendvaluescannotrecor.Text")); return; } string update_sql = "update mic_special_definition_info set name = ?, description= ?, minValue = ?, maxValue = ? where id = '" + m_id + "'"; //SQL语句(带参数) SQLiteParameter[] para = new SQLiteParameter[4]; //构造并绑定参数 string[] tag = { "name", "description", "minValue", "maxValue" }; Object[] value = { name, description, minValue, maxValue }; for (int i = 0; i < 4; 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).UpdateInfoCatalog(); this.Close(); } private void txtMinValue_KeyPress(object sender, KeyPressEventArgs e) { ChkKeyPress(sender, e); } private void txtMaxValue_KeyPress(object sender, KeyPressEventArgs e) { ChkKeyPress(sender, e); } /// /// 只能是数值 /// /// /// private void ChkKeyPress(object sender, KeyPressEventArgs e) { string value = ((TextBox)sender).Text; //判断按键是不是要输入的类型。 if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46) e.Handled = true; //小数点的处理。 if ((int)e.KeyChar == 46) //小数点 { if (value.Length <= 0) e.Handled = true; //小数点不能在第一位 else { float f; float oldf; bool b1 = false, b2 = false; b1 = float.TryParse(value, out oldf); b2 = float.TryParse(value + e.KeyChar.ToString(), out f); if (b2 == false) { if (b1 == true) e.Handled = true; else e.Handled = false; } } } } } }