302 lines
13 KiB
C#
302 lines
13 KiB
C#
using System;
|
||
using System.IO;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
using System.Runtime.InteropServices;
|
||
|
||
using Acrobat;
|
||
using DocumentTools;
|
||
using DrawToolsLib;
|
||
using AxAcroPDFLib;
|
||
using AcroPDFLib;
|
||
using iTextSharp.text.pdf;
|
||
|
||
using TmatrixLibrary;
|
||
|
||
namespace TmatrixCodeGenerator
|
||
{
|
||
public partial class Tmatrix_Form : Form
|
||
{
|
||
StreamReader gsr;
|
||
string TMXFileName, PDFFileName, gKeyStr;
|
||
TmatrixClass TMC = new TmatrixClass();
|
||
public static string gPrintFileName;
|
||
string gDirectory = Application.StartupPath;
|
||
string gFileName = "";
|
||
bool gbInitDone = false;
|
||
//string gUserName = "";
|
||
//string gPassword = "";
|
||
|
||
enum TMATRIX_POINT_TYPE
|
||
{
|
||
TmatrixPointType_2x2 = 0, // 2x2 Point Type
|
||
TmatrixPointType_3x3 = 1, // 3x3 Point Type
|
||
};
|
||
enum TMATRIX_OBJECT_TYPE
|
||
{
|
||
TMATRIX_OT_ElementCode = 0, // 此类型对象的Index范围是:75497472~83886079(十六进制为:0x04800000~0x04ffffff)
|
||
TMATRIX_OT_PositionCode, // 此类型对象没有Index
|
||
};
|
||
|
||
public Tmatrix_Form()
|
||
{
|
||
InitializeComponent();
|
||
if (TMC.TmatrixInitialize() == false)
|
||
{
|
||
MessageBox.Show(this, "Code Generator initialize fail !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
Close();
|
||
}
|
||
else
|
||
{
|
||
gbInitDone = true;
|
||
}
|
||
}
|
||
private void GenerateCode()
|
||
{
|
||
GenerateCode_Form dialog = new GenerateCode_Form();
|
||
dialog.ShowDialog();
|
||
if (GlobalClass.gbGenPageSet == false) return;
|
||
if (gbInitDone == false)
|
||
{
|
||
MessageBox.Show(this, "Code Generator initialize fail !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
int SPID = 0;
|
||
try
|
||
{
|
||
SPID = int.Parse(SPID_textBox.Text);
|
||
}
|
||
catch
|
||
{
|
||
MessageBox.Show(this, "Please input correct format for start page ID !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
MessageBox.Show(this, "Generating code...........", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
this.Hide();
|
||
//int PointType = (int)(TMATRIX_POINT_TYPE.TmatrixPointType_3x3);
|
||
//string sGenerateResult = TMC.GenerateTmatrixCode(gKeyStr, PDFFileName, SPID, PointType, GlobalClass.gbGenerateBGWithVImage, GlobalClass.gbGenerateVImage, GlobalClass.gbGenerateBGWithoutVImage, GlobalClass.gbGenerateBGWithImage);
|
||
bool[] bPublishImageType = new bool[4];
|
||
bPublishImageType[0] = GlobalClass.gbGenerateBGWithVImage;
|
||
bPublishImageType[1] = GlobalClass.gbGenerateVImage;
|
||
bPublishImageType[2] = GlobalClass.gbGenerateBGWithoutVImage;
|
||
bPublishImageType[3] = GlobalClass.gbGenerateBGWithImage;
|
||
|
||
string sGenerateResult = TMC.GenerateTmatrixCode_OID4(gKeyStr, PDFFileName, SPID, GlobalClass.gPointType, bPublishImageType, GlobalClass.gPointDPI);
|
||
if (sGenerateResult.Substring(0, 1) == "1")
|
||
{
|
||
this.Show();
|
||
MessageBox.Show(this, sGenerateResult.Substring(1, sGenerateResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
else if (sGenerateResult.Substring(0, 1) == "0")
|
||
{
|
||
gDirectory = Path.GetDirectoryName(PDFFileName);
|
||
gFileName = Path.GetFileName(PDFFileName);
|
||
/*
|
||
gDirectory += "\\";
|
||
string WFName = gFileName.Substring(0, gFileName.Length - 4) + "_*.PDF";
|
||
string[] files = Directory.GetFiles(@gDirectory, WFName);
|
||
int i;
|
||
string Pfile;
|
||
File_listBox.Items.Clear();
|
||
for (i = 0; i < files.Length; i++)
|
||
{
|
||
Pfile = Path.GetFileName(files[i]);
|
||
File_listBox.Items.Add(Pfile);
|
||
File_listBox.SelectedIndex = File_listBox.Items.Count - 1;
|
||
}
|
||
*/
|
||
this.Show();
|
||
MessageBox.Show(this, sGenerateResult.Substring(1, sGenerateResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
return;
|
||
|
||
}
|
||
private void GenerateCode_old()
|
||
{
|
||
GenerateCode_Form dialog = new GenerateCode_Form();
|
||
dialog.ShowDialog();
|
||
if (GlobalClass.gbGenPageSet == false) return;
|
||
if (gbInitDone == false)
|
||
{
|
||
MessageBox.Show(this, "Code Generator initialize fail !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
int SPID = 0;
|
||
try
|
||
{
|
||
SPID = int.Parse(SPID_textBox.Text);
|
||
}
|
||
catch
|
||
{
|
||
MessageBox.Show(this, "Please input correct format for start page ID !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
MessageBox.Show(this, "Generating code...........", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
this.Hide();
|
||
int PointType = (int)(TMATRIX_POINT_TYPE.TmatrixPointType_3x3);
|
||
string sGenerateResult = TMC.GenerateTmatrixCode(gKeyStr, PDFFileName, SPID, PointType, GlobalClass.gbGenerateBGWithVImage, GlobalClass.gbGenerateVImage, GlobalClass.gbGenerateBGWithoutVImage, GlobalClass.gbGenerateBGWithImage);
|
||
if (sGenerateResult.Substring(0, 1) == "1")
|
||
{
|
||
this.Show();
|
||
MessageBox.Show(this, sGenerateResult.Substring(1, sGenerateResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
else if (sGenerateResult.Substring(0, 1) == "0")
|
||
{
|
||
gDirectory = Path.GetDirectoryName(PDFFileName);
|
||
gFileName = Path.GetFileName(PDFFileName);
|
||
this.Show();
|
||
MessageBox.Show(this, sGenerateResult.Substring(1, sGenerateResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
return;
|
||
|
||
}
|
||
private void GenerateTmatrixCode_button_Click(object sender, EventArgs e)
|
||
{
|
||
GenerateCode();
|
||
}
|
||
|
||
private void SelectPDF_button_Click(object sender, EventArgs e)
|
||
{
|
||
OpenFileDialog OpenDlg = new OpenFileDialog();
|
||
OpenDlg.FileName = "";
|
||
OpenDlg.DefaultExt = "pdf";
|
||
OpenDlg.Filter = "PDF Files (*.pdf)|*.pdf";
|
||
if (OpenDlg.ShowDialog() == DialogResult.OK) {
|
||
PDFFileName = OpenDlg.FileName;
|
||
FName_textBox.Text = PDFFileName;
|
||
}
|
||
}
|
||
|
||
private void Exit_button_Click(object sender, EventArgs e)
|
||
{
|
||
Close();
|
||
}
|
||
private void SelectTmatrixKey_button_Click(object sender, EventArgs e)
|
||
{
|
||
OpenFileDialog OpenDlg = new OpenFileDialog();
|
||
OpenDlg.FileName = "";
|
||
OpenDlg.DefaultExt = "tmx";
|
||
OpenDlg.Filter = "TMX Files (*.tmx)|*.tmx";
|
||
if (OpenDlg.ShowDialog() == DialogResult.OK)
|
||
{
|
||
BID_textBox.Text = "";
|
||
PID1_textBox.Text = "";
|
||
PID2_textBox.Text = "";
|
||
Expiration_textBox.Text = "";
|
||
PDF_groupBox.Enabled = false;
|
||
PDFFileName = "";
|
||
TMXFileName = OpenDlg.FileName;
|
||
//MessageBox.Show(TMXFileName);
|
||
gsr = new StreamReader(TMXFileName);
|
||
gKeyStr = gsr.ReadLine();
|
||
gsr.Close();
|
||
string KeyCheckResult = TMC.TmatrixKeyCheck_OID4(gKeyStr);
|
||
|
||
if (KeyCheckResult.Substring(0, 1) == "1")
|
||
{
|
||
MessageBox.Show(this, KeyCheckResult.Substring(1, KeyCheckResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
else if (KeyCheckResult.Substring(0, 1) == "0")
|
||
{
|
||
string[] s = gKeyStr.Split(';');
|
||
string[] s1 = s[0].Split(',');
|
||
SID_textBox.Text = s1[0].Substring(1, 1);
|
||
OID_textBox.Text = s1[1].Substring(1, 3);
|
||
BID_textBox.Text = s1[2].Substring(1, 4);
|
||
PID1_textBox.Text = s1[3].Substring(1, 3);
|
||
PID2_textBox.Text = s1[3].Substring(5, 3);
|
||
Expiration_textBox.Text = s1[4].Substring(1, s1[4].Length - 1);
|
||
PDF_groupBox.Enabled = true;
|
||
}
|
||
}
|
||
}
|
||
private void Tmatrix_Form_FormClosing(object sender, FormClosingEventArgs e)
|
||
{
|
||
TMC.TmatrixUninitialize();
|
||
}
|
||
private void GeneratePartialCode()
|
||
{
|
||
GenerateCode_Form dialog = new GenerateCode_Form();
|
||
dialog.ShowDialog();
|
||
if (GlobalClass.gbGenPageSet == false) return;
|
||
if (gbInitDone == false)
|
||
{
|
||
MessageBox.Show(this, "Code Generator initialize fail !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||
return;
|
||
}
|
||
int SPID = 0;
|
||
try
|
||
{
|
||
SPID = int.Parse(SPID_textBox.Text);
|
||
}
|
||
catch
|
||
{
|
||
MessageBox.Show(this, "Please input correct format for start page ID !", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
return;
|
||
}
|
||
MessageBox.Show(this, "Generating code...........", "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
this.Hide();
|
||
//int PointType = (int)(TMATRIX_POINT_TYPE.TmatrixPointType_3x3);
|
||
|
||
//256 is for Total Pages, 10 is for partial area in each page, this is just a sample program, area no can be expanded by yourself.
|
||
UInt32[][] Tx = new UInt32[256][];
|
||
UInt32[][] Ty = new UInt32[256][];
|
||
UInt32[][] Tw = new UInt32[256][];
|
||
UInt32[][] Th = new UInt32[256][];
|
||
int i;
|
||
for (i = 0; i < 256; i++)
|
||
{
|
||
Tx[i] = new UInt32[10];
|
||
Ty[i] = new UInt32[10];
|
||
Tw[i] = new UInt32[10];
|
||
Th[i] = new UInt32[10];
|
||
}
|
||
Tx[0][0] = UInt32.Parse(X1_textBox.Text);
|
||
Tx[1][0] = UInt32.Parse(X2_textBox.Text);
|
||
Tx[2][0] = UInt32.Parse(X3_textBox.Text);
|
||
Ty[0][0] = UInt32.Parse(Y1_textBox.Text);
|
||
Ty[1][0] = UInt32.Parse(Y2_textBox.Text);
|
||
Ty[2][0] = UInt32.Parse(Y3_textBox.Text);
|
||
Tw[0][0] = UInt32.Parse(W1_textBox.Text);
|
||
Tw[1][0] = UInt32.Parse(W2_textBox.Text);
|
||
Tw[2][0] = UInt32.Parse(W3_textBox.Text);
|
||
Th[0][0] = UInt32.Parse(H1_textBox.Text);
|
||
Th[1][0] = UInt32.Parse(H2_textBox.Text);
|
||
Th[2][0] = UInt32.Parse(H3_textBox.Text);
|
||
Tw[0][1] = 0;
|
||
Tw[1][1] = 0;
|
||
Tw[2][1] = 0;
|
||
Th[0][1] = 0;
|
||
Th[1][1] = 0;
|
||
Th[2][1] = 0;
|
||
|
||
//string sGenerateResult = TMC.GenerateTmatrixCodeByArea(gKeyStr, PDFFileName, SPID, PointType, GlobalClass.gbGenerateBGWithVImage, GlobalClass.gbGenerateVImage, GlobalClass.gbGenerateBGWithoutVImage, GlobalClass.gbGenerateBGWithImage,Tx, Ty, Tw, Th);
|
||
string sGenerateResult = TMC.GenerateTmatrixCodeByArea_OID4(gKeyStr, PDFFileName, SPID, GlobalClass.gPointType, GlobalClass.gPointDPI, GlobalClass.gbGenerateBGWithVImage, GlobalClass.gbGenerateVImage, GlobalClass.gbGenerateBGWithoutVImage, GlobalClass.gbGenerateBGWithImage, Tx, Ty, Tw, Th);
|
||
if (sGenerateResult.Substring(0, 1) == "1")
|
||
{
|
||
this.Show();
|
||
MessageBox.Show(this, sGenerateResult.Substring(1, sGenerateResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||
}
|
||
else if (sGenerateResult.Substring(0, 1) == "0")
|
||
{
|
||
gDirectory = Path.GetDirectoryName(PDFFileName);
|
||
gFileName = Path.GetFileName(PDFFileName);
|
||
this.Show();
|
||
MessageBox.Show(this, sGenerateResult.Substring(1, sGenerateResult.Length - 1), "Code Generator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||
}
|
||
return;
|
||
|
||
}
|
||
|
||
private void GeneratePartialCode_button_Click(object sender, EventArgs e)
|
||
{
|
||
GeneratePartialCode();
|
||
}
|
||
}
|
||
}
|