private void btn_Login_Click(object sender, EventArgs e) { Employee obj = (from emp in Program._dbContext.Employees where emp.Email == txt_UserName.Text && emp.Password == txt_Password.Text select emp).FirstOrDefault(); if (obj != null) { lbl_Error.Visible = false; if (obj.IsAdmin) { MessageBox.Show("Hello Admin"); } else { MessageBox.Show("Hello Employee"); EmployeeForm employeeForm = new EmployeeForm(); this.Hide(); employeeForm.Show(); } } else { lbl_Error.Visible = true; } }
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(); } }