public void SaveSecondWeighingData(Freight frg, ModelTMSContainer ControlObjectContext) { FreightWeighing fgw = frg.FreightWeighing.First <FreightWeighing>(); FreightWeighingMaterial fwm = fgw.FreightWeighingMaterial.First <FreightWeighingMaterial>(); fgw.WeighingDateTime2 = CalendarWithTimeControl2.SelectedDateTime; fgw.Key2 = TextBoxKey2.Text; try { fgw.Weight2 = Convert.ToDouble("0" + TextBoxWeight2.Text); } catch { }; fwm.TarraWeight = fgw.Weight2; fwm.NetWeight = fwm.GrossWeight - fwm.TarraWeight; frg.TotalNetWeight = fwm.NetWeight; frg.Description = TextBoxDescription.Text; frg.Comments = TextBoxComments.Text; frg.FreightStatus = "Done"; frg.RecalcTotalWeightFromWeighing(); if (CheckBoxWeighingActionSort.Checked) { frg.FreightStatus = "In sorting"; } if (CheckBoxWeighingActionInvoice.Checked) { frg.FreightStatus = "To be invoiced"; } }
protected bool PrepareOldWeighingForSorting() { // check whether this weighing may be deleted. If this is not the case then inform the user that this weighing is already processed. ModelTMSContainer ControlObjectContext = new ModelTMSContainer(Session["CustomerConnectString"].ToString(), Session); bool Success = false; // start transaction using (TransactionScope TS = new TransactionScope()) { try { // add weighing materual as sorting material Freight frg = Freight.SelectFreightByFreightId(CurrentWeighingId, ControlObjectContext); frg.RecalcTotalWeightFromWeighing(); foreach (FreightWeighing fw in frg.FreightWeighing) { foreach (FreightWeighingMaterial fwm in fw.FreightWeighingMaterial) { FreightSortingMaterial fsm = new FreightSortingMaterial(); fsm.Material = fwm.Material; fsm.Weight = fwm.NetWeight; fsm.GrossWeight = fwm.GrossWeight; fsm.TarraWeight = fwm.TarraWeight; fsm.Freight = frg; ControlObjectContext.AddToFreightSortingMaterialSet(fsm); } } frg.RecalcTotalWeightFromSorting(); // and save to persistent storage ControlObjectContext.SaveChanges(System.Data.Objects.SaveOptions.DetectChangesBeforeSave); // commit the transaciton TS.Complete(); Success = true; } catch (Exception ex) // commit or procedure failed somewhere { // rollback transaction TS.Dispose(); // inform user Common.InformUserOnTransactionFail(ex, Page); } } return(Success); }