Esempio n. 1
0
        /// <summary>
        /// Graph ChangeMousePos event handler
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">event args</param>
        private void Graph_SelectAxisBtnClick(object sender, EventArgs e)
        {
            SimcaData             data  = null;
            UserControlSimcaGraph graph = null;

            switch ((TAB_ID)_tabControlPlot.SelectedIndex)
            {
            case TAB_ID.SCORE_PLOT:
                data  = _scoreData;
                graph = _graphScore;
                break;

            case TAB_ID.LOADING_PLOT:
                data  = _loadingData;
                graph = _graphLoading;
                break;

            case TAB_ID.S_PLOT:
                data  = _sPlotData;
                graph = _graphSPlot;
                break;

            default:
                break;
            }

            if (data == null)
            {
                return;
            }

            FormSimcaSelectAxis dlg = new FormSimcaSelectAxis(data);

            if (dlg.ShowDialog(this) != DialogResult.OK)
            {
                dlg.Dispose();
                return;
            }

            if ((dlg.SelectAxisIndexX != data.AxisXDataIndex) ||
                (dlg.SelectAxisIndexY != data.AxisYDataIndex))
            {
                data.AxisXDataIndex = dlg.SelectAxisIndexX;
                data.AxisYDataIndex = dlg.SelectAxisIndexY;
                graph.SetData(data);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Read file
        /// </summary>
        /// <param name="data">The target SIMCA data</param>
        /// <param name="graph">The target graph</param>
        private void ReadFile(SimcaData data, UserControlSimcaGraph graph)
        {
            string formatDlgTitle = "Select {0} data file";
            string formatErrMsg   = string.Empty;

            // type
            string typeName  = "score";
            Label  pathLabel = _labelScorePath;

            if (data == _scoreData)
            {
                typeName  = "score";
                pathLabel = _labelScorePath;
            }

            if (data == _loadingData)
            {
                typeName  = "loding";
                pathLabel = _labelLoadingPath;
            }

            if (data == _sPlotData)
            {
                typeName  = "S";
                pathLabel = _labelSPlotPath;
            }

            // Show file open dialog
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.FileName         = string.Empty;
            ofd.InitialDirectory = string.Empty;
            ofd.Filter           = "csv file(*.csv)|*.csv";
            ofd.FilterIndex      = 0;
            ofd.Title            = string.Format(formatDlgTitle, typeName);
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                // Tab select
                _tabControlPlot.SelectedIndex = (int)data.DataType;

                // Grid tab select
                if (_formGridInstance != null)
                {
                    _formGridInstance.TabSelect(data.DataType);
                }

                // Read file data
                SimcaData.SIMCA_READ_ERR_CODE errorCode = SimcaData.SIMCA_READ_ERR_CODE.OK;
                data.Clear();
                try
                {
                    using (TextFieldParser parser = new TextFieldParser(
                               ofd.FileName,
                               System.Text.Encoding.GetEncoding("Shift_JIS")))
                    {
                        parser.TextFieldType = FieldType.Delimited;
                        parser.SetDelimiters(",");
                        while (parser.EndOfData == false)
                        {
                            errorCode = data.Add(parser.ReadFields(), _dbData);
                            if (errorCode != SimcaData.SIMCA_READ_ERR_CODE.OK)
                            {
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    formatErrMsg = ex.Message;
                    errorCode    = SimcaData.SIMCA_READ_ERR_CODE.NG_READ;
                }

                if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.OK)
                {
                    errorCode = data.CheckData(_dbData.GetSelectedMatrixIndex());
                }

                if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_CLASS)
                {
                    string workMsg = string.Format(WARN_MSG_FMT_MSG_CLASS, Path.GetFileName(ofd.FileName));
                    MessageBox.Show(
                        workMsg,
                        "Warning",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    errorCode = SimcaData.SIMCA_READ_ERR_CODE.OK;
                }

                if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.OK)
                {
                    graph.SetData(data);
                    _filePath[(int)data.DataType] = ofd.FileName;
                    LabelSetText(pathLabel, ofd.FileName);

                    if (_formGridInstance != null)
                    {
                        _formGridInstance.Update(data);
                    }
                    return;
                }

                if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_DATA)
                {
                    formatErrMsg = ERR_MSG_FMT_FILE_READ_DATA;
                }
                else if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_READ)
                {
                    // formatErrMsg = ERR_MSG_FMT_READ_FILE;
                }
                else
                {
                    formatErrMsg = ERR_MSG_FMT_FILE_READ_FMT;
                }

                string work = string.Format(formatErrMsg, typeName, Path.GetFileName(ofd.FileName));
                work = char.ToUpper(work[0]) + work.Substring(1);
                MessageBox.Show(
                    work,
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                graph.SetDefaultData();
                data.Clear();
                if (_formGridInstance != null)
                {
                    _formGridInstance.Update(data);
                }

                pathLabel.Text = string.Empty;
                _filePath[(int)data.DataType] = string.Empty;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// FormSimcaGrid ApplyClick evevt handler
        /// </summary>
        /// <param name="sender">object</param>
        /// <param name="e">ApplyClickEventArgs</param>
        private void FormSimcaGrid_ApplyClick(object sender, FormSimcaGrid.ApplyClickEventArgs e)
        {
            SimcaData.SIMCA_READ_ERR_CODE errorCode = SimcaData.SIMCA_READ_ERR_CODE.OK;

            string typeName             = "score";
            Label  pathLabel            = _labelScorePath;
            UserControlSimcaGraph graph = _graphScore;
            SimcaData             data  = _scoreData;

            switch (e._dataType)
            {
            case SimcaData.SIMCA_DATA_TYPE.SCORE_PLOT:
                typeName  = "score";
                pathLabel = _labelScorePath;
                graph     = _graphScore;
                data      = _scoreData;
                break;

            case SimcaData.SIMCA_DATA_TYPE.LOADING_PLOT:
                typeName  = "loading";
                pathLabel = _labelLoadingPath;
                graph     = _graphLoading;
                data      = _loadingData;
                break;

            case SimcaData.SIMCA_DATA_TYPE.S_PLOT:
                typeName  = "S";
                pathLabel = _labelSPlotPath;
                graph     = _graphSPlot;
                data      = _sPlotData;
                break;

            default:
                break;
            }

            // Tab select
            _tabControlPlot.SelectedIndex = (int)e._dataType;

            data.Clear();
            errorCode = data.SetPasteData(e._applyData, _dbData);

            pathLabel.Text = string.Empty;
            _filePath[(int)e._dataType] = string.Empty;

            string workMsg;

            if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_CLASS)
            {
                workMsg = string.Format(WARN_MSG_FMT_MSG_CLASS, "paste data");
                MessageBox.Show(
                    workMsg,
                    "Warning",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                errorCode = SimcaData.SIMCA_READ_ERR_CODE.OK;
            }

            if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.OK)
            {
                graph.SetData(data);
                //if (_formGridInstance != null)
                //{
                //    _formGridInstance.Update(data);
                //}

                return;
            }

            string formatErrMsg;

            if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_DATA)
            {
                formatErrMsg = ERR_MSG_FMT_FILE_READ_DATA;
            }
            else if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_READ)
            {
                formatErrMsg = ERR_MSG_FMT_READ_FILE;
            }
            else
            {
                formatErrMsg = ERR_MSG_FMT_FILE_READ_FMT;
            }

            workMsg = string.Format(formatErrMsg, typeName, "paste data");
            workMsg = char.ToUpper(workMsg[0]) + workMsg.Substring(1);
            MessageBox.Show(
                workMsg,
                "Error",
                MessageBoxButtons.OK,
                MessageBoxIcon.Error);
            graph.SetDefaultData();
            data.Clear();
            if (_formGridInstance != null)
            {
                _formGridInstance.Update(data);
            }
        }