⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factory.cs

📁 WINCE数据库sqlce 通讯stock 代码
💻 CS
📖 第 1 页 / 共 5 页
字号:
						eHHP.ScanSendCommand("UPAAD21.");
						eHHP.ScanSendCommand("UPAAD51.");
					}

					Cursor.Current = Cursors.Default;
					break;
				case ScannerEventCodes.SCANNERREMOVED:
					//ScanTimer.Enabled = false;
					break;
				default:break;
			}
		}

		private void timer_Tick(object sender, System.EventArgs e)
		{
			if (!gScanner.ScannerInserted)
				return;
			gTimerCounter--;
			this.Text = "Scan " + Convert.ToString(gTimerCounter);
			if (gTimerCounter == 3)
				this.Text = "Data Cleared - Rescanning";
			else if (gTimerCounter == 0)
			{
				gTimerCounter = gDemoSecs;
				gScanner.TriggerScanner();
			}
		}

		//------------------------手动交易选择获取事物及客户信息(ZJNET ADD 2005.8.11)--------------------------------


		private void TBox_ThName_SelectedValueChanged(object sender, System.EventArgs e)
		{

			string SqlText;
			if (MBID == "OK")
			{
				CEData le;
				le=new CEData();
				SqlCeConnection conn=le.conn;
				
				TBox_Pack.Items.Clear();

				//读取事物产品ID
				try
				{
					SqlText=null;
					SqlCeDataReader myReader=null;
					SqlText = "SELECT TAIAA,TAIAB FROM TAI WHERE TAIAB = '"+TBox_ThName.Text.ToString()+"'";
					SqlCeCommand cmd=new SqlCeCommand(SqlText,conn);
					myReader=cmd.ExecuteReader();
					myReader.Read();
					THID = myReader.GetString(0);
					myReader.Close();
				}
				catch
				{
					//MessageBOX.Text=" 信息读取失败!";
					conn.Dispose();
				}
		  
				//读取事物包装信息
				try
				{
					if (THID.ToString() != "")
					{
						SqlText=null;
						SqlCeDataReader myReader=null;
						SqlText = "SELECT * FROM TAE WHERE TAEAA = '"+THID.ToString()+"'";
						SqlCeCommand cmd=new SqlCeCommand(SqlText,conn);
						myReader=cmd.ExecuteReader();
						while (myReader.Read())
						{
							TBox_Pack.Items.Add(myReader.GetString(2));
						}
						myReader.Close();

					}
				}
				catch
				{
					//MessageBOX.Text=" 信息读取失败!";
					conn.Dispose();
				}
				conn.Dispose();  
			}
		}

		private void TBox_Pack_SelectedValueChanged(object sender, System.EventArgs e)
		{
			string SqlText;
			if (MBID == "OK")
			{
				CEData lr;
				lr=new CEData();
				SqlCeConnection conn=lr.conn;
				
				//读取事物包装层次ID
				try
				{
					SqlText=null;
					SqlCeDataReader myReader=null;
					SqlText = "SELECT TAEAD,TAEAF FROM TAE WHERE TAEAB = '"+TBox_Pack.Text.ToString()+"'AND TAEAA = '"+THID+"'";
					SqlCeCommand cmd=new SqlCeCommand(SqlText,conn);
					myReader=cmd.ExecuteReader();
					myReader.Read();				
					PKID = myReader.GetString(0);//获取产品包装层次ID			
					LGSL = System.Convert.ToDouble(myReader.GetValue(1).ToString());//获取量纲数量
					myReader.Close();
				}
				catch
				{
					//MessageBOX.Text=" 信息读取失败!";
					conn.Dispose();
				}
				conn.Dispose();
			}
		}




		/// <summary>
		//---------------------------------write by 廖满亮------------------------------------

		private void Frm_Main_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			if(!CloseThread)
				e.Cancel=true;

			CloseThread=true;
			

		}

		
		private void CloseMe(object o, EventArgs e)
		{
			this.Close();
		}

		private void Frm_Main_Closed(object sender, System.EventArgs e)
		{
			t.Enabled=false;
			Noti.RemoveLast();
			g_mi.UnregisterAllHardwareKeys();
			if(SocketScanner.IsSocketScanRunning())
			{
				SocketScanner.StopSocketScan();

			}
			gScanner.Dispose();
			this.Dispose(true);
		}

		private void Btn_Exchange_Click(object sender, System.EventArgs e)
		{
			if(!IsExchange)
				return;

			IsExchange=false;
			try
			{
				MessageBOX.Text="";

				if(Edit()==true)  //判断交易信息是否完整
					return;

				if (MBID =="OK")
				{
					Manual();//执行手动交易过程

					MBID = null; //判断是手动交易还是扫描交易

					THID = null; //手动输入时获取的产品ID

					PKID = null; //手动输入时获取的产品包装层次ID

					LGSL = 0.0; //手动输入信息时获取产品基类包装数量

					
					TBox_ClientID.Items.Clear();
					TBox_ThName.Items.Clear();
					Clear(); //清屏
					MBID = "OK";//判断是扫描还是手动交易方式
					Choose();
					Thread.Sleep(2000);

				}
				else if(MBID =="NO")
				{
					Scan();
					TBox_ClientID.Items.Clear();
					TBox_ThName.Items.Clear();
					Clear();//清屏
					MBID = "OK";//判断是扫描还是手动交易方式
					Choose();
					//Thread.Sleep(2000);
				}
				Thread.Sleep(2000);
			}
			finally
			{
				IsExchange=true;
			}
		}

		private void Btn_Scan_Click(object sender, System.EventArgs e)
		{
			if(!IsScan)
				return;
					
			IsScan=false;
			try
			{
				MessageBOX.Text = "";
				if(ScanSize<40)
				{
					gScanner.TriggerScanner();
					Thread.Sleep(2000);
					
				}

				if(ScanSize>40)
				{
					Singularity();//异常信息的处理
					ScanData="";
					ScanSize=0;
					//return;
				}
				if(ScanSize==40)
				{				
					ScanData="";
					ScanSize=0;
					gScanner.TriggerScanner();
				}
			}
			finally
			{
				IsScan=true;
			}
		}
		public class PictureButton : Control
		{
			Image backgroundImage, pressedImage;
			bool pressed = false;

			// Property for the background image to be drawn behind the button text.
			public Image BackgroundImage
			{
				get
				{
					return this.backgroundImage;
				}
				set
				{
					this.backgroundImage = value;
				}
			}

			// Property for the background image to be drawn behind the button text when
			// the button is pressed.
			/// </summary>
			public Image PressedImage
			{
				get
				{
					return this.pressedImage;
				}
				set
				{
					this.pressedImage = value;
				}
			}

			// When the mouse is pressed, set the "pressed" flag = true and invalidate
			// to cause a repaint.  The Compact Framework sets the mouse capture automatically.
			protected override void OnMouseDown(MouseEventArgs e)
			{
				this.pressed = true;
				this.Invalidate();
				base.OnMouseDown (e);
			}

			// When the mouse is released, reset the "pressed" flag and invalidate to redraw the 
			// button in the un-pressed state.
			protected override void OnMouseUp(MouseEventArgs e)
			{
				this.pressed = false;
				this.Invalidate();
				base.OnMouseUp (e);
			}

			// Override the OnPaint method so we can draw the background image and the text.
			protected override void OnPaint(PaintEventArgs e)
			{
				if(this.pressed && this.pressedImage != null)
					e.Graphics.DrawImage(this.pressedImage, 0, 0);
				else
					e.Graphics.DrawImage(this.backgroundImage, 0, 0);

				// Draw the text if there is any.
				if(this.Text.Length > 0)
				{
					SizeF size = e.Graphics.MeasureString(this.Text, this.Font);

					// Center the text inside the client area of the PictureButton.
					e.Graphics.DrawString(this.Text,
						this.Font,
						new SolidBrush(this.ForeColor),
						(this.ClientSize.Width - size.Width) / 2,
						(this.ClientSize.Height - size.Height) / 2);
				}

				// Draw a border around the outside of the control to look like regular 
				// PPC buttons.
				e.Graphics.DrawEllipse(new Pen(Color.Black), 0, 0, 
					this.ClientSize.Width - 1, this.ClientSize.Height - 1);

				
				

				base.OnPaint(e);
			}
		}
		private void t_Tick(object sender, EventArgs e)
		{
			try
			{
				Noti.RemoveLast();
			}
			catch
			{
			}
			t.Enabled=false;
		}

		private void TBox_Amount_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			int iTemp=0;
			try
			{
				iTemp=Int32.Parse(TBox_Amount.Text);
			}
			catch(Exception)
			{
				iTemp=0;
			}
			if(e.KeyCode==Keys.Up)
			{
				iTemp+=AddNum;
				/*
				if(iTemp>20)
				{
					iTemp=1;
				}
				*/
				TBox_Amount.Text=iTemp.ToString();
			}
			if(e.KeyCode==Keys.Down)
			{
				iTemp-=AddNum;
				
				if(iTemp<1)
				{
					iTemp=1;
				}
				
				TBox_Amount.Text=iTemp.ToString();
			}
		}

		private void Btn_OK_Click(object sender, System.EventArgs e)
		{
			if(!CheckIP(TBox_IP.Text) || !CheckPort(TBox_Port.Text))
			{
				lb_Msg.Text="IP或端口错误!";
			}
			else
			{
				TPanel.Visible=false;
				lb_Msg.Text="";
				SaveToFile(TBox_IP.Text,TBox_Port.Text);
			}
		}
		/// <summary>
		/// 保存工厂通讯服务器的IP地址和端口
		/// </summary>
		/// <param name="IP">工厂的IP</param>
		/// <param name="Port">工厂的端口</param>
		/// <returns>true:保存成功,false:保存失败</returns>
		private bool SaveToFile(string IP,string Port)
		{
			StreamWriter sw=null;
			try
			{
				sw=new StreamWriter(IniFileName);
				sw.WriteLine(IP);
				sw.WriteLine(Port);
			}
			finally
			{
				sw.Close();
			}
			return true;
		}
		private string[] ReadFromFile(string FileName)
		{
			string[] result=new string[2]{"",""};
			if(File.Exists(FileName))
			{	
				StreamReader sr=null;
				try
				{
					sr=new StreamReader(FileName);
					result[0]=sr.ReadLine();
					result[1]=sr.ReadLine();
				}
				finally
				{
					sr.Close();
				}
			}
			return result;
		}
		/// <summary>
		/// 检验当前PDA是否处于通讯状态
		/// </summary>
		/// <returns>true:代表处于通讯中,false:代表处于离线中</returns>
		private bool IsOnLine()
		{
			string sTemp="";
			IPAddress[] addressList=null;
			try
			{
				addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;  
			}
			catch
			{
				return false;
			}
			for (int i = 0; i < addressList.Length; i ++) 
			{ 
				sTemp += addressList[i].ToString(); 
			}
			if(sTemp.CompareTo("127.0.0.1")==0)
			{
				return false;
			}
			else
			{
				return true;
			}
		}
       
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -