GridItemSetting.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. 
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. namespace Dongke.WinForm.Controls.InvoiceLayout
  6. {
  7. internal partial class GridItemSetting : Setting
  8. {
  9. #region 成员变量
  10. private bool _isTransparent = false; // 背景是否透明
  11. private Color _fillColor = Color.Black; // 背景颜色
  12. private bool _isColChanged = false;
  13. #endregion 成员变量
  14. #region 属性
  15. /// <summary>
  16. /// 列属性是否改变
  17. /// </summary>
  18. public bool ColumnsChanged
  19. {
  20. get
  21. {
  22. return _isColChanged;
  23. }
  24. }
  25. /// <summary>
  26. /// X(mm)
  27. /// </summary>
  28. public float ShapeLocationX
  29. {
  30. get
  31. {
  32. return System.Convert.ToSingle(numLoctionX.Value);
  33. }
  34. set
  35. {
  36. decimal d = System.Convert.ToDecimal(value);
  37. if (d < numLoctionX.Minimum)
  38. {
  39. d = numLoctionX.Minimum;
  40. }
  41. else if (numLoctionX.Maximum < d)
  42. {
  43. d = numLoctionX.Maximum;
  44. }
  45. numLoctionX.Value = d;
  46. }
  47. }
  48. /// <summary>
  49. /// Y(mm)
  50. /// </summary>
  51. public float ShapeLocationY
  52. {
  53. get
  54. {
  55. return System.Convert.ToSingle(numLoctionY.Value);
  56. }
  57. set
  58. {
  59. decimal d = System.Convert.ToDecimal(value);
  60. if (d < numLoctionY.Minimum)
  61. {
  62. d = numLoctionY.Minimum;
  63. }
  64. else if (numLoctionY.Maximum < d)
  65. {
  66. d = numLoctionY.Maximum;
  67. }
  68. numLoctionY.Value = d;
  69. }
  70. }
  71. /// <summary>
  72. /// 宽(mm)
  73. /// </summary>
  74. public float ShapeWidth
  75. {
  76. get
  77. {
  78. return System.Convert.ToSingle(numWidth.Value);
  79. }
  80. set
  81. {
  82. decimal d = System.Convert.ToDecimal(value);
  83. if (d < numWidth.Minimum)
  84. {
  85. d = numWidth.Minimum;
  86. }
  87. else if (numWidth.Maximum < d)
  88. {
  89. d = numWidth.Maximum;
  90. }
  91. numWidth.Value = d;
  92. }
  93. }
  94. /// <summary>
  95. /// 高(mm)
  96. /// </summary>
  97. public float ShapeHeight
  98. {
  99. get
  100. {
  101. return System.Convert.ToSingle(numHeight.Value);
  102. }
  103. set
  104. {
  105. decimal d = System.Convert.ToDecimal(value);
  106. if (d < numHeight.Minimum)
  107. {
  108. d = numHeight.Minimum;
  109. }
  110. else if (numHeight.Maximum < d)
  111. {
  112. d = numHeight.Maximum;
  113. }
  114. numHeight.Value = d;
  115. }
  116. }
  117. /// <summary>
  118. /// 列头行高
  119. /// </summary>
  120. public float HeadRowsHeight
  121. {
  122. get
  123. {
  124. return System.Convert.ToSingle(numHeadRowsHeight.Value);
  125. }
  126. set
  127. {
  128. decimal d = System.Convert.ToDecimal(value);
  129. if (d < numHeadRowsHeight.Minimum)
  130. {
  131. d = numHeadRowsHeight.Minimum;
  132. }
  133. else if (numHeadRowsHeight.Maximum < d)
  134. {
  135. d = numHeadRowsHeight.Maximum;
  136. }
  137. numHeadRowsHeight.Value = d;
  138. }
  139. }
  140. /// <summary>
  141. /// 线的颜色
  142. /// </summary>
  143. public Color LineColor
  144. {
  145. get
  146. {
  147. return lblLineColor.BackColor;
  148. }
  149. set
  150. {
  151. lblLineColor.BackColor = value;
  152. if (lblLineColor.BackColor != Color.White)
  153. {
  154. lblLineBColor.BackColor = lblLineColor.BackColor;
  155. }
  156. else
  157. {
  158. lblLineBColor.BackColor = Color.Black;
  159. }
  160. }
  161. }
  162. /// <summary>
  163. /// 背景颜色
  164. /// </summary>
  165. public Color FillColor
  166. {
  167. get
  168. {
  169. return _fillColor;
  170. }
  171. set
  172. {
  173. _fillColor = value;
  174. SetFillColor();
  175. }
  176. }
  177. /// <summary>
  178. /// 线宽
  179. /// </summary>
  180. public float LineWidth
  181. {
  182. get
  183. {
  184. return System.Convert.ToSingle(numLineWidth.Value);
  185. }
  186. set
  187. {
  188. decimal d = System.Convert.ToDecimal(value);
  189. if (d < numLineWidth.Minimum)
  190. {
  191. d = numLineWidth.Minimum;
  192. }
  193. else if (numLineWidth.Maximum < d)
  194. {
  195. d = numLineWidth.Maximum;
  196. }
  197. numLineWidth.Value = d;
  198. }
  199. }
  200. /// <summary>
  201. /// 背景是否透明
  202. /// </summary>
  203. public bool Transparent
  204. {
  205. get
  206. {
  207. return _isTransparent;
  208. }
  209. set
  210. {
  211. _isTransparent = value;
  212. SetFillColor();
  213. }
  214. }
  215. /// <summary>
  216. /// 是否显示列标题
  217. /// </summary>
  218. public bool TitleVisible
  219. {
  220. get
  221. {
  222. return cbxTitleVisible.Checked;
  223. }
  224. set
  225. {
  226. cbxTitleVisible.Checked = value;
  227. }
  228. }
  229. /// <summary>
  230. /// 是否每页都显示列标题
  231. /// </summary>
  232. public bool AlwaysTitleVisible
  233. {
  234. get
  235. {
  236. return cbxAlwaysTitleVisible.Checked;
  237. }
  238. set
  239. {
  240. cbxAlwaysTitleVisible.Checked = value;
  241. }
  242. }
  243. /// <summary>
  244. /// 行高
  245. /// </summary>
  246. public float RowsHeight
  247. {
  248. get
  249. {
  250. return System.Convert.ToSingle(numRowsHeight.Value);
  251. }
  252. set
  253. {
  254. decimal d = System.Convert.ToDecimal(value);
  255. if (d < numRowsHeight.Minimum)
  256. {
  257. d = numRowsHeight.Minimum;
  258. }
  259. else if (numRowsHeight.Maximum < d)
  260. {
  261. d = numRowsHeight.Maximum;
  262. }
  263. numRowsHeight.Value = d;
  264. }
  265. }
  266. /// <summary>
  267. /// 一页显示的行数
  268. /// </summary>
  269. public int RowsCount
  270. {
  271. get
  272. {
  273. return System.Convert.ToInt32(numRowsCount.Value);
  274. }
  275. set
  276. {
  277. decimal d = System.Convert.ToDecimal(value);
  278. if (d < numRowsCount.Minimum)
  279. {
  280. d = numRowsCount.Minimum;
  281. }
  282. else if (numRowsCount.Maximum < d)
  283. {
  284. d = numRowsCount.Maximum;
  285. }
  286. numRowsCount.Value = d;
  287. }
  288. }
  289. public GridItemColumnCollection Columns
  290. {
  291. get;
  292. set;
  293. }
  294. #endregion 属性
  295. #region 构造函数
  296. /// <summary>
  297. /// 构造函数
  298. /// </summary>
  299. public GridItemSetting()
  300. {
  301. InitializeComponent();
  302. }
  303. #endregion 构造函数
  304. #region 函数
  305. /// <summary>
  306. /// 设置背景颜色
  307. /// </summary>
  308. private void SetFillColor()
  309. {
  310. if (_isTransparent)
  311. {
  312. lblFillColor.BackColor = Color.Empty;
  313. lblFillBColor.BackColor = Color.Empty;
  314. }
  315. else
  316. {
  317. lblFillColor.BackColor = _fillColor;
  318. if (_fillColor != Color.White)
  319. {
  320. lblFillBColor.BackColor = _fillColor;
  321. }
  322. else
  323. {
  324. lblFillBColor.BackColor = Color.Black;
  325. }
  326. }
  327. }
  328. #endregion 函数
  329. #region 事件处理
  330. /// <summary>
  331. /// Shown
  332. /// </summary>
  333. /// <param name="sender">指定的对象</param>
  334. /// <param name="e">提供的事件数据</param>
  335. private void GridItemSetting_Shown(object sender, System.EventArgs e)
  336. {
  337. this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
  338. this.lisCols.DataSource = Columns;
  339. }
  340. /// <summary>
  341. /// 设置线的颜色
  342. /// </summary>
  343. /// <param name="sender">指定的对象</param>
  344. /// <param name="e">提供的事件数据</param>
  345. private void btnSelectLineColor_Click(object sender, System.EventArgs e)
  346. {
  347. colorDialog.Color = (lblLineColor.BackColor == Color.Transparent) ? Color.Empty : lblLineColor.BackColor;
  348. if (colorDialog.ShowDialog() == DialogResult.OK)
  349. {
  350. LineColor = colorDialog.Color;
  351. }
  352. }
  353. /// <summary>
  354. /// 设置背景颜色
  355. /// </summary>
  356. /// <param name="sender">指定的对象</param>
  357. /// <param name="e">提供的事件数据</param>
  358. private void btnSelectFillColor_Click(object sender, System.EventArgs e)
  359. {
  360. colorDialog.Color = _isTransparent ? Color.Empty : _fillColor;
  361. if (colorDialog.ShowDialog() == DialogResult.OK)
  362. {
  363. _fillColor = colorDialog.Color;
  364. Transparent = false;
  365. }
  366. }
  367. /// <summary>
  368. /// 设置线段是否透明
  369. /// </summary>
  370. /// <param name="sender">指定的对象</param>
  371. /// <param name="e">提供的事件数据</param>
  372. private void btnSelectLineTransparent_Click(object sender, System.EventArgs e)
  373. {
  374. lblLineColor.BackColor = Color.Transparent;
  375. lblLineBColor.BackColor = Color.Transparent;
  376. }
  377. /// <summary>
  378. /// 设置背景是否透明
  379. /// </summary>
  380. /// <param name="sender">指定的对象</param>
  381. /// <param name="e">提供的事件数据</param>
  382. private void btnFillTransparent_Click(object sender, System.EventArgs e)
  383. {
  384. Transparent = true;
  385. }
  386. #region 表格列编辑
  387. /// <summary>
  388. /// 上移列
  389. /// </summary>
  390. /// <param name="sender"></param>
  391. /// <param name="e"></param>
  392. private void btnColUp_Click(object sender, System.EventArgs e)
  393. {
  394. if (lisCols.SelectedIndex < 1)
  395. {
  396. return;
  397. }
  398. int index = lisCols.SelectedIndex - 1;
  399. GridItemColumn gic = (lisCols.SelectedItem as GridItemColumn);
  400. gic.DisplayIndexInternal = index;
  401. gic = (lisCols.Items[index] as GridItemColumn);
  402. gic.DisplayIndexInternal = lisCols.SelectedIndex;
  403. Columns.UpdateColumnsOrder();
  404. lisCols.DataSource = null;
  405. this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
  406. this.lisCols.DataSource = Columns;
  407. lisCols.SelectedIndex = index;
  408. _isColChanged = true;
  409. }
  410. /// <summary>
  411. /// 下移列
  412. /// </summary>
  413. /// <param name="sender"></param>
  414. /// <param name="e"></param>
  415. private void btnColDown_Click(object sender, System.EventArgs e)
  416. {
  417. if (lisCols.SelectedIndex < 0 || lisCols.SelectedIndex == Columns.Count - 1)
  418. {
  419. return;
  420. }
  421. int index = lisCols.SelectedIndex + 1;
  422. GridItemColumn gic = (lisCols.SelectedItem as GridItemColumn);
  423. gic.DisplayIndexInternal = index;
  424. gic = (lisCols.Items[index] as GridItemColumn);
  425. gic.DisplayIndexInternal = lisCols.SelectedIndex;
  426. Columns.UpdateColumnsOrder();
  427. lisCols.DataSource = null;
  428. this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
  429. this.lisCols.DataSource = Columns;
  430. lisCols.SelectedIndex = index;
  431. _isColChanged = true;
  432. }
  433. /// <summary>
  434. /// 编辑列
  435. /// </summary>
  436. /// <param name="sender"></param>
  437. /// <param name="e"></param>
  438. private void btnColEdit_Click(object sender, System.EventArgs e)
  439. {
  440. if (lisCols.SelectedIndex < 0)
  441. {
  442. return;
  443. }
  444. int index = lisCols.SelectedIndex;
  445. GridItemColumn gic = (lisCols.SelectedItem as GridItemColumn);
  446. using (GridItemColumnSetting itemPropertySetting = new GridItemColumnSetting())
  447. {
  448. itemPropertySetting.IsNew = false;
  449. itemPropertySetting.TextWidth = gic.Width;
  450. itemPropertySetting.Culture = gic.Culture;
  451. itemPropertySetting.LineSpaceHead = gic.LineSpaceHead;
  452. itemPropertySetting.CharacterSpaceHead = gic.CharacterSpaceHead;
  453. itemPropertySetting.CharacterCountHead = gic.CharacterCountHead;
  454. itemPropertySetting.TextAlignHead = gic.TextAlignHead;
  455. itemPropertySetting.TextAlignVerticalHead = gic.TextAlignVerticalHead;
  456. itemPropertySetting.TextColorHead = gic.TextColorHead;
  457. itemPropertySetting.TextFontHead = gic.FontHead;
  458. itemPropertySetting.WrapHead = gic.WrapHead;
  459. itemPropertySetting.LineSpace = gic.LineSpace;
  460. itemPropertySetting.CharacterSpace = gic.CharacterSpace;
  461. itemPropertySetting.CharacterCount = gic.CharacterCount;
  462. itemPropertySetting.TextAlign = gic.TextAlign;
  463. itemPropertySetting.TextAlignVertical = gic.TextAlignVertical;
  464. itemPropertySetting.TextPreview = gic.DisplayValue;
  465. itemPropertySetting.TextColor = gic.TextColor;
  466. itemPropertySetting.ItemStyle = gic.ItemStyle;
  467. itemPropertySetting.ColName = gic.Name;
  468. itemPropertySetting.HeaderText = gic.HeaderText;
  469. itemPropertySetting.TextFormat = gic.Format;
  470. itemPropertySetting.TextFont = gic.Font;
  471. itemPropertySetting.Wrap = gic.Wrap;
  472. itemPropertySetting.DefaultValue = gic.DefaultValue;
  473. itemPropertySetting.IsDataBinding = gic.IsDataBinding;
  474. itemPropertySetting.chkFixedRatio.Checked = gic.FixedRatio;
  475. itemPropertySetting.chkM.Checked = gic.PicMargin;
  476. itemPropertySetting.chkPic.Checked = gic.PicColumn;
  477. itemPropertySetting.chkFixedRatio.Enabled = gic.PicColumn;
  478. itemPropertySetting.chkM.Enabled = gic.PicColumn;
  479. DialogResult result = itemPropertySetting.ShowDialog();
  480. if (result == DialogResult.OK)
  481. {
  482. gic.Width = itemPropertySetting.TextWidth;
  483. gic.LineSpaceHead = itemPropertySetting.LineSpaceHead;
  484. gic.CharacterSpaceHead = itemPropertySetting.CharacterSpaceHead;
  485. gic.CharacterCountHead = itemPropertySetting.CharacterCountHead;
  486. gic.TextAlignHead = itemPropertySetting.TextAlignHead;
  487. gic.TextAlignVerticalHead = itemPropertySetting.TextAlignVerticalHead;
  488. gic.TextColorHead = itemPropertySetting.TextColorHead;
  489. gic.FontHead = itemPropertySetting.TextFontHead;
  490. gic.WrapHead = itemPropertySetting.WrapHead;
  491. gic.LineSpace = itemPropertySetting.LineSpace;
  492. gic.CharacterSpace = itemPropertySetting.CharacterSpace;
  493. gic.CharacterCount = itemPropertySetting.CharacterCount;
  494. gic.Font = itemPropertySetting.TextFont;
  495. gic.Wrap = itemPropertySetting.Wrap;
  496. gic.TextAlign = itemPropertySetting.TextAlign;
  497. gic.TextAlignVertical = itemPropertySetting.TextAlignVertical;
  498. gic.TextColor = itemPropertySetting.TextColor;
  499. gic.DisplayValue = itemPropertySetting.TextPreview;
  500. gic.ItemStyle = itemPropertySetting.ItemStyle;
  501. gic.Name = itemPropertySetting.ColName;
  502. gic.HeaderText = itemPropertySetting.HeaderText;
  503. gic.Format = itemPropertySetting.TextFormat;
  504. gic.Culture = itemPropertySetting.Culture;
  505. gic.DefaultValue = itemPropertySetting.DefaultValue;
  506. gic.FixedRatio = itemPropertySetting.chkFixedRatio.Checked;
  507. gic.PicMargin = itemPropertySetting.chkM.Checked;
  508. gic.PicColumn = itemPropertySetting.chkPic.Checked;
  509. lisCols.DataSource = null;
  510. this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
  511. this.lisCols.DataSource = Columns;
  512. lisCols.SelectedIndex = index;
  513. _isColChanged = true;
  514. }
  515. }
  516. }
  517. /// <summary>
  518. /// 添加列
  519. /// </summary>
  520. /// <param name="sender"></param>
  521. /// <param name="e"></param>
  522. private void btnColAdd_Click(object sender, System.EventArgs e)
  523. {
  524. // 生成列名
  525. string colName = Columns.GeNewColumnName();
  526. Columns.Add(colName, colName);
  527. lisCols.DataSource = null;
  528. this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
  529. this.lisCols.DataSource = Columns;
  530. lisCols.SelectedIndex = lisCols.Items.Count - 1;
  531. _isColChanged = true;
  532. }
  533. /// <summary>
  534. /// 移除列
  535. /// </summary>
  536. /// <param name="sender"></param>
  537. /// <param name="e"></param>
  538. private void btnColRemove_Click(object sender, System.EventArgs e)
  539. {
  540. if (lisCols.SelectedIndex < 0)
  541. {
  542. return;
  543. }
  544. int index = lisCols.SelectedIndex;
  545. lisCols.SelectedIndex = (index < Columns.Count - 1) ? index : index - 1;
  546. Columns.RemoveAtInternal(index, false);
  547. lisCols.DataSource = null;
  548. this.lisCols.DisplayMember = GridItemColumnCollection.DisplayMember;
  549. this.lisCols.DataSource = Columns;
  550. lisCols.SelectedIndex = (index < Columns.Count) ? index : index - 1;
  551. _isColChanged = true;
  552. }
  553. #endregion 表格列编辑
  554. private void cbxTitleVisible_CheckedChanged(object sender, System.EventArgs e)
  555. {
  556. cbxAlwaysTitleVisible.Enabled = cbxTitleVisible.Checked;
  557. }
  558. #endregion 事件处理
  559. }
  560. }