PrintOptions.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. namespace ProjectBase.Controls
  12. {
  13. public partial class PrintOptions : DevExpress.XtraEditors.XtraForm
  14. {
  15. public PrintOptions()
  16. {
  17. InitializeComponent();
  18. }
  19. public PrintOptions(List<string> availableFields)
  20. {
  21. InitializeComponent();
  22. foreach (string field in availableFields)
  23. {
  24. chklst.Items.Add(field, true);
  25. }
  26. }
  27. /// <summary>
  28. /// 设置选定项目
  29. /// </summary>
  30. /// <param name="items"></param>
  31. public void SetCheckedItems(string[] items)
  32. {
  33. for (int i = 0; i < this.chklst.Items.Count; i++)
  34. {
  35. this.chklst.SetItemChecked(i, false);
  36. foreach (string item in items)
  37. {
  38. if (item == this.chklst.Items[i].ToString())
  39. {
  40. this.chklst.SetItemChecked(i, true);
  41. }
  42. }
  43. }
  44. }
  45. /// <summary>
  46. /// 获取用户选定的项目内容
  47. /// </summary>
  48. /// <returns></returns>
  49. public List<string> GetCheckItems()
  50. {
  51. List<string> list = new List<string>();
  52. for (int i = 0; i < this.chklst.Items.Count; i++)
  53. {
  54. if (this.chklst.GetItemChecked(i))
  55. {
  56. list.Add(this.chklst.Items[i].ToString());
  57. }
  58. }
  59. return list;
  60. }
  61. private void PrintOtions_Load(object sender, EventArgs e)
  62. {
  63. // Initialize some controls
  64. rdoAllRows.Checked = true;
  65. chkFitToPageWidth.Checked = true;
  66. }
  67. private void btnOK_Click(object sender, EventArgs e)
  68. {
  69. this.DialogResult = DialogResult.OK;
  70. this.Close();
  71. }
  72. private void btnCancel_Click(object sender, EventArgs e)
  73. {
  74. this.DialogResult = DialogResult.Cancel;
  75. this.Close();
  76. }
  77. public List<string> GetSelectedColumns()
  78. {
  79. List<string> lst = new List<string>();
  80. foreach (object item in chklst.CheckedItems)
  81. {
  82. lst.Add(item.ToString());
  83. }
  84. return lst;
  85. }
  86. public string PrintTitle
  87. {
  88. get { return txtTitle.Text; }
  89. set { this.txtTitle.Text = value; }
  90. }
  91. public bool PrintAllRows
  92. {
  93. get { return rdoAllRows.Checked; }
  94. }
  95. public bool FitToPageWidth
  96. {
  97. get { return chkFitToPageWidth.Checked; }
  98. }
  99. private void chkSelectAll_CheckedChanged(object sender, EventArgs e)
  100. {
  101. for (int i = 0; i < this.chklst.Items.Count; i++)
  102. {
  103. this.chklst.SetItemChecked(i, this.chkSelectAll.Checked);
  104. }
  105. }
  106. }
  107. }