/// <summary> /// Добавить или править /// </summary> /// <param name="mtlist"></param> /// <returns></returns> public int SaveMTList(MTList mtlist) { MTList dbEntry; if (mtlist.IDMTList == 0) { dbEntry = new MTList() { IDMTList = mtlist.IDMTList, IDMTSostav = mtlist.IDMTSostav, Position = mtlist.Position, CarriageNumber = mtlist.CarriageNumber, CountryCode = mtlist.CountryCode, Weight = mtlist.Weight, IDCargo = mtlist.IDCargo, Cargo = mtlist.Cargo, IDStation = mtlist.IDStation, Station = mtlist.Station, Consignee = mtlist.Consignee, Operation = mtlist.Operation, CompositionIndex = mtlist.CompositionIndex, DateOperation = mtlist.DateOperation, TrainNumber = mtlist.TrainNumber, NaturList = mtlist.NaturList }; context_edit.MTList.Add(dbEntry); } else { dbEntry = context_edit.MTList.Find(mtlist.IDMTList); if (dbEntry != null) { dbEntry.IDMTList = mtlist.IDMTList; dbEntry.IDMTSostav = mtlist.IDMTSostav; dbEntry.Position = mtlist.Position; dbEntry.CarriageNumber = mtlist.CarriageNumber; dbEntry.CountryCode = mtlist.CountryCode; dbEntry.Weight = mtlist.Weight; dbEntry.IDCargo = mtlist.IDCargo; dbEntry.Cargo = mtlist.Cargo; dbEntry.IDStation = mtlist.IDStation; dbEntry.Station = mtlist.Station; dbEntry.Consignee = mtlist.Consignee; dbEntry.Operation = mtlist.Operation; dbEntry.CompositionIndex = mtlist.CompositionIndex; dbEntry.DateOperation = mtlist.DateOperation; dbEntry.TrainNumber = mtlist.TrainNumber; dbEntry.NaturList = mtlist.NaturList; } } try { context_edit.SaveChanges(); } catch (Exception e) { return(-1); } return(dbEntry.IDMTList); }
public void Test_MTContent_GetListToNatur() { MTContent mt = new MTContent(); MTList lst = mt.GetListToNatur(4839, 67923441, DateTime.Parse("2016-01-06 13:55:00"), 15); //string sw = "60662830;65383853;67660423;74021965;65046567;56560055;24534372;50546159;57517948;55977870;55763296;55320519;63627558;65206062;67751354;67794347;64083868;66522079;65009771;66495458;67288738;65125502;65710154;66399379;65469769;62823661;65438236;55063119;53777959;60832383;56765530;56138001;53436556;52749769;56936644;56969702;52876307;53551669;60091303;55119531;55118251;61246328;59717553;57411928;60267812;52965274;55139851;52733540;53569752;66680547;65483307;60261211;56982416;54122338;61243358;60806072;62034137;59785881;"; //Console.WriteLine("id sostav = {0}", mt.GetIDSostavToWagons(sw)); }
/// <summary> /// Вернуть номер поезда состава /// </summary> /// <param name="id_mtsostav"></param> /// <returns></returns> public int?GetTrainNumberToSostav(int id_mtsostav) { MTList mtlist = Get_MTListToSostav(id_mtsostav).FirstOrDefault(); if (mtlist != null) { return(mtlist.TrainNumber); } return(null); }
/// <summary> /// Проверка у состава есть вагоны /// </summary> /// <param name="id_mtsostav"></param> /// <returns></returns> public bool IsMTListToMTSostsv(int id_mtsostav) { MTList mtlist = Get_MTListToSostav(id_mtsostav).FirstOrDefault(); if (mtlist != null) { return(true); } return(false); }
/// <summary> /// Удалить /// </summary> /// <param name="IDMTList"></param> /// <returns></returns> public MTList DeleteMTList(int IDMTList) { MTList dbEntry = context_edit.MTList.Find(IDMTList); if (dbEntry != null) { context_edit.MTList.Remove(dbEntry); context_edit.SaveChanges(); } return(dbEntry); }
/// <summary> /// Переносим вагоны состава /// </summary> /// <param name="file"></param> /// <param name="id_sostav"></param> /// <returns></returns> protected int TransferXMLToMTlist(string file, int id_sostav) { int count = 0; int error = 0; int trans = 0; string trans_id = ""; try { XDocument doc = XDocument.Load(file); foreach (XElement element in doc.Element("NewDataSet").Elements("Table")) { MTList mtl = new MTList() { IDMTList = 0, IDMTSostav = id_sostav, Position = !String.IsNullOrWhiteSpace((string)element.Element("Position")) ? (int)element.Element("Position") : -1, CarriageNumber = !String.IsNullOrWhiteSpace((string)element.Element("CarriageNumber")) ? (int)element.Element("CarriageNumber") : -1, CountryCode = !String.IsNullOrWhiteSpace((string)element.Element("CountryCode")) ? (int)element.Element("CountryCode") : -1, Weight = !String.IsNullOrWhiteSpace((string)element.Element("Weight")) ? (int)element.Element("Weight") : -1, IDCargo = !String.IsNullOrWhiteSpace((string)element.Element("IDCargo")) ? (int)element.Element("IDCargo") : -1, Cargo = !String.IsNullOrWhiteSpace((string)element.Element("Cargo")) ? (string)element.Element("Cargo") : "?", IDStation = !String.IsNullOrWhiteSpace((string)element.Element("IDStation")) ? (int)element.Element("IDStation") : -1, Station = !String.IsNullOrWhiteSpace((string)element.Element("Station")) ? (string)element.Element("Station") : "?", Consignee = !String.IsNullOrWhiteSpace((string)element.Element("Consignee")) ? (int)element.Element("Consignee") : -1, Operation = !String.IsNullOrWhiteSpace((string)element.Element("Operation")) ? (string)element.Element("Operation") : "?", CompositionIndex = !String.IsNullOrWhiteSpace((string)element.Element("CompositionIndex")) ? (string)element.Element("CompositionIndex") : "?", DateOperation = !String.IsNullOrWhiteSpace((string)element.Element("DateOperation")) ? DateTime.Parse((string)element.Element("DateOperation"), CultureInfo.CreateSpecificCulture("ru-RU")) : DateTime.Now, TrainNumber = !String.IsNullOrWhiteSpace((string)element.Element("TrainNumber")) ? (int)element.Element("TrainNumber") : -1, }; // Переносим вагон int keylist = mtc.SaveMTList(mtl); if (keylist > 0) { trans++; } if (keylist < 1) { error++; } trans_id = trans_id + keylist.ToString() + "; "; count++; } LogRW.LogInformation(String.Format("В файле {0} определенно: {1} вагонов, перенесено в БД RailWay : {2}, ошибок переноса : {3}, код возврата :{4}", file, count, trans, error, trans_id), this.eventID); } catch (Exception e) { LogRW.LogError(String.Format("[MT.TransferXMLToMTlist] :Ошибка переноса вагонов, файл:{0}. Подробно: (Источник:{1}, Код:{2}, Описание:{3})", file, e.Source, e.HResult, e.Message), this.eventID); return(-1); } return(count); }
public void Read_List() { // Arrange - create the mock repository mock_mt.Setup(m => m.MTList).Returns(new MTList[] { new MTList() { IDMTList = 1, IDMTSostav = 1, Position = 1, CarriageNumber = 60490943, CountryCode = 221, Weight = 57, IDCargo = 17101, Cargo = "sss", IDStation = 46600, Station = "НИКОПОЛЬ", Consignee = 3925, Operation = "ТСП", CompositionIndex = "3540-097-4670", DateOperation = DateTime.Parse("2016-08-22 11:40:00.000"), TrainNumber = 1402, NaturList = null }, new MTList() { IDMTList = 2, IDMTSostav = 1, Position = 2, CarriageNumber = 60490944, CountryCode = 221, Weight = 50, IDCargo = 17101, Cargo = "sss", IDStation = 46600, Station = "НИКОПОЛЬ", Consignee = 3925, Operation = "ТСП", CompositionIndex = "3540-097-4670", DateOperation = DateTime.Parse("2016-08-22 11:40:00.000"), TrainNumber = 1402, NaturList = null }, new MTList() { IDMTList = 3, IDMTSostav = 2, Position = 1, CarriageNumber = 33490944, CountryCode = 222, Weight = 60, IDCargo = 17100, Cargo = "sss", IDStation = 46600, Station = "Кривой Рог", Consignee = 3925, Operation = "ПРИБ", CompositionIndex = "3540-055-4670", DateOperation = DateTime.Parse("2016-08-22 11:40:00.000"), TrainNumber = 1402, NaturList = null }, }.AsQueryable()); // Arrange - create the controller MTContent target = new MTContent(mock_mt.Object); // Act // Проверка MTList mtl = target.Get_MTList(1); MTList mtl_null = target.Get_MTList(0); List <MTList> list_ws = target.Get_MTListToSostav(1).ToList(); List <MTList> list_all = target.Get_MTList().ToList(); int? tn = target.GetTrainNumberToSostav(1); int? tn_null = target.GetTrainNumberToSostav(0); bool exlist = target.IsMTListToMTSostsv(1); bool exlist_null = target.IsMTListToMTSostsv(0); //bool sostav_exist = target.IsExistSostav("regl_8701-058-4670_2016082212353.xml"); //bool sostav_not_exist = target.IsExistSostav("1regl_8701-058-4670_2016082212353.xml"); //MTSostav mts_notClose = target.Get_NoCloseMTSostav("8701-058-4670", DateTime.Parse("2016-08-23 12:35:00.000")); //MTSostav mts_notClose_null = target.Get_NoCloseMTSostav("8701-058-4670", DateTime.Parse("2016-08-21 12:35:00.000")); // Assert // Assert.AreEqual(null, mtl_null); Assert.AreEqual(60490943, mtl.CarriageNumber); Assert.AreEqual(DateTime.Parse("2016-08-22 11:40:00.000"), mtl.DateOperation); Assert.AreEqual(1, mtl.Position); Assert.AreEqual(2, list_ws.Count()); Assert.AreEqual(1, list_ws[0].IDMTList); Assert.AreEqual(2, list_ws[1].IDMTList); Assert.AreEqual(3, list_all.Count()); Assert.AreEqual(1402, tn); Assert.AreEqual(null, tn_null); Assert.AreEqual(true, exlist); Assert.AreEqual(false, exlist_null); //Assert.AreEqual(true, sostav_exist); //Assert.AreEqual(false, sostav_not_exist); //Assert.AreEqual(2, mts_notClose.IDMTSostav); //Assert.AreEqual(null, mts_notClose_null); }
/// <summary> /// Добавить или править /// </summary> /// <param name="mtlist"></param> /// <returns></returns> public int SaveMTList(MTList mtlist) { return(rep_MT.SaveMTList(mtlist)); }