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();
            }
        }
Пример #2
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();
            }
        }
        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();
            }
        }