Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // получение изменений конфигурации КП
            ControlsToConfig();

            // сохранение конфигурации КП
            string errMsg;

            if (config.Save(configFileName, out errMsg))
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                ScadaUiUtils.ShowError(errMsg);
            }
        }
Example #2
0
        /// <summary>
        /// Validates the form controls.
        /// </summary>
        private bool ValidateControls()
        {
            if (!string.IsNullOrEmpty(txtConfigFileName.Text) &&
                !File.Exists(Path.Combine(appDirs.ConfigDir, txtConfigFileName.Text)))
            {
                ScadaUiUtils.ShowError(CommonPhrases.FileNotFound);
                return(false);
            }

            if (!ScadaUtils.ParseRange(txtDeviceFilter.Text, true, true, out _))
            {
                ScadaUiUtils.ShowError(CommonPhrases.ValidRangeRequired);
                return(false);
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// Download configuration
        /// </summary>
        private void DownloadConfig(ServersSettings.ServerSettings serverSettings)
        {
            // download
            Cursor = Cursors.WaitCursor;
            string logFileName = AppData.AppDirs.LogDir + "ScadaAdminDownload.txt";
            bool   downloadOK  = DownloadUpload.DownloadConfig(serverSettings,
                                                               logFileName, out bool logCreated, out string msg);

            Cursor = Cursors.Default;

            // display of the result message
            if (downloadOK)
            {
                ScadaUiUtils.ShowInfo(msg);

                // launch import
                ServersSettings.DownloadSettings downloadSettings = serverSettings.Download;
                if (downloadSettings.ImportBase)
                {
                    var frmImport = new FrmImport();
                    if (downloadSettings.SaveToDir)
                    {
                        frmImport.DefaultSelection  = FrmImport.SelectedItem.AllTables;
                        frmImport.DefaultBaseDATDir = Path.Combine(downloadSettings.DestDir, "BaseDAT");
                    }
                    else
                    {
                        frmImport.DefaultSelection   = FrmImport.SelectedItem.Archive;
                        frmImport.DefaultArcFileName = downloadSettings.DestFile;
                        frmImport.DefaultBaseDATDir  = AppData.Settings.AppSett.BaseDATDir;
                    }

                    frmImport.ShowDialog();
                }
            }
            else
            {
                AppUtils.ProcError(msg);

                // log display in notebook
                if (logCreated)
                {
                    Process.Start(logFileName);
                }
            }
        }
Example #4
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            // изменение переменной
            string oidStr = txtOID.Text.Trim();

            if (CheckOID(oidStr))
            {
                variable.Name   = txtName.Text.Trim();
                variable.OID    = txtOID.Text.Trim();
                variable.IsBits = chkBits.Checked;
                DialogResult    = DialogResult.OK;
            }
            else
            {
                ScadaUiUtils.ShowError(KpPhrases.IncorrectOID);
            }
        }
Example #5
0
 /// <summary>
 /// Сохранить настройки приложения в файле
 /// </summary>
 private void SaveSettings()
 {
     try
     {
         XmlDocument    xmlDoc  = new XmlDocument();
         XmlDeclaration xmlDecl = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
         xmlDoc.AppendChild(xmlDecl);
         XmlElement rootElem = xmlDoc.CreateElement("ScadaTableEditorConfig");
         xmlDoc.AppendChild(rootElem);
         rootElem.AppendParamElem("BaseDATDir", baseDATDir, CommonPhrases.BaseDATDir);
         xmlDoc.Save(exeDir + SettingsFileName);
     }
     catch (Exception ex)
     {
         ScadaUiUtils.ShowError(CommonPhrases.SaveAppSettingsError + ":\n" + ex.Message);
     }
 }
Example #6
0
        /// <summary>
        /// Загрузить шаблон устройства из файла
        /// </summary>
        private void LoadTemplate(string fname)
        {
            DeviceTemplate templ = new DeviceTemplate();
            string         errMsg;

            if (templ.Load(fname, out errMsg))
            {
                template = templ;
                fileName = fname;
                SetFormTitle();
                FillTree();
            }
            else
            {
                ScadaUiUtils.ShowError(errMsg);
            }
        }
Example #7
0
        /// <summary>
        /// Скачать конфигурацию
        /// </summary>
        private void DownloadConfig(ServersSettings.ServerSettings serverSettings)
        {
            // скачивание
            Cursor = Cursors.WaitCursor;
            string logFileName = AppData.AppDirs.LogDir + "ScadaAdminDownload.txt";
            bool   downloadOK  = DownloadUpload.DownloadConfig(serverSettings,
                                                               logFileName, out bool logCreated, out string msg);

            Cursor = Cursors.Default;

            // отображение сообщения о результате
            if (downloadOK)
            {
                ScadaUiUtils.ShowInfo(msg);

                // запуск импорта
                ServersSettings.DownloadSettings downloadSettings = serverSettings.Download;
                if (downloadSettings.ImportBase)
                {
                    FrmImport frmImport = new FrmImport();
                    if (downloadSettings.SaveToDir)
                    {
                        frmImport.DefaultSelection  = FrmImport.SelectedItem.AllTables;
                        frmImport.DefaultBaseDATDir = Path.Combine(downloadSettings.DestDir, "BaseDAT");
                    }
                    else
                    {
                        frmImport.DefaultSelection   = FrmImport.SelectedItem.Archive;
                        frmImport.DefaultArcFileName = downloadSettings.DestFile;
                        frmImport.DefaultBaseDATDir  = AppData.Settings.AppSett.BaseDATDir;
                    }
                    frmImport.ShowDialog();
                }
            }
            else
            {
                AppUtils.ProcError(msg);

                // отображение журнала в блокноте
                if (logCreated)
                {
                    Process.Start(logFileName);
                }
            }
        }
Example #8
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            // импорт выбранной таблицы из формата DAT
            Tables.TableInfo tableInfo = cbTable.SelectedItem as Tables.TableInfo;

            if (AppData.Connected)
            {
                string logFileName = chkImportLog.Checked ? AppData.ExeDir + "ScadaAdminImport.txt" : "";
                bool   importOK;
                bool   logCreated;
                string msg;

                if (tableInfo == null)
                {
                    // импорт архива
                    importOK = ImportExport.ImportArchive(txtFileName.Text, Tables.TableInfoList,
                                                          logFileName, out logCreated, out msg);
                }
                else
                {
                    // импорт таблицы
                    int minID    = gbIDs.Enabled && chkStartID.Checked ? Convert.ToInt32(numStartID.Value) : 0;
                    int maxID    = gbIDs.Enabled && chkFinalID.Checked ? Convert.ToInt32(numFinalID.Value) : int.MaxValue;
                    int newMinID = gbIDs.Enabled && chkNewStartID.Checked ? Convert.ToInt32(numNewStartID.Value) : 0;
                    importOK = ImportExport.ImportTable(txtFileName.Text, tableInfo, minID, maxID, newMinID,
                                                        logFileName, out logCreated, out msg);
                }

                // отображение сообщения о результате импорта
                if (importOK)
                {
                    ScadaUiUtils.ShowInfo(msg);
                }
                else
                {
                    AppUtils.ProcError(msg);
                }

                // отображение журанала в блокноте
                if (logCreated)
                {
                    Process.Start(logFileName);
                }
            }
        }
Example #9
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            try {
                if (rbSnapshot.Checked)
                {
                    dataTable = new DataTable("SrezTable");
                    srezTable = new SrezTable();
                    var sa = new SrezAdapter {
                        FileName = txtFileName.Text
                    };
                    sa.Fill(dataTable);
                    sa.Fill(srezTable);
                    dataTable.RowChanged += DataTable_RowChanged;
                    dataTable.Columns["DateTime"].ReadOnly = true;
                    dataTable.Columns["CnlNum"].ReadOnly   = true;
                }
                else if (rbEvent.Checked)
                {
                    dataTable = new DataTable("EventTable");
                    srezTable = null;
                    var ea = new EventAdapter {
                        FileName = txtFileName.Text
                    };
                    ea.Fill(dataTable);
                }
                else     // rbBase.Checked
                {
                    dataTable = new DataTable("BaseTable");
                    srezTable = null;
                    var ba = new BaseAdapter {
                        FileName = txtFileName.Text
                    };
                    ba.Fill(dataTable, true);
                }

                dataTable.DefaultView.AllowNew  = !rbSnapshot.Checked;
                dataTable.DefaultView.AllowEdit = true;
                dataGridView.DataSource         = dataTable;
            } catch (Exception ex) {
                dataTable = null;
                ScadaUiUtils.ShowError(ex.Message);
            } finally {
                ShowRecordCount();
            }
        }
Example #10
0
        /// <summary>
        /// Commits and ends the edit operation on the current cell and row.
        /// </summary>
        public bool EndEdit()
        {
            if (dataGridView.EndEdit())
            {
                if (dataGridView.CurrentRow == null ||
                    ValidateRow(dataGridView.CurrentRow.Index, out string errMsg))
                {
                    bindingSource.EndEdit();
                    return(true);
                }
                else
                {
                    ScadaUiUtils.ShowError(errMsg);
                }
            }

            return(false);
        }
Example #11
0
 private void miToolsOptions_Click(object sender, EventArgs e)
 {
     // отображение формы настроек
     if (FrmSettings.ShowDialog(settings, out bool restartNeeded))
     {
         if (settings.Save(appData.AppDirs.ConfigDir + Settings.DefFileName, out string errMsg))
         {
             if (restartNeeded)
             {
                 ScadaUiUtils.ShowInfo(AppPhrases.RestartNeeded);
             }
         }
         else
         {
             ScadaUiUtils.ShowError(errMsg);
         }
     }
 }
Example #12
0
 /// <summary>
 /// Загрузить таблицу базы конфигурации
 /// </summary>
 private static bool LoadDataTable(BaseAdapter baseAdapter, Log errLog, ref DataTable dataTable)
 {
     try
     {
         baseAdapter.Fill(dataTable, true);
         return(true);
     }
     catch (Exception ex)
     {
         string errMsg = AppPhrases.IncorrectFilter + ":\r\n" + ex.Message;
         if (errLog != null)
         {
             errLog.WriteAction(errMsg, Log.ActTypes.Exception);
         }
         ScadaUiUtils.ShowError(errMsg);
         return(false);
     }
 }
Example #13
0
        private void FrmBaseTableView_Load(object sender, EventArgs e)
        {
            // перевод формы
            Translator.TranslateForm(this, "Scada.Server.Ctrl.FrmBaseTableView");
            if (lblCount.Text.Contains("{0}"))
            {
                bindingNavigator.CountItemFormat = lblCount.Text;
            }

            // настройка элементов управления
            string tableTitle = BaseTableTitles.TryGetValue(baseAdapter.TableName, out tableTitle) ?
                                " - " + tableTitle : "";

            Text += " - " + baseAdapter.TableName + tableTitle;
            dataGridView.AutoGenerateColumns = true;
            bindingSource.DataSource         = dataTable;
            ScadaUiUtils.AutoSizeColumns(dataGridView);
        }
Example #14
0
 /// <summary>
 /// Transfers the configuration.
 /// </summary>
 private bool TransferConfig()
 {
     if (!appData.ExtensionHolder.GetExtension(profile.Extension, out extensionLogic))
     {
         ScadaUiUtils.ShowError(AppPhrases.ExtensionNotFound, profile.Extension);
         return(false);
     }
     else if (!extensionLogic.CanDeploy)
     {
         ScadaUiUtils.ShowError(AppPhrases.ExtensionCannotDeploy, profile.Extension);
         return(false);
     }
     else
     {
         ShowDialog();
         return(operationResult);
     }
 }
Example #15
0
        /// <summary>
        /// Validates the form field.
        /// </summary>
        private bool ValidateFields()
        {
            string fileName = FileName;

            if (fileName == "")
            {
                ScadaUiUtils.ShowError(AppPhrases.FileNameEmpty);
                return(false);
            }

            if (!AdminUtils.NameIsValid(fileName))
            {
                ScadaUiUtils.ShowError(AppPhrases.FileNameInvalid);
                return(false);
            }

            return(true);
        }
Example #16
0
        private void btnRecordOnOff_Click(object sender, EventArgs e)
        {
            Command cmd = new Command(BaseValues.CmdTypes.Standard);

            cmd.KPNum  = kpNum;
            cmd.CmdNum = 2;
            cmd.CmdVal = sender == btnRecordOn ? 1.0 : 0.0;
            string msg;

            if (CommUtils.SaveCmd(cmdDir, "KpAeroQuad", cmd, out msg))
            {
                ScadaUiUtils.ShowInfo(msg);
            }
            else
            {
                ScadaUiUtils.ShowError(msg);
            }
        }
Example #17
0
        private void btnSend_i_Click(object sender, EventArgs e)
        {
            Command cmd = new Command(BaseValues.CmdTypes.Binary);

            cmd.KPNum   = kpNum;
            cmd.CmdNum  = 1;
            cmd.CmdData = new byte[] { 0x69 }; // символ i
            string msg;

            if (CommUtils.SaveCmd(cmdDir, "KpAeroQuad", cmd, out msg))
            {
                ScadaUiUtils.ShowInfo(msg);
            }
            else
            {
                ScadaUiUtils.ShowError(msg);
            }
        }
Example #18
0
        private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            // сохранение состояния формы
            FormState formState = new FormState(this);

            formState.SchemeDir = ofdScheme.InitialDirectory;
            formState.ImageDir  = ImageEditor.ImageDir;
            string errMsg;

            if (!formState.Save(appData.AppDirs.ConfigDir + FormState.DefFileName, out errMsg))
            {
                log.WriteError(errMsg);
                ScadaUiUtils.ShowError(errMsg);
            }

            // завершение работы приложения
            appData.FinalizeApp();
        }
Example #19
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (RangeUtils.StrToRange(txtRange.Text, true, true, out ICollection <int> newRange))
            {
                range.Clear();

                foreach (int val in newRange)
                {
                    range.Add(val);
                }

                DialogResult = DialogResult.OK;
            }
            else
            {
                ScadaUiUtils.ShowError(SchemePhrases.RangeNotValid);
            }
        }
Example #20
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            // reload table
            var newDataTable = new DataTable();

            if (LoadDataTable(baseAdapter, errLog, ref newDataTable))
            {
                dataTable = newDataTable;
                try {
                    dataTable.DefaultView.RowFilter = txtFilter.Text;
                } catch {
                    txtFilter.Text = "";
                }

                bindingSource.DataSource = dataTable;
                ScadaUiUtils.AutoResizeColumns(dataGridView);
            }
        }
Example #21
0
        /// <summary>
        /// Проверить настройки передачи конфигурации
        /// </summary>
        private bool ValidateUploadSettings()
        {
            if (rbGetFromDir.Checked)
            {
                if (string.IsNullOrWhiteSpace(txtSrcDir.Text))
                {
                    ScadaUiUtils.ShowError(AppPhrases.ConfigDirRequired);
                    return(false);
                }
            }
            else if (string.IsNullOrWhiteSpace(txtSrcFile.Text))
            {
                ScadaUiUtils.ShowError(AppPhrases.ConfigArcRequired);
                return(false);
            }

            return(true);
        }
Example #22
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // создание переменной
            string oidStr = txtOID.Text.Trim();

            if (CheckOID(oidStr))
            {
                variable = new KpConfig.Variable()
                {
                    Name = txtName.Text.Trim(), OID = oidStr, IsBits = chkBits.Checked
                };
                DialogResult = DialogResult.OK;
            }
            else
            {
                ScadaUiUtils.ShowError(KpPhrases.IncorrectOID);
            }
        }
Example #23
0
        /// <summary>
        /// Applies the state to the specified form.
        /// </summary>
        public void Apply(FrmMain form)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            if (!IsEmpty && ScadaUiUtils.AreaIsVisible(Left, Top, Width, Height))
            {
                form.SetBounds(Left, Top, Width, Height);
                form.WindowState   = Maximized ? FormWindowState.Maximized : FormWindowState.Normal;
                form.ExplorerWidth = ExplorerWidth;
            }
            else
            {
                form.WindowState = FormWindowState.Maximized;
            }
        }
Example #24
0
        /// <summary>
        /// Exports data to CSV.
        /// </summary>
        private void ExportToCsv()
        {
            try
            {
                sfdCsv.FileName = Path.GetFileNameWithoutExtension(FileName) + ".csv";

                if (sfdCsv.ShowDialog() == DialogResult.OK)
                {
                    CsvConverter csvConverter = new CsvConverter(sfdCsv.FileName);
                    csvConverter.ConvertToCsv(srezTable);
                }
            }
            catch (Exception ex)
            {
                errLog.WriteException(ex, ServerShellPhrases.ExportToCsvError);
                ScadaUiUtils.ShowError(ServerShellPhrases.ExportToCsvError + ": " + ex.Message);
            }
        }
Example #25
0
 /// <summary>
 /// Opens the project.
 /// </summary>
 private void OpenProject(ProjectItem item)
 {
     if (!item.IsEmpty)
     {
         if (File.Exists(item.Path))
         {
             ChildFormTag.SendMessage(this, AppMessage.OpenProject,
                                      new Dictionary <string, object> {
                 { "Path", item.Path }
             });
         }
         else
         {
             ScadaUiUtils.ShowWarning(CommonPhrases.NamedFileNotFound, item.Path);
             RemoveProjectFromList(item);
         }
     }
 }
Example #26
0
 /// <summary>
 /// Сохранить изменения таблицы срезов
 /// </summary>
 private bool Save()
 {
     try
     {
         srezAdapter.Update(srezTable);
         return(true);
     }
     catch (Exception ex)
     {
         string errMsg = AppPhrases.SaveSrezTableError + ":\r\n" + ex.Message;
         if (errLog != null)
         {
             errLog.WriteAction(errMsg, Log.ActTypes.Exception);
         }
         ScadaUiUtils.ShowError(errMsg);
         return(false);
     }
 }
Example #27
0
        /// <summary>
        /// Validates the form controls.
        /// </summary>
        private bool ValidateControls()
        {
            StringBuilder sbError = new();

            if (string.IsNullOrWhiteSpace(txtName.Text))
            {
                sbError.AppendError(lblName, CommonPhrases.NonemptyRequired);
            }

            if (txtLoLo.Text != "" && !ScadaUtils.TryParseDouble(txtLoLo.Text, out _))
            {
                sbError.AppendError(lblLoLo, CommonPhrases.RealRequired);
            }

            if (txtLow.Text != "" && !ScadaUtils.TryParseDouble(txtLow.Text, out _))
            {
                sbError.AppendError(lblLow, CommonPhrases.RealRequired);
            }

            if (txtHigh.Text != "" && !ScadaUtils.TryParseDouble(txtHigh.Text, out _))
            {
                sbError.AppendError(lblHigh, CommonPhrases.RealRequired);
            }

            if (txtHiHi.Text != "" && !ScadaUtils.TryParseDouble(txtHiHi.Text, out _))
            {
                sbError.AppendError(lblHiHi, CommonPhrases.RealRequired);
            }

            if (txtDeadband.Text != "" && !ScadaUtils.TryParseDouble(txtDeadband.Text, out _))
            {
                sbError.AppendError(lblDeadband, CommonPhrases.RealRequired);
            }

            if (sbError.Length > 0)
            {
                ScadaUiUtils.ShowError(CommonPhrases.CorrectErrors + Environment.NewLine + sbError);
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #28
0
        private void timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();

            // соединение
            if (client == null)
            {
                if (!DownloadUpload.Connect(ctrlServerConn.SelectedSettings.Connection,
                                            out client, out sessionID, out string errMsg))
                {
                    Disconnect();
                    ScadaUiUtils.ShowError(errMsg);
                }
            }

            // запрос данных
            if (client != null)
            {
                ServiceStatus status;

                try
                {
                    txtServerStatus.Text = client.GetServiceStatus(out status, sessionID, ServiceApp.Server) ?
                                           StatusToString(status) : "---";
                }
                catch (Exception ex)
                {
                    txtServerStatus.Text = ex.Message;
                }

                try
                {
                    txtCommStatus.Text = client.GetServiceStatus(out status, sessionID, ServiceApp.Comm) ?
                                         StatusToString(status) : "---";
                }
                catch (Exception ex)
                {
                    txtCommStatus.Text = ex.Message;
                }

                txtUpdateTime.Text = DateTime.Now.ToLocalizedString();
                timer.Start();
            }
        }
Example #29
0
        private void FrmMain_Load(object sender, EventArgs e)
        {
            // определение директории исполняемого файла приложения
            exeDir = ScadaUtils.NormalDir(Path.GetDirectoryName(Application.ExecutablePath));

            // локализация приложения
            string langDir = exeDir + "Lang\\";
            string errMsg;

            if (Localization.LoadingRequired(langDir, "ScadaData"))
            {
                if (Localization.LoadDictionaries(langDir, "ScadaData", out errMsg))
                {
                    CommonPhrases.Init();
                }
                else
                {
                    ScadaUiUtils.ShowError(errMsg);
                }
            }

            if (Localization.LoadingRequired(langDir, "ScadaTableEditor"))
            {
                if (Localization.LoadDictionaries(langDir, "ScadaTableEditor", out errMsg))
                {
                    Translator.TranslateForm(this, "ScadaTableEditor.FrmMain", toolTip);
                    WebPhrases.Init();
                    AppPhrases.Init();
                    openFileDialog.Filter = AppPhrases.OpenFileFilter;
                    saveFileDialog.Filter = AppPhrases.SaveFileFilter;
                }
                else
                {
                    ScadaUiUtils.ShowError(errMsg);
                }
            }

            // настройка элементов управления
            dgvCnls.AutoGenerateColumns  = false;
            dgvItems.AutoGenerateColumns = false;

            // создание нового представления
            CreateTableView();
        }
Example #30
0
        /// <summary>
        /// Инициализировать форму
        /// </summary>
        private void Init()
        {
            // инициализация формы
            if (!inited)
            {
                inited = true;

                // настройка элементов управления в зависимости от локализации
                PictureBox activePictureBox;

                if (Localization.UseRussian)
                {
                    activePictureBox     = pbAboutRu;
                    pbAboutEn.Visible    = false;
                    lblVersionEn.Visible = false;
                    lblVersionRu.Text    = "Версия " + SchemeUtils.SchemeVersion;
                }
                else
                {
                    activePictureBox     = pbAboutEn;
                    pbAboutRu.Visible    = false;
                    lblVersionRu.Visible = false;
                    lblVersionEn.Text    = "Version " + SchemeUtils.SchemeVersion;
                }

                // загрузка изображения и гиперссылки из файлов, если они существуют
                bool   imgLoaded;
                string errMsg;
                if (ScadaUiUtils.LoadAboutForm(exeDir, this, activePictureBox, lblWebsite,
                                               out imgLoaded, out linkUrl, out errMsg))
                {
                    if (imgLoaded)
                    {
                        lblVersionRu.Visible = false;
                        lblVersionEn.Visible = false;
                    }
                }
                else
                {
                    errLog.WriteAction(errMsg);
                    ScadaUiUtils.ShowError(errMsg);
                }
            }
        }