1274 lines
46 KiB
C#
1274 lines
46 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.Drawing.Imaging;
|
|||
|
|
using System.Drawing.Printing;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows.Forms;
|
|||
|
|
using System.Xml.Serialization;
|
|||
|
|
using System.Xml;
|
|||
|
|
using System.Printing;
|
|||
|
|
using FluentFTP;
|
|||
|
|
|
|||
|
|
namespace FalitPrint
|
|||
|
|
{
|
|||
|
|
public partial class FormMain : Form
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
private int iRt;
|
|||
|
|
|
|||
|
|
private int iCount = 1;
|
|||
|
|
|
|||
|
|
public int iServerIdx;
|
|||
|
|
|
|||
|
|
public int Processing;
|
|||
|
|
|
|||
|
|
public byte CtlFolder;
|
|||
|
|
|
|||
|
|
public string SubFolder;
|
|||
|
|
|
|||
|
|
public string CtlHeadFilter;
|
|||
|
|
|
|||
|
|
public string CtlTailFilter;
|
|||
|
|
|
|||
|
|
public string PrintName;
|
|||
|
|
|
|||
|
|
public int printsignal;
|
|||
|
|
|
|||
|
|
public int iFTP_Type;
|
|||
|
|
|
|||
|
|
public int iPrinterStatus;
|
|||
|
|
|
|||
|
|
public int iSubNameIndex;
|
|||
|
|
|
|||
|
|
public int iFtpConnectIndex;
|
|||
|
|
|
|||
|
|
public int iLangIndex;
|
|||
|
|
|
|||
|
|
public int iNowLangIndex = -1;
|
|||
|
|
|
|||
|
|
private static string result = Environment.CurrentDirectory;
|
|||
|
|
|
|||
|
|
public string sXmlSavePaht = "C:\\PLNC";
|
|||
|
|
|
|||
|
|
public string sLabelSavePaht = "C:\\PLNC\\Label";
|
|||
|
|
|
|||
|
|
public string SysPhotoPath = "home/disk3/data/open_hmi/photo";
|
|||
|
|
|
|||
|
|
public string PrintSet = result + "\\PrintSet.txt";
|
|||
|
|
|
|||
|
|
public string sLangEncoding = "";
|
|||
|
|
|
|||
|
|
public int x;
|
|||
|
|
|
|||
|
|
public int order;
|
|||
|
|
|
|||
|
|
private static string data = result + "\\data.txt";
|
|||
|
|
|
|||
|
|
private string Printer_name;
|
|||
|
|
|
|||
|
|
public string sLabelSavePhotoPaht = "C:\\PLNC\\HMI";
|
|||
|
|
|
|||
|
|
public string control = result + "\\control.txt";
|
|||
|
|
|
|||
|
|
public string photo_path;
|
|||
|
|
|
|||
|
|
public int print_count;
|
|||
|
|
|
|||
|
|
private FtpClient client;
|
|||
|
|
public FormMain()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
ConnectInitial();
|
|||
|
|
Connect_SYS_loop();
|
|||
|
|
ComponentInitial();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ConnectInitial()
|
|||
|
|
{
|
|||
|
|
LNCAPI.DLL_USE_SETTING DllSetting = default;
|
|||
|
|
DllSetting.SoftwareType = 5u;
|
|||
|
|
DllSetting.TalkInfoNum = 1u;
|
|||
|
|
DllSetting.MemSizeI = 4096u;
|
|||
|
|
DllSetting.MemSizeO = 4096u;
|
|||
|
|
DllSetting.MemSizeC = 4096u;
|
|||
|
|
DllSetting.MemSizeS = 4096u;
|
|||
|
|
DllSetting.MemSizeA = 4096u;
|
|||
|
|
DllSetting.MemSizeR = 3500000u;
|
|||
|
|
DllSetting.MemSizeF = 0u;
|
|||
|
|
LNCAPI.FtpSetConnection(5);
|
|||
|
|
iRt = LNCAPI.LibraryInitial(ref DllSetting, 1111, "15C33863AD3210BB63CDDAAB12D2851C55C169A74B5D6C15");
|
|||
|
|
if (iRt == 100)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("Initial Success");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("Initial Fail");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Connect_SYS_loop()
|
|||
|
|
{
|
|||
|
|
LNCAPI.LClearQueue(iServerIdx);
|
|||
|
|
LNCAPI.LReadBegin(iServerIdx);
|
|||
|
|
LNCAPI.LReadNS(iServerIdx, 3000, 2);
|
|||
|
|
LNCAPI.LReadNS(iServerIdx, 3000, 2);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 17003, 1);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 3051529, 64);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 20302, 1);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 1369252, 1);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 1390110, 1);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 48000, 1);
|
|||
|
|
LNCAPI.LReadNR(iServerIdx, 1358000, 64);
|
|||
|
|
LNCAPI.LReadEnd(iServerIdx);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ComponentInitial()
|
|||
|
|
{
|
|||
|
|
dgConnect.RowCount = iCount;
|
|||
|
|
dgConnect.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
|
|||
|
|
Panel_Connect_1.Visible = false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
LNCAPI.MainProcess();
|
|||
|
|
int iConnectStatus = LNCAPI.GetConnectionMsg(iServerIdx, 2);
|
|||
|
|
switch (iConnectStatus)
|
|||
|
|
{
|
|||
|
|
case 0:
|
|||
|
|
laConnectStatus.BackColor = Color.Gray;
|
|||
|
|
laConnectStatus.Text = "断线";
|
|||
|
|
break;
|
|||
|
|
case 1:
|
|||
|
|
laConnectStatus.BackColor = Color.Yellow;
|
|||
|
|
laConnectStatus.Text = "连接中";
|
|||
|
|
break;
|
|||
|
|
case 2:
|
|||
|
|
laConnectStatus.BackColor = Color.Gray;
|
|||
|
|
laConnectStatus.Text = "连接失败";
|
|||
|
|
break;
|
|||
|
|
case 3:
|
|||
|
|
laConnectStatus.BackColor = Color.Blue;
|
|||
|
|
laConnectStatus.Text = "已经连接";
|
|||
|
|
Panel_Connect_1.Visible = false;
|
|||
|
|
break;
|
|||
|
|
case 4:
|
|||
|
|
laConnectStatus.BackColor = Color.Gray;
|
|||
|
|
laConnectStatus.Text = "无响应";
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
if (iConnectStatus == 3)
|
|||
|
|
{
|
|||
|
|
laAlarm.BackColor = LNCAPI.memS(iServerIdx, 3000) == 1 ? Color.Red : Color.LightGray;
|
|||
|
|
laWarning.BackColor = LNCAPI.memS(iServerIdx, 3001) == 1 ? Color.Yellow : Color.LightGray;
|
|||
|
|
la_LoopQueue.Text = Convert.ToString(LNCAPI.GetConnectionMsg(iServerIdx, 21));
|
|||
|
|
la_DirectQueue.Text = Convert.ToString(LNCAPI.GetConnectionMsg(iServerIdx, 22));
|
|||
|
|
}
|
|||
|
|
using (PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue())
|
|||
|
|
{
|
|||
|
|
string PrintStaticText = "";
|
|||
|
|
switch (defaultPrintQueue.QueueStatus)
|
|||
|
|
{
|
|||
|
|
case PrintQueueStatus.Busy:
|
|||
|
|
PrintStaticText = "打印机忙";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.DoorOpen:
|
|||
|
|
PrintStaticText = "打印机上盖打开";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Error:
|
|||
|
|
PrintStaticText = "发生错误,无法打印";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.IOActive:
|
|||
|
|
PrintStaticText = "发生打印文件中";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Initializing:
|
|||
|
|
PrintStaticText = "打印机初始化";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.ManualFeed:
|
|||
|
|
PrintStaticText = "等待放入纸张";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.NoToner:
|
|||
|
|
PrintStaticText = "打印机无墨粉";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.None:
|
|||
|
|
PrintStaticText = "未知状态";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.NotAvailable:
|
|||
|
|
PrintStaticText = "状态不可用";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Offline:
|
|||
|
|
PrintStaticText = "打印机离线";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.OutOfMemory:
|
|||
|
|
PrintStaticText = "打印机内存溢出";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.OutputBinFull:
|
|||
|
|
PrintStaticText = "输出纸盒已满";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.PagePunt:
|
|||
|
|
PrintStaticText = "不能打印";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.PaperJam:
|
|||
|
|
PrintStaticText = "打印机卡纸";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.PaperOut:
|
|||
|
|
PrintStaticText = "无效的纸张";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.PaperProblem:
|
|||
|
|
PrintStaticText = "纸张错误";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Paused:
|
|||
|
|
PrintStaticText = "暂停";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.PendingDeletion:
|
|||
|
|
PrintStaticText = "正在删除";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.PowerSave:
|
|||
|
|
PrintStaticText = "节能魔兽";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Printing:
|
|||
|
|
PrintStaticText = "准备打印";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Processing:
|
|||
|
|
PrintStaticText = "执行中";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.ServerUnknown:
|
|||
|
|
PrintStaticText = "未知错误";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.TonerLow:
|
|||
|
|
PrintStaticText = "缺墨";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.UserIntervention:
|
|||
|
|
PrintStaticText = "需要手动处理";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.Waiting:
|
|||
|
|
PrintStaticText = "等待";
|
|||
|
|
break;
|
|||
|
|
case PrintQueueStatus.WarmingUp:
|
|||
|
|
PrintStaticText = "预热";
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
Err_Box.Text = PrintStaticText;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Bebug()
|
|||
|
|
{
|
|||
|
|
LNCAPI.LibrarySetDebug(2);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Saw_Func_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
int Photo_Download_Index = LNCAPI.memR(iServerIdx, 1390110);
|
|||
|
|
if (Photo_Download_Index == 1 || Photo_Download_Index == 2)
|
|||
|
|
{
|
|||
|
|
photoshow.Image.Dispose();
|
|||
|
|
photoshow.Image = Image.FromFile(result + "\\test.png");
|
|||
|
|
Downloads_Photo();
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, 1390110, -1);
|
|||
|
|
LNCAPI.DWaitDone(iServerIdx, 5000);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SYS_Connect_Check_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (LNCAPI.memR(iServerIdx, 1369252) == 0)
|
|||
|
|
{
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, 1369252, 1);
|
|||
|
|
LNCAPI.DWaitDone(iServerIdx, 5000);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Form1_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (!File.Exists(sXmlSavePaht))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(sXmlSavePaht);
|
|||
|
|
}
|
|||
|
|
if (!File.Exists(sLabelSavePaht))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(sLabelSavePaht);
|
|||
|
|
}
|
|||
|
|
if (File.Exists(PrintSet))
|
|||
|
|
{
|
|||
|
|
using (FileStream fs2 = new FileStream(result + "\\PrintSet.txt", FileMode.Open, FileAccess.Read))
|
|||
|
|
{
|
|||
|
|
using (StreamReader sr2 = new StreamReader(fs2))
|
|||
|
|
{
|
|||
|
|
string[] sLine2 = new string[10];
|
|||
|
|
int iLineCount2 = 0;
|
|||
|
|
string str2;
|
|||
|
|
while ((str2 = sr2.ReadLine()) != null)
|
|||
|
|
{
|
|||
|
|
sLine2[iLineCount2] = str2;
|
|||
|
|
iLineCount2++;
|
|||
|
|
}
|
|||
|
|
laphotoPath.Text = sLine2[0];
|
|||
|
|
edIP.Text = sLine2[1];
|
|||
|
|
if (sLine2[2] != null)
|
|||
|
|
{
|
|||
|
|
ed_XML_Path.Text = sLine2[2];
|
|||
|
|
}
|
|||
|
|
laprintposX.Text = sLine2[3].Split('\t')[0];
|
|||
|
|
laprintposY.Text = sLine2[3].Split('\t')[1];
|
|||
|
|
lapaperH.Text = sLine2[3].Split('\t')[2];
|
|||
|
|
lapaperW.Text = sLine2[3].Split('\t')[3];
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
using (File.Create(PrintSet))
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (File.Exists(data))
|
|||
|
|
{
|
|||
|
|
using (FileStream fs = new FileStream(result + "\\data.txt", FileMode.Open, FileAccess.Read))
|
|||
|
|
{
|
|||
|
|
using (StreamReader sr = new StreamReader(fs))
|
|||
|
|
{
|
|||
|
|
string[] sLine = new string[10];
|
|||
|
|
int iLineCount = 0;
|
|||
|
|
string str;
|
|||
|
|
while ((str = sr.ReadLine()) != null)
|
|||
|
|
{
|
|||
|
|
sLine[iLineCount] = str;
|
|||
|
|
iLineCount++;
|
|||
|
|
}
|
|||
|
|
if (sLine[0] == "0")
|
|||
|
|
{
|
|||
|
|
check_connect_1.Checked = true;
|
|||
|
|
check_connect_2.Checked = false;
|
|||
|
|
order = 0;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
check_connect_1.Checked = false;
|
|||
|
|
check_connect_2.Checked = true;
|
|||
|
|
order = 1;
|
|||
|
|
}
|
|||
|
|
if (sLine[1] != null)
|
|||
|
|
{
|
|||
|
|
Printer_name = sLine[1];
|
|||
|
|
}
|
|||
|
|
if (sLine[2] != null)
|
|||
|
|
{
|
|||
|
|
sLabelSavePaht = sLine[2];
|
|||
|
|
}
|
|||
|
|
if (sLine[3] != null)
|
|||
|
|
{
|
|||
|
|
photo_path = sLine[3];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
Printer_path.Text = Printer_name;
|
|||
|
|
save_path.Text = sLabelSavePaht;
|
|||
|
|
photo_path_Box.Text = photo_path;
|
|||
|
|
BootConnect();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void WriteLog(string Func, string Info)
|
|||
|
|
{
|
|||
|
|
string Log = result + "\\Log.txt";
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
using (FileStream PLNC = (File.Exists(Log) ? new FileStream(Log, FileMode.Append, FileAccess.Write) : File.Create(Log)))
|
|||
|
|
{
|
|||
|
|
StreamWriter PLNC_SW = new StreamWriter(PLNC);
|
|||
|
|
PLNC_SW.WriteLine("[" + Func + "] " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " " + Info);
|
|||
|
|
PLNC_SW.Dispose();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine("[WriteLog] " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " " + ex.Message);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void RefreshPrintSet()
|
|||
|
|
{
|
|||
|
|
using (FileStream fs = new FileStream(result + "\\PrintSet.txt", FileMode.Create, FileAccess.ReadWrite))
|
|||
|
|
{
|
|||
|
|
using (StreamWriter sw = new StreamWriter(fs))
|
|||
|
|
{
|
|||
|
|
sw.WriteLine(laphotoPath.Text);
|
|||
|
|
sw.WriteLine(edIP.Text);
|
|||
|
|
sw.WriteLine(" ");
|
|||
|
|
sw.WriteLine(laprintposX.Text.ToString() + "\t" + laprintposY.Text.ToString() + "\t" + lapaperH.Text.ToString() + "\t" + lapaperW.Text.ToString());
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void StringSaveToR(string Src, int iLen, int iRNo, int iRCount)
|
|||
|
|
{
|
|||
|
|
if (iRNo < 0 || iRCount <= 0)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
_ = iLen % 4;
|
|||
|
|
int ciCount = iLen / 4 + ((!(iLen % 4).Equals(0)) ? 1 : 0);
|
|||
|
|
int[] iRValue = new int[600];
|
|||
|
|
int iIndex = 0;
|
|||
|
|
int i = 0;
|
|||
|
|
for (i = 0; i < ciCount; i++)
|
|||
|
|
{
|
|||
|
|
int iDest = 0;
|
|||
|
|
int j = 0;
|
|||
|
|
for (j = 0; j < 4; j++)
|
|||
|
|
{
|
|||
|
|
int iStrIndex = i * 4 + j;
|
|||
|
|
if (iStrIndex < iLen)
|
|||
|
|
{
|
|||
|
|
int iByteData = Src[iStrIndex] & 0xFF;
|
|||
|
|
iDest |= iByteData << 8 * j;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (i < 600)
|
|||
|
|
{
|
|||
|
|
iRValue[i] = iDest;
|
|||
|
|
}
|
|||
|
|
iIndex++;
|
|||
|
|
}
|
|||
|
|
LNCAPI.DWriteBegin(iServerIdx);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo, iRValue[0]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 1, iRValue[1]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 2, iRValue[2]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 3, iRValue[3]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 4, iRValue[4]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 5, iRValue[5]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 6, iRValue[6]);
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, iRNo + 7, iRValue[7]);
|
|||
|
|
LNCAPI.DWriteEnd(iServerIdx);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string StringReadFromR(int iRNo, int iRCount, string Src)
|
|||
|
|
{
|
|||
|
|
if (iRNo >= 0 && iRCount > 0)
|
|||
|
|
{
|
|||
|
|
int[] a_iData = new int[8];
|
|||
|
|
int j = 0;
|
|||
|
|
for (int i = iRCount - 1; i >= 0; i--)
|
|||
|
|
{
|
|||
|
|
a_iData[i] = LNCAPI.memR(iServerIdx, iRNo + j);
|
|||
|
|
j++;
|
|||
|
|
}
|
|||
|
|
int iIndex = 0;
|
|||
|
|
for (int i = 0; i < iRCount; i++)
|
|||
|
|
{
|
|||
|
|
int iData = a_iData[--j];
|
|||
|
|
for (int k = 0; k < 4; k++)
|
|||
|
|
{
|
|||
|
|
char cIntData = Convert.ToChar((iData >> 8 * k) & 0xFF);
|
|||
|
|
if (cIntData >= ' ')
|
|||
|
|
{
|
|||
|
|
Src += cIntData;
|
|||
|
|
iIndex++;
|
|||
|
|
}
|
|||
|
|
else if (cIntData == '\0')
|
|||
|
|
{
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return Src;
|
|||
|
|
}
|
|||
|
|
return "ture";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void tabMW_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
if (tabMW.SelectedTab == tabXml)
|
|||
|
|
{
|
|||
|
|
if (LNCAPI.GetConnectionMsg(iServerIdx, 2) != 3)
|
|||
|
|
{
|
|||
|
|
Panel_Connect_1.Visible = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Panel_Connect_1.Visible = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Panel_Connect_1.Visible = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btSetSize_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
RefreshPrintSet();
|
|||
|
|
MessageBox.Show("设置成功");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btPrintSingle_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
OpenFileDialog singleprint = new OpenFileDialog();
|
|||
|
|
singleprint.Multiselect = false;
|
|||
|
|
singleprint.Title = "选择文件";
|
|||
|
|
singleprint.Filter = "Image Files|*.bmp;*.png";
|
|||
|
|
if (singleprint.ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
PrintDocument obj = new PrintDocument
|
|||
|
|
{
|
|||
|
|
PrinterSettings =
|
|||
|
|
{
|
|||
|
|
PrinterName = Printer_name
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
Console.WriteLine("Single");
|
|||
|
|
laphotoPath.Text = singleprint.FileName;
|
|||
|
|
laprintPath.Text = singleprint.FileName;
|
|||
|
|
RefreshPrintSet();
|
|||
|
|
photoshow.Image = Image.FromFile(singleprint.FileName);
|
|||
|
|
obj.PrintPage += printDocument1_PrintPage;
|
|||
|
|
obj.Print();
|
|||
|
|
obj.Dispose();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("PrintSingle", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Print_index_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
printsignal = LNCAPI.memR(iServerIdx, 20302 + order);
|
|||
|
|
if (printsignal == 1)
|
|||
|
|
{
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, 20302 + order, 2);
|
|||
|
|
LNCAPI.DWaitDone(iServerIdx, 5000);
|
|||
|
|
Print_Action();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Print_Action()
|
|||
|
|
{
|
|||
|
|
int iMSG_HINT_Start_R = 1358000 + order * 32;
|
|||
|
|
int IMSG_HINT_Count = 32;
|
|||
|
|
byte[] Namech = new byte[128];
|
|||
|
|
LNCAPI.memRString(0, iMSG_HINT_Start_R, IMSG_HINT_Count, Namech);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
PrintName = Encoding.GetEncoding(0).GetString(Namech);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
PrintName = Encoding.GetEncoding(1).GetString(Namech);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
PrintName = Encoding.GetEncoding(2).GetString(Namech);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
PrintName = PrintName.Trim();
|
|||
|
|
laprintPath.Text = sLabelSavePaht + "\\" + PrintName;
|
|||
|
|
if (File.Exists(laprintPath.Text))
|
|||
|
|
{
|
|||
|
|
using (PrintDocument obj3 = new PrintDocument())
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
|
|||
|
|
obj3.PrinterSettings.PrinterName = Printer_name;
|
|||
|
|
photoshow.Image = Image.FromFile(laprintPath.Text);
|
|||
|
|
obj3.PrintPage += printDocument1_PrintPage;
|
|||
|
|
obj3.Print();
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, 20402 + order, 2);
|
|||
|
|
MessageBox.Show("文件不存在");
|
|||
|
|
}
|
|||
|
|
Namech = null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (Image img = Image.FromFile(laprintPath.Text))
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(laprintPath.Text);
|
|||
|
|
double iHgight = double.Parse(lapaperH.Text) / 25.4 * 100.0;
|
|||
|
|
double iWidth = double.Parse(lapaperW.Text) / 25.4 * 100.0;
|
|||
|
|
Point position = new Point(int.Parse(laprintposX.Text), int.Parse(laprintposY.Text));
|
|||
|
|
Size size = new Size((int)iWidth, (int)iHgight);
|
|||
|
|
Rectangle photosize = new Rectangle(position, size);
|
|||
|
|
e.Graphics.DrawImage(img, photosize);
|
|||
|
|
}
|
|||
|
|
LNCAPI.DWrite1R(iServerIdx, 20402 + order, 1);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("PrintDocumect1", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btDetect_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
int i = 0;
|
|||
|
|
LNCAPI.LOCAL_CONTROLLER_INFO Info = default;
|
|||
|
|
_ = dgConnect.Rows;
|
|||
|
|
iCount = LNCAPI.LocalDetectControllers();
|
|||
|
|
if (iCount == 0)
|
|||
|
|
{
|
|||
|
|
dgConnect.RowCount = 1;
|
|||
|
|
}
|
|||
|
|
else if (iCount != 0)
|
|||
|
|
{
|
|||
|
|
dgConnect.RowCount = iCount;
|
|||
|
|
}
|
|||
|
|
for (i = 0; i < iCount; i++)
|
|||
|
|
{
|
|||
|
|
iRt = LNCAPI.LocalReadController(i, ref Info);
|
|||
|
|
string[] str_1 = Encoding.Default.GetString(Info.IP).Split(default(char));
|
|||
|
|
string[] str_2 = Encoding.Default.GetString(Info.Name).Split(default(char));
|
|||
|
|
_ = Info.IPLong + " : " + str_1[0] + str_2[0];
|
|||
|
|
dgConnect.Rows[i].HeaderCell.Value = i.ToString();
|
|||
|
|
dgConnect.Rows[i].Cells[0].Value = str_1[0];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btAutoConnect_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
LNCAPI.ConnectLocalList(iServerIdx, dgConnect.CurrentCell.RowIndex);
|
|||
|
|
string sIP = dgConnect.CurrentCell.Value.ToString();
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
edIP.Text = sIP;
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("AutoConnect", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btConnect_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string sIP = edIP.Text;
|
|||
|
|
LNCAPI.ConnectLocalIP(iServerIdx, sIP);
|
|||
|
|
Bebug();
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Connect", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void BootConnect()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string sIP = edIP.Text;
|
|||
|
|
LNCAPI.ConnectLocalIP(iServerIdx, sIP);
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Connect", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btDisconnect_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
LNCAPI.Disconnect(iServerIdx);
|
|||
|
|
client.Disconnect();
|
|||
|
|
client.Dispose();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Disconnect", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Ftp_Connect(string Connect_IP)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
client = new FtpClient(Connect_IP, "root", "admin0800095590", 2100, new FtpConfig()
|
|||
|
|
{
|
|||
|
|
ConnectTimeout = 500,
|
|||
|
|
SocketKeepAlive = true,
|
|||
|
|
});
|
|||
|
|
//client.SocketKeepAlive = true;
|
|||
|
|
client.Connect();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Connect", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ClearAllFIles()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string sIP = edIP.Text;
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
if (client.IsConnected)
|
|||
|
|
{
|
|||
|
|
photoshow.Image.Dispose();
|
|||
|
|
photoshow.Image = Image.FromFile(result + "\\test.png");
|
|||
|
|
FtpListItem[] listing = client.GetListing(SysPhotoPath);
|
|||
|
|
foreach (FtpListItem item in listing)
|
|||
|
|
{
|
|||
|
|
client.DeleteFile(item.FullName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("FTP 连接失败!");
|
|||
|
|
}
|
|||
|
|
foreach (string item2 in new List<string> { sLabelSavePaht })
|
|||
|
|
{
|
|||
|
|
string[] files = Directory.GetFiles(item2);
|
|||
|
|
for (int i = 0; i < files.Length; i++)
|
|||
|
|
{
|
|||
|
|
File.Delete(files[i]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("ClearAllFIles", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void btTransform_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
int iListCount = -1;
|
|||
|
|
int iCount = 0;
|
|||
|
|
int iLabelIndex = 0;
|
|||
|
|
int cncFilename = 1373200;
|
|||
|
|
int labelFilename = 1375200;
|
|||
|
|
int imageFilename = 1377200;
|
|||
|
|
string[] sXmlList = new string[1500];
|
|||
|
|
string XmlDocument = "";
|
|||
|
|
sLabelSavePaht = "C:\\PLNC\\Label";
|
|||
|
|
Data_Record();
|
|||
|
|
save_path.Text = sLabelSavePaht;
|
|||
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|||
|
|
dialog.Multiselect = false;
|
|||
|
|
dialog.Title = "选择文件清单";
|
|||
|
|
dialog.Filter = "Input Files|*.xml";
|
|||
|
|
if (!File.Exists(sLabelSavePaht))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(sLabelSavePaht);
|
|||
|
|
}
|
|||
|
|
new XmlDocument();
|
|||
|
|
LNCAPI.DWrite1RBit(iServerIdx, 8046, 8, 0);
|
|||
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
Panel_Transfer.Visible = true;
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
print_count = 0;
|
|||
|
|
ed_XML_Path.Text = Path.GetDirectoryName(dialog.FileName);
|
|||
|
|
RefreshPrintSet();
|
|||
|
|
ClearAllFIles();
|
|||
|
|
int[] test = new int[360];
|
|||
|
|
LNCAPI.DWriteBegin(iServerIdx);
|
|||
|
|
for (int j = 0; j < 21; j++)
|
|||
|
|
{
|
|||
|
|
LNCAPI.DWriteNR(iServerIdx, 1373200 + j * 300, 300, test);
|
|||
|
|
}
|
|||
|
|
LNCAPI.DWriteEnd(iServerIdx);
|
|||
|
|
string[] fileNames = dialog.FileNames;
|
|||
|
|
foreach (string item in fileNames)
|
|||
|
|
{
|
|||
|
|
XmlDocument = Path.GetDirectoryName(item);
|
|||
|
|
CycleFile root = (CycleFile)new XmlSerializer(typeof(CycleFile)).Deserialize(new StringReader(File.ReadAllText(item, Encoding.UTF8)));
|
|||
|
|
if (root.Cycle == null)
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
foreach (Field items in root.Cycle)
|
|||
|
|
{
|
|||
|
|
if (iListCount >= 250 || (!(items.Name == "PlateID") && !(items.Name == "LabelName") && !(items.Name == "LargeImage")))
|
|||
|
|
{
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
if (items.Name == "PlateID")
|
|||
|
|
{
|
|||
|
|
if (iListCount == 249)
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("最大上传250个文件");
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
iListCount++;
|
|||
|
|
iCount = 0;
|
|||
|
|
}
|
|||
|
|
if (items.Name == "LargeImage")
|
|||
|
|
{
|
|||
|
|
iLabelIndex = 1;
|
|||
|
|
}
|
|||
|
|
sXmlList[iListCount * 6 + iCount] = items.Name;
|
|||
|
|
sXmlList[iListCount * 6 + iCount + 1] = items.Value;
|
|||
|
|
iCount += 2;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
Uplaoads_Photo();
|
|||
|
|
for (int i = 0; i < iListCount + 1; i++)
|
|||
|
|
{
|
|||
|
|
StringSaveToR(sXmlList[1 + i * 6], sXmlList[1 + i * 6].Length, cncFilename + i * 8, 8);
|
|||
|
|
LNCAPI.FtpWaitDone(50);
|
|||
|
|
StringSaveToR(sXmlList[3 + i * 6], sXmlList[3 + i * 6].Length, labelFilename + i * 8, 8);
|
|||
|
|
LNCAPI.FtpWaitDone(50);
|
|||
|
|
if (iLabelIndex == 1)
|
|||
|
|
{
|
|||
|
|
StringSaveToR(sXmlList[5 + i * 6], sXmlList[5 + i * 6].Length, imageFilename + i * 8, 8);
|
|||
|
|
LNCAPI.FtpWaitDone(50);
|
|||
|
|
}
|
|||
|
|
xmltoNc(XmlDocument, sXmlList[3 + i * 6], sXmlList[1 + i * 6]);
|
|||
|
|
}
|
|||
|
|
Panel_Transfer.Visible = false;
|
|||
|
|
MessageBox.Show("转换完成!");
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Transform", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
LNCAPI.DWrite1RBit(iServerIdx, 8046, 8, 1);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void xmltoNc(string ListPath, string LabelFileName, string CNCFileName)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(ListPath + LabelFileName);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
int XmlValueCount = 0;
|
|||
|
|
string[] sProg = new string[100];
|
|||
|
|
string[] sProg_2 = new string[100];
|
|||
|
|
string sPhotoRename = "";
|
|||
|
|
string sPhotoRename_last = "";
|
|||
|
|
string sXmlBakPath = ListPath + "\\" + LabelFileName;
|
|||
|
|
string path = sXmlSavePaht + "\\" + LabelFileName;
|
|||
|
|
new XmlDocument();
|
|||
|
|
File.Delete(path);
|
|||
|
|
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
|
|||
|
|
iLangIndex = LNCAPI.memR(iServerIdx, 48000);
|
|||
|
|
if (iLangIndex == 0)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "Big5";
|
|||
|
|
}
|
|||
|
|
else if (iLangIndex == 1)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "GB2312";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "UTF8";
|
|||
|
|
}
|
|||
|
|
StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding(sLangEncoding));
|
|||
|
|
CycleFile root = (CycleFile)new XmlSerializer(typeof(CycleFile)).Deserialize(new StringReader(File.ReadAllText(sXmlBakPath, Encoding.UTF8)));
|
|||
|
|
sw.Write(";MADE BY LNC " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "\n");
|
|||
|
|
int one = 0;
|
|||
|
|
string output;
|
|||
|
|
if (root.Cycle != null)
|
|||
|
|
{
|
|||
|
|
foreach (Field items in root.Cycle)
|
|||
|
|
{
|
|||
|
|
sProg[XmlValueCount] = items.Name;
|
|||
|
|
sProg[XmlValueCount + 1] = items.Value;
|
|||
|
|
XmlValueCount += 2;
|
|||
|
|
if (XmlValueCount == 8)
|
|||
|
|
{
|
|||
|
|
if (one == 0)
|
|||
|
|
{
|
|||
|
|
sProg_2[1] = sProg[1];
|
|||
|
|
sProg_2[2] = sProg[2];
|
|||
|
|
sProg_2[3] = sProg[3];
|
|||
|
|
sProg_2[4] = sProg[4];
|
|||
|
|
sProg_2[5] = sProg[5];
|
|||
|
|
one = 1;
|
|||
|
|
XmlValueCount = 0;
|
|||
|
|
sPhotoRename = sProg[1].Split('.')[0] + ".png";
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
sPhotoRename_last = sProg_2[1].Split('.')[0] + ".png";
|
|||
|
|
sPhotoRename = sProg[1].Split('.')[0] + ".png";
|
|||
|
|
output = "M801 \"" + sPhotoRename_last + "\" " + sProg_2[2] + sProg_2[3] + " " + sProg_2[4] + sProg_2[5] + " \"" + sPhotoRename + "\" \n";
|
|||
|
|
sw.Write(output);
|
|||
|
|
sProg_2[1] = sProg[1];
|
|||
|
|
sProg_2[2] = sProg[2];
|
|||
|
|
sProg_2[3] = sProg[3];
|
|||
|
|
sProg_2[4] = sProg[4];
|
|||
|
|
sProg_2[5] = sProg[5];
|
|||
|
|
XmlValueCount = 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
output = "M801 \"" + sPhotoRename + "\" " + sProg[2] + sProg[3] + " " + sProg[4] + sProg[5] + "\n";
|
|||
|
|
sw.Write(output);
|
|||
|
|
output = "M802 \"" + CNCFileName + "\"\n";
|
|||
|
|
sw.Write(output);
|
|||
|
|
sw.Write("M30");
|
|||
|
|
sw.Dispose();
|
|||
|
|
fs.Dispose();
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("xmltoNc", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Uplaoads_Photo()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (!Directory.Exists(sLabelSavePhotoPaht))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(sLabelSavePhotoPaht);
|
|||
|
|
Console.WriteLine(sLabelSavePhotoPaht);
|
|||
|
|
}
|
|||
|
|
foreach (string item2 in new List<string> { sLabelSavePhotoPaht })
|
|||
|
|
{
|
|||
|
|
string[] files = Directory.GetFiles(item2);
|
|||
|
|
for (int j = 0; j < files.Length; j++)
|
|||
|
|
{
|
|||
|
|
File.Delete(files[j]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
FileStream fs_control = new FileStream(control, FileMode.Create, FileAccess.ReadWrite);
|
|||
|
|
iLangIndex = LNCAPI.memR(iServerIdx, 48000);
|
|||
|
|
if (iLangIndex == 0)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "Big5";
|
|||
|
|
}
|
|||
|
|
else if (iLangIndex == 1)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "GB2312";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "UTF8";
|
|||
|
|
}
|
|||
|
|
StreamWriter sw = new StreamWriter(fs_control, Encoding.GetEncoding(sLangEncoding));
|
|||
|
|
int control_Name = 0;
|
|||
|
|
foreach (string item in from s in Directory.GetFiles(ed_XML_Path.Text, "*.*", SearchOption.AllDirectories)
|
|||
|
|
where s.EndsWith(".bmp") || s.EndsWith(".png") || s.EndsWith(".jpg")
|
|||
|
|
select s)
|
|||
|
|
{
|
|||
|
|
string sRename = item.Split('\\')[item.Split('\\').Length - 1].Split('.')[0] + ".png";
|
|||
|
|
string AsPath = sLabelSavePaht + "\\" + sRename;
|
|||
|
|
string HMI_sRename = control_Name + ".png";
|
|||
|
|
string HMI_AsPath2 = sLabelSavePhotoPaht + "\\" + HMI_sRename;
|
|||
|
|
using (FileStream fs = new FileStream(item, FileMode.Open, FileAccess.Read))
|
|||
|
|
{
|
|||
|
|
Image image = Image.FromStream(fs);
|
|||
|
|
|
|||
|
|
image.Save(AsPath, ImageFormat.Png);
|
|||
|
|
image.Save(HMI_AsPath2, ImageFormat.Png);
|
|||
|
|
image.Dispose();
|
|||
|
|
}
|
|||
|
|
sw.WriteLine(sRename);
|
|||
|
|
sw.WriteLine(HMI_sRename);
|
|||
|
|
control_Name++;
|
|||
|
|
}
|
|||
|
|
sw.Dispose();
|
|||
|
|
fs_control.Dispose();
|
|||
|
|
string sIP = edIP.Text;
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
if (client.IsConnected)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < control_Name; i++)
|
|||
|
|
{
|
|||
|
|
_ = i + ".png";
|
|||
|
|
string PC_AsPath = sLabelSavePhotoPaht + "\\" + i + ".png";
|
|||
|
|
string HMI_AsPath = SysPhotoPath + "/" + i + ".png";
|
|||
|
|
client.UploadFile(PC_AsPath, HMI_AsPath);
|
|||
|
|
}
|
|||
|
|
string HMI_control = SysPhotoPath + "/control.txt";
|
|||
|
|
client.UploadFile(control, HMI_control);
|
|||
|
|
Directory.GetFiles(sLabelSavePaht);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("FTP连接失败!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Uplaoads_Photo", ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Downloads_Photo()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (!client.IsConnected)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (LNCAPI.memR(iServerIdx, 1390110) == 1)
|
|||
|
|
{
|
|||
|
|
foreach (string path in new List<string> { SysPhotoPath })
|
|||
|
|
{
|
|||
|
|
FtpListItem[] listing = client.GetListing(path);
|
|||
|
|
foreach (FtpListItem item in listing)
|
|||
|
|
{
|
|||
|
|
Console.WriteLine(item.Name);
|
|||
|
|
client.DownloadFile(sLabelSavePaht + "/" + item.Name, item.FullName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
if (LNCAPI.memR(iServerIdx, 1390110) == 2)
|
|||
|
|
{
|
|||
|
|
client.DownloadFile(sLabelSavePaht + "/Manual_Cut_Label.png", "home/disk3/data/open_hmi/photo/Manual_Cut_Label.png");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
WriteLog("Downloads_Photo", ex.Message.ToString());
|
|||
|
|
Console.WriteLine(ex.Message.ToString());
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string ConvertUTF8toBIG5(string strInput)
|
|||
|
|
{
|
|||
|
|
byte[] strut8 = Encoding.Unicode.GetBytes(strInput);
|
|||
|
|
byte[] strbig5 = Encoding.Convert(Encoding.Unicode, Encoding.Default, strut8);
|
|||
|
|
return Encoding.Default.GetString(strbig5);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public static string ConvertUTF8toGBK(string strInput)
|
|||
|
|
{
|
|||
|
|
byte[] strut8 = Encoding.Unicode.GetBytes(strInput);
|
|||
|
|
byte[] strgbk = Encoding.Convert(Encoding.Unicode, Encoding.Default, strut8);
|
|||
|
|
return Encoding.Default.GetString(strgbk);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ChangeLangEncoder()
|
|||
|
|
{
|
|||
|
|
iLangIndex = LNCAPI.memR(iServerIdx, 48000);
|
|||
|
|
if (iLangIndex == 0)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "Big5";
|
|||
|
|
}
|
|||
|
|
else if (iLangIndex == 1)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "GB2312";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "UTF8";
|
|||
|
|
}
|
|||
|
|
iNowLangIndex = iLangIndex;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Print_Count()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void GetPrintStatus()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Print_Status_Tick(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void check_connect_1_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
order = 0;
|
|||
|
|
check_connect_2.Checked = false;
|
|||
|
|
Data_Record();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void check_connect_2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
order = 1;
|
|||
|
|
check_connect_1.Checked = false;
|
|||
|
|
Data_Record();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Printer_selection_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
PrintDialog PD = new PrintDialog();
|
|||
|
|
PD.Document = printDocument1;
|
|||
|
|
DialogResult num = PD.ShowDialog();
|
|||
|
|
Printer_name = PD.PrinterSettings.PrinterName;
|
|||
|
|
if (num == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
Update_file_name();
|
|||
|
|
}
|
|||
|
|
Data_Record();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Update_file_name()
|
|||
|
|
{
|
|||
|
|
PrintDocument printDocument = new PrintDocument();
|
|||
|
|
Printer_path.Text = Printer_name;
|
|||
|
|
printDocument.PrinterSettings.PrinterName = Printer_name;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Data_Record()
|
|||
|
|
{
|
|||
|
|
FileStream fileStream = new FileStream(result + "\\data.txt", FileMode.Create, FileAccess.ReadWrite);
|
|||
|
|
StreamWriter streamWriter = new StreamWriter(fileStream);
|
|||
|
|
streamWriter.WriteLine(order);
|
|||
|
|
streamWriter.WriteLine(Printer_name);
|
|||
|
|
streamWriter.WriteLine(sLabelSavePaht);
|
|||
|
|
streamWriter.WriteLine(photo_path);
|
|||
|
|
streamWriter.Dispose();
|
|||
|
|
fileStream.Dispose();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Image_selection_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
FolderBrowserDialog LabelSavePaht = new FolderBrowserDialog();
|
|||
|
|
if (LabelSavePaht.ShowDialog() == DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
sLabelSavePaht = LabelSavePaht.SelectedPath;
|
|||
|
|
save_path.Text = LabelSavePaht.SelectedPath;
|
|||
|
|
Data_Record();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void photo_Up_Button_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
FolderBrowserDialog photo_Up_Path = new FolderBrowserDialog();
|
|||
|
|
if (photo_Up_Path.ShowDialog() != DialogResult.OK)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
photo_path = photo_Up_Path.SelectedPath;
|
|||
|
|
photo_path_Box.Text = photo_Up_Path.SelectedPath;
|
|||
|
|
Data_Record();
|
|||
|
|
FileStream fs_control = new FileStream(control, FileMode.Create, FileAccess.ReadWrite);
|
|||
|
|
iLangIndex = LNCAPI.memR(iServerIdx, 48000);
|
|||
|
|
if (iLangIndex == 0)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "Big5";
|
|||
|
|
}
|
|||
|
|
else if (iLangIndex == 1)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "GB2312";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "UTF8";
|
|||
|
|
}
|
|||
|
|
StreamWriter sw = new StreamWriter(fs_control, Encoding.GetEncoding(sLangEncoding));
|
|||
|
|
if (!Directory.Exists(sLabelSavePhotoPaht))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(sLabelSavePhotoPaht);
|
|||
|
|
Console.WriteLine(sLabelSavePhotoPaht);
|
|||
|
|
}
|
|||
|
|
string sIP = edIP.Text;
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
if (client.IsConnected)
|
|||
|
|
{
|
|||
|
|
photoshow.Image.Dispose();
|
|||
|
|
photoshow.Image = Image.FromFile(result + "\\test.png");
|
|||
|
|
FtpListItem[] listing = client.GetListing(SysPhotoPath);
|
|||
|
|
foreach (FtpListItem item2 in listing)
|
|||
|
|
{
|
|||
|
|
client.DeleteFile(item2.FullName);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("FTP连接失败!");
|
|||
|
|
}
|
|||
|
|
foreach (string item3 in new List<string> { sLabelSavePhotoPaht })
|
|||
|
|
{
|
|||
|
|
string[] files = Directory.GetFiles(item3);
|
|||
|
|
for (int j = 0; j < files.Length; j++)
|
|||
|
|
{
|
|||
|
|
File.Delete(files[j]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
iLangIndex = LNCAPI.memR(iServerIdx, 48000);
|
|||
|
|
if (iLangIndex == 0)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "Big5";
|
|||
|
|
}
|
|||
|
|
else if (iLangIndex == 1)
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "GB2312";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sLangEncoding = "UTF8";
|
|||
|
|
}
|
|||
|
|
sw = new StreamWriter(fs_control, Encoding.GetEncoding(sLangEncoding));
|
|||
|
|
int control_Name = 0;
|
|||
|
|
foreach (string item in from s in Directory.GetFiles(photo_path, "*.*", SearchOption.AllDirectories)
|
|||
|
|
where s.EndsWith(".bmp") || s.EndsWith(".png") || s.EndsWith(".jpg")
|
|||
|
|
select s)
|
|||
|
|
{
|
|||
|
|
string sRename = item.Split('\\')[item.Split('\\').Length - 1].Split('.')[0] + ".png";
|
|||
|
|
_ = sLabelSavePaht + "\\" + sRename;
|
|||
|
|
string HMI_sRename = control_Name + ".png";
|
|||
|
|
string HMI_AsPath2 = sLabelSavePhotoPaht + "\\" + HMI_sRename;
|
|||
|
|
using (FileStream fs = new FileStream(item, FileMode.Open, FileAccess.Read))
|
|||
|
|
{
|
|||
|
|
Image image = Image.FromStream(fs);
|
|||
|
|
image.Save(HMI_AsPath2, ImageFormat.Png);
|
|||
|
|
image.Dispose();
|
|||
|
|
sw.WriteLine(sRename);
|
|||
|
|
sw.WriteLine(HMI_sRename);
|
|||
|
|
control_Name++;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
sw.Dispose();
|
|||
|
|
fs_control.Dispose();
|
|||
|
|
Ftp_Connect(sIP);
|
|||
|
|
if (client.IsConnected)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < control_Name; i++)
|
|||
|
|
{
|
|||
|
|
_ = i + ".png";
|
|||
|
|
string PC_AsPath = sLabelSavePhotoPaht + "\\" + i + ".png";
|
|||
|
|
string HMI_AsPath = SysPhotoPath + "/" + i + ".png";
|
|||
|
|
client.UploadFile(PC_AsPath, HMI_AsPath);
|
|||
|
|
}
|
|||
|
|
string HMI_control = SysPhotoPath + "/control.txt";
|
|||
|
|
client.UploadFile(control, HMI_control);
|
|||
|
|
Directory.GetFiles(sLabelSavePaht);
|
|||
|
|
MessageBox.Show("上传完成!");
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
MessageBox.Show("FTP连接失败!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|