private void 值輸btn登入值日生系統_Click(object sender, EventArgs e) { if ((tb值日生姓名.Text.Length > 0) && (tb值日生班級.Text.Length > 0) && (tb值日生電話.Text.Length > 0)) { SqlConnection con = new SqlConnection(scsb.ToString()); con.Open(); string strSQL = "Insert Into 值日生Info(@new值日生班級,@new值日生姓名,@new值日生電話)"; SqlCommand cmd = new SqlCommand(strSQL, con); cmd.Parameters.AddWithValue("@New值日生班級", tb值日生班級.Text); cmd.Parameters.AddWithValue("@New值日生姓名", tb值日生姓名.Text); cmd.Parameters.AddWithValue("@New值日生電話", tb值日生電話.Text); Form值日生端 myform值日生端 = new Form值日生端(); Form學生端 myform學生端 = new Form學生端(); Form值日生輸入 myform值日生輸入資料 = new Form值日生輸入(); Form櫃台端 myform櫃台端 = new Form櫃台端(tb值日生姓名.Text); myform值日生端.Show(); //myform值日生端.ShowDialog(); myform值日生輸入資料.ShowInTaskbar = false; myform學生端.Show(); //myform學生端.ControlBox = false; //myform學生端.WindowState = FormWindowState.Minimized; myform學生端.Dispose(); con.Close(); } else { MessageBox.Show("請輸入完整資料"); } }
private void btn登入值日生系統_Click(object sender, EventArgs e) { Form學生端 myform學生端 = new Form學生端(); myform學生端.strMsg2 = tb值日生姓名.Text; SqlConnection con = new SqlConnection(scsb.ToString()); con.Open(); string strSQL = "select * from DutyInfo"; SqlCommand cmd = new SqlCommand(strSQL, con); SqlDataReader reader = cmd.ExecuteReader(); //select top 1[欄位清單] from[資料表] order by[排序欄位] desc string strMsg = ""; //myform值日生端.Show(); while (reader.Read() == true) { strMsg = string.Format("{0}", reader["DutyName"]); listBox1.Items.Add(strMsg); } reader.Close(); for (int i = 0; i < listBox1.Items.Count; i++) { if (tb值日生姓名.Text == listBox1.Items[i].ToString()) { string strinsert = "insert into [DutyInfoS] values(@NewDutyClass,@NewDutyName,@NewDutyPhoneNum) "; SqlCommand cmd1 = new SqlCommand(strinsert, con); cmd1.Parameters.AddWithValue("@NewDutyClass", tb值日生班級.Text); cmd1.Parameters.AddWithValue("@NewDutyName", tb值日生姓名.Text); cmd1.Parameters.AddWithValue("@NewDutyPhoneNum", tb值日生電話.Text); cmd1.ExecuteNonQuery(); myform值日生端.Show(); break; } } con.Close(); this.Dispose(); }
private void F1btn學生_Click(object sender, EventArgs e) { try { Form學生端 myform學生端 = new Form學生端(); SqlConnection con = new SqlConnection(scsb.ToString()); con.Open(); string strSQL = "select top 1 * from StoreInfoS order by StoreID desc"; SqlCommand cmd = new SqlCommand(strSQL, con); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); myform學生端.strMsg1 = string.Format("{0}", reader["StoreName"]); myform學生端.Show(); } catch { MessageBox.Show("值日生尚未選店"); } //myform學生端.WindowState = FormWindowState.Normal; }