private static void CreateDataWorksheet(Excel.Worksheet sheet, LsData lsData, string sheetName)
        {
            sheet.Name = sheetName;

            sheet.Columns[(new XlPosition()).Column].ColumnWidth = 2.5;

            SetValue(sheet, LsParameters.BetaName, dataBHeadSp);
            SetRowValues(sheet, lsData.Parameters.XValsNames, dataXHeadsSp);
            SetValue(
                sheet,
                lsData.Parameters.YValName,
                new XlPosition(
                    dataXHeadsSp.Row,
                    dataXHeadsSp.Column + lsData.Parameters.XMtx.ColumnCount));

            SetRowValues(sheet, lsData.Parameters.Beta, dataBValsSp);
            SetTableValues(sheet, lsData.Parameters.XMtx, dataXValsSp);
            SetColumnValues(
                sheet,
                lsData.Parameters.YVtr,
                new XlPosition(
                    dataXValsSp.Row,
                    dataXValsSp.Column + lsData.Parameters.XMtx.ColumnCount));

            ReleaseMemory(sheet);
        }
        private static void CreaeteWorksheet(string fileName, LsData lsData, WriteData writeData, bool visible = true)
        {
            Excel.Application xlApp = new Excel.Application();
            if (xlApp == null)
            {
                return;
            }

            if (lsData == null)
            {
                lsData = ExcelWorker.lsData;
            }

            object misValue = System.Reflection.Missing.Value;


            var xlWorkbook = (File.Exists(fileName))
                ? xlApp.Workbooks.Open(fileName)
                : xlApp.Workbooks.Add(misValue);

            xlApp.Visible = visible;

            Task.Factory.StartNew(() =>
            {
                writeData(xlWorkbook, lsData);

                Save(xlWorkbook, fileName);

                ReleaseMemory(xlApp, xlWorkbook);
            });
        }
        private static void CreateParametersWorksheet(Excel.Worksheet sheet, LsData lsData, string sheetName)
        {
            sheet.Name = sheetName;

            sheet.Columns[(new XlPosition()).Column].ColumnWidth = 2.5;
            sheet.Columns[paramDHeadsSp.Column].ColumnWidth      = 30;

            SetColumnValues(sheet, paramDHeads, paramDHeadsSp);
            string[] paramsDVals =
            {
                lsData.Parameters.NumbOfTests.ToString(),
                lsData.Parameters.NumbOfXVal.ToString(),
                ((int)lsData.Parameters.NoiseX).ToString(),
                ((int)lsData.Parameters.NoiseY).ToString(),
                lsData.Parameters.Gamma.ToString(),
                lsData.Parameters.Theta.ToString()
            };

            SetColumnValues(sheet, paramsDVals, paramDValsSp);


            SetColumnValues(sheet, paramNsHeads, paramNsHeadSp);
            SetColumnValues(sheet, paramNsTys, paramNsTySp);

            ReleaseMemory(sheet);
        }
        /*
         * Pre-condition:
         *      Gets workbook
         *
         * Post-condition:
         *      Read Parameters and Data from excel file
         *      and returns then as LsData
         */
        private static LsData GetData(Excel.Workbook workbook)
        {
            LsData lsData = new LsData();

            GetParameters(lsData, workbook.Sheets["Parameters"]);
            GetData(lsData, workbook.Sheets["Data"]);

            return(lsData);
        }
 private static void GetParameters(LsData lsData, Excel.Worksheet sheet)
 {
     lsData.Parameters.NumbOfTests = GetInt(sheet, new XlPosition(paramDValsSp.Row, paramDValsSp.Column));
     lsData.Parameters.NumbOfXVal  = GetInt(sheet, new XlPosition(paramDValsSp.Row + 1, paramDValsSp.Column));
     lsData.Parameters.NoiseX      = (NoiseTypes)GetInt(sheet, new XlPosition(paramDValsSp.Row + 2, paramDValsSp.Column));
     lsData.Parameters.NoiseY      = (NoiseTypes)GetInt(sheet, new XlPosition(paramDValsSp.Row + 3, paramDValsSp.Column));
     lsData.Parameters.Gamma       = GetDouble(sheet, new XlPosition(paramDValsSp.Row + 4, paramDValsSp.Column));
     lsData.Parameters.Theta       = GetDouble(sheet, new XlPosition(paramDValsSp.Row + 5, paramDValsSp.Column));
 }
        private void BtnLoadData_Click(object sender, RoutedEventArgs e)
        {
            WinForms.OpenFileDialog ofd = new WinForms.OpenFileDialog();
            ofd.Filter = "Excel File|*.xls";

            lsData =
                (ofd.ShowDialog() == WinForms.DialogResult.OK)
                    ? ExcelWorker.GetData(fileName = ofd.FileName)
                    : null;
        }
        public DataTableWindow(LsData lsData, LsResult lsResult, string filePath)
        {
            InitializeComponent();

            this.lsData   = lsData;
            this.lsResult = lsResult;
            this.filePath = filePath;

            InitializeComponents();
        }
        private static void GetData(LsData lsData, Excel.Worksheet sheet)
        {
            lsData.Parameters.InitializeMatrices();

            // Read names of X and Y values
            ReadRow(sheet, lsData.Parameters.XValsNames, dataXHeadsSp);
            lsData.Parameters.YValName = sheet.Cells[dataXHeadsSp.Row, dataXHeadsSp.Column + lsData.Parameters.XMtx.ColumnCount].Value2.ToString();

            ReadRow(sheet, lsData.Parameters.Beta, dataBValsSp);
            ReadTable(sheet, lsData.Parameters.XMtx, dataXValsSp);
            ReadColumn(sheet, lsData.Parameters.YVtr, new XlPosition(dataXValsSp.Row, dataXValsSp.Column + lsData.Parameters.XMtx.ColumnCount));
        }
Пример #9
0
        public ChartWindow(LsData lsData)
        {
            InitializeComponent();

            this.lsData = lsData;

            ClearChart();

            DrawX();
            DrawY();
            DrawYResults();
        }
        public static void Save(LsData lsData, SaveType saveType)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Excel File|*.xls";

            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Save(lsData, sfd.FileName, saveType);
        }
        public static void Save(LsData lsData, string fileName, SaveType saveType)
        {
            switch (saveType)
            {
            case SaveType.All:
                CreaeteWorksheet(fileName, lsData, WriteAllLsData);
                return;

            case SaveType.Result:
                CreaeteWorksheet(fileName, lsData, WriteResults);
                return;

            case SaveType.Data:
                CreaeteWorksheet(fileName, lsData, WriteParametersAndData);
                return;

            default:
                return;
            }
        }
Пример #12
0
        /*
         * Pre-condition:
         *      numberOfXValues, numberOfExperiments,
         *      beta and noise are set
         * Post-condition:
         *      Create lsData which can be used in further calculations
         */
        private void BtnGenerateData_Click(object sender, RoutedEventArgs e)
        {
            if (SldNumberOfXValues.Value < 2)
            {
                return;
            }

            int numberOfXValues     = (int)SldNumberOfXValues.Value;
            int numberOfExperiments = Convert.ToInt32(TbxNumberOfExperiments.Text);

            double[] beta = scrollViewerTbx.GetBeta();

            DetermineNoiseType();

            lsData =
                LsDataBuilder.Build(
                    numberOfXValues,
                    numberOfExperiments,
                    beta,
                    noiseX,
                    noiseY,
                    Convert.ToDouble(TbxGamma.Text),
                    Convert.ToDouble(TbxTheta.Text));
        }
 private static void WriteResults(Excel.Workbook xlWorkbook, LsData lsData)
 {
     WriteResults(xlWorkbook, lsData.ResultLs, "Result LS");
     WriteResults(xlWorkbook, lsData.ResultIls, "Result ILS");
 }
 private static void WriteParametersAndData(Excel.Workbook xlWorkbook, LsData lsData)
 {
     CreateParametersWorksheet(xlWorkbook.Worksheets.Item[1], lsData, "Parameters");
     CreateDataWorksheet(xlWorkbook.Worksheets.Add(), lsData, "Data");
 }
 private static void WriteAllLsData(Excel.Workbook xlWorkbook, LsData lsData)
 {
     WriteParametersAndData(xlWorkbook, lsData);
     WriteResults(xlWorkbook, lsData);
 }