Class: StudentCreateFormController

Inherits:
Object
  • Object
show all
Defined in:
lib/source/student_create_form_controller.rb

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ StudentCreateFormController

Returns a new instance of StudentCreateFormController.



6
7
8
# File 'lib/source/student_create_form_controller.rb', line 6

def initialize(controller)
  @controller = controller
end

Instance Method Details

#on_db_conn_error(e) ⇒ Object



30
31
32
33
34
# File 'lib/source/student_create_form_controller.rb', line 30

def on_db_conn_error(e)
  api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
  api.call(0, "No connection to DB", "Error", 0)
  exit(false)
end

#on_view_createdObject



10
11
12
13
14
15
16
17
# File 'lib/source/student_create_form_controller.rb', line 10

def on_view_created
  begin
    #raise StandardError "Test"
    @student_rep = StudentList.new(StudentListDBAdapter.new)
  rescue SQLException::SQLException => e
    on_db_conn_error(e)
  end
end

#process_fields(fields) ⇒ Object



23
24
25
26
27
28
# File 'lib/source/student_create_form_controller.rb', line 23

def process_fields(fields)
  student = Student.new(**fields)
  @student_rep.add_student(student)
  @view.close
  @controller.view.refresh_current_page
end

#view=(view) ⇒ Object



19
20
21
# File 'lib/source/student_create_form_controller.rb', line 19

def view=(view)
  @view = view
end