private bool SetProperties(Dictionary <string, object> buildingData, CExcel exls, Dictionary <string, string> propertyCellMapping, out bool changesMade) { changesMade = false; foreach (KeyValuePair <string, string> property in propertyCellMapping) { try { if (buildingData.ContainsKey(property.Key)) { object value = buildingData[property.Key]; Set(sheet, property.Value, value, ref exls); changesMade = true; } //else //{ // Set(sheet, property.Value, 0, ref exls); // //TODO //} } catch (System.Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}", property.Key), sourceFunction: "SetProperties", exception: ex); throw ex; } } return(true); }
private void BT_BuildSql_Click(object sender, EventArgs e) { RTB_Content.Clear(); DataSet ds = CExcel.Import_Excel(TB_BrowseFileName.Text); if (ds != null) { int final = ds.Tables[0].Rows.Count - 1; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (i == 0) { RTB_Content.Text += CSql.GetDataTableNameString(TB_Name.Text) + "\n"; } else if (i == ds.Tables[0].Rows.Count - 1) { RTB_Content.Text += CSql.GetDataTableColumnString(ds.Tables[0].Rows[i][0].ToString(), ds.Tables[0].Rows[i][1].ToString(), ds.Tables[0].Rows[i][3].ToString(), true) + "\n"; } else { RTB_Content.Text += CSql.GetDataTableColumnString(ds.Tables[0].Rows[i][0].ToString(), ds.Tables[0].Rows[i][1].ToString(), ds.Tables[0].Rows[i][3].ToString(), false) + "\n"; } } } }
private bool SetProperties(ModuleProcess process, CExcel exls, Dictionary <string, string> propertyCellMapping) { var nw = process.CurrentData[inputResultName] as List <object>; Dictionary <string, object> CurrentData = nw[0] as Dictionary <string, Object>; if (CurrentData == null) { return(false); } foreach (KeyValuePair <string, string> property in propertyCellMapping) { try { if (CurrentData.ContainsKey(property.Key)) { object value = CurrentData[property.Key]; Set(sheet, property.Value, value, ref exls); } else { process.CalcMessage = ""; } } catch (System.Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}, isCurrentDataMissing = {1}", property.Key, CurrentData == null), sourceFunction: "SetProperties", exception: ex); throw ex; } } return(true); }
public static void Export() { Enums.Add(default(ECashItemType)); using (var MetaFile = new CExcel(Enums, "bin", 4)) { ulong CheckSum = 0; // Server Meta Datas //////////////////////////////////////////////////////////////////////////////////////////////////// Console.WriteLine("Exporting Server Meta Data"); //MetaFile.Open("MetaDataXLS/forbidden_text.xlsx"); //CheckSum ^= MetaFile.Export<SForbiddenTextMeta>("forbidden_text", "./MetaDataServer"); //Console.WriteLine("Exporting Checksum Files"); //var Stream = new CStream(); //Stream.Push(CheckSum); //Stream.SaveFile("./MetaDataServer/checksum.bin"); //// Stream.SaveFile("./MetaData/checksum.bytes"); MetaFile.Open("../../../Design/XmlTableFile/Config.xml"); CheckSum ^= MetaFile.Export <SConfigMeta>("Config", "../../Bin/GameServer/GameServer/x64/MetaData"); Console.WriteLine("Checksum : " + CheckSum.ToString()); Console.WriteLine("Press Any Key To Exit"); Console.ReadKey(); } }
private void Set(string sheet, string cell, object value, ref CExcel exls) { if (!exls.SetCellValue(sheet, cell, value)) { throw new Exception(String.Format("Could not set cell {} to value {2} in sheet {3}", cell, value, sheet)); } }
private bool SetDistrictProperties(Dictionary <string, object> currentData, CExcel exls, Dictionary <string, string> propertyCellMapping, string sheetName) { foreach (KeyValuePair <string, string> property in propertyCellMapping) { try { if (currentData.ContainsKey(property.Key)) { object value = currentData[property.Key]; Set(sheetName, property.Value, value, ref exls); } else { return(false); } } catch (Exception ex) { SendErrorMessage( message: String.Format(ex.Message + "\t key = {0}, CurrentDataMissing = {1}", property.Key, currentData == null), sourceFunction: "SetDistrictProperties", exception: ex); throw ex; } } return(true); }
public static void Export() { using (var MetaFile = new CExcel(Enums, "bytes", 0)) { // Client Meta Datas //////////////////////////////////////////////////////////////////////////////////////////////////// Console.WriteLine("Exporting Client Meta Data"); Console.WriteLine("Exporting Done !!!"); Console.WriteLine("Press Any Key To Close."); Console.ReadKey(); } }
private bool SetDistrictProperties(Dictionary <string, Object> currentData, CExcel exls, Dictionary <string, string> propertyCellMapping) { #if (ToClipBoard) using (FileStream fs = File.Open(@"C:\Temp\EcoTemp\DistData.csv", FileMode.Create)) { using (StreamWriter sw = new StreamWriter(fs)) { foreach (KeyValuePair <string, object> pair in currentData) { sw.WriteLineAsync(string.Format("{0}\t{1}\t{2}", pair.Key, propertyCellMapping[pair.Key], pair.Value)); } } } #endif foreach (KeyValuePair <string, string> property in propertyCellMapping) { //Dictionary<string, object> CurrentData = process.CurrentData; try { { if (currentData.ContainsKey(property.Key)) { object value = currentData[property.Key]; double val = Convert.ToDouble(value); if (val < 0) { //process.CalcMessage = String.Format("Property '{0}' has invalid data, only values equal or above zero is allowed; value: {1}", property.Key, val); return(false); } Set(sheet, property.Value, value, ref exls); } else { //process.CalcMessage = ""; return(false); } } } catch (System.Exception ex) { SendErrorMessage( message: String.Format(ex.Message + "\t key = {0}, isCurrentDataMissing = {1}", property.Key, currentData == null), sourceFunction: "SetProperties", exception: ex); throw ex; } } return(true); }
static void Main(string[] args) { SetConsoleCtrlHandler(new HandlerRoutine(ConsoleCtrlCheck), true); DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_CLOSE, MF_BYCOMMAND); using (var MetaFile = new CExcel(new List <Enum>(), "bin", 0)) { MetaFile.Open("test.xlsx"); //MetaFile.ExportEnum("test", "EnumType", "EnumCol", "EnumFile.cs", "public enum ETest : sbyte\n{{\n{0}\n}}\n"); MetaFile.ExportEnum("test", "EnumType", "EnumCol", "EnumFile.cs", "public enum ETest : sbyte\n{{\n{0}\n}}\n"); } }
private bool GetProperties(CExcel exls, KeyValuePair <string, string> cellMapping, ref Dictionary <string, object> buildingDefaultValues) { try { buildingDefaultValues.Add(cellMapping.Key, exls.GetCellValue(sheet, cellMapping.Value)); } catch (Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}", cellMapping.Key), sourceFunction: "GetProperties", exception: ex); return(false); } return(true); }
private bool GetBuildingDefaultValues(CExcel exls, out Dictionary <string, object> buildingDefaultValues) { buildingDefaultValues = new Dictionary <string, object>(); try { if (!GetProperties(exls, buildingCellMapping, ref buildingDefaultValues)) { return(false); } return(true); } catch (Exception ex) { return(false); } }
private void BT_SqlInsert_Click(object sender, EventArgs e) { RTB_Content.Clear(); DataSet ds = CExcel.Import_Excel(TB_BrowseFileName.Text); string[] ColumnName = new string[ds.Tables[0].Rows.Count - 1]; string[] ColumnMean = new string[ds.Tables[0].Rows.Count - 1]; string[] ColumnStatus = new string[ds.Tables[0].Rows.Count - 1]; for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++) { ColumnName[i] = ds.Tables[0].Rows[i + 1][0].ToString(); ColumnMean[i] = ds.Tables[0].Rows[i + 1][2].ToString(); ColumnStatus[i] = ds.Tables[0].Rows[i + 1][3].ToString(); } if (ds != null) { RTB_Content.Text = CSql.SCADA_Insert(ColumnName, TB_Name.Text, ColumnStatus); } }
private bool SetBuildingProperties(Dictionary <string, object> buildingData, CExcel exls, Dictionary <string, string> propertyCellMapping, out bool changesMade) { #if (ToClipBoard) using (FileStream fs = File.Open(@"C:\Temp\EcoTemp\BuildingData.csv", FileMode.Append)) { using (StreamWriter sw = new StreamWriter(fs)) { foreach (KeyValuePair <string, string> pair in propertyCellMapping) { if (buildingData.ContainsKey(pair.Key)) { sw.WriteLineAsync(string.Format("{0}\t{1}\t{2}", pair.Key, pair.Value, buildingData[pair.Key])); } } } } #endif changesMade = false; foreach (KeyValuePair <string, string> property in propertyCellMapping) { try { if (buildingData.ContainsKey(property.Key)) { object value = buildingData[property.Key]; Set(sheet, property.Value, value, ref exls); changesMade = true; } //else //{ // Set(sheet, property.Value, 0, ref exls); // //TODO //} } catch (System.Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}", property.Key), sourceFunction: "SetProperties", exception: ex); throw ex; } } return(true); }
private bool SetProperties(ModuleProcess process, CExcel exls, Dictionary <string, string> propertyCellMapping) { var nw = process.CurrentData[inputResultName] as List <Object>; //var CurrentData = nw[0] as Dictionary<string, object>; foreach (KeyValuePair <string, string> property in propertyCellMapping) { Dictionary <string, object> CurrentData = nw[0] as Dictionary <string, object>; try { { if (CurrentData.ContainsKey(property.Key)) { object value = CurrentData[property.Key]; double val = Convert.ToDouble(value); if (val < 0) { process.CalcMessage = String.Format("Property '{0}' has invalid data, only values equal or above zero is allowed; value: {1}", property.Key, val); return(false); } Set(sheet, property.Value, value, ref exls); } else { process.CalcMessage = ""; return(false); } } } catch (System.Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}, isCurrentDataMissing = {1}", property.Key, CurrentData == null), sourceFunction: "SetProperties", exception: ex); throw ex; } } return(true); }
//string buildingsData = Newtonsoft.Json.JsonConvert.SerializeObject(process.CurrentData["Buildings"]); //List<Dictionary<string, object>> buildings = Newtonsoft.Json.JsonConvert.DeserializeObject(buildingsData, typeof(List<Dictionary<string, object>>)) as List<Dictionary<string, object>>; //Set common properties //if (!SetProperties(process, exls, generalCellMapping)) // return false; //Calculate kpi //outputDetailed = new Ecodistrict.Messaging.Data.OutputDetailed(process.KpiId); //double kpiValue = 0; //int noRenovatedBuildings = 0; //NEW_CODE: Start with getting all default (Inital start) values from the excel Sheet for buildingdata //Dictionary<string, object> buildingDefaultValues = new Dictionary<string, object>(); //if (buildings != null && buildings.Count > 0) // if (!GetBuildingDefaultValues(exls, out buildingDefaultValues)) // return false; // foreach (Dictionary<string, object> buildingData in buildings) // { // double kpiValuei; // bool changesMade; // if (!SetInputDataOneBuilding(process,buildingData, exls, out changesMade)) // return false; // kpiValuei = 100 * Convert.ToDouble(exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId])); // if (changesMade) // ++noRenovatedBuildings; // //NEW_CODE: Reset all used building values // if (!SetInputDataOneBuilding(process, buildingDefaultValues, exls, out changesMade)) // return false; // kpiValue += kpiValuei; // outputDetailed.KpiValueList.Add(new Ecodistrict.Messaging.Data.GeoObject("building", buildingData[buidingIdKey] as string, process.KpiId, kpiValuei)); // } // if (noRenovatedBuildings > 0) // kpiValue /= Convert.ToDouble(noRenovatedBuildings); // output = new Ecodistrict.Messaging.Data.Output(process.KpiId, Math.Round(kpiValue, 1)); // return true; //} //catch (System.Exception ex) //{ // SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); // throw ex; //} //} private bool GetBuildingDefaultValues(CExcel exls, out Dictionary <string, object> DefaultValues) { DefaultValues = new Dictionary <string, object>(); try { #region Get data if (!GetProperties(exls, generalBuildingCellMapping, ref DefaultValues)) { return(false); } if (!GetProperties(exls, paidSeparatelyChoiseCellMapping, ref DefaultValues)) { return(false); } if (!GetProperties(exls, householdElectricityCellMapping, ref DefaultValues)) { return(false); } if (!GetProperties(exls, householdHotWaterCellMapping, ref DefaultValues)) { return(false); } if (!GetProperties(exls, householdCoolingCellMapping, ref DefaultValues)) { return(false); } if (!GetProperties(exls, householdSpaceHeatingCellMapping, ref DefaultValues)) { return(false); } #endregion return(true); } catch (Exception ex) { return(false); } }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Output output, out OutputDetailed outputDetailed) { output = null; outputDetailed = null; if (!CheckAndReportDistrictProp(process, process.CurrentData, inputResultName)) { return(false); } if (!SetProperties(process, exls, GreenCellMapping)) { return(false); } double kpiValue; kpiValue = Convert.ToDouble(exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId])); output = new Output(process.KpiId, Math.Round(kpiValue, 1)); return(true); }
private void BT_BuildCs_Click(object sender, EventArgs e) { RTB_Content.Clear(); DataSet ds = CExcel.Import_Excel(TB_BrowseFileName.Text); if (ds != null) { string[] ColumnName = new string[ds.Tables[0].Rows.Count - 1]; string[] ColumnMean = new string[ds.Tables[0].Rows.Count - 1]; string[] ColumnStatus = new string[ds.Tables[0].Rows.Count - 1]; for (int i = 0; i < ds.Tables[0].Rows.Count - 1; i++) { ColumnName[i] = ds.Tables[0].Rows[i + 1][0].ToString(); ColumnMean[i] = ds.Tables[0].Rows[i + 1][2].ToString(); ColumnStatus[i] = ds.Tables[0].Rows[i + 1][3].ToString(); } RTB_Content.Text += CSql.GetCsUsingString(); RTB_Content.Text += CSql.GetCsClassHeadString(TB_Name.Text); RTB_Content.Text += CSql.GetCsClassShuXingString(ColumnName); RTB_Content.Text += CSql.GetCsClassRegionString(ColumnName, ColumnMean); RTB_Content.Text += CSql.GetCsClassFunctionString(ColumnName, TB_Name.Text, ColumnStatus); } }
public void Export() { try { int iCnt = 0; Load(); //TODO: figure out why this.count is = to 0. it should be = to 2 string[,] transactions = new string[this.Count + 1, 6]; transactions[0, 0] = "Ticker"; transactions[0, 1] = "Transaction Date"; transactions[0, 2] = "Quantity"; transactions[0, 3] = "Price"; transactions[0, 4] = "Buy"; while (iCnt < this.Count) { iCnt++; CTransaction v = this[iCnt - 1]; transactions[iCnt, 0] = v.Ticker.ToString(); transactions[iCnt, 1] = v.TransDate.ToString(); transactions[iCnt, 2] = v.Quantity.ToString(); transactions[iCnt, 3] = v.PricePerSharePaid.ToString(); transactions[iCnt, 4] = v.Buy.ToString(); } CExcel.Export("Transaction.xlsx", transactions); } catch (Exception ex) { CErrorLog err = new CErrorLog(); err.LogError(ex.Message); throw ex; } }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { output = null; outputDetailed = null; bool perHeatedArea = false; if (!KpiList.Contains(process.KpiId)) { process.CalcMessage = String.Format("kpi not available for this module, requested kpi: {0}", process.KpiId); return(false); } switch (process.KpiId) { case kpi_gwp: case kpi_peu: break; case kpi_gwp_per_heated_area: case kpi_peu_per_heated_area: perHeatedArea = true; break; } if (!CheckAndReportDistrictProp(process, process.CurrentData, inputDistrictName)) { return(false); } if (!CheckAndReportBuildingProp(process, process.CurrentData, inputBuildingName)) { return(false); } var nw = process.CurrentData[inputDistrictName] as List <object>; var districtdata = nw[0] as Dictionary <string, object>; var myBuildings = process.CurrentData[inputBuildingName] as List <object>; //Set common properties if (!SetDistrictProperties(districtdata, exls, districtCellMapping)) { return(false); } //Get all default building data data from Excel document var buildingDefaultValues = new Dictionary <string, object>(); if (myBuildings != null && myBuildings.Count > 0) { if (!GetBuildingDefaultValues(exls, out buildingDefaultValues)) { return(false); } } outputDetailed = new OutputDetailed(process.KpiId); double kpiValue = 0; int noOfRenovatedBuildings = 0; foreach (Dictionary <string, object> buildingData in myBuildings) { double kpiValuei; bool changesMade; if (!SetInputDataOneBuilding(buildingData, exls, out changesMade)) { return(false); } kpiValuei = Convert.ToDouble(exls.GetCellValue(sheet, kpiCellMapping[process.KpiId])); if (changesMade) { noOfRenovatedBuildings++; } if (noOfRenovatedBuildings % 50 == 0) { SendStatusMessage(string.Format("{0} building processed", noOfRenovatedBuildings)); } //Reset buildingdata do tefault if (buildingDefaultValues != null && !SetInputDataOneBuilding(buildingDefaultValues, exls, out changesMade)) { return(false); } if (perHeatedArea) { kpiValuei *= 1000; //From tonnes CO2 eq / m2 to kg CO2 eq/ m2 and MWh / m2 to kWh/ m2 resp. } kpiValue += kpiValuei; outputDetailed.KpiValueList.Add(new GeoObject("building", buildingData["building_id"] as string, process.KpiId, kpiValuei)); } if (noOfRenovatedBuildings > 0 & (process.KpiId == kpi_gwp | process.KpiId == kpi_peu)) { kpiValue /= 30.0 * Convert.ToDouble(noOfRenovatedBuildings); } else if (process.KpiId == kpi_gwp_per_heated_area | process.KpiId == kpi_peu_per_heated_area) { kpiValue /= 30.0 * Convert.ToDouble(250000); //TMP } output = new Ecodistrict.Messaging.Data.Output(process.KpiId, Math.Round(kpiValue, 1)); return(true); }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { try { output = null; outputDetailed = null; //Check and prepare data //Dictionary<string, object> district_data; //GeoValue buildingsAsIS; if (!CheckAndReportDistrictProp(process, process.CurrentData, inputDistrictName)) { return(false); } if (!CheckAndReportDistrictProp(process, process.CurrentData, inputBuildingName)) { return(false); } var nw = process.CurrentData[inputDistrictName] as List <Object>; var districtData = nw[0] as Dictionary <string, Object>; var myBuildings = process.CurrentData[inputBuildingName] as List <Object>; //Set common properties if (!SetDistrictProperties(districtData, exls, generalCellMapping)) { return(false); } //Calculate kpi //NEW_CODE: Start with getting all default (Inital start) values from the excel Sheet for buildingdata Dictionary <string, object> buildingDefaultValues = new Dictionary <string, object>(); if (myBuildings != null && myBuildings.Count > 0) { if (!GetBuildingDefaultValues(exls, out buildingDefaultValues)) { return(false); } } outputDetailed = new Ecodistrict.Messaging.Data.OutputDetailed(process.KpiId); double kpiValue = 0; int noRenovatedBuildings = 0; foreach (Dictionary <string, object> buildingData in myBuildings) { double kpiValuei; bool changesMade; if (!SetInputDataOneBuilding(buildingData, exls, out changesMade)) { return(false); } kpiValuei = Convert.ToDouble(exls.GetCellValue(sheet, kpiCellMapping[process.KpiId])); if (changesMade) { ++noRenovatedBuildings; } if (noRenovatedBuildings % 50 == 0) { SendStatusMessage(string.Format("{0} building processed", noRenovatedBuildings)); } //NEW_CODE: Reset all used building values if (buildingDefaultValues != null && !SetInputDataOneBuilding(buildingDefaultValues, exls, out changesMade)) { return(false); } kpiValue += kpiValuei; //TODO fix this below outputDetailed.KpiValueList.Add(new Ecodistrict.Messaging.Data.GeoObject("building", buildingData["building_id"] as string, process.KpiId, kpiValuei)); } if (noRenovatedBuildings > 0 && (process.KpiId != kpi_totalLCC)) { kpiValue /= Convert.ToDouble(noRenovatedBuildings); } output = new Ecodistrict.Messaging.Data.Output(process.KpiId, Math.Round(kpiValue, 1)); SendStatusMessage(string.Format("Totally {0} building processed", noRenovatedBuildings)); return(true); } catch (System.Exception ex) { SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); throw ex; } }
private bool SetInputDataOneBuilding(Dictionary <string, object> buildingData, CExcel exls, out bool changesMade) { changesMade = false; bool changesMade_i = false; try { #region Set Data if (!SetProperties(buildingData, exls, buildingCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; #endregion return(true); } catch (System.Exception ex) { return(false); } }
private bool GetBuildingDefaultValues(CExcel exls, out Dictionary <string, object> buildingDefaultValues) { buildingDefaultValues = new Dictionary <string, object>(); try { #region Get data if (!GetProperties(exls, buildingCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, heatingSystemCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, heatingPumpCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, heatingSystemBoreHoleCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, heatingSystemCirculationPumpCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, buildingShellInsulationMaterial1CellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, buildingShellInsulationMaterial2CellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, buildingShellFacadeSystemCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, buildingShellWindowsCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, buildingShellDoorsCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, VentilationSystemVentilationDuctsCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, VentilationSystemAirflowAssemblyCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, VentilationSystemDistributionHousingsCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, RadiatorsCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, WaterTapsCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, PipingSystemsCopperCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, PipingSystemsPEXCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, PipingSystemsPPCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, PipingSystemsCastIronCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, PipingSystemsGalvanisedSteelCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, PipingSystemsReliningCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, ElectricalWiringCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, EnergyProductionCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, BuildingCondBoilersCellMapping, ref buildingDefaultValues)) { return(false); } if (!GetProperties(exls, CalcExtraCommandsCellMapping, ref buildingDefaultValues)) { return(false); } #endregion return(true); } catch (Exception ex) { return(false); } }
private bool SetProperties(ModuleProcess process, Dictionary <string, object> data, CExcel exls, Dictionary <string, string> propertyCellMapping) { foreach (KeyValuePair <string, string> property in propertyCellMapping) { try { if (!CheckAndReportDistrictProp(process, data, property.Key)) { return(false); } object value = data[property.Key]; double val = Convert.ToDouble(value); Set(sheetInput, property.Value, value, ref exls); } catch (System.Exception ex) { SendErrorMessage(message: String.Format(ex.Message + "\t key = {0}, isDataMissing = {1}", property.Key, data == null), sourceFunction: "SetProperties", exception: ex); throw ex; } } return(true); }
bool SetInput(ModuleProcess process, Dictionary <string, object> dataAsIS, Dictionary <string, object> dataVariant, KeyValuePair <string, string> settingCellMapping, Dictionary <string, string> propertyCellMapping, CExcel exls, out bool Used) { //Used = true; //Set(sheetSettings, settingCellMapping.Value, "Y", ref exls); //if (!SetProperties(process, dataAsIS, exls, propertyCellMapping)) // return false; //return true; Used = false; if (dataVariant.ContainsKey(settingCellMapping.Key)) { if (dataVariant[settingCellMapping.Key] as string == null) { process.CalcMessage = "Module setting not properly set in database"; return(false); } if (dataVariant[settingCellMapping.Key] as string == "Yes") { Used = true; Set(sheetSettings, settingCellMapping.Value, "Y", ref exls); if (!SetProperties(process, dataAsIS, exls, propertyCellMapping)) { return(false); } } else { exls.SetCellValue(sheetSettings, settingCellMapping.Value, "N"); } } else { exls.SetCellValue(sheetSettings, settingCellMapping.Value, "N"); } return(true); }
private bool SetInputDataOneBuilding(Dictionary <string, object> buildingData, CExcel exls, out bool changesMade) { changesMade = false; bool changesMade_i = false; try { //Antwerp fix if (UseAntwerpFix) { Dictionary <string, object> buildingExtraData = new Dictionary <string, object>(); if (buildingData.ContainsKey(cHeatingSystemFieldName)) { if (buildingData[cHeatingSystemFieldName] != null) { if ((string)buildingData[cHeatingSystemFieldName] == cHeatingSystemCommand) { buildingExtraData.Add(cHeatingSystemDestination, cHeatingSystemValue); } } } if (buildingData.ContainsKey(cFacadeMaterialFieldName)) { if (buildingData[cFacadeMaterialFieldName] != null) { if ((string)buildingData[cFacadeMaterialFieldName] == cFacadeMaterialCommand) { buildingExtraData.Add(cFacadeMaterialDestination, cFacadeMaterialValue); } } } if (buildingData.ContainsKey(cRoofMaterialFieldName)) { if (buildingData[cRoofMaterialFieldName] != null) { if ((string)buildingData[cRoofMaterialFieldName] == cRoofMaterialCommandExtraInsCommand) { buildingExtraData.Add(cRoofMaterialDestination, cRoofMaterialCommandExtraInsValue); } else if ((string)buildingData[cRoofMaterialFieldName] == cRoofMaterialCommandVegRoofCommand) { buildingExtraData.Add(cRoofMaterialDestination, cRoofMaterialCommandVegRoofValue); } } } if (buildingData.ContainsKey(cGlazingTypeFieldName)) { if (buildingData[cGlazingTypeFieldName] != null) { if ((string)buildingData[cGlazingTypeFieldName] == cGlazingTypeDoubleGlazeCommand) { buildingExtraData.Add(cGlazingTypeDestination, cGlazingTypeDoubleGlazeValue); } else if ((string)buildingData[cGlazingTypeFieldName] == cGlazingTypeTripleGlazeCommand) { buildingExtraData.Add(cGlazingTypeDestination, cGlazingTypeTripleGlazeValue); } } } if (buildingExtraData.Count > 0) { if (!SetProperties(buildingExtraData, exls, CalcExtraCommandsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; } } //end Antwerp fix #region Set Data if (!SetProperties(buildingData, exls, buildingCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, heatingSystemCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, heatingPumpCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, heatingSystemBoreHoleCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, heatingSystemCirculationPumpCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, buildingShellInsulationMaterial1CellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, buildingShellInsulationMaterial2CellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, buildingShellFacadeSystemCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, buildingShellWindowsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, buildingShellDoorsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, VentilationSystemVentilationDuctsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, VentilationSystemAirflowAssemblyCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, VentilationSystemDistributionHousingsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, RadiatorsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, WaterTapsCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, PipingSystemsCopperCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, PipingSystemsPEXCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, PipingSystemsPPCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, PipingSystemsCastIronCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, PipingSystemsGalvanisedSteelCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, PipingSystemsReliningCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, ElectricalWiringCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, EnergyProductionCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; if (!SetProperties(buildingData, exls, BuildingCondBoilersCellMapping, out changesMade_i)) { return(false); } changesMade = changesMade | changesMade_i; #endregion return(true); } catch (System.Exception ex) { return(false); } }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { try { output = null; outputDetailed = null; if (!KpiList.Contains(process.KpiId)) { process.CalcMessage = "Kpi not available for this module"; return(false); } if (!CheckAndReportDistrictProp(process, process.CurrentData, inputDistrictName)) { return(false); } string dbKpiId = kpi_kpi_mapping[process.KpiId]; double kpiValue = 0; var nw = process.CurrentData[inputDistrictName] as List <Object>; var districtData = nw[0] as Dictionary <string, Object>; if (!SetDistrictProperties(districtData, exls, propertyCellMapping_CalcSheet, sheetInput)) { return(false); } if (!SetDistrictProperties(districtData, exls, propertyCellMapping_MeasureSheet, sheetSettings)) { return(false); } double?val = exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId]) as double?; if (val == null) { return(false); } kpiValue = Math.Round((double)val, 1); output = new Ecodistrict.Messaging.Data.Output(process.KpiId, kpiValue); return(true); #region Old Code //Prepare AsIs data //if (process.As_IS_Data == null) //{ // process.CalcMessage = "No as is data"; // return false; //} ////string distrName = "District"; //string distrName = "District trafic area"; //if (!process.As_IS_Data.ContainsKey(distrName)) //{ // process.CalcMessage = "As is district information missing"; // return false; //} //Dictionary<string, object> dataAsIS ; //if (process.As_IS_Data[distrName] is Dictionary<string, object>) // dataAsIS = process.As_IS_Data[distrName] as Dictionary<string, object>; //else //{ // process.CalcMessage = "As is data received from data module is wrongly formated"; // return false; //} ////AsIS //if (process.IsAsIS) //{ // if (!dataAsIS.ContainsKey(dbKpiId)) // { // process.CalcMessage = "As is information missing"; // return false; // } // kpiValue = Convert.ToDouble(dataAsIS[dbKpiId]); //} ////Variant //else //{ // //Prepare Variant data // if (process.Variant_Data == null) // { // process.CalcMessage = "No variant data"; // return false; // } // if (!process.Variant_Data.ContainsKey(distrName)) // { // process.CalcMessage = "Variant district information missing"; // return false; // } // Dictionary<string, object> dataVariant; // if (process.Variant_Data[distrName] is Dictionary<string, object>) // dataVariant = process.Variant_Data[distrName] as Dictionary<string, object>; // else // { // process.CalcMessage = "Variant data received from data module is wrongly formated"; // return false; // } // //Set Data // if (!SetProperties(process, dataAsIS, exls, propertyCellMapping_AsIs)) // return false; // if (!SetProperties(process, dataVariant, exls, propertyCellMapping_General)) // return false; // //01 // bool used01; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use01, propertyCellMapping_01, exls, out used01)) // return false; // //02 // bool used02; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use02, propertyCellMapping_02, exls, out used02)) // return false; // //03 // bool used03; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use03, propertyCellMapping_03, exls, out used03)) // return false; // //04 // bool used04; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use04, propertyCellMapping_04, exls, out used04)) // return false; // //05 // bool used05; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use05, propertyCellMapping_05, exls, out used05)) // return false; // //06 // bool used06; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use06, propertyCellMapping_06, exls, out used06)) // return false; // //07 // bool used07; // if (used06) // { // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use07, propertyCellMapping_07_1, exls, out used07)) // return false; // } // else // { // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use07, propertyCellMapping_07_2, exls, out used07)) // return false; // } // //08 // bool used08; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use08, propertyCellMapping_08, exls, out used08)) // return false; // //09 // bool used09; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use09, propertyCellMapping_09, exls, out used09)) // return false; // //10 // bool used10; // if (!SetInput(process, dataAsIS, dataVariant, propertyCellMapping_Use10, propertyCellMapping_10, exls, out used10)) // return false; // double? val = exls.GetCellValue(sheetOutput, kpiCellMapping[process.KpiId]) as double?; // if (val == null) // return false; // kpiValue = Math.Round((double)val,1); //} //output = new Ecodistrict.Messaging.Data.Output(process.KpiId, kpiValue); //return true; #endregion } catch (System.Exception ex) { SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); throw ex; } }
protected override bool CalculateKpi(ModuleProcess process, CExcel exls, out Ecodistrict.Messaging.Data.Output output, out Ecodistrict.Messaging.Data.OutputDetailed outputDetailed) { try { output = null; outputDetailed = null; if (!KpiList.Contains(process.KpiId)) { process.CalcMessage = "kpi not avaiable for this module"; return(false); } if (process.CurrentData == null) { process.CalcMessage = "Data missing"; return(false); } if (!SetProperties(process, exls, propertyCellMapping_STGreen)) { return(false); } //if (process.KpiId == kpi_green) // if (!SetProperties(process, exls, propertyCellMapping_Green)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_biodiversity) | // (process.KpiId == kpi_social_value) | // (process.KpiId == kpi_climate_adaptation)) // if (!SetProperties(process, exls, propertyCellMapping_BSK)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_social_value) | // (process.KpiId == kpi_climate_adaptation)) // if (!SetProperties(process, exls, propertyCellMapping_SK)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_biodiversity)) // if (!SetProperties(process, exls, propertyCellMapping_B)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_social_value)) // if (!SetProperties(process, exls, propertyCellMapping_S)) // return false; //if ((process.KpiId == kpi_green) | // (process.KpiId == kpi_climate_adaptation)) // if (!SetProperties(process, exls, propertyCellMapping_K)) // return false; //} //string outSheet = "EXISTING"; //if (process.Request.variantId != null) //{ // outSheet = "PLANNED"; //} //double? val = exls.GetCellValue(outSheet, kpiCellMapping[process.KpiId]) as double?; double?val = exls.GetCellValue(sheet, kpiCellMapping[process.KpiId]) as double?; if (val == null) { return(false); } double value = Math.Round((double)val, 2); //double value; //if (process.KpiId == kpi_green) // value = Math.Round((double)val, 2); //else // value = Math.Round((double)val * 100.0, 0); output = new Ecodistrict.Messaging.Data.Output(process.KpiId, value); return(true); } catch (System.Exception ex) { SendErrorMessage(message: ex.Message, sourceFunction: "CalculateKpi", exception: ex); throw ex; } }
static void Run(object param) { if (!isRun) { isRun = true; try { //получаем настройки приложения var sett = Properties.Settings.Default; sett.Reload(); //элементы для сравнения с файла List <Element> l_elements = new List <Element>(); string new_workbookfile; //куда сохраняем результат bool iswritefile = false; //нужно ли что-то отправлять int i_write = 0; //сколько строк было удалено //формируем новый полный путь для копии файла int ind = sett.FullNameFileSaveTemp.IndexOf('.'); string name = sett.FullNameFileSaveTemp.Substring(0, ind); string expansion = sett.FullNameFileSaveTemp.Substring(ind + 1, sett.FullNameFileSaveTemp.Length - ind - 1); new_workbookfile = name + "_" + DateTime.Now.ToString().Replace('.', '_').Replace(':', '_') + "." + expansion; using (CExcel excel = new CExcel()) { using (CWorkbook workbook_read = excel.OpenWorkbook(sett.FullNameFileExcel)) { //создали копию файла workbook_read.SaveAs(new_workbookfile); } using (CWorkbook workbook_read = excel.OpenWorkbook(sett.FullNameFileExcel)) { using (CWorkbook workbook_write = excel.OpenWorkbook(new_workbookfile)) { CWorkbook.ProfiCreditWorksheet worksheet_read = workbook_read.ActiveSheet; CWorkbook.ProfiCreditWorksheet worksheet_write = workbook_write.ActiveSheet; object valCounterparty = null; //контрагент что ежит object valFinishDate = null; //срок до что лежит string counterparty = null; //контрагент DateTime?finishdate; //срок до к типу дата и время int i = 1; //индекс строки в файле bool iswrite; //нужно ли оставить в копии файла DateTime tempdt = DateTime.Now.AddDays(sett.OldDay); //колько дней сдвинуть текущую дату DateTime dt = new DateTime(tempdt.Year, tempdt.Month, tempdt.Day); int sizecol = 0; //кол-о колонок в файле object val = null; //определяем кол-во анализируемых столбцов по содержимому первых ячеек каждого столбца do { val = worksheet_read.GetCells(1, i); i++; } while (val != null); sizecol = i - 2; i = 2; do { iswrite = false; //каждый раз сбрасываем признак того, что нужно ли сохранить запись в копии файла valCounterparty = worksheet_read.GetCells(i, sett.ColumnIndexCounterparty); if (valCounterparty != null) { counterparty = valCounterparty.ToString().Trim(); valFinishDate = worksheet_read.GetCells(i, sett.ColumnIndexFinishDate); finishdate = valFinishDate as DateTime?; if (finishdate != null) { tempdt = finishdate.Value; tempdt = new DateTime(tempdt.Year, tempdt.Month, tempdt.Day); if ((tempdt.Date <= dt.Date) && (tempdt.Date >= DateTime.Now)) { iswrite = true; } } else { iswrite = true; } l_elements.Add(new Element() { Counterparty = counterparty, FinishDate = finishdate, ValFinishDate = valFinishDate }); if (!iswrite) { worksheet_write.RowDelete(i - i_write); i_write++; } else { iswritefile = true; } i++; } else { break; } } while (valCounterparty != null); if (iswritefile) { workbook_write.Save(); } } } } //если были записи - то отправляем с вложением файла копии if (iswritefile) { Mail.RunMailMessage(sett.MailServer, sett.MailAddressTo, sett.MailAddressFrom, sett.MainSendNotEmptyBodyMess, "По документу: было выявлено всего " + (l_elements.Count - i_write).ToString() + " записей, срок жизни которых истекает через " + sett.OldDay.ToString() + " дней и меньше.\r\nПодробности во вложении." + "\r\n Соощение сформировано: " + DateTime.Now.ToString(), new string[] { new_workbookfile }); } //иначе-по настройкам либо отправляем, либо нет сообщение о том, что ничего не выявлено else if (sett.IsSendEmptyBody) { Mail.RunMailMessage(sett.MailServer, sett.MailAddressFrom, sett.MailAddressFrom, sett.MainSendEmptyBodyMess, "По документу: записи, срок жизни которых истекает через " + sett.OldDay.ToString() + " дней и меньше, не обнаружены." + "\r\n Соощение сформировано: " + DateTime.Now.ToString()); } try { File.Delete(new_workbookfile); } catch (Exception exp) { Mail.RunMailMessage(sett.MailServer, sett.MailAddressFrom, sett.MailAddressFrom, "Ошибка выполнения MailOutExcel по файлу", exp.Message); } //[email protected];[email protected];[email protected]" //RunMailMessage(sett.MailServer, "[email protected];[email protected];", "*****@*****.**", "Тестовое сообщение", "Прошу подтвердить обратным письмом, что сообщения до Вас доходят"); using (Stream stream = new FileStream("log.txt", FileMode.Create, FileAccess.Write)) { using (TextWriter tw = new StreamWriter(stream, Encoding.Unicode)) { tw.WriteLine("Все хорошо"); tw.Flush(); } } } catch (Exception exp) { using (Stream stream = new FileStream("log.txt", FileMode.Create, FileAccess.Write)) { using (TextWriter tw = new StreamWriter(stream, Encoding.Unicode)) { tw.WriteLine(exp.Message); tw.Flush(); } } } Console.WriteLine("Сообщение отправлено в " + DateTime.Now.ToString()); isRun = false; } }
/// <summary> /// Calculates the Kpi when the dashboard has sent a StartModuleRequest /// </summary> /// <param name="indata">Collection of indata as a dictionary. Key is the name of the parameter /// and Value is an object variable with value of the parameter</param> /// <param name="kpiId">Kpi id. Decides which Kpi should be calculated</param> /// <param name="exls">Excel object in which the calculations should take place</param> /// <returns></returns> protected override Ecodistrict.Messaging.Output.Outputs CalculateKpi(Dictionary <string, Input> indata, string kpiId, CExcel exls) { Ecodistrict.Messaging.Output.Outputs outputs; switch (kpiId) { case kpi_CheeseTaste: outputs = CalcCheeseTasteKpi(indata, exls); break; case kpi_CheesePrice: outputs = CalcCheesePriceKpi(indata, exls); break; default: throw new ArgumentException(string.Format("Kpi id unknown! ({0})", kpiId)); } return(outputs); }
private Ecodistrict.Messaging.Output.Outputs CalcCheeseTasteKpi(Dictionary <string, Input> indata, CExcel exls) { Ecodistrict.Messaging.Output.Outputs outputs = new Ecodistrict.Messaging.Output.Outputs(); try { foreach (var input in indata) { //Set all input values switch (input.Key) { case "Cheddar_Taste": //C3 cell exls.SetCellValue("Sheet1", "B3", input.Value); break; case "Gamle_Ole_Taste": exls.SetCellValue("Sheet1", "B4", input.Value); break; case "Vasterbotten_Taste": exls.SetCellValue("Sheet1", "B5", input.Value); break; case "Edamer_Taste": exls.SetCellValue("Sheet1", "B6", input.Value); break; case "Maasdamer_Taste": exls.SetCellValue("Sheet1", "B7", input.Value); break; case "Gouda_Taste": exls.SetCellValue("Sheet1", "B8", input.Value); break; default: break; } } //Get the Kpi value var kpiValue = exls.GetCellValue("Sheet1", "B17"); //Put it in the calc result outputs.Add(new Ecodistrict.Messaging.Output.Kpi(kpiValue, "Max Cheese taste Kpi", "Unit")); return(outputs); } catch (Exception ex) { throw new Exception(string.Format("Could not calculate the cheese taste Kpi!\n{0}", ex)); } }