Class: StudentInputFormControllerCreate

Inherits:
Object
  • Object
show all
Defined in:
lib/source/controllers/student_input_form/student_input_form_controller_create.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent_controller) ⇒ StudentInputFormControllerCreate

Returns a new instance of StudentInputFormControllerCreate.



6
7
8
9
# File 'lib/source/controllers/student_input_form/student_input_form_controller_create.rb', line 6

def initialize(parent_controller)
  @parent_controller = parent_controller
  LoggerHolder.instance.debug('StudentInputFormControllerCreate: initialized')
end

Instance Method Details

#on_view_createdObject



20
21
22
23
24
25
26
# File 'lib/source/controllers/student_input_form/student_input_form_controller_create.rb', line 20

def on_view_created
  begin
    @student_rep = StudentRepository.new(DBSourceAdapter.new)
  rescue Mysql2::Error::ConnectionError => e
    on_db_conn_error(e)
  end
end

#process_fields(fields) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/source/controllers/student_input_form/student_input_form_controller_create.rb', line 28

def process_fields(fields)
  begin
    last_name = fields.delete(:last_name)
    first_name = fields.delete(:first_name)
    father_name = fields.delete(:father_name)

    return if last_name.nil? || first_name.nil? || father_name.nil?

    student = Student.new(last_name, first_name, father_name, **fields)

    @student_rep.add_student(student)

    LoggerHolder.instance.debug('StudentInputFormControllerCreate: adding student to DB')

    @view.close
  rescue ArgumentError => e
    LoggerHolder.instance.debug("StudentInputFormControllerCreate: wrong fields: #{e.message}")
    api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
    api.call(0, e.message, 'Error', 0)
  end
end

#refreshObject



16
17
18
# File 'lib/source/controllers/student_input_form/student_input_form_controller_create.rb', line 16

def refresh
  @parent_controller.refresh_data(1, 20)
end

#set_view(view) ⇒ Object



11
12
13
14
# File 'lib/source/controllers/student_input_form/student_input_form_controller_create.rb', line 11

def set_view(view)
  @view = view
  LoggerHolder.instance.debug('StudentInputFormControllerCreate: view set')
end