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; using System.Threading.Tasks; using System.Windows.Forms; using PaintDotNet.Base.CommTool; using PaintDotNet.Data.Param; namespace PaintDotNet.GeneralAnalysis.Countometer { public class HotKeySetingDialog : PdnBaseForm { #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.organizationname.text") + ":"; this.hotKey.HeaderText = PdnResources.GetString("Menu.icon.text"); this.name.HeaderText = PdnResources.GetString("Menu.name.text"); this.direction.HeaderText = PdnResources.GetString("Menu.Generalanalysis.Integrator.action.text"); this.isCount.HeaderText = PdnResources.GetString("Menu.Generalanalysis.Integrator.Whetherstatistics.text"); this.isDel.HeaderText = PdnResources.GetString("Menu.operation.text"); this.isDel.Text = PdnResources.GetString("Menu.Edit.Delete.Text"); this.Text = PdnResources.GetString("Menu.Keyboarddefinition.text"); this.groupBox1.Text = PdnResources.GetString("Menu.operation.text"); this.btnSaveAs.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Saveas.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.Keyboarddefinition.text"); this.btnAdd.Text = PdnResources.GetString("Menu.Addto.text"); this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.definequantity.text") + ":"; this.direction.Items.AddRange(new object[] { "", PdnResources.GetString("Menu.Weightmeasurement.Text"), PdnResources.GetString("Menu.skip.Text")}); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.btnSaveAs = new System.Windows.Forms.Button(); this.btnClose = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.dgvKeyList = new System.Windows.Forms.DataGridView(); this.btnAdd = new System.Windows.Forms.Button(); this.txtAddNum = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.txtTissuesName = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.isDel = new System.Windows.Forms.DataGridViewLinkColumn(); this.isCount = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.direction = new System.Windows.Forms.DataGridViewComboBoxColumn(); this.name = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.hotKey = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.id = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgvKeyList)).BeginInit(); 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.btnSaveAs); this.groupBox1.Controls.Add(this.btnClose); this.groupBox1.Controls.Add(this.btnSave); this.groupBox1.Location = new System.Drawing.Point(12, 12); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(608, 71); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "操作"; // // btnSaveAs // this.btnSaveAs.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnSaveAs.Location = new System.Drawing.Point(292, 24); this.btnSaveAs.Name = "btnSaveAs"; this.btnSaveAs.Size = new System.Drawing.Size(84, 31); this.btnSaveAs.TabIndex = 2; this.btnSaveAs.Text = "另存"; this.btnSaveAs.UseVisualStyleBackColor = true; this.btnSaveAs.Click += new System.EventHandler(this.btnSaveAs_Click); // // 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(504, 24); this.btnClose.Name = "btnClose"; this.btnClose.Size = new System.Drawing.Size(84, 31); 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(398, 24); this.btnSave.Name = "btnSave"; this.btnSave.Size = new System.Drawing.Size(84, 31); 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.dgvKeyList); this.groupBox2.Controls.Add(this.btnAdd); this.groupBox2.Controls.Add(this.txtAddNum); this.groupBox2.Controls.Add(this.label2); this.groupBox2.Controls.Add(this.txtTissuesName); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Location = new System.Drawing.Point(12, 89); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(608, 521); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "键盘定义"; // // dgvKeyList // this.dgvKeyList.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.dgvKeyList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dgvKeyList.ColumnHeadersHeight = 20; this.dgvKeyList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.id, this.hotKey, this.name, this.direction, this.isCount, this.isDel}); this.dgvKeyList.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter; this.dgvKeyList.Location = new System.Drawing.Point(18, 79); this.dgvKeyList.Name = "dgvKeyList"; this.dgvKeyList.RowHeadersVisible = false; this.dgvKeyList.RowHeadersWidth = 51; this.dgvKeyList.RowTemplate.Height = 20; this.dgvKeyList.Size = new System.Drawing.Size(570, 423); this.dgvKeyList.TabIndex = 5; this.dgvKeyList.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvKeyList_CellClick); this.dgvKeyList.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvKeyList_CellContentClick); this.dgvKeyList.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvKeyList_CellValueChanged); this.dgvKeyList.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dgvKeyList_KeyDown); // // btnAdd // this.btnAdd.Location = new System.Drawing.Point(442, 24); this.btnAdd.Name = "btnAdd"; this.btnAdd.Size = new System.Drawing.Size(84, 33); this.btnAdd.TabIndex = 4; this.btnAdd.Text = "添加"; this.btnAdd.UseVisualStyleBackColor = true; this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click); // // txtAddNum // this.txtAddNum.Location = new System.Drawing.Point(347, 29); this.txtAddNum.Name = "txtAddNum"; this.txtAddNum.Size = new System.Drawing.Size(77, 21); this.txtAddNum.TabIndex = 3; this.txtAddNum.TextChanged += new System.EventHandler(this.txtAddNum_TextChanged); this.txtAddNum.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtAddNum_KeyPress); // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(255, 35); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(65, 12); this.label2.TabIndex = 2; this.label2.Text = "定义数量:"; // // txtTissuesName // this.txtTissuesName.Location = new System.Drawing.Point(94, 29); this.txtTissuesName.Name = "txtTissuesName"; this.txtTissuesName.Size = new System.Drawing.Size(145, 21); this.txtTissuesName.TabIndex = 1; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(15, 35); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(65, 12); this.label1.TabIndex = 0; this.label1.Text = "组织名称:"; // // isDel // dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; this.isDel.DefaultCellStyle = dataGridViewCellStyle4; this.isDel.MinimumWidth = 6; this.isDel.Name = "isDel"; this.isDel.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.isDel.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.isDel.UseColumnTextForLinkValue = true; // // isCount // this.isCount.MinimumWidth = 6; this.isCount.Name = "isCount"; this.isCount.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.isCount.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; // // direction // this.direction.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.direction.DefaultCellStyle = dataGridViewCellStyle3; this.direction.MinimumWidth = 6; this.direction.Name = "direction"; this.direction.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.direction.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; // // name // this.name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.name.MinimumWidth = 6; this.name.Name = "name"; // // hotKey // this.hotKey.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White; this.hotKey.DefaultCellStyle = dataGridViewCellStyle2; this.hotKey.MinimumWidth = 6; this.hotKey.Name = "hotKey"; this.hotKey.ReadOnly = true; this.hotKey.Resizable = System.Windows.Forms.DataGridViewTriState.True; // // id // this.id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; this.id.DefaultCellStyle = dataGridViewCellStyle1; this.id.HeaderText = "id"; this.id.MinimumWidth = 6; this.id.Name = "id"; this.id.Visible = false; // // HotKeySetingDialog // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(632, 622); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Name = "HotKeySetingDialog"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "键盘定义"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.HotKeySetingDialog_FormClosing); this.Controls.SetChildIndex(this.groupBox1, 0); this.Controls.SetChildIndex(this.groupBox2, 0); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgvKeyList)).EndInit(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btnSaveAs; private System.Windows.Forms.Button btnClose; private System.Windows.Forms.Button btnSave; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.DataGridView dgvKeyList; private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.TextBox txtAddNum; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox txtTissuesName; private System.Windows.Forms.Label label1; #endregion /// /// 网格调色板 /// PaintDotNet.ColorsForm colorsFormGrid; /// /// 矩形调色板 /// PaintDotNet.ColorsForm colorsFormRect; /// /// 圆形调色板 /// PaintDotNet.ColorsForm colorsFormCircular; private SQLiteHelper m_sqlHelper; private string m_tissuesId; private DataTable m_hotKeyList; private DataTable m_tissuesList; private int m_rowIndex = -1; private int m_columnIndex = -1; private DataGridViewTextBoxColumn id; private DataGridViewTextBoxColumn hotKey; private DataGridViewTextBoxColumn name; private DataGridViewComboBoxColumn direction; private DataGridViewCheckBoxColumn isCount; private DataGridViewLinkColumn isDel; private Form m_parentForm; public HotKeySetingDialog(Form form, string id) { m_parentForm = form; m_tissuesId = id; InitializeComponent(); InitializeLanguageText(); InitializeData(); this.colorsFormGrid = new ColorsForm(); this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen; this.colorsFormGrid.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); this.colorsFormRect = new ColorsForm(); this.colorsFormRect.StartPosition = FormStartPosition.CenterScreen; this.colorsFormRect.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); this.colorsFormCircular = new ColorsForm(); this.colorsFormCircular.StartPosition = FormStartPosition.CenterScreen; this.colorsFormCircular.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged); } private void InitializeData() { dgvKeyList.DefaultCellStyle.SelectionBackColor = dgvKeyList.DefaultCellStyle.BackColor; dgvKeyList.DefaultCellStyle.SelectionForeColor = dgvKeyList.DefaultCellStyle.ForeColor; dgvKeyList.AllowUserToAddRows = false; dgvKeyList.AutoGenerateColumns = false; m_sqlHelper = new SQLiteHelper(); //连接数据库 m_sqlHelper.Connect(); // 组织信息 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(); // 按键设置列表 string select_sql = "select * from mic_tissues_key where delete_flag = 0 and tissue_id = '" + m_tissuesId + "'"; //查询的SQL语句 m_hotKeyList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中 DrawDgvKeyList(); } private void DrawDgvKeyList() { this.dgvKeyList.Rows.Clear(); if(m_hotKeyList.Rows.Count > 0) { dgvKeyList.Rows.Add(m_hotKeyList.Rows.Count); for (int i = 0; i < m_hotKeyList.Rows.Count; ++i) { dgvKeyList.Rows[i].Cells["id"].Value = m_hotKeyList.Rows[i]["id"].ToString(); Color bgColor = ColorTranslator.FromHtml(m_hotKeyList.Rows[i]["color"].ToString()); dgvKeyList.Rows[i].Cells["hotKey"].Value = m_hotKeyList.Rows[i]["hot_key"].ToString(); dgvKeyList.Rows[i].Cells["hotKey"].Style.BackColor = bgColor; dgvKeyList.Rows[i].Cells["hotKey"].Style.ForeColor = Color.White; dgvKeyList.Rows[i].Cells["hotKey"].Style.SelectionBackColor = bgColor; dgvKeyList.Rows[i].Cells["hotKey"].Style.SelectionForeColor = Color.White; dgvKeyList.Rows[i].Cells["name"].Value = m_hotKeyList.Rows[i]["name"].ToString(); dgvKeyList.Rows[i].Cells["direction"].Value = m_hotKeyList.Rows[i]["direction"].ToString(); if (m_hotKeyList.Rows[i]["is_count"].ToString().Equals("1")) { dgvKeyList.Rows[i].Cells["isCount"].Value = true; } else { dgvKeyList.Rows[i].Cells["isCount"].Value = false; } } } } /// /// 调色板回调函数 /// /// /// private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce) { } private void ShowColorsForm(int rowIndex) { Color color = Color.White; if (rowIndex < m_hotKeyList.Rows.Count) { for (int i = 0; i < m_hotKeyList.Rows.Count; ++i) { if (i == rowIndex) { string c = m_hotKeyList.Rows[i]["color"].ToString(); if (!string.IsNullOrEmpty(c)) { color = ColorTranslator.FromHtml(c); } } } } this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(color); //this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged)); this.colorsFormGrid.ShowDialog(); } /// /// 网格Panel的调色板颜色改变 /// /// /// private void gridColorChanged(object sender, EventArgs e) { Color color = this.colorsFormGrid.UserPrimaryColor.ToColor(); m_hotKeyList.Rows[m_rowIndex]["color"] = ColorTranslator.ToHtml(color); this.colorsFormGrid.Close(); dgvKeyList.Rows[m_rowIndex].Cells[1].Style.BackColor = color; dgvKeyList.Rows[m_rowIndex].Cells[1].Style.ForeColor = Color.White; dgvKeyList.Rows[m_rowIndex].Cells[1].Style.SelectionBackColor = color; dgvKeyList.Rows[m_rowIndex].Cells[1].Style.SelectionForeColor = Color.White; } private void txtAddNum_KeyPress(object sender, KeyPressEventArgs e) { TextBox textBox = (TextBox)sender; if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8) e.Handled = true; } private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtAddNum.Text.Trim())) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddquantityfirst.text")); return; } //获取表行数 int sum = dgvKeyList.Rows.Count; string maxName = PdnResources.GetString("Menu.organization.text"); int num = int.Parse(txtAddNum.Text.Trim()); if (num > 0) { dgvKeyList.Rows.Add(num); } for (int i = 0; i < num; ++i) { m_hotKeyList.Rows.Add(0, m_tissuesId, "", "", "White", 0, ""); } for (int i = 0; i < num; ++i) { Thread.Sleep(50); Color colorRandom = new Color(); colorRandom = GetRandomColor(); dgvKeyList.Rows[sum+i].Cells[1].Style.BackColor = colorRandom; dgvKeyList.Rows[sum + i].Cells[1].Style.SelectionBackColor = colorRandom; dgvKeyList.Rows[sum + i].Cells[1].Style.ForeColor = Color.White; dgvKeyList.Rows[sum + i].Cells[1].Style.SelectionForeColor = Color.White; dgvKeyList.Rows[sum + i].Cells[2].Value = maxName + (1 + sum + i); m_hotKeyList.Rows[sum + i]["color"] = ColorTranslator.ToHtml(colorRandom); m_hotKeyList.Rows[sum + i]["name"] = maxName + (1 + sum + i); } } /// /// 生成随机的颜色信息 /// /// 生成结果示例:#FF5A5E #F7464A public Color GetRandomColor() { // 随机数 Random rnd = new Random(); // 随机色 Color myColor = System.Drawing.Color.FromArgb( rnd.Next(0, 255), /*红色*/ rnd.Next(0, 255), /*绿色*/ rnd.Next(0, 255)  /*蓝色*/ ); return myColor; } private void txtAddNum_TextChanged(object sender, EventArgs e) { } private void dgvKeyList_CellClick(object sender, DataGridViewCellEventArgs e) { m_rowIndex = e.RowIndex; m_columnIndex = e.ColumnIndex; // 点击图标 if (dgvKeyList.Columns[e.ColumnIndex].Name == "hotKey" && e.RowIndex >= 0) { dgvKeyList.Columns[e.ColumnIndex].DefaultCellStyle.SelectionBackColor = dgvKeyList.Columns[e.ColumnIndex].DefaultCellStyle.BackColor; //ShowColorsForm(m_rowIndex); } } private void dgvKeyList_CellContentClick(object sender, DataGridViewCellEventArgs e) { // 修改显示是否统计 if (dgvKeyList.Columns[e.ColumnIndex].Name == "isCount" && e.RowIndex >= 0) { bool selectValue = Convert.ToBoolean(dgvKeyList.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue); m_hotKeyList.Rows[e.RowIndex]["is_count"] = selectValue ? 1 : 0; } //点击删除 if (dgvKeyList.Columns[e.ColumnIndex].Name == "isDel" && e.RowIndex >= 0) { int index = -1; for (int i = 0; i < m_hotKeyList.Rows.Count; i++) { if (m_hotKeyList.Rows[i]["delete_flag"].ToString() != "1") { index++; } if (index == e.RowIndex) { m_hotKeyList.Rows[i]["delete_flag"] = 1; break; } } //m_hotKeyList.Rows.RemoveAt(e.RowIndex); dgvKeyList.Rows.RemoveAt(e.RowIndex); } } private void dgvKeyList_KeyDown(object sender, KeyEventArgs e) { if(m_columnIndex != 1) { return; } string keyString = e.KeyCode.ToString(); if (keyString.Equals("ControlKey")) { keyString = "Control"; } if (keyString.Equals("Menu")) { keyString = "Alt"; } if (!keyString.Equals("")) { for (int i = 0; i < m_hotKeyList.Rows.Count; ++i) { if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("0")) { string s = m_hotKeyList.Rows[i]["hot_key"].ToString(); if (keyString.Equals(s)) { MessageBox.Show(PdnResources.GetString("Menu.user-defineepeated.text")); return; } } } m_hotKeyList.Rows[m_rowIndex]["hot_key"] = keyString; m_hotKeyList.Rows[m_rowIndex]["delete_flag"] = "0"; dgvKeyList.Rows[m_rowIndex].Cells[m_columnIndex].Value = keyString; } } private void dgvKeyList_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if(m_rowIndex < 0 || m_columnIndex < 0) { return; } // 修改名称 if (dgvKeyList.Columns[e.ColumnIndex].Name == "name" && e.RowIndex >= 0) { m_hotKeyList.Rows[m_rowIndex]["name"] = dgvKeyList.Rows[m_rowIndex].Cells[m_columnIndex].Value; } // 设置方向 if (dgvKeyList.Columns[e.ColumnIndex].Name == "direction" && e.RowIndex >= 0) { m_hotKeyList.Rows[m_rowIndex]["direction"] = dgvKeyList.Rows[m_rowIndex].Cells[m_columnIndex].Value; } } private void HotKeySetingDialog_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) { if (m_hotKeyList.Rows.Count <= 0) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseangsfirst.text")); return; } // 是否更新组织名称 string tissuesName = txtTissuesName.Text.Trim(); if (tissuesName != m_tissuesList.Rows[0]["tissue_name"].ToString()) { if (string.IsNullOrWhiteSpace(tissuesName) || string.IsNullOrEmpty(tissuesName)) { MessageBox.Show(PdnResources.GetString("Menu.Organiotbeempty.text")); return; } string update_sql = "update mic_tissues set tissue_name = ? where id = ?"; //SQL语句(带参数) SQLiteParameter[] para = new SQLiteParameter[2]; //构造并绑定参数 string[] tag = { "tissue_name", "id" }; Object[] value = { tissuesName, m_tissuesId }; for (int i = 0; i < 2; i++) { para[i] = new SQLiteParameter(tag[i], value[i]); } m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更新操作 } // 更新或添加按键设置 for (int i = 0; i < m_hotKeyList.Rows.Count; ++i) { // 插入 if (m_hotKeyList.Rows[i]["id"].ToString().Equals("0")) { // 新增加又删除的跳过 if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("1") || m_hotKeyList.Rows[i]["hot_key"].ToString().Equals("")) { continue; } string insert_sql = "insert into mic_tissues_key(tissue_id, name, hot_key, color, is_count, direction, delete_flag) values(?,?,?,?,?,?,0)"; //插入的SQL语句(带参数) SQLiteParameter[] para = new SQLiteParameter[6]; //构造并绑定参数 string[] tag = { "tissue_id", "name", "hot_key", "color", "is_count", "direction" }; Object[] value = { m_hotKeyList.Rows[i]["tissue_id"].ToString(), m_hotKeyList.Rows[i]["name"].ToString(), m_hotKeyList.Rows[i]["hot_key"].ToString(), m_hotKeyList.Rows[i]["color"].ToString(), m_hotKeyList.Rows[i]["is_count"].ToString(), m_hotKeyList.Rows[i]["direction"].ToString() }; for (int t = 0; t < 6; t++) { para[t] = new SQLiteParameter(tag[t], value[t]); } m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作 } else { if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("1")) { string delete_sql = "delete from mic_tissues_key where id = " + m_hotKeyList.Rows[i]["id"].ToString(); m_sqlHelper.ExecuteNonQuery(delete_sql, null); continue; } string update_sql = "update mic_tissues_key set tissue_id = ?, name = ?, hot_key = ?, color = ?, is_count = ?, direction = ?, delete_flag = ? where id = ?"; //更新的SQL语句(带参数) SQLiteParameter[] para = new SQLiteParameter[8]; //构造并绑定参数 string[] tag = { "tissue_id", "name", "hot_key", "color", "is_count", "direction", "delete_flag", "id" }; Object[] value = { m_hotKeyList.Rows[i]["tissue_id"].ToString(), m_hotKeyList.Rows[i]["name"].ToString(), m_hotKeyList.Rows[i]["hot_key"].ToString(), m_hotKeyList.Rows[i]["color"].ToString(), m_hotKeyList.Rows[i]["is_count"].ToString(), m_hotKeyList.Rows[i]["direction"].ToString(), m_hotKeyList.Rows[i]["delete_flag"].ToString(), m_hotKeyList.Rows[i]["id"].ToString() }; for (int t = 0; t < 8; t++) { para[t] = new SQLiteParameter(tag[t], value[t]); } m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更细操作 } } ((GeneralCountometerDialog)m_parentForm).TissuesKeyRefresh(); //MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text")); this.Close(); } private void btnSaveAs_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_hotKeyList.Rows.Count <= 0) { MessageBox.Show(PdnResources.GetString("Menu.Pleaseangsfirst.text")); return; } // 保存组织名称 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); //执行插入操作 for (int i = 0; i < m_hotKeyList.Rows.Count; ++i) { // 新增加又删除的跳过 if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("1") || m_hotKeyList.Rows[i]["hot_key"].ToString().Equals("")) { continue; } // 插入 insert_sql = "insert into mic_tissues_key(tissue_id, name, hot_key, color, is_count, direction, delete_flag) values(?,?,?,?,?,?,0)"; //插入的SQL语句(带参数) para = new SQLiteParameter[6]; //构造并绑定参数 string[] tag2 = { "tissue_id", "name", "hot_key", "color", "is_count", "direction" }; Object[] value2 = { tissueId, m_hotKeyList.Rows[i]["name"].ToString(), m_hotKeyList.Rows[i]["hot_key"].ToString(), m_hotKeyList.Rows[i]["color"].ToString(), m_hotKeyList.Rows[i]["is_count"].ToString(), m_hotKeyList.Rows[i]["direction"].ToString() }; for (int t = 0; t < 6; t++) { para[t] = new SQLiteParameter(tag2[t], value2[t]); } m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作 } ((GeneralCountometerDialog)m_parentForm).TissuesListLoad(); //MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text")); this.Close(); } } }