|
|
@@ -11,6 +11,7 @@ using System.Text.RegularExpressions;
|
|
|
using System.Net.Sockets;
|
|
|
using System.Data;
|
|
|
using System.Web.Script.Serialization;
|
|
|
+using System.Drawing.Imaging;
|
|
|
|
|
|
namespace FileWatcher
|
|
|
{
|
|
|
@@ -18,37 +19,60 @@ namespace FileWatcher
|
|
|
{
|
|
|
DataHelper dh = new DataHelper();
|
|
|
|
|
|
- public SOP()
|
|
|
+ string usercode;
|
|
|
+ string sourcecode;
|
|
|
+
|
|
|
+ public SOP(string iUserCode, string iSource)
|
|
|
{
|
|
|
+ usercode = iUserCode;
|
|
|
+ sourcecode = iSource;
|
|
|
InitializeComponent();
|
|
|
}
|
|
|
|
|
|
private void Form3_Load(object sender, EventArgs e)
|
|
|
{
|
|
|
CheckForIllegalCrossThreadCalls = false;
|
|
|
- //Dictionary<string, object> dic = new Dictionary<string, object>();
|
|
|
- //dic.Add("em_name", "管理员");
|
|
|
- //dic.Add("em_code", "ADMIN");
|
|
|
- //dic.Add("caller", "ProductSOP");
|
|
|
- //UploadFilesToRemoteUrl("http://10.1.162.15:8080/mes/MEScommon/uploadFiles.action?_noc=1", @"C:\MES_NEW\mes-client\FileWatcher\bin\Debug\包装产品.jpg", dic);
|
|
|
+ IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
|
|
|
+ string IPAddress = "";
|
|
|
+ for (int i = 0; i < IpEntry.AddressList.Length; i++)
|
|
|
+ {
|
|
|
+ if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
|
|
|
+ {
|
|
|
+ IPAddress = IpEntry.AddressList[i].ToString();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void uploadfile()
|
|
|
{
|
|
|
Workbook workbook = new Workbook();
|
|
|
- workbook.LoadFromFile(FilePath.Text, ExcelVersion.Version97to2003);
|
|
|
+ workbook.LoadFromFile(FilePath.Text);
|
|
|
workbook.ConverterSetting.JPEGQuality = 100;
|
|
|
workbook.ConverterSetting.XDpi = 600;
|
|
|
workbook.ConverterSetting.YDpi = 600;
|
|
|
+ List<Worksheet> list = new List<Worksheet>();
|
|
|
List<string> filename = new List<string>();
|
|
|
- OperatResult.AppendText("一共Sheet: " + workbook.Worksheets[0].Rows.Length + "\n");
|
|
|
+ OperatResult.AppendText("一共Sheet: " + workbook.Worksheets.Count + "\n");
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < workbook.Worksheets.Count; i++)
|
|
|
{
|
|
|
- workbook.Worksheets[i].SaveToImage(workbook.Worksheets[i].Name + ".jpg");
|
|
|
- filename.Add(workbook.Worksheets[i].Name + ".jpg");
|
|
|
- OperatResult.AppendText("解析图片【" + workbook.Worksheets[i].Name + ".jpg】" + "\n");
|
|
|
+ Workbook bw = new Workbook();
|
|
|
+ Worksheet she = bw.CreateEmptySheet();
|
|
|
+ she.Name = workbook.Worksheets[i].Name;
|
|
|
+ she.CopyFrom(workbook.Worksheets[i]);
|
|
|
+ if (JPG.Checked)
|
|
|
+ {
|
|
|
+ var myThread = new Thread(() => SaveFileToJPG(she));
|
|
|
+ myThread.Start();
|
|
|
+ filename.Add(she.Name + ".jpg");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var myThread = new Thread(() => SaveFileToPDF(she));
|
|
|
+ myThread.Start();
|
|
|
+ filename.Add(she.Name + ".pdf");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
@@ -62,12 +86,39 @@ namespace FileWatcher
|
|
|
dh.ExecuteSql("update ProductSOP set ps_attachsop='' where ps_prodcode='" + pr_code.Text + "'", "update");
|
|
|
for (int i = 0; i < filename.ToArray().Length; i++)
|
|
|
{
|
|
|
- OperatResult.AppendText("上传图片【" + filename.ToArray()[i] + "】\n");
|
|
|
- string fp_id = UploadFilesToRemoteUrl("http://10.1.162.15:8080/mes/MEScommon/uploadFiles.action?_noc=1", @"C:\MES_NEW\mes-client\FileWatcher\bin\Debug\" + filename.ToArray()[i], dic);
|
|
|
+ OperatResult.AppendText("上传文件【" + filename.ToArray()[i] + "】\n");
|
|
|
+ string fp_id = UploadFilesToRemoteUrl("http://10.1.81.208:11773/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + filename.ToArray()[i], dic);
|
|
|
dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void SaveFileToPDF(Worksheet sheet)
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
|
|
|
+ }
|
|
|
+ sheet.SaveToPdf(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".pdf");
|
|
|
+ OperatResult.AppendText("解析PDF【" + sheet.Name + ".pdf】" + "\n");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SaveFileToJPG(Worksheet sheet)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
|
|
|
+ }
|
|
|
+ sheet.SaveToImage(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".jpg");
|
|
|
+ OperatResult.AppendText("解析图片【" + sheet.Name + ".jpg】" + "\n");
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Console.WriteLine(ex.Message);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 请求上传图片到阿里云
|
|
|
/// </summary>
|
|
|
@@ -75,7 +126,7 @@ namespace FileWatcher
|
|
|
/// <param name="filepath">本地文件路径</param>
|
|
|
/// <param name="dic">上传的数据信息</param>
|
|
|
/// <returns></returns>
|
|
|
- public static string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic)
|
|
|
+ public string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
@@ -158,6 +209,7 @@ namespace FileWatcher
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
+ LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP", "上传失败", pr_code.Text, "");
|
|
|
Console.WriteLine(e.Message + e.StackTrace);
|
|
|
}
|
|
|
return "";
|
|
|
@@ -175,16 +227,24 @@ namespace FileWatcher
|
|
|
|
|
|
private void UploadSOP_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- //Thread thread = new Thread(uploadfile);
|
|
|
- //SetLoadingWindow stw = new SetLoadingWindow(thread, "上传文件");
|
|
|
- //stw.StartPosition = FormStartPosition.CenterScreen;
|
|
|
- //stw.ShowDialog();
|
|
|
- uploadfile();
|
|
|
+
|
|
|
+ Thread thread = new Thread(uploadfile);
|
|
|
+ SetLoadingWindow stw = new SetLoadingWindow(thread, "上传文件");
|
|
|
+ stw.StartPosition = FormStartPosition.CenterScreen;
|
|
|
+ stw.ShowDialog();
|
|
|
+ if (JPG.Checked)
|
|
|
+ {
|
|
|
+ LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP【图片格式】", "上传成功", pr_code.Text, "");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP【PDF格式】", "上传成功", pr_code.Text, "");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void OperatResult_TextChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- OperatResult.SelectionStart = Text.Length;
|
|
|
+ //OperatResult.SelectionStart = Text.Length;
|
|
|
OperatResult.ScrollToCaret();
|
|
|
}
|
|
|
|
|
|
@@ -194,11 +254,11 @@ namespace FileWatcher
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- tcpserver.Start();
|
|
|
- Thread.Sleep(5000);
|
|
|
DataTable dt = (DataTable)dh.ExecuteSql("select * from productsop where ps_prodcode='" + pr_code.Text + "'", "select");
|
|
|
if (dt.Rows.Count > 0)
|
|
|
{
|
|
|
+ tcpserver.Start();
|
|
|
+ Thread.Sleep(5000);
|
|
|
List<Dictionary<string, string>> listr = new List<Dictionary<string, string>>();
|
|
|
string PS_ATTACHSOP = dt.Rows[0]["PS_ATTACHSOP"].ToString();
|
|
|
PS_ATTACHSOP = PS_ATTACHSOP.Substring(0, PS_ATTACHSOP.Length - 1).Replace(";", ",");
|
|
|
@@ -214,16 +274,17 @@ namespace FileWatcher
|
|
|
path = dt.Rows[i]["fp_path"].ToString();
|
|
|
path = encryptBASE64(path.Replace("/app/uas/webapps/postattach", pathroot)).Replace("\\s*|\r|\n|\t", "");
|
|
|
dic1.Add("path", path);
|
|
|
- dic1.Add("filename", dt.Rows[i]["fp_name"].ToString());
|
|
|
+ dic1.Add("filename", dt.Rows[i]["fp_name"].ToString().Replace(" ", "").Replace("(", "").Replace(")", ""));
|
|
|
dic1.Add("ps_prodcode", pr_code.Text);
|
|
|
listr.Add(dic1);
|
|
|
}
|
|
|
- map1.Add("ps_code","");
|
|
|
+ map1.Add("ps_code", "");
|
|
|
map1.Add("url", listr);
|
|
|
map.Add("success", true);
|
|
|
map.Add("data", map1);
|
|
|
tcpserver.Send(jss.Serialize(map));
|
|
|
tcpserver.Stop();
|
|
|
+ LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播成功", pr_code.Text, "");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -232,6 +293,7 @@ namespace FileWatcher
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
+ LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播失败", pr_code.Text, "");
|
|
|
Console.WriteLine(ex.Message + ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
@@ -256,5 +318,33 @@ namespace FileWatcher
|
|
|
}
|
|
|
return encode;
|
|
|
}
|
|
|
+
|
|
|
+ private void pr_code_KeyDown(object sender, KeyEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.KeyCode == Keys.Enter)
|
|
|
+ {
|
|
|
+ LoadPrCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void LoadPrCode()
|
|
|
+ {
|
|
|
+ DataTable dt = (DataTable)dh.ExecuteSql("select pr_code,pr_spec,pr_detail from product where pr_code='" + pr_code.Text + "'", "select");
|
|
|
+ if (dt.Rows.Count > 0)
|
|
|
+ {
|
|
|
+ pr_spec.Text = dt.Rows[0]["pr_spec"].ToString();
|
|
|
+ pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("产品编号" + pr_code.Text + "不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void pr_code_Leave(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ LoadPrCode();
|
|
|
+ }
|
|
|
}
|
|
|
}
|