Esempio n. 1
0
        //数据录入
        public void entryMessage()
        {
            if (textName.Text != "" && textID.Text != "" && textCard.Text != "" && textCard.Text != "" && combo1.Text != "" && combo2.Text != "" && picShow.Image != null)
            {
                //保存 姓名、学号、卡号、宿舍号、图片
                DormStudent newStudent = new DormStudent();
                //姓名
                newStudent.studentName = textName.Text;
                //学号
                newStudent.studentID = textID.Text;
                //卡号
                newStudent.cardID = textCard.Text;
                //宿舍号
                newStudent.dormitoryID = combo1.Text + "-" + combo2.Text;

                //图片,复制到指定位置
                ImageFormat imgformat = null;
                imgformat = ImageFormat.Jpeg;
                String path = "E:\\大三\\RFID\\项目\\stuPicture\\";
                picShow.Image.Save(path + @"\" + newStudent.cardID + ".jpg", imgformat);

                //卡号、学号、姓名、寝室号
                String insert_str = "'" + newStudent.cardID + "','" + newStudent.studentID + "','" + newStudent.studentName + "','" + newStudent.dormitoryID + "'";
                MessageBox.Show("!!!!" + insert_str);
                insertMessage(insert_str, dataBaseName1);
            }
        }
Esempio n. 2
0
        // 接收消息
        private void receiveMessage()
        {
            while (true)
            {
                String data = null;
                //tsState.Text = "接收消息中";
                try
                {
                    if (reader != null)
                    {
                        data = reader.ReadString();

                        try
                        {
                            MessageBox.Show("客户端发消息来了:" + data);
                            String          send_str;
                            MySqlDataReader readerStudent = null;
                            //MessageBox.Show("2 " + data);
                            if (data.Length == 6)
                            {
                                //MessageBox.Show("3 " + data);
                                readerStudent = queryData(data, dataBaseName1);

                                if (readerStudent.Read())
                                {
                                    //MessageBox.Show("4 " + data);
                                    DormStudent student = new DormStudent();
                                    student.studentName = readerStudent.GetValue(3).ToString();
                                    student.studentID   = readerStudent.GetValue(2).ToString();
                                    student.cardID      = readerStudent.GetValue(1).ToString();
                                    student.dormitoryID = readerStudent.GetValue(4).ToString();

                                    //卡号、学号、姓名、寝室号
                                    send_str = "Y " + student.cardID + " " + student.studentID + " " + student.studentName + " " + student.dormitoryID;
                                    //卡号、时间、学号、姓名
                                    String insert_str = "'" + student.cardID + "','" + DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss") + "','" + student.studentID + "','" + student.studentName + "'";
                                    insertMessage(insert_str, dataBaseName);
                                    showData("");
                                }
                                else
                                {
                                    //MessageBox.Show("5 " + data);
                                    send_str = "N IllegalAccounts";
                                    String str = "'" + data + "','" + DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss") + "'";
                                    insertMessage(str, dataBaseName2);
                                }
                            }
                            else
                            {
                                //MessageBox.Show("6 " + data);
                                send_str = "N  IllegalInput";
                                String str = "'" + data + "','" + DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss") + "'";
                                insertMessage(str, dataBaseName2);
                                //MessageBox.Show("反正你给的不是卡号,所以我不管了<(-︿-)>");
                            }
                            if (send_str != null)
                            {
                                Thread threadread = new Thread(new ParameterizedThreadStart(sendMessage));
                                threadread.Start(send_str);
                            }
                        }
                        catch
                        {
                            //MessageBox.Show("聊聊没有成功接受消息呢,请主人仔细检查一下错误吧〒▽〒" + "\n" + ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("给我错误消息了,请仔细检查一下错误吧〒▽〒" + "\n" + ex.Message);
                }
            }
        }