private void Flightdgv_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { int id = Convert.ToInt32(Flightdgv.Rows[e.RowIndex].Cells[0].Value.ToString()); this.selectedFlight = db.Fligts.Find(id); Companycb.Text = this.selectedFlight.Company.Name; Countrycb.Text = this.selectedFlight.City.Country.Name; Gatecb.Text = this.selectedFlight.Gate.Name; Runwaycb.Text = this.selectedFlight.Runway.Name; Citycb.Text = this.selectedFlight.City.Name; AddFlightbtn.Visible = false; Updatebtn.Visible = true; Deletebtn.Visible = true; }
private void AddFlightbtn_Click(object sender, EventArgs e) { Fligt flg = new Fligt(); string name = Companycb.Text; string Company = Companycb.Text; string City = Citycb.Text; int Runway = getRunwayIdByName(Runwaycb.Text); int Gate = getGateIdByName(Gatecb.Text); DateTime date = FlightDate.Value; DateTime GateFullTimeBefore = date.AddMinutes(-30); DateTime GateFullTimeAfter = date.AddMinutes(30); List <Fligt> checkGate = db.Fligts.Where(c => c.FlightDate >= GateFullTimeBefore && c.FlightDate <= GateFullTimeAfter && c.GateID == Gate).ToList(); DateTime runwayFullTimeBefore = date.AddMinutes(-45); DateTime runwayFullTimeAfter = date.AddMinutes(45); List <Fligt> checkRunway = db.Fligts.Where(c => c.FlightDate >= runwayFullTimeBefore && c.FlightDate <= runwayFullTimeAfter && c.RunwayID == Runway).ToList(); if (!(City == string.Empty || Company == string.Empty || Runwaycb.Text == string.Empty || Gatecb.Text == string.Empty)) { if (!(checkGate.Count > 0 || checkRunway.Count > 0)) { flg.FlightDate = FlightDate.Value; flg.CompanyID = getCompanyIdByName(Company); flg.CityID = getCityIdByName(City); flg.RunwayID = Runway; flg.GateID = Gate; flg.FlightDate = FlightDate.Value; if (arivalbtn.Checked == true) { flg.Type = 1; } if (departurebtn.Checked == true) { flg.Type = 0; } db.Fligts.Add(flg); db.SaveChanges(); loadData(); Clear(); } else { MessageBox.Show("bu zamana gediw yoxdu "); } } else { MessageBox.Show("boxlari doldurun"); } }