示例#1
0
        public void TeacherRequestEventHandler(object sender, TeacherInfoEventArgs e)
        {
            switch (e.Action)
            {
            case 0:
                try
                {
                    OleDbCommand aCommand = new OleDbCommand(e.Query, aConnection);
                    aConnection.Open();
                    int recordsAffected = aCommand.ExecuteNonQuery();
                    aConnection.Close();
                    if (recordsAffected != 0)
                    {
                        ReturnInfo = string.Format("Operation was successful, the change was made at {0}", DateTime.Now.ToString("g"));
                    }
                }

                catch (OleDbException Ole)
                {
                    Console.WriteLine("Error: {0}", Ole.Errors[0].Message);
                    aConnection.Close();
                }
                break;

            case 1:
                try
                {
                    OleDbCommand aCommand = new OleDbCommand(e.Query, aConnection);
                    aConnection.Open();
                    OleDbDataReader aReader = aCommand.ExecuteReader();
                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("Name: {0} Subject: {1} Teacher: {2} Grades: ",
                                                    aReader.GetString(1) + " " + aReader.GetString(2),
                                                    aReader.GetString(3), aReader.GetString(4));
                    }
                    aReader.Close();
                    aConnection.Close();

                    string[] rawInput = e.RawInput.Split(' ');
                    aCommand = new OleDbCommand(String.Format("SELECT * FROM Grades WHERE student = '{0}'", rawInput[1] + " " + rawInput[2]), aConnection);

                    aConnection.Open();
                    aReader = aCommand.ExecuteReader();
                    while (aReader.Read())
                    {
                        ReturnInfo += string.Format("{0}, ", aReader.GetString(1));
                    }
                    aReader.Close();
                    aConnection.Close();
                }
                catch (OleDbException Ole)
                {
                    Console.WriteLine("Error: {0}", Ole.Errors[0].Message);
                    aConnection.Close();
                }
                break;
            }
        }
        private void KeyActive(object sender, EventArgs e)
        {
            while (input.isKeyAvailable())
            {
                // Here should be the current view being rendered

                KeyEventArgs         keyArgs = new KeyEventArgs();
                TeacherInfoEventArgs teacherInfoEventArgs = new TeacherInfoEventArgs();
                keyArgs.Cki = input.GetKey();

                // Here diffrent methods will be attached to the event based on the Key
                // Triggered and deleted if needed

                // This is a pure logic for a controller -- into a method
                switch (keyArgs.Cki.Key)
                {
                case ConsoleKey.LeftArrow:
                case ConsoleKey.RightArrow:
                    timer.KeyPress += taskbarController.ChangeSelect;
                    timer.OnKeyPress(keyArgs);
                    timer.KeyPress -= taskbarController.ChangeSelect;
                    break;

                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), taskbar.ReturnStateAsInt());

                        if (taskbar.ReturnStateAsInt() == 4)
                        {
                            teacherInfoEventArgs.Action = 1;
                        }
                        else
                        {
                            teacherInfoEventArgs.Action = 0;
                        }

                        teacherInfoEventArgs.Query    = queryCreator.ReturnQuery();
                        teacherInfoEventArgs.RawInput = queryCreator.Input;

                        timer.TeacherRequest += teacherDBController.TeacherRequestEventHandler;
                        timer.OnTeacherRequest(teacherInfoEventArgs);
                        timer.TeacherRequest -= teacherDBController.TeacherRequestEventHandler;
                    }
                    if (teacherInfoEventArgs.Action == 1 && queryCreator.ReturnQuery() != null)
                    {
                        outputBoxController1.FillOutputBox(teacherDBController.ReturnOperaionResult());
                    }
                    else
                    {
                        outputBoxController2.FillOutputBox(teacherDBController.ReturnOperaionResult());
                    }
                    inputBoxController.NullInput();
                    queryCreator.NullQeury();
                    teacherDBController.NullOperationResult();
                    break;

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

                case ConsoleKey.T:
                    outputBoxController1.FillOutputBox(teacher.DisplayInfo());
                    break;
                }
                teacherView.Render();
                System.Threading.Thread.Sleep(100);
            }
        }