コード例 #1
0
        public void StudentRequestEventHandler(object sender, StudentInfoEventArgs e)
        {
            try
            {
                OleDbCommand aCommand = new OleDbCommand(e.Query, aConnection);
                aConnection.Open();
                OleDbDataReader aReader = aCommand.ExecuteReader();
                switch (e.RawInput)
                {
                case "G":
                    ReturnInfo += string.Format("Grades :");
                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("{0}, ", aReader.GetString(1));
                    }
                    break;

                case "S":
                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("Subject : {0}", aReader.GetString(3));
                    }
                    break;

                case "T":
                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("Teacher : {0}", aReader.GetString(4));
                    }
                    break;

                case "A":

                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("Teacher : {0}, Subject : {1}, Grades : ", aReader.GetString(4), aReader.GetString(3));
                    }
                    aReader.Close();
                    aConnection.Close();

                    aCommand = new OleDbCommand(String.Format("SELECT * FROM Grades WHERE student = '{0}'", e.User.FirstName + " " + e.User.LastName), aConnection);
                    aConnection.Open();
                    aReader = aCommand.ExecuteReader();

                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("{0}, ", aReader.GetString(1));
                    }
                    break;
                }
                aReader.Close();
                aConnection.Close();
            }
            catch (OleDbException Ole)
            {
                Console.WriteLine("Error: {0}", Ole.Errors[0].Message);
                aConnection.Close();
            }
        }
コード例 #2
0
        private void KeyActive(object sender, EventArgs e)
        {
            while (input.isKeyAvailable())
            {
                KeyEventArgs         keyArgs = new KeyEventArgs();
                StudentInfoEventArgs studentInfoEventArgs = new StudentInfoEventArgs();
                keyArgs.Cki = input.GetKey();

                switch (keyArgs.Cki.Key)
                {
                case ConsoleKey.I:
                    timer.KeyPress += inputBoxController.ChangeState;
                    timer.OnKeyPress(keyArgs);
                    timer.KeyPress -= inputBoxController.ChangeState;
                    break;

                case ConsoleKey.Enter:
                    timer.KeyPress += inputBoxController.ChangeState;
                    timer.OnKeyPress(keyArgs);
                    timer.KeyPress -= inputBoxController.ChangeState;
                    if (inputBoxController.GetInput(2) != null)
                    {
                        queryCreator.CreateQuery(inputBoxController.GetInput(2));


                        studentInfoEventArgs.Query    = queryCreator.ReturnQuery();
                        studentInfoEventArgs.RawInput = queryCreator.Input;
                        studentInfoEventArgs.User     = queryCreator.User;

                        timer.StudentRequest += studentDBController.StudentRequestEventHandler;
                        timer.OnStudentRequest(studentInfoEventArgs);
                        timer.StudentRequest -= studentDBController.StudentRequestEventHandler;

                        outputBoxController.FillOutputBox(studentDBController.ReturnOperaionResult());
                    }

                    inputBoxController.NullInput();
                    queryCreator.NullQeury();
                    studentDBController.NullOperationResult();
                    break;

                case ConsoleKey.C:
                    timer.KeyPress += outputBoxController.ClearOutputBox;
                    timer.OnKeyPress(keyArgs);
                    timer.KeyPress -= outputBoxController.ClearOutputBox;
                    break;

                case ConsoleKey.S:
                    outputBoxController.FillOutputBox(student.DisplayInfo());
                    break;
                }
                studentView.Render();
                System.Threading.Thread.Sleep(100);
            }
        }