📄 factory.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using System.Net;
using System.Net.Sockets;
using System.Data.SqlServerCe;
using System.Text;
using System.IO;
using System.Threading;
using System.Resources;
using SocketCommunications.SocketScan;
using GXInputLibrary;
using PocketPC;
namespace Wholesale
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Frm_Main : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private SubStr Len;
private SocketScanner gScanner;
private bool ScanMode=true;//扫描模式
private string ScanData=null;//扫描数据
private int ScanSize=0;//扫描大小
//private System.Windows.Forms.Timer ScanTimer;//扫描时间
//private string symbology;
private int gTimerCounter = 0;
//private System.Windows.Forms.Timer demoScanTimer;
private System.Windows.Forms.Timer timer;
private int gDemoSecs = 0;
private string HCuppID = null;//终端隶属客户ID
private string ProductID = "";//获取扫描时的产品ID
private string Cuppid = "";//扫描客户的ID
private string Path = "";//贵重物品交易批此路径
private string MBID = null; //判断是手动交易还是扫描交易
private string THID = null; //手动输入时获取的产品ID
private string PKID = null;//手动输入时获取事物的包装层次ID
private double LGSL = 0.0; //手动输入信息时获取产品基类包装数量
private string JYLJ = "";
private GXInput g_mi=null;
private Thread t_thread=null;
private bool CloseThread=false;
private int WaitTime=500; //暂停等待时间
private string ServerIP="222.90.66.24";
private int ServerPort=9000;
private string DeviceID=""; //硬件ID
private string PassWord=""; //效验密码
private string IniFileName="NetSetup.ini"; //配置文件名
private int AddNum=1; //按键累加的数量
private string MsgTitle="提示";
private bool IsScan=true; //是否处于扫描状态
private bool IsExchange=true; //是否处于交易状态
private Notification Noti=new Notification();
private System.Windows.Forms.ComboBox TBox_ThName;
private System.Windows.Forms.ComboBox TBox_ClientID;
private System.Windows.Forms.TextBox MessageBOX;
private System.Windows.Forms.ComboBox TBox_Pack;
private System.Windows.Forms.TextBox TBox_Amount;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox TBox_IP;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox TBox_Port;
private System.Windows.Forms.Button Btn_OK;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label lb_Msg;
private System.Windows.Forms.Panel TPanel;
private System.Windows.Forms.Timer t=new System.Windows.Forms.Timer();
private ResourceManager rm=new ResourceManager("Wholesale.StringRes",Assembly.GetExecutingAssembly());
Bitmap MakeBitmap(Color color, int width, int height)
{
Bitmap bmp = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(new SolidBrush(color), 0, 0, bmp.Width, bmp.Height);
//g.DrawEllipse(new Pen(Color.DarkGray), 3, 3, width - 6, height - 6);
g.Dispose();
return bmp;
}
public Frm_Main()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//===============绘制图像按钮================================
PictureButton Btn_Exchange=new PictureButton(); //初始化图像按钮
Btn_Exchange.Parent=this;
Btn_Exchange.Bounds=new Rectangle(5,190,96,64);
Btn_Exchange.ForeColor=Color.Black;
Btn_Exchange.Text="确定";
Btn_Exchange.Font=new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold);
Btn_Exchange.BackgroundImage = MakeBitmap(Color.White, Btn_Exchange.Width, Btn_Exchange.Height);
Btn_Exchange.PressedImage = MakeBitmap(Color.LightBlue, Btn_Exchange.Width, Btn_Exchange.Height);
Btn_Exchange.Click+=new EventHandler(Btn_Exchange_Click);
PictureButton Btn_Scan=new PictureButton(); //初始化图像按钮
Btn_Scan.Parent=this;
Btn_Scan.Bounds=new Rectangle(110,180,120,80);
Btn_Scan.ForeColor=Color.Black;
Btn_Scan.Text="读取";
Btn_Scan.Font=new System.Drawing.Font("宋体", 21F, System.Drawing.FontStyle.Bold);
Btn_Scan.BackgroundImage = MakeBitmap(Color.White, Btn_Scan.Width, Btn_Scan.Height);
Btn_Scan.PressedImage = MakeBitmap(Color.LightBlue, Btn_Scan.Width, Btn_Scan.Height);
Btn_Scan.Click+=new EventHandler(Btn_Scan_Click);
//==============绘制结束=======================================
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.timer = new System.Windows.Forms.Timer();
this.TBox_ThName = new System.Windows.Forms.ComboBox();
this.TBox_ClientID = new System.Windows.Forms.ComboBox();
this.MessageBOX = new System.Windows.Forms.TextBox();
this.TBox_Pack = new System.Windows.Forms.ComboBox();
this.TBox_Amount = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.TPanel = new System.Windows.Forms.Panel();
this.lb_Msg = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.Btn_OK = new System.Windows.Forms.Button();
this.TBox_Port = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.TBox_IP = new System.Windows.Forms.TextBox();
//
// timer
//
this.timer.Interval = 1000;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// TBox_ThName
//
this.TBox_ThName.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular);
this.TBox_ThName.Location = new System.Drawing.Point(90, 40);
this.TBox_ThName.Size = new System.Drawing.Size(134, 28);
this.TBox_ThName.SelectedValueChanged += new System.EventHandler(this.TBox_ThName_SelectedValueChanged);
//
// TBox_ClientID
//
this.TBox_ClientID.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular);
this.TBox_ClientID.Location = new System.Drawing.Point(90, 12);
this.TBox_ClientID.Size = new System.Drawing.Size(134, 28);
//
// MessageBOX
//
this.MessageBOX.BackColor = System.Drawing.SystemColors.Window;
this.MessageBOX.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.MessageBOX.ForeColor = System.Drawing.Color.Black;
this.MessageBOX.Location = new System.Drawing.Point(2, 128);
this.MessageBOX.Multiline = true;
this.MessageBOX.Size = new System.Drawing.Size(236, 45);
this.MessageBOX.Text = "";
this.MessageBOX.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// TBox_Pack
//
this.TBox_Pack.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular);
this.TBox_Pack.Location = new System.Drawing.Point(90, 67);
this.TBox_Pack.Size = new System.Drawing.Size(134, 28);
this.TBox_Pack.SelectedValueChanged += new System.EventHandler(this.TBox_Pack_SelectedValueChanged);
//
// TBox_Amount
//
this.TBox_Amount.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular);
this.TBox_Amount.ForeColor = System.Drawing.SystemColors.Desktop;
this.TBox_Amount.Location = new System.Drawing.Point(90, 95);
this.TBox_Amount.Size = new System.Drawing.Size(134, 30);
this.TBox_Amount.Text = "1";
this.TBox_Amount.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TBox_Amount_KeyDown);
//
// label8
//
this.label8.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold);
this.label8.ForeColor = System.Drawing.SystemColors.ControlText;
this.label8.Location = new System.Drawing.Point(22, 98);
this.label8.Size = new System.Drawing.Size(71, 22);
this.label8.Text = "数 量";
//
// label6
//
this.label6.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold);
this.label6.ForeColor = System.Drawing.SystemColors.ControlText;
this.label6.Location = new System.Drawing.Point(22, 14);
this.label6.Size = new System.Drawing.Size(71, 22);
this.label6.Text = "商 家";
//
// label7
//
this.label7.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold);
this.label7.ForeColor = System.Drawing.SystemColors.ControlText;
this.label7.Location = new System.Drawing.Point(22, 70);
this.label7.Size = new System.Drawing.Size(71, 22);
this.label7.Text = "包 装";
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold);
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(22, 42);
this.label1.Size = new System.Drawing.Size(71, 22);
this.label1.Text = "事 物";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//
// label2
//
this.label2.ForeColor = System.Drawing.Color.White;
this.label2.Location = new System.Drawing.Point(4, 31);
this.label2.Size = new System.Drawing.Size(48, 24);
this.label2.Text = "IP地址:";
//
// TPanel
//
this.TPanel.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(64)), ((System.Byte)(0)));
this.TPanel.Controls.Add(this.lb_Msg);
this.TPanel.Controls.Add(this.label4);
this.TPanel.Controls.Add(this.Btn_OK);
this.TPanel.Controls.Add(this.TBox_Port);
this.TPanel.Controls.Add(this.label3);
this.TPanel.Controls.Add(this.TBox_IP);
this.TPanel.Controls.Add(this.label2);
this.TPanel.Location = new System.Drawing.Point(24, 152);
this.TPanel.Size = new System.Drawing.Size(184, 104);
this.TPanel.Visible = false;
//
// lb_Msg
//
this.lb_Msg.ForeColor = System.Drawing.Color.Red;
this.lb_Msg.Location = new System.Drawing.Point(8, 80);
this.lb_Msg.Size = new System.Drawing.Size(88, 20);
//
// label4
//
this.label4.ForeColor = System.Drawing.Color.White;
this.label4.Location = new System.Drawing.Point(0, 8);
this.label4.Size = new System.Drawing.Size(184, 20);
this.label4.Text = "请填入工厂通讯的IP地址和端口";
//
// Btn_OK
//
this.Btn_OK.Location = new System.Drawing.Point(104, 79);
this.Btn_OK.Text = "确定";
this.Btn_OK.Click += new System.EventHandler(this.Btn_OK_Click);
//
// TBox_Port
//
this.TBox_Port.Location = new System.Drawing.Point(50, 51);
this.TBox_Port.Text = "";
//
// label3
//
this.label3.ForeColor = System.Drawing.Color.White;
this.label3.Location = new System.Drawing.Point(4, 53);
this.label3.Size = new System.Drawing.Size(40, 16);
this.label3.Text = "端口:";
//
// TBox_IP
//
this.TBox_IP.Location = new System.Drawing.Point(50, 27);
this.TBox_IP.Size = new System.Drawing.Size(120, 21);
this.TBox_IP.Text = "";
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//
// Frm_Main
//
this.Controls.Add(this.TPanel);
this.Controls.Add(this.TBox_ThName);
this.Controls.Add(this.TBox_ClientID);
this.Controls.Add(this.MessageBOX);
this.Controls.Add(this.TBox_Pack);
this.Controls.Add(this.TBox_Amount);
this.Controls.Add(this.label8);
this.Controls.Add(this.label6);
this.Controls.Add(this.label7);
this.Controls.Add(this.label1);
this.Menu = this.mainMenu1;
this.Text = "工厂终端";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Frm_Main_Closing);
this.Load += new System.EventHandler(this.Frm_Main_Load);
this.Closed += new System.EventHandler(this.Frm_Main_Closed);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
static void Main()
{
Application.Run(new Frm_Main());
}
//---------------------------------------------------------函数区(LML ADD 2005-8-1)-----------------------------------------------
//write by lml 2005-8-2
//自动补零
//sName:传入需要补零的字符串
//i:传入需要的位数
//返回补零的字符串
static string BC(string sName,int i)
{
while(sName.Length<i)
{
sName="0"+sName;
}
return sName;
}
/// <summary>
/// 末尾补零
/// </summary>
/// <param name="sName"></param>
/// <param name="i"></param>
/// <returns></returns>
static string CB(string sName,int i)
{
while(sName.Length<i)
{
sName=sName+"0";
}
return sName;
}
/// <summary>
/// 返回PDA的硬件ID
/// </summary>
/// <returns></returns>
public string PDAID()
{
return DeviceID;
}
/// <summary>
/// 返回网络效验密码
/// </summary>
/// <returns></returns>
public string Pass()
{
return PassWord;
}
//生成头文件信息
//PDAID:硬件id
//FileName:文件名
//pass:口令
//other:其他信息
//返回128位头文件信息
static string HeaderMsg(string PDAID,string FileName,string Pass,string Other)
{
MD5 md5=new MD5();
return (string.Concat(BC(PDAID,30),BC(Pass,10),BC(Other,56),md5.MDFile(FileName)));
}
/// <summary>
/// 删除指定目录下的特定文件
/// </summary>
/// <param name="Path">指定的目录名</param>
/// <param name="Ext">指定的扩展名</param>
/// <param name="FileNameLength">文件名长度</param>
/// <returns></returns>
static void DeleteFiles(string Path,string Ext,int FileNameLength)
{
string[] sTemp=Directory.GetFiles(Path,Ext);
for(int i=0;i<sTemp.Length;i++)
{
int FileLength=sTemp[i].Length;
string sFile="";
for(int j=FileLength-1;j>=0;j--)
{
if(sTemp[i].Substring(j,1)=="\\")
{
sFile=sTemp[i].Substring(j+1);
break;
}
}
if(sFile.Length==FileNameLength)
File.Delete(sTemp[i]);
}
}
/// <summary>
/// 消息提示
/// </summary>
/// <param name="msg">提示的消息</param>
/// <param name="title">提示的标题</param>
/// <param name="time">提示的显示时间</param>
void MsgBox(string msg,string title,uint time)
{
t.Interval=(int)time*1000;
t.Enabled=true;
t.Tick+=new EventHandler(t_Tick);
Noti.RemoveLast();
Noti.Add(msg,title,time,IntPtr.Zero);
}
/// <summary>
/// 检查IP地址是否正确
/// </summary>
/// <param name="IP">需要检查的IP地址</param>
/// <returns>true:代表正确,false:代表不正确</returns>
private bool CheckIP(string IP)
{
if(IP.Length<7 || IP.Length>15)
return false;
int iNum=0;
char[] sep=new char[]{'.'};
try
{
foreach(string sTemp in IP.Split(sep))
{
if(iNum==4)
break;
if(Int32.Parse(sTemp)>255 || Int32.Parse(sTemp)<1)
return false;
iNum++;
}
return true;
}
catch(Exception)
{
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -