private void button3_Click(object sender, EventArgs e)
 {
     if (selected_item_id == nonselected)
     {
         System.Windows.Forms.MessageBox.Show("Firstly, select a student id to delete.");
     }
     else
     {
         Student student = catalog.getByIndex(selected_item_id);
         if (MessageBox.Show("Are you sure you want to delete " + student.Name + " ? ", "Exit",
                             MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             try
             {
                 conn.Connect();
                 string selectQ = "DELETE FROM students WHERE ID = " + selected_item_id;
                 query.setSQL(selectQ);
                 query.executeNonQuery();
                 catalog.deleteByIndex(selected_item_id);
                 setListView();
                 selected_item_id = nonselected;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Delete error:" + ex.ToString());
             }
             finally
             {
                 conn.Disconnect();
             }
         }
     }
 }
        private void addOpp()
        {
            Student student = new Student();

            //student.Id = Int32.Parse(textBox1.Text);
            student.Name      = textBox2.Text;
            student.Surname   = textBox3.Text;
            student.BirthDate = textBox4.Text;

            try
            {
                conn.Connect();
                string selectQ = "insert into students (name,surname,birthdate) values(:PR1,:PR2,:PR3);";
                query.setSQL(selectQ);
                query.addParam("name", ParameterType.ptVarChar);
                query.setParamValueSTRING("name", student.Name);
                query.addParam("surname", ParameterType.ptVarChar);
                query.setParamValueSTRING("surname", student.Surname);
                query.addParam("birthdate", ParameterType.ptVarChar);
                query.setParamValueSTRING("birthdate", student.BirthDate);
                query.executeNonQuery();

                query.setSQL("select max(id) as last_id from students;");
                query.executeQuery();
                query.first();
                student.Id = query.getFiedValueINT("last_id");

                catalog.add(student);
                mainform.setListView();

                MessageBox.Show("Student is added");

                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Setup error:" + ex.ToString());
            }
            finally
            {
                conn.Disconnect();
            }
        }
        private void addOpp()
        {
            Student student = new Student();

            student.Name      = textBox2.Text;
            student.Surname   = textBox3.Text;
            student.BirthDate = textBox4.Text;

            try
            {
                conn.Connect();
                string selectQ = "insert into students (NAME,SURNAME,BIRTH_DATE) values( " + textBox2.Text + "," + textBox3.Text + "," + Convert.ToInt32(textBox4.Text) + ")";
                query.setSQL(selectQ);
                query.executeNonQuery();

                query.setSQL("select max(id) as last_id from students;");
                query.executeQuery();
                query.first();
                student.Id = query.getFiedValueINT("last_id");

                catalog.add(student);
                mainform.setListView();

                MessageBox.Show("Student is added");

                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Setup error:" + ex.ToString());
            }
            finally
            {
                conn.Disconnect();
            }
        }
        private void setup()
        {
            ObjectFactory factory = ObjectFactory.getInstance();

            factory.setMainForm(this);
            catalog = factory.getCatalog();
            query   = (QueryBase)factory.create("query");
            conn    = (ConnectionBase)factory.create("connection");
            conn.setConnString(ProjectVariables.getConnectionString());
            query.setConnection(conn);

            try
            {
                conn.Connect();
                string selectQ = "SELECT * FROM students";
                query.setSQL(selectQ);
                query.executeQuery();
                int i = 0;
                query.first();
                while (!query.eof())
                {
                    Student student = new Student();
                    student.Id        = query.getFiedValueINT("ID");
                    student.Name      = query.getFiedValueSTRING("NAME");
                    student.Surname   = query.getFiedValueSTRING("SURNAME");
                    student.BirthDate = query.getFiedValueSTRING("BIRTH_DATE");
                    catalog.add(student);
                    Console.WriteLine(i); i++;
                    query.next();
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Setup error:" + ex.ToString());
            }
            finally
            {
                conn.Disconnect();
            }
        }
        private static void Code(TerminalTabControlItem terminalTabPage, IHostingForm parentForm, FavoriteConfigurationElement favorite, ConnectionBase conn = null)
        {
            if (conn == null)
            {
                conn = CreateConnection(favorite);
                conn.TerminalTabPage = terminalTabPage;
                terminalTabPage.TabColor = FavoriteConfigurationElement.TranslateColor(favorite.TabColor);
                terminalTabPage.Connection = conn;
            }

            conn.Favorite = favorite;
            conn.ParentForm = parentForm;

            if (conn.Connect())
            {
                if (conn.InvokeRequired)
                    conn.Invoke(new MethodInvoker(delegate
                    {
                        conn.BringToFront();
                        conn.Update();
                    }));
                else
                {
                    conn.BringToFront();
                    conn.Update();
                }
                
                if (parentForm.InvokeRequired)
                    parentForm.Invoke(new MethodInvoker(delegate
                    {
                        parentForm.UpdateControls();

                        if (favorite.DesktopSize == DesktopSize.FullScreen)
                            parentForm.FullScreen = true;
                    }));
                else
                {
                    parentForm.UpdateControls();

                    if (favorite.DesktopSize == DesktopSize.FullScreen)
                        parentForm.FullScreen = true;
                }

                conn.AfterConnectPlugins();
            }
            else
            {
            	string message = "Sorry, " + AssemblyInfo.Title + " was unable to create the connection. Try again or check the log for more information.";

                Log.Error(message);
                MessageBox.Show(message, AssemblyInfo.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (parentForm.InvokeRequired)
                    parentForm.Invoke(new MethodInvoker(delegate { parentForm.RemoveAndUnSelect(terminalTabPage); }));
                else
                    parentForm.RemoveAndUnSelect(terminalTabPage);
            }

            if (conn.Connected && favorite.NewWindow)
            {
                if (parentForm.InvokeRequired)
                    parentForm.Invoke(new MethodInvoker(delegate { parentForm.DetachTabToNewWindow(terminalTabPage); }));
                else
                    parentForm.DetachTabToNewWindow(terminalTabPage);
            }
        }
        private static void Code(TerminalTabControlItem terminalTabPage, IHostingForm parentForm, FavoriteConfigurationElement favorite, ConnectionBase conn = null)
        {
            if (conn == null)
            {
                conn = CreateConnection(favorite);
                conn.TerminalTabPage       = terminalTabPage;
                terminalTabPage.TabColor   = FavoriteConfigurationElement.TranslateColor(favorite.TabColor);
                terminalTabPage.Connection = conn;
            }

            conn.Favorite   = favorite;
            conn.ParentForm = parentForm;

            if (conn.Connect())
            {
                if (conn.InvokeRequired)
                {
                    conn.Invoke(new MethodInvoker(delegate
                    {
                        conn.BringToFront();
                        conn.Update();
                    }));
                }
                else
                {
                    conn.BringToFront();
                    conn.Update();
                }

                if (parentForm.InvokeRequired)
                {
                    parentForm.Invoke(new MethodInvoker(delegate
                    {
                        parentForm.UpdateControls();

                        if (favorite.DesktopSize == DesktopSize.FullScreen)
                        {
                            parentForm.FullScreen = true;
                        }
                    }));
                }
                else
                {
                    parentForm.UpdateControls();

                    if (favorite.DesktopSize == DesktopSize.FullScreen)
                    {
                        parentForm.FullScreen = true;
                    }
                }

                conn.AfterConnectPlugins();
            }
            else
            {
                string message = "Sorry, " + AssemblyInfo.Title + " was unable to create the connection. Try again or check the log for more information.";

                Log.Error(message);
                MessageBox.Show(message, AssemblyInfo.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (parentForm.InvokeRequired)
                {
                    parentForm.Invoke(new MethodInvoker(delegate { parentForm.RemoveAndUnSelect(terminalTabPage); }));
                }
                else
                {
                    parentForm.RemoveAndUnSelect(terminalTabPage);
                }
            }

            if (conn.Connected && favorite.NewWindow)
            {
                if (parentForm.InvokeRequired)
                {
                    parentForm.Invoke(new MethodInvoker(delegate { parentForm.DetachTabToNewWindow(terminalTabPage); }));
                }
                else
                {
                    parentForm.DetachTabToNewWindow(terminalTabPage);
                }
            }
        }