DateYearMonth.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary
  10. {
  11. public partial class DateYearMonth : UserControl
  12. {
  13. LYFZ.ComponentLibrary.ButtonDownArrow btnDown = new ButtonDownArrow();
  14. public DateYearMonth()
  15. {
  16. InitializeComponent();
  17. this.Load += DateYearMonth_Load;
  18. this.Leave += DateYearMonth_Leave;
  19. this.tblPanelMonth.Leave += tblPanelMonth_Leave;
  20. this.tblPanelYear.Leave += tblPanelYear_Leave;
  21. this.lblUp.Click += lblUp_Click;
  22. this.lblNext.Click += lblNext_Click;
  23. this.lblYear.Click += lblYear_Click;
  24. this.txtYearMonthValue.KeyDown += txtYearMonthValue_KeyDown;
  25. this.txtYearMonthValue.Leave += txtYearMonthValue_Leave;
  26. this.lblToYear.Click += panelToyear_Click;
  27. this.panellblToYear.Click += panelToyear_Click;
  28. this.panellblToYear.MouseEnter += lblToYear_MouseEnter;
  29. this.panellblToYear.MouseLeave += lblToYear_MouseLeave;
  30. this.lblToYear.MouseEnter += lblToYear_MouseEnter;
  31. this.lblToYear.MouseLeave += lblToYear_MouseLeave;
  32. this.lblYear.MouseEnter += lblYear_MouseEnter;
  33. this.lblYear.MouseLeave += lblYear_MouseLeave;
  34. btnDown.Size = new Size(18, this.txtYearMonthValue.Height - 2);
  35. btnDown.Dock = DockStyle.Right;
  36. btnDown.IsDown = true;
  37. btnDown.Click += btnDown_Click;
  38. this.txtYearMonthValue.Controls.Add(btnDown);
  39. this.SetHeight();
  40. }
  41. private string _strdatevalue;
  42. /// <summary>
  43. /// 设置或获取值
  44. /// </summary>
  45. public string StrDateValue
  46. {
  47. get
  48. {
  49. if (this.txtYearMonthValue.Text.Trim() != "-")
  50. { return this.txtYearMonthValue.Text.Trim(); }
  51. else
  52. { return ""; }
  53. }
  54. set
  55. {
  56. _strdatevalue = value;
  57. if (_strdatevalue != "")
  58. {
  59. this.DetectedDate(_strdatevalue);
  60. this.txtYearMonthValue.Text = this.CurrentYear + "-" + this.GetBeforeAddZero(this.CurrentMonth, 2);
  61. }
  62. }
  63. }
  64. /// <summary>
  65. /// 获取年
  66. /// </summary>
  67. public int StrYear
  68. { get { return this.CurrentYear; } }
  69. /// <summary>
  70. /// 获取月
  71. /// </summary>
  72. public int StrMonth
  73. { get { return this.CurrentMonth; } }
  74. private bool _isReadOnly;
  75. /// <summary>
  76. /// 是否只读
  77. /// </summary>
  78. public bool IsReadOnly
  79. {
  80. get { return _isReadOnly; }
  81. set
  82. {
  83. _isReadOnly = value;
  84. this.txtYearMonthValue.ReadOnly = _isReadOnly;
  85. }
  86. }
  87. /// <summary>
  88. /// 当前选择的年份
  89. /// </summary>
  90. int CurrentYear = 0;
  91. /// <summary>
  92. /// 当年选择的月份
  93. /// </summary>
  94. int CurrentMonth = 1;
  95. EnumType CurrentType;
  96. /// <summary>
  97. /// 当前选择类型
  98. /// </summary>
  99. enum EnumType
  100. {
  101. /// <summary>
  102. /// 月选择器
  103. /// </summary>
  104. enumMonth,
  105. /// <summary>
  106. /// 年选择器
  107. /// </summary>
  108. enumYear
  109. }
  110. public delegate void DateYearMonth_ClickChengedValue(string SelectValue);
  111. /// <summary>
  112. /// 选择Value值更改事件
  113. /// </summary>
  114. [Category("控件扩展事件"), Description("删除客户")]
  115. public event DateYearMonth_ClickChengedValue ClickChengedValue;
  116. public delegate void DateYearMonth_KeyDown();
  117. /// <summary>
  118. /// 窗体的KeyDown
  119. /// </summary>
  120. [Category("控件扩展事件"), Description("删除客户")]
  121. public new event DateYearMonth_KeyDown KeyDown;
  122. /// <summary>
  123. /// 窗体加载事件
  124. /// </summary>
  125. /// <param name="sender"></param>
  126. /// <param name="e"></param>
  127. void DateYearMonth_Load(object sender, EventArgs e)
  128. {
  129. if (this.CurrentYear == 0)
  130. { this.CurrentYear = SDateTime.Now.Year; }
  131. if (this.CurrentMonth == 0)
  132. { this.CurrentYear = SDateTime.Now.Month; }
  133. this.PaintingCharts_Month();
  134. this.CurrentType = EnumType.enumMonth;
  135. this.panellblToYear.BorderStyle = BorderStyle.FixedSingle;
  136. this.panellblToYear.BorderColor = this.GetColor(ColorType.当前年移过字体);
  137. this.lblToYear.Text = "当前年月:" + SDateTime.Now.Year + "-" + this.GetBeforeAddZero(SDateTime.Now.Month, 2);
  138. this.ParentForm.Click += ParentForm_Click;
  139. foreach (Control cont in this.ParentForm.Controls)
  140. {
  141. if (!(cont is DateYearMonth))
  142. { cont.Click += DateYearMonth_Click; }
  143. }
  144. }
  145. /// <summary>
  146. /// 父窗体的点击事件隐藏控件
  147. /// </summary>
  148. /// <param name="sender"></param>
  149. /// <param name="e"></param>
  150. void ParentForm_Click(object sender, EventArgs e)
  151. { this.DateYearMonth_Click(this, null); }
  152. /// <summary>
  153. /// 父窗体的控件的点击事件隐藏控件
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. void DateYearMonth_Click(object sender, EventArgs e)
  158. { this.SetHeight(); }
  159. /// <summary>
  160. /// 数据处理_月
  161. /// </summary>
  162. private void PaintingCharts_Month()
  163. {
  164. Panel panel = null;
  165. Label lable = null;
  166. this.lblYear.Location = new Point(88, this.lblYear.Location.Y);
  167. this.lblYear.Text = this.CurrentYear.ToString();
  168. int YearMonthCount = 1;
  169. for (int i = 0; i < this.tblPanelMonth.RowCount; i++)
  170. {
  171. for (int j = 0; j < this.tblPanelMonth.ColumnCount; j++)
  172. {
  173. #region 每日板块
  174. panel = new Panel();
  175. if (YearMonthCount == CurrentMonth)
  176. { panel.BackColor = this.GetColor(ColorType.选中); }
  177. else
  178. { panel.BackColor = this.GetColor(ColorType.默认); }
  179. panel.Margin = new System.Windows.Forms.Padding(1, 1, 1, 1);
  180. panel.Name = "panel_" + YearMonthCount;
  181. panel.Tag = YearMonthCount;
  182. panel.Dock = DockStyle.Fill;
  183. panel.Click += panel_Click;
  184. panel.MouseEnter += panel_MouseEnter;
  185. panel.MouseLeave += panel_MouseLeave;
  186. //每日
  187. lable = new Label();
  188. lable.Name = "lblMonth" + YearMonthCount;
  189. lable.Font = new System.Drawing.Font("微软雅黑", 9);
  190. lable.ForeColor = this.GetColor(ColorType.字体);
  191. lable.AutoSize = false;
  192. lable.Size = new System.Drawing.Size(50, 20);
  193. lable.Text = GetMonth(YearMonthCount.ToString());
  194. lable.Tag = YearMonthCount;
  195. int Location_X = 10;
  196. if (YearMonthCount > 10)
  197. { Location_X -= 6; }
  198. lable.Location = new Point(Location_X, 12);
  199. lable.Click += lable_Click;
  200. lable.MouseEnter += lable_MouseEnter;
  201. lable.MouseLeave += lable_MouseLeave;
  202. panel.Controls.Add(lable);
  203. #endregion
  204. this.tblPanelMonth.Controls.Add(panel);
  205. YearMonthCount++;
  206. }
  207. }
  208. this.panelMonth.BringToFront();
  209. }
  210. /// <summary>
  211. /// 返回当月
  212. /// </summary>
  213. /// <param name="StrMonth"></param>
  214. /// <returns></returns>
  215. string GetMonth(string StrMonth)
  216. {
  217. switch (StrMonth.Trim())
  218. {
  219. case "1": StrMonth = "一月"; break;
  220. case "2": StrMonth = "二月"; break;
  221. case "3": StrMonth = "三月"; break;
  222. case "4": StrMonth = "四月"; break;
  223. case "5": StrMonth = "五月"; break;
  224. case "6": StrMonth = "六月"; break;
  225. case "7": StrMonth = "七月"; break;
  226. case "8": StrMonth = "八月"; break;
  227. case "9": StrMonth = "九月"; break;
  228. case "10": StrMonth = "十月"; break;
  229. case "11": StrMonth = "十一月"; break;
  230. case "12": StrMonth = "十二月"; break;
  231. }
  232. return StrMonth;
  233. }
  234. /// <summary>
  235. /// 年点击事件
  236. /// </summary>
  237. /// <param name="sender"></param>
  238. /// <param name="e"></param>
  239. void lblYear_Click(object sender, EventArgs e)
  240. {
  241. switch (this.CurrentType)
  242. {
  243. case EnumType.enumMonth:
  244. this.CurrentType = EnumType.enumYear;
  245. this.CurrentYear = Convert.ToInt32(this.lblYear.Text);
  246. this.CleartblPanelYearControls();
  247. break;
  248. case EnumType.enumYear:
  249. break;
  250. }
  251. }
  252. /// <summary>
  253. /// 上一年
  254. /// </summary>
  255. /// <param name="sender"></param>
  256. /// <param name="e"></param>
  257. void lblUp_Click(object sender, EventArgs e)
  258. {
  259. switch (this.CurrentType)
  260. {
  261. case EnumType.enumMonth:
  262. this.CurrentYear = Convert.ToInt32(this.lblYear.Text) - 1;
  263. this.CleartblPanelMonthControls();
  264. break;
  265. case EnumType.enumYear:
  266. this.CurrentYear = Convert.ToInt32(this.lblYear.Text.Trim().Split('-')[0]) - 12;
  267. this.CleartblPanelYearControls();
  268. break;
  269. }
  270. }
  271. /// <summary>
  272. /// 下一年
  273. /// </summary>
  274. /// <param name="sender"></param>
  275. /// <param name="e"></param>
  276. void lblNext_Click(object sender, EventArgs e)
  277. {
  278. switch (this.CurrentType)
  279. {
  280. case EnumType.enumMonth:
  281. this.CurrentYear = Convert.ToInt32(this.lblYear.Text) + 1;
  282. this.CleartblPanelMonthControls();
  283. break;
  284. case EnumType.enumYear:
  285. this.CurrentYear = Convert.ToInt32(this.lblYear.Text.Trim().Split('-')[0]) + 12;
  286. this.CleartblPanelYearControls();
  287. break;
  288. }
  289. }
  290. /// <summary>
  291. /// 清空月份选择器
  292. /// </summary>
  293. void CleartblPanelMonthControls()
  294. {
  295. this.tblPanelMonth.Controls.Clear();
  296. this.PaintingCharts_Month();
  297. }
  298. /// <summary>
  299. /// 清空年份选择器
  300. /// </summary>
  301. void CleartblPanelYearControls()
  302. {
  303. this.tblPanelYear.Controls.Clear();
  304. this.PaintingCharts_Year();
  305. }
  306. /// <summary>
  307. /// 数据处理_年
  308. /// </summary>
  309. private void PaintingCharts_Year()
  310. {
  311. Panel panel = null;
  312. Label lable = null;
  313. this.panelYear.Location = this.panelMonth.Location;
  314. this.lblYear.Text = this.CurrentYear + "-" + (this.CurrentYear + 11);
  315. this.lblYear.Location = new Point(73, this.lblYear.Location.Y);
  316. int ForInt = 0; ;
  317. for (int i = 0; i < this.tblPanelYear.RowCount; i++)
  318. {
  319. for (int j = 0; j < this.tblPanelYear.ColumnCount; j++)
  320. {
  321. #region 每日板块
  322. panel = new Panel();
  323. if (this.CurrentYear == this.CurrentYear + ForInt)
  324. { panel.BackColor = this.GetColor(ColorType.选中); }
  325. else
  326. { panel.BackColor = this.GetColor(ColorType.默认); }
  327. panel.Margin = new System.Windows.Forms.Padding(1, 1, 1, 1);
  328. panel.Name = "panel_" + this.CurrentYear + ForInt;
  329. panel.Tag = this.CurrentYear + ForInt;
  330. panel.Dock = DockStyle.Fill;
  331. panel.MouseEnter += panel_MouseEnter;
  332. panel.MouseLeave += panel_MouseLeave;
  333. panel.Click += panel_Click;
  334. //每日
  335. lable = new Label();
  336. lable.Name = "lblYear" + this.CurrentYear + ForInt;
  337. lable.Font = new System.Drawing.Font("微软雅黑", 9);
  338. lable.ForeColor = this.GetColor(ColorType.字体);
  339. lable.AutoSize = false;
  340. lable.Size = new System.Drawing.Size(50, 20);
  341. lable.Text = (this.CurrentYear + ForInt).ToString();
  342. lable.Tag = this.CurrentYear + ForInt;
  343. lable.Location = new Point(8, 12);
  344. lable.MouseEnter += lable_MouseEnter;
  345. lable.MouseLeave += lable_MouseLeave;
  346. lable.Click += lable_Click;
  347. panel.Controls.Add(lable);
  348. #endregion
  349. this.tblPanelYear.Controls.Add(panel);
  350. ForInt++;
  351. }
  352. }
  353. this.panelYear.BringToFront();
  354. }
  355. /// <summary>
  356. /// lbl光标离开事件
  357. /// </summary>
  358. /// <param name="sender"></param>
  359. /// <param name="e"></param>
  360. void lable_MouseLeave(object sender, EventArgs e)
  361. {
  362. Label lbl = sender as Label;
  363. switch (this.CurrentType)
  364. {
  365. case EnumType.enumMonth:
  366. if (Convert.ToInt32(lbl.Tag) == this.CurrentMonth)
  367. { lbl.Parent.BackColor = this.GetColor(ColorType.选中); }
  368. else
  369. { lbl.Parent.BackColor = this.GetColor(ColorType.默认); }
  370. break;
  371. case EnumType.enumYear:
  372. if (Convert.ToInt32(lbl.Tag) == this.CurrentYear)
  373. { lbl.Parent.BackColor = this.GetColor(ColorType.选中); }
  374. else
  375. { lbl.Parent.BackColor = this.GetColor(ColorType.默认); }
  376. break;
  377. }
  378. }
  379. /// <summary>
  380. /// lbl光标进入事件
  381. /// </summary>
  382. /// <param name="sender"></param>
  383. /// <param name="e"></param>
  384. void lable_MouseEnter(object sender, EventArgs e)
  385. {
  386. Label lbl = sender as Label;
  387. lbl.Parent.BackColor = this.GetColor(ColorType.移过);
  388. }
  389. /// <summary>
  390. /// 层光标离开事件
  391. /// </summary>
  392. /// <param name="sender"></param>
  393. /// <param name="e"></param>
  394. void panel_MouseLeave(object sender, EventArgs e)
  395. {
  396. Panel panel = sender as Panel;
  397. switch (this.CurrentType)
  398. {
  399. case EnumType.enumMonth:
  400. if (Convert.ToInt32(panel.Tag) == this.CurrentMonth)
  401. { panel.BackColor = this.GetColor(ColorType.选中); }
  402. else
  403. { panel.BackColor = this.GetColor(ColorType.默认); }
  404. break;
  405. case EnumType.enumYear:
  406. if (Convert.ToInt32(panel.Tag) == this.CurrentYear)
  407. { panel.BackColor = this.GetColor(ColorType.选中); }
  408. else
  409. { panel.BackColor = this.GetColor(ColorType.默认); }
  410. break;
  411. }
  412. }
  413. /// <summary>
  414. /// 层光标进入事件
  415. /// </summary>
  416. /// <param name="sender"></param>
  417. /// <param name="e"></param>
  418. void panel_MouseEnter(object sender, EventArgs e)
  419. {
  420. Panel panel = sender as Panel;
  421. panel.BackColor = this.GetColor(ColorType.移过);
  422. }
  423. /// <summary>
  424. /// 当前年光标进入事件
  425. /// </summary>
  426. /// <param name="sender"></param>
  427. /// <param name="e"></param>
  428. void lblToYear_MouseEnter(object sender, EventArgs e)
  429. {
  430. this.lblToYear.ForeColor = this.GetColor(ColorType.当前年移过字体);
  431. }
  432. /// <summary>
  433. /// 当前年光标离开事件
  434. /// </summary>
  435. /// <param name="sender"></param>
  436. /// <param name="e"></param>
  437. void lblToYear_MouseLeave(object sender, EventArgs e)
  438. {
  439. this.lblToYear.ForeColor = this.GetColor(ColorType.当前年离开字体);
  440. }
  441. /// <summary>
  442. /// 当前提示选择的年月提示光标进入事件
  443. /// </summary>
  444. /// <param name="sender"></param>
  445. /// <param name="e"></param>
  446. void lblYear_MouseEnter(object sender, EventArgs e)
  447. {
  448. this.lblYear.ForeColor = this.GetColor(ColorType.当前年移过字体);
  449. }
  450. /// <summary>
  451. /// 当前提示选择的年月提示光标离开事件
  452. /// </summary>
  453. /// <param name="sender"></param>
  454. /// <param name="e"></param>
  455. void lblYear_MouseLeave(object sender, EventArgs e)
  456. {
  457. this.lblYear.ForeColor = this.GetColor(ColorType.当前年离开字体);
  458. }
  459. /// <summary>
  460. /// 选择年月
  461. /// </summary>
  462. /// <param name="sender"></param>
  463. /// <param name="e"></param>
  464. void lable_Click(object sender, EventArgs e)
  465. { this.SelectCurrentYearMonth(sender, false); }
  466. /// <summary>
  467. /// 选择年月
  468. /// </summary>
  469. /// <param name="sender"></param>
  470. /// <param name="e"></param>
  471. private void panel_Click(object sender, EventArgs e)
  472. { this.SelectCurrentYearMonth(sender, true); }
  473. /// <summary>
  474. /// 选择当前年月
  475. /// </summary>
  476. /// <param name="objControls"></param>
  477. /// <param name="IsPanel"></param>
  478. void SelectCurrentYearMonth(object objControls, bool IsPanel)
  479. {
  480. switch (this.CurrentType)
  481. {
  482. case EnumType.enumMonth:
  483. for (int i = 0; i < 12; i++)
  484. {
  485. Panel newpanel = (Panel)tblPanelMonth.Controls[i];
  486. if (newpanel != null)
  487. { newpanel.BackColor = this.GetColor(ColorType.默认); }
  488. }
  489. if (IsPanel)
  490. {
  491. Panel panelA = objControls as Panel;
  492. if (panelA != null)
  493. {
  494. this.txtYearMonthValue.Text = this.lblYear.Text.Trim() + "-" + this.GetBeforeAddZero(Convert.ToInt32(panelA.Tag), 2);
  495. this.CurrentYear = Convert.ToInt32(this.lblYear.Text);
  496. this.CurrentMonth = Convert.ToInt32(panelA.Tag);
  497. }
  498. }
  499. else
  500. {
  501. Label lbl = objControls as Label;
  502. if (lbl != null)
  503. {
  504. this.txtYearMonthValue.Text = this.lblYear.Text.Trim() + "-" + this.GetBeforeAddZero(Convert.ToInt32(lbl.Tag), 2);
  505. this.CurrentYear = Convert.ToInt32(this.lblYear.Text);
  506. this.CurrentMonth = Convert.ToInt32(lbl.Tag);
  507. }
  508. }
  509. this.btnDown.IsDown = true;
  510. this.SetHeight();
  511. this.NewClickChengedValue();
  512. break;
  513. case EnumType.enumYear:
  514. if (IsPanel)
  515. {
  516. Panel panel = objControls as Panel;
  517. if (panel != null)
  518. { this.CurrentYear = Convert.ToInt32(panel.Tag); }
  519. }
  520. else
  521. {
  522. Label lbl = objControls as Label;
  523. if (lbl != null)
  524. { this.CurrentYear = Convert.ToInt32(lbl.Tag); }
  525. }
  526. this.CleartblPanelMonthControls();
  527. this.CurrentType = EnumType.enumMonth;
  528. break;
  529. }
  530. }
  531. /// <summary>
  532. /// 选择今年
  533. /// </summary>
  534. /// <param name="sender"></param>
  535. /// <param name="e"></param>
  536. void panelToyear_Click(object sender, EventArgs e)
  537. {
  538. this.CurrentYear = SDateTime.Now.Year;
  539. this.CurrentMonth = SDateTime.Now.Month;
  540. this.txtYearMonthValue.Text = this.CurrentYear + "" + this.GetBeforeAddZero(this.CurrentMonth, 2);
  541. this.btnDown.IsDown = true;
  542. this.SetHeight();
  543. this.NewClickChengedValue();
  544. }
  545. /// <summary>
  546. /// 选择值后的事件
  547. /// </summary>
  548. void NewClickChengedValue()
  549. {
  550. if (this.ClickChengedValue != null)
  551. { this.ClickChengedValue(this.StrDateValue); }
  552. }
  553. /// <summary>
  554. /// 点击展开
  555. /// </summary>
  556. /// <param name="sender"></param>
  557. /// <param name="e"></param>
  558. void btnDown_Click(object sender, EventArgs e)
  559. {
  560. this.btnDown.Parent.Parent.Anchor = AnchorStyles.Left | AnchorStyles.Top;
  561. if (this.Height > 25)
  562. {
  563. this.btnDown.IsDown = true;
  564. this.SetHeight();
  565. this.txtYearMonthValue.Focus();
  566. }
  567. else
  568. {
  569. this.btnDown.IsDown = false;
  570. if (this.panelYearMonthValue.Width < 216)
  571. { this.Size = new Size(216, 202); }
  572. else
  573. { this.Size = new Size(this.panelYearMonthValue.Width, 202); }
  574. int YearLog = this.CurrentYear;
  575. if (this.txtYearMonthValue.Text.Trim() != "-")
  576. {
  577. this.DetectedDate(this.txtYearMonthValue.Text.Trim());
  578. for (int i = 0; i < 12; i++)
  579. {
  580. Panel newpanel = (Panel)tblPanelMonth.Controls[i];
  581. if (newpanel != null)
  582. {
  583. if (Convert.ToInt32(newpanel.Tag) == this.CurrentMonth)
  584. { newpanel.BackColor = this.GetColor(ColorType.选中); }
  585. else
  586. { newpanel.BackColor = this.GetColor(ColorType.默认); }
  587. }
  588. }
  589. }
  590. else
  591. {
  592. this.CurrentYear = SDateTime.Now.Year;
  593. this.CurrentMonth = SDateTime.Now.Month;
  594. }
  595. if (YearLog != this.CurrentYear)
  596. {
  597. this.tblPanelMonth.Controls.Clear();
  598. this.PaintingCharts_Month();
  599. }
  600. this.panelMonth.BringToFront();
  601. this.BringToFront();
  602. this.Focus();
  603. }
  604. }
  605. /// <summary>
  606. /// 输入时隐藏控件
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. void txtYearMonthValue_KeyDown(object sender, KeyEventArgs e)
  611. {
  612. this.SetHeight();
  613. if (e.KeyCode == Keys.Enter)
  614. {
  615. if (this.KeyDown != null)
  616. {
  617. //string StrYearDate = LYFZ.Command.Command_Validate.DateTimeToString(this.StrYear + "-01" + "-01");
  618. //if (string.IsNullOrEmpty(StrYearDate))
  619. //{
  620. // MessageBoxCustom.Show("年份输入不在有效范围!");
  621. // this.txtYearMonthValue.Text = StrYearDate;
  622. // return;
  623. //}
  624. //if (string.IsNullOrEmpty(this.StrMonth.ToString().Trim()))
  625. //{ return; }
  626. //string StrTime = LYFZ.Command.Command_Validate.DateTimeToString(this.StrDateValue + "-01");
  627. //if (string.IsNullOrEmpty(StrTime))
  628. //{
  629. // MessageBoxCustom.Show("月份输入不在有效范围,有效范围在1到12月!");
  630. // this.txtYearMonthValue.Text = SDateTime.Now.ToString("yyyy-MM");
  631. // return;
  632. //}
  633. this.KeyDown();
  634. }
  635. }
  636. }
  637. /// <summary>
  638. /// 输入后离开事件
  639. /// </summary>
  640. /// <param name="sender"></param>
  641. /// <param name="e"></param>
  642. void txtYearMonthValue_Leave(object sender, EventArgs e)
  643. {
  644. if (!string.IsNullOrEmpty(this.StrDateValue.Trim()))
  645. {
  646. //string StrYearDate = LYFZ.Command.Command_Validate.DateTimeToString(this.StrYear + "-01" + "-01");
  647. //if (string.IsNullOrEmpty(StrYearDate))
  648. //{
  649. // MessageBoxCustom.Show("年份输入不在有效范围!");
  650. // this.txtYearMonthValue.Text = StrYearDate;
  651. // return;
  652. //}
  653. //if (string.IsNullOrEmpty(this.StrMonth.ToString().Trim()))
  654. //{ return; }
  655. //string StrTime = LYFZ.Command.Command_Validate.DateTimeToString(this.StrDateValue + "-01");
  656. //if (string.IsNullOrEmpty(StrTime))
  657. //{
  658. // MessageBoxCustom.Show("月份输入不在有效范围,有效范围在1到12月!");
  659. // this.txtYearMonthValue.Text = "";
  660. // return;
  661. //}
  662. }
  663. }
  664. /// <summary>
  665. /// 离开事件隐藏控件
  666. /// </summary>
  667. /// <param name="sender"></param>
  668. /// <param name="e"></param>
  669. void tblPanelYear_Leave(object sender, EventArgs e)
  670. { this.SetHeight(); }
  671. /// <summary>
  672. /// 离开事件隐藏控件
  673. /// </summary>
  674. /// <param name="sender"></param>
  675. /// <param name="e"></param>
  676. void tblPanelMonth_Leave(object sender, EventArgs e)
  677. { this.SetHeight(); }
  678. /// <summary>
  679. /// 离开事件隐藏控件
  680. /// </summary>
  681. /// <param name="sender"></param>
  682. /// <param name="e"></param>
  683. void DateYearMonth_Leave(object sender, EventArgs e)
  684. { this.SetHeight(); }
  685. /// <summary>
  686. /// 设置当前高
  687. /// </summary>
  688. void SetHeight()
  689. { this.Size = new Size(this.panelYearMonthValue.Width, 25); }
  690. /// <summary>
  691. /// 在值的前面用O补充
  692. /// </summary>
  693. /// <param name="Value">要操作的值</param>
  694. /// <param name="ValueLength">值要达到的长度</param>
  695. /// <returns></returns>
  696. string GetBeforeAddZero(int Value, int ValueLength)
  697. {
  698. string StrValue = Value.ToString().Trim();
  699. while (StrValue.Length < ValueLength)
  700. { StrValue = "0" + StrValue; }
  701. return StrValue;
  702. }
  703. /// <summary>
  704. /// 检测日期
  705. /// </summary>
  706. void DetectedDate(string DateValue)
  707. {
  708. string[] YearMonth = DateValue.Trim().Split('-');
  709. string StrYear = YearMonth[0];
  710. string StrMonth = YearMonth[1];
  711. if (StrYear.Trim().Length == 4)
  712. {
  713. int intYear = Convert.ToInt32(StrYear);
  714. if (intYear < 1753)
  715. {
  716. this.CurrentYear = 1753;
  717. this.txtYearMonthValue.Text = this.CurrentYear + "" + StrMonth;
  718. }
  719. else
  720. { this.CurrentYear = intYear; }
  721. }
  722. else
  723. { this.CurrentYear = SDateTime.Now.Year; }
  724. if (StrMonth.Trim().Length > 0)
  725. {
  726. int intMonth = Convert.ToInt32(StrMonth);
  727. if (intMonth > 12)
  728. {
  729. this.CurrentMonth = 12;
  730. this.txtYearMonthValue.Text = this.CurrentYear + "" + this.CurrentMonth;
  731. }
  732. else if (intMonth <= 0)
  733. {
  734. this.CurrentMonth = 1;
  735. this.txtYearMonthValue.Text = this.CurrentYear + "" + this.CurrentMonth;
  736. }
  737. else
  738. { this.CurrentMonth = intMonth; }
  739. }
  740. else
  741. { this.CurrentMonth = SDateTime.Now.Month; }
  742. }
  743. /// <summary>
  744. /// 获取颜色
  745. /// </summary>
  746. /// <param name="CurrentColorType"></param>
  747. /// <returns></returns>
  748. Color GetColor(ColorType CurrentColorType)
  749. {
  750. switch (CurrentColorType)
  751. {
  752. case ColorType.选中:
  753. return Color.LightPink;
  754. case ColorType.移过:
  755. return Color.SkyBlue;
  756. case ColorType.字体:
  757. return Color.White;
  758. case ColorType.当前年移过字体:
  759. return Color.Blue;
  760. case ColorType.当前年离开字体:
  761. return Color.Black;
  762. default:
  763. return Color.Gainsboro;
  764. }
  765. }
  766. /// <summary>
  767. /// 颜色枚举
  768. /// </summary>
  769. enum ColorType
  770. {
  771. 默认,
  772. 选中,
  773. 移过,
  774. 字体,
  775. 当前年移过字体,
  776. 当前年离开字体,
  777. }
  778. }
  779. }