CommonUtil.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ComponentFactory.Krypton.Toolkit;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. namespace NXWMS
  8. {
  9. /// <summary>
  10. /// 通用工具
  11. /// </summary>
  12. public static class CommonUtil
  13. {
  14. /// <summary>
  15. /// 设定控件组中所有字段值等于Row
  16. /// </summary>
  17. /// <param name="container"></param>
  18. /// <param name="dataView"></param>
  19. /// <param name="row"></param>
  20. public static void GetGroupControls(TableLayoutPanel container, DataGridView dataView, DataGridViewRow row)
  21. {
  22. foreach (Control c in container.Controls)
  23. {
  24. if (c.Tag != null)
  25. {
  26. if (c.Tag.GetType().Name == "String")
  27. {
  28. if (dataView.Columns.Contains(c.Tag.ToString()))
  29. {
  30. switch (c.GetType().Name)
  31. {
  32. case "KryptonCheckBox":
  33. var kryptonCheckBox = (c as KryptonCheckBox);
  34. kryptonCheckBox.Checked = (row.Cells[c.Tag.ToString()].Value == null ? "" : row.Cells[c.Tag.ToString()].Value.ToString()) == "1" ? true : false;
  35. break;
  36. case "CheckBox":
  37. var checkbox = (c as KryptonCheckBox);
  38. checkbox.Checked = (row.Cells[c.Tag.ToString()].Value == null ? "" : row.Cells[c.Tag.ToString()].Value.ToString()) == "1" ? true : false;
  39. break;
  40. case "KryptonComboBox":
  41. case "ComboBox":
  42. case "KryptonTextBox":
  43. case "TextBox":
  44. default:
  45. c.Text = row.Cells[c.Tag.ToString()].Value == null ? "" : row.Cells[c.Tag.ToString()].Value.ToString();
  46. break;
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 设定控件组中所有字段值等于空
  55. /// </summary>
  56. /// <param name="container"></param>
  57. /// <param name="dataView"></param>
  58. public static void SetGroupControlsEmpty(TableLayoutPanel container, DataGridView dataView)
  59. {
  60. foreach (Control c in container.Controls)
  61. {
  62. if (c.Tag != null)
  63. {
  64. if (c.Tag.GetType().Name == "String")
  65. {
  66. if (dataView.Columns.Contains(c.Tag.ToString()))
  67. {
  68. c.Text = "";
  69. }
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }