Exemplo n.º 1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            FileInfo fi = new FileInfo(Application.ExecutablePath);

            AppPath = fi.DirectoryName + @"\";
            AppName = fi.Name;
            // Настройка фала логов
            Logger.Log.LogPath = AppPath;
            Logger.Log.LogName = Convert.ToString(DateTime.Today.Year) + Convert.ToString(DateTime.Today.Month) + Convert.ToString(DateTime.Today.Day) + "_" + AppName;
            Logger.Log.AppName = AppName;
            // ^ Настройка фала логов

            EqGateAPIFile = AppPath + "EQGateAPI.xml";
            if (!EQGateAPI.EQGateClassAPI.InitXML(EqGateAPIFile))
            {
                string sTemp = "Основной файл «" + EqGateAPIFile + "» с настройками API не найден! Прииложение будет закрыто...";
                Logger.Log.SaveLog("Main", sTemp, "err");
                MessageBox.Show(sTemp, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
            ConfigFile = AppPath + Path.GetFileNameWithoutExtension(AppName) + ".xml";
            Logger.Log.SaveLog("Main", "Чтение настроек из файла: «" + ConfigFile + "»", "inf");
            if (!EqGateConfig.InitXML(ConfigFile))
            {
                string sTemp = "Основной файл «" + ConfigFile + "» с настройками не найден! Прииложение будет закрыто...";
                Logger.Log.SaveLog("Main", sTemp, "err");
                MessageBox.Show(sTemp, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }
            WorkPath = EqGateConfig.GetValue("WorkPath", "");
            if ((WorkPath == String.Empty) || (!Directory.Exists(WorkPath)))
            {
                WorkPath = AppPath;
            }

            if (!Directory.Exists(WorkPath))
            {
                string sTemp = "Рабочий каталог «" + WorkPath + "» не найден! Прииложение будет закрыто...";
                Logger.Log.SaveLog("Main", sTemp, "err");
                MessageBox.Show(sTemp, "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
                return;
            }

            AccountsFileExt = EqGateConfig.GetAttribute("Ext", "Accounts", "");

            int Count = 0;

            //
            Count             = EqGateConfig.GetChildNodesCount("Accounts", "");
            AccountType       = new string[Count];
            AccountFile       = new string[Count];
            AccountSQL        = new string[Count];
            AccountResultFile = new string[Count];
            AccountDB         = new string[Count];
            for (int iCounter = 0; iCounter < Count; iCounter++)
            {
                AccountType[iCounter]       = EqGateConfig.GetAttribute("Type", "", "Accounts", iCounter);
                AccountFile[iCounter]       = EqGateConfig.GetAttribute("Name", "", "Accounts", iCounter);
                AccountResultFile[iCounter] = EqGateConfig.GetAttribute("ResultFile", "", "Accounts", iCounter);
                if (AccountType[iCounter] == "SQL")
                {
                    AccountDB[iCounter]  = EqGateConfig.GetAttribute("DB", "", "Accounts", iCounter);
                    AccountSQL[iCounter] = EqGateConfig.GetValue("", "Accounts", iCounter);
                }
                comboBox_AccountsList.Items.Insert(iCounter, EqGateConfig.GetAttribute("Description", "", "Accounts", iCounter)
                                                   + " [" + AccountFile[iCounter] + "]"
                                                   + " {" + AccountType[iCounter] + "}");
            }

            if (comboBox_AccountsList.Items.Count > 0)
            {
                comboBox_AccountsList.SelectedIndex = 0;
            }


            Count = EqGateConfig.GetChildNodesCount("Hosts", "");
            comboBox_Host.Items.Clear();
            for (int iCounter = 0; iCounter < Count; iCounter++)
            {
                comboBox_Host.Items.Insert(iCounter, EqGateConfig.GetValue("", "Hosts", iCounter));
            }
            if (comboBox_Host.Items.Count > 0)
            {
                comboBox_Host.SelectedIndex = 0;
            }

            Count = EqGateConfig.GetChildNodesCount("Ports", "");
            comboBox_Port.Items.Clear();
            for (int iCounter = 0; iCounter < Count; iCounter++)
            {
                comboBox_Port.Items.Insert(iCounter, EqGateConfig.GetValue("", "Ports", iCounter));
            }
            if (comboBox_Port.Items.Count > 0)
            {
                comboBox_Port.SelectedIndex = 0;
            }

            Count = EqGateConfig.GetChildNodesCount("Blocs", "");
            comboBox_DB.Items.Clear();
            for (int iCounter = 0; iCounter < Count; iCounter++)
            {
                comboBox_DB.Items.Insert(iCounter, EqGateConfig.GetValue("", "Blocs", iCounter));
            }
            if (comboBox_DB.Items.Count > 0)
            {
                comboBox_DB.SelectedIndex = 0;
            }

            Count = EqGateConfig.GetChildNodesCount("Users", "");
            comboBox_User.Items.Clear();
            for (int iCounter = 0; iCounter < Count; iCounter++)
            {
                comboBox_User.Items.Insert(iCounter, EqGateConfig.GetValue("", "Users", iCounter));
            }
            if (comboBox_User.Items.Count > 0)
            {
                comboBox_User.SelectedIndex = 0;
            }

            // Подготовка формы
            textBox_Session_Info.Clear();
            toolStripStatusLabel_ClientVersion.Text = String.Empty;
            toolStripStatusLabel_ServerVersion.Text = String.Empty;
            groupBox_OpenSession.Enabled            = false;
            groupBox_CloseSession.Enabled           = false;
            groupBox_Disconnect.Enabled             = false;
            dateTimePicker_HZBPD.Value = DateTime.Now;
            // Определение версии клиента
            toolStripStatusLabel_ClientVersion.Text = "Версия клиента: " + EQGateDLL.GetClientVersion();
        }