private void onTypesCompare(object sender, EventArgs e) { string query = String.Format("select st.name as \"Назва дослідження\", sce.year as \"Рік\",typ.id as \"Тип блоків\",sum("); switch (sender.ToString()) { case "Загальна генерація": { query += "th.total_energy"; break; } case "Витрати (без будівництва)": { query += "th.fuel_total+th.om_domestic"; break; } case "Потужність": { query += "th.plant_capacity"; break; } } query += ") as \"Загалом\" from plants as pl, scenario as sce, study as st, thermal_plants as th, types_of_plants as typ"; for (int i = 0; i < selectedPlantsId.Count; i++) { if (i == 0) { query += String.Format(" where (st.id={0}", selectedPlantsId[i]); } else { query += String.Format(" or st.id={0}", selectedPlantsId[i]); } } query += ") and sce.id_study=st.id and th.id_scenario=sce.id and th.plant_name=pl.id and pl.typeName=typ.id"; query += " and sce.year>=" + view.currentMinYear.ToString() + " and sce.year<=" + view.currentMaxYear.ToString(); List <string> unselecteedTypes = view.listCheckBoxObj.GetUnselectedItems().ToList <string>(); for (int i = 0; i < unselecteedTypes.Count; i++) { if (i == 0) { query += String.Format(" and (pl.typeName!='{0}'", unselecteedTypes[i]); } else { query += String.Format(" and pl.typeName!='{0}'", unselecteedTypes[i]); } } if (unselecteedTypes.Count > 0) { query += ") "; } query += " group by st.name,sce.year,typ.id"; query += "\n union all \n"; query += String.Format("select st.name as \"Назва дослідження\", sce.year as \"Рік\",typ.id as \"Тип блоків\",sum("); switch (sender.ToString()) { case "Загальна генерація": { query += "hp.total_energy"; break; } case "Витрати (без будівництва)": { query += "hp.om_local"; break; } case "Потужність": { query += "hp.total_capacity"; break; } } query += ") as \"Загалом\" from plants as pl, scenario as sce, study as st, hydro_plants as hp, types_of_plants as typ"; for (int i = 0; i < selectedPlantsId.Count; i++) { if (i == 0) { query += String.Format(" where (st.id={0}", selectedPlantsId[i]); } else { query += String.Format(" or st.id={0}", selectedPlantsId[i]); } } query += ") and sce.id_study=st.id and hp.idscenario=sce.id and hp.name=pl.id and pl.typeName=typ.id"; query += " and sce.year>=" + view.currentMinYear.ToString() + " and sce.year<=" + view.currentMaxYear.ToString(); unselecteedTypes = view.listCheckBoxObj.GetUnselectedItems().ToList <string>(); for (int i = 0; i < unselecteedTypes.Count; i++) { if (i == 0) { query += String.Format(" and (pl.typeName!='{0}'", unselecteedTypes[i]); } else { query += String.Format(" and pl.typeName!='{0}'", unselecteedTypes[i]); } } if (unselecteedTypes.Count > 0) { query += ") "; } query += " group by st.name,sce.year,typ.id"; query += " order by sce.year ASC, typ.id ASC, st.name ASC"; view.updateDataTable(DB.getInstance().exec(query)); }