Query the data C # winform on the current day of this week,
This is what I did on the winform page.
1. First, add three lable entries on the page. When you click lable for the first time, the corresponding data will be queried. When you click the same lable for the second time, all data will be refreshed.
2. Clicking different labels will display a color prompt indicating which of the following labels will be restored during the second click.
3. The data queried this month on the current day is queried based on the time period. Therefore, you must first obtain the time period of the current day for this week and the time period of this month.
This day labDay this week labWeek this month labMonth
The Code is as follows:
1 public partial class frmSelCase 2 {3 private List <Label> m_lstLabel = new List <Label> (); 4} 5 6 // The color is changed to the Blue even number of times. The default color is 7 bool [] labelClick = {false, false, false}. 8 9 private void initControls () 10 {11 // three lable click events 12 labDay. click + = new EventHandler (labDay_Click); 13 labWeek. click + = new EventHandler (labWeek_Click); 14 labMonth. click + = new EventHandler (labMonth_Click); 15 16 initResonArr Ay (); 17 for (int I = 0; I <m_lstLabel.Count; I ++) 18 {19 Label labLeaveReson = m_lstLabel [I]; 20 labLeaveReson. click + = new EventHandler (lab_Click); 21} 22} 23 24 private void initResonArray () 25 {26 week (labDay); 27 m_lstLabel.Add (labWeek); 28 m_lstLabel.Add (labMonth ); 29} 30 31 // I wrote a 32 33 private void lab_Click (object sender, EventArgs e) 34 {35 if (null = m _ LstLabel) return; 36 if (null = sender) return; 37 Label labCurClick = (Label) sender; 38 39 for (int I = 0; I <m_lstLabel.Count; I ++) 40 {41 Label labReson = m_lstLabel [I]; 42 43 if (labReson. name = labCurClick. name & labelClick [I] = false) 44 {45 if (labReson. backColor! = Color. FromArgb (16,155,246) labReson. BackColor = Color. FromArgb (16,155,246); 46 if (labReson. ForeColor! = Color. FromArgb (255,255,255) labReson. ForeColor = Color. FromArgb (255,255,255); 47 labelClick [I] = true; 48} 49 else 50 {51 if (labReson. BackColor! = Color. FromArgb (217,229,238) labReson. BackColor = Color. FromArgb (217,229,238); 52 if (labReson. ForeColor! = Color. fromArgb (17, 95,124) labReson. foreColor = Color. fromArgb (17, 95,124); 53 labelClick [I] = false; 54} 55} 56} 57 58 // get the time range 59 private void getDateRange (DateRange range, out DateTime startTime, out DateTime endTime) 60 {61 startTime = DateTime. minValue; 62 endTime = DateTime. minValue; 63 64 DateTime dtNow = DateTime. now; 65 66 switch (range) 67 {68 case DateRange. day: 69 startTime = dtNow. date; 70 endTime = dtNow. addDays (1 ). addSeconds (-1); 71 break; 72 case DateRange. week: 73 startTime = dtNow. date. addDays (1-Convert. toInt32 (dtNow. dayOfWeek. toString ("d"); 74 endTime = startTime. addDays (7 ). addSeconds (-1); 75 break; 76 case DateRange. month: 77 startTime = dtNow. date. addDays (1-DateTime. now. date. day); 78 endTime = startTime. addMonths (1 ). addSeconds (-1); 79 break; 80 case DateRange. none: 81 default: 82 break; 83} 84} 85 86 // click this day to query the data of the current day and then click it to restore the lable color and initial data 87 private void labDay_Click (object sender, EventArgs e) 88 {89 if (DateRange. day = m_dateRange) 90 {91 m_dateRange = DateRange. none; 92} 93 else 94 {95 m_dateRange = DateRange. day; 96} 97 getDateRange (m_dateRange, out m_dtFilter_StartTime, out m_dtFilter_EndTime); 98 String strInputText = InputText. toUpper (); 99 if (SysDefine. FAILED = refreshList (0, strInputText) 100 {101 MessageBox. show (this. errorText, "information", MessageBoxButtons. OK, MessageBoxIcon. warning); 102} 103 104 105 // click this week to query the data of this week and then click it to restore the color and initial data of lable 106 private void labWeek_Click (object sender, EventArgs e) 107 {108 if (DateRange. week = m_dateRange) 109 {110 m_dateRange = DateRange. none; 111} 112 else113 {114 m_dateRange = DateRange. week; 115} 116 117 getDateRange (m_dateRange, out m_dtFilter_StartTime, out m_dtFilter_EndTime); 118 119 String strInputText = InputText. toUpper (); 120 if (SysDefine. FAILED = refreshList (0, strInputText) 121 {122 MessageBox. show (this. errorText, "information", MessageBoxButtons. OK, MessageBoxIcon. warning); 123} 124 125} 126 127 // click this month to query the data of this month and then click it to restore the lable color and initial data 128 private void labMonth_Click (object sender, EventArgs e) 129 {130 if (DateRange. month = m_dateRange) 131 {132 m_dateRange = DateRange. none; 133} 134 else135. {136 m_dateRange = DateRange. month; 137} 138 139 getDateRange (m_dateRange, out m_dtFilter_StartTime, out m_dtFilter_EndTime); 140 141 String strInputText = InputText. toUpper (); 142 if (SysDefine. FAILED = refreshList (0, strInputText) 143 {144 MessageBox. show (this. errorText, "information", MessageBoxButtons. OK, MessageBoxIcon. warning); 145} 146} 147 148 // locate the status of the current lable in four unselected days select week select Month149 private DateRange m_dateRange = DateRange. none; 150 private enum DateRange151 {152 None = 0,153 Day = 1,154 Week = 2,155 Month = 3156} 157 158 public String InputText159 {160 get {return ucPages. inputText;} 161 set {ucPages. inputText = value;} 163} 164 165 private DateTime m_dtFilter_StartTime = DateTime. minValue; 166 public DateTime Filter_StartDate167 {168 get {return m_dtFilter_StartTime;} 169} 170 171 private DateTime m_dtFilter_EndTime = DateTime. minValue; 172 public DateTime Filter_EndDate173 {174 get {return m_dtFilter_EndTime;} 175}