/// <summary> /// Méthode qui permet d'afficher la LC sélectionnée /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonAfficher_Click(object sender, EventArgs e) { if (comboClient.SelectedIndex < 0 || comboLC.SelectedIndex < 0) { return; } Cursor.Current = Cursors.WaitCursor; if (radioButtonArchive.Checked) { PopUp_AfficherPDF afficherPDF = new PopUp_AfficherPDF(); afficherPDF.Initialiser(Program.FINACOOPFolder + lcVisible.chemin_lc); afficherPDF.Show(); } else { PopUp_Patienter waitForm = new PopUp_Patienter(); try { // MessageBox.Show(Program.FINACOOPFolder + lcVisible.chemin_lc); AfficherLC(Program.FINACOOPFolder + lcVisible.chemin_lc); } catch (Exception) { MessageBox.Show("Le fichier est introuvable. Il a peut-être été supprimé" + " ou déplacé."); WordTools.CloseWord(); } Cursor.Current = Cursors.Default; waitForm.Close(); } }
/// <summary> /// Méthode qui permet de valider l'envoir /// au clients /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonEnvoyer_Click(object sender, System.EventArgs e) { Cursor.Current = Cursors.WaitCursor; PopUp_Patienter waitForm = new PopUp_Patienter(); waitForm.Show(); for (int i = 0; i < dataGridView.Rows.Count; i++) { DataGridViewCheckBoxCell chkchecking = dataGridView.Rows[i].Cells[5] as DataGridViewCheckBoxCell; if (chkchecking.Value != null && (bool)chkchecking.Value) { try { CopyLc(listLc[i]); CreatePDF(listLc[i]); } catch (Exception) { MessageBox.Show("Le fichier est introuvable. Il a peut-être été supprimé" + " ou déplacé."); } try { SendMailClient(listLc[i], this.textBoxPass.Text); }catch (Exception) { MessageBox.Show("Une erreur est survenue, l'Email n'a pas était envoyé. Merci de vérifier votre connexion internet et que le port SMTP 587 soit bien ouvert."); } if (envoieMail) { ChangeEtat(listLc[i]); modelManager.UpdatePathLc(listLc[i], Properties.Settings.Default.PathEnvoyer + modelManager.FindClient(listLc[i].id_client).raison_sociale + "\\" + listLc[i].nom_lc); } } } Init(); Cursor.Current = Cursors.Default; waitForm.Close(); }
/// <summary> /// Méthode qui permet de gérer la signature /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonSigner_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; string pass = EncryptePass(textBoxPass.Text); if (!pass.Equals(Page_Principale.Utilisateur.mdp_utilisateur)) { Cursor.Current = Cursors.Default; MessageBox.Show("Votre mot de passe est incorrect"); return; } if (Page_Principale.Utilisateur.image_Blob_Signature == null) { Cursor.Current = Cursors.Default; MessageBox.Show("Vous ne disposez pas de signature dans la base. Veuillez contacter l'Administrateur."); return; } PopUp_Patienter waitForm = new PopUp_Patienter(); waitForm.Show(); for (int i = 0; i < LCDataGridView.RowCount; ++i) { DataGridViewCheckBoxCell chkchecking = LCDataGridView.Rows[i].Cells[4] as DataGridViewCheckBoxCell; //MessageBox.Show(chkchecking.Value.ToString()); if (chkchecking.Value != null && (bool)chkchecking.Value) { var app = new Microsoft.Office.Interop.Word.Application(); try { //ouverture du document // MessageBox.Show(Program.FINACOOPFolder + listLc[i].chemin_lc); if (listLc[i].id_etat.ToString().Equals(modelManager.GetIdEtatRefuser().ToString())) { if (listLc[i].id_signataire != Page_Principale.Utilisateur.id_utilisateur) { Utilisateur signataireOrigine = modelManager.GetUser(listLc[i].id_signataire); MessageBox.Show("Seul le signataire original de cette LC (" + signataireOrigine.nom_utilisateur + " " + signataireOrigine.prenom_utilisateur + ") ou l'administrateur peut la revalider"); } else { modelManager.ChangerEtatLC_Signer(listLc[i].id_lc); AfficherLC(Program.FINACOOPFolder + listLc[i].chemin_lc); MessageBox.Show("Votre fichier a été revalidé"); } } else { var doc = app.Documents.Add( Program.FINACOOPFolder + listLc[i].chemin_lc, Visible: false); doc.Activate(); //récuperation du mot à remplacer //************************************************ var motcle = "signature"; // MessageBox.Show("Remplacement du mot: " + motcle + " ..."); var sel = app.Selection; sel.Find.Text = string.Format("[" + motcle + "]"); sel.Find.Execute(Replace: WdReplace.wdReplaceNone); sel.Range.Select(); //Insertion de l'image // var imgPath = Path.GetFullPath(string.Format(file2)); System.Drawing.Image imgPath = ByteArrayToImage(Page_Principale.Utilisateur.image_Blob_Signature); imgPath.Save(Program.FINACOOPFolder + @"\signature.png"); sel.InlineShapes.AddPicture( FileName: Program.FINACOOPFolder + @"\signature.png", LinkToFile: false, SaveWithDocument: true); File.Delete(Program.FINACOOPFolder + @"\signature.png"); //************************************************ //sauvegarde du doc. modelManager.ChangerEtatLC_Signer(listLc[i].id_lc); modelManager.AjoutSignataire(listLc[i], Page_Principale.Utilisateur); doc.SaveAs(Program.FINACOOPFolder + listLc[i].chemin_lc); doc.Close(); AjoutNomSignataire(Program.FINACOOPFolder + listLc[i].chemin_lc); AfficherLC(Program.FINACOOPFolder + listLc[i].chemin_lc); MessageBox.Show("Votre fichier a bien été signé"); } } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.Message); } } } Init(); Cursor.Current = Cursors.Default; waitForm.Close(); }
private void BoutonGenerer_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (FichierValoHonoraires.Text.Length == 0) { MessageBox.Show("Merci de choisir un fichier d'honoraires"); Cursor.Current = Cursors.Default; return; } PopUp_Patienter waitForm = new PopUp_Patienter(); waitForm.Show(); string raisonSociale = ListeDeroulanteChoixClient.SelectedItem.ToString(); String nomFichier = DateTime.Today.ToString("dd_MM_yyyy") + "_" + ListeDeroulanteChoixClient.SelectedItem.ToString() + "_" + "FINACOOP_" + textBoxMission.Text + ".docx"; Client client = new Client(); client = clients[ListeDeroulanteChoixClient.SelectedIndex]; Dictionary <string, string> donnees = new Dictionary <string, string>() { { "RaisonSociale", client.raison_sociale ?? " " }, { "FormeJuridique", "( " + client.forme_juridique + " )" ?? "( )" }, { "Adresse", String.Format("{0} {1}", client.Adresse.numero ?? " ", client.Adresse.voie ?? " ") }, { "CP", client.Adresse.code_postal ?? " " }, { "Ville", client.Adresse.ville ?? " " }, { "Activite", client.activite ?? " " }, // { "ExerciceSocial", ((DateTime) client.exercice_debut).ToString("yyyy_MM_dd")??" " + // " - " + ((DateTime) client.exercice_fin).ToString("yyyy_MM_dd")??" " }, { "DateCourante", DateTime.Today.ToShortDateString() ?? " " }, //{ "Millesime", DateTime.Today.Year.ToString()??" " }, { "Prenom", client.prenom_referent ?? " " }, { "Nom", client.nom_referent ?? " " }, { "Fonction", client.fonction_referent ?? " " }, { "Civilite", (client.sexe_referent == "M" ? "Monsieur" : "Madame") ?? " " }, { "CherGenre", (client.sexe_referent == "M" ? "Cher" : "Chère") ?? " " }, { "CA", client.CA.ToString() ?? " " }, { "Effectif", client.effectifs.ToString() ?? " " }, { "OrganisationComptable", client.organisation_comptable ?? " " }, { "VolumesAnnuels", client.volume_annuel.ToString() ?? " " }, { "DateImmatriculation", client.date_immatriculation.ToString() ?? " " }, { "LieuImmatriculation", client.lieu_immatriculation ?? " " }, { "Millesime", dateTimeExercice_debut.Value.ToString("dd/MM/yyyy") + " - " + dateTimeExercice_fin.Value.ToString("dd/MM/yyyy") }, { "ExerciceSocial", dateTimeExercice_debut.Value.ToString("dd/MM/yyyy") + " - " + dateTimeExercice_fin.Value.ToString("dd/MM/yyyy") } }; try { using (var stream = File.Open(FichierValoHonoraires.Text, FileMode.Open, FileAccess.Read)) { using (var reader = ExcelReaderFactory.CreateReader(stream)) { var result = reader.AsDataSet(); var spreadsheet = result.Tables[2]; for (int i = 0; i < spreadsheet.Rows.Count; i++) { for (int j = 0; j < spreadsheet.Columns.Count; j++) { if ((spreadsheet.Rows[i][j].ToString()).Contains("{{")) { String chaine = spreadsheet.Rows[i][j].ToString(); String[] cutChaine = chaine.Split(new[] { "{{", "}}" }, StringSplitOptions.RemoveEmptyEntries); chaine = cutChaine[0]; donnees.Add(chaine, spreadsheet.Rows[i - 1][j].ToString()); } } } } } } catch (Exception er) { MessageBox.Show("Erreur de chargement. Merci de vérifier que vous avez renseigné le bon fichier FINACOOP"); Cursor.Current = Cursors.Default; MessageBox.Show(er.StackTrace); } try { using (DocX documentModele = DocX.Load(Program.FINACOOPFolder + modeles[comboBoxModel.SelectedIndex].chemin_modele)) { foreach (var item in donnees) { documentModele.ReplaceText("{{" + item.Key + "}}", item.Value); } string pathFolder = Program.FINACOOPFolder + Properties.Settings.Default.PathRealiser + client.raison_sociale; if (!Directory.Exists(pathFolder)) { Directory.CreateDirectory(pathFolder); File.SetAttributes(pathFolder, FileAttributes.Normal); } LC lc = new LC { chemin_lc = Properties.Settings.Default.PathRealiser + client.raison_sociale + @"\" + nomFichier, date_debut = DateTime.Today, id_client = client.id_client, id_modele = modeles[comboBoxModel.SelectedIndex].id_modele, nom_lc = nomFichier, id_etat = modeleManager.GetEtatByLibelle("C"), id_utilisateur = Page_Principale.Utilisateur.id_utilisateur, millesime = dateTimeExercice_debut.Value.ToString("dd_MM_yyyy") + " - " + dateTimeExercice_fin.Value.ToString("dd_MM_yyyy"), date_lc = DateTime.Now // lc.exercice_debut = dateTimeExercice_debut.Value; // lc.exercice_fin = dateTimeExercice_fin.Value; }; if (File.Exists(pathFolder + @"\" + nomFichier)) { string message = "Cette LC existe déjà, voulez-vous l'écraser ?"; string caption = "Lettre de coopération existante"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(message, caption, buttons); if (result == DialogResult.No) { waitForm.Close(); Cursor.Current = Cursors.Default; return; } } File.Delete(pathFolder + @"\" + nomFichier); documentModele.SaveAs(pathFolder + @"\" + nomFichier); File.Delete(pathFolder + @"\" + nomFichier.Replace(".docx", ".xlsx")); File.Copy(FichierValoHonoraires.Text, pathFolder + @"\" + nomFichier.Replace(".docx", ".xlsx")); AfficherLC(pathFolder + @"\" + nomFichier); SaveLC(lc); waitForm.Close(); MessageBox.Show("La lettre de coopération a été générée dans le fichier " + pathFolder + @"\" + nomFichier + ".\nAssurez-vous que la lettre de coopération générée ne contient pas d'erreurs, modifiez-la si nécessaire.", "Lettre de coopération générée", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception er) { MessageBox.Show("Erreur de chargement. Merci de vérifier que vous avez renseigné le bon fichier FINACOOP"); MessageBox.Show(er.StackTrace); Cursor.Current = Cursors.Default; waitForm.Close(); } }