Exemple #1
0
        //查询所有学生数据
        public List <StuInfo> queryAllStudents()
        {
            List <StuInfo>   stus    = new List <StuInfo>();
            string           sql     = "select * from students order by sno";
            SQLiteCommand    command = new SQLiteCommand(sql, dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();

            while (reader.Read())
            {
                StuInfo stu = new StuInfo(reader["sno"].ToString(), reader["sname"].ToString(),
                                          reader["ssex"].ToString(), reader["sclass"].ToString());
                stus.Add(stu);
            }
            return(stus);
        }
Exemple #2
0
        //查找学生信息
        public List <StuInfo> queryStudents(StuInfo.type type, string param)
        {
            string sql = "";

            //根据不同的类型编辑sql语句
            switch (type)
            {
            case StuInfo.type.sno:
                sql = "select * from students where sno='" + param + "'";
                break;

            case StuInfo.type.sname:
                sql = "select * from students where sname='" + param + "'";
                break;

            case StuInfo.type.ssex:
                sql = "select * from students where ssex='" + param + "'";
                break;

            case StuInfo.type.sclass:
                sql = "select * from students where sclass='" + param + "'";
                break;
            }

            SQLiteCommand    command = new SQLiteCommand(sql, dbConnection);
            SQLiteDataReader reader  = command.ExecuteReader();
            //装载结果的List
            List <StuInfo> stus = new List <StuInfo>();

            //读取所有结果
            while (reader.Read())
            {
                StuInfo stu = new StuInfo(reader["sno"].ToString(), reader["sname"].ToString(),
                                          reader["ssex"].ToString(), reader["sclass"].ToString());
                stus.Add(stu);
            }
            return(stus);
        }
Exemple #3
0
        //插入学生信息
        private void insertStu(string msg)
        {
            //判断是否登录
            if (!isLegal(mSocket.RemoteEndPoint.ToString()))
            {
                mSocket.Send(Encoding.UTF8.GetBytes(MyProtocol.head_unlogin));
                return;
            }
            string[] args = msg.Split('#');
            StuInfo  stu  = new StuInfo(resumeSpecStr(args[0]), resumeSpecStr(args[1]),
                                        resumeSpecStr(args[2]), resumeSpecStr(args[3]));

            if (mDataManager.isSnoExists(stu.getsno()))
            {
                mSocket.Send(Encoding.UTF8.GetBytes(MyProtocol.head_insertStu + MyProtocol.body_exists));
                Console.WriteLine("insert denied(exist):" + stu.getsname());
                return;
            }
            //添加
            mDataManager.insertStuInfo(stu);
            //发送成功消息
            mSocket.Send(Encoding.UTF8.GetBytes(MyProtocol.head_insertStu + MyProtocol.body_success));
            Console.WriteLine("insert a student:" + stu.getsname());
        }