1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;
using System.Collections;
using System.Xml.Xsl;
using System.Diagnostics;
using System.IO;
using System.Drawing;
public void CTRL568_5_Clicked(object sender, ClickedEventArgs e)'code pour retoucher l'image
{
try
{
'verifier image non vide -ok
XPathNavigator nav = e.Source.CreateNavigator();
string s = nav.SelectSingleNode(@"my:champ109", NamespaceManager).Value;
if (s != "")
{
'enregistrer l'image dans un fichier temp: c:\GBV\temp.tom -voir C:\Bureau Bis\Divers\surcharger image
byte[] image = Convert.FromBase64String(s);
MemoryStream memStr = new MemoryStream();
memStr.Write(image, 0, image.Length);
Image img = Image.FromStream(memStr);
img.Save(@"c:\GBV\temp.tom");
'faire un processus qui ouvre temp.tom
'sur le PC mettre paint pour ouvrir les fichier.tom
Process myProcess = new Process();
myProcess.StartInfo.FileName = @"c:\GBV\temp.tom";
myProcess.Start();
'limite de temps pour modifier l'image 2 minutes
bool completed = myProcess.WaitForExit(120000);
if (!completed)
{
' Temps d'attente dépassé : on tue le processus
if (!myProcess.HasExited)
myProcess.Kill();
MessageBox.Show("limite de temps pour modifier l'image depassé (2 minutes)", " ", MessageBoxButtons.OK);
}
else
{
'quant l'utilisateur sort en enregistrant, je reconvertit en base64, puis j'insére l'image dans le formulaire
string resultatBase64 = "";
'convertir temp.tom en base64
string inputFileName = @"c:\GBV\temp.tom";
System.IO.FileStream inFile;
byte[] binaryData;
inFile = new System.IO.FileStream(inputFileName,
System.IO.FileMode.Open,
System.IO.FileAccess.Read);
binaryData = new Byte[inFile.Length];
long bytesRead = inFile.Read(binaryData, 0,
(int)inFile.Length);
inFile.Close();
resultatBase64 = System.Convert.ToBase64String(binaryData,
0,
binaryData.Length);
nav.SelectSingleNode(@"my:champ109", NamespaceManager).SetValue(resultatBase64);
}
}
}
catch { }
} |
Partager