1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
| using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms;
namespace CallTheRoll { public partial class mainForm : Form { public mainForm() { InitializeComponent(); }
#region 变量定义 #region 自定义变量 int tablewidth = 150; int tableheight = 70; int numcolumn = 7; int numrow = 6; int numstu = 41; string thefont = "宋体"; int thefontsize = 31; #endregion #region 公共变量 int idmak = 1; int cycleindex = 0; int cycleindexmak = 0; int chooseid = 1; string exepath = System.Environment.CurrentDirectory; int allRows = 0; #endregion #endregion
private void Form1_Paint(object sender, PaintEventArgs e) { Pen pen = new Pen(Color.Red, 2);
for (int i = 30; i <= (tablewidth * numcolumn + 30); i = i + tablewidth) {
Point point = new Point(i, 30);
Point point1 = new Point(i, (tableheight * numrow + 30));
e.Graphics.DrawLine(pen, point, point1);
} for (int i = 30; i <= (tableheight * numrow + 30); i = i + tableheight) {
Point point2 = new Point(30, i);
Point point3 = new Point((tablewidth * numcolumn + 30), i);
e.Graphics.DrawLine(pen, point2, point3);
} }
private void Form1_Load(object sender, EventArgs e) { ReadTheInformation(); this.Width = tablewidth * numcolumn + 80; this.Height = tableheight * numrow + 175; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; CallTheRoll.Anchor = AnchorStyles.Bottom; }
#region 函数封装 public void Initialize() { for (int j = 0; j < numrow; j++) { for (int i = 0; i < numcolumn; i++) { int id; id = j * numcolumn + i + 1; if (id > numstu) { break; } Label lab1 = new Label(); lab1.Location = new Point(30 + tablewidth * i, 30 + tableheight * j); lab1.Visible = true; lab1.Width = tablewidth - 1; lab1.Height = tableheight - 1; lab1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; lab1.BackColor = Color.White; if (id < 10) { lab1.Text = "0" + id.ToString(); } else { lab1.Text = id.ToString(); } lab1.Font = new Font(thefont, thefontsize); this.Controls.Add(lab1); lab1.Name = id.ToString(); } } } public void ReadTheInformation() { flag = false; try {
string TheInformation = exepath + "//CustomInformation.xlsx"; XSSFWorkbook workbook = null; using (FileStream fs = File.Open(TheInformation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { workbook = new XSSFWorkbook(fs); fs.Close(); } ISheet worksheet = workbook.GetSheetAt(0);
allRows = worksheet.LastRowNum;
tablewidth = Convert.ToInt32(worksheet.GetRow(0).GetCell(2).ToString()); tableheight = Convert.ToInt32(worksheet.GetRow(1).GetCell(2).ToString()); numstu = Convert.ToInt32(worksheet.GetRow(2).GetCell(2).ToString()); numcolumn = Convert.ToInt32(worksheet.GetRow(3).GetCell(2).ToString()); numrow = Convert.ToInt32(worksheet.GetRow(4).GetCell(2).ToString()); thefont = worksheet.GetRow(5).GetCell(2).ToString(); thefontsize = Convert.ToInt32(worksheet.GetRow(6).GetCell(2).ToString());
int row_column = numcolumn * numrow;
if ((allRows + 1) != numstu) { MessageBox.Show("学生数量错误!"); System.Environment.Exit(0); } else if (row_column < numstu) { MessageBox.Show("学生数 > 行数 * 列数"); System.Environment.Exit(0); }
Initialize();
for (int informationid = 1; informationid <= numstu; informationid++) { FillInInformation(informationid, worksheet.GetRow(informationid - 1).GetCell(0).ToString()); } } catch (Exception err) { MessageBox.Show(err.Message); } }
public void FillInInformation(int stuno, string stuname) { Control[] lb = Controls.Find(stuno.ToString(), true); lb[0].Text = stuname; }
public void PopUpPrompt(int stuno) { Control[] lb = Controls.Find(stuno.ToString(), true); string stuname = lb[0].Text; PopUpPromptForm pupfrm = new PopUpPromptForm(stuname); pupfrm.ShowDialog(); }
public void CycleAnimation() { if (idmak != 1) { createtimer.Dispose(); deletetimer.Dispose(); choosetimer.Dispose(); choosedeltimer.Dispose(); Control[] ctrl = Controls.Find(((idmak - 1).ToString()), true); ctrl[0].BackColor = Color.White; idmak = 1; createtimer.Start(); } else { createtimer.Dispose(); deletetimer.Dispose(); createtimer.Start(); } }
public void ChooseCycle() { Random chooserand = new Random(); chooseid = chooserand.Next(1, (numstu + 1)); idmak = 1; choosetimer.Start(); } #endregion
#region btn_click事件 private void CallTheRoll_Click(object sender, EventArgs e) { createtimer.Interval = 950; deletetimer.Interval = 950; cycleindexmak = 0; Random cycleindexrandom = new Random(); cycleindex = cycleindexrandom.Next(1, 3); CycleAnimation(); } #endregion
#region timer事件 private void createtimer_Tick(object sender, EventArgs e) { createtimer.Interval = deletetimer.Interval; if (idmak <= numstu) { if (idmak == 1) { deletetimer.Start(); } Control[] ctrl = Controls.Find((idmak.ToString()), true); ctrl[0].BackColor = Color.Red; if (idmak == 4) { Control[] ctrl3 = Controls.Find("3", true); ctrl3[0].BackColor = Color.White; } idmak++; if (idmak > numstu) { createtimer.Dispose(); } } }
private void deletetimer_Tick(object sender, EventArgs e) { if (idmak <= (numstu + 1)) { if (deletetimer.Interval > 100) { deletetimer.Interval -= 150; } Control[] ctrl = Controls.Find(((idmak - 1).ToString()), true); ctrl[0].BackColor = Color.White; if (cycleindexmak == 0) { if (idmak == 4) { Control[] ctrl2 = Controls.Find("2", true); ctrl2[0].BackColor = Color.White; Control[] ctrl3 = Controls.Find("3", true); ctrl3[0].BackColor = Color.Red; } } if (idmak == (numstu + 1)) { deletetimer.Dispose(); cycleindexmak += 1; if (cycleindexmak < cycleindex) { createtimer.Dispose(); idmak = 1; createtimer.Start(); } else { ChooseCycle(); } } } }
private void choosetimer_Tick(object sender, EventArgs e) { if (idmak <= chooseid) { if (idmak == 1) { choosedeltimer.Start(); } Control[] ctrl = Controls.Find((idmak.ToString()), true); ctrl[0].BackColor = Color.Red; idmak++; if (idmak > chooseid) { PopUpPrompt(idmak - 1); choosetimer.Dispose(); } } }
private void choosedeltimer_Tick(object sender, EventArgs e) { if (idmak <= chooseid) { Control[] ctrl = Controls.Find(((idmak - 1).ToString()), true); ctrl[0].BackColor = Color.White; if (idmak == chooseid) { choosedeltimer.Dispose(); } } } # endregion
private void configbtn_Click(object sender, EventArgs e) { ConfigHintForm chfrm = new ConfigHintForm(); chfrm.ShowDialog(); }
private void helpbtn_Click(object sender, EventArgs e) { System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(); info.WorkingDirectory = Application.StartupPath; info.FileName = "readme.docx"; info.Arguments = ""; try { System.Diagnostics.Process.Start(info); } catch (System.ComponentModel.Win32Exception we) { MessageBox.Show(this, we.Message); } }
} }
|