Exemple #1
0
        /// <summary>
        /// Calculate the selected dataset.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            if (activeId == -1)
            {
                MessageBox.Show("No data selected.", "Cannot open data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string outputFileName;

            sfdSave.ShowDialog();
            outputFileName = sfdSave.FileName;
            MovingAverageDS ds = DSAccess.Operation(DSOperation.Find, new MovingAverageDS {
                id = activeId
            }, DSFindBy.Id).FirstOrDefault();

            try
            {
                File.WriteAllText(outputFileName, CalculateDSToString.OutputCalculation(ds));
            }
            catch (Exception ex)
            {
                string title = "Could not save output.";
                MessageBox.Show(ex.Message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        /// <summary>
        /// Calculate all of the datasets.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCalculateAll_Click(object sender, EventArgs e)
        {
            string outputFileName;

            sfdSave.ShowDialog();
            outputFileName = sfdSave.FileName;
            MovingAverageDS[] dataSets = DSAccess.Operation(DSOperation.GetAll);
            StringBuilder     builder  = new StringBuilder();

            if (dataSets.Length > 0)
            {
                foreach (MovingAverageDS ds in dataSets)
                {
                    CalculateDSToString.OutputCalculation(ds, builder);
                    builder.AppendLine();
                }

                try
                {
                    File.WriteAllText(outputFileName, builder.ToString());
                }
                catch (Exception ex)
                {
                    string title = "Could not save output.";
                    MessageBox.Show(ex.Message, title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("No data was detected in the database. Cannot calculate an average of nothing.",
                                "No Data Detected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }