HotKeySetingDialog.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SQLite;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using PaintDotNet.Base.CommTool;
  13. using PaintDotNet.Data.Param;
  14. namespace PaintDotNet.GeneralAnalysis.Countometer
  15. {
  16. public class HotKeySetingDialog : PdnBaseForm
  17. {
  18. #region
  19. /// <summary>
  20. /// Required designer variable.
  21. /// </summary>
  22. private System.ComponentModel.IContainer components = null;
  23. /// <summary>
  24. /// Clean up any resources being used.
  25. /// </summary>
  26. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  27. protected override void Dispose(bool disposing)
  28. {
  29. if (disposing && (components != null))
  30. {
  31. components.Dispose();
  32. }
  33. base.Dispose(disposing);
  34. }
  35. #region Windows Form Designer generated code
  36. private void InitializeLanguageText()
  37. {
  38. this.label1.Text = PdnResources.GetString("Menu.organizationname.text") + ":";
  39. this.hotKey.HeaderText = PdnResources.GetString("Menu.icon.text");
  40. this.name.HeaderText = PdnResources.GetString("Menu.name.text");
  41. this.direction.HeaderText = PdnResources.GetString("Menu.Generalanalysis.Integrator.action.text");
  42. this.isCount.HeaderText = PdnResources.GetString("Menu.Generalanalysis.Integrator.Whetherstatistics.text");
  43. this.isDel.HeaderText = PdnResources.GetString("Menu.operation.text");
  44. this.isDel.Text = PdnResources.GetString("Menu.Edit.Delete.Text");
  45. this.Text = PdnResources.GetString("Menu.Keyboarddefinition.text");
  46. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  47. this.btnSaveAs.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.Saveas.text");
  48. this.btnClose.Text = PdnResources.GetString("Menu.File.Close.Text");
  49. this.btnSave.Text = PdnResources.GetString("Menu.File.Save.Text");
  50. this.groupBox2.Text = PdnResources.GetString("Menu.Keyboarddefinition.text");
  51. this.btnAdd.Text = PdnResources.GetString("Menu.Addto.text");
  52. this.label2.Text = PdnResources.GetString("Menu.Generalanalysis.Integrator.definequantity.text") + ":";
  53. this.direction.Items.AddRange(new object[] {
  54. "",
  55. PdnResources.GetString("Menu.Weightmeasurement.Text"),
  56. PdnResources.GetString("Menu.skip.Text")});
  57. }
  58. /// <summary>
  59. /// Required method for Designer support - do not modify
  60. /// the contents of this method with the code editor.
  61. /// </summary>
  62. private void InitializeComponent()
  63. {
  64. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
  65. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
  66. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  67. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  68. this.groupBox1 = new System.Windows.Forms.GroupBox();
  69. this.btnSaveAs = new System.Windows.Forms.Button();
  70. this.btnClose = new System.Windows.Forms.Button();
  71. this.btnSave = new System.Windows.Forms.Button();
  72. this.groupBox2 = new System.Windows.Forms.GroupBox();
  73. this.dgvKeyList = new System.Windows.Forms.DataGridView();
  74. this.btnAdd = new System.Windows.Forms.Button();
  75. this.txtAddNum = new System.Windows.Forms.TextBox();
  76. this.label2 = new System.Windows.Forms.Label();
  77. this.txtTissuesName = new System.Windows.Forms.TextBox();
  78. this.label1 = new System.Windows.Forms.Label();
  79. this.isDel = new System.Windows.Forms.DataGridViewLinkColumn();
  80. this.isCount = new System.Windows.Forms.DataGridViewCheckBoxColumn();
  81. this.direction = new System.Windows.Forms.DataGridViewComboBoxColumn();
  82. this.name = new System.Windows.Forms.DataGridViewTextBoxColumn();
  83. this.hotKey = new System.Windows.Forms.DataGridViewTextBoxColumn();
  84. this.id = new System.Windows.Forms.DataGridViewTextBoxColumn();
  85. this.groupBox1.SuspendLayout();
  86. this.groupBox2.SuspendLayout();
  87. ((System.ComponentModel.ISupportInitialize)(this.dgvKeyList)).BeginInit();
  88. this.SuspendLayout();
  89. //
  90. // groupBox1
  91. //
  92. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  93. | System.Windows.Forms.AnchorStyles.Right)));
  94. this.groupBox1.Controls.Add(this.btnSaveAs);
  95. this.groupBox1.Controls.Add(this.btnClose);
  96. this.groupBox1.Controls.Add(this.btnSave);
  97. this.groupBox1.Location = new System.Drawing.Point(12, 12);
  98. this.groupBox1.Name = "groupBox1";
  99. this.groupBox1.Size = new System.Drawing.Size(608, 71);
  100. this.groupBox1.TabIndex = 1;
  101. this.groupBox1.TabStop = false;
  102. this.groupBox1.Text = "操作";
  103. //
  104. // btnSaveAs
  105. //
  106. this.btnSaveAs.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  107. this.btnSaveAs.Location = new System.Drawing.Point(292, 24);
  108. this.btnSaveAs.Name = "btnSaveAs";
  109. this.btnSaveAs.Size = new System.Drawing.Size(84, 31);
  110. this.btnSaveAs.TabIndex = 2;
  111. this.btnSaveAs.Text = "另存";
  112. this.btnSaveAs.UseVisualStyleBackColor = true;
  113. this.btnSaveAs.Click += new System.EventHandler(this.btnSaveAs_Click);
  114. //
  115. // btnClose
  116. //
  117. this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  118. this.btnClose.Location = new System.Drawing.Point(504, 24);
  119. this.btnClose.Name = "btnClose";
  120. this.btnClose.Size = new System.Drawing.Size(84, 31);
  121. this.btnClose.TabIndex = 1;
  122. this.btnClose.Text = "关闭";
  123. this.btnClose.UseVisualStyleBackColor = true;
  124. this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
  125. //
  126. // btnSave
  127. //
  128. this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  129. this.btnSave.Location = new System.Drawing.Point(398, 24);
  130. this.btnSave.Name = "btnSave";
  131. this.btnSave.Size = new System.Drawing.Size(84, 31);
  132. this.btnSave.TabIndex = 0;
  133. this.btnSave.Text = "保存";
  134. this.btnSave.UseVisualStyleBackColor = true;
  135. this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  136. //
  137. // groupBox2
  138. //
  139. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  140. | System.Windows.Forms.AnchorStyles.Left)
  141. | System.Windows.Forms.AnchorStyles.Right)));
  142. this.groupBox2.Controls.Add(this.dgvKeyList);
  143. this.groupBox2.Controls.Add(this.btnAdd);
  144. this.groupBox2.Controls.Add(this.txtAddNum);
  145. this.groupBox2.Controls.Add(this.label2);
  146. this.groupBox2.Controls.Add(this.txtTissuesName);
  147. this.groupBox2.Controls.Add(this.label1);
  148. this.groupBox2.Location = new System.Drawing.Point(12, 89);
  149. this.groupBox2.Name = "groupBox2";
  150. this.groupBox2.Size = new System.Drawing.Size(608, 521);
  151. this.groupBox2.TabIndex = 2;
  152. this.groupBox2.TabStop = false;
  153. this.groupBox2.Text = "键盘定义";
  154. //
  155. // dgvKeyList
  156. //
  157. this.dgvKeyList.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  158. | System.Windows.Forms.AnchorStyles.Left)
  159. | System.Windows.Forms.AnchorStyles.Right)));
  160. this.dgvKeyList.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
  161. this.dgvKeyList.ColumnHeadersHeight = 20;
  162. this.dgvKeyList.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
  163. this.id,
  164. this.hotKey,
  165. this.name,
  166. this.direction,
  167. this.isCount,
  168. this.isDel});
  169. this.dgvKeyList.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
  170. this.dgvKeyList.Location = new System.Drawing.Point(18, 79);
  171. this.dgvKeyList.Name = "dgvKeyList";
  172. this.dgvKeyList.RowHeadersVisible = false;
  173. this.dgvKeyList.RowHeadersWidth = 51;
  174. this.dgvKeyList.RowTemplate.Height = 20;
  175. this.dgvKeyList.Size = new System.Drawing.Size(570, 423);
  176. this.dgvKeyList.TabIndex = 5;
  177. this.dgvKeyList.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvKeyList_CellClick);
  178. this.dgvKeyList.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvKeyList_CellContentClick);
  179. this.dgvKeyList.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvKeyList_CellValueChanged);
  180. this.dgvKeyList.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dgvKeyList_KeyDown);
  181. //
  182. // btnAdd
  183. //
  184. this.btnAdd.Location = new System.Drawing.Point(442, 24);
  185. this.btnAdd.Name = "btnAdd";
  186. this.btnAdd.Size = new System.Drawing.Size(84, 33);
  187. this.btnAdd.TabIndex = 4;
  188. this.btnAdd.Text = "添加";
  189. this.btnAdd.UseVisualStyleBackColor = true;
  190. this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
  191. //
  192. // txtAddNum
  193. //
  194. this.txtAddNum.Location = new System.Drawing.Point(347, 29);
  195. this.txtAddNum.Name = "txtAddNum";
  196. this.txtAddNum.Size = new System.Drawing.Size(77, 21);
  197. this.txtAddNum.TabIndex = 3;
  198. this.txtAddNum.TextChanged += new System.EventHandler(this.txtAddNum_TextChanged);
  199. this.txtAddNum.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtAddNum_KeyPress);
  200. //
  201. // label2
  202. //
  203. this.label2.AutoSize = true;
  204. this.label2.Location = new System.Drawing.Point(255, 35);
  205. this.label2.Name = "label2";
  206. this.label2.Size = new System.Drawing.Size(65, 12);
  207. this.label2.TabIndex = 2;
  208. this.label2.Text = "定义数量:";
  209. //
  210. // txtTissuesName
  211. //
  212. this.txtTissuesName.Location = new System.Drawing.Point(94, 29);
  213. this.txtTissuesName.Name = "txtTissuesName";
  214. this.txtTissuesName.Size = new System.Drawing.Size(145, 21);
  215. this.txtTissuesName.TabIndex = 1;
  216. //
  217. // label1
  218. //
  219. this.label1.AutoSize = true;
  220. this.label1.Location = new System.Drawing.Point(15, 35);
  221. this.label1.Name = "label1";
  222. this.label1.Size = new System.Drawing.Size(65, 12);
  223. this.label1.TabIndex = 0;
  224. this.label1.Text = "组织名称:";
  225. //
  226. // isDel
  227. //
  228. dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  229. this.isDel.DefaultCellStyle = dataGridViewCellStyle4;
  230. this.isDel.MinimumWidth = 6;
  231. this.isDel.Name = "isDel";
  232. this.isDel.Resizable = System.Windows.Forms.DataGridViewTriState.True;
  233. this.isDel.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
  234. this.isDel.UseColumnTextForLinkValue = true;
  235. //
  236. // isCount
  237. //
  238. this.isCount.MinimumWidth = 6;
  239. this.isCount.Name = "isCount";
  240. this.isCount.Resizable = System.Windows.Forms.DataGridViewTriState.True;
  241. this.isCount.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
  242. //
  243. // direction
  244. //
  245. this.direction.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  246. dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  247. dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
  248. this.direction.DefaultCellStyle = dataGridViewCellStyle3;
  249. this.direction.MinimumWidth = 6;
  250. this.direction.Name = "direction";
  251. this.direction.Resizable = System.Windows.Forms.DataGridViewTriState.True;
  252. this.direction.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
  253. //
  254. // name
  255. //
  256. this.name.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  257. this.name.MinimumWidth = 6;
  258. this.name.Name = "name";
  259. //
  260. // hotKey
  261. //
  262. this.hotKey.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  263. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  264. dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 10.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  265. dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
  266. this.hotKey.DefaultCellStyle = dataGridViewCellStyle2;
  267. this.hotKey.MinimumWidth = 6;
  268. this.hotKey.Name = "hotKey";
  269. this.hotKey.ReadOnly = true;
  270. this.hotKey.Resizable = System.Windows.Forms.DataGridViewTriState.True;
  271. //
  272. // id
  273. //
  274. this.id.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
  275. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  276. this.id.DefaultCellStyle = dataGridViewCellStyle1;
  277. this.id.HeaderText = "id";
  278. this.id.MinimumWidth = 6;
  279. this.id.Name = "id";
  280. this.id.Visible = false;
  281. //
  282. // HotKeySetingDialog
  283. //
  284. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  285. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  286. this.ClientSize = new System.Drawing.Size(632, 622);
  287. this.Controls.Add(this.groupBox2);
  288. this.Controls.Add(this.groupBox1);
  289. this.Name = "HotKeySetingDialog";
  290. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  291. this.Text = "键盘定义";
  292. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.HotKeySetingDialog_FormClosing);
  293. this.Controls.SetChildIndex(this.groupBox1, 0);
  294. this.Controls.SetChildIndex(this.groupBox2, 0);
  295. this.groupBox1.ResumeLayout(false);
  296. this.groupBox2.ResumeLayout(false);
  297. this.groupBox2.PerformLayout();
  298. ((System.ComponentModel.ISupportInitialize)(this.dgvKeyList)).EndInit();
  299. this.ResumeLayout(false);
  300. }
  301. #endregion
  302. private System.Windows.Forms.GroupBox groupBox1;
  303. private System.Windows.Forms.Button btnSaveAs;
  304. private System.Windows.Forms.Button btnClose;
  305. private System.Windows.Forms.Button btnSave;
  306. private System.Windows.Forms.GroupBox groupBox2;
  307. private System.Windows.Forms.DataGridView dgvKeyList;
  308. private System.Windows.Forms.Button btnAdd;
  309. private System.Windows.Forms.TextBox txtAddNum;
  310. private System.Windows.Forms.Label label2;
  311. private System.Windows.Forms.TextBox txtTissuesName;
  312. private System.Windows.Forms.Label label1;
  313. #endregion
  314. /// <summary>
  315. /// 网格调色板
  316. /// </summary>
  317. PaintDotNet.ColorsForm colorsFormGrid;
  318. /// <summary>
  319. /// 矩形调色板
  320. /// </summary>
  321. PaintDotNet.ColorsForm colorsFormRect;
  322. /// <summary>
  323. /// 圆形调色板
  324. /// </summary>
  325. PaintDotNet.ColorsForm colorsFormCircular;
  326. private SQLiteHelper m_sqlHelper;
  327. private string m_tissuesId;
  328. private DataTable m_hotKeyList;
  329. private DataTable m_tissuesList;
  330. private int m_rowIndex = -1;
  331. private int m_columnIndex = -1;
  332. private DataGridViewTextBoxColumn id;
  333. private DataGridViewTextBoxColumn hotKey;
  334. private DataGridViewTextBoxColumn name;
  335. private DataGridViewComboBoxColumn direction;
  336. private DataGridViewCheckBoxColumn isCount;
  337. private DataGridViewLinkColumn isDel;
  338. private Form m_parentForm;
  339. public HotKeySetingDialog(Form form, string id)
  340. {
  341. m_parentForm = form;
  342. m_tissuesId = id;
  343. InitializeComponent();
  344. InitializeLanguageText();
  345. InitializeData();
  346. this.colorsFormGrid = new ColorsForm();
  347. this.colorsFormGrid.StartPosition = FormStartPosition.CenterScreen;
  348. this.colorsFormGrid.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  349. this.colorsFormRect = new ColorsForm();
  350. this.colorsFormRect.StartPosition = FormStartPosition.CenterScreen;
  351. this.colorsFormRect.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  352. this.colorsFormCircular = new ColorsForm();
  353. this.colorsFormCircular.StartPosition = FormStartPosition.CenterScreen;
  354. this.colorsFormCircular.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  355. }
  356. private void InitializeData()
  357. {
  358. dgvKeyList.DefaultCellStyle.SelectionBackColor = dgvKeyList.DefaultCellStyle.BackColor;
  359. dgvKeyList.DefaultCellStyle.SelectionForeColor = dgvKeyList.DefaultCellStyle.ForeColor;
  360. dgvKeyList.AllowUserToAddRows = false;
  361. dgvKeyList.AutoGenerateColumns = false;
  362. m_sqlHelper = new SQLiteHelper(); //连接数据库
  363. m_sqlHelper.Connect();
  364. // 组织信息
  365. string select_sql1 = "select * from mic_tissues where delete_flag = 0 and id = '" + m_tissuesId +"'"; //查询的SQL语句
  366. m_tissuesList = m_sqlHelper.ExecuteDataTable(select_sql1, null); //执行查询操作,结果存放在dt中
  367. txtTissuesName.Text = m_tissuesList.Rows[0]["tissue_name"].ToString();
  368. // 按键设置列表
  369. string select_sql = "select * from mic_tissues_key where delete_flag = 0 and tissue_id = '" + m_tissuesId + "'"; //查询的SQL语句
  370. m_hotKeyList = m_sqlHelper.ExecuteDataTable(select_sql, null); //执行查询操作,结果存放在dt中
  371. DrawDgvKeyList();
  372. }
  373. private void DrawDgvKeyList()
  374. {
  375. this.dgvKeyList.Rows.Clear();
  376. if(m_hotKeyList.Rows.Count > 0)
  377. {
  378. dgvKeyList.Rows.Add(m_hotKeyList.Rows.Count);
  379. for (int i = 0; i < m_hotKeyList.Rows.Count; ++i)
  380. {
  381. dgvKeyList.Rows[i].Cells["id"].Value = m_hotKeyList.Rows[i]["id"].ToString();
  382. Color bgColor = ColorTranslator.FromHtml(m_hotKeyList.Rows[i]["color"].ToString());
  383. dgvKeyList.Rows[i].Cells["hotKey"].Value = m_hotKeyList.Rows[i]["hot_key"].ToString();
  384. dgvKeyList.Rows[i].Cells["hotKey"].Style.BackColor = bgColor;
  385. dgvKeyList.Rows[i].Cells["hotKey"].Style.ForeColor = Color.White;
  386. dgvKeyList.Rows[i].Cells["hotKey"].Style.SelectionBackColor = bgColor;
  387. dgvKeyList.Rows[i].Cells["hotKey"].Style.SelectionForeColor = Color.White;
  388. dgvKeyList.Rows[i].Cells["name"].Value = m_hotKeyList.Rows[i]["name"].ToString();
  389. dgvKeyList.Rows[i].Cells["direction"].Value = m_hotKeyList.Rows[i]["direction"].ToString();
  390. if (m_hotKeyList.Rows[i]["is_count"].ToString().Equals("1"))
  391. {
  392. dgvKeyList.Rows[i].Cells["isCount"].Value = true;
  393. }
  394. else
  395. {
  396. dgvKeyList.Rows[i].Cells["isCount"].Value = false;
  397. }
  398. }
  399. }
  400. }
  401. /// <summary>
  402. /// 调色板回调函数
  403. /// </summary>
  404. /// <param name="sender"></param>
  405. /// <param name="ce"></param>
  406. private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
  407. {
  408. }
  409. private void ShowColorsForm(int rowIndex)
  410. {
  411. Color color = Color.White;
  412. if (rowIndex < m_hotKeyList.Rows.Count)
  413. {
  414. for (int i = 0; i < m_hotKeyList.Rows.Count; ++i)
  415. {
  416. if (i == rowIndex)
  417. {
  418. string c = m_hotKeyList.Rows[i]["color"].ToString();
  419. if (!string.IsNullOrEmpty(c))
  420. {
  421. color = ColorTranslator.FromHtml(c);
  422. }
  423. }
  424. }
  425. }
  426. this.colorsFormGrid.UserPrimaryColor = ColorBgra.FromColor(color);
  427. //this.colorsFormGrid.setSaveBtn_Click(new System.EventHandler(this.gridColorChanged));
  428. this.colorsFormGrid.ShowDialog();
  429. }
  430. /// <summary>
  431. /// 网格Panel的调色板颜色改变
  432. /// </summary>
  433. /// <param name="sender"></param>
  434. /// <param name="e"></param>
  435. private void gridColorChanged(object sender, EventArgs e)
  436. {
  437. Color color = this.colorsFormGrid.UserPrimaryColor.ToColor();
  438. m_hotKeyList.Rows[m_rowIndex]["color"] = ColorTranslator.ToHtml(color);
  439. this.colorsFormGrid.Close();
  440. dgvKeyList.Rows[m_rowIndex].Cells[1].Style.BackColor = color;
  441. dgvKeyList.Rows[m_rowIndex].Cells[1].Style.ForeColor = Color.White;
  442. dgvKeyList.Rows[m_rowIndex].Cells[1].Style.SelectionBackColor = color;
  443. dgvKeyList.Rows[m_rowIndex].Cells[1].Style.SelectionForeColor = Color.White;
  444. }
  445. private void txtAddNum_KeyPress(object sender, KeyPressEventArgs e)
  446. {
  447. TextBox textBox = (TextBox)sender;
  448. if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8)
  449. e.Handled = true;
  450. }
  451. private void btnAdd_Click(object sender, EventArgs e)
  452. {
  453. if (string.IsNullOrEmpty(txtAddNum.Text.Trim()))
  454. {
  455. MessageBox.Show(PdnResources.GetString("Menu.Pleaseaddquantityfirst.text"));
  456. return;
  457. }
  458. //获取表行数
  459. int sum = dgvKeyList.Rows.Count;
  460. string maxName = PdnResources.GetString("Menu.organization.text");
  461. int num = int.Parse(txtAddNum.Text.Trim());
  462. if (num > 0)
  463. {
  464. dgvKeyList.Rows.Add(num);
  465. }
  466. for (int i = 0; i < num; ++i)
  467. {
  468. m_hotKeyList.Rows.Add(0, m_tissuesId, "", "", "White", 0, "");
  469. }
  470. for (int i = 0; i < num; ++i)
  471. {
  472. Thread.Sleep(50);
  473. Color colorRandom = new Color();
  474. colorRandom = GetRandomColor();
  475. dgvKeyList.Rows[sum+i].Cells[1].Style.BackColor = colorRandom;
  476. dgvKeyList.Rows[sum + i].Cells[1].Style.SelectionBackColor = colorRandom;
  477. dgvKeyList.Rows[sum + i].Cells[1].Style.ForeColor = Color.White;
  478. dgvKeyList.Rows[sum + i].Cells[1].Style.SelectionForeColor = Color.White;
  479. dgvKeyList.Rows[sum + i].Cells[2].Value = maxName + (1 + sum + i);
  480. m_hotKeyList.Rows[sum + i]["color"] = ColorTranslator.ToHtml(colorRandom);
  481. m_hotKeyList.Rows[sum + i]["name"] = maxName + (1 + sum + i);
  482. }
  483. }
  484. /// <summary>
  485. /// 生成随机的颜色信息
  486. /// </summary>
  487. /// <returns>生成结果示例:#FF5A5E #F7464A</returns>
  488. public Color GetRandomColor()
  489. {
  490. // 随机数
  491. Random rnd = new Random();
  492. // 随机色
  493. Color myColor = System.Drawing.Color.FromArgb(
  494. rnd.Next(0, 255), /*红色*/
  495. rnd.Next(0, 255), /*绿色*/
  496. rnd.Next(0, 255)  /*蓝色*/ );
  497. return myColor;
  498. }
  499. private void txtAddNum_TextChanged(object sender, EventArgs e)
  500. {
  501. }
  502. private void dgvKeyList_CellClick(object sender, DataGridViewCellEventArgs e)
  503. {
  504. m_rowIndex = e.RowIndex;
  505. m_columnIndex = e.ColumnIndex;
  506. // 点击图标
  507. if (dgvKeyList.Columns[e.ColumnIndex].Name == "hotKey" && e.RowIndex >= 0)
  508. {
  509. dgvKeyList.Columns[e.ColumnIndex].DefaultCellStyle.SelectionBackColor = dgvKeyList.Columns[e.ColumnIndex].DefaultCellStyle.BackColor;
  510. //ShowColorsForm(m_rowIndex);
  511. }
  512. }
  513. private void dgvKeyList_CellContentClick(object sender, DataGridViewCellEventArgs e)
  514. {
  515. // 修改显示是否统计
  516. if (dgvKeyList.Columns[e.ColumnIndex].Name == "isCount" && e.RowIndex >= 0)
  517. {
  518. bool selectValue = Convert.ToBoolean(dgvKeyList.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue);
  519. m_hotKeyList.Rows[e.RowIndex]["is_count"] = selectValue ? 1 : 0;
  520. }
  521. //点击删除
  522. if (dgvKeyList.Columns[e.ColumnIndex].Name == "isDel" && e.RowIndex >= 0)
  523. {
  524. int index = -1;
  525. for (int i = 0; i < m_hotKeyList.Rows.Count; i++)
  526. {
  527. if (m_hotKeyList.Rows[i]["delete_flag"].ToString() != "1")
  528. {
  529. index++;
  530. }
  531. if (index == e.RowIndex)
  532. {
  533. m_hotKeyList.Rows[i]["delete_flag"] = 1;
  534. break;
  535. }
  536. }
  537. //m_hotKeyList.Rows.RemoveAt(e.RowIndex);
  538. dgvKeyList.Rows.RemoveAt(e.RowIndex);
  539. }
  540. }
  541. private void dgvKeyList_KeyDown(object sender, KeyEventArgs e)
  542. {
  543. if(m_columnIndex != 1)
  544. {
  545. return;
  546. }
  547. string keyString = e.KeyCode.ToString();
  548. if (keyString.Equals("ControlKey"))
  549. {
  550. keyString = "Control";
  551. }
  552. if (keyString.Equals("Menu"))
  553. {
  554. keyString = "Alt";
  555. }
  556. if (!keyString.Equals(""))
  557. {
  558. for (int i = 0; i < m_hotKeyList.Rows.Count; ++i)
  559. {
  560. if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("0"))
  561. {
  562. string s = m_hotKeyList.Rows[i]["hot_key"].ToString();
  563. if (keyString.Equals(s))
  564. {
  565. MessageBox.Show(PdnResources.GetString("Menu.user-defineepeated.text"));
  566. return;
  567. }
  568. }
  569. }
  570. m_hotKeyList.Rows[m_rowIndex]["hot_key"] = keyString;
  571. m_hotKeyList.Rows[m_rowIndex]["delete_flag"] = "0";
  572. dgvKeyList.Rows[m_rowIndex].Cells[m_columnIndex].Value = keyString;
  573. }
  574. }
  575. private void dgvKeyList_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  576. {
  577. if(m_rowIndex < 0 || m_columnIndex < 0)
  578. {
  579. return;
  580. }
  581. // 修改名称
  582. if (dgvKeyList.Columns[e.ColumnIndex].Name == "name" && e.RowIndex >= 0)
  583. {
  584. m_hotKeyList.Rows[m_rowIndex]["name"] = dgvKeyList.Rows[m_rowIndex].Cells[m_columnIndex].Value;
  585. }
  586. // 设置方向
  587. if (dgvKeyList.Columns[e.ColumnIndex].Name == "direction" && e.RowIndex >= 0)
  588. {
  589. m_hotKeyList.Rows[m_rowIndex]["direction"] = dgvKeyList.Rows[m_rowIndex].Cells[m_columnIndex].Value;
  590. }
  591. }
  592. private void HotKeySetingDialog_FormClosing(object sender, FormClosingEventArgs e)
  593. {
  594. m_sqlHelper.DisConnect();
  595. }
  596. private void btnClose_Click(object sender, EventArgs e)
  597. {
  598. this.Close();
  599. }
  600. private void btnSave_Click(object sender, EventArgs e)
  601. {
  602. if (m_hotKeyList.Rows.Count <= 0)
  603. {
  604. MessageBox.Show(PdnResources.GetString("Menu.Pleaseangsfirst.text"));
  605. return;
  606. }
  607. // 是否更新组织名称
  608. string tissuesName = txtTissuesName.Text.Trim();
  609. if (tissuesName != m_tissuesList.Rows[0]["tissue_name"].ToString())
  610. {
  611. if (string.IsNullOrWhiteSpace(tissuesName) || string.IsNullOrEmpty(tissuesName))
  612. {
  613. MessageBox.Show(PdnResources.GetString("Menu.Organiotbeempty.text"));
  614. return;
  615. }
  616. string update_sql = "update mic_tissues set tissue_name = ? where id = ?"; //SQL语句(带参数)
  617. SQLiteParameter[] para = new SQLiteParameter[2]; //构造并绑定参数
  618. string[] tag = { "tissue_name", "id" };
  619. Object[] value = { tissuesName, m_tissuesId };
  620. for (int i = 0; i < 2; i++)
  621. {
  622. para[i] = new SQLiteParameter(tag[i], value[i]);
  623. }
  624. m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更新操作
  625. }
  626. // 更新或添加按键设置
  627. for (int i = 0; i < m_hotKeyList.Rows.Count; ++i)
  628. {
  629. // 插入
  630. if (m_hotKeyList.Rows[i]["id"].ToString().Equals("0"))
  631. {
  632. // 新增加又删除的跳过
  633. if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("1") || m_hotKeyList.Rows[i]["hot_key"].ToString().Equals(""))
  634. {
  635. continue;
  636. }
  637. string insert_sql = "insert into mic_tissues_key(tissue_id, name, hot_key, color, is_count, direction, delete_flag) values(?,?,?,?,?,?,0)"; //插入的SQL语句(带参数)
  638. SQLiteParameter[] para = new SQLiteParameter[6]; //构造并绑定参数
  639. string[] tag = { "tissue_id", "name", "hot_key", "color", "is_count", "direction" };
  640. 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() };
  641. for (int t = 0; t < 6; t++)
  642. {
  643. para[t] = new SQLiteParameter(tag[t], value[t]);
  644. }
  645. m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  646. }
  647. else
  648. {
  649. if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("1"))
  650. {
  651. string delete_sql = "delete from mic_tissues_key where id = " + m_hotKeyList.Rows[i]["id"].ToString();
  652. m_sqlHelper.ExecuteNonQuery(delete_sql, null);
  653. continue;
  654. }
  655. string update_sql = "update mic_tissues_key set tissue_id = ?, name = ?, hot_key = ?, color = ?, is_count = ?, direction = ?, delete_flag = ? where id = ?"; //更新的SQL语句(带参数)
  656. SQLiteParameter[] para = new SQLiteParameter[8]; //构造并绑定参数
  657. string[] tag = { "tissue_id", "name", "hot_key", "color", "is_count", "direction", "delete_flag", "id" };
  658. 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() };
  659. for (int t = 0; t < 8; t++)
  660. {
  661. para[t] = new SQLiteParameter(tag[t], value[t]);
  662. }
  663. m_sqlHelper.ExecuteNonQuery(update_sql, para); //执行更细操作
  664. }
  665. }
  666. ((GeneralCountometerDialog)m_parentForm).TissuesKeyRefresh();
  667. //MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
  668. this.Close();
  669. }
  670. private void btnSaveAs_Click(object sender, EventArgs e)
  671. {
  672. string tissuesName = txtTissuesName.Text.Trim();
  673. if (string.IsNullOrWhiteSpace(tissuesName) || string.IsNullOrEmpty(tissuesName))
  674. {
  675. MessageBox.Show(PdnResources.GetString("Menu.Organiotbeempty.text"));
  676. return;
  677. }
  678. if (m_hotKeyList.Rows.Count <= 0)
  679. {
  680. MessageBox.Show(PdnResources.GetString("Menu.Pleaseangsfirst.text"));
  681. return;
  682. }
  683. // 保存组织名称
  684. string tissueId = System.Guid.NewGuid().ToString("N");
  685. string insert_sql = "insert into mic_tissues(id,tissue_name, delete_flag) values(?,?,0)"; //插入的SQL语句(带参数)
  686. SQLiteParameter[] para = new SQLiteParameter[2]; //构造并绑定参数
  687. string[] tag = { "id", "tissue_name" };
  688. Object[] value = { tissueId, tissuesName };
  689. for (int i = 0; i < 2; i++)
  690. {
  691. para[i] = new SQLiteParameter(tag[i], value[i]);
  692. }
  693. m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  694. for (int i = 0; i < m_hotKeyList.Rows.Count; ++i)
  695. {
  696. // 新增加又删除的跳过
  697. if (m_hotKeyList.Rows[i]["delete_flag"].ToString().Equals("1") || m_hotKeyList.Rows[i]["hot_key"].ToString().Equals(""))
  698. {
  699. continue;
  700. }
  701. // 插入
  702. insert_sql = "insert into mic_tissues_key(tissue_id, name, hot_key, color, is_count, direction, delete_flag) values(?,?,?,?,?,?,0)"; //插入的SQL语句(带参数)
  703. para = new SQLiteParameter[6]; //构造并绑定参数
  704. string[] tag2 = { "tissue_id", "name", "hot_key", "color", "is_count", "direction" };
  705. 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() };
  706. for (int t = 0; t < 6; t++)
  707. {
  708. para[t] = new SQLiteParameter(tag2[t], value2[t]);
  709. }
  710. m_sqlHelper.ExecuteNonQuery(insert_sql, para); //执行插入操作
  711. }
  712. ((GeneralCountometerDialog)m_parentForm).TissuesListLoad();
  713. //MessageBox.Show(PdnResources.GetString("Menu.Successfullysaved.text"));
  714. this.Close();
  715. }
  716. }
  717. }