Sha256: f55631b89e27963e0d02e8964e3f696222047207fb55158c4ce95854e29eaca6
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
# frozen_string_literal: true require 'win32api' require_relative '../util/LoggerHolder' class StudentInputFormController def initialize(parent_controller) @parent_controller = parent_controller LoggerHolder.instance.debug('StudentInputFormController: initialized') end def set_view(view) @view = view end def refresh @parent_controller.refresh_data(1,20) end def on_view_created begin @student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance)) rescue Mysql2::Error::ConnectionError=>e on_db_conn_error(e) end end def process_fields(fields) begin last_name = fields.delete(:last_name) first_name = fields.delete(:first_name) parental_name = fields.delete(:parental_name) return if last_name.nil? || first_name.nil? || parental_name.nil? student = Student.new(last_name, first_name, parental_name, **fields) @student_list.add_student(student) LoggerHolder.instance.debug('StudentInputFormController: adding student to DB') @view.close rescue ArgumentError => e api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I') LoggerHolder.instance.debug("StudentInputFormController: wrong fields: #{e.message}") api.call(0, e.message, 'Error', 0) end end def on_db_conn_error(error) LoggerHolder.instance.debug('StudentInputFormController: DB connection error:') LoggerHolder.instance.error(error.message) api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I') api.call(0, "No connection to DB", "Error", 0) @view.close end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mc_gem-0.0.1 | mc_gem/lib/source/controllers/student_input_form_controller.rb |