Example #1
0
 public Mersim getDataForHydrocondition(int idStudy, int year, int period, string hydrocondition)
 {
     Model model = new Model();
     int hydroconditionId = getHydroconditionId(hydrocondition);
     IDataReader dataTotal = model.getScenario(idStudy, year, period, hydroconditionId);
     IDataReader dataThermal = model.getThermalDataForScenario(idStudy, year, period, hydroconditionId);
     IDataReader dataHydro = model.getHydroDataForScenario(idStudy, year, period, hydroconditionId);
     Mersim mersimOne = new Mersim(dataTotal, dataThermal, dataHydro);
     return mersimOne;
 }
Example #2
0
        public Mersim getDataForHydrocondition(int idStudy, int year, int period, string hydrocondition)
        {
            Model       model            = new Model();
            int         hydroconditionId = getHydroconditionId(hydrocondition);
            IDataReader dataTotal        = model.getScenario(idStudy, year, period, hydroconditionId);
            IDataReader dataThermal      = model.getThermalDataForScenario(idStudy, year, period, hydroconditionId);
            IDataReader dataHydro        = model.getHydroDataForScenario(idStudy, year, period, hydroconditionId);
            Mersim      mersimOne        = new Mersim(dataTotal, dataThermal, dataHydro);

            return(mersimOne);
        }
Example #3
0
        public static void writeStudyToExcel(string fileName, int idStudy)
        {
            Model model = new Model();

            Exc.Application ObjExcel     = null;
            Exc.Workbook    ObjWorkBook  = null;
            Exc.Worksheet   ObjWorkSheet = null;
            try
            {
                //Приложение самого Excel
                ObjExcel = new Exc.Application();
                //Книга.
                ObjWorkBook = ObjExcel.Workbooks.Add(System.Reflection.Missing.Value);
                //Таблица.
                ObjWorkSheet = (Exc.Worksheet)ObjWorkBook.Sheets[1];

                IDataReader study     = model.getStudyForId(idStudy);
                IDataReader scenaries = model.getScanariosForStudy(idStudy);
                study.Read();
                ObjExcel.Cells[1, 1] = study.GetValue(0).ToString();
                ObjExcel.Cells[2, 1] = study.GetValue(1).ToString();

                int rowNumber = 5;
                int marginRow = 2;

                while (scenaries.Read())
                {
                    ObjExcel.Cells[rowNumber, 1]   = "Year:";
                    ObjExcel.Cells[rowNumber, 2]   = scenaries.GetValue(1).ToString();
                    ObjExcel.Cells[++rowNumber, 1] = "Period:";
                    ObjExcel.Cells[rowNumber, 2]   = scenaries.GetValue(2).ToString();
                    ObjExcel.Cells[++rowNumber, 1] = "Hydrocondition:";
                    ObjExcel.Cells[rowNumber, 2]   = scenaries.GetValue(3).ToString();
                    ObjExcel.Cells[++rowNumber, 1] = "Probality:";
                    ObjExcel.Cells[rowNumber, 2]   = scenaries.GetValue(4).ToString();

                    IDataReader hydroData = new Model().getHydroDataForScenario(idStudy, int.Parse(scenaries.GetValue(1).ToString()), int.Parse(scenaries.GetValue(2).ToString()), int.Parse(scenaries.GetValue(3).ToString()));

                    rowNumber += marginRow;
                    while (hydroData.Read())
                    {
                        for (int i = 1; i < 16; i++)
                        {
                            ObjExcel.Cells[rowNumber, i] = hydroData.GetValue(i - 1).ToString();
                        }
                        rowNumber++;
                    }

                    IDataReader thermalData = model.getThermalDataForScenario(idStudy, int.Parse(scenaries.GetValue(1).ToString()), int.Parse(scenaries.GetValue(2).ToString()), int.Parse(scenaries.GetValue(3).ToString()));
                    rowNumber += marginRow;
                    while (thermalData.Read())
                    {
                        for (int i = 1; i < 16; i++)
                        {
                            ObjExcel.Cells[rowNumber, i] = thermalData.GetValue(i - 1).ToString();
                        }
                        rowNumber++;
                    }
                    rowNumber += marginRow;
                }
                ObjWorkBook.SaveAs(fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }

            finally {
                //Закрытие книгу Excel.
                ObjWorkBook.Close();
                //Закрытие приложения Excel.
                ObjExcel.Quit();
                //Обнуляем созданые объекты
                ObjWorkBook  = null;
                ObjWorkSheet = null;
                ObjExcel     = null;
                //Вызываем сборщик мусора для их уничтожения и освобождения памяти
                GC.Collect();
            }
        }
Example #4
0
        public static void writeStudyToExcel(string fileName, int idStudy)
        {
            Model model = new Model();
            Exc.Application ObjExcel=null;
            Exc.Workbook ObjWorkBook=null;
            Exc.Worksheet ObjWorkSheet=null;
            try
            {
                //Приложение самого Excel
                ObjExcel = new Exc.Application();
                //Книга.
                ObjWorkBook = ObjExcel.Workbooks.Add(System.Reflection.Missing.Value);
                //Таблица.
                ObjWorkSheet = (Exc.Worksheet)ObjWorkBook.Sheets[1];

                IDataReader study = model.getStudyForId(idStudy);
                IDataReader scenaries = model.getScanariosForStudy(idStudy);
                study.Read();
                ObjExcel.Cells[1, 1] = study.GetValue(0).ToString();
                ObjExcel.Cells[2, 1] = study.GetValue(1).ToString();

                int rowNumber = 5;
                int marginRow = 2;

                while (scenaries.Read())
                {
                    ObjExcel.Cells[rowNumber, 1] = "Year:";
                    ObjExcel.Cells[rowNumber, 2] = scenaries.GetValue(1).ToString();
                    ObjExcel.Cells[++rowNumber, 1] = "Period:";
                    ObjExcel.Cells[rowNumber, 2] = scenaries.GetValue(2).ToString();
                    ObjExcel.Cells[++rowNumber, 1] = "Hydrocondition:";
                    ObjExcel.Cells[rowNumber, 2] = scenaries.GetValue(3).ToString();
                    ObjExcel.Cells[++rowNumber, 1] = "Probality:";
                    ObjExcel.Cells[rowNumber, 2] = scenaries.GetValue(4).ToString();

                    IDataReader hydroData = new Model().getHydroDataForScenario(idStudy, int.Parse(scenaries.GetValue(1).ToString()), int.Parse(scenaries.GetValue(2).ToString()), int.Parse(scenaries.GetValue(3).ToString()));

                    rowNumber += marginRow;
                    while (hydroData.Read())
                    {
                        for (int i = 1; i < 16; i++)
                        {
                            ObjExcel.Cells[rowNumber, i] = hydroData.GetValue(i - 1).ToString();
                        }
                        rowNumber++;
                    }

                    IDataReader thermalData = model.getThermalDataForScenario(idStudy, int.Parse(scenaries.GetValue(1).ToString()), int.Parse(scenaries.GetValue(2).ToString()), int.Parse(scenaries.GetValue(3).ToString()));
                    rowNumber += marginRow;
                    while (thermalData.Read())
                    {
                        for (int i = 1; i < 16; i++)
                        {
                            ObjExcel.Cells[rowNumber, i] = thermalData.GetValue(i - 1).ToString();
                        }
                        rowNumber++;
                    }
                    rowNumber += marginRow;
                }
                ObjWorkBook.SaveAs(fileName);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }

            finally {
                //Закрытие книгу Excel.
                ObjWorkBook.Close();
                //Закрытие приложения Excel.
                ObjExcel.Quit();
                //Обнуляем созданые объекты
                ObjWorkBook = null;
                ObjWorkSheet = null;
                ObjExcel = null;
                //Вызываем сборщик мусора для их уничтожения и освобождения памяти
                GC.Collect();
            }
        }