Example #1
0
 public PresenterPlant(IPlants view)
 {
     model = new Model();
     this.view = view;
     this.view.deletePlant += OnDeletePlant;
     this.view.insertPlant += OnInsertPlant;
     this.view.updatePlant += OnUpdatePlant;
     view.updatePlants(getPlants());
     view.updateTypesOfPlants(getTypesOfPlants());
 }
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
 private List<string> getTypes()
 {
     List<string> result = new List<string>();
     Model model = new Model();
     IDataReader reader=model.getTypesOfPlants();
     while (reader.Read()) {
         result.Add(reader.GetString(0));
     }
     return result;
 }
Example #4
0
 public List<int> getYearsForStudy(int idStudy)
 {
     List<int> result = new List<int>();
     Model model = new Model();
     IDataReader data = model.getYearsForStudy(idStudy);
     while (data.Read())
     {
         result.Add(Convert.ToInt32(data.GetValue(0).ToString()));
     }
     return result;
 }
Example #5
0
 public List<string> getHydroconditionsForPeriod(int idStudy, int year, int period)
 {
     List<string> result = new List<string>();
     Model model = new Model();
     IDataReader data = model.getHydroconditionsForPeriod(idStudy, year, period);
     while (data.Read())
     {
         result.Add(data.GetValue(0).ToString() + " | " + data.GetValue(1).ToString() + "%");
     }
     return result;
 }
Example #6
0
 public void update(DataTable dt)
 {
     Model model = new Model();
     model.update(dt);
 }
Example #7
0
 public DataTable getPlantsTypes()
 {
     Model model = new Model();
     return model.getPlantTypes();
 }
Example #8
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();
            }
        }