Sha256: 27b564fa563d6c42a0b2a5410a5df389115b888864b4c32c936cf0e977866190

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'win32api'

class MasterInputFormControllerCreate
  def initialize(parent_controller)
    @parent_controller = parent_controller
    @author_rep = MasterDBDataSource.new
  end

  def set_view(view)
    @view = view
  end

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

  def process_fields(fields)
    begin
      puts fields
      item = Master.new(-1, *fields.values)
      puts item
      item = @author_rep.add(item)
      @parent_controller.state_notifier.add(item)
      @view.close
    rescue ArgumentError => e
      api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
      api.call(0, e.message, 'Error', 0)
    end
  end

  private

  def on_db_conn_error
    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
jewerly_system-1.0.0 lib/source/master/controllers/master_input_form_controller_create.rb