public Type867IntervalSummaryAcrossMeters ParseIntervalSummaryAcrossMeters(XElement element, IDictionary <string, XNamespace> namespaces) { XNamespace empty; if (!namespaces.TryGetValue(string.Empty, out empty)) { empty = XNamespace.None; } var model = new Type867IntervalSummaryAcrossMeters { TypeCode = element.GetChildText(empty + "TypeCode"), ServicePeriodStart = element.GetChildText(empty + "ServicePeriodStart"), ServicePeriodStartTime = element.GetChildText(empty + "ServicePeriodStartTime"), ServicePeriodEnd = element.GetChildText(empty + "ServicePeriodEnd"), ServicePeriodEndTime = element.GetChildText(empty + "ServicePeriodEndTime"), MeterRole = element.GetChildText(empty + "MeterRole"), MeterUOM = element.GetChildText(empty + "MeterUOM"), MeterInterval = element.GetChildText(empty + "MeterInterval") }; var quantitiesLoopElement = element.Element(empty + "IntervalSummaryAcrossMetersQtyLoop"); if (quantitiesLoopElement != null) { var quantityElements = quantitiesLoopElement.Elements(empty + "IntervalSummaryAcrossMetersQty"); foreach (var quantityElement in quantityElements) { var quantityModel = ParseIntervalSummaryAcrossMetersQty(quantityElement, namespaces); model.AddQuantity(quantityModel); } } return(model); }
public int InsertIntervalSummaryAcrossMeters(Type867IntervalSummaryAcrossMeters model) { using (var connection = new SqlConnection(_connectionString)) using (var command = connection.CreateCommand("csp867IntervalSummaryAcrossMetersInsert")) { SqlParameter keyParameter; command.AddWithValue("@867_Key", model.HeaderKey) .AddIfNotEmptyOrDbNull("@TypeCode", model.TypeCode) .AddIfNotEmptyOrDbNull("@ServicePeriodStart", model.ServicePeriodStart) .AddIfNotEmptyOrDbNull("@ServicePeriodStartTime", model.ServicePeriodStartTime) .AddIfNotEmptyOrDbNull("@ServicePeriodEnd", model.ServicePeriodEnd) .AddIfNotEmptyOrDbNull("@ServicePeriodEndTime", model.ServicePeriodEndTime) .AddIfNotEmptyOrDbNull("@MeterRole", model.MeterRole) .AddIfNotEmptyOrDbNull("@MeterUOM", model.MeterUOM) .AddIfNotEmptyOrDbNull("@MeterInterval", model.MeterInterval) .AddOutParameter("@IntervalSummaryAcrossMeters_Key", SqlDbType.Int, out keyParameter); if (connection.State != ConnectionState.Open) { connection.Open(); } command.ExecuteNonQuery(); if (keyParameter.Value == null) { throw new Exception(); } var key = (int)keyParameter.Value; model.IntervalSummaryAcrossMetersKey = key; return(key); } }
private void ParseIntervalSummaryAcrossMeters(Prism867Context context, string[] marketFields) { context.RecordType = GetRecordType(context, marketFields, 0); switch (context.RecordType) { case "PP": break; default: logger.DebugFormat("Record Usage Type not found: {0}. Transaction Number \"{1}\".", context.RecordType, context.TransactionNumber); return; } var current = context.Current; if (current == null || current.ModelType != Type867Types.Header) { throw new InvalidOperationException(); } var header = current as Type867Header; if (header == null) { throw new InvalidOperationException(); } var model = new Type867IntervalSummaryAcrossMeters { TypeCode = context.RecordType, MeterRole = marketFields.AtIndex(6), MeterUOM = string.Empty, MeterInterval = string.Empty, }; var servicePeriodStart = marketFields.AtIndex(2); if (servicePeriodStart.Length < 9) { model.ServicePeriodStart = servicePeriodStart; } else { model.ServicePeriodStart = servicePeriodStart.Substring(0, 8); model.ServicePeriodStartTime = servicePeriodStart.Substring(8); } var servicePeriodEnd = marketFields.AtIndex(3); if (servicePeriodEnd.Length < 9) { model.ServicePeriodEnd = servicePeriodEnd; } else { model.ServicePeriodEnd = servicePeriodEnd.Substring(0, 8); model.ServicePeriodEndTime = servicePeriodEnd.Substring(8); } var meterType = marketFields.AtIndex(4) + marketFields.AtIndex(5); if (meterType.Length > 1) { model.MeterUOM = meterType.Substring(0, 2); } if (meterType.Length > 2) { model.MeterInterval = meterType.Substring(2, 3); } context.PushModel(model); header.AddIntervalSummaryAcrossMeters(model); }