private void butCurrentWeek_Click(object sender, EventArgs e) { this.LastWeeks = 0; betweenDate bdate = this.getDate(LastWeeks, 1); this.dtpStartDate.Value = bdate.start_time; this.dtpStopDate.Value = bdate.end_time; this.cbDate.Checked = true; }
private void ProductionStatus_Load(object sender, EventArgs e) { this.cbDateType.SelectedIndex = 0; this.cbDate.Checked = false; // this.dtpStartDate.Value = DateTime.Now.addw betweenDate bdate = this.getDate(LastWeeks, 0); this.dtpStartDate.Value = bdate.start_time; this.dtpStopDate.Value = bdate.end_time; this.rbWIP.Checked = true; this.splitContainer1.SplitterDistance = Convert.ToInt32(this.splitContainer1.Height * 0.8); }
private betweenDate getDate(int weeks, int type) { DateTime currentTime = DateTime.Now; int week = Convert.ToInt32(currentTime.DayOfWeek); week = week == 0 ? 7 : week; betweenDate bdate = new betweenDate(); switch (type) { case 0: //获取上周星期一/星期天 bdate.start_time = currentTime.AddDays(1 - week - 7 * weeks); //上周星期一 bdate.end_time = currentTime.AddDays(7 - week - 7 * weeks); //上周星期天 -1 星期六 // Console.WriteLine("上周:" + start_time_last_week + "|" + end_time_last_week); break; case 1: //获取本周星期一/星期天 bdate.start_time = currentTime.AddDays(1 - week); //本周星期一 bdate.end_time = currentTime.AddDays(7 - week); //本周星期天 // Console.WriteLine("本周:" + start_time_current_week + "|" + end_time_current_week); break; case 2: //3-5;6-8;9-11;12-2 startQuarter bdate.start_time = currentTime.AddMonths(0 - (currentTime.Month % 3)).AddDays(1 - currentTime.Day); //本季度初 bdate.end_time = bdate.start_time.AddMonths(3).AddDays(-1); //本季度末 break; case 3: //1-3;4-6;7-9;10-12 startQuarter bdate.start_time = currentTime.AddMonths(0 - (currentTime.Month - 1) % 3).AddDays(1 - currentTime.Day); //本季度初 bdate.end_time = bdate.start_time.AddMonths(3).AddDays(-1); //本季度末 break; default: bdate.start_time = currentTime; bdate.end_time = currentTime; break; } return(bdate); }