using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using NetClient;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.IO;

namespace LogDemo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private LogClient m_Client = null;
        private const int PageviewNumber = 50;

        private ObservableCollection<LogInfo> LogInfoList
        {
            get;
            set;
        }

        public MainWindow()
        {
            LoadLanguage();
            InitializeComponent();
            try
            {
                m_Client = new LogClient();
                m_Client.WaitTime = 5000;
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
                Process.GetCurrentProcess().Kill();
            }
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }

        private void LoadLanguage()
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "Language";
            string fileNamePath = string.Empty;
            ResourceDictionary resourceDictionary = new ResourceDictionary();
            switch (System.Globalization.CultureInfo.CurrentCulture.LCID)
            {
                case 0x00804:
                    fileNamePath = path + "\\zh-cn.xaml";
                    if (!File.Exists(fileNamePath))
                    {
                        resourceDictionary.Source = new Uri("pack://application:,,,/language/zh-cn.xaml");
                    }
                    else
                    {
                        resourceDictionary.Source = new Uri(fileNamePath, UriKind.RelativeOrAbsolute);
                    }
                    break;
                default:
                    fileNamePath = path + "\\en-us.xaml";
                    if (!File.Exists(fileNamePath))
                    {
                        resourceDictionary.Source = new Uri("pack://application:,,,/language/en-us.xaml");
                    }
                    else
                    {
                        resourceDictionary.Source = new Uri(fileNamePath, UriKind.RelativeOrAbsolute);
                    }
                    break;
            }
            App.Current.Resources.MergedDictionaries.Add(resourceDictionary);
        }

        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            m_Client.PageviewNumber = PageviewNumber;

            type_comboBox.Items.Add((string)App.Current.Resources["ID_ALL_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_SYSTEM_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_CONFIG_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_STORAGE_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_ALARM_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_RECORD_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_ACCOUNT_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_CLEAR_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_PLAYBACK_LOG"]);
            type_comboBox.Items.Add((string)App.Current.Resources["ID_MANAGER_LOG"]);
            type_comboBox.SelectedIndex = 0;

            login_btn.IsEnabled = true;
            logout_btn.IsEnabled = false;
            type_comboBox.IsEnabled = false;
            startTimeD_Picker.Enabled = false;
            startTime_Picker.Enabled = false;
            endTimeD_Picker.Enabled = false;
            endTime_Picker.Enabled = false;
            query_btn.IsEnabled = false;
            prepage_btn.IsEnabled = false;
            nextpage_btn.IsEnabled = false;
        }

        private void Port_TextInput(object sender, TextCompositionEventArgs e)
        {
            try
            {
                Convert.ToUInt32(e.Text);
                e.Handled = false;
            }
            catch
            {
                e.Handled = true;
            }
        }

        private void Login_Clicked(object sender, RoutedEventArgs e)
        {
            string ip = ip_textbox.Text.Trim();
            if (ip == "" || ip == null)
            {
                MessageBox.Show((string)App.Current.Resources["ID_IP_ERROR"]);
                return;
            }
            ushort port = 0;
            string portString = port_textbox.Text.Trim();
            if (portString == null || portString == "")
            {
                MessageBox.Show((string)App.Current.Resources["ID_PORT_ERROR1"]);
                return;
            }
            try
            {
                port = Convert.ToUInt16(port_textbox.Text.Trim());
            }
            catch
            {
                MessageBox.Show((string)App.Current.Resources["ID_PORT_ERROR2"]);
                return;
            }
            string username = username_textbox.Text.Trim();
            if (username == null || username == "")
            {
                MessageBox.Show((string)App.Current.Resources["ID_USERNAME_ERROR"]);
                return;
            }
            string password= password_textbox.Password.Trim();
            try
            {
                m_Client.Login(ip, port, username, password);
            }
            catch (NETClientExcetion ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            NET_DEV_ENABLE_INFO devEnableInfo = new NET_DEV_ENABLE_INFO();
            object obj = devEnableInfo;
            try
            {
                m_Client.QuerySystemInfo(EM_SYS_ABILITY.DEVALL_INFO, ref obj);
            }
            catch (NETClientExcetion ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            devEnableInfo = (NET_DEV_ENABLE_INFO)obj;
            if (devEnableInfo.IsFucEnable[(int)EM_DEV_ENABLE_TYPE.LOG] == 0)
            {
                MessageBox.Show((string)App.Current.Resources["ID_NOT_SUPPORT"]);
                return;
            }

            LogInfoList = new ObservableCollection<LogInfo>();
            LogInfoList.Clear();
            login_btn.IsEnabled = false;
            logout_btn.IsEnabled = true;
            type_comboBox.IsEnabled = true;
            startTimeD_Picker.Enabled = true;
            startTime_Picker.Enabled = true;
            endTimeD_Picker.Enabled = true;
            endTime_Picker.Enabled = true;
            query_btn.IsEnabled = true;
        }

        private void Logout_Clicked(object sender, RoutedEventArgs e)
        {
            m_Client.Logout();
            LogInfoList = null;
            log_listview.ItemsSource = null;
            login_btn.IsEnabled = true;
            logout_btn.IsEnabled = false;
            type_comboBox.IsEnabled = false;
            startTimeD_Picker.Enabled = false;
            startTime_Picker.Enabled = false;
            endTimeD_Picker.Enabled = false;
            endTime_Picker.Enabled = false;
            query_btn.IsEnabled = false;
            prepage_btn.IsEnabled = false;
            nextpage_btn.IsEnabled = false;
        }

        private void Query_Clicked(object sender, RoutedEventArgs e)
        {
            DateTime startTime = new DateTime(startTimeD_Picker.Value.Year, startTimeD_Picker.Value.Month, startTimeD_Picker.Value.Day, startTime_Picker.Value.Hour, startTime_Picker.Value.Minute, startTime_Picker.Value.Second);
            DateTime endTime = new DateTime(endTimeD_Picker.Value.Year, endTimeD_Picker.Value.Month, endTimeD_Picker.Value.Day, endTime_Picker.Value.Hour, endTime_Picker.Value.Minute, endTime_Picker.Value.Second);
            if (startTime == endTime)
            {
                MessageBox.Show((string)App.Current.Resources["ID_TIME_ERROR1"]);
                return;
            }
            if (startTime > endTime)
            {
                MessageBox.Show((string)App.Current.Resources["ID_TIME_ERROR2"]);
                return;
            }
            List<NET_DEVICE_LOG_ITEM_EX> loglist;
            try
            {
                loglist = m_Client.Query((EM_LOG_QUERY_TYPE)type_comboBox.SelectedIndex, startTime, endTime);
            }
            catch (NETClientExcetion ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            if (loglist == null)
            {
                MessageBox.Show((string)App.Current.Resources["ID_NONELOG"]);
                return;
            }
            prepage_btn.IsEnabled = false;
            if (m_Client.IsNextPage)
            {
                nextpage_btn.IsEnabled = true;
            }
            else
            {
                nextpage_btn.IsEnabled = false;
            }
            ShowLog(loglist);
        }

        private void ShowLog(List<NET_DEVICE_LOG_ITEM_EX> loglist)
        {
            LogInfoList.Clear();
            foreach (var item in loglist)
            {
                LogInfo info = new LogInfo();
                info.ID = (loglist.IndexOf(item) + 1).ToString();
                info.LOGTYPE = ConvertType(item.nLogType);
                info.TIME = item.stuOperateTime.ToString();
                info.LOGCONTENT = ConvertString(item.szDetailContext);
                
                LogInfoList.Add(info);
            }
            log_listview.ItemsSource = null;
            log_listview.ItemsSource = LogInfoList;
        }

        private string ConvertType(int type)
        {
            switch (type)
            {
                case (int)EM_LOG_TYPE.REBOOT:
                    return (string)App.Current.Resources["ID_REBOOT_LOG"];
                case (int)EM_LOG_TYPE.SHUT:
                    return (string)App.Current.Resources["ID_SHUT_LOG"];
                case (int)EM_LOG_TYPE.REPORTSTOP:
                    return (string)App.Current.Resources["ID_REPORTSTOP_LOG"];
                case (int)EM_LOG_TYPE.REPORTSTART:
                    return (string)App.Current.Resources["ID_REPORTSTART_LOG"];
                case (int)EM_LOG_TYPE.UPGRADE:
                    return (string)App.Current.Resources["ID_UPGRADE_LOG"];
                case (int)EM_LOG_TYPE.SYSTIME_UPDATE:
                    return (string)App.Current.Resources["ID_SYSTIME_UPDATE_LOG"];
                case (int)EM_LOG_TYPE.GPS_TIME_UPDATE:
                    return (string)App.Current.Resources["ID_GPS_TIME_UPDATE_LOG"];
                case (int)EM_LOG_TYPE.AUDIO_TALKBACK:
                    return (string)App.Current.Resources["ID_AUDIO_TALKBACK_LOG"];
                case (int)EM_LOG_TYPE.COMM_ADAPTER:
                    return (string)App.Current.Resources["ID_COMM_ADAPTER_LOG"];
                case (int)EM_LOG_TYPE.NET_TIMING:
                    return (string)App.Current.Resources["ID_NET_TIMING_LOG"];
                case (int)EM_LOG_TYPE.TYPE_NR:
                    return (string)App.Current.Resources["ID_TYPE_NR_LOG"];
                case (int)EM_LOG_TYPE.CONFSAVE:
                    return (string)App.Current.Resources["ID_CONFSAVE_LOG"];
                case (int)EM_LOG_TYPE.CONFLOAD:
                    return (string)App.Current.Resources["ID_CONFLOAD_LOG"];
                case (int)EM_LOG_TYPE.FSERROR:
                    return (string)App.Current.Resources["ID_FSERROR_LOG"];
                case (int)EM_LOG_TYPE.HDD_WERR:
                    return (string)App.Current.Resources["ID_HDD_WERR_LOG"];
                case (int)EM_LOG_TYPE.HDD_RERR:
                    return (string)App.Current.Resources["ID_HDD_RERR_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE:
                    return (string)App.Current.Resources["ID_HDD_TYPE_LOG"];
                case (int)EM_LOG_TYPE.HDD_FORMAT:
                    return (string)App.Current.Resources["ID_HDD_FORMAT_LOG"];
                case (int)EM_LOG_TYPE.HDD_NOSPACE:
                    return (string)App.Current.Resources["ID_HDD_NOSPACE_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_RW:
                    return (string)App.Current.Resources["ID_HDD_TYPE_RW_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_RO:
                    return (string)App.Current.Resources["ID_HDD_TYPE_RO_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_RE:
                    return (string)App.Current.Resources["ID_HDD_TYPE_RE_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_SS:
                    return (string)App.Current.Resources["ID_HDD_TYPE_SS_LOG"];
                case (int)EM_LOG_TYPE.HDD_NONE:
                    return (string)App.Current.Resources["ID_HDD_NONE_LOG"];
                case (int)EM_LOG_TYPE.HDD_NOWORKHDD:
                    return (string)App.Current.Resources["ID_HDD_NOWORKHDD_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_BK:
                    return (string)App.Current.Resources["ID_HDD_TYPE_BK_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_REVERSE:
                    return (string)App.Current.Resources["ID_HDD_TYPE_REVERSE_LOG"];
                case (int)EM_LOG_TYPE.HDD_START_INFO:
                    return (string)App.Current.Resources["ID_HDD_START_INFO_LOG"];
                case (int)EM_LOG_TYPE.HDD_WORKING_DISK:
                    return (string)App.Current.Resources["ID_HDD_WORKING_DISK_LOG"];
                case (int)EM_LOG_TYPE.HDD_OTHER_ERROR:
                    return (string)App.Current.Resources["ID_HDD_OTHER_ERROR_LOG"];
                case (int)EM_LOG_TYPE.HDD_SLIGHT_ERR:
                    return (string)App.Current.Resources["ID_HDD_SLIGHT_ERR_LOG"];
                case (int)EM_LOG_TYPE.HDD_SERIOUS_ERR:
                    return (string)App.Current.Resources["ID_HDD_SERIOUS_ERR_LOG"];
                case (int)EM_LOG_TYPE.HDD_NOSPACE_END:
                    return (string)App.Current.Resources["ID_HDD_NOSPACE_END_LOG"];
                case (int)EM_LOG_TYPE.HDD_TYPE_RAID_CONTROL:
                    return (string)App.Current.Resources["ID_TYPE_RAID_CONTROL_LOG"];
                case (int)EM_LOG_TYPE.HDD_TEMPERATURE_HIGH:
                    return (string)App.Current.Resources["ID_HDD_TEMPERATURE_HIGH_LOG"];
                case (int)EM_LOG_TYPE.HDD_TEMPERATURE_LOW:
                    return (string)App.Current.Resources["ID_HDD_TEMPERATURE_LOW_LOG"];
                case (int)EM_LOG_TYPE.HDD_ESATA_REMOVE:
                    return (string)App.Current.Resources["ID_HDD_ESATA_REMOVE_LOG"];
                case (int)EM_LOG_TYPE.ALM_IN:
                    return (string)App.Current.Resources["ID_ALM_IN_LOG"];
                case (int)EM_LOG_TYPE.NETALM_IN:
                    return (string)App.Current.Resources["ID_NETALM_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_END:
                    return (string)App.Current.Resources["ID_ALM_END_LOG"];
                case (int)EM_LOG_TYPE.LOSS_IN:
                    return (string)App.Current.Resources["ID_LOSS_IN_LOG"];
                case (int)EM_LOG_TYPE.LOSS_END:
                    return (string)App.Current.Resources["ID_LOSS_END_LOG"];
                case (int)EM_LOG_TYPE.MOTION_IN:
                    return (string)App.Current.Resources["ID_MOTION_IN_LOG"];
                case (int)EM_LOG_TYPE.MOTION_END:
                    return (string)App.Current.Resources["ID_MOTION_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_BOSHI:
                    return (string)App.Current.Resources["ID_ALM_BOSHI_LOG"];
                case (int)EM_LOG_TYPE.NET_ABORT:
                    return (string)App.Current.Resources["ID_NET_ABORT_LOG"];
                case (int)EM_LOG_TYPE.NET_ABORT_RESUME:
                    return (string)App.Current.Resources["ID_NET_ABORT_RESUME_LOG"];
                case (int)EM_LOG_TYPE.CODER_BREAKDOWN:
                    return (string)App.Current.Resources["ID_CODER_BREAKDOWN_LOG"];
                case (int)EM_LOG_TYPE.CODER_BREAKDOWN_RESUME:
                    return (string)App.Current.Resources["ID_CODER_BREAKDOWN_RESUME_LOG"];
                case (int)EM_LOG_TYPE.BLIND_IN:
                    return (string)App.Current.Resources["ID_BLIND_IN_LOG"];
                case (int)EM_LOG_TYPE.BLIND_END:
                    return (string)App.Current.Resources["ID_BLIND_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_TEMP_HIGH:
                    return (string)App.Current.Resources["ID_ALM_TEMP_HIGH_LOG"];
                case (int)EM_LOG_TYPE.ALM_VOLTAGE_LOW:
                    return (string)App.Current.Resources["ID_ALM_VOLTAGE_LOW_LOG"];
                case (int)EM_LOG_TYPE.ALM_BATTERY_LOW:
                    return (string)App.Current.Resources["ID_ALM_BATTERY_LOW_LOG"];
                case (int)EM_LOG_TYPE.ALM_ACC_BREAK:
                    return (string)App.Current.Resources["ID_ALM_ACC_BREAK_LOG"];
                case (int)EM_LOG_TYPE.ALM_ACC_RES:
                    return (string)App.Current.Resources["ID_ALM_ACC_RES_LOG"];
                case (int)EM_LOG_TYPE.GPS_SIGNAL_LOST:
                    return (string)App.Current.Resources["ID_GPS_SIGNAL_LOST_LOG"];
                case (int)EM_LOG_TYPE.GPS_SIGNAL_RESUME:
                    return (string)App.Current.Resources["ID_GPS_SIGNAL_RESUME_LOG"];
                case (int)EM_LOG_TYPE.LOG_3G_SIGNAL_LOST:
                    return (string)App.Current.Resources["ID_3G_SIGNAL_LOST_LOG"];
                case (int)EM_LOG_TYPE.LOG_3G_SIGNAL_RESUME:
                    return (string)App.Current.Resources["ID_3G_SIGNAL_RESUME_LOG"];
                case (int)EM_LOG_TYPE.ALM_IPC_IN:
                    return (string)App.Current.Resources["ID_ALM_IPC_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_IPC_END:
                    return (string)App.Current.Resources["ID_ALM_IPC_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_DIS_IN:
                    return (string)App.Current.Resources["ID_ALM_DIS_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_DIS_END:
                    return (string)App.Current.Resources["ID_ALM_DIS_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_UPS_IN:
                    return (string)App.Current.Resources["ID_ALM_UPS_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_UPS_END:
                    return (string)App.Current.Resources["ID_ALM_UPS_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_NAS_IN:
                    return (string)App.Current.Resources["ID_ALM_NAS_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_NAS_END:
                    return (string)App.Current.Resources["ID_ALM_NAS_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_REDUNDANT_POWER_IN:
                    return (string)App.Current.Resources["ID_ALM_REDUNDANT_POWER_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_REDUNDANT_POWER_END:
                    return (string)App.Current.Resources["ID_ALM_REDUNDANT_POWER_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_RECORD_FAILED_IN:
                    return (string)App.Current.Resources["ID_ALM_RECORD_FAILED_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_RECORD_FAILED_END:
                    return (string)App.Current.Resources["ID_ALM_RECORD_FAILED_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_VGEXCEPT_IN:
                    return (string)App.Current.Resources["ID_ALM_VGEXCEPT_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_VGEXCEPT_END:
                    return (string)App.Current.Resources["ID_ALM_VGEXCEPT_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_FANSPEED_IN:
                    return (string)App.Current.Resources["ID_ALM_FANSPEED_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_FANSPEED_END:
                    return (string)App.Current.Resources["ID_ALM_FANSPEED_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_DROP_FRAME_IN:
                    return (string)App.Current.Resources["ID_ALM_DROP_FRAME_IN_LOG"];
                case (int)EM_LOG_TYPE.ALM_DROP_FRAME_END:
                    return (string)App.Current.Resources["ID_ALM_DROP_FRAME_END_LOG"];
                case (int)EM_LOG_TYPE.ALM_DISK_STATE_CHECK:
                    return (string)App.Current.Resources["ID_ALM_DISK_STATE_CHECK_LOG"];
                case (int)EM_LOG_TYPE.ALARM_COAXIAL_SMOKE:
                    return (string)App.Current.Resources["ID_ALARM_COAXIAL_SMOKE_LOG"];
                case (int)EM_LOG_TYPE.ALARM_COAXIAL_TEMP_HIGH:
                    return (string)App.Current.Resources["ID_ALARM_COAXIAL_TEMP_HIGH_LOG"];
                case (int)EM_LOG_TYPE.ALARM_COAXIAL_ALM_IN:
                    return (string)App.Current.Resources["ID_ALARM_COAXIAL_ALM_IN_LOG"];
                case (int)EM_LOG_TYPE.INFRAREDALM_IN:
                    return (string)App.Current.Resources["ID_INFRAREDALM_IN_LOG"];
                case (int)EM_LOG_TYPE.INFRAREDALM_END:
                    return (string)App.Current.Resources["ID_INFRAREDALM_END_LOG"];
                case (int)EM_LOG_TYPE.IPCONFLICT:
                    return (string)App.Current.Resources["ID_IPCONFLICT_LOG"];
                case (int)EM_LOG_TYPE.IPCONFLICT_RESUME:
                    return (string)App.Current.Resources["ID_IPCONFLICT_RESUME_LOG"];
                case (int)EM_LOG_TYPE.SDPLUG_IN:
                    return (string)App.Current.Resources["ID_SDPLUG_IN_LOG"];
                case (int)EM_LOG_TYPE.SDPLUG_OUT:
                    return (string)App.Current.Resources["ID_SDPLUG_OUT_LOG"];
                case (int)EM_LOG_TYPE.NET_PORT_BIND_FAILED:
                    return (string)App.Current.Resources["ID_NET_PORT_BIND_FAILED_LOG"];
                case (int)EM_LOG_TYPE.HDD_BEEP_RESET:
                    return (string)App.Current.Resources["ID_HDD_BEEP_RESET_LOG"];
                case (int)EM_LOG_TYPE.MAC_CONFLICT:
                    return (string)App.Current.Resources["ID_MAC_CONFLICT_LOG"];
                case (int)EM_LOG_TYPE.MAC_CONFLICT_RESUME:
                    return (string)App.Current.Resources["ID_MAC_CONFLICT_RESUME_LOG"];
                case (int)EM_LOG_TYPE.ALARM_OUT:
                    return (string)App.Current.Resources["ID_ALARM_OUT_LOG"];
                case (int)EM_LOG_TYPE.ALM_RAID_STAT_EVENT:
                    return (string)App.Current.Resources["ID_ALM_RAID_STAT_EVENT_LOG"];
                case (int)EM_LOG_TYPE.ABLAZE_ON:
                    return (string)App.Current.Resources["ID_ABLAZE_ON_LOG"];
                case (int)EM_LOG_TYPE.ABLAZE_OFF:
                    return (string)App.Current.Resources["ID_ABLAZE_OFF_LOG"];
                case (int)EM_LOG_TYPE.INTELLI_ALARM_PLUSE:
                    return (string)App.Current.Resources["ID_INTELLI_ALARM_PLUSE_LOG"];
                case (int)EM_LOG_TYPE.INTELLI_ALARM_IN:
                    return (string)App.Current.Resources["ID_INTELLI_ALARM_IN_LOG"];
                case (int)EM_LOG_TYPE.INTELLI_ALARM_END:
                    return (string)App.Current.Resources["ID_INTELLI_ALARM_END_LOG"];
                case (int)EM_LOG_TYPE.LOG_3G_SIGNAL_SCAN:
                    return (string)App.Current.Resources["ID_3G_SIGNAL_SCAN_LOG"];
                case (int)EM_LOG_TYPE.GPS_SIGNAL_SCAN:
                    return (string)App.Current.Resources["ID_GPS_SIGNAL_SCAN_LOG"];
                case (int)EM_LOG_TYPE.AUTOMATIC_RECORD:
                    return (string)App.Current.Resources["ID_AUTOMATIC_RECORD_LOG"];
                case (int)EM_LOG_TYPE.MANUAL_RECORD:
                    return (string)App.Current.Resources["ID_MANUAL_RECORD_LOG"];
                case (int)EM_LOG_TYPE.CLOSED_RECORD:
                    return (string)App.Current.Resources["ID_CLOSED_RECORD_LOG"];
                case (int)EM_LOG_TYPE.LOGIN:
                    return (string)App.Current.Resources["ID_LOGIN_LOG"];
                case (int)EM_LOG_TYPE.LOGOUT:
                    return (string)App.Current.Resources["ID_LOGOUT_LOG"];
                case (int)EM_LOG_TYPE.ADD_USER:
                    return (string)App.Current.Resources["ID_USER_LOG"];
                case (int)EM_LOG_TYPE.DELETE_USER:
                    return (string)App.Current.Resources["ID_DELETE_USER_LOG"];
                case (int)EM_LOG_TYPE.MODIFY_USER:
                    return (string)App.Current.Resources["ID_MODIFY_USER_LOG"];
                case (int)EM_LOG_TYPE.ADD_GROUP:
                    return (string)App.Current.Resources["ID_ADD_GROUP_LOG"];
                case (int)EM_LOG_TYPE.DELETE_GROUP:
                    return (string)App.Current.Resources["ID_DELETE_GROUP_LOG"];
                case (int)EM_LOG_TYPE.MODIFY_GROUP:
                    return (string)App.Current.Resources["ID_MODIFY_GROUP_LOG"];
                case (int)EM_LOG_TYPE.NET_LOGIN:
                    return (string)App.Current.Resources["ID_NET_LOGIN_LOG"];
                case (int)EM_LOG_TYPE.MODIFY_PASSWORD:
                    return (string)App.Current.Resources["ID_MODIFY_PASSWORD_LOG"];
                case (int)EM_LOG_TYPE.CLEAR:
                    return (string)App.Current.Resources["ID_CLEAR_LOG_LOG"];
                case (int)EM_LOG_TYPE.SEARCHLOG:
                    return (string)App.Current.Resources["ID_SEARCHLOG_LOG"];
                case (int)EM_LOG_TYPE.SEARCH:
                    return (string)App.Current.Resources["ID_SEARCH_LOG"];
                case (int)EM_LOG_TYPE.DOWNLOAD:
                    return (string)App.Current.Resources["ID_DOWNLOAD_LOG"];
                case (int)EM_LOG_TYPE.PLAYBACK:
                    return (string)App.Current.Resources["ID_PLAYBACK_LOG_LOG"];
                case (int)EM_LOG_TYPE.BACKUP:
                    return (string)App.Current.Resources["ID_BACKUP_LOG"];
                case (int)EM_LOG_TYPE.BACKUPERROR:
                    return (string)App.Current.Resources["ID_BACKUPERROR_LOG"];
                case (int)EM_LOG_TYPE.BACK_UPRT:
                    return (string)App.Current.Resources["ID_BACK_UPRT_LOG"];
                case (int)EM_LOG_TYPE.BACKUPCLONE:
                    return (string)App.Current.Resources["ID_BACKUPCLONE_LOG"];
                case (int)EM_LOG_TYPE.DISK_CHANGED:
                    return (string)App.Current.Resources["ID_DISK_CHANGED_LOG"];
                case (int)EM_LOG_TYPE.IMAGEPLAYBACK:
                    return (string)App.Current.Resources["ID_IMAGEPLAYBACK_LOG"];
                case (int)EM_LOG_TYPE.LOCKFILE:
                    return (string)App.Current.Resources["ID_LOCKFILE_LOG"];
                case (int)EM_LOG_TYPE.UNLOCKFILE:
                    return (string)App.Current.Resources["ID_UNLOCKFILE_LOG"];
                case (int)EM_LOG_TYPE.ATMPOS:
                    return (string)App.Current.Resources["ID_ATMPOS_LOG"];
                case (int)EM_LOG_TYPE.PLAY_PAUSE:
                    return (string)App.Current.Resources["ID_PLAY_PAUSE_LOG"];
                case (int)EM_LOG_TYPE.PLAY_START:
                    return (string)App.Current.Resources["ID_PLAY_START_LOG"];
                case (int)EM_LOG_TYPE.PLAY_STOP:
                    return (string)App.Current.Resources["ID_PLAY_STOP_LOG"];
                case (int)EM_LOG_TYPE.PLAY_BACK:
                    return (string)App.Current.Resources["ID_PLAY_BACK_LOG"];
                case (int)EM_LOG_TYPE.PLAY_FAST:
                    return (string)App.Current.Resources["ID_PLAY_FAST_LOG"];
                case (int)EM_LOG_TYPE.PLAY_SLOW:
                    return (string)App.Current.Resources["ID_PLAY_SLOW_LOG"];
                case (int)EM_LOG_TYPE.SMART_SEARCH:
                    return (string)App.Current.Resources["ID_SMART_SEARCH_LOG"];
                case (int)EM_LOG_TYPE.RECORD_SNAP:
                    return (string)App.Current.Resources["ID_RECORD_SNAP_LOG"];
                case (int)EM_LOG_TYPE.ADD_TAG:
                    return (string)App.Current.Resources["ID_ADD_TAG_LOG"];
                case (int)EM_LOG_TYPE.DEL_TAG:
                    return (string)App.Current.Resources["ID_DEL_TAG_LOG"];
                case (int)EM_LOG_TYPE.USB_IN:
                    return (string)App.Current.Resources["ID_USB_IN_LOG"];
                case (int)EM_LOG_TYPE.USB_OUT:
                    return (string)App.Current.Resources["ID_USB_OUT_LOG"];
                case (int)EM_LOG_TYPE.BACKUP_FILE:
                    return (string)App.Current.Resources["ID_BACKUP_FILE_LOG"];
                case (int)EM_LOG_TYPE.BACKUP_LOG:
                    return (string)App.Current.Resources["ID_BACKUP_LOG_LOG"];
                case (int)EM_LOG_TYPE.BACKUP_CONFIG:
                    return (string)App.Current.Resources["ID_BACKUP_CONFIG_LOG"];
                case (int)EM_LOG_TYPE.TIME_UPDATE:
                    return (string)App.Current.Resources["ID_TIME_UPDATE_LOG"];
                case (int)EM_LOG_TYPE.REMOTE_STATE:
                    return (string)App.Current.Resources["ID_REMOTE_STATE_LOG"];
                case (int)EM_LOG_TYPE.USER_DEFINE:
                    return (string)App.Current.Resources["ID_USER_DEFINE_LOG"];
                default:
                    return (string)App.Current.Resources["ID_DEFAULT_TYPE"];
            }
        }
        private string ConvertString(string str)
        {
            string[] splitChar = new string[1];
            splitChar[0] = "\n";
            string[] slist = str.Split(splitChar, StringSplitOptions.RemoveEmptyEntries);
            return string.Join(";", slist);
        }

        private void PrePage_Clicked(object sender, RoutedEventArgs e)
        {
            List<NET_DEVICE_LOG_ITEM_EX> loglist;
            try
            {
                loglist = m_Client.PrePage();
            }
            catch (NETClientExcetion ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            nextpage_btn.IsEnabled = true;
            if (m_Client.IsPrePage)
            {
                prepage_btn.IsEnabled = true;
            }
            else
            {
                prepage_btn.IsEnabled = false;
            }
            ShowLog(loglist);
        }

        private void NextPage_Clicked(object sender, RoutedEventArgs e)
        {
            List<NET_DEVICE_LOG_ITEM_EX> loglist;
            try
            {
                loglist = m_Client.NextPage();
            }
            catch (NETClientExcetion ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            prepage_btn.IsEnabled = true;
            if (m_Client.IsNextPage)
            {
                nextpage_btn.IsEnabled = true;
            }
            else
            {
                nextpage_btn.IsEnabled = false;
            }
            ShowLog(loglist);
        }

        

    }

    public class LogInfo
    {
        public string ID { get; set; }
        public string LOGTYPE { get; set; }
        public string TIME { get; set; }
        public string LOGCONTENT { get; set; }
    }
}
