123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.ComponentLibrary
- {
- public partial class DateYearMonth : UserControl
- {
- LYFZ.ComponentLibrary.ButtonDownArrow btnDown = new ButtonDownArrow();
- public DateYearMonth()
- {
- InitializeComponent();
- this.Load += DateYearMonth_Load;
- this.Leave += DateYearMonth_Leave;
- this.tblPanelMonth.Leave += tblPanelMonth_Leave;
- this.tblPanelYear.Leave += tblPanelYear_Leave;
- this.lblUp.Click += lblUp_Click;
- this.lblNext.Click += lblNext_Click;
- this.lblYear.Click += lblYear_Click;
- this.txtYearMonthValue.KeyDown += txtYearMonthValue_KeyDown;
- this.txtYearMonthValue.Leave += txtYearMonthValue_Leave;
- this.lblToYear.Click += panelToyear_Click;
- this.panellblToYear.Click += panelToyear_Click;
- this.panellblToYear.MouseEnter += lblToYear_MouseEnter;
- this.panellblToYear.MouseLeave += lblToYear_MouseLeave;
- this.lblToYear.MouseEnter += lblToYear_MouseEnter;
- this.lblToYear.MouseLeave += lblToYear_MouseLeave;
- this.lblYear.MouseEnter += lblYear_MouseEnter;
- this.lblYear.MouseLeave += lblYear_MouseLeave;
- btnDown.Size = new Size(18, this.txtYearMonthValue.Height - 2);
- btnDown.Dock = DockStyle.Right;
- btnDown.IsDown = true;
- btnDown.Click += btnDown_Click;
- this.txtYearMonthValue.Controls.Add(btnDown);
- this.SetHeight();
- }
- private string _strdatevalue;
- /// <summary>
- /// 设置或获取值
- /// </summary>
- public string StrDateValue
- {
- get
- {
- if (this.txtYearMonthValue.Text.Trim() != "-")
- { return this.txtYearMonthValue.Text.Trim(); }
- else
- { return ""; }
- }
- set
- {
- _strdatevalue = value;
- if (_strdatevalue != "")
- {
- this.DetectedDate(_strdatevalue);
- this.txtYearMonthValue.Text = this.CurrentYear + "-" + this.GetBeforeAddZero(this.CurrentMonth, 2);
- }
- }
- }
- /// <summary>
- /// 获取年
- /// </summary>
- public int StrYear
- { get { return this.CurrentYear; } }
- /// <summary>
- /// 获取月
- /// </summary>
- public int StrMonth
- { get { return this.CurrentMonth; } }
- private bool _isReadOnly;
- /// <summary>
- /// 是否只读
- /// </summary>
- public bool IsReadOnly
- {
- get { return _isReadOnly; }
- set
- {
- _isReadOnly = value;
- this.txtYearMonthValue.ReadOnly = _isReadOnly;
- }
- }
- /// <summary>
- /// 当前选择的年份
- /// </summary>
- int CurrentYear = 0;
- /// <summary>
- /// 当年选择的月份
- /// </summary>
- int CurrentMonth = 1;
- EnumType CurrentType;
- /// <summary>
- /// 当前选择类型
- /// </summary>
- enum EnumType
- {
- /// <summary>
- /// 月选择器
- /// </summary>
- enumMonth,
- /// <summary>
- /// 年选择器
- /// </summary>
- enumYear
- }
- public delegate void DateYearMonth_ClickChengedValue(string SelectValue);
- /// <summary>
- /// 选择Value值更改事件
- /// </summary>
- [Category("控件扩展事件"), Description("删除客户")]
- public event DateYearMonth_ClickChengedValue ClickChengedValue;
- public delegate void DateYearMonth_KeyDown();
- /// <summary>
- /// 窗体的KeyDown
- /// </summary>
- [Category("控件扩展事件"), Description("删除客户")]
- public new event DateYearMonth_KeyDown KeyDown;
- /// <summary>
- /// 窗体加载事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DateYearMonth_Load(object sender, EventArgs e)
- {
- if (this.CurrentYear == 0)
- { this.CurrentYear = SDateTime.Now.Year; }
- if (this.CurrentMonth == 0)
- { this.CurrentYear = SDateTime.Now.Month; }
- this.PaintingCharts_Month();
- this.CurrentType = EnumType.enumMonth;
- this.panellblToYear.BorderStyle = BorderStyle.FixedSingle;
- this.panellblToYear.BorderColor = this.GetColor(ColorType.当前年移过字体);
- this.lblToYear.Text = "当前年月:" + SDateTime.Now.Year + "-" + this.GetBeforeAddZero(SDateTime.Now.Month, 2);
- this.ParentForm.Click += ParentForm_Click;
- foreach (Control cont in this.ParentForm.Controls)
- {
- if (!(cont is DateYearMonth))
- { cont.Click += DateYearMonth_Click; }
- }
- }
- /// <summary>
- /// 父窗体的点击事件隐藏控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void ParentForm_Click(object sender, EventArgs e)
- { this.DateYearMonth_Click(this, null); }
- /// <summary>
- /// 父窗体的控件的点击事件隐藏控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DateYearMonth_Click(object sender, EventArgs e)
- { this.SetHeight(); }
- /// <summary>
- /// 数据处理_月
- /// </summary>
- private void PaintingCharts_Month()
- {
- Panel panel = null;
- Label lable = null;
- this.lblYear.Location = new Point(88, this.lblYear.Location.Y);
- this.lblYear.Text = this.CurrentYear.ToString();
- int YearMonthCount = 1;
- for (int i = 0; i < this.tblPanelMonth.RowCount; i++)
- {
- for (int j = 0; j < this.tblPanelMonth.ColumnCount; j++)
- {
- #region 每日板块
- panel = new Panel();
- if (YearMonthCount == CurrentMonth)
- { panel.BackColor = this.GetColor(ColorType.选中); }
- else
- { panel.BackColor = this.GetColor(ColorType.默认); }
- panel.Margin = new System.Windows.Forms.Padding(1, 1, 1, 1);
- panel.Name = "panel_" + YearMonthCount;
- panel.Tag = YearMonthCount;
- panel.Dock = DockStyle.Fill;
- panel.Click += panel_Click;
- panel.MouseEnter += panel_MouseEnter;
- panel.MouseLeave += panel_MouseLeave;
- //每日
- lable = new Label();
- lable.Name = "lblMonth" + YearMonthCount;
- lable.Font = new System.Drawing.Font("微软雅黑", 9);
- lable.ForeColor = this.GetColor(ColorType.字体);
- lable.AutoSize = false;
- lable.Size = new System.Drawing.Size(50, 20);
- lable.Text = GetMonth(YearMonthCount.ToString());
- lable.Tag = YearMonthCount;
- int Location_X = 10;
- if (YearMonthCount > 10)
- { Location_X -= 6; }
- lable.Location = new Point(Location_X, 12);
- lable.Click += lable_Click;
- lable.MouseEnter += lable_MouseEnter;
- lable.MouseLeave += lable_MouseLeave;
- panel.Controls.Add(lable);
- #endregion
- this.tblPanelMonth.Controls.Add(panel);
- YearMonthCount++;
- }
- }
- this.panelMonth.BringToFront();
- }
- /// <summary>
- /// 返回当月
- /// </summary>
- /// <param name="StrMonth"></param>
- /// <returns></returns>
- string GetMonth(string StrMonth)
- {
- switch (StrMonth.Trim())
- {
- case "1": StrMonth = "一月"; break;
- case "2": StrMonth = "二月"; break;
- case "3": StrMonth = "三月"; break;
- case "4": StrMonth = "四月"; break;
- case "5": StrMonth = "五月"; break;
- case "6": StrMonth = "六月"; break;
- case "7": StrMonth = "七月"; break;
- case "8": StrMonth = "八月"; break;
- case "9": StrMonth = "九月"; break;
- case "10": StrMonth = "十月"; break;
- case "11": StrMonth = "十一月"; break;
- case "12": StrMonth = "十二月"; break;
- }
- return StrMonth;
- }
- /// <summary>
- /// 年点击事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblYear_Click(object sender, EventArgs e)
- {
- switch (this.CurrentType)
- {
- case EnumType.enumMonth:
- this.CurrentType = EnumType.enumYear;
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text);
- this.CleartblPanelYearControls();
- break;
- case EnumType.enumYear:
- break;
- }
- }
- /// <summary>
- /// 上一年
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblUp_Click(object sender, EventArgs e)
- {
- switch (this.CurrentType)
- {
- case EnumType.enumMonth:
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text) - 1;
- this.CleartblPanelMonthControls();
- break;
- case EnumType.enumYear:
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text.Trim().Split('-')[0]) - 12;
- this.CleartblPanelYearControls();
- break;
- }
- }
- /// <summary>
- /// 下一年
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblNext_Click(object sender, EventArgs e)
- {
- switch (this.CurrentType)
- {
- case EnumType.enumMonth:
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text) + 1;
- this.CleartblPanelMonthControls();
- break;
- case EnumType.enumYear:
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text.Trim().Split('-')[0]) + 12;
- this.CleartblPanelYearControls();
- break;
- }
- }
- /// <summary>
- /// 清空月份选择器
- /// </summary>
- void CleartblPanelMonthControls()
- {
- this.tblPanelMonth.Controls.Clear();
- this.PaintingCharts_Month();
- }
- /// <summary>
- /// 清空年份选择器
- /// </summary>
- void CleartblPanelYearControls()
- {
- this.tblPanelYear.Controls.Clear();
- this.PaintingCharts_Year();
- }
- /// <summary>
- /// 数据处理_年
- /// </summary>
- private void PaintingCharts_Year()
- {
- Panel panel = null;
- Label lable = null;
- this.panelYear.Location = this.panelMonth.Location;
- this.lblYear.Text = this.CurrentYear + "-" + (this.CurrentYear + 11);
- this.lblYear.Location = new Point(73, this.lblYear.Location.Y);
- int ForInt = 0; ;
- for (int i = 0; i < this.tblPanelYear.RowCount; i++)
- {
- for (int j = 0; j < this.tblPanelYear.ColumnCount; j++)
- {
- #region 每日板块
- panel = new Panel();
- if (this.CurrentYear == this.CurrentYear + ForInt)
- { panel.BackColor = this.GetColor(ColorType.选中); }
- else
- { panel.BackColor = this.GetColor(ColorType.默认); }
- panel.Margin = new System.Windows.Forms.Padding(1, 1, 1, 1);
- panel.Name = "panel_" + this.CurrentYear + ForInt;
- panel.Tag = this.CurrentYear + ForInt;
- panel.Dock = DockStyle.Fill;
- panel.MouseEnter += panel_MouseEnter;
- panel.MouseLeave += panel_MouseLeave;
- panel.Click += panel_Click;
- //每日
- lable = new Label();
- lable.Name = "lblYear" + this.CurrentYear + ForInt;
- lable.Font = new System.Drawing.Font("微软雅黑", 9);
- lable.ForeColor = this.GetColor(ColorType.字体);
- lable.AutoSize = false;
- lable.Size = new System.Drawing.Size(50, 20);
- lable.Text = (this.CurrentYear + ForInt).ToString();
- lable.Tag = this.CurrentYear + ForInt;
- lable.Location = new Point(8, 12);
- lable.MouseEnter += lable_MouseEnter;
- lable.MouseLeave += lable_MouseLeave;
- lable.Click += lable_Click;
- panel.Controls.Add(lable);
- #endregion
- this.tblPanelYear.Controls.Add(panel);
- ForInt++;
- }
- }
- this.panelYear.BringToFront();
- }
- /// <summary>
- /// lbl光标离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lable_MouseLeave(object sender, EventArgs e)
- {
- Label lbl = sender as Label;
- switch (this.CurrentType)
- {
- case EnumType.enumMonth:
- if (Convert.ToInt32(lbl.Tag) == this.CurrentMonth)
- { lbl.Parent.BackColor = this.GetColor(ColorType.选中); }
- else
- { lbl.Parent.BackColor = this.GetColor(ColorType.默认); }
- break;
- case EnumType.enumYear:
- if (Convert.ToInt32(lbl.Tag) == this.CurrentYear)
- { lbl.Parent.BackColor = this.GetColor(ColorType.选中); }
- else
- { lbl.Parent.BackColor = this.GetColor(ColorType.默认); }
- break;
- }
- }
- /// <summary>
- /// lbl光标进入事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lable_MouseEnter(object sender, EventArgs e)
- {
- Label lbl = sender as Label;
- lbl.Parent.BackColor = this.GetColor(ColorType.移过);
- }
- /// <summary>
- /// 层光标离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void panel_MouseLeave(object sender, EventArgs e)
- {
- Panel panel = sender as Panel;
- switch (this.CurrentType)
- {
- case EnumType.enumMonth:
- if (Convert.ToInt32(panel.Tag) == this.CurrentMonth)
- { panel.BackColor = this.GetColor(ColorType.选中); }
- else
- { panel.BackColor = this.GetColor(ColorType.默认); }
- break;
- case EnumType.enumYear:
- if (Convert.ToInt32(panel.Tag) == this.CurrentYear)
- { panel.BackColor = this.GetColor(ColorType.选中); }
- else
- { panel.BackColor = this.GetColor(ColorType.默认); }
- break;
- }
- }
- /// <summary>
- /// 层光标进入事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void panel_MouseEnter(object sender, EventArgs e)
- {
- Panel panel = sender as Panel;
- panel.BackColor = this.GetColor(ColorType.移过);
- }
- /// <summary>
- /// 当前年光标进入事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblToYear_MouseEnter(object sender, EventArgs e)
- {
- this.lblToYear.ForeColor = this.GetColor(ColorType.当前年移过字体);
- }
- /// <summary>
- /// 当前年光标离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblToYear_MouseLeave(object sender, EventArgs e)
- {
- this.lblToYear.ForeColor = this.GetColor(ColorType.当前年离开字体);
- }
- /// <summary>
- /// 当前提示选择的年月提示光标进入事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblYear_MouseEnter(object sender, EventArgs e)
- {
- this.lblYear.ForeColor = this.GetColor(ColorType.当前年移过字体);
- }
- /// <summary>
- /// 当前提示选择的年月提示光标离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lblYear_MouseLeave(object sender, EventArgs e)
- {
- this.lblYear.ForeColor = this.GetColor(ColorType.当前年离开字体);
- }
- /// <summary>
- /// 选择年月
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void lable_Click(object sender, EventArgs e)
- { this.SelectCurrentYearMonth(sender, false); }
- /// <summary>
- /// 选择年月
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel_Click(object sender, EventArgs e)
- { this.SelectCurrentYearMonth(sender, true); }
- /// <summary>
- /// 选择当前年月
- /// </summary>
- /// <param name="objControls"></param>
- /// <param name="IsPanel"></param>
- void SelectCurrentYearMonth(object objControls, bool IsPanel)
- {
- switch (this.CurrentType)
- {
- case EnumType.enumMonth:
- for (int i = 0; i < 12; i++)
- {
- Panel newpanel = (Panel)tblPanelMonth.Controls[i];
- if (newpanel != null)
- { newpanel.BackColor = this.GetColor(ColorType.默认); }
- }
- if (IsPanel)
- {
- Panel panelA = objControls as Panel;
- if (panelA != null)
- {
- this.txtYearMonthValue.Text = this.lblYear.Text.Trim() + "-" + this.GetBeforeAddZero(Convert.ToInt32(panelA.Tag), 2);
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text);
- this.CurrentMonth = Convert.ToInt32(panelA.Tag);
- }
- }
- else
- {
- Label lbl = objControls as Label;
- if (lbl != null)
- {
- this.txtYearMonthValue.Text = this.lblYear.Text.Trim() + "-" + this.GetBeforeAddZero(Convert.ToInt32(lbl.Tag), 2);
- this.CurrentYear = Convert.ToInt32(this.lblYear.Text);
- this.CurrentMonth = Convert.ToInt32(lbl.Tag);
- }
- }
- this.btnDown.IsDown = true;
- this.SetHeight();
- this.NewClickChengedValue();
- break;
- case EnumType.enumYear:
- if (IsPanel)
- {
- Panel panel = objControls as Panel;
- if (panel != null)
- { this.CurrentYear = Convert.ToInt32(panel.Tag); }
- }
- else
- {
- Label lbl = objControls as Label;
- if (lbl != null)
- { this.CurrentYear = Convert.ToInt32(lbl.Tag); }
- }
- this.CleartblPanelMonthControls();
- this.CurrentType = EnumType.enumMonth;
- break;
- }
- }
- /// <summary>
- /// 选择今年
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void panelToyear_Click(object sender, EventArgs e)
- {
- this.CurrentYear = SDateTime.Now.Year;
- this.CurrentMonth = SDateTime.Now.Month;
- this.txtYearMonthValue.Text = this.CurrentYear + "" + this.GetBeforeAddZero(this.CurrentMonth, 2);
- this.btnDown.IsDown = true;
- this.SetHeight();
- this.NewClickChengedValue();
- }
- /// <summary>
- /// 选择值后的事件
- /// </summary>
- void NewClickChengedValue()
- {
- if (this.ClickChengedValue != null)
- { this.ClickChengedValue(this.StrDateValue); }
- }
- /// <summary>
- /// 点击展开
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void btnDown_Click(object sender, EventArgs e)
- {
- this.btnDown.Parent.Parent.Anchor = AnchorStyles.Left | AnchorStyles.Top;
- if (this.Height > 25)
- {
- this.btnDown.IsDown = true;
- this.SetHeight();
- this.txtYearMonthValue.Focus();
- }
- else
- {
- this.btnDown.IsDown = false;
- if (this.panelYearMonthValue.Width < 216)
- { this.Size = new Size(216, 202); }
- else
- { this.Size = new Size(this.panelYearMonthValue.Width, 202); }
- int YearLog = this.CurrentYear;
- if (this.txtYearMonthValue.Text.Trim() != "-")
- {
- this.DetectedDate(this.txtYearMonthValue.Text.Trim());
- for (int i = 0; i < 12; i++)
- {
- Panel newpanel = (Panel)tblPanelMonth.Controls[i];
- if (newpanel != null)
- {
- if (Convert.ToInt32(newpanel.Tag) == this.CurrentMonth)
- { newpanel.BackColor = this.GetColor(ColorType.选中); }
- else
- { newpanel.BackColor = this.GetColor(ColorType.默认); }
- }
- }
- }
- else
- {
- this.CurrentYear = SDateTime.Now.Year;
- this.CurrentMonth = SDateTime.Now.Month;
- }
- if (YearLog != this.CurrentYear)
- {
- this.tblPanelMonth.Controls.Clear();
- this.PaintingCharts_Month();
- }
- this.panelMonth.BringToFront();
- this.BringToFront();
- this.Focus();
- }
- }
- /// <summary>
- /// 输入时隐藏控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void txtYearMonthValue_KeyDown(object sender, KeyEventArgs e)
- {
- this.SetHeight();
- if (e.KeyCode == Keys.Enter)
- {
- if (this.KeyDown != null)
- {
- //string StrYearDate = LYFZ.Command.Command_Validate.DateTimeToString(this.StrYear + "-01" + "-01");
- //if (string.IsNullOrEmpty(StrYearDate))
- //{
- // MessageBoxCustom.Show("年份输入不在有效范围!");
- // this.txtYearMonthValue.Text = StrYearDate;
- // return;
- //}
- //if (string.IsNullOrEmpty(this.StrMonth.ToString().Trim()))
- //{ return; }
- //string StrTime = LYFZ.Command.Command_Validate.DateTimeToString(this.StrDateValue + "-01");
- //if (string.IsNullOrEmpty(StrTime))
- //{
- // MessageBoxCustom.Show("月份输入不在有效范围,有效范围在1到12月!");
- // this.txtYearMonthValue.Text = SDateTime.Now.ToString("yyyy-MM");
- // return;
- //}
- this.KeyDown();
- }
- }
- }
- /// <summary>
- /// 输入后离开事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void txtYearMonthValue_Leave(object sender, EventArgs e)
- {
- if (!string.IsNullOrEmpty(this.StrDateValue.Trim()))
- {
- //string StrYearDate = LYFZ.Command.Command_Validate.DateTimeToString(this.StrYear + "-01" + "-01");
- //if (string.IsNullOrEmpty(StrYearDate))
- //{
- // MessageBoxCustom.Show("年份输入不在有效范围!");
- // this.txtYearMonthValue.Text = StrYearDate;
- // return;
- //}
- //if (string.IsNullOrEmpty(this.StrMonth.ToString().Trim()))
- //{ return; }
- //string StrTime = LYFZ.Command.Command_Validate.DateTimeToString(this.StrDateValue + "-01");
- //if (string.IsNullOrEmpty(StrTime))
- //{
- // MessageBoxCustom.Show("月份输入不在有效范围,有效范围在1到12月!");
- // this.txtYearMonthValue.Text = "";
- // return;
- //}
- }
- }
- /// <summary>
- /// 离开事件隐藏控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void tblPanelYear_Leave(object sender, EventArgs e)
- { this.SetHeight(); }
- /// <summary>
- /// 离开事件隐藏控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void tblPanelMonth_Leave(object sender, EventArgs e)
- { this.SetHeight(); }
- /// <summary>
- /// 离开事件隐藏控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void DateYearMonth_Leave(object sender, EventArgs e)
- { this.SetHeight(); }
- /// <summary>
- /// 设置当前高
- /// </summary>
- void SetHeight()
- { this.Size = new Size(this.panelYearMonthValue.Width, 25); }
- /// <summary>
- /// 在值的前面用O补充
- /// </summary>
- /// <param name="Value">要操作的值</param>
- /// <param name="ValueLength">值要达到的长度</param>
- /// <returns></returns>
- string GetBeforeAddZero(int Value, int ValueLength)
- {
- string StrValue = Value.ToString().Trim();
- while (StrValue.Length < ValueLength)
- { StrValue = "0" + StrValue; }
- return StrValue;
- }
- /// <summary>
- /// 检测日期
- /// </summary>
- void DetectedDate(string DateValue)
- {
- string[] YearMonth = DateValue.Trim().Split('-');
- string StrYear = YearMonth[0];
- string StrMonth = YearMonth[1];
- if (StrYear.Trim().Length == 4)
- {
- int intYear = Convert.ToInt32(StrYear);
- if (intYear < 1753)
- {
- this.CurrentYear = 1753;
- this.txtYearMonthValue.Text = this.CurrentYear + "" + StrMonth;
- }
- else
- { this.CurrentYear = intYear; }
- }
- else
- { this.CurrentYear = SDateTime.Now.Year; }
- if (StrMonth.Trim().Length > 0)
- {
- int intMonth = Convert.ToInt32(StrMonth);
- if (intMonth > 12)
- {
- this.CurrentMonth = 12;
- this.txtYearMonthValue.Text = this.CurrentYear + "" + this.CurrentMonth;
- }
- else if (intMonth <= 0)
- {
- this.CurrentMonth = 1;
- this.txtYearMonthValue.Text = this.CurrentYear + "" + this.CurrentMonth;
- }
- else
- { this.CurrentMonth = intMonth; }
- }
- else
- { this.CurrentMonth = SDateTime.Now.Month; }
- }
- /// <summary>
- /// 获取颜色
- /// </summary>
- /// <param name="CurrentColorType"></param>
- /// <returns></returns>
- Color GetColor(ColorType CurrentColorType)
- {
- switch (CurrentColorType)
- {
- case ColorType.选中:
- return Color.LightPink;
- case ColorType.移过:
- return Color.SkyBlue;
- case ColorType.字体:
- return Color.White;
- case ColorType.当前年移过字体:
- return Color.Blue;
- case ColorType.当前年离开字体:
- return Color.Black;
- default:
- return Color.Gainsboro;
- }
- }
- /// <summary>
- /// 颜色枚举
- /// </summary>
- enum ColorType
- {
- 默认,
- 选中,
- 移过,
- 字体,
- 当前年移过字体,
- 当前年离开字体,
- }
- }
- }
|