1 |
1 |
using System;
|
2 |
2 |
using System.Collections.Generic;
|
|
3 |
using System.IO;
|
3 |
4 |
using System.Linq;
|
4 |
5 |
using System.Net;
|
5 |
6 |
using System.Text;
|
|
7 |
using System.Xml;
|
6 |
8 |
using iTextSharp.text;
|
7 |
9 |
using iTextSharp.text.pdf;
|
8 |
10 |
using KCOMDataModel.DataModel;
|
... | ... | |
16 |
18 |
public static void DrawSign(System.Windows.Point startPoint, System.Windows.Point endPoint, List<System.Windows.Point> pointSet, PdfContentByte contentByte, string UserID, double Angle, double opac, string projectNo)
|
17 |
19 |
{
|
18 |
20 |
contentByte.SaveState();
|
|
21 |
System.Text.StringBuilder url = new System.Text.StringBuilder(512);
|
|
22 |
CommonLib.Common.GetPrivateProfileString("UpLoadServiceUrl", "URL", "", url, 512, Path.Combine(CommonLib.Common.AppDataFolder, "FinalService.ini"));
|
|
23 |
string soapurl = url.ToString();
|
19 |
24 |
|
20 |
|
using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(projectNo).ToString()))
|
|
25 |
if (!string.IsNullOrEmpty(soapurl))
|
21 |
26 |
{
|
22 |
|
var _sign = _entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == UserID);
|
|
27 |
var _ifsign = getEnsembleSign(UserID, soapurl);
|
|
28 |
byte[] imageBytes = System.Convert.FromBase64String(_ifsign);
|
|
29 |
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes))
|
|
30 |
{
|
|
31 |
var midP = MathSet.getMiddlePoint(startPoint, endPoint);
|
|
32 |
List<System.Windows.Point> tempPoint = new List<System.Windows.Point>();
|
|
33 |
foreach (var item in pointSet)
|
|
34 |
{
|
|
35 |
tempPoint.Add(MathSet.RotateAbout(midP, item, Angle));
|
|
36 |
}
|
|
37 |
|
|
38 |
var Rect = GetPointsToRectX(tempPoint);
|
23 |
39 |
|
24 |
|
if (_sign.Count() > 0)
|
|
40 |
Image img = Image.GetInstance(ms);
|
|
41 |
img.ScaleAbsolute(Rect.Width, Rect.Height);
|
|
42 |
|
|
43 |
img.SetAbsolutePosition(Rect.Left + ((Rect.Width - img.ScaledWidth) / 2), Rect.Bottom + ((Rect.Height - img.ScaledHeight) / 2));
|
|
44 |
var x = Rect.Left + ((Rect.Width - img.ScaledWidth) / 2);
|
|
45 |
var y = Rect.Bottom + ((Rect.Height - img.ScaledHeight) / 2);
|
|
46 |
midP = MathSet.getMiddlePoint(new System.Windows.Point(x, y), new System.Windows.Point(x + img.ScaledWidth, y + img.ScaledHeight));
|
|
47 |
System.Drawing.Drawing2D.Matrix mat2 = new System.Drawing.Drawing2D.Matrix();
|
|
48 |
mat2.RotateAt((float)Angle * -1, new System.Drawing.PointF((float)midP.X, (float)midP.Y));
|
|
49 |
contentByte.Transform(mat2);
|
|
50 |
PdfGState gs1 = new PdfGState();
|
|
51 |
gs1.FillOpacity = (float)opac;
|
|
52 |
contentByte.SetGState(gs1);
|
|
53 |
contentByte.AddImage(img);
|
|
54 |
}
|
|
55 |
}
|
|
56 |
else
|
|
57 |
{
|
|
58 |
using (CIEntities _entity = new CIEntities(KCOMDataModel.Common.ConnectStringBuilder.ProjectCIConnectString(projectNo).ToString()))
|
25 |
59 |
{
|
26 |
|
byte[] imageBytes = System.Convert.FromBase64String(_sign.First().SIGN_STR);
|
27 |
|
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes))
|
|
60 |
var _sign = _entity.SIGN_INFO.Where(sin => sin.MEMBER_USER_ID == UserID);
|
|
61 |
|
|
62 |
if (_sign.Count() > 0)
|
28 |
63 |
{
|
29 |
|
var midP = MathSet.getMiddlePoint(startPoint, endPoint);
|
30 |
|
List<System.Windows.Point> tempPoint = new List<System.Windows.Point>();
|
31 |
|
foreach (var item in pointSet)
|
|
64 |
byte[] imageBytes = System.Convert.FromBase64String(_sign.First().SIGN_STR);
|
|
65 |
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(imageBytes))
|
32 |
66 |
{
|
33 |
|
tempPoint.Add(MathSet.RotateAbout(midP, item, Angle));
|
34 |
|
}
|
|
67 |
var midP = MathSet.getMiddlePoint(startPoint, endPoint);
|
|
68 |
List<System.Windows.Point> tempPoint = new List<System.Windows.Point>();
|
|
69 |
foreach (var item in pointSet)
|
|
70 |
{
|
|
71 |
tempPoint.Add(MathSet.RotateAbout(midP, item, Angle));
|
|
72 |
}
|
|
73 |
|
|
74 |
var Rect = GetPointsToRectX(tempPoint);
|
35 |
75 |
|
36 |
|
var Rect = GetPointsToRectX(tempPoint);
|
37 |
|
|
38 |
|
Image img = Image.GetInstance(ms);
|
39 |
|
img.ScaleAbsolute(Rect.Width, Rect.Height);
|
40 |
|
|
41 |
|
img.SetAbsolutePosition(Rect.Left + ((Rect.Width - img.ScaledWidth) / 2), Rect.Bottom + ((Rect.Height - img.ScaledHeight) / 2));
|
42 |
|
var x = Rect.Left + ((Rect.Width - img.ScaledWidth) / 2);
|
43 |
|
var y = Rect.Bottom + ((Rect.Height - img.ScaledHeight) / 2);
|
44 |
|
midP = MathSet.getMiddlePoint(new System.Windows.Point(x, y), new System.Windows.Point(x + img.ScaledWidth, y + img.ScaledHeight));
|
45 |
|
System.Drawing.Drawing2D.Matrix mat2 = new System.Drawing.Drawing2D.Matrix();
|
46 |
|
mat2.RotateAt((float)Angle * -1, new System.Drawing.PointF((float)midP.X, (float)midP.Y));
|
47 |
|
contentByte.Transform(mat2);
|
48 |
|
PdfGState gs1 = new PdfGState();
|
49 |
|
gs1.FillOpacity = (float)opac;
|
50 |
|
contentByte.SetGState(gs1);
|
51 |
|
contentByte.AddImage(img);
|
|
76 |
Image img = Image.GetInstance(ms);
|
|
77 |
img.ScaleAbsolute(Rect.Width, Rect.Height);
|
|
78 |
|
|
79 |
img.SetAbsolutePosition(Rect.Left + ((Rect.Width - img.ScaledWidth) / 2), Rect.Bottom + ((Rect.Height - img.ScaledHeight) / 2));
|
|
80 |
var x = Rect.Left + ((Rect.Width - img.ScaledWidth) / 2);
|
|
81 |
var y = Rect.Bottom + ((Rect.Height - img.ScaledHeight) / 2);
|
|
82 |
midP = MathSet.getMiddlePoint(new System.Windows.Point(x, y), new System.Windows.Point(x + img.ScaledWidth, y + img.ScaledHeight));
|
|
83 |
System.Drawing.Drawing2D.Matrix mat2 = new System.Drawing.Drawing2D.Matrix();
|
|
84 |
mat2.RotateAt((float)Angle * -1, new System.Drawing.PointF((float)midP.X, (float)midP.Y));
|
|
85 |
contentByte.Transform(mat2);
|
|
86 |
PdfGState gs1 = new PdfGState();
|
|
87 |
gs1.FillOpacity = (float)opac;
|
|
88 |
contentByte.SetGState(gs1);
|
|
89 |
contentByte.AddImage(img);
|
|
90 |
}
|
52 |
91 |
}
|
53 |
92 |
}
|
54 |
93 |
}
|
|
94 |
|
55 |
95 |
contentByte.RestoreState();
|
56 |
96 |
}
|
57 |
97 |
|
|
98 |
static string getEnsembleSign(string user_id, string soapurl)
|
|
99 |
{
|
|
100 |
string result = string.Empty;
|
|
101 |
|
|
102 |
try
|
|
103 |
{
|
|
104 |
WebClient webClient = new WebClient();
|
|
105 |
string data = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ens=\"http://EnsemblePlus.Webservice\"> <soapenv:Header/> <soapenv:Body> <ens:checkoutSignImage>"
|
|
106 |
+ "<ens:sUserNo>" + user_id + "</ens:sUserNo>"
|
|
107 |
+ "</ens:checkoutSignImage> </soapenv:Body></soapenv:Envelope>";
|
|
108 |
webClient.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
|
|
109 |
webClient.Headers.Add("SOAPAction", "http://EnsemblePlus.Webservice");
|
|
110 |
var _result = webClient.UploadString(new Uri(soapurl), data);
|
|
111 |
XmlDocument xmlDoc = new XmlDocument();
|
|
112 |
xmlDoc.LoadXml(_result);
|
|
113 |
XmlNodeList list = xmlDoc.GetElementsByTagName("checkoutSignImageResponse");
|
|
114 |
foreach (XmlNode xn in list)
|
|
115 |
{
|
|
116 |
result = xn["checkoutSignImageReturn"].InnerText;
|
|
117 |
}
|
|
118 |
if (!result.Contains("No business object"))
|
|
119 |
{
|
|
120 |
return result;
|
|
121 |
}
|
|
122 |
else
|
|
123 |
{
|
|
124 |
return null;
|
|
125 |
}
|
|
126 |
}
|
|
127 |
catch (Exception ex)
|
|
128 |
{
|
|
129 |
throw ex;
|
|
130 |
}
|
|
131 |
|
|
132 |
|
|
133 |
}
|
58 |
134 |
public static void DrawImage(System.Windows.Point startPoint, System.Windows.Point endPoint, List<System.Windows.Point> pointSet, PdfContentByte contentByte, string filePath, double Angle, double opac)
|
59 |
135 |
{
|
60 |
136 |
contentByte.SaveState();
|