void GetCurrentMeters(IList <int> Installations) { try { LogManager.WriteLog("GetCurrentMeters Started", LogManager.enumLogLevel.Info); IMeterLife meterLife = MeterLifeBusinessObject.CreateInstance(); meterLife.GetCurrentMeters(Installations, (i, j, k) => { this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate { lblStatus.SetValue(System.Windows.Controls.Label.ContentProperty, string.Format("Processing ... ({0:D} out of {1:D})", j, k)); pgBar.Value = j; }); }); this.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate { lblStatus.SetValue(System.Windows.Controls.Label.ContentProperty, "Retrieving data from database..."); }); Thread.Sleep(SleepTime); LogManager.WriteLog("GetCurrentMeters Ended", LogManager.enumLogLevel.Info); } catch (Exception ex) { ExceptionManager.Publish(ex); Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate { this.Close(); }); } finally { try { if (_afterAction != null) { _afterAction(); } } catch { } Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart) delegate { this.Close(); }); } }
private void FetchDataAndBindGrid() { try { IMeterLife meterLife = MeterLifeBusinessObject.CreateInstance(); LogManager.WriteLog("MeterLife: Get Current Meters for Installation No: " + InstallationNo.ToString() + "<START>", LogManager.enumLogLevel.Debug); meterLife.GetCurrentMeters(InstallationNo); LogManager.WriteLog("MeterLife: Database Fetching <START>", LogManager.enumLogLevel.Debug); DataSet dsMeterLife = meterLife.GetMeterLife(InstallationNo); LogManager.WriteLog("MeterLife: Database Fetching <END>", LogManager.enumLogLevel.Debug); if (_bindGrid != null) { this.Dispatcher.Invoke(_bindGrid, dsMeterLife); } else { LogManager.WriteLog("CMeterLife screen was disposed already. Skipped loading.", LogManager.enumLogLevel.Info); } } catch (Exception ex) { LogManager.WriteLog("Error Occured in MeterLife: Get Current Meters for Installation No " + InstallationNo.ToString() + " : " + ex.Message, LogManager.enumLogLevel.Error); ExceptionManager.Publish(ex); } finally { if (_enableControls != null) { this.Dispatcher.Invoke(_enableControls, null); } else { LogManager.WriteLog("CMeterLife screen was disposed already. Skipped loading.", LogManager.enumLogLevel.Info); } } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { try { string SiteCode = ""; string AssetNumber = ""; string PosNumber = ""; this.Cursor = Cursors.Wait; btnPrint.IsEnabled = false; LogManager.WriteLog("Inside btnPrint_Click", LogManager.enumLogLevel.Info); IMeterLife meterLife = MeterLifeBusinessObject.CreateInstance(); meterLife.GetAssetDetails(this.InstallationNo, ref SiteCode, ref AssetNumber, ref PosNumber); if (lstView != null) { if (lstView.Items.Count > 0) { DataTable meterData = new DataTable(); meterData.TableName = "MachineMeters"; meterData.Columns.Add("Meter"); meterData.Columns.Add("Start"); meterData.Columns.Add("Current"); meterData.Columns.Add("Difference"); meterData.Columns.Add("Value"); meterData.Columns.Add("SiteCode"); meterData.Columns.Add("PosNumber"); meterData.Columns.Add("AssetNumber"); LogManager.WriteLog("Filling the Meter Datatable for Print Report...", LogManager.enumLogLevel.Info); foreach (DataRowView dvItem in lstView.Items) { DataRow meterRow = meterData.NewRow(); meterRow["Meter"] = dvItem["Meter"].ToString(); meterRow["Start"] = dvItem["Start"].ToString(); meterRow["Current"] = dvItem["Current"].ToString(); meterRow["Difference"] = dvItem["Difference"].ToString(); meterRow["Value"] = dvItem["Value"].ToString() != string.Empty ? Convert.ToDecimal(dvItem["Value"]).GetUniversalCurrencyFormatWithSymbol() : "NA"; meterRow["SiteCode"] = SiteCode; meterRow["PosNumber"] = PosNumber; meterRow["AssetNumber"] = AssetNumber; meterData.Rows.Add(meterRow); } LogManager.WriteLog("Meter Datatable filled successfully with Print Report Data.", LogManager.enumLogLevel.Info); CReportViewer cReportViewer = new CReportViewer(); cReportViewer.PrintMeterLifeReport(meterData); cReportViewer = null; meterData = null; } else { MessageBox.ShowBox("MessageID47"); } } else { MessageBox.ShowBox("MessageID47"); } } catch (Exception ex) { ExceptionManager.Publish(ex); } finally { this.Cursor = Cursors.Arrow; btnPrint.IsEnabled = true; } }