Exemplo n.º 1
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            var selectedCar = autoCompleteBox1.SelectedItem as TrainTracker.Web.Models.RailCar;
            if (selectedCar == null)
            {
                MessageBox.Show("Car is not in System.\nPlease Enter a 'New Car'");
                return;
            }
            var context = new RailServeDS();
            InvokeOperation<int> InvokeOp = context.GetRailCarsByNumber(selectedCar.Number);
            InvokeOp.Completed += (ss, ee) =>
            {
                int carInSystem = InvokeOp.Value;
                if(carInSystem < 1)
                {
                    MessageBox.Show("Car is not in System. Please enter a 'New Car from next tab'");
                        return;
                }
                else
                {
                Random key = new Random();

                var currentStatus = new RailCarCurrentStatu();
                currentStatus.CurrentStatusID = key.Next(0, 99999999);
                var selectedStatus = loadComboBox.SelectedItem as TrainTracker.Web.Models.CarLoadStatu;
                var selectedComm = commComboBox.SelectedItem as TrainTracker.Web.Models.Commodity;
                var selectedDepartment = departmentComboBox.SelectedItem as TrainTracker.Web.Models.Department;
                var selectedTrack = trackComboBox.SelectedItem as TrainTracker.Web.Models.Track;

                currentStatus.LocationID = myLocation;
                currentStatus.YardID = (int)selectedTrack.YardId;
                currentStatus.StatusId = selectedStatus.StatusID;
                currentStatus.CommodityId = selectedComm.CommodityID;
                currentStatus.CarID = selectedCar.CarID;
                currentStatus.TrackId = selectedTrack.TrackID;

                currentStatus.PrimaryUser = WebContext.Current.User.Name;
                currentStatus.Demurrage = checkBox1.IsChecked;
                currentStatus.Company = company.Text;
                currentStatus.DepartmentId = selectedDepartment.DepartmentID;
                currentStatus.ReceiptDate = date.DisplayDate;
                currentStatus.ReceiptTime = (DateTime)time.Value;
                currentStatus.MovementDate = DateTime.Today;

                if(weight.Text != null || weight.Text !="")
                {
                    int we;
                    if (Int32.TryParse(weight.Text, out we))
                      currentStatus.Weight = we;
                    else
                    {
                        MessageBox.Show("Weight is not a valid Numeric field");
                        return;
                     }
                 }
                currentStatus.Supplier = supplier.Text;
                currentStatus.Comments = comments.Text;
                currentStatus.HistoryTypeId = 1; //HistoryType is stored in db to distinguish movement types
                if (railCarCurrentStatuDomainDataSource.DataView.CanAdd == false)
                    railCarCurrentStatuDomainDataSource.Load();
                railCarCurrentStatuDomainDataSource.DataView.Add(currentStatus);
                if (railCarCurrentStatuDomainDataSource.HasChanges)
                {
                    railCarCurrentStatuDomainDataSource.SubmitChanges();
                    MessageBox.Show("Car: " +selectedCar.Number + " is now is your yard!");
                    save.IsEnabled = false;
                 }
               }
               };
        }
Exemplo n.º 2
0
        private void car_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var context = new RailServeDS();
            var selectedCar = autoCompleteBox1.SelectedItem as TrainTracker.Web.Models.RailCar;
            if (selectedCar != null)
            {
                InvokeOperation<int> InvokeOp = context.GetRailCarCurrentStatusByLocationandCarCount(myLocation, selectedCar.CarID);
                InvokeOp.Completed += (ss, ee) =>
                {
                    int carInSystem = InvokeOp.Value;
                    if (carInSystem >= 1)
                    {
                        MessageBox.Show("Car is already in your location");
                        save.IsEnabled = false;
                        return;
                    }
                    else
                        save.IsEnabled = true;

                };
            }
        }