void fillAllElements(string connsignmentNo) { try { RuntimeData data; data = dataContext.SingleOrDefault(x => x.ConsignmentNo == connsignmentNo); if (data != null) { if (backDataGrid != null) { if (backDataGrid.Items.Contains(data)) { backDataGrid.SelectedItem = data; DataGridRow row; try { row = (DataGridRow)backDataGrid.ItemContainerGenerator.ContainerFromItem(data); row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); } catch (Exception) { Console.WriteLine("Error...."); } } else { backDataGrid.SelectedItems.Clear(); } } this.Focus(); fillDetails(data); } else { if (backDataGrid != null) { backDataGrid.SelectedItems.Clear(); } BillingDataDataContext db = new BillingDataDataContext(); var TData = db.Transactions.SingleOrDefault(x => x.ConnsignmentNo == connsignmentNo); if (TData != null) { fillDetails(UtilityClass.convertTransObjToRunObj(TData)); } else { clearDetails(); } } } catch (Exception ex) { MessageBox.Show("Unable to load connsignment:" + ex.Message); this.Close(); } }
public RuntimeData fillData(RuntimeData data) { List <Client> clientList = DataSources.ClientCopy; List <City> cityList = DataSources.CityCopy; List <Service> serviceList = DataSources.ServicesCopy; if (CustomerSelected.Text == "") { CustomerSelected.Text = "<NONE>"; } if (WeightAccToDTDC.Text == "") { WeightAccToDTDC.Text = "0"; } if (WeightAccToFranchize.Text == "") { WeightAccToFranchize.Text = WeightAccToDTDC.Text; } if (BilledWeightTextBox.Text == "") { BilledWeightTextBox.Text = WeightAccToFranchize.Text; } if (BilledAmount.Text == "") { BilledAmount.Text = "0"; } if (Destination.Text == "" || Destination.Text == null) { MessageBox.Show("City cannot be empty"); return(null); } data = dataContext.SingleOrDefault(x => x.ConsignmentNo == ConnsignmentNumber.Text); if (data == null) { BillingDataDataContext db = new BillingDataDataContext(); var TData = db.Transactions.SingleOrDefault(x => x.ConnsignmentNo == ConnsignmentNumber.Text); if (TData == null) { data = new RuntimeData(); data.Id = Guid.NewGuid(); data.ConsignmentNo = ConnsignmentNumber.Text; } else { data = UtilityClass.convertTransObjToRunObj(TData); } } double weight; if (Double.TryParse(WeightAccToDTDC.Text, out weight)) { data.Weight = weight; } else { MessageBox.Show("Weight is incorrect", "Error"); return(null); } data.FrWeight = Double.Parse(WeightAccToFranchize.Text); double tmpD; if (Cost.Text == "" || !double.TryParse(Cost.Text, out tmpD)) { Cost.Text = "0"; } data.Amount = Decimal.Parse(Cost.Text); var c1 = cityList.Where(x => x.NameAndCode == Destination.Text).FirstOrDefault(); if (c1 != null) { data.Destination = c1.CITY_CODE; data.City_Desc = c1.CITY_DESC; } decimal tempDecimal; if (decimal.TryParse(DestinationPin.Text, out tempDecimal)) { data.DestinationPin = tempDecimal; } data.CustCode = DataSources.ClientCopy.Where(x => x.NameAndCode == CustomerSelected.Text).Select(y => y.CLCODE).FirstOrDefault(); if (data.CustCode == "" || data.CustCode == null || data.CustCode == "<NONE>") { MessageBox.Show("No customer selected...", "Error"); return(null); } if (MODE.Text != "") { data.Mode = MODE.Text; } Service service = serviceList.Where(x => x.NameAndCode == TypeComboBox.Text.Trim()).FirstOrDefault(); if (service == null) { MessageBox.Show("No service selected...", "Error"); return(null); } data.Type = service.SER_CODE; data.Service_Desc = service.SER_DESC; data.BookingDate = InsertionDate.SelectedDate ?? DateTime.Today; if (decimal.TryParse(BilledAmount.Text, out tempDecimal)) { data.FrAmount = tempDecimal; } else { MessageBox.Show("Invalid billed amount", "Error"); return(null); } if (DoxCombobox.Text == "") { DoxCombobox.Text = "Dox"; } data.DOX = DoxCombobox.Text.Length > 1 ? DoxCombobox.Text.ElementAt(0) : 'D'; float tempValue; if (float.TryParse(BilledWeightTextBox.Text, out tempValue)) { data.BilledWeight = double.Parse(BilledWeightTextBox.Text, CultureInfo.InvariantCulture); } else { BilledWeightTextBox.Text = ""; } if (data.Destination == null) { MessageBoxResult rsltMessageBox = MessageBox.Show("City not found \n Would you like to enter city", "", MessageBoxButton.YesNo, MessageBoxImage.Asterisk); if (MessageBoxResult.Yes == rsltMessageBox) { return(null); } else { this.Close(); } } data.CustCode = clientList.Where(x => x.NameAndCode == CustomerSelected.Text).Select(y => y.CLCODE).FirstOrDefault(); if (data.CustCode != null) { data.Client_Desc = clientList.Where(x => x.NameAndCode == CustomerSelected.Text).Select(y => y.CLNAME).FirstOrDefault(); } if (this.BilledWeightTextBox.Text == "" || this.BilledWeightTextBox.Text == null) { if (this.WeightAccToFranchize.Text == "" || this.WeightAccToFranchize == null) { data.BilledWeight = 0; } else { data.BilledWeight = data.FrWeight; } } else { if (float.TryParse(BilledWeightTextBox.Text, out tempValue)) { data.BilledWeight = double.Parse(BilledWeightTextBox.Text, CultureInfo.InvariantCulture); } } data.ConsigneeName = ConsgineeName.Text; data.ConsignerName = ConsignerName.Text; data.SubClient = SubClientComboBox.Text; if (RecalculateCheckBox.IsChecked == true) { data.RecalculateEnabled = 'T'; } else { data.RecalculateEnabled = 'F'; } if (decimal.TryParse(InsuranceBox.Text, out tempDecimal)) { data.Insurance = tempDecimal; } else { data.Insurance = 0; InsuranceBox.Text = "0"; } return(data); }