/// <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); } }
/// <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; } }
/// <summary> /// Paste of clipboard data /// </summary> /// <param name="dataType">Data type</param> /// <param name="typeName">Data type name</param> private void PasteClipboardData(SimcaData.SIMCA_DATA_TYPE dataType, string typeName) { // Set wait Cursor Cursor preCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; int index = _tabControlGrid.SelectedIndex; // Data will be set if data is in a clipboard. if (Clipboard.ContainsText()) { string clipboardText = Clipboard.GetText(); SimcaData.SIMCA_READ_ERR_CODE errorCode = SimcaData.SIMCA_READ_ERR_CODE.OK; // Convert TSV to CSV string workPaste = ConvTsvToCsv(clipboardText); if (workPaste == null) { errorCode = SimcaData.SIMCA_READ_ERR_CODE.NG_FORMAT; } SimcaData tempData = new SimcaData(dataType); if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.OK) { errorCode = tempData.SetPasteData(workPaste, null); } string formatErrMsg; if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_DATA) { // NG_DATA formatErrMsg = ERR_MSG_FMT_FILE_READ_DATA; } else if (errorCode == SimcaData.SIMCA_READ_ERR_CODE.NG_FORMAT) { // NG_FORMAT formatErrMsg = ERR_MSG_FMT_FILE_READ_FMT; } else { // OK Update(tempData); _pasteValue[index] = workPaste; _enableApply[index] = true; _enableSave[index] = true; UpdataButton(); Cursor.Current = preCursor; return; } string workMsg = string.Format(formatErrMsg, typeName, "paste data"); workMsg = char.ToUpper(workMsg[0]) + workMsg.Substring(1); MessageBox.Show( workMsg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); SimcaData clrData = new SimcaData(dataType); Update(clrData); _pasteValue[index] = string.Empty; _enableApply[index] = false; _enableSave[index] = false; UpdataButton(); Cursor.Current = preCursor; return; } }