private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (dataGridView.CurrentRow.Index >= dataGridView.RowCount - 1) { return; } id.Text = dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString(); int Id = int.Parse(id.Text); ShowShipping(Id); shipping Shipping = Functions.FindShipping(Id); if (dataGridView1.CurrentCell.ColumnIndex == 1) { DriversForm DF = new DriversForm(Shipping.DriverId); DF.Show(); return; } if (dataGridView1.CurrentCell.ColumnIndex == 2) { CarsForm CF = new CarsForm(Shipping.CarId); CF.Show(); return; } if (dataGridView1.CurrentCell.ColumnIndex == 3) { FreightsForm FF = new FreightsForm(Shipping.FreightId); FF.Show(); return; } }
private void button3_Click(object sender, EventArgs e) { if (driver.SelectedIndex < 0 || car.SelectedIndex < 0 || freight.SelectedIndex < 0) { MessageBox.Show("Musi być określony kierowca, pojazd i zlecenie"); return; } shipping Shipping = new shipping { CarId = ((Transport)car.SelectedItem).Id, DriverId = ((Transport)driver.SelectedItem).Id, FreightId = ((Transport)freight.SelectedItem).Id, //DepartTime = DateTime.Now, Delivered = "Not yet", // ArriveTime = null, Comment = comment.Text }; freights Freight = Functions.FindFreights(Shipping.FreightId); cars Car = Functions.FindCar(Shipping.CarId); drivers Driver = Functions.FindDriver(Shipping.DriverId); cargo Cargo = Functions.FindCargo(Freight.CargoId); if (Freight.Weight > Car.Carry) { MessageBox.Show("Ten pojazd ma za małą ładowność"); return; } if (Boolean.Parse(Cargo.ADR) && !Boolean.Parse(Driver.ADR_License)) { MessageBox.Show("Kierowca nie może wieźć ładunku niebezpiecznego"); return; } //Freight.Weight projektEntities context = new projektEntities(); context.shipping.Add(Shipping); context.SaveChanges(); LoadData(); dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2]; id.Text = Shipping.Id.ToString(); updateResources(); }
private void button3_Click(object sender, EventArgs e) { if (driver.SelectedIndex < 0 || car.SelectedIndex < 0 || freight.SelectedIndex < 0) { MessageBox.Show("Musi być określony kierowca, pojazd i zlecenie"); return; } shipping Shipping = new shipping { CarId = ((Transport)car.SelectedItem).Id, DriverId = ((Transport)driver.SelectedItem).Id, FreightId = ((Transport)freight.SelectedItem).Id, //DepartTime = DateTime.Now, Delivered = "Not yet", // ArriveTime = null, Comment = comment.Text }; freights Freight = Functions.FindFreights(Shipping.FreightId); cars Car = Functions.FindCar(Shipping.CarId); drivers Driver = Functions.FindDriver(Shipping.DriverId); cargo Cargo = Functions.FindCargo(Freight.CargoId); if (Freight.Weight > Car.Carry) { MessageBox.Show("Ten pojazd ma za małą ładowność"); return; } if(Boolean.Parse(Cargo.ADR) && !Boolean.Parse(Driver.ADR_License)) { MessageBox.Show("Kierowca nie może wieźć ładunku niebezpiecznego"); return; } //Freight.Weight projektEntities context = new projektEntities(); context.shipping.Add(Shipping); context.SaveChanges(); LoadData(); dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2]; id.Text = Shipping.Id.ToString(); updateResources(); }
private void ShowShipping(int Id) { shipping Shipping = Functions.FindShipping(Id); projektEntities ctx = new projektEntities(); var result = (from fr in ctx.freights join ca in ctx.cargo on fr.CargoId equals ca.Id join st in ctx.companies on fr.From equals st.Id join stci in ctx.cities_list on st.CityId equals stci.Id join stco in ctx.company_name_list on st.CompanyId equals stco.Id join de in ctx.companies on fr.To equals de.Id join deci in ctx.cities_list on de.CityId equals deci.Id join deco in ctx.company_name_list on de.CompanyId equals deco.Id where fr.Id == Shipping.FreightId select new { Freight = fr, Cargo = ca, Start = st, StartCity = stci, StartCompany = stco, Destination = de, DestinationCity = deci, DestinationCompany = deco }).First(); drivers Driver = Functions.FindDriver(Shipping.DriverId); cars Car = Functions.FindCar(Shipping.CarId); driver.Text = Driver.Surname + " " + Driver.Name; if (Boolean.Parse(Driver.Busy) || !Boolean.Parse(Driver.Employed)) { driver.SelectedIndex = -1; driver.DropDownStyle = ComboBoxStyle.DropDown; driver.Enabled = false; driver.Text = Driver.Surname + " " + Driver.Name; } else { driver.DropDownStyle = ComboBoxStyle.DropDownList; driver.Enabled = true; } car.Text = Car.Make + " " + Car.Model + ", " + Car.Number_plate; if (Boolean.Parse(Car.IsUsed) || Boolean.Parse(Car.Sold)) { car.SelectedIndex = -1; car.DropDownStyle = ComboBoxStyle.DropDown; car.Enabled = false; car.Text = Car.Make + " " + Car.Model + ", " + Car.Number_plate; } else { car.DropDownStyle = ComboBoxStyle.DropDownList; car.Enabled = true; } freight.Text = result.Cargo.Name + ": " + result.StartCompany.Company + ", " + result.StartCity.City + '\u279C' + result.DestinationCompany.Company + ", " + result.DestinationCity.City; if (result.Freight.Amount < 1) { freight.SelectedIndex = -1; freight.DropDownStyle = ComboBoxStyle.DropDown; freight.Enabled = false; freight.Text = result.Cargo.Name + ": " + result.StartCompany.Company + ", " + result.StartCity.City + '\u279C' + result.DestinationCompany.Company + ", " + result.DestinationCity.City; } else { freight.DropDownStyle = ComboBoxStyle.DropDownList; freight.Enabled = true; } context.Dispose(); comment.Text = Shipping.Comment; context.SaveChanges(); }