Exemplo n.º 1
0
 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();
            }
        }
Exemplo n.º 4
0
        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();
            }
        }