private void ucAgendaOpdracht_Load(object sender, EventArgs e) { if (miniopdracht.klant != null) { txtKlantNaam.Text = miniopdracht.klant.naam; } //txtAankomst.Text = miniopdracht.opdracht_id_full.ToString(); if (rit.rit1_vertrek != null) { txtVertrek.Text = rit.rit1_vertrek; } txtVertrek2.Text = rit.rit2_vertrek; if (rit.rit1_terug != null) { txtAankomst.Text = rit.rit1_terug; } txtAankomst2.Text = rit.rit2_terug; lblInfo.Text = opdracht.contract_id_full; cbbChauffeur.DataSource = OpdrachtManagement.getChauffeurs(); cbbChauffeur.ValueMember = "chauffeur_id"; cbbChauffeur.DisplayMember = "naam"; cbbChauffeur.SelectedIndex = -1; cbbSecChauff.DataSource = OpdrachtManagement.getChauffeurs(); cbbSecChauff.ValueMember = "chauffeur_id"; cbbSecChauff.DisplayMember = "naam"; cbbSecChauff.SelectedIndex = -1; cbbChauffeur.Enabled = true; cbbVoertuig.DataSource = OpdrachtManagement.getVoertuigen(); cbbVoertuig.ValueMember = "voertuig_id"; cbbVoertuig.DisplayMember = "nummerplaat"; cbbBusId.DataSource = OpdrachtManagement.getVoertuigenVanOpdracht(miniopdracht); cbbBusId.ValueMember = "voertuig_id"; cbbBusId.DisplayMember = "voertuig_id"; try { cbbVoertuig.SelectedValue = OpdrachtManagement.getVoertuigenVanOpdracht(miniopdracht).First().voertuig_id; cbbChauffeur.SelectedValue = OpdrachtManagement.getFirstChauffeurVanOpdracht(miniopdracht).First().chauffeur_id; if (OpdrachtManagement.getSecondChauffeurVanOpdracht(miniopdracht).SingleOrDefault() != null) { cbbSecChauff.SelectedValue = OpdrachtManagement.getSecondChauffeurVanOpdracht(miniopdracht).First().chauffeur_id; } else { cbbSecChauff.SelectedValue = OpdrachtManagement.getFirstChauffeurVanOpdracht(miniopdracht).First().chauffeur_id; } } catch { } }
private void ucAgendaOpdracht_Load(object sender, EventArgs e) { if (miniopdracht.klant != null) { txtKlant.Text = miniopdracht.klant.naam; } txtID.Text = miniopdracht.opdracht_id_full.ToString(); if (miniopdracht.vanaf_uur != null) { txtVertrek.Text = miniopdracht.vanaf_uur.ToString(); } if (miniopdracht.tot_uur != null) { txtTerug.Text = miniopdracht.tot_uur.ToString(); } cbbChauffeur.DataSource = OpdrachtManagement.getChauffeursVanOpdracht(miniopdracht); cbbChauffeur.ValueMember = "chauffeur_id"; cbbChauffeur.DisplayMember = "naam"; cbbVoertuig.DataSource = OpdrachtManagement.getVoertuigenVanOpdracht(miniopdracht); cbbVoertuig.ValueMember = "voertuig_id"; cbbVoertuig.DisplayMember = "nummerplaat"; }
//EditTim: Printen van alle ritten van de gekozen chauffeur op de gekozen datum private void button1_Click(object sender, EventArgs e) { DateTime date = dateTimePicker1.Value.Date; //alle informatie van contracten ophalen IEnumerable <rit_instantie> ritten = ContractManagement.getRitten(date); foreach (rit_instantie ri in ritten) { opdracht od = ContractManagement.getContract(ri.contract_rit); if (date.ToString("dddd", new CultureInfo("en-US")) == (ri.contract_rit.dag)) { var idfull = od.contract_id_full; var ritnummer = od.ritomschrijving; var rit1vertr = ri.contract_rit.rit1_vertrek; var rit2vertr = ri.contract_rit.rit2_vertrek; var rit1terug = ri.contract_rit.rit1_terug; var rit2terug = ri.contract_rit.rit2_terug; if (ContractManagement.hasRitInfo(ri)) { rit_info info = ContractManagement.getRitInfo(ri); chauffeurnaam = info.chauffeur.naam; voertuignaam1 = info.voertuig.identificatie; voertuignaam2 = info.voertuig1.identificatie; } var vertrek = OpdrachtManagement.getVertrek(od.opdracht_id); var bestemming = OpdrachtManagement.getBestemming(od.opdracht_id); if (chauffeurnaam.ToString() == cbxChauffeurs.SelectedItem.ToString()) { //missing oject to use with various word commands object missing = System.Reflection.Missing.Value; //the template file you will be using object fileToOpen = (object)@"R:\CarGo\ritblad_chauffeur_CONTRACT.docx"; //object fileToOpen = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritblad_template.docx"; //Where the new file will be saved to. object fileToSave = (object)@"R:\CarGo\printouts\ritblad_chauffeur_CONTRACT" + "" + DateTime.Now.Second + DateTime.Now.Millisecond + ".docx"; //object fileToSave = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritbladen\ritblad_" + opdracht.opdracht_id_full + "_" + OpdrachtManagement.getChauffeursVanOpdracht(opdracht).First().naam + ".docx"; //Create new instance of word and create a new document Word.Application wordApp = new Word.Application(); Word.Document doc = null; //MessageBox.Show(System.IO.Path.GetTempPath(), "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //Properties for the new word document object readOnly = false; object isVisible = false; //Settings the application to invisible, so the user doesn't notice that anything is going on wordApp.Visible = false; //Open and activate the chosen template doc = wordApp.Documents.Open(ref fileToOpen, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); try { File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true); } catch { MainForm.updateStatus = "Kan nieuw document niet opslaan"; return; } //Search for bookmarks and replace them with the text you want PrintManagement.findAndReplace(doc, "Datum", date.ToString("dddd dd MMMM yyyy")); PrintManagement.findAndReplace(doc, "Van1", rit1vertr); PrintManagement.findAndReplace(doc, "Tot1", rit1terug); PrintManagement.findAndReplace(doc, "Van2", rit2vertr); PrintManagement.findAndReplace(doc, "Tot2", rit2terug); PrintManagement.findAndReplace(doc, "Naam", chauffeurnaam); PrintManagement.findAndReplace(doc, "Ritnummer1", ritnummer); PrintManagement.findAndReplace(doc, "Ritnummer", ritnummer); PrintManagement.findAndReplace(doc, "Bestemming1", vertrek.FullAdress); PrintManagement.findAndReplace(doc, "Bestemming2", vertrek.FullAdress); PrintManagement.findAndReplace(doc, "Vertrekplaats1", bestemming.FullAdress); PrintManagement.findAndReplace(doc, "Vertrekplaats2", bestemming.FullAdress); PrintManagement.findAndReplace(doc, "Voertuignummer1", voertuignaam1); PrintManagement.findAndReplace(doc, "Voertuignummer2", voertuignaam2); //doc = wordApp.Documents.Open(fileToSave, ReadOnly: false, Visible: true); doc.Save(); doc.Activate(); //Making word visible to be able to show the print preview. wordApp.Visible = true; } } } foreach (opdracht o in OpdrachtManagement.getOpdrachten(date)) { rit_info info = ContractManagement.getRitInfo(null); int counter = 0; chauffeur firstChauff = null; chauffeur secChauff = null; var idfull = o.contract_id_full; var ritnummer = o.ritomschrijving; var rit1vertr = o.vanaf_uur; var rit1terug = o.tot_uur; foreach (opdracht_chauffeur cha in OpdrachtManagement.getChauffeursVanOpdract(o)) { if (counter == 0) { firstChauff = cha.chauffeur; } else if (counter == 1) { secChauff = cha.chauffeur; } counter++; } var vertrek = OpdrachtManagement.getVertrek(o.opdracht_id); var bestemming = OpdrachtManagement.getBestemming(o.opdracht_id); IEnumerable <opdracht_voertuig> voertuigen = OpdrachtManagement.getVoertuigenVanOpdracht(o); var voertuignaam3 = voertuigen.First().voertuig.identificatie; if (firstChauff.naam.ToString() == cbxChauffeurs.SelectedItem.ToString()) { //missing oject to use with various word commands object missing = System.Reflection.Missing.Value; //the template file you will be using object fileToOpen = (object)@"R:\CarGo\ritblad_chauffeur_CONTRACT.docx"; //object fileToOpen = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritblad_template.docx"; //Where the new file will be saved to. object fileToSave = (object)@"R:\CarGo\printouts\ritblad_chauffeur_CONTRACT" + "" + DateTime.Now.Second + DateTime.Now.Millisecond + ".docx"; //object fileToSave = (object)@"\\172.16.10.2\Users\jeroen\CarGo\ritbladen\ritblad_" + opdracht.opdracht_id_full + "_" + OpdrachtManagement.getChauffeursVanOpdracht(opdracht).First().naam + ".docx"; //Create new instance of word and create a new document Word.Application wordApp = new Word.Application(); Word.Document doc = null; //MessageBox.Show(System.IO.Path.GetTempPath(), "Error Title", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); //Properties for the new word document object readOnly = false; object isVisible = false; //Settings the application to invisible, so the user doesn't notice that anything is going on wordApp.Visible = false; //Open and activate the chosen template doc = wordApp.Documents.Open(ref fileToOpen, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); try { File.Copy(fileToOpen.ToString(), fileToSave.ToString(), true); } catch { MainForm.updateStatus = "Kan nieuw document niet opslaan"; return; } //Search for bookmarks and replace them with the text you want PrintManagement.findAndReplace(doc, "Datum", date.ToString("dddd dd MMMM yyyy")); PrintManagement.findAndReplace(doc, "Van1", rit1vertr); PrintManagement.findAndReplace(doc, "Tot1", rit1terug); PrintManagement.findAndReplace(doc, "Van2", ""); PrintManagement.findAndReplace(doc, "Tot2", ""); PrintManagement.findAndReplace(doc, "Naam", firstChauff.naam.ToString()); PrintManagement.findAndReplace(doc, "Ritnummer1", ritnummer); PrintManagement.findAndReplace(doc, "Ritnummer", ""); PrintManagement.findAndReplace(doc, "Bestemming1", vertrek.FullAdress); PrintManagement.findAndReplace(doc, "Bestemming2", ""); PrintManagement.findAndReplace(doc, "Vertrekplaats1", bestemming.FullAdress); PrintManagement.findAndReplace(doc, "Vertrekplaats2", ""); PrintManagement.findAndReplace(doc, "Voertuignummer1", voertuignaam3); PrintManagement.findAndReplace(doc, "Voertuignummer2", ""); //doc = wordApp.Documents.Open(fileToSave, ReadOnly: false, Visible: true); doc.Save(); doc.Activate(); //Making word visible to be able to show the print preview. wordApp.Visible = true; } } }