📄 wholesale.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 System.Reflection;
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;
public bool CloseThread=false;
private int WaitTime=500;
private string ServerIP=""; //服务器IP地址
private int ServerPort=0; //服务器端口
private string DeviceID=""; //硬件ID
private string PassWord=""; //效验密码
private bool IsScan=true; //是否处于扫描状态
private bool IsExchange=true; //是否处于交易状态
private string MsgTitle="提示";
private Notification Noti=new Notification();
private System.Windows.Forms.Timer t=new System.Windows.Forms.Timer();
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 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();
//
// 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;
//
// Frm_Main
//
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,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);
}
private void Frm_Main_Load(object sender, System.EventArgs e)
{
MsgBox(rm.GetString("10001"),MsgTitle,2);
this.MinimizeBox=false;
OpenScanner();
if(!File.Exists("\\Windows\\启动\\Wholesale.lnk"))
{
char r='"';
StreamWriter sw=new StreamWriter("\\Windows\\启动\\Wholesale.lnk");
sw.WriteLine("100#"+r+"\\Program Files\\Wholesale\\Wholesale.exe"+r);
sw.Flush();
sw.Close();
}
g_mi=new GXInput();
g_mi.RegisterAllHardwareKeys();
t_thread=new Thread(new ThreadStart(ThreadProc));
t_thread.Priority=ThreadPriority.Lowest;
t_thread.Start();
CEData lo;
lo=new CEData();
SqlCeConnection conn=lo.conn;
//初始化终端机隶属客户
try
{
string SqlText=null;
SqlCeDataReader myReader=null;
SqlText = "SELECT TAGAI,TAGAJ,TAGAA,TAGAB,TAGAC,TAGAD FROM TAG";
SqlCeCommand cmd=new SqlCeCommand(SqlText,conn);
myReader=cmd.ExecuteReader();
myReader.Read();
HCuppID =myReader.GetValue(0).ToString(); //读取客户的ID
ServerIP=myReader.GetValue(3).ToString(); //读取通讯服务器的IP地址
ServerPort=Int32.Parse(myReader.GetValue(4).ToString()); //读取通讯服务器的端口
DeviceID=myReader.GetValue(2).ToString(); //读取硬件ID
PassWord=myReader.GetValue(5).ToString(); //读取效验密码
myReader.Close();
}
catch
{
conn.Dispose();
this.Close();
//return;
}
finally
{
conn.Dispose();
}
MBID = "OK";//判断是扫描还是手动交易方式
TBox_ClientID.Items.Clear();
TBox_ThName.Items.Clear();
Choose();//选择历史交易信息
GoNet();
}
public void ThreadProc()
{
EventHandler eh=new EventHandler(ScanKeys);
do
{
this.Invoke(eh);
Thread.Sleep(10);
}while(!CloseThread);
this.Invoke(new EventHandler(this.CloseMe));
}
//------------------------------------------------通讯部分 add by lml------------------------------------
private void GoNet()
{
if(!IsOnLine())
{
return;
}
//屏蔽按钮,防止连续按下
//MessageBOX.Text="请稍等...";
MsgBox(rm.GetString("10006"),MsgTitle,3);
//通讯状态
bool status=true;
//网络初始化
try
{
//CENet net=new CENet(TBox_Address.Text,Int32.Parse(TBox_Com.Text));
CENet net=new CENet(ServerIP,ServerPort);
//发送硬件ID,效验上次文件完整
if(!net.SendPKID(BC(PDAID(),30)))
status=false;
//重复连接的次数i;
if(status)
{
for(int i=0;i<4;i++)
{
if(i==3)
{
//错误,退出
status=false;
break;
}
string sTemp=net.RecCmd();
string sCmd=sTemp.Substring(0,5);
string sOldFile=sTemp.Substring(5,21);
if(sCmd.CompareTo("Suces")!=0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -