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;
using PaintDotNet.GeneralAnalysis.Special;
namespace PaintDotNet.GeneralAnalysis
{
public partial class SpecialDefinitionDialog : 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.Text = PdnResources.GetString("Menu.Generalanalysis.Specificdefinition.Specialdefinitionoflength.text");
this.maxValue.HeaderText = PdnResources.GetString("Menu.Endvalue.text") + "(<)";
this.minValue.HeaderText = PdnResources.GetString("Menu.Startingvalue.text") + "(≥)";
this.description.HeaderText = PdnResources.GetString("Menu.instruction.text");
this.groupBox1.Text = PdnResources.GetString("Menu.Specialdata.text");
this.groupBox2.Text = PdnResources.GetString("Menu.Levelinformation.text");
this.name.HeaderText = PdnResources.GetString("Menu.name.text");
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.lstSpecialList = new System.Windows.Forms.ListBox();
this.btnSpecialDelete = new System.Windows.Forms.Button();
this.btnSpecialUpdate = new System.Windows.Forms.Button();
this.btnSpecialAdd = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.dgvInfoList = new System.Windows.Forms.DataGridView();
this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.description = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.minValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.maxValue = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btnSpecialInfoDelete = new System.Windows.Forms.Button();
this.btnSpecialInfoUpdate = new System.Windows.Forms.Button();
this.btnSpecialInfoAdd = new System.Windows.Forms.Button();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvInfoList)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.groupBox1.Controls.Add(this.lstSpecialList);
this.groupBox1.Controls.Add(this.btnSpecialDelete);
this.groupBox1.Controls.Add(this.btnSpecialUpdate);
this.groupBox1.Controls.Add(this.btnSpecialAdd);
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(253, 359);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "专项数据";
//
// lstSpecialList
//
this.lstSpecialList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lstSpecialList.FormattingEnabled = true;
this.lstSpecialList.ItemHeight = 12;
this.lstSpecialList.Location = new System.Drawing.Point(8, 46);
this.lstSpecialList.Margin = new System.Windows.Forms.Padding(2);
this.lstSpecialList.Name = "lstSpecialList";
this.lstSpecialList.Size = new System.Drawing.Size(236, 304);
this.lstSpecialList.TabIndex = 8;
this.lstSpecialList.SelectedIndexChanged += new System.EventHandler(this.lstSpecialList_SelectedIndexChanged);
//
// btnSpecialDelete
//
this.btnSpecialDelete.Location = new System.Drawing.Point(212, 17);
this.btnSpecialDelete.Margin = new System.Windows.Forms.Padding(2);
this.btnSpecialDelete.Name = "btnSpecialDelete";
this.btnSpecialDelete.Size = new System.Drawing.Size(31, 22);
this.btnSpecialDelete.TabIndex = 3;
this.btnSpecialDelete.UseVisualStyleBackColor = true;
this.btnSpecialDelete.Click += new System.EventHandler(this.btnSpecialDelete_Click);
//
// btnSpecialUpdate
//
this.btnSpecialUpdate.Location = new System.Drawing.Point(174, 17);
this.btnSpecialUpdate.Margin = new System.Windows.Forms.Padding(2);
this.btnSpecialUpdate.Name = "btnSpecialUpdate";
this.btnSpecialUpdate.Size = new System.Drawing.Size(31, 22);
this.btnSpecialUpdate.TabIndex = 2;
this.btnSpecialUpdate.UseVisualStyleBackColor = true;
this.btnSpecialUpdate.Click += new System.EventHandler(this.btnSpecialUpdate_Click);
//
// btnSpecialAdd
//
this.btnSpecialAdd.Location = new System.Drawing.Point(136, 17);
this.btnSpecialAdd.Margin = new System.Windows.Forms.Padding(2);
this.btnSpecialAdd.Name = "btnSpecialAdd";
this.btnSpecialAdd.Size = new System.Drawing.Size(31, 22);
this.btnSpecialAdd.TabIndex = 1;
this.btnSpecialAdd.UseVisualStyleBackColor = true;
this.btnSpecialAdd.Click += new System.EventHandler(this.btnSpecialAdd_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.dgvInfoList);
this.groupBox2.Controls.Add(this.btnSpecialInfoDelete);
this.groupBox2.Controls.Add(this.btnSpecialInfoUpdate);
this.groupBox2.Controls.Add(this.btnSpecialInfoAdd);
this.groupBox2.Location = new System.Drawing.Point(266, 10);
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(459, 359);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "级别信息";
//
// dgvInfoList
//
this.dgvInfoList.AllowUserToAddRows = false;
this.dgvInfoList.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.dgvInfoList.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvInfoList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.id,
this.name,
this.description,
this.minValue,
this.maxValue});
this.dgvInfoList.Location = new System.Drawing.Point(9, 46);
this.dgvInfoList.Margin = new System.Windows.Forms.Padding(2);
this.dgvInfoList.Name = "dgvInfoList";
this.dgvInfoList.RowHeadersVisible = false;
this.dgvInfoList.RowHeadersWidth = 51;
this.dgvInfoList.RowTemplate.Height = 27;
this.dgvInfoList.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvInfoList.Size = new System.Drawing.Size(441, 302);
this.dgvInfoList.TabIndex = 7;
//
// id
//
this.id.HeaderText = "id";
this.id.MinimumWidth = 6;
this.id.Name = "id";
this.id.Visible = false;
//
// name
//
this.name.FillWeight = 129.3591F;
this.name.HeaderText = "name";
this.name.MinimumWidth = 6;
this.name.Name = "name";
this.name.Width = 80;
//
// description
//
this.description.FillWeight = 111.8908F;
this.description.HeaderText = "description";
this.description.MinimumWidth = 6;
this.description.Name = "description";
//
// minValue
//
this.minValue.FillWeight = 77.53182F;
this.minValue.HeaderText = "minValue";
this.minValue.MinimumWidth = 6;
this.minValue.Name = "minValue";
this.minValue.Width = 150;
//
// maxValue
//
this.maxValue.FillWeight = 81.21828F;
this.maxValue.HeaderText = "maxValue";
this.maxValue.MinimumWidth = 6;
this.maxValue.Name = "maxValue";
this.maxValue.Width = 110;
//
// btnSpecialInfoDelete
//
this.btnSpecialInfoDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSpecialInfoDelete.Location = new System.Drawing.Point(418, 17);
this.btnSpecialInfoDelete.Margin = new System.Windows.Forms.Padding(2);
this.btnSpecialInfoDelete.Name = "btnSpecialInfoDelete";
this.btnSpecialInfoDelete.Size = new System.Drawing.Size(31, 22);
this.btnSpecialInfoDelete.TabIndex = 6;
this.btnSpecialInfoDelete.UseVisualStyleBackColor = true;
this.btnSpecialInfoDelete.Click += new System.EventHandler(this.btnSpecialInfoDelete_Click);
//
// btnSpecialInfoUpdate
//
this.btnSpecialInfoUpdate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSpecialInfoUpdate.Location = new System.Drawing.Point(380, 17);
this.btnSpecialInfoUpdate.Margin = new System.Windows.Forms.Padding(2);
this.btnSpecialInfoUpdate.Name = "btnSpecialInfoUpdate";
this.btnSpecialInfoUpdate.Size = new System.Drawing.Size(31, 22);
this.btnSpecialInfoUpdate.TabIndex = 5;
this.btnSpecialInfoUpdate.UseVisualStyleBackColor = true;
this.btnSpecialInfoUpdate.Click += new System.EventHandler(this.btnSpecialInfoUpdate_Click);
//
// btnSpecialInfoAdd
//
this.btnSpecialInfoAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnSpecialInfoAdd.Location = new System.Drawing.Point(341, 17);
this.btnSpecialInfoAdd.Margin = new System.Windows.Forms.Padding(2);
this.btnSpecialInfoAdd.Name = "btnSpecialInfoAdd";
this.btnSpecialInfoAdd.Size = new System.Drawing.Size(31, 22);
this.btnSpecialInfoAdd.TabIndex = 4;
this.btnSpecialInfoAdd.UseVisualStyleBackColor = true;
this.btnSpecialInfoAdd.Click += new System.EventHandler(this.btnSpecialInfoAdd_Click);
//
// SpecialDefinitionDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(734, 384);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Margin = new System.Windows.Forms.Padding(2);
this.MaximizeBox = false;
this.Name = "SpecialDefinitionDialog";
this.Text = "专项定义";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgvInfoList)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button btnSpecialDelete;
private System.Windows.Forms.Button btnSpecialUpdate;
private System.Windows.Forms.Button btnSpecialAdd;
private System.Windows.Forms.DataGridView dgvInfoList;
private System.Windows.Forms.Button btnSpecialInfoDelete;
private System.Windows.Forms.Button btnSpecialInfoUpdate;
private System.Windows.Forms.Button btnSpecialInfoAdd;
private System.Windows.Forms.ListBox lstSpecialList;
private System.Windows.Forms.ToolTip toolTip1;
#endregion
private SpecialItem m_specialItem;
private SQLiteHelper m_sqlHelper;
private int m_selectedIndex;
private DataTable m_specialList;
private DataGridViewTextBoxColumn id;
private DataGridViewTextBoxColumn name;
private DataGridViewTextBoxColumn description;
private DataGridViewTextBoxColumn minValue;
private DataGridViewTextBoxColumn maxValue;
private string m_specialId;
public SpecialDefinitionDialog(SpecialItem item)
{
m_specialItem = item;
InitializeComponent();
InitializeLanguageText();
InitializeButtonBackgroudImage();
InitializeToolTip();
InitializeData();
}
private void InitializeButtonBackgroudImage()
{
this.btnSpecialAdd.FlatStyle = FlatStyle.Flat;
this.btnSpecialAdd.FlatAppearance.BorderSize = 0;
this.btnSpecialAdd.BackgroundImageLayout = ImageLayout.Center;
this.btnSpecialAdd.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListAddIcon.png").Reference;
this.btnSpecialUpdate.FlatStyle = FlatStyle.Flat;
this.btnSpecialUpdate.FlatAppearance.BorderSize = 0;
this.btnSpecialUpdate.BackgroundImageLayout = ImageLayout.Center;
this.btnSpecialUpdate.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListEditIcon.png").Reference;
this.btnSpecialDelete.FlatStyle = FlatStyle.Flat;
this.btnSpecialDelete.FlatAppearance.BorderSize = 0;
this.btnSpecialDelete.BackgroundImageLayout = ImageLayout.Center;
this.btnSpecialDelete.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListDeleteIcon.png").Reference;
this.btnSpecialInfoAdd.FlatStyle = FlatStyle.Flat;
this.btnSpecialInfoAdd.FlatAppearance.BorderSize = 0;
this.btnSpecialInfoAdd.BackgroundImageLayout = ImageLayout.Center;
this.btnSpecialInfoAdd.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListAddIcon.png").Reference;
this.btnSpecialInfoUpdate.FlatStyle = FlatStyle.Flat;
this.btnSpecialInfoUpdate.FlatAppearance.BorderSize = 0;
this.btnSpecialInfoUpdate.BackgroundImageLayout = ImageLayout.Center;
this.btnSpecialInfoUpdate.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListEditIcon.png").Reference;
this.btnSpecialInfoDelete.FlatStyle = FlatStyle.Flat;
this.btnSpecialInfoDelete.FlatAppearance.BorderSize = 0;
this.btnSpecialInfoDelete.BackgroundImageLayout = ImageLayout.Center;
this.btnSpecialInfoDelete.BackgroundImage = PdnResources.GetImageResource("Icons.MenuRulesListDeleteIcon.png").Reference;
}
private void InitializeToolTip()
{
this.toolTip1 = new ToolTip();
this.toolTip1.SetToolTip(this.btnSpecialAdd, PdnResources.GetString("Menu.Addto.text"));
this.toolTip1.SetToolTip(this.btnSpecialUpdate, PdnResources.GetString("Menu.modify.Text"));
this.toolTip1.SetToolTip(this.btnSpecialDelete, PdnResources.GetString("Menu.Edit.Delete.Text"));
this.toolTip1.SetToolTip(this.btnSpecialInfoAdd, PdnResources.GetString("Menu.Addto.text"));
this.toolTip1.SetToolTip(this.btnSpecialInfoUpdate, PdnResources.GetString("Menu.modify.Text"));
this.toolTip1.SetToolTip(this.btnSpecialInfoDelete, PdnResources.GetString("Menu.Edit.Delete.Text"));
this.toolTip1.ShowAlways = true;
}
private void InitializeData()
{
m_sqlHelper = new SQLiteHelper(); //连接数据库
m_sqlHelper.Connect();
if (m_specialItem == SpecialItem.AREA)
{
this.Text = PdnResources.GetString("Menu.Generalanalysis.Specificdefinition.Specificdecontent.text");
}
SpecialListLoad();
}
public void SpecialListLoad()
{
string select_sql = "select * from mic_special_definition where delete_flag = 0 and special_type = ? "; //查询的SQL语句
SQLiteParameter[] para = new SQLiteParameter[1];
para[0] = new SQLiteParameter("special_type", m_specialItem);
m_specialList = m_sqlHelper.ExecuteDataTable(select_sql, para); //执行查询操作,结果存放在dt中
this.lstSpecialList.Items.Clear();
if (m_specialList.Rows.Count > 0)
{
for (int i = 0; i < m_specialList.Rows.Count; ++i)
{
lstSpecialList.Items.Add(m_specialList.Rows[i]["special_name"].ToString());
}
if (m_selectedIndex > m_specialList.Rows.Count - 1)
{
m_selectedIndex = m_specialList.Rows.Count - 1;
}
lstSpecialList.SelectedIndex = m_selectedIndex;
}
}
private void lstSpecialList_SelectedIndexChanged(object sender, EventArgs e)
{
m_selectedIndex = this.lstSpecialList.SelectedIndex;
m_specialId = m_specialList.Rows[m_selectedIndex]["id"].ToString();
UpdateInfoCatalog();
}
public void UpdateInfoCatalog()
{
dgvInfoList.AutoGenerateColumns = false;
dgvInfoList.AllowUserToAddRows = false;
dgvInfoList.ReadOnly = true;
this.dgvInfoList.Rows.Clear();
string select_sql = "select * from mic_special_definition_info where special_id = '" + m_specialId + "'"; //查询的SQL语句
DataTable infoList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
if (infoList.Rows.Count > 0)
{
dgvInfoList.Rows.Add(infoList.Rows.Count);
for (int i = 0; i < infoList.Rows.Count; ++i)
{
dgvInfoList.Rows[i].Cells["id"].Value = infoList.Rows[i]["id"].ToString();
dgvInfoList.Rows[i].Cells["name"].Value = infoList.Rows[i]["name"].ToString();
dgvInfoList.Rows[i].Cells["description"].Value = infoList.Rows[i]["description"].ToString();
dgvInfoList.Rows[i].Cells["minValue"].Value = infoList.Rows[i]["minValue"];
dgvInfoList.Rows[i].Cells["maxValue"].Value = infoList.Rows[i]["maxValue"];
}
}
}
private void btnSpecialAdd_Click(object sender, EventArgs e)
{
SpecialDialog dg = new SpecialDialog(this, true, null, m_specialItem);
dg.ShowDialog();
}
private void btnSpecialUpdate_Click(object sender, EventArgs e)
{
if (m_specialId == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddspecialinformationfirst.Text"));
return;
}
SpecialDialog dg = new SpecialDialog(this, false, m_specialId, m_specialItem);
dg.ShowDialog();
}
private void btnSpecialDelete_Click(object sender, EventArgs e)
{
if (m_specialId == null)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectthepecialdatatodeletefirst.Text"));
return;
}
DialogResult result = MessageBox.Show(PdnResources.GetString("Menu.ousureyouwanttodeletetheselect.Text")+"?", PdnResources.GetString("Menu.Tips.text"), MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
// 删除组织信息
string delete_sql = "delete from mic_special_definition where id = '" + m_specialId + "'";
m_sqlHelper.ExecuteNonQuery(delete_sql, null); //执行删除操作
// 删除定义键
delete_sql = "delete from mic_special_definition_info where special_id = '" + m_specialId + "'";
m_sqlHelper.ExecuteNonQuery(delete_sql, null); //执行删除操作
this.SpecialListLoad();
//MessageBox.Show("删除成功");
}
}
private void btnSpecialInfoAdd_Click(object sender, EventArgs e)
{
SpecialInfoDialog dg = new SpecialInfoDialog(this, m_specialId, true, null);
dg.ShowDialog();
}
private void btnSpecialInfoUpdate_Click(object sender, EventArgs e)
{
if (dgvInfoList.SelectedRows.Count != 1)
{
MessageBox.Show(PdnResources.GetString("Menu.Selectwofdata.text"));
return;
}
string specialInfoId = "";
foreach (DataGridViewRow r in dgvInfoList.SelectedRows)
{
if (!r.IsNewRow)
{
specialInfoId = r.Cells["id"].Value.ToString();
}
}
SpecialInfoDialog dg = new SpecialInfoDialog(this, m_specialId, false, specialInfoId);
dg.ShowDialog();
}
private void btnSpecialInfoDelete_Click(object sender, EventArgs e)
{
if (dgvInfoList.SelectedRows.Count <= 0)
{
MessageBox.Show(PdnResources.GetString("Menu.Pleasesobedeleted.text"));
return;
}
DialogResult result = MessageBox.Show(PdnResources.GetString("Menu.thatyouwanttodeleteheselect.Text")+"?", PdnResources.GetString("Menu.Tips.text"), MessageBoxButtons.OKCancel);
if (result == DialogResult.OK)
{
//执行删除
foreach (DataGridViewRow r in dgvInfoList.SelectedRows)
{
if (!r.IsNewRow)
{
string id = r.Cells["id"].Value.ToString();
string sql = "delete from mic_special_definition_info where id ='" + id + "'";
m_sqlHelper.ExecuteNonQuery(sql, null);
dgvInfoList.Rows.Remove(r);
}
}
//MessageBox.Show(PdnResources.GetString("Menu.successfullydeleted.text")+"!");
}
}
}
}