private void button1_Click(object sender, EventArgs e) { p.Name = textBox1.Text; p.Age = int.Parse(textBox2.Text); p.Phone = textBox3.Text; p.NationalID = textBox4.Text; // Context.Passengers.Add(p); //Context.SaveChanges(); Passenger_ID = p.ID; R.JourneyID = this.Journeys_id; R.PassengerID = Passenger_ID; R.NumOfTickets = int.Parse(textBox5.Text); R.EmployeeID = LoginForm.EmpID; //R.Passenger = p; // Context.Reserves.Add(R); Journey J = (from j in Program._dbContext.Journeys where j.ID == Journeys_id select j).FirstOrDefault(); avilable = J.MaxNumber - J.NumOfReservedChairs; if (avilable < int.Parse(textBox5.Text)) { MessageBox.Show("Number of Tickets are more than avilable \n avilable= " + avilable); } else { Program._dbContext.Passengers.Add(p); Program._dbContext.SaveChanges(); //MessageBox.Show(J.NumOfReservedChairs.ToString()); J.NumOfReservedChairs += int.Parse(textBox5.Text); //MessageBox.Show(J.NumOfReservedChairs.ToString()); R.PassengerID = p.ID; Program._dbContext.Reserves.Add(R); Program._dbContext.SaveChanges(); MessageBox.Show("Booked Done"); #region Send e-mail To Passenger on his Mail try { MailMessage msg = new MailMessage(); msg.From = new MailAddress("*****@*****.**"); msg.To.Add(txt_email.Text); msg.Subject = "Tourism App Team"; msg.Body = $"Dear {p.Name},\nThis Mail confirms that you have just booked {R.NumOfTickets} Tickets " + $"In our Journey \"{J.Title}\" with ResrvationID: {R.ID} at " + $"{DateTime.Now.ToShortDateString().ToString()}\nHope for You a nice Journey,\nTourism App Team,\nRegards.\n" + $"\n\nNote: The Reservation ID you need to keep it if you need to update your number of Tickets"; msg.Attachments.Add(new Attachment("../../Resources/ticket.jpg")); SmtpClient smt = new SmtpClient(); smt.Host = "smtp.gmail.com"; System.Net.NetworkCredential ntcd = new NetworkCredential(); smt.UseDefaultCredentials = false; ntcd.UserName = "******"; ntcd.Password = "******"; smt.Credentials = ntcd; smt.EnableSsl = true; smt.Port = 587; smt.Send(msg); MessageBox.Show("Your Mail is sended"); } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion EmployeeForm empForm = new EmployeeForm(); empForm.Show(); this.Hide(); } }
private void button4_Click(object sender, EventArgs e) { //Journary Added Program._dbContext = new Data_Context(); Database.SetInitializer <Data_Context>(new MigrateDatabaseToLatestVersion <Data_Context, Migrations.Configuration>()); string Title = textBox11.Text.ToString(); string Descrption = textBox12.Text.ToString(); int Maxnumber; if (int.TryParse(textBox13.Text, out Maxnumber)) { lbl_maxNumber.Visible = false; } else { lbl_maxNumber.Visible = true; } string Travelway = cmb_TravelWay.SelectedItem.ToString(); Type travel = Type.Bus; if (Travelway.ToLower() == "plane") { travel = Type.Plane; } //string Travalway = textBox14.Text.ToString(); //Type gender = Gender.female; //if (Gendertxt.ToLower() == "male") //{ // gender = Gender.male; //} int tickectcost; if (int.TryParse(textBox15.Text, out tickectcost)) { lbl_TicketCost.Visible = false; } else { lbl_TicketCost.Visible = true; } int NDay; if (int.TryParse(textBox16.Text, out NDay)) { lbl_numOfDays.Visible = false; } else { lbl_numOfDays.Visible = true; } string Location = textBox17.Text.ToString(); DateTime dtime = /*DateTime.Parse(dateTimePicker1.Text.ToString())*/ dateTimePicker1.Value; if (dtime > DateTime.Now) { lbl_Date.Visible = false; } else { lbl_Date.Visible = true; } int numchair = 0; if (!lbl_maxNumber.Visible && !lbl_TicketCost.Visible && !lbl_numOfDays.Visible && !lbl_Date.Visible) { Journey Jour = new Journey() { Title = Title, Description = Descrption, MaxNumber = Maxnumber, TravelWay = travel, TicketCost = tickectcost, NumOfDays = NDay, Location = Location, Date = dtime, NumOfReservedChairs = numchair }; Program._dbContext.Journeys.Add(Jour); Program._dbContext.SaveChanges(); //show message MessageBox.Show("Added Success "); //Clear Text textBox11.Text = ""; textBox12.Text = ""; textBox13.Text = ""; //textBox14.Text = ""; cmb_TravelWay.SelectedItem = ""; textBox15.Text = ""; textBox16.Text = ""; textBox17.Text = ""; dateTimePicker1.Text = ""; // clear datagridview and refresh dataGridView2.Rows.Clear(); dataGridView2.Refresh(); //read all Data var Jo = (from s in Program._dbContext.Journeys select s).ToList(); foreach (var item in Jo) { dataGridView2.Rows.Add(new String[] { item.ID.ToString(), item.Title, item.Description, item.MaxNumber.ToString(), item.TravelWay.ToString(), item.TicketCost.ToString(), item.NumOfDays.ToString(), item.Location, item.Date.ToString(), item.NumOfReservedChairs.ToString() }); } } else { MessageBox.Show("Please Check the errors before adding"); } }