예제 #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();

            var query = (from f in context.shipping
                         where f.Id == Id
                         select new
            {
                Shipping = f
            }).First();

            if (query.Shipping.ArriveTime.HasValue)
            {
                MessageBox.Show("To zlecenie zostało już ukończone");
                return;
            }
            query.Shipping.Comment    = comment.Text;
            query.Shipping.ArriveTime = DateTime.Now;

            context.Entry(query.Shipping).State = EntityState.Modified;
            context.SaveChanges();
            updateResources();
            ClearForm();
            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();

            var query = (from f in context.shipping
                         where f.Id == Id
                         select new
            {
                Shipping = f
            }).First();

            query.Shipping.Comment = comment.Text;

            context.Entry(query.Shipping).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #3
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (cargo.SelectedIndex < 0 || start.SelectedIndex < 0 || destination.SelectedIndex < 0)
            {
                MessageBox.Show("Towar, miejsce startowe i miejsce docelowe nie mogą być puste");
                return;
            }
            freights Freight = new freights
            {
                Amount          = (byte)amount.Value,
                CargoId         = ((Transport)cargo.SelectedItem).Id,
                Comment         = comment.Text,
                From            = ((Transport)start.SelectedItem).Id,
                ScheduledArrive = date.Value,
                To     = ((Transport)destination.SelectedItem).Id,
                Weight = (int)weight.Value
            };

            projektEntities context = new projektEntities();

            context.freights.Add(Freight);
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
            id.Text = Freight.Id.ToString();
        }
예제 #4
0
파일: CarsForm.cs 프로젝트: lukadut/bazy
        private void button3_Click(object sender, EventArgs e)
        {
            if (Functions.AllowedPlate(plate.Text))
            {
                cars Car = new cars
                {
                    Make         = make.Text,
                    Model        = model.Text,
                    Comment      = comment.Text,
                    Number_plate = plate.Text,
                    Carry        = (int)carry.Value,
                    IsUsed       = false.ToString(),
                    Sold         = false.ToString()
                };
                projektEntities context = new projektEntities();
                context.cars.Add(Car);
                context.SaveChanges();

                LoadData();
                dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
                id.Text = Car.Id.ToString();
            }
            else
            {
                MessageBox.Show("Istnieje już auto o takiej rejestracji");
            }
        }
예제 #5
0
 private void getOrAddCity(int index)
 {
     if (index < 0)
     {
         String name = Functions.TextFormat(cities.Text);
         if (name.Length == 0)
         {
             throw new Exception("Miasto nie może mieć pustej nazwy");
         }
         cities_list newCity = new cities_list()
         {
             City = name
         };
         context.cities_list.Add(newCity);
         context.SaveChanges();
         cities.Items.Add(new Transport()
         {
             Name = newCity.City,
             Id   = newCity.Id
         });
         cities.SelectedIndex = cities.Items.Count - 1;
     }
 }
예제 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var             query   = (from c in context.cargo
                                       where c.Id == Id
                                       select new
            {
                Cargo = c
            }).First();

            if (query.Cargo == null)
            {
                MessageBox.Show("Nie znaleziono auta o takim Id");
                return;
            }

            query.Cargo.Name    = name.Text;
            query.Cargo.ADR     = adr.Checked.ToString();
            query.Cargo.Type    = Types[Functions.FindStringIndex(TypesPL, type.Text)];
            query.Cargo.Comment = comment.Text;

            string adrClass = "";

            foreach (var item in CheckBoxList)
            {
                if (item.Checked)
                {
                    adrClass += Functions.classes[(int)item.Tag];
                }
                adrClass += ",";
                //Cargo.AdrClass[(int)item.Tag] = item.Checked;
            }
            adrClass = adrClass.Remove(adrClass.LastIndexOf(','));
            query.Cargo.ADR_Class            = adrClass;
            context.Entry(query.Cargo).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #7
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                getOrAddCity(cities.SelectedIndex);
                getOrAddCompany(companies.SelectedIndex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            companies Company = new companies
            {
                Address   = address.Text,
                Comment   = comment.Text,
                CityId    = ((Transport)cities.SelectedItem).Id,
                CompanyId = ((Transport)companies.SelectedItem).Id
            };
            projektEntities context = new projektEntities();

            try
            {
                context.companies.Add(Company);
                context.SaveChanges();

                LoadData();
                int currentRow = dataGridView.RowCount - 2;
                for (int i = 0; i < dataGridView.RowCount; i++)
                {
                    System.Console.WriteLine(dataGridView[0, i].Value.ToString());
                    if (int.Parse(dataGridView[0, i].Value.ToString()) == Company.Id)
                    {
                        currentRow = i;
                        break;
                    }
                }
                dataGridView.CurrentCell = dataGridView[0, currentRow];
                id.Text = Company.Id.ToString();
            } catch (Exception) {
                MessageBox.Show("Taka firma już istnieje");
            }
        }
예제 #8
0
        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();
        }
예제 #9
0
파일: CarsForm.cs 프로젝트: lukadut/bazy
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var             query   = (from car in context.cars
                                       where car.Id == Id
                                       select new
            {
                Car = car
            }).First();

            if (query.Car == null)
            {
                MessageBox.Show("Nie znaleziono auta o takim Id");
                return;
            }
            if (!Functions.AllowedPlate(plate.Text) && plate.Text != query.Car.Number_plate)
            {
                MessageBox.Show("Taki numer rejestracji już występuje");
                return;
            }

            query.Car.Make         = make.Text;
            query.Car.Model        = model.Text;
            query.Car.Comment      = comment.Text;
            query.Car.Number_plate = plate.Text;
            query.Car.Carry        = (int)carry.Value;
            query.Car.Sold         = sold.Checked.ToString();

            context.Entry(query.Car).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();

            var query = (from company in context.companies
                         where company.Id == Id
                         select new
            {
                company
            }).First();

            try
            {
                getOrAddCity(cities.SelectedIndex);
                getOrAddCompany(companies.SelectedIndex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            query.company.Address   = address.Text;
            query.company.Comment   = comment.Text;
            query.company.CityId    = ((Transport)cities.SelectedItem).Id;
            query.company.CompanyId = ((Transport)companies.SelectedItem).Id;

            context.Entry(query.company).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #11
0
파일: DriversForm.cs 프로젝트: lukadut/bazy
        private void button3_Click(object sender, EventArgs e)
        {
            drivers Driver = new drivers
            {
                Name        = name.Text,
                Surname     = surname.Text,
                Wage        = (int)wage.Value,
                ADR_License = adr.Checked.ToString(),
                Employed    = true.ToString(),
                Busy        = false.ToString(),
                Comment     = comment.Text
            };
            projektEntities context = new projektEntities();

            context.drivers.Add(Driver);
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
            id.Text = Driver.Id.ToString();
        }
예제 #12
0
파일: DriversForm.cs 프로젝트: lukadut/bazy
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var             query   = (from driver in context.drivers
                                       where driver.Id == Id
                                       select new
            {
                Driver = driver
            }).First();

            if (query.Driver == null)
            {
                MessageBox.Show("Nie znaleziono kierowcy o takim Id");
                return;
            }


            query.Driver.Name        = name.Text;
            query.Driver.Surname     = surname.Text;
            query.Driver.Comment     = comment.Text;
            query.Driver.Wage        = (int)wage.Value;
            query.Driver.Employed    = employed.Checked.ToString();
            query.Driver.ADR_License = adr.Checked.ToString();

            context.Entry(query.Driver).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;

            if (id.Text == "")
            {
                return;
            }
            int Id = int.Parse(id.Text);

            if (cargo.SelectedIndex < 0 || start.SelectedIndex < 0 || destination.SelectedIndex < 0)
            {
                MessageBox.Show("Towar, miejsce startowe i miejsce docelowe nie mogą być puste");
                return;
            }
            projektEntities context = new projektEntities();

            var query = (from f in context.freights
                         where f.Id == Id
                         select new
            {
                Freight = f
            }).First();

            query.Freight.Amount          = (byte)amount.Value;
            query.Freight.CargoId         = ((Transport)cargo.SelectedItem).Id;
            query.Freight.Comment         = comment.Text;
            query.Freight.From            = ((Transport)start.SelectedItem).Id;
            query.Freight.ScheduledArrive = date.Value;
            query.Freight.To     = ((Transport)destination.SelectedItem).Id;
            query.Freight.Weight = (int)weight.Value;

            context.Entry(query.Freight).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();

            var query = (from f in context.shipping
                         where f.Id == Id
                         select new
                         {
                             Shipping = f
                         }).First();
            query.Shipping.Comment = comment.Text;

            context.Entry(query.Shipping).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #15
0
파일: CargoForm.cs 프로젝트: lukadut/bazy
        private void button3_Click(object sender, EventArgs e)
        {
            //////FreightsList.Types a = FreightsList.Types.Container;
            //////string b = "Flatbed";
            //////a = (FreightsList.Types)2;
            //////Console.WriteLine("Types a = " + a + (int)a);
            //////Console.WriteLine(b + " == " + a + "  asasd ");
            //////Console.WriteLine((string)a.ToString() == b);
            //////Console.WriteLine("");
            //////MessageBox.Show(dataGridView1.Rows[1].Cells[4].Value.ToString());

            string adrClass = "";
            foreach (var item in CheckBoxList)
            {
                if (item.Checked)
                {
                    adrClass += Functions.classes[(int)item.Tag];
                }
                adrClass += ",";
                //Cargo.AdrClass[(int)item.Tag] = item.Checked;
            }
            adrClass = adrClass.Remove(adrClass.LastIndexOf(','));

            cargo Cargo = new cargo()
            {
                Name = name.Text,
                ADR = adr.Checked.ToString(),
                Type = Types[Functions.FindStringIndex(TypesPL, type.Text)],
                Comment = comment.Text,
                ADR_Class = adrClass
            };

            projektEntities context = new projektEntities();
            context.cargo.Add(Cargo);
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
            id.Text = Cargo.Id.ToString();
            ////string adrClass = "";
            ////foreach (var item in CheckBoxList)
            ////{
            ////    if (item.Checked)
            ////    {
            ////        adrClass += Functions.classes[(int)item.Tag] + ",";
            ////    }
            ////}
            ////if (adrClass.Length > 0)
            ////    adrClass.Remove(adrClass.Length - 1, 1);
            ////else
            ////    adr.Checked = false;
            ////DataBase.AddFreightsList(name.Text, Types[Functions.FindStringIndex(TypesPL, type.Text)], adrClass, adr.Checked, comment.Text);
            ////LoadData(DataBase);

            //////if (Functions.AllowedPlate(plate.Text, DataBase.CarsList))
            //////{
            //////    //DataBase.AddCar(plate.Text, make.Text, model.Text, (uint)carry.Value, false, false, comment.Text);
            //////    //DataBase.CarsList.Add(new Cars());
            //////    //LoadData(DataBase);
            //////}
            //////else
            //////{
            //////    MessageBox.Show("Istnieje już auto o takiej rejestracji");
            //////}
        }
예제 #16
0
파일: CarsForm.cs 프로젝트: lukadut/bazy
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var query = (from car in context.cars
                         where car.Id == Id
                         select new
                         {
                             Car = car
                         }).First();
            if (query.Car == null)
            {
                MessageBox.Show("Nie znaleziono auta o takim Id");
                return;
            }
            if (!Functions.AllowedPlate(plate.Text) && plate.Text != query.Car.Number_plate)
            {
                MessageBox.Show("Taki numer rejestracji już występuje");
                return;
            }

            query.Car.Make = make.Text;
            query.Car.Model = model.Text;
            query.Car.Comment = comment.Text;
            query.Car.Number_plate = plate.Text;
            query.Car.Carry = (int)carry.Value;
            query.Car.Sold = sold.Checked.ToString();

            context.Entry(query.Car).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #17
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (cargo.SelectedIndex < 0 || start.SelectedIndex < 0 || destination.SelectedIndex < 0)
            {
                MessageBox.Show("Towar, miejsce startowe i miejsce docelowe nie mogą być puste");
                return;
            }
            freights Freight = new freights
            {
                Amount = (byte)amount.Value,
                CargoId = ((Transport)cargo.SelectedItem).Id,
                Comment = comment.Text,
                From = ((Transport)start.SelectedItem).Id,
                ScheduledArrive = date.Value,
                To = ((Transport)destination.SelectedItem).Id,
                Weight = (int)weight.Value
            };

            projektEntities context = new projektEntities();
            context.freights.Add(Freight);
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
            id.Text = Freight.Id.ToString();
        }
예제 #18
0
파일: CarsForm.cs 프로젝트: lukadut/bazy
        private void button3_Click(object sender, EventArgs e)
        {
            if (Functions.AllowedPlate(plate.Text))
            {
                cars Car = new cars
                {
                    Make = make.Text,
                    Model = model.Text,
                    Comment = comment.Text,
                    Number_plate = plate.Text,
                    Carry = (int)carry.Value,
                    IsUsed=false.ToString(),
                    Sold = false.ToString()
                };
                projektEntities context = new projektEntities();
                context.cars.Add(Car);
                context.SaveChanges();

                LoadData();
                dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount-2];
                id.Text = Car.Id.ToString();
            }
            else
            {
                MessageBox.Show("Istnieje już auto o takiej rejestracji");
            }
        }
예제 #19
0
파일: DriversForm.cs 프로젝트: lukadut/bazy
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var query = (from driver in context.drivers
                         where driver.Id == Id
                         select new
                         {
                             Driver = driver
                         }).First();
            if (query.Driver == null)
            {
                MessageBox.Show("Nie znaleziono kierowcy o takim Id");
                return;
            }

            query.Driver.Name = name.Text;
            query.Driver.Surname = surname.Text;
            query.Driver.Comment = comment.Text;
            query.Driver.Wage = (int)wage.Value;
            query.Driver.Employed = employed.Checked.ToString();
            query.Driver.ADR_License = adr.Checked.ToString();

            context.Entry(query.Driver).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #20
0
        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();
        }
예제 #21
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                getOrAddCity(cities.SelectedIndex);
                getOrAddCompany(companies.SelectedIndex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            companies Company = new companies
            {
                Address = address.Text,
                Comment = comment.Text,
                CityId = ((Transport)cities.SelectedItem).Id,
                CompanyId = ((Transport)companies.SelectedItem).Id
            };
            projektEntities context = new projektEntities();
            try
            {
                context.companies.Add(Company);
                context.SaveChanges();

                LoadData();
                int currentRow = dataGridView.RowCount - 2;
                for (int i = 0; i < dataGridView.RowCount; i++)
                {
                    System.Console.WriteLine(dataGridView[0, i].Value.ToString());
                    if (int.Parse(dataGridView[0, i].Value.ToString()) == Company.Id)
                    {
                        currentRow = i;
                        break;
                    }
                }
                dataGridView.CurrentCell = dataGridView[0, currentRow];
                id.Text = Company.Id.ToString();
            } catch(Exception){
                MessageBox.Show("Taka firma już istnieje");
            }
        }
예제 #22
0
파일: CargoForm.cs 프로젝트: lukadut/bazy
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();
            var query = (from c in context.cargo
                         where c.Id == Id
                         select new
                         {
                             Cargo = c
                         }).First();
            if (query.Cargo == null)
            {
                MessageBox.Show("Nie znaleziono auta o takim Id");
                return;
            }

            query.Cargo.Name = name.Text;
            query.Cargo.ADR = adr.Checked.ToString();
            query.Cargo.Type = Types[Functions.FindStringIndex(TypesPL, type.Text)];
            query.Cargo.Comment = comment.Text;

            string adrClass = "";
            foreach (var item in CheckBoxList)
            {
                if (item.Checked)
                {
                    adrClass += Functions.classes[(int)item.Tag];
                }
                adrClass += ",";
                //Cargo.AdrClass[(int)item.Tag] = item.Checked;
            }
            adrClass = adrClass.Remove(adrClass.LastIndexOf(','));
            query.Cargo.ADR_Class = adrClass;
            context.Entry(query.Cargo).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #23
0
        private void button3_Click(object sender, EventArgs e)
        {
            //////FreightsList.Types a = FreightsList.Types.Container;
            //////string b = "Flatbed";
            //////a = (FreightsList.Types)2;
            //////Console.WriteLine("Types a = " + a + (int)a);
            //////Console.WriteLine(b + " == " + a + "  asasd ");
            //////Console.WriteLine((string)a.ToString() == b);
            //////Console.WriteLine("");
            //////MessageBox.Show(dataGridView1.Rows[1].Cells[4].Value.ToString());

            string adrClass = "";

            foreach (var item in CheckBoxList)
            {
                if (item.Checked)
                {
                    adrClass += Functions.classes[(int)item.Tag];
                }
                adrClass += ",";
                //Cargo.AdrClass[(int)item.Tag] = item.Checked;
            }
            adrClass = adrClass.Remove(adrClass.LastIndexOf(','));

            cargo Cargo = new cargo()
            {
                Name      = name.Text,
                ADR       = adr.Checked.ToString(),
                Type      = Types[Functions.FindStringIndex(TypesPL, type.Text)],
                Comment   = comment.Text,
                ADR_Class = adrClass
            };

            projektEntities context = new projektEntities();

            context.cargo.Add(Cargo);
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
            id.Text = Cargo.Id.ToString();
            ////string adrClass = "";
            ////foreach (var item in CheckBoxList)
            ////{
            ////    if (item.Checked)
            ////    {
            ////        adrClass += Functions.classes[(int)item.Tag] + ",";
            ////    }
            ////}
            ////if (adrClass.Length > 0)
            ////    adrClass.Remove(adrClass.Length - 1, 1);
            ////else
            ////    adr.Checked = false;
            ////DataBase.AddFreightsList(name.Text, Types[Functions.FindStringIndex(TypesPL, type.Text)], adrClass, adr.Checked, comment.Text);
            ////LoadData(DataBase);

            //////if (Functions.AllowedPlate(plate.Text, DataBase.CarsList))
            //////{
            //////    //DataBase.AddCar(plate.Text, make.Text, model.Text, (uint)carry.Value, false, false, comment.Text);
            //////    //DataBase.CarsList.Add(new Cars());
            //////    //LoadData(DataBase);
            //////}
            //////else
            //////{
            //////    MessageBox.Show("Istnieje już auto o takiej rejestracji");
            //////}
        }
예제 #24
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);
            if (cargo.SelectedIndex < 0 || start.SelectedIndex < 0 || destination.SelectedIndex < 0)
            {
                MessageBox.Show("Towar, miejsce startowe i miejsce docelowe nie mogą być puste");
                return;
            }
            projektEntities context = new projektEntities();

            var query = (from f in context.freights
                         where f.Id == Id
                         select new
                         {
                             Freight = f
                         }).First();
            query.Freight.Amount = (byte)amount.Value;
            query.Freight.CargoId = ((Transport)cargo.SelectedItem).Id;
            query.Freight.Comment = comment.Text;
            query.Freight.From = ((Transport)start.SelectedItem).Id;
            query.Freight.ScheduledArrive = date.Value;
            query.Freight.To = ((Transport)destination.SelectedItem).Id;
            query.Freight.Weight = (int)weight.Value;

            context.Entry(query.Freight).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #25
0
        private void button4_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();

            var query = (from f in context.shipping
                         where f.Id == Id
                         select new
                         {
                             Shipping = f
                         }).First();
            if (query.Shipping.ArriveTime.HasValue)
            {
                MessageBox.Show("To zlecenie zostało już ukończone");
                return;
            }
            query.Shipping.Comment = comment.Text;
            query.Shipping.ArriveTime = DateTime.Now;

            context.Entry(query.Shipping).State = EntityState.Modified;
            context.SaveChanges();
            updateResources();
            ClearForm();
            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #26
0
        private void button1_Click(object sender, EventArgs e)
        {
            int currentRow = dataGridView1.CurrentRow.Index;
            int currentCol = dataGridView1.CurrentCell.ColumnIndex;
            if (id.Text == "")
                return;
            int Id = int.Parse(id.Text);

            projektEntities context = new projektEntities();

            var query = (from company in context.companies
                         where company.Id == Id
                         select new
                         {
                             company
                         }).First();
            try
            {
                getOrAddCity(cities.SelectedIndex);
                getOrAddCompany(companies.SelectedIndex);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            query.company.Address = address.Text;
            query.company.Comment = comment.Text;
            query.company.CityId = ((Transport)cities.SelectedItem).Id;
            query.company.CompanyId = ((Transport)companies.SelectedItem).Id;

            context.Entry(query.company).State = EntityState.Modified;
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[currentCol, currentRow];
        }
예제 #27
0
        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();
        }
예제 #28
0
파일: DriversForm.cs 프로젝트: lukadut/bazy
        private void button3_Click(object sender, EventArgs e)
        {
            drivers Driver = new drivers
            {
                Name = name.Text,
                Surname = surname.Text,
                Wage = (int)wage.Value,
                ADR_License = adr.Checked.ToString(),
                Employed = true.ToString(),
                Busy = false.ToString(),
                Comment = comment.Text
            };
            projektEntities context = new projektEntities();
            context.drivers.Add(Driver);
            context.SaveChanges();

            LoadData();
            dataGridView.CurrentCell = dataGridView[0, dataGridView.RowCount - 2];
            id.Text = Driver.Id.ToString();
        }