private void btn_getTrainBarryLocomotives_Click(object sender, EventArgs e) { int F15Rec_ID; if (!int.TryParse(this.txtbx_locomotives_F15Rec_ID.Text, out F15Rec_ID)) { MessageBox.Show("Wrong F15Rec_ID or the F15Rec_ID is not specified"); return; } PWS0.trainBarryLocomotives locomotives = new PWS0.trainBarryLocomotives(); locomotives.fnc_getTrainsBarryLocomotives(F15Rec_ID); MessageBox.Show("Warning!!! 'get Train Barry Locomotives' does not save locomtives into database. To save locomotives you need to perform 'get Train Barries'", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("Finished!!!"); }
private void sb_saveToDB(trainBarryJsonModel train, int cycleNumber, bool getLocomotives, bool getBillOfLadings) { trainBarryBillOfLadings billOfLadings = new trainBarryBillOfLadings(); trainBarryLocomotives locos = new trainBarryLocomotives(); using (var entityLogistic = new Model.logisticEntities()) { bool add = false; Model.PWS0TrainsBarry entryPWS0Train = entityLogistic.PWS0TrainsBarry.FirstOrDefault(o => o.jCurrent_Station_Code == train.Current_Station_Code && o.jDestination_Station_Code == train.Destination_Station_Code //&& o.jEntrance_Date== train.Entrance_Date //&& o.jEntrance_DateTime== train.Entrance_DateTime //&& o.jEntrance_Time== train.Entrance_Time && o.jF15Rec_ID == train.F15Rec_ID && o.jSource_Station_Code == train.Source_Station_Code && o.jTashkil_Date == train.Tashkil_Date && o.jTashkil_Time == train.Tashkil_Time && o.jTrain_No == train.Train_No //&& o.jUpdate_DateTime == train.Update_DateTime ); if (entryPWS0Train == null) { add = true; entryPWS0Train = new Model.PWS0TrainsBarry(); } try { entryPWS0Train.CurrentStationId = stations.fnc_getStationId(train.Current_Station_Code, null, true); entryPWS0Train.DestinationStationId = stations.fnc_getStationId(train.Destination_Station_Code, null, true); entryPWS0Train.FetchTime = DateTime.Now; entryPWS0Train.jCurrent_Station_Code = train.Current_Station_Code; entryPWS0Train.jDestination_Station_Code = train.Destination_Station_Code; entryPWS0Train.jEntrance_Date = train.Entrance_Date; entryPWS0Train.jEntrance_DateTime = train.Entrance_DateTime; entryPWS0Train.jEntrance_Time = train.Entrance_Time; entryPWS0Train.jF15Rec_ID = train.F15Rec_ID; entryPWS0Train.jLocomotiveNumbers = (train.F15Rec_ID.HasValue && getLocomotives ? locos.fnc_getTrainsBarryLocomotives(train.F15Rec_ID.Value) : null); entryPWS0Train.jSource_Station_Code = train.Source_Station_Code; entryPWS0Train.jTashkil_Date = train.Tashkil_Date; entryPWS0Train.jTashkil_Time = train.Tashkil_Time; entryPWS0Train.jTrain_No = train.Train_No; entryPWS0Train.jUpdate_DateTime = train.Update_DateTime; entryPWS0Train.SourceStationId = stations.fnc_getStationId(train.Source_Station_Code, null, true); entryPWS0Train.TashkilDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(train.Tashkil_Date, string.IsNullOrEmpty(train.Tashkil_Time) ? null : (int?)int.Parse(train.Tashkil_Time)); entryPWS0Train.CycleNumber = cycleNumber; if (add) { entityLogistic.PWS0TrainsBarry.Add(entryPWS0Train); } entityLogistic.SaveChanges(); if (train.F15Rec_ID.HasValue && train.Train_No.HasValue && getBillOfLadings) { billOfLadings.readAndSaveToDB(train.F15Rec_ID.Value, train.Train_No.Value, entryPWS0Train.Id, cycleNumber, train); } } catch (Exception ex) { } } }