public Type814ServiceMeterType ParseServiceMeterType(XElement element, IDictionary <string, XNamespace> namespaces) { XNamespace empty; if (!namespaces.TryGetValue(string.Empty, out empty)) { empty = XNamespace.None; } var model = new Type814ServiceMeterType { MeterMultiplier = element.GetChildText(empty + "MeterMultiplier"), MeterType = element.GetChildText(empty + "MeterType"), ProductType = element.GetChildText(empty + "ProductType"), TimeOfUse = element.GetChildText(empty + "TimeOfUse"), TimeOfUse2 = element.GetChildText(empty + "TimeOfUse2"), NumberOfDials = element.GetChildText(empty + "NumberOfDials"), UnmeteredNumberOfDevices = element.GetChildText(empty + "UnmeteredNumberOfDevices"), UnmeteredDescription = element.GetChildText(empty + "UnmeteredDescription"), StartMeterRead = element.GetChildText(empty + "StartMeterRead"), ChangeReason = element.GetChildText(empty + "ChangeReason"), }; return(model); }
public void ParseServiceMeterType(Prism814Context context, string[] marketFields) { var current = context.Current; if (current == null || current.ModelType != Type814Types.ServiceMeter) { throw new InvalidOperationException(); } var meter = current as Type814ServiceMeter; if (meter == null) { throw new InvalidOperationException(); } var model = new Type814ServiceMeterType { ProductType = context.ProductType, UnmeteredNumberOfDevices = context.UnmeterQuantity, UnmeteredDescription = context.UnmeterDescription, MeterMultiplier = marketFields.AtIndex(3), MeterType = marketFields.AtIndex(2), TimeOfUse = marketFields.AtIndex(5), TimeOfUse2 = marketFields.AtIndex(6), NumberOfDials = marketFields.AtIndex(4), StartMeterRead = marketFields.AtIndex(10), EndMeterRead = marketFields.AtIndex(11), }; meter.AddType(model); }
public void ParseServiceMeter(Prism814Context context, string[] marketFields) { var current = context.Current; if (current == null || current.ModelType != Type814Types.Service) { throw new InvalidOperationException(); } var service = current as Type814Service; if (service == null) { throw new InvalidOperationException(); } var model = new Type814ServiceMeter { EntityIdCode = marketFields.AtIndex(4), MeterNumber = marketFields.AtIndex(2), MeterType = marketFields.AtIndex(5), LoadProfile = marketFields.AtIndex(8), RateClass = marketFields.AtIndex(6), RateSubClass = marketFields.AtIndex(7), MeterCycle = marketFields.AtIndex(10), MeterCycleDayOfMonth = marketFields.AtIndex(36), SpecialNeedsIndicator = marketFields.AtIndex(21), OldMeterNumber = marketFields.AtIndex(3), MeterOwnerIndicator = marketFields.AtIndex(23), AmsIndicator = marketFields.AtIndex(51), SummaryInterval = marketFields.AtIndex(51), }; service.AddMeter(model); context.PushModel(model); marketFields.TryAtIndex(11, x => context.ProductType = x); marketFields.TryAtIndex(13, x => context.UnmeterQuantity = x); marketFields.TryAtIndex(14, x => context.UnmeterDescription = x); var hasIntervalType = false; var hasProductType = false; marketFields.TryAtIndex(5, x => hasIntervalType = true); marketFields.TryAtIndex(11, x => hasProductType = true); if (hasIntervalType || !hasProductType) { return; } var meterTypeModel = new Type814ServiceMeterType { ProductType = marketFields.AtIndex(11), UnmeteredNumberOfDevices = marketFields.AtIndex(13), UnmeteredDescription = marketFields.AtIndex(37), }; model.AddType(meterTypeModel); }
public Type814ServiceMeterType[] ListServiceMeterTypes(int meterKey) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("esp_814ServiceMeterTOUList")) { command.AddWithValue("@Meter_Key", meterKey); if (connection.State != ConnectionState.Open) { connection.Open(); } var collection = new List <Type814ServiceMeterType>(); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var item = new Type814ServiceMeterType { TypeKey = reader.GetInt32("Type_Key"), MeterKey = meterKey, }; reader.TryGetString("MeterMultiplier", x => item.MeterMultiplier = x); reader.TryGetString("MeterType", x => item.MeterType = x); reader.TryGetString("ProductType", x => item.ProductType = x); reader.TryGetString("TimeOfUse", x => item.TimeOfUse = x); reader.TryGetString("NumberOfDials", x => item.NumberOfDials = x); reader.TryGetString("UnmeteredNumberOfDevices", x => item.UnmeteredNumberOfDevices = x); reader.TryGetString("UnmeteredDescription", x => item.UnmeteredDescription = x); reader.TryGetString("StartMeterRead", x => item.StartMeterRead = x); reader.TryGetString("EndMeterRead", x => item.EndMeterRead = x); reader.TryGetString("ChangeReason", x => item.ChangeReason = x); reader.TryGetString("TimeOfUse2", x => item.TimeOfUse2 = x); collection.Add(item); } return(collection.ToArray()); } } }
public void When_Saving_Header_With_Any_Service_Meter_Types_Then_Insert_Service_Meter_Type_Is_Called() { // arrange const int serviceMeterKey = 2; var type = new Type814ServiceMeterType { ChangeReason = "mock" }; var meter = new Type814ServiceMeter(); meter.AddType(type); var service = new Type814Service(); service.AddMeter(meter); var header = new Type814Header(); header.AddService(service); dataAccess.Stub(x => x.InsertHeader(Arg.Is(header))) .Return(1); dataAccess.Stub(x => x.InsertService(Arg.Is(service))) .Return(1); dataAccess.Stub(x => x.InsertServiceMeter(Arg.Is(meter))) .Return(serviceMeterKey); dataAccess.Expect(x => x.InsertServiceMeterType(Arg.Is(type))) .Return(1); // act concern.SaveHeader(header); // assert Assert.AreEqual(serviceMeterKey, type.MeterKey); dataAccess.VerifyAllExpectations(); }
public int InsertServiceMeterType(Type814ServiceMeterType model) { using (var connection = new SqlConnection(connectionString)) using (var command = connection.CreateCommand("csp814ServiceMeterTypeInsert")) { SqlParameter keyParameter; command.AddWithValue("@Meter_Key", model.MeterKey) .AddWithValue("@MeterMultiplier", model.MeterMultiplier) .AddWithValue("@MeterType", model.MeterType) .AddWithValue("@ProductType", model.ProductType) .AddWithValue("@TimeOfUse", model.TimeOfUse) .AddWithValue("@TimeOfUse2", model.TimeOfUse2) .AddWithValue("@NumberOfDials", model.NumberOfDials) .AddWithValue("@UnmeteredNumberOfDevices", model.UnmeteredNumberOfDevices) .AddWithValue("@UnmeteredDescription", model.UnmeteredDescription) .AddWithValue("@StartMeterRead", model.StartMeterRead) .AddWithValue("@EndMeterRead", model.EndMeterRead) .AddWithValue("@ChangeReason", model.ChangeReason) .AddOutParameter("@Type_Key", SqlDbType.Int, out keyParameter); if (connection.State != ConnectionState.Open) { connection.Open(); } command.ExecuteNonQuery(); if (keyParameter.Value == null) { throw new Exception(); } var typeKey = (int)keyParameter.Value; model.TypeKey = typeKey; return(typeKey); } }