package kr.co.icontrols.ilp300_700.admin.setting;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.widget.RelativeLayout;

import kr.co.icontrols.ilp300_700.MainActivity;
import kr.co.icontrols.ilp300_700.R;
import kr.co.icontrols.ilp300_700.ethernet.EthernetCtrl;
import kr.co.icontrols.ilp300_700.global.Configure;
import kr.co.icontrols.ilp300_700.global.Configure.ConfigValKey;
import kr.co.icontrols.ilp300_700.global.Configure.ConfigValue;
import kr.co.icontrols.ilp300_700.global.Configure.SetValue;
import kr.co.icontrols.ilp300_700.global.DataClasses.POSITION;
import kr.co.icontrols.ilp300_700.global.Declare;
import kr.co.icontrols.ilp300_700.global.Enumeration.DATAINPUTSTEP;
import kr.co.icontrols.ilp300_700.global.Global;
import kr.co.icontrols.ilp300_700.global.ID;
import kr.co.icontrols.wallpadsupport.WpadImageView;
import kr.co.icontrols.wallpadsupport.WpadScreen;
import kr.co.icontrols.wallpadsupport.WpadTextView;

public class AdminSet_Setting_BasicInfo extends WpadScreen {

    String TAG = "AdminSet_Setting_BasicInfo";

    boolean bLOG = true;   // true, false
    boolean bLOG_DEBUG = false;   // true, false
    boolean bLOG_INFO = true;   // true, false
    Context mContext;
    WpadImageView Image_Background;
    WpadTextView Text_Title;
    WpadTextView Text_Guide;
    WpadTextView Text_Line_01_Item;
    WpadTextView Text_Line_02_Item;
    WpadTextView Text_Line_03_Item;
    WpadTextView Text_Line_04_Item;
    WpadTextView Text_Line_01_Input;
    WpadTextView Text_Line_02_Input;
    WpadTextView Text_Line_03_Input;
    WpadTextView Text_Line_04_Input;

    int TextColor_Normal = Color.WHITE;
    int TextColor_Highlight = Color.GREEN;
    int nFontSize_Guide = 14;
    int nFontSize_Instruction = 28;
    boolean bFontNonBold = false;
    boolean bFontBold = true;

    String strText_Title = "로비폰 기본정보 설정";
    String strText_Guide = " * : 행 이동\n# : 보기 이동\n경비실 : 설정";
    String strText_Line_01_Item = "현장코드";
    String strText_Line_02_Item = "설치동";
    String strText_Line_03_Item = "로비폰 ID";
    String strText_Line_04_Item = "네트워크 옵션";
    String strText_Line_01_Input = "";
    String strText_Line_02_Input = "";
    String strText_Line_03_Input = "";
    String strText_Line_04_Input = "";
    boolean bFirstBootInput = true;   // 기기 최초부팅시 로비폰 ID값을 입력하면 정보를 입력한 것으로 간주한다.
    private int nNetworkOptionIndex = 0;
    private String[] NetworkOptionList = {"기본", "IP대역", "IP대역/A클래스", "A클래스"};
    private boolean bIPExpansion = false;
    private boolean bSubnetAClass = false;

    public AdminSet_Setting_BasicInfo(Context context, RelativeLayout layout) {
        super(context, layout);
        try {
            LOG("------------------ [START - AdminSet_Setting_BasicInfo] -------------------");

            mContext = context;
            Initialize();

            Image_Background = new WpadImageView(context, 0, Declare.DeviceInfo.getScreenSizeFullW(ConfigValue.DEVICE_MODELTYPE), Declare.DeviceInfo.getScreenSizeFullH(ConfigValue.DEVICE_MODELTYPE), R.drawable.bg_back, 0, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.IMAGES.BACKGROUND);
            ViewRegistration(layout, Image_Background, 0, 0);

            Text_Title = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.TITLE).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.TITLE).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.TITLE);
            ViewRegistration(layout, Text_Title, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.TITLE).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.TITLE).Y);
            Text_Title.setText(strText_Title);

            Text_Guide = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.GUIDE).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.GUIDE).H, Gravity.LEFT, Color.parseColor("#7d7d7d"), nFontSize_Guide, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.GUIDE);
            ViewRegistration(layout, Text_Guide, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.GUIDE).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.GUIDE).Y);
            Text_Guide.setText(strText_Guide);

            Text_Line_01_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Item).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Item);
            ViewRegistration(layout, Text_Line_01_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Item).Y);
            Text_Line_01_Item.setText(strText_Line_01_Item);

            Text_Line_02_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Item).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Item);
            ViewRegistration(layout, Text_Line_02_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Item).Y);
            Text_Line_02_Item.setText(strText_Line_02_Item);

            Text_Line_03_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Item).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Item);
            ViewRegistration(layout, Text_Line_03_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Item).Y);
            Text_Line_03_Item.setText(strText_Line_03_Item);

            Text_Line_04_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Item).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Item);
            ViewRegistration(layout, Text_Line_04_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Item).Y);
            Text_Line_04_Item.setText(strText_Line_04_Item);

            Text_Line_01_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Input).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Input);
            ViewRegistration(layout, Text_Line_01_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Input).Y);
            Text_Line_01_Input.setText("[ " + strText_Line_01_Input + " ]");

            Text_Line_02_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Input).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Input);
            ViewRegistration(layout, Text_Line_02_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Input).Y);
            Text_Line_02_Input.setText("[ " + strText_Line_02_Input + " ]");

            Text_Line_03_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Input).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Input);
            ViewRegistration(layout, Text_Line_03_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Input).Y);
            Text_Line_03_Input.setText("[ " + strText_Line_03_Input + " ]");

            Text_Line_04_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Input).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Input);
            ViewRegistration(layout, Text_Line_04_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Input).Y);
            Text_Line_04_Input.setText("[ " + strText_Line_04_Input + " ]");

            UpdateScreen();

            if (ConfigValue.eFirstBoot != SetValue.TRUE) {
                ((MainActivity) mContext).setAutoScreenChange(ID.SCREENS.Main, MainActivity.nAdminScreenTimeout);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] AdminSet_Setting_BasicInfo(Context context, RelativeLayout layout)");
            e.printStackTrace();
        }
    }

    private void LOG(String log) {
        if (bLOG) Log.v(TAG, log);
    }

    private void LOG_DEBUG(String log) {
        if (bLOG_DEBUG) Log.d(TAG, log);
    }

    private void LOG_INFO(String log) {
        if (bLOG_INFO) Log.i(TAG, log);
    }

    protected void Initialize() {
        try {
            Global.DataInputStep = DATAINPUTSTEP.INPUT_01;
            nNetworkOptionIndex = 0;

            strText_Line_01_Input = ConfigValue.strSitecode;
            strText_Line_02_Input = ConfigValue.strDevice_Dong;
            strText_Line_03_Input = ConfigValue.strDevice_ID;
            strText_Line_04_Input = getNetworkOption();

            if (ConfigValue.eFirstBoot == SetValue.TRUE) bFirstBootInput = false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] Initialize() : " + e);
            e.printStackTrace();
        }
    }

    @Override
    protected void onClose() {
        try {
            LOG("------------------ [onClose - AdminSet_Setting_BasicInfo] -------------------");
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onClose() : " + e);
            e.printStackTrace();
        }
        super.onClose();
    }

    @Override
    protected void onBrReceive(Intent intent) {
        try {
            LOG("[onBrReceive] Intent : " + intent);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onBrReceive(...) : " + e);
            e.printStackTrace();
        }
        super.onBrReceive(intent);
    }

    @Override
    protected void onKeyDown(int keyCode, KeyEvent event) {
        try {
            LOG("[onKeyDown] keyCode [" + keyCode + "]");
            if (Declare.Button.NUMBER_00 <= keyCode && keyCode <= Declare.Button.NUMBER_09) {
                if (Global.DataInputStep == DATAINPUTSTEP.INPUT_01) {
                    strText_Line_01_Input += keyCode - 7;

                    if (strText_Line_01_Input.length() > 8) {
                        strText_Line_01_Input = strText_Line_01_Input.substring(1);
                    }
                } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_02) {
                    strText_Line_02_Input += keyCode - 7;

                    if (strText_Line_02_Input.length() > 4) {
                        strText_Line_02_Input = strText_Line_02_Input.substring(1);
                    }
                    strText_Line_02_Input = String.valueOf(Integer.parseInt(strText_Line_02_Input));
                } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_03) {
                    strText_Line_03_Input += keyCode - 7;

                    if (strText_Line_03_Input.length() > 2) {
                        strText_Line_03_Input = strText_Line_03_Input.substring(1);
                    }
                    strText_Line_03_Input = String.valueOf(Integer.parseInt(strText_Line_03_Input));
                }
                UpdateScreen();
            } else if (keyCode == Declare.Button.STAR) {
                if (Global.DataInputStep == DATAINPUTSTEP.INPUT_01) {
                    Global.DataInputStep = DATAINPUTSTEP.INPUT_02;
                } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_02) {
                    Global.DataInputStep = DATAINPUTSTEP.INPUT_03;
                } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_03) {
                    if (bFirstBootInput == false && ConfigValue.eFirstBoot == SetValue.TRUE)
                        bFirstBootInput = true;
                    Global.DataInputStep = DATAINPUTSTEP.INPUT_04;
                } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_04) {
                    Global.DataInputStep = DATAINPUTSTEP.INPUT_01;
                }
                UpdateScreen();
            } else if (keyCode == Declare.Button.SHARP) {
                if (Global.DataInputStep == DATAINPUTSTEP.INPUT_04) {
                    nNetworkOptionIndex++;
                    if (nNetworkOptionIndex >= NetworkOptionList.length) nNetworkOptionIndex = 0;
                    strText_Line_04_Input = NetworkOptionList[nNetworkOptionIndex];
                    setNetworkOption(nNetworkOptionIndex);
                }
                UpdateScreen();
            } else if (keyCode == Declare.Button.GUARD) {
                // 설정정보를 저장하는 기능을 정의한다.
                if (bFirstBootInput) {
                    if (setBasicInfo(strText_Line_01_Input, strText_Line_02_Input, strText_Line_03_Input, bIPExpansion, bSubnetAClass)) {
                        if (ConfigValue.eFirstBoot == SetValue.TRUE) {
                            if (setMainServerType(SetValue.ServerMixed_Integrated)) {
                                MainActivity.mIOInterface.setDns(Configure.DefaultConfigValue.strDNS2IPAddress, Declare.Const.DNS_IP2);
                                MainActivity.mSound.PlayMent_lobby(R.raw.setting);
                            }
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_MainSub);
                        } else {
                            MainActivity.mSound.PlayMent_lobby(R.raw.setting);
                            super.setChangeScreen(ID.SCREENS.Reboot);
                        }
                    } else {
                        LOG("[setBasicInfo] Input data is wrong!!");
                        MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                        Initialize();
                        UpdateScreen();
                    }
                } else {
                    LOG("[setBasicInfo] bFirstBootInput = " + bFirstBootInput);
                    MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                    Initialize();
                    UpdateScreen();
                }
            } else if (keyCode == Declare.Button.CANCEL || keyCode == Declare.Button.TACT_CANCEL) {
                if (ConfigValue.eFirstBoot != SetValue.TRUE) {
                    super.setChangeScreen(ID.SCREENS.AdminSet_Setting);
                } else {
                    Initialize();
                    MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                    UpdateScreen();
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onKeyDown(int keyCode, KeyEvent event)");
            e.printStackTrace();
        }
        super.onKeyDown(keyCode, event);
    }

    private boolean setMainServerType(SetValue eSetValue) {
        try {
            LOG("[setMainServerType] eSetValue [" + eSetValue + "]");
            boolean biMAPServerRestart = false;

            if (eSetValue == SetValue.Server_Separated) {
                if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated)
                    biMAPServerRestart = true;

                ConfigValue.eMainServerType = SetValue.Server_Separated;
                ConfigValue.eSubServerType = SetValue.Server_Separated;
                ConfigValue.strMainServerIPAddress = Configure.DefaultConfigValue.strMainServerIPAddress;
                ConfigValue.strMonitoringPCIPAddress = Configure.DefaultConfigValue.strMonitoringPCIPAddress;
                ConfigValue.strDNSIPAddress = Configure.DefaultConfigValue.strDNSIPAddress;
                ConfigValue.nMainServerPortNum = Declare.TargetPort.nServer1_X;
            } else if (eSetValue == SetValue.Server_Integrated) {
                if (ConfigValue.eMainServerType == SetValue.Server2dot0_Integrated)
                    biMAPServerRestart = true;

                ConfigValue.eMainServerType = SetValue.Server_Integrated;
                ConfigValue.eSubServerType = SetValue.Server_Integrated;
                ConfigValue.strMonitoringPCIPAddress = Configure.DefaultConfigValue.strMainServerIPAddress;
                ConfigValue.strDNSIPAddress = Configure.DefaultConfigValue.strDNSIPAddress;
                ConfigValue.nMainServerPortNum = Declare.TargetPort.nServer1_X;
            } else if (eSetValue == SetValue.Server2dot0_Integrated) {
                if ((ConfigValue.eMainServerType != SetValue.Server2dot0_Integrated)||(ConfigValue.eSubServerType != SetValue.Server2dot0_Integrated))
                    biMAPServerRestart = true;

                ConfigValue.eMainServerType = SetValue.Server2dot0_Integrated;
                ConfigValue.eSubServerType = SetValue.Server2dot0_Integrated;
                ConfigValue.strMainServerIPAddress = Configure.DefaultConfigValue.strMainServerIPAddress;
                ConfigValue.strMonitoringPCIPAddress = Configure.DefaultConfigValue.strMainServerIPAddress;
                ConfigValue.strDNSIPAddress = Configure.DefaultConfigValue.strDNSIPAddress;
                ConfigValue.nMainServerPortNum = Declare.TargetPort.nServer2_0;
            } else if (eSetValue == SetValue.ServerMixed_Integrated) {
                if (ConfigValue.eSubServerType != SetValue.ServerMixed_Integrated)
                    biMAPServerRestart = true;

                ConfigValue.eMainServerType = SetValue.Server2dot0_Integrated;
                //ConfigValue.eMainServerType = SetValue.ServerMixed_Integrated;
                ConfigValue.eSubServerType = SetValue.ServerMixed_Integrated;
                ConfigValue.strMonitoringPCIPAddress = Configure.DefaultConfigValue.strMainServer2IPAddress;
                ConfigValue.strMainServerIPAddress = Configure.DefaultConfigValue.strMainServer2IPAddress;
                ConfigValue.strDNSIPAddress = Configure.DefaultConfigValue.strDNS2IPAddress;
                ConfigValue.nMainServerPortNum = Declare.TargetPort.nServer2_0;
                ConfigValue.nSubServerPortNum = Declare.TargetPort.nServer1_X;
            } else {
                Log.w(TAG, "[setMainServerType] eSetValue is not available!!");
                return false;
            }

            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainServerType, ConfigValue.eMainServerType))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.SubServerType, ConfigValue.eSubServerType))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MonitoringPCIPAddress, ConfigValue.strMonitoringPCIPAddress))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainServerIPAddress, ConfigValue.strMainServerIPAddress))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.DNSIPAddress, ConfigValue.strDNSIPAddress))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainServerPortNum, ConfigValue.nMainServerPortNum))
                return false;

            Log.i(TAG, "[setMainServerType] biMAPServerRestart [" + biMAPServerRestart + "], ConfigValue.eMainServerType [" + ConfigValue.eMainServerType + "]");
            Log.i(TAG, "[setMainServerType] ConfigValue.strMonitoringPCIPAddress [" + ConfigValue.strMonitoringPCIPAddress + "], ConfigValue.nMainServerPortNum [" + ConfigValue.nMainServerPortNum + "]");

            if (biMAPServerRestart) ((MainActivity) mContext).restartiMAPServer();

            ((MainActivity) mContext).sendHandlerMsgDelayed(MainActivity.HANDLERMSG.SEND_HEARTBEAT_NOTICE, 0, 0, 2000);

            return true;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setMainServerType(SetValue eSetValue)");
            e.printStackTrace();
            return false;
        }
    }

    protected void UpdateScreen() {
        try {
//            LOG("[updateScreen] Start!!");
            if (Global.DataInputStep == DATAINPUTSTEP.INPUT_01) {
                Text_Line_01_Input.setText("[ " + strText_Line_01_Input + " ]");
                Text_Line_01_Item.setTextColor(TextColor_Highlight);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_01_Input.setTextColor(TextColor_Highlight);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Normal);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
            } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_02) {
                Text_Line_02_Input.setText("[ " + strText_Line_02_Input + " ]");
                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Highlight);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Highlight);
                Text_Line_03_Input.setTextColor(TextColor_Normal);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
            } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_03) {
                Text_Line_03_Input.setText("[ " + strText_Line_03_Input + " ]");
                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Highlight);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Highlight);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
            } else if (Global.DataInputStep == DATAINPUTSTEP.INPUT_04) {
                Text_Line_04_Input.setText("[ " + strText_Line_04_Input + " ]");
                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Highlight);
                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Normal);
                Text_Line_04_Input.setTextColor(TextColor_Highlight);
            } else {
                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Normal);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] updateScreen() : " + e);
            e.printStackTrace();
        }
    }

    private POSITION getPosition(int nID) {
//        LOG("[getPosition] Start!!");
        POSITION position = new POSITION();
        position.SetPosition(0, 0, 480, 272);
        try {
            switch (nID) {
                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.IMAGES.BACKGROUND:
                    position.SetPosition(0, 0, 480, 272);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.TITLE:
                    position.SetPosition(0, 24, 480, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.GUIDE:
                    position.SetPosition(382, 10, 98, 55);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Item:
                    position.SetPosition(30, 73, 165, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Item:
                    position.SetPosition(30, 122, 165, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Item:
                    position.SetPosition(30, 171, 165, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Item:
                    position.SetPosition(30, 220, 165, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_01_Input:
                    position.SetPosition(205, 73, 245, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_02_Input:
                    position.SetPosition(205, 122, 245, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_03_Input:
                    position.SetPosition(205, 171, 245, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_BASICINFO.ELEMENTS.TEXTS.LINE_04_Input:
                    position.SetPosition(205, 220, 245, 40);
                    return position;

                default:
                    return position;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] getPosition() : " + e);
            e.printStackTrace();
            return position;
        }
    }

    private boolean setBasicInfo(String sitecode, String dong, String id, boolean bIPExpansion, boolean bSubnetAClass) {
        try {
            LOG("[setBasicInfo] sitecode [" + sitecode + "], dong [" + dong + "], id [" + id + "], bIPExpansion [" + bIPExpansion + "], bSubnetAClass [" + bSubnetAClass + "]");
            if (sitecode.length() != 8) return false;
            if (dong.length() < 3 || 4 < dong.length()) return false;
            if (id.length() < 1 || 2 < id.length()) return false;

            if (bIPExpansion) setIPExpansion(SetValue.TRUE);
            else setIPExpansion(SetValue.FALSE);

            return EthernetCtrl.setDeviceIPAddressByBasicInfo(mContext, sitecode, dong, id, bSubnetAClass);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setBasicInfo(sitecode, dong, id)");
            e.printStackTrace();
            return false;
        }
    }

    private String getNetworkOption() {
        try {
            if (ConfigValue.eIPExpansion == SetValue.TRUE) {
                if (ConfigValue.strSubnetmask.equals("255.255.0.0")) {
                    nNetworkOptionIndex = 1;
                    setNetworkOption(nNetworkOptionIndex);
                    return NetworkOptionList[nNetworkOptionIndex];
                } else if (ConfigValue.strSubnetmask.equals("255.0.0.0")) {
                    nNetworkOptionIndex = 2;
                    setNetworkOption(nNetworkOptionIndex);
                    return NetworkOptionList[nNetworkOptionIndex];
                }
            } else if (ConfigValue.eIPExpansion == SetValue.FALSE) {
                if (ConfigValue.strSubnetmask.equals("255.255.0.0")) {
                    nNetworkOptionIndex = 0;
                    setNetworkOption(nNetworkOptionIndex);
                    return NetworkOptionList[nNetworkOptionIndex];
                } else if (ConfigValue.strSubnetmask.equals("255.0.0.0")) {
                    nNetworkOptionIndex = 3;
                    setNetworkOption(nNetworkOptionIndex);
                    return NetworkOptionList[nNetworkOptionIndex];
                }
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] getNetworkOption()");
            e.printStackTrace();
            return null;
        }
        return "NONE";
    }

    private void setNetworkOption(int nOpt) {
        try {
            if (nOpt == 0) {
                bIPExpansion = false;
                bSubnetAClass = false;
            } else if (nOpt == 1) {
                bIPExpansion = true;
                bSubnetAClass = false;
            } else if (nOpt == 2) {
                bIPExpansion = true;
                bSubnetAClass = true;
            } else if (nOpt == 3) {
                bIPExpansion = false;
                bSubnetAClass = true;
            } else {
                bIPExpansion = false;
                bSubnetAClass = false;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setNetworkOption(int nOpt)");
            e.printStackTrace();
        }
    }

    private boolean setIPExpansion(SetValue eSetValue) {
        try {
            LOG("[setIPExpansion] eSetValue [" + eSetValue + "]");
            ConfigValue.eIPExpansion = eSetValue;
            return MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.IPExpansion, ConfigValue.eIPExpansion);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setIPExpansion(SetValue eSetValue)");
            e.printStackTrace();
            return false;
        }
    }

}
