private void ShearsimpleButton_Click(object sender, EventArgs e) { XtraReportSetting = InitialMethod.InitialXtraReportLoad(); ReportTitleSetting reportTitle = InitialMethod.InitialReportTitleSetting(); if (StartdateEdit.Text != "") { string ttime = string.Empty; if (XtraReportSetting.Day.ToString().Length == 2) { ttime = Convert.ToDateTime(StartdateEdit.EditValue).ToString("yyyy/MM/") + $"{XtraReportSetting.Day} 00:00:00"; } else { ttime = Convert.ToDateTime(StartdateEdit.EditValue).ToString("yyyy/MM/") + $"0{XtraReportSetting.Day} 00:00:00"; } XtraReport xtraReport = new XtraReport(); AnalysisXtraReport analysisXtraReport = new AnalysisXtraReport(); analysisXtraReport.create_XtraReport(MysqlMethod, ttime, reportTitle); analysisXtraReport.CreateDocument(); xtraReport.Pages.AddRange(analysisXtraReport.Pages); documentViewer1.DocumentSource = xtraReport; } else { FlyoutAction action = new FlyoutAction(); action.Caption = "電表資訊-查詢報表錯誤"; action.Description = "請選擇條件再進行瀏覽"; action.Commands.Add(FlyoutCommand.OK); FlyoutDialog.Show(FindForm(), action); } }
public SettingUserControl(MysqlMethod mysql, Form1 form1) { InitializeComponent(); XtraReportSetting = InitialMethod.InitialXtraReportLoad(); Form1 = form1; MysqlMethod = mysql; GatewayConfigs = MysqlMethod.Search_GatewayConfig(); foreach (var Gatewayitem in GatewayConfigs) { var configs = MysqlMethod.Search_ElectricConfig(Gatewayitem.GatewayIndex); foreach (var Configitem in configs) { ElectricConfigs.Add(Configitem); } } ReportConfigs = MysqlMethod.Search_ReportConfig(); ReportTitleSetting reportTitle = InitialMethod.InitialReportTitleSetting(); ContractNoTextEdit.Text = reportTitle.ContractNo; ElectNoTextEdit.Text = reportTitle.ElectNo; FileFormatSetting fileFormat = InitialMethod.InitialFileFormatSetting(); OutputFormatComboBoxEdit.SelectedIndex = fileFormat.FileFormat; AutotoggleSwitch.IsOn = XtraReportSetting.AutoExport; //自動匯出開關 PathtextEdit.Text = XtraReportSetting.Path; //儲存路徑 DaycomboBoxEdit.Text = XtraReportSetting.Day.ToString(); //匯出時間 int Index = 0; foreach (var ReportConfigitem in ReportConfigs) { var electricconfig = ElectricConfigs.Where(g => g.GatewayIndex == ReportConfigitem.GatewayIndex & g.DeviceIndex == ReportConfigitem.DeviceIndex).ToList()[0]; ExportElectricSettingUserControl control = new ExportElectricSettingUserControl(ReportConfigitem, electricconfig, MysqlMethod) { Location = new Point(5 + 420 * Index, 5) }; ReportviewpanelControl.Controls.Add(control); exportElectricSettingUserControls.Add(control); Index++; } }
/// <summary> /// 自動發送功能 /// </summary> public override void TextChange() { XtraReportSetting = InitialMethod.InitialXtraReportLoad(); ReportTitleSetting reportTitle = InitialMethod.InitialReportTitleSetting(); FileFormatSetting fileFormat = InitialMethod.InitialFileFormatSetting(); if (XtraReportSetting.AutoExport && DateTime.Now.Day == XtraReportSetting.Day) { if (!ExportFlag) { string ttime = string.Empty; if (XtraReportSetting.Day.ToString().Length == 2) { ttime = DateTime.Now.ToString("yyyy/MM/") + $"{XtraReportSetting.Day} 00:00:00"; } else { ttime = DateTime.Now.ToString("yyyy/MM/") + $"0{XtraReportSetting.Day} 00:00:00"; } AnalysisXtraReport analysisXtraReport = new AnalysisXtraReport(); analysisXtraReport.create_XtraReport(MysqlMethod, ttime, reportTitle); analysisXtraReport.CreateDocument(); if (Directory.Exists($"{XtraReportSetting.Path}")) { FileFormatTypeEnum fileFormatType = (FileFormatTypeEnum)fileFormat.FileFormat; switch (fileFormatType) { case FileFormatTypeEnum.PDF: { string path = XtraReportSetting.Path + $"\\Production Report(F1&F2)_{DateTime.Now.ToString("yyyyMMdd")}.pdf"; analysisXtraReport.ExportToPdf(path); break; } case FileFormatTypeEnum.DOCX: { string path = XtraReportSetting.Path + $"\\Production Report(F1&F2)_{DateTime.Now.ToString("yyyyMMdd")}.docx"; DocxExportOptions options = new DocxExportOptions() { TableLayout = true }; analysisXtraReport.ExportToDocx(path, options); break; } case FileFormatTypeEnum.XLSX: { string path = XtraReportSetting.Path + $"\\Production Report(F1&F2)_{DateTime.Now.ToString("yyyyMMdd")}.xlsx"; analysisXtraReport.ExportToXlsx(path); break; } } } ExportFlag = true; } } else { ExportFlag = false; } }
public void create_XtraReport(MysqlMethod mysql, string TTime, ReportTitleSetting reportTitle) { MysqlMethod = mysql; ContractNoLabel.Text = reportTitle.ContractNo; //契約編號 ElectNoLabel.Text = reportTitle.ElectNo; //電號 var TaiwanDate = new System.Globalization.TaiwanCalendar(); //民國轉換 XtraReportSetting = InitialMethod.InitialXtraReportLoad(); DateTime dateTime = Convert.ToDateTime(TTime); DateTime nowtime = DateTime.Now; ReportConfigs = MysqlMethod.Search_ReportConfig();//報表資訊 GatewayConfigs = MysqlMethod.Search_GatewayConfig(); foreach (var item in GatewayConfigs) { var configs = MysqlMethod.Search_ElectricConfig(item.GatewayIndex); ElectricConfigs.AddRange(configs); } string startime = startime = dateTime.AddMonths(-1).ToString("yyyyMMdd"); string endtime = dateTime.AddDays(-1).ToString("yyyyMMdd"); foreach (var item in ElectricConfigs) { var data = MysqlMethod.Search_ElectricSumTotal(startime, endtime, item.GatewayIndex, item.DeviceIndex); TotalkWh.Add(data); } var SumTotalkWh = TotalkWh[0] + TotalkWh[1]; StartDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddMonths(-1))}"; StartDatexrLabel2.Text = $"{dateTime.AddMonths(-1).ToString("MM")}"; if (XtraReportSetting.Day.ToString().Length == 2) { StartDatexrLabel3.Text = $"{XtraReportSetting.Day}"; //StartDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddMonths(-1))}年{dateTime.AddMonths(-1).ToString("MM")}月{ XtraReportSetting.Day}日"; } else { StartDatexrLabel3.Text = $"0{XtraReportSetting.Day}"; //StartDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddMonths(-1))}年{dateTime.AddMonths(-1).ToString("MM")}月0{ XtraReportSetting.Day}日"; } EndDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddDays(-1))}"; EndDatexrLabel2.Text = $"{dateTime.AddDays(-1).ToString("MM")}"; EndDatexrLabel3.Text = $"{dateTime.AddDays(-1).ToString("dd")}"; //EndDatexrLabel1.Text = $"{TaiwanDate.GetYear(dateTime.AddDays(-1))}年{dateTime.AddDays(-1).ToString("MM月dd日")}"; CurrentMeterReadingDayxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}"; CurrentMeterReadingDayxrLabel2.Text = $"{nowtime.ToString("MM")}"; CurrentMeterReadingDayxrLabel3.Text = $"{nowtime.ToString("dd")}"; //CurrentMeterReadingDayxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}年{nowtime.ToString("MM")}月{nowtime.ToString("dd")}日";//本期抄表日 DateOfReportingxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}"; DateOfReportingxrLabel2.Text = $"{nowtime.ToString("MM")}"; DateOfReportingxrLabel3.Text = $"{nowtime.ToString("dd")}"; //DateOfReportingxrLabel1.Text = $"{TaiwanDate.GetYear(nowtime)}年{nowtime.ToString("MM")}月{nowtime.ToString("dd")}日";//填報日期 if (ReportConfigs.Count > 0) { #region 第一顆電表 xrTableCell7.Text = ReportConfigs[0].ElectricNo; xrTableCell12.Text = ReportConfigs[0].ElectricitySalePeriod.ToString(); //售電期限 xrTableCell17.Text = $"{TaiwanDate.GetYear(ReportConfigs[0].StartingDate)}.{ReportConfigs[0].StartingDate.Month}.{ReportConfigs[0].StartingDate.Day}"; //計價起始日 xrTableCell22.Text = $"{TaiwanDate.GetYear(ReportConfigs[0].OfficialPricingStartDate)}.{ReportConfigs[0].OfficialPricingStartDate.Month}.{ReportConfigs[0].OfficialPricingStartDate.Day}"; //正是購售電能日 xrTableCell52.Text = $"{TaiwanDate.GetYear(ReportConfigs[0].PricStartTime)}.{ReportConfigs[0].PricStartTime.Month}.{ReportConfigs[0].PricStartTime.Day}-{TaiwanDate.GetYear(ReportConfigs[0].PricEndTime)}.{ReportConfigs[0].PricEndTime.Month}.{ReportConfigs[0].PricEndTime.Day}"; //計價起迄期間 xrTableCell27.Text = ReportConfigs[0].ElectricityPurchaseRate.ToString("0.####"); //購電費率 xrTableCell32.Text = ReportConfigs[0].DeviceCapacity.ToString("0.###"); //裝置容量 xrTableCell37.Text = ReportConfigs[0].PurchaseAndSaleCapacity.ToString("0.###"); //購售電容量 xrTableCell42.Text = TotalkWh[0].ToString("0.##"); //生產電度量 if (TotalkWh[0] != 0) { xrTableCell47.Text = $"{Convert.ToInt32((TotalkWh[0] / SumTotalkWh) * 100)}%"; } #endregion #region 第二顆電表 xrTableCell8.Text = ReportConfigs[1].ElectricNo; xrTableCell13.Text = ReportConfigs[1].ElectricitySalePeriod.ToString(); //售電期限 xrTableCell18.Text = $"{TaiwanDate.GetYear(ReportConfigs[1].StartingDate)}.{ReportConfigs[1].StartingDate.Month}.{ReportConfigs[1].StartingDate.Day}"; //計價起始日 xrTableCell23.Text = $"{TaiwanDate.GetYear(ReportConfigs[1].OfficialPricingStartDate)}.{ReportConfigs[1].OfficialPricingStartDate.Month}.{ReportConfigs[1].OfficialPricingStartDate.Day}"; //正是購售電能日 xrTableCell53.Text = $"{TaiwanDate.GetYear(ReportConfigs[1].PricStartTime)}.{ReportConfigs[1].PricStartTime.Month}.{ReportConfigs[1].PricStartTime.Day}-{TaiwanDate.GetYear(ReportConfigs[1].PricEndTime)}.{ReportConfigs[1].PricEndTime.Month}.{ReportConfigs[1].PricEndTime.Day}"; //計價起迄期間 xrTableCell28.Text = ReportConfigs[1].ElectricityPurchaseRate.ToString("#.####"); //購電費率 xrTableCell33.Text = ReportConfigs[1].DeviceCapacity.ToString("#.###"); //裝置容量 xrTableCell38.Text = ReportConfigs[1].PurchaseAndSaleCapacity.ToString("#.###"); //購售電容量 xrTableCell43.Text = TotalkWh[1].ToString("#.##"); //生產電度量 if (TotalkWh[1] != 0) { xrTableCell48.Text = $"{Convert.ToInt32((TotalkWh[1] / SumTotalkWh) * 100)}%"; } #endregion #region 合計 xrTableCell35.Text = $"{(ReportConfigs[0].DeviceCapacity + ReportConfigs[1].DeviceCapacity).ToString("#.###")}"; //裝置容量 xrTableCell40.Text = $"{ (ReportConfigs[0].PurchaseAndSaleCapacity + ReportConfigs[1].PurchaseAndSaleCapacity).ToString("#.###")}"; //購售電容量 xrTableCell45.Text = $"{SumTotalkWh.ToString("#.##")}"; #endregion } }
public Form1() { #region Serilog initial Log.Logger = new LoggerConfiguration() .WriteTo.Console() .WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\log\\log-.txt", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}") .CreateLogger(); //宣告Serilog初始化 #endregion #region Loading initial FluentSplashScreenOptions op = new FluentSplashScreenOptions(); op.Title = "太陽能資料蒐集系統";//太陽能資料蒐集系統 帆宣自動化抄表系統 op.Subtitle = "Automatic Meter Reading System"; op.LeftFooter = "Copyright © 2021 SIN MAO Energy CO., LTD." + Environment.NewLine + "All Rights reserved."; op.LoadingIndicatorType = FluentLoadingIndicatorType.Dots; op.OpacityColor = Color.FromArgb(62, 91, 135); op.Opacity = 130; SplashScreenManager.ShowFluentSplashScreen( op, parentForm: this, useFadeIn: true, useFadeOut: true ); #endregion #region 入資料庫JSON op.RightFooter = $"載入資料庫資訊"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); SystemSetting = InitialMethod.SystemLoad(); Thread.Sleep(1000); #endregion #region 入按鈕JSON op.RightFooter = $"載入按鈕資訊"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); ButtonSetting = InitialMethod.InitialButtonLoad(); Thread.Sleep(1000); #endregion #region 入匯出報表JSON op.RightFooter = $"載入匯出報表資訊"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); XtraReportSetting = InitialMethod.InitialXtraReportLoad(); Thread.Sleep(1000); #endregion #region JSON錯誤資訊檢查 if (SystemSetting == null && ButtonSetting == null && XtraReportSetting == null) { ErrorStr = "資料庫與按鈕Json錯誤"; } else if (SystemSetting != null && ButtonSetting == null && XtraReportSetting != null) { ErrorStr = "按鈕Json錯誤"; } else if (SystemSetting == null && ButtonSetting != null && XtraReportSetting != null) { ErrorStr = "資料庫Json錯誤"; } else if (SystemSetting != null && ButtonSetting != null && XtraReportSetting == null) { ErrorStr = "匯出報表Json錯誤"; } if (ErrorStr == "") { op.RightFooter = $"載入完成"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); Thread.Sleep(1000); SplashScreenManager.CloseForm(); } else { op.RightFooter = $"{ErrorStr}"; SplashScreenManager.Default.SendCommand(FluentSplashScreenCommand.UpdateOptions, op); Thread.Sleep(5000); SplashScreenManager.CloseForm(); } #endregion InitializeComponent(); if (ErrorStr == "") { Change_Logo(); //載入Logo SettingbarButtonItem.ImageOptions.Image = imageCollection1.Images["technology"]; //設定按鈕圖 #region 建立資料庫物件 MysqlMethod = new MysqlMethod(SystemSetting); if (SystemSetting != null) { GatewayConfigs = MysqlMethod.Search_GatewayConfig(); } #endregion #region 建立通訊 if (GatewayConfigs != null) { foreach (var item in GatewayConfigs) { GatewayTypeEnum gatewayType = (GatewayTypeEnum)item.GatewayTypeEnum; switch (gatewayType) { case GatewayTypeEnum.ModbusRTU: { SerialportMasterComponent serialport = new SerialportMasterComponent(item, MysqlMethod) { MysqlMethod = MysqlMethod }; serialport.MyWorkState = true; Field4Components.Add(serialport); } break; case GatewayTypeEnum.ModbusTCP: { TCPMasterComponent TCP = new TCPMasterComponent(item, MysqlMethod) { MysqlMethod = MysqlMethod }; TCP.MyWorkState = true; Field4Components.Add(TCP); } break; } } } #endregion #region 建立按鈕物件 NavigationFrame = new NavigationFrame() { Dock = DockStyle.Fill }; NavigationFrame.Parent = ViewpanelControl; ButtonMethod = new ButtonMethod() { Form1 = this, navigationFrame = NavigationFrame }; ButtonMethod.AccordionLoad(accordionControl1, ButtonSetting); #endregion #region 建立畫面 foreach (var Componentitem in Field4Components) { foreach (var Absprotocolitem in Componentitem.ElectricAbsProtocols) { ElectricAbsProtocols.Add(Absprotocolitem); } } #region 主畫面 MainUserControl main = new MainUserControl(MysqlMethod, ElectricAbsProtocols) { Dock = DockStyle.Fill }; NavigationFrame.AddPage(main); Field4UserControls.Add(main); #endregion #region 報表畫面 ChartUserControl chart = new ChartUserControl(MysqlMethod) { Dock = DockStyle.Fill }; NavigationFrame.AddPage(chart); Field4UserControls.Add(chart); #endregion #region 月報表畫面 xtraReportUserControl = new XtraReportUserControl(MysqlMethod) { Dock = DockStyle.Fill }; NavigationFrame.AddPage(xtraReportUserControl); #endregion #endregion } timer1.Interval = 1000; timer1.Enabled = true; }