using irisDataBase.Model;
using irisHelper;
using irisMemory;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace irisDataBase.Service.mysqlImpl
{
    public class IrisDataServiceImpl: IrisDataService
    {
        /// <summary>
        /// 从本地数据库获取iris_data表中的所有注册用户的虹膜编码，用于识别时形成CodeList
        /// </summary>
        /// <returns> Data set </returns>
        public DataSet getAllIrisCodeLocal()
        {
            if (DatabaseLocal.mySqlConnect.State == ConnectionState.Closed)
            {
                int langue= Convert.ToInt32(ConfigHelper.GetAppConfig("language"));
                if (langue == 1)
                    MessageBox.Show("与本地数据库连接断开，软件即将关闭，请检查后再启动！","提示");
                else
                    MessageBox.Show("Disconnect from local database", "message");
                Application.Exit();
                return null;
            }

            string sQry = "SELECT PERSON_ID, LEFT_IRIS_CODE1, LEFT_IRIS_CODE2, LEFT_IRIS_CODE3,RIGHT_IRIS_CODE1,RIGHT_IRIS_CODE2,RIGHT_IRIS_CODE3 FROM iris_data_view";
            MySqlCommand aCommand = new MySqlCommand(sQry, DatabaseLocal.mySqlConnect);
            MySqlDataAdapter aAdapter = new MySqlDataAdapter();
            aAdapter.SelectCommand = aCommand;
            DataSet aDataSet = new DataSet();

            try
            {
                aAdapter.Fill(aDataSet);
            }
            catch (MySqlException exSqlDb)
            {
                LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, " getAllIrisCodeLocal : " + exSqlDb.Message);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(MethodBase.GetCurrentMethod().DeclaringType, " getAllIrisCodeLocal : " + ex.Message);
            }

            return aDataSet;
        }

    }
}
