📄 retail.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.Data.SqlServerCe;
using System.Text;
using System.IO;
using System.Threading;
using SocketCommunications.SocketScan;
using System.Reflection;
using System.Resources;
//添加.dll文件
using GXInputLibrary;
using PocketPC;
namespace Retail
{
/// <summary>
/// Retail 的摘要说明。
/// </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 System.Windows.Forms.Timer timer;//扫描时间
private int gDemoSecs = 0;
//private string symbology;
private int gTimerCounter = 0;
// ######################## ZJNET ADD VAR #############################
// #
private string HCuppID = "";//终端机隶属客户编号 #
private string Path = "";//事物路径信息 #
private string ProductID = "";//产品ID #
private string ProductName = "";//产品名称 #
private string PackID = "";//包装层次ID #
private string GZQZ = "";//贵重权值; #
private string LOOK = ""; //详查条件信息 #
private string Abnormity = "";//异常事物特征码 #
private string CharacterID = "";//128位事物特征码 #
private double NLG=0;//交易事物的基类包装数量 #
private double NPE=0;//本地终端机交易事物的配额数量
private string PDATA=""; //事物特征码(40位)
private string PackName=""; //包装层次名称
string stempTime=""; //事物的生产时间
// #
// ######################## ZJNET ADD VAR END #########################
private Thread mythread = null; //定义硬件按钮的线程
private GXInput g_mi = null;
public bool CloseThread=false; //线程停止标记
private int WaitTime=500; //暂停等待时间
private string ServerIP=""; //服务器IP地址
private int ServerPort=0; //服务器端口
private string DeviceID=""; //硬件ID
private string PassWord=""; //效验密码
private string MsgTitle="提示"; //提示消息标题
private System.Windows.Forms.TextBox TBox_Memo;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.TextBox TBox_Validity;
private System.Windows.Forms.TextBox TBox_StartTime;
private System.Windows.Forms.TextBox TBox_ThName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox MessageBOX;
private bool IsScan=true; //是否处于扫描状态
private Notification Noti=new Notification();
private System.Windows.Forms.Timer t=new System.Windows.Forms.Timer();
private ResourceManager rm=new ResourceManager("Retail.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_Scan=new PictureButton(); //初始化图像按钮
Btn_Scan.Parent=this;
Btn_Scan.Bounds=new Rectangle(8,215,225,50);
Btn_Scan.ForeColor=Color.Black;
Btn_Scan.Text="读取";
Btn_Scan.Font=new System.Drawing.Font("宋体", 25F, System.Drawing.FontStyle.Bold);
Btn_Scan.BackgroundImage = MakeBitmap(Color.Yellow, 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_Memo = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.TBox_Validity = new System.Windows.Forms.TextBox();
this.TBox_StartTime = new System.Windows.Forms.TextBox();
this.TBox_ThName = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.MessageBOX = new System.Windows.Forms.TextBox();
//
// timer
//
this.timer.Interval = 1000;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// TBox_Memo
//
this.TBox_Memo.BackColor = System.Drawing.Color.White;
this.TBox_Memo.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
this.TBox_Memo.ForeColor = System.Drawing.SystemColors.Desktop;
this.TBox_Memo.Location = new System.Drawing.Point(8, 42);
this.TBox_Memo.Multiline = true;
this.TBox_Memo.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.TBox_Memo.Size = new System.Drawing.Size(224, 96);
this.TBox_Memo.Text = "";
//
// label9
//
this.label9.Font = new System.Drawing.Font("楷体_GB2312", 14.25F, System.Drawing.FontStyle.Bold);
this.label9.ForeColor = System.Drawing.Color.Black;
this.label9.Location = new System.Drawing.Point(1, 117);
this.label9.Size = new System.Drawing.Size(71, 27);
this.label9.Text = "备注:";
this.label9.Visible = false;
//
// TBox_Validity
//
this.TBox_Validity.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));
this.TBox_Validity.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular);
this.TBox_Validity.ForeColor = System.Drawing.SystemColors.Desktop;
this.TBox_Validity.Location = new System.Drawing.Point(96, 87);
this.TBox_Validity.Size = new System.Drawing.Size(136, 21);
this.TBox_Validity.Text = "";
this.TBox_Validity.Visible = false;
//
// TBox_StartTime
//
this.TBox_StartTime.BackColor = System.Drawing.Color.White;
this.TBox_StartTime.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold);
this.TBox_StartTime.ForeColor = System.Drawing.SystemColors.Desktop;
this.TBox_StartTime.Location = new System.Drawing.Point(72, 146);
this.TBox_StartTime.Size = new System.Drawing.Size(160, 26);
this.TBox_StartTime.Text = "";
//
// TBox_ThName
//
this.TBox_ThName.BackColor = System.Drawing.Color.White;
this.TBox_ThName.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.TBox_ThName.ForeColor = System.Drawing.SystemColors.Desktop;
this.TBox_ThName.Location = new System.Drawing.Point(72, 8);
this.TBox_ThName.Size = new System.Drawing.Size(160, 30);
this.TBox_ThName.Text = "";
//
// label5
//
this.label5.Font = new System.Drawing.Font("楷体_GB2312", 14.25F, System.Drawing.FontStyle.Bold);
this.label5.ForeColor = System.Drawing.SystemColors.ControlText;
this.label5.Location = new System.Drawing.Point(0, 87);
this.label5.Size = new System.Drawing.Size(86, 22);
this.label5.Text = "有效期:";
this.label5.Visible = false;
//
// label4
//
this.label4.Font = new System.Drawing.Font("楷体_GB2312", 14.25F, System.Drawing.FontStyle.Bold);
this.label4.ForeColor = System.Drawing.SystemColors.ControlText;
this.label4.Location = new System.Drawing.Point(0, 149);
this.label4.Size = new System.Drawing.Size(96, 23);
this.label4.Text = "有效期";
//
// label1
//
this.label1.Font = new System.Drawing.Font("楷体_GB2312", 14.25F, System.Drawing.FontStyle.Bold);
this.label1.ForeColor = System.Drawing.SystemColors.ControlText;
this.label1.Location = new System.Drawing.Point(4, 11);
this.label1.Size = new System.Drawing.Size(56, 24);
this.label1.Text = "事物";
//
// MessageBOX
//
this.MessageBOX.Font = new System.Drawing.Font("宋体", 18F, System.Drawing.FontStyle.Bold);
this.MessageBOX.Location = new System.Drawing.Point(8, 176);
this.MessageBOX.Multiline = true;
this.MessageBOX.Size = new System.Drawing.Size(224, 35);
this.MessageBOX.Text = "";
this.MessageBOX.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.MessageBOX.WordWrap = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
//
// Frm_Main
//
this.Controls.Add(this.MessageBOX);
this.Controls.Add(this.TBox_Memo);
this.Controls.Add(this.label9);
this.Controls.Add(this.TBox_Validity);
this.Controls.Add(this.TBox_StartTime);
this.Controls.Add(this.TBox_ThName);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
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;
}
//末尾补0
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,int time)
{
t.Interval=time*1000;
t.Enabled=true;
t.Tick+=new EventHandler(t_Tick);
Noti.RemoveLast();
Noti.Add(msg,title,(uint)time,IntPtr.Zero);
}
//######################################################################### LML END ########################################################################
//############################################################主过程方法定义区(ZJNET ADD 2005-8-1)###################################################################################################
//--------------------------------------判断事物交易信息加载是否完整 ZJNET 2005.8.1--------------------------------------------------------------
private bool Edit()//
{
if (TBox_ThName.Text.Length==0)
{
//MessageBOX.Text=" 事物信息加载错误!";
return false;
}
else
return true;
}
//---------------------------------------------------------------END--------------------------------------------------------------------------------
//-----------------------------------------------------交易后的清屏过程 ZJNET 2005.8.1---------------------------------------------------------------
private void Clear()
{
TBox_ThName.Text="";
TBox_Validity.Text="";
TBox_StartTime.Text="";
TBox_Memo.Text = "";
}
//---------------------------------------------------------------END--------------------------------------------------------------------------------
//------------------------------------------------------异常信息的处理 ZJNET 2005.8.1---------------------------------------------------------------
private void Singularity()
{
CEData lo;
lo=new CEData();
string SqlText;
SqlCeConnection conn=lo.conn;
try
{
SqlText = "INSERT INTO TAB (TABAA,TABAB,TABAD,TABAF) VALUES ('"+Abnormity+"','"+DeviceID+"','"+DateTime.Now+"',0)";
lo.ExeSQLNO(SqlText);
//MessageBOX.Text=" 异常信息已被记录!";
//MsgBox(rm.GetString("10004"),MsgTitle,3);
}
catch
{
conn.Dispose();
}
conn.Dispose();
}
//---------------------------------------------------------------END--------------------------------------------------------------------------------
//----------------------------------------//扫描条码信息转换为128位的二进制字符串 ZJNET 2005.8.1-------------------------------------------------------
private string Bit(string BarCode)
{
Conver rd = new Conver();
string Code=null;
string Str61,Str64;
Str61 = rd.dtb(BarCode.Substring(0,19)).ToString();
Str64 = rd.dtb(BarCode.Substring(19,19)).ToString();
int N = Str61.Length;
int M = Str64.Length;
for (int i=0;i<61-N;i++)
{
Str61 = "0" + Str61.ToString();
}
for (int j=0;j<63-M;j++)
{
Str64 = "0" + Str64.ToString();
}
Code = Str61.ToString() + Str64.ToString();
return Code;
}
//---------------------------------------------------------------END--------------------------------------------------------------------------------
//---------------------------------根据扫描的条码从数据库中获取信息数据(ZJNET ADD 2005.8.1)----------------------------------
private void GetparmInfo()
{
Len = new SubStr();
PDATA = ScanData;//获取40位事物特征码 string
CharacterID = Bit(ScanData);//获取128位事物特征码
ProductID = Len.SubProductID(CharacterID);//获取产品ID
PackID = Len.SubPack(CharacterID);//获取产品包装层次ID
GZQZ = Len.SubCostly(CharacterID);//获取贵重权值
LOOK = CharacterID.Substring(0,50);//获取详查信息
Business();//执行事物交易过程
}
//---------------------------------------------------------------END--------------------------------------------------------------------------------
//--------------------------------- 获取产品名称 (ZJNET ADD 2005.9.13)----------------------------------------------------------
private bool GetProduct()
{
bool IsExit=false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -