private void button1_Click(object sender, EventArgs e) { if (numberPlateInput.Text.Trim().Equals("") || categoryInput.Text.Trim().Equals("") || passengerPermitInput.Text.Trim().Equals("") || mileageInput.Text.Trim().Equals("") || remarksInput.Text.Trim().Equals("")) { MessageBox.Show("Input should not be empty!"); return; } changeMileage(int.Parse(mileageInput.Text)); this.Hide(); AdminForm admin = new AdminForm(); admin.ShowDialog(); }
private void searchButton_Click(object sender, EventArgs e) { string date = datepicker.Value.ToString("dd/MM/yyyy"); //connection to database string Conn = "datasource=localhost;port=3306;username=root;password=;database=sbc;sslMode=none"; //Retrieve records from database MySqlConnection MyConn = new MySqlConnection(Conn); try { MyConn.Open(); MySqlDataReader MyReader; string Query = "SELECT NumberPlate, Category, Specification, busowner.name FROM bus" + " JOIN busowner ON bus.OwnerIC = busowner.IC" + " WHERE NumberPlate NOT IN(SELECT BusNumberPlate FROM drivershift WHERE Date = '" + date + "')" + " AND bus.status = 'Available'" + " ORDER BY FIELD(name, 'SBC') DESC;"; MySqlCommand cmd = new MySqlCommand(Query, MyConn); MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = cmd; DataTable dTable = new DataTable(); MyAdapter.Fill(dTable); tableResult.DataSource = dTable; MyConn.Close(); //if no records are found, redirect back to mainpage if (dTable.Rows.Count < 1) { MessageBox.Show("No Buses are available for this day!"); checkBusExists = false; return; } else { checkBusExists = true; } //check if sbc exists if (!checkSBC_Exists(dTable)) { DialogResult dr = MessageBox.Show("Internal SBC bookings are not available, do you want to outsource to external provider?", "No SBC Buses Found", MessageBoxButtons.YesNo); switch (dr) { case DialogResult.Yes: Booking emptyBooking = new Booking(datepicker.Value.ToString("dd/MM/yyyy")); this.Hide(); createBookings3 book3 = new createBookings3(customer, emptyBooking); book3.ShowDialog(); /*MessageBox.Show("Yes");*/ break; case DialogResult.No: MessageBox.Show("No"); this.Hide(); AdminForm adminPage = new AdminForm(); adminPage.ShowDialog(); break; } } } catch (Exception err) { MessageBox.Show(err.Message); } }
private void button1_Click(object sender, EventArgs e) { String empId = usernameInput.Text; String userPwd = passwordInput.Text; String computedHash; if (empId.Trim() == "" || userPwd.Trim() == "") { MessageBox.Show("Username or Password field should not be blank!"); } //Perform hashing for password using (var md5Hash = MD5.Create()) { // Byte array representation of source string var sourceBytes = Encoding.UTF8.GetBytes(userPwd); // Generate hash value(Byte Array) for input data var hashBytes = md5Hash.ComputeHash(sourceBytes); // Convert hash byte array to string computedHash = BitConverter.ToString(hashBytes).Replace("-", string.Empty);; } try { //Connection to database string Conn = "datasource=localhost; port=3306;username=root;password=;database=sbc; sslMode=none"; string Query = "SELECT * FROM admin WHERE EmpID ='" + empId + "';"; MySqlConnection MyConn = new MySqlConnection(Conn); MySqlCommand MyComd = new MySqlCommand(Query, MyConn); MySqlDataReader MyReader; MyConn.Open(); MyReader = MyComd.ExecuteReader(); if (MyReader.Read()) { string dbEmpId = MyReader.GetString("EmpID"); string dbName = MyReader.GetString("Name"); Boolean dbMaster = MyReader.GetBoolean("Master"); Program.admin = new Admin(dbEmpId, dbName, dbMaster); string hash = MyReader.GetString("hash"); if (computedHash.ToLower() == hash.ToLower()) { //login successful this.Hide(); AdminForm adminForm = new AdminForm(); PermitExpiryReminder(); adminForm.ShowDialog(); } else { //show error message box MessageBox.Show("Password incorrect"); } } //check permit validity }catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { string bookingID = ""; name = nameInput.Text; phone = phoneInput.Text; destination = destinationInput.Text; origin = originInput.Text; passengers = passengerInput.Text; shuttleType = shuttleTypeInput.Text; remarks = remarksInput.Text; date = dateInput.Text; //connect db string Conn = "datasource=localhost;port=3306;username=root;password=;database=sbc;sslMode=none"; //Retrieve records from database MySqlConnection MyConn = new MySqlConnection(Conn); MySqlDataReader MyReader; try { string Query = "SELECT BookingID FROM booking ORDER BY BookingID desc LIMIT 1;"; MySqlCommand MyComd = new MySqlCommand(Query, MyConn); MyConn.Open(); MyReader = MyComd.ExecuteReader(); //if data exists, get latest booking ID and increment by 1 if (MyReader.Read()) { bookingID = MyReader.GetString("BookingID"); string bookingNumber = bookingID.Substring(1); char[] strBooking = bookingNumber.ToCharArray(); int[] intBooking = Array.ConvertAll(strBooking, s => int.Parse(s.ToString())); recursive(intBooking, intBooking.Length - 1); bookingID = "B"; for (int i = 0; i < intBooking.Length; i++) { bookingID += intBooking[i]; } } else { //if no records in booking table bookingID = "B0001"; } MyReader.Close(); if (booking.getAsignedTo().Equals("SBC")) { //sql to create bookings record Query = "INSERT INTO booking VALUES ('" + bookingID + "', '" + phone + "', '" + date + "', '" + origin + "', '" + destination + "', '" + Program.admin.getEmpID() + "', '" + "Booked but not paid" + "', '" + int.Parse(passengers) + "', '" + remarks + "', " + 0 + ");"; //get driverIC string driverIC = DBgetDriverIC(); //insert record into drivershift table Query += "INSERT INTO drivershift VALUES('" + bookingID + "', '" + driverIC + "', '" + date + "', '" + booking.getNumberPlate() + "');"; //write logs Query += "INSERT INTO Log (EmpID, Message) VALUES ('" + Program.admin.getEmpID() + "', 'Assigned a bus & driver to " + bookingID + "');"; MyComd.CommandText = Query; MyComd.ExecuteNonQuery(); MyConn.Close(); } else { //sql to create bookings record but no drivers confirmed Query = "INSERT INTO booking VALUES ('" + bookingID + "', '" + phone + "', '" + date + "', '" + origin + "', '" + destination + "', '" + Program.admin.getEmpID() + "', '" + "Requested" + "', '" + int.Parse(passengers) + "', '" + remarks + "', " + 0 + ");"; MyComd.CommandText = Query; MyComd.ExecuteNonQuery(); //write logs MyReader.Close(); MyComd.CommandText = "INSERT INTO Log (EmpID, Message) VALUES ('" + Program.admin.getEmpID() + "', 'Created request for external" + "provider');"; MyComd.ExecuteNonQuery(); MyConn.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } MessageBox.Show("Booking record is successful!"); AdminForm mainPage = new AdminForm(); this.Hide(); mainPage.ShowDialog(); }