public void Test_SUD_RC_Vagons() { RC_Vagons vag = new RC_Vagons(); VAGONS w1 = new VAGONS() { id_vag = 0, num = 0, date_ar = DateTime.Now }; int id_new = vag.SaveVAGONS(w1); Test_RC_Vagons(0); VAGONS w2 = new VAGONS() { id_vag = id_new, num = 1, date_ar = DateTime.Now }; int id_ch = vag.SaveVAGONS(w2); Test_RC_Vagons(1); VAGONS del = vag.DeleteVAGONS(id_ch); WL(del); }
/// <summary> /// Получить ID вагона системы Railcars (если id нет создать из данных КИС или создать временную строку) /// </summary> /// <param name="num_vag"></param> /// <param name="dt"></param> /// <param name="train_number"></param> /// <param name="id_sostav"></param> /// <param name="natur"></param> /// <param name="transit"></param> /// <returns></returns> public int DefinitionSetIDVagon(int num_vag, DateTime dt, int train_number, int?id_sostav, int?natur, bool transit) { int?id_vagons = rs_vag.GetIDVagons(num_vag, dt); if (id_vagons == null) { id_vagons = rs_vag.GetIDNewVagons(num_vag, dt); if (id_vagons == null) { KometaVagonSob kvs = kc.GetVagonsSob(num_vag, dt); VAGONS wag; if (kvs != null) { int?owner = DefinitionIDOwner(kvs.SOB, null); // Определим id владельца (системы railCars) wag = new VAGONS() { id_vag = 0, num = num_vag, id_ora = null, id_owner = owner, id_stat = null, is_locom = train_number, locom_seria = null, rod = kvs.ROD, st_otpr = "-", date_ar = kvs.DATE_AR, date_end = kvs.DATE_END, date_in = dt, IDSostav = id_sostav, Natur = natur, Transit = transit }; } else { wag = new VAGONS() { id_vag = 0, num = num_vag, id_ora = null, id_owner = null, id_stat = null, is_locom = train_number, locom_seria = null, rod = null, st_otpr = "-", date_ar = null, date_end = null, date_in = dt, IDSostav = id_sostav, Natur = natur, Transit = transit }; } id_vagons = rs_vag.SaveVAGONS(wag); // Вернуть id или ошибку } } return((int)id_vagons); }
/// <summary> /// Добавить или править /// </summary> /// <param name="WAYS"></param> /// <returns></returns> public int SaveVAGONS(VAGONS VAGONS) { VAGONS dbEntry; if (VAGONS.id_vag == 0) { dbEntry = new VAGONS() { id_vag = VAGONS.id_vag, num = VAGONS.num, id_ora = VAGONS.id_ora, id_owner = VAGONS.id_owner, id_stat = VAGONS.id_stat, is_locom = VAGONS.is_locom, locom_seria = VAGONS.locom_seria, rod = VAGONS.rod, st_otpr = VAGONS.st_otpr, date_ar = VAGONS.date_ar, date_end = VAGONS.date_end, date_in = VAGONS.date_in, IDSostav = VAGONS.IDSostav, Natur = VAGONS.Natur, Transit = VAGONS.Transit }; context_edit.VAGONS.Add(dbEntry); } else { dbEntry = context_edit.VAGONS.Find(VAGONS.id_vag); if (dbEntry != null) { //dbEntry.id_vag = VAGONS.id_vag; dbEntry.num = VAGONS.num; dbEntry.id_ora = VAGONS.id_ora; dbEntry.id_owner = VAGONS.id_owner; dbEntry.id_stat = VAGONS.id_stat; dbEntry.is_locom = VAGONS.is_locom; dbEntry.locom_seria = VAGONS.locom_seria; dbEntry.rod = VAGONS.rod; dbEntry.st_otpr = VAGONS.st_otpr; dbEntry.date_ar = VAGONS.date_ar; dbEntry.date_end = VAGONS.date_end; dbEntry.date_in = VAGONS.date_in; dbEntry.IDSostav = VAGONS.IDSostav; dbEntry.Natur = VAGONS.Natur; dbEntry.Transit = VAGONS.Transit; } } try { context_edit.SaveChanges(); } catch (Exception e) { LogRW.LogError(e, "SaveVAGONS", eventID); return(-1); } return(dbEntry.id_vag); }
/// <summary> /// Получить ID временно созданого вагона по номеру и дате захода на АМКР /// </summary> /// <param name="num_vag"></param> /// <param name="dt"></param> /// <returns></returns> public int?GetIDNewVagons(int num_vag, DateTime dt) { VAGONS vg = GetNewVagons(num_vag, dt); if (vg != null) { return(vg.id_vag); } return(null); }
/// <summary> /// Удалить /// </summary> /// <param name="id_way"></param> /// <returns></returns> public VAGONS DeleteVAGONS(int id_vag) { VAGONS dbEntry = context_edit.VAGONS.Find(id_vag); if (dbEntry != null) { context_edit.VAGONS.Remove(dbEntry); try { context_edit.SaveChanges(); } catch (Exception e) { LogRW.LogError(e, "DeleteVAGONS", eventID); return(null); } } return(dbEntry); }
/// <summary> /// Добавить удалить /// </summary> /// <param name="vagons"></param> /// <returns></returns> public int SaveVAGONS(VAGONS vagons) { return(rep_v.SaveVAGONS(vagons)); }
public void WL(VAGONS t) { Console.WriteLine("id_vag: {0}, num: {1}, id_ora: {2}, id_owner: {3}, id_stat: {4}, is_locom: {5}, locom_seria: {6}, rod: {7}, st_otpr: {8}, date_ar: {9}, :date_end {10}", t.id_vag, t.num, t.id_ora, t.id_owner, t.id_stat, t.is_locom, t.locom_seria, t.rod, t.st_otpr, t.date_ar, t.date_end); }
/// <summary> /// Синхронизировать справочник вагонов (тип, владелец, аренда, страна владельца) /// </summary> /// <param name="day"></param> /// <returns></returns> public int SynchronizeWagons(int day) { List <KometaVagonSob> list_shange = kc.GetChangeVagonsSob(day).ToList(); if (list_shange.Count() == 0) { return(0); } int updates = 0; int errors = 0; int skippeds = 0; foreach (KometaVagonSob kvs in list_shange) { int? owner = DefinitionIDOwner(kvs.SOB, null); // Определим id владельца (системы railCars) VAGONS wag_new = null; VAGONS wag = rs_vag.GetVagons(kvs.N_VAGON, kvs.DATE_AR); if (wag == null) { wag = rs_vag.GetNewVagons(kvs.N_VAGON, kvs.DATE_AR); if (wag == null) { // создадим новую строку с этой арендой wag_new = new VAGONS() { id_vag = 0, num = kvs.N_VAGON, id_ora = null, id_owner = owner, id_stat = null, is_locom = null, locom_seria = null, rod = kvs.ROD, st_otpr = "-", date_ar = kvs.DATE_AR, date_end = kvs.DATE_END, date_in = null, IDSostav = null, Natur = null, Transit = false, }; } else { // обновим аренду на вновь сосзданом wag_new = new VAGONS() { id_vag = wag.id_vag, num = wag.num, id_ora = wag.id_ora, id_owner = owner, id_stat = wag.id_stat, is_locom = wag.is_locom, locom_seria = wag.locom_seria, rod = kvs.ROD, st_otpr = wag.st_otpr, date_ar = kvs.DATE_AR, date_end = kvs.DATE_END, date_in = wag.date_in, IDSostav = wag.IDSostav, Natur = wag.Natur, Transit = wag.Transit, }; } } else { if (wag.date_ar < kvs.DATE_AR | wag.id_owner != owner) { // создадим новую строку с этой арендой старую закроем wag_new = new VAGONS() { id_vag = 0, num = kvs.N_VAGON, id_ora = null, id_owner = owner, id_stat = null, is_locom = null, locom_seria = null, rod = kvs.ROD, st_otpr = "-", date_ar = kvs.DATE_AR, date_end = kvs.DATE_END, date_in = null, IDSostav = null, Natur = null, Transit = false, }; if (wag.date_end == null) { wag.date_end = kvs.DATE_AR.AddMinutes(-1); rs_vag.SaveVAGONS(wag); } } else { skippeds++; } } if (wag_new != null) { int res = rs_vag.SaveVAGONS(wag_new); if (res > 0) { updates++; } if (res < 0) { errors++; } } } LogRW.LogWarning(String.Format("Определено для синхронизации справочника RailWay: {0} строк, синхронизировано: {1}, пропущено: {2}, ошибок синхронизации: {3}.", list_shange.Count(), updates, skippeds, errors), eventID); return(updates); }