private void btnLogin_Click(object sender, EventArgs e) { if (cbbClass.SelectedIndex < 0 || cbbName.SelectedIndex < 0) { RmsgBox.Show("請選擇姓名", "錯誤"); return; } loginName = studentItems[cbbName.SelectedIndex].name; studentNumber = studentItems[cbbName.SelectedIndex].number; class_name = classItems[cbbClass.SelectedIndex].name; int id = studentItems[cbbName.SelectedIndex].id; int class_id = classItems[cbbClass.SelectedIndex].id; Boolean ifOnDuty = false; if (ckb_onDuty.Checked) { ifOnDuty = true; } //MessageBox.Show(string.Format("ID: {3}, 姓名: {0}, 座號: {1}, 班級: {2}", loginName, studentNumber, class_name, id), "登入成功", MessageBoxButtons.OK, MessageBoxIcon.None); Form_main form = new Form_main(this, id, loginName, studentNumber, class_name, class_id, ifOnDuty); //hide form1 and show form_main form.Show(); this.Hide(); }
private void Form1_Load(object sender, EventArgs e) { if (skipLogin) { loginName = "Jay Li"; class_name = "AppDev 98"; Form_main form = new Form_main(this, 1, loginName, 1, class_name, 1, true); form.ShowDialog(); } scsb = new SqlConnectionStringBuilder(); scsb.DataSource = "CR3-08"; scsb.InitialCatalog = "Lunch"; scsb.IntegratedSecurity = true; sqlCon = scsb.ToString(); // comment this out when not in III SqlConnection con = new SqlConnection(sqlCon); con.Open(); SqlCommand cmd = new SqlCommand("select * from class", con); SqlDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { classItems.Add(new class_item((int)reader["class_id"], (string)reader["name"])); cbbClass.Items.Add(classItems.Last <class_item>().name); } reader.Close(); con.Close(); } finally { if (reader != null) { reader.Close(); } if (con != null) { con.Close(); } } //cbbClass.DataSource = classItems; //cbbClass.DisplayMember = "name"; }