//Updates databse with fields private void save_Click(object sender, EventArgs e) { //Check if all fields has data if (jobClientEmailBox.Text != "" && jobContractorEmailBox.Text != "" && jobDescriptionBox.Text != "" && jobDateBox.Text != "" && JobLocationBox.Text != "") { //Checks for valid email bool contractorEmailVal = EmailValidator(jobContractorEmailBox.Text); bool clientEmailVal = EmailValidator(jobClientEmailBox.Text); if (contractorEmailVal == false || clientEmailVal == false) { MessageBox.Show("Please enter Valid Emails"); } else { //Creates w new job Client clientTable = new Client(); Contractor contractorTable = new Contractor(); DateTime jobDateTime = new DateTime(jobDateBox.Value.Year, jobDateBox.Value.Month, jobDateBox.Value.Day, jobTimeBox.Value.Hour, jobTimeBox.Value.Minute, jobTimeBox.Value.Second); Job jobTable = new Job(); //checks if entered email is in the database if (clientTable.GetClient(jobClientEmailBox.Text) == null || contractorTable.GetContractor(jobContractorEmailBox.Text) == null) { //Tried to add a job to a null employee or client MessageBox.Show("Email/'s not in database, please check spelling and try again"); } else { jobTable.AddJob(clientTable.GetClient(jobClientEmailBox.Text).ID, contractorTable.GetContractor(jobContractorEmailBox.Text).ID, jobDescriptionBox.Text, JobLocationBox.Text, jobDateTime, jobPriorityCbx.Checked); MessageBox.Show("Saved Successfully"); } } } else { MessageBox.Show("Please Complete all fields"); } }
//Create a new Contractor public void AddContractor(String name, String address, String landLine, String mobile, String employeeID, String email) { // Open database (or create if not exits) using (var db = new LiteDatabase(@"IQIncorporated.db")) { // Get contractors collection var contractors = db.GetCollection <Contractor>("contractors"); // Create new contractor instance var contractor = new Contractor { Name = name, Address = address, LandLine = landLine, Mobile = mobile, EmployeeID = employeeID, Email = email }; // Insert new customer document (Id will be auto-incremented) contractors.Insert(contractor); } }