public bool AddEventReport(ReportContents reportContents) { try { int reportId = -1; reportId = AddEventReportHeader(reportContents); if (reportId != -1) { foreach (var eventContentse in reportContents.EventList) { AddEvent(eventContentse, reportId); } return(true); } return(false); } catch (Exception e) { throw; } }
private int AddEventReportHeader(ReportContents reportContents) { int reportId = -1; string isoFormat = "yyyy-MM-dd hh:mm:ss"; string startTid = reportContents.StartDateTime.ToString(isoFormat); string endTid = reportContents.EndDateTime.ToString(isoFormat); string query = "Declare @ReportId int " + "Select @ReportId = 0 " + "Exec [dbo].[AddEventReport] " + $"@WorkstationName = '{reportContents.WorkStationName}', " + $"@Configuration = '{reportContents.Configuration}', " + $"@SamplesInPeriod = {reportContents.MeasureInPeriod}, " + $"@SamplesTotal = {reportContents.TotalMeasure}, " + $"@ChassisId = '{reportContents.ChassisId}', " + $"@SwVersion = '{reportContents.SoftWareVersion}', " + $"@StartDateTime = '{startTid}', " + $"@EndDateTime = '{endTid}', " + $"@CompanyId = {reportContents.CompanyId}, " + $"@CountryId = {reportContents.CountryId}, " + "@ReportId = @ReportId OUTPUT " + "SELECT @ReportId as N'ReportId' "; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(query, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { reportId = (int)reader["ReportId"]; } } catch (Exception e) { Console.WriteLine(e); throw; } finally { reader.Close(); } } return(reportId); }
public EventReportXmlHelper(string fileName) { eventReport = XDocument.Load(fileName); reportContents = new ReportContents(); }