Beispiel #1
0
        private void miAddDataSource_Click(object sender, EventArgs e)
        {
            // добавление назначения экспорта
            DataSource dataSource = null;

            if (sender == miAddSqlDataSource)
            {
                dataSource = new SqlDataSource();
            }
            else if (sender == miAddOraDataSource)
            {
                dataSource = new OraDataSource();
            }
            else if (sender == miAddPgSqlDataSource)
            {
                dataSource = new PgSqlDataSource();
            }
            else if (sender == miAddMySqlDataSource)
            {
                dataSource = new MySqlDataSource();
            }
            else if (sender == miAddOleDbDataSource)
            {
                dataSource = new OleDbDataSource();
            }

            if (dataSource != null)
            {
                ModConfig.ExportDestination expDest = new ModConfig.ExportDestination(dataSource, new ModConfig.ExportParams());
                TreeNode treeNode = NewExpDestNode(expDest);

                int ind = config.ExportDestinations.BinarySearch(expDest);
                if (ind >= 0)
                {
                    ind++;
                }
                else
                {
                    ind = ~ind;
                }

                config.ExportDestinations.Insert(ind, expDest);
                treeView.Nodes.Insert(ind, treeNode);
                treeView.SelectedNode = treeNode;

                SetConnectionString();
                SetControlsEnabled();
                Modified = true;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Загрузить конфигурацию модуля
        /// </summary>
        public bool Load(out string errMsg)
        {
            SetToDefault();

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(FileName);

                // загрузка назначений экспорта
                XmlNode expDestsNode = xmlDoc.DocumentElement.SelectSingleNode("ExportDestinations");
                if (expDestsNode != null)
                {
                    XmlNodeList expDestNodeList = expDestsNode.SelectNodes("ExportDestination");
                    foreach (XmlElement expDestElem in expDestNodeList)
                    {
                        // загрузка источника данных
                        DataSource dataSource = null;

                        if (expDestElem.SelectSingleNode("DataSource") is XmlNode dataSourceNode)
                        {
                            // получение типа источника данных
                            if (!Enum.TryParse(dataSourceNode.GetChildAsString("DBType"), out DBType dbType))
                            {
                                dbType = DBType.Undefined;
                            }

                            // создание источника данных
                            switch (dbType)
                            {
                            case DBType.MSSQL:
                                dataSource = new SqlDataSource();
                                break;

                            case DBType.Oracle:
                                dataSource = new OraDataSource();
                                break;

                            case DBType.PostgreSQL:
                                dataSource = new PgSqlDataSource();
                                break;

                            case DBType.MySQL:
                                dataSource = new MySqlDataSource();
                                break;

                            case DBType.OLEDB:
                                dataSource = new OleDbDataSource();
                                break;

                            default:
                                dataSource = null;
                                break;
                            }

                            if (dataSource != null)
                            {
                                dataSource.Server           = dataSourceNode.GetChildAsString("Server");
                                dataSource.Database         = dataSourceNode.GetChildAsString("Database");
                                dataSource.User             = dataSourceNode.GetChildAsString("User");
                                dataSource.Password         = ScadaUtils.Decrypt(dataSourceNode.GetChildAsString("Password"));
                                dataSource.ConnectionString = dataSourceNode.GetChildAsString("ConnectionString");

                                if (string.IsNullOrEmpty(dataSource.ConnectionString))
                                {
                                    dataSource.ConnectionString = dataSource.BuildConnectionString();
                                }
                            }
                        }

                        if (dataSource != null &&
                            expDestElem.SelectSingleNode("ExportParams") is XmlNode exportParamsNode)
                        {
                            // загрузка параметров экспорта
                            ExportParams exportParams = new ExportParams();
                            exportParams.LoadFromXml(exportParamsNode);

                            // создание назначения экспорта
                            ExportDestination expDest = new ExportDestination(dataSource, exportParams);
                            ExportDestinations.Add(expDest);
                        }
                    }

                    // сортировка назначений экспорта
                    ExportDestinations.Sort();
                }

                // загрузка номеров каналов управления для экспорта в ручном режиме
                if (xmlDoc.DocumentElement.SelectSingleNode("ManualExport") is XmlNode manExpNode)
                {
                    CurDataCtrlCnlNum = manExpNode.GetChildAsInt("CurDataCtrlCnlNum");
                    ArcDataCtrlCnlNum = manExpNode.GetChildAsInt("ArcDataCtrlCnlNum");
                    EventsCtrlCnlNum  = manExpNode.GetChildAsInt("EventsCtrlCnlNum");
                }

                errMsg = "";
                return(true);
            }
            catch (FileNotFoundException ex)
            {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message +
                         Environment.NewLine + ModPhrases.ConfigureModule;
                return(false);
            }
            catch (Exception ex)
            {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message;
                return(false);
            }
        }
Beispiel #3
0
        private void miAddDataSource_Click(object sender, EventArgs e)
        {
            // добавление назначения экспорта
            DataSource dataSource = null;

            if (sender == miAddSqlDataSource)
                dataSource = new SqlDataSource();
            else if (sender == miAddOraDataSource)
                dataSource = new OraDataSource();
            else if (sender == miAddPgSqlDataSource)
                dataSource = new PgSqlDataSource();
            else if (sender == miAddMySqlDataSource)
                dataSource = new MySqlDataSource();
            else if (sender == miAddOleDbDataSource)
                dataSource = new OleDbDataSource();

            if (dataSource != null)
            {
                Config.ExportDestination expDest = new Config.ExportDestination(dataSource, new Config.ExportParams());
                TreeNode treeNode = NewExpDestNode(expDest);

                int ind = config.ExportDestinations.BinarySearch(expDest);
                if (ind >= 0)
                    ind++;
                else
                    ind = ~ind;

                config.ExportDestinations.Insert(ind, expDest);
                treeView.Nodes.Insert(ind, treeNode);
                treeView.SelectedNode = treeNode;

                SetConnectionString();
                SetControlsEnabled();
                Modified = true;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Download module configuration
        /// </summary>
        public bool Load(out string errMsg)
        {
            SetToDefault();

            try {
                var xmlDoc = new XmlDocument();
                xmlDoc.Load(FileName);

                // loading export destinations
                var expDestsNode = xmlDoc.DocumentElement.SelectSingleNode("ExportDestinations");
                if (expDestsNode != null)
                {
                    var expDestNodeList = expDestsNode.SelectNodes("ExportDestination");
                    foreach (XmlElement expDestElem in expDestNodeList)
                    {
                        // loading data source
                        DataSource dataSource     = null;
                        var        dataSourceNode = expDestElem.SelectSingleNode("DataSource");

                        if (dataSourceNode != null)
                        {
                            // getting data source type
                            DBTypes dbType;
                            if (!Enum.TryParse <DBTypes>(dataSourceNode.GetChildAsString("DBType"), out dbType))
                            {
                                dbType = DBTypes.Undefined;
                            }

                            // create data source
                            switch (dbType)
                            {
                            case DBTypes.MSSQL:
                                dataSource = new SqlDataSource();
                                break;

                            case DBTypes.Oracle:
                                dataSource = new OraDataSource();
                                break;

                            case DBTypes.PostgreSQL:
                                dataSource = new PgSqlDataSource();
                                break;

                            case DBTypes.MySQL:
                                dataSource = new MySqlDataSource();
                                break;

                            case DBTypes.OLEDB:
                                dataSource = new OleDbDataSource();
                                break;

                            default:
                                dataSource = null;
                                break;
                            }

                            if (dataSource != null)
                            {
                                dataSource.Server           = dataSourceNode.GetChildAsString("Server");
                                dataSource.Database         = dataSourceNode.GetChildAsString("Database");
                                dataSource.User             = dataSourceNode.GetChildAsString("User");
                                dataSource.Password         = dataSourceNode.GetChildAsString("Password");
                                dataSource.ConnectionString = dataSourceNode.GetChildAsString("ConnectionString");

                                if (string.IsNullOrEmpty(dataSource.ConnectionString))
                                {
                                    dataSource.ConnectionString = dataSource.BuildConnectionString();
                                }
                            }
                        }

                        // load export options
                        ExportParams exportParams     = null;
                        var          exportParamsNode = expDestElem.SelectSingleNode("ExportParams");

                        if (dataSource != null && exportParamsNode != null)
                        {
                            exportParams = new ExportParams {
                                ExportCurDataQuery = exportParamsNode.GetChildAsString("ExportCurDataQuery")
                            };
                            exportParams.ExportCurData = !string.IsNullOrEmpty(exportParams.ExportCurDataQuery) &&
                                                         exportParamsNode.GetChildAsBool("ExportCurData");
                            exportParams.ExportArcDataQuery = exportParamsNode.GetChildAsString("ExportArcDataQuery");
                            exportParams.ExportArcData      = !string.IsNullOrEmpty(exportParams.ExportArcDataQuery) &&
                                                              exportParamsNode.GetChildAsBool("ExportArcData");
                            exportParams.ExportEventQuery = exportParamsNode.GetChildAsString("ExportEventQuery");
                            exportParams.ExportEvents     = !string.IsNullOrEmpty(exportParams.ExportEventQuery) &&
                                                            exportParamsNode.GetChildAsBool("ExportEvents");
                        }

                        // creating export destination
                        if (dataSource != null && exportParams != null)
                        {
                            var expDest = new ExportDestination(dataSource, exportParams);
                            ExportDestinations.Add(expDest);
                        }
                    }

                    // sort export destinations
                    ExportDestinations.Sort();
                }

                // loading control channel numbers for manual export
                var manExpNode = xmlDoc.DocumentElement.SelectSingleNode("ManualExport");
                if (manExpNode != null)
                {
                    CurDataCtrlCnlNum = manExpNode.GetChildAsInt("CurDataCtrlCnlNum");
                    ArcDataCtrlCnlNum = manExpNode.GetChildAsInt("ArcDataCtrlCnlNum");
                    EventsCtrlCnlNum  = manExpNode.GetChildAsInt("EventsCtrlCnlNum");
                }

                errMsg = "";
                return(true);
            } catch (FileNotFoundException ex) {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message +
                         Environment.NewLine + ModPhrases.ConfigureModule;
                return(false);
            } catch (Exception ex) {
                errMsg = ModPhrases.LoadModSettingsError + ": " + ex.Message;
                return(false);
            }
        }