public bool ExportAsCSV(int index, Spot spot)
        {
            this.ClearError();

            Analyzer       analyzer       = this.GetAnalyzer(1);
            AnalyzeAreaSet analyzeAreaSet = this.GetAnalyzeAreaSet(index);

            string fileName = this.Name + "-" + analyzeAreaSet.Name + ".csv";
            string file     = "";

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.FileName         = fileName;
            dialog.Filter           = "CSVファイル(*.csv)|*.csv";
            dialog.Title            = "保存先のファイルを選択してください";
            dialog.RestoreDirectory = true;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                file = dialog.FileName;
            }
            else
            {
                this.SetError("出力を中断しました。");
                return(false);
            }

            if (File.Exists(file))
            {
                DialogResult result = MessageBox.Show(string.Format("'{0}' は既に存在します。\n新しいファイルに置き換えますか?", fileName), "CSVで出力", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    this.SetError("出力を中断しました。");
                    return(false);
                }
            }

            try
            {
                using (StreamWriter sw = new StreamWriter(file))
                {
                    string[] times    = new string[this.T + 1];
                    string[] count473 = new string[this.T + 1];
                    string[] count561 = new string[this.T + 1];
                    string[] intDen   = new string[this.T + 1];

                    for (int t = 1; t <= this.T; t++)
                    {
                        times[t] = "T" + t.ToString();
                    }

                    this._WriteCSVLine(sw, times);

                    count473[0] = "Count473";
                    count561[0] = "Count561";
                    intDen[0]   = "IntDen";

                    int[] valueCount473 = spot._getCount473();
                    int[] valueCount561 = spot._getCount561();
                    int[] valueIntDen   = spot._getIntDen();

                    for (int t = 1; t <= this.T; t++)
                    {
                        count473[t] = valueCount473[t - 1].ToString();
                        count561[t] = valueCount561[t - 1].ToString();
                        intDen[t]   = valueIntDen[t - 1].ToString();
                    }

                    this._WriteCSVLine(sw, count473);
                    this._WriteCSVLine(sw, count561);
                    this._WriteCSVLine(sw, intDen);
                }
            }
            catch (Exception e)
            {
                this.SetError(e.Message);
                return(false);
            }


            return(true);
        }
Beispiel #2
0
        private void SetSpotChart()
        {
            DataGridViewRow row = dataAnalyzeAreaSets.CurrentRow;

            if (row == null)
            {
                return;
            }

            Cursor oldCursor = Cursor.Current;

            Cursor.Current   = Cursors.WaitCursor;
            labelStatus.Text = "";

            toolStripProgressBar1.Visible = true;
            toolStripProgressBar1.Maximum = this._Project.T;
            toolStripProgressBar1.Minimum = 1;

            AnalyzeAreaSet analyzeAreaSet = (AnalyzeAreaSet)row.DataBoundItem;

            chartSpot.Visible = true;
            chartSpot.Series.Clear();

            //グラフ設定
            string legend473Count = "473Count";
            string legend561Count = "561Count";
            string legendIntDen   = "IntDen";

            chartSpot.Series.Add(legend473Count);
            chartSpot.Series.Add(legend561Count);
            chartSpot.Series.Add(legendIntDen);

            chartSpot.Series[legend473Count].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chartSpot.Series[legend561Count].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
            chartSpot.Series[legendIntDen].ChartType   = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;

            chartSpot.Series[legend473Count].LegendText = legend473Count;
            chartSpot.Series[legend561Count].LegendText = legend561Count;
            chartSpot.Series[legendIntDen].LegendText   = legendIntDen;

            chartSpot.Series[legend473Count].IsValueShownAsLabel     = false;
            chartSpot.Series[legend473Count].SmartLabelStyle.Enabled = false;
            chartSpot.Series[legend473Count].LabelBorderDashStyle    = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.NotSet;
            chartSpot.Series[legend473Count].LabelBorderWidth        = 0;
            chartSpot.Series[legend473Count].LabelForeColor          = Color.FromArgb(0, 0, 0, 0);

            chartSpot.Series[legend561Count].IsValueShownAsLabel     = false;
            chartSpot.Series[legend561Count].SmartLabelStyle.Enabled = false;
            chartSpot.Series[legend561Count].LabelBorderDashStyle    = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.NotSet;
            chartSpot.Series[legend561Count].LabelBorderWidth        = 0;
            chartSpot.Series[legend561Count].LabelForeColor          = Color.FromArgb(0, 0, 0, 0);

            chartSpot.Series[legendIntDen].IsValueShownAsLabel     = false;
            chartSpot.Series[legendIntDen].SmartLabelStyle.Enabled = false;
            chartSpot.Series[legendIntDen].LabelBorderDashStyle    = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.NotSet;
            chartSpot.Series[legendIntDen].LabelBorderWidth        = 0;
            chartSpot.Series[legendIntDen].LabelForeColor          = Color.FromArgb(0, 0, 0, 0);

            chartSpot.Series[legendIntDen].YAxisType = System.Windows.Forms.DataVisualization.Charting.AxisType.Secondary;
            //


            string[] xValues         = new string[scrollT.Maximum];
            int[]    yValues473Count = new int[scrollT.Maximum];
            int[]    yValues561Count = new int[scrollT.Maximum];
            int[]    yValuesIntDen   = new int[scrollT.Maximum];

            for (int t = 1; t <= this._Project.T; t++)
            {
                xValues[t - 1] = t.ToString();

                double[] spots = this._Analyzer.AnalyzeSpot(analyzeAreaSet, t, (int)nudThreshold.Value);

                yValues473Count[t - 1] = (int)spots[0];
                yValues561Count[t - 1] = (int)spots[1];
                yValuesIntDen[t - 1]   = (int)spots[2];

                toolStripProgressBar1.Value = t;
                toolStripProgressBar1.PerformStep();
            }
            Spot spot = new Spot();

            spot._setCount473(yValues473Count);
            spot._setCount561(yValues561Count);
            spot._setIntDen(yValuesIntDen);
            this._Spot = spot;

            for (int i = 0; i < xValues.Length; i++)
            {
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp473Count = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                System.Windows.Forms.DataVisualization.Charting.DataPoint dp561Count = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                System.Windows.Forms.DataVisualization.Charting.DataPoint dpIntDen   = new System.Windows.Forms.DataVisualization.Charting.DataPoint();

                dp473Count.SetValueXY(xValues[i], yValues473Count[i]);
                dp561Count.SetValueXY(xValues[i], yValues561Count[i]);
                dpIntDen.SetValueXY(xValues[i], yValuesIntDen[i]);

                dp473Count.IsValueShownAsLabel = true;
                dp561Count.IsValueShownAsLabel = true;
                dpIntDen.IsValueShownAsLabel   = true;

                chartSpot.Series["473Count"].Points.Add(dp473Count);
                chartSpot.Series["561Count"].Points.Add(dp561Count);
                chartSpot.Series["IntDen"].Points.Add(dpIntDen);
            }

            toolStripProgressBar1.Visible = false;
            Cursor.Current   = oldCursor;
            labelStatus.Text = "解析が完了しました";
            this._Flash      = "";

            buttonExportAsCSV.Enabled = true;
        }