private void btnHome_Click(object sender, RoutedEventArgs e) { Technician_Dispatch dispatch = new Technician_Dispatch(); dispatch.Show(); this.Close(); }
private void btnSaveFault_Click(object sender, RoutedEventArgs e) { int staffID = Convert.ToInt32(txtStaffID.Text); int staffMachineID = Convert.ToInt32(txtMachineID.Text); int techID = Convert.ToInt32(txtTechID.Text); int zone = Convert.ToInt32(cmbZone.Text); string comments = txtComments.Text; string status = "Waiting"; DateTime date = DateTime.Now; string insertNewJob = "INSERT INTO jobs (reportingStaffID, reportingMachineID, assignedTechnicianID, zoneNo, date_time, status, comments) VALUES (@staffID, @staffMachineID, @techID, @zone, @dateTime, @status, @comments)"; var cmd = database2.dataConnection(insertNewJob); cmd.Parameters.Add("@staffID", OleDbType.Integer).Value = staffID; cmd.Parameters.Add("@staffMachineID", OleDbType.Integer).Value = staffMachineID; cmd.Parameters.Add("@techID", OleDbType.Integer).Value = techID; cmd.Parameters.Add("@zone", OleDbType.Integer).Value = zone; cmd.Parameters.Add("@dateTime", OleDbType.Date).Value = date; cmd.Parameters.Add("@status", OleDbType.VarChar).Value = status; cmd.Parameters.Add("@comments", OleDbType.VarChar).Value = comments; var data = database2.parameters(); try { MessageBoxResult result = MessageBox.Show("Are you sure you wish to add this job?", "Fault report", MessageBoxButton.YesNo, MessageBoxImage.Warning); switch (result) { case MessageBoxResult.Yes: MessageBox.Show("Job seccessfuly added!", "Fault report", MessageBoxButton.OK, MessageBoxImage.Information); string newRecord = "Added new user reported job: " + staffID + "," + staffMachineID + "," + techID + "," + zone + "," + date + "," + status + "," + comments + "<br>"; using (StreamWriter writer = new StreamWriter(@"..\..\..\log.txt", true)) { writer.WriteLine(newRecord); } Technician_Dispatch dispatch = new Technician_Dispatch(); dispatch.Show(); this.Close(); break; case MessageBoxResult.No: break; } } catch { MessageBox.Show("Ooops. Something went wrong!", "Fault report", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void userLogin() { string username = txtUsername.Text; string password = txtPassword.Password; if (username != "" && password != "") { var enteredPassword = encrypt.sha256_hash(password);//encrypt entered password try { string sql = "SELECT username, password, jobTitle FROM users WHERE username= @username AND password= @password"; var cmd = database.dataConnection(sql); cmd.Parameters.Add("@username", OleDbType.VarChar).Value = username; cmd.Parameters.Add("@password", OleDbType.VarChar).Value = enteredPassword; var data = database.parameters(); var userUsername = data.Tables[0].Rows[0]["username"].ToString(); var userPassword = data.Tables[0].Rows[0]["password"].ToString(); var jobTitle = data.Tables[0].Rows[0]["jobTitle"].ToString(); if (username == userUsername && enteredPassword == userPassword && jobTitle == "dispatch manager")//if username, password and job title are correct { Application.Current.Properties["sessionUsername"] = userUsername; Technician_Dispatch dispatch = new Technician_Dispatch(); dispatch.Show(); this.Close(); checkJobs checkJobStatus = new checkJobs();//get the number of waiting and unresolved jobs Array jobs = checkJobStatus.checkPendingJobs(); int waiting = Convert.ToInt32(jobs.GetValue(0)); int unresolved = Convert.ToInt32(jobs.GetValue(1)); if (waiting != 0 || unresolved != 0) { MessageBox.Show("Attention! It appears that there are a few uncompleted jobs!" + "\n" + "\nWaiting: " + waiting + "\nUnresolved: " + unresolved, "Job status", MessageBoxButton.OK, MessageBoxImage.Warning); } } else if (jobTitle != "dispatch manager") { MessageBox.Show("Only dispatch managers are authorized to use this application!", "Login", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show("Failed to LogIn!", "Login", MessageBoxButton.OK, MessageBoxImage.Error); } } catch { MessageBox.Show("Wrong username/password. Please try again!", "Login", MessageBoxButton.OK, MessageBoxImage.Error); txtPassword.Password = ""; } } else { txtUsername.BorderBrush = Brushes.Red;//paint the textbox boarder red if one of the fields is not entered txtPassword.BorderBrush = Brushes.Red; MessageBox.Show("Username and Password required!", "Login", MessageBoxButton.OK, MessageBoxImage.Information); } }