checkresult.cs

来自「固定资产的终端程序!里面有对数据的处理。 好东西」· CS 代码 · 共 610 行 · 第 1/2 页

CS
610
字号
							txtStartDate.Text=rdr.GetString(5).ToString();
							txtStatus.Text=rdr.GetString(6).ToString();
							UserID=rdr.GetString(7).ToString();
						}
						catch
						{
							E.Beep("",50,2670,2);
							E.MessageShow(true,"出现异常!"); 
							TxtClear();
						
							//====
							if(conn.State==ConnectionState.Open)
							{
								conn.Close();
							}
							//====

							return false;
						}
					}
					else
					{
						E.Beep("",50,2670,2);
						E.MessageShow(true,"没有找到关于条码:"+txtCode.Text.Trim()+"的数据!"); 		
						TxtClear();

						//====
						if(conn.State==ConnectionState.Open)
						{
							conn.Close();
						}
						//====

						return false;
					}
				}
				else
				{
					E.Beep("",50,2670,2);
					E.MessageShow(true,"查找数据失败,请重新查找!"); 		

					//====
					if(conn.State==ConnectionState.Open)
					{
						conn.Close();
					}
					//====

					return false;
				}
			}
			catch 
			{}
			finally
			{
				if (rdr!=null)
					rdr.Dispose();

				//====
				if(conn.State==ConnectionState.Open)
				{
					conn.Close();
				}
				//====
			}
			E.Beep("",150,2670,1);

			//====
			if(conn.State==ConnectionState.Open)
			{
				conn.Close();
			}
			//====
			return true;
		}
		private void code_OnGetCode(string str)
		{
			TxtClear();
			//str=str.Substring(3,str.Length-3);
			txtCode.Text=str;
			Query();
		}
		public void TxtClear()
		{
			txtCode.Text="";
			txtName.Text="";
			txtSpec.Text="";
			txtdepartment.Text="";
			txtManager.Text="";
			txtStatus.Text="";
			txtStartDate.Text="";
		}
		

		private void CheckResult_Load(object sender, System.EventArgs e)
		{
			code.Open();
			E.Focus(txtCode);
		}
		
		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.DialogResult=DialogResult.Cancel;
			Close();
		}

		private void CheckResult_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if ((e.KeyChar==(char)27) )
			{
				Close();
			}
			if ((e.KeyChar==(char)13) )
			{
				btnSave_Click(sender,e);
			}
		}

		private void CheckResult_Closed(object sender, System.EventArgs e)
		{
			code.Dispose();
		}
		private void CheckResult_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if ((e.KeyData==Keys.Left) )
			{
				Close();
			}
			if (e.KeyData==Keys.Right)
			{
				btnOut_Click(sender,e);
			}
			if (e.KeyData==Keys.F3)
			{
				btnQuery_Click(null,null);
			}
			if (e.KeyData==Keys.F2)
			{
				TxtClear();
				E.Focus(txtCode);
			}
			if (e.KeyData==Keys.F1)
			{
				btnModifyStatus_Click(sender,e);
			}
		}
		private void btnOut_Click(object sender, System.EventArgs e)
		{
			if (E.ExecSC("select Count(*) from Asset where UserID<>'0'")>0)
			{
				SaveFile.SavePDFile();
			}
			else
			{
				E.Beep("",50,2670,2);
				E.MessageShow(true,"没有数据!");//MessageBox.Show("没有数据!","信息",MessageBoxButtons.OK,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);
			}
		}

		private void btnSave_Click(object sender, System.EventArgs e)
		{
			if (txtCode.Text.Trim()=="")
			{
				E.Beep("",50,2670,2);
				E.MessageShow(true,"条码不能为空,请扫描或输入!");
				E.Focus(txtCode);
				return;
			}
			else
			{
				if ((UserID!="0")&&(UserID!=""))
				{
					E.Beep("",50,2670,2);
					E.MessageShow(true,"此资产已盘点过!");
					E.Focus(txtCode);
					return;
				}
				if (UserID=="")
				{
					E.Beep("",50,2670,2);
					E.MessageShow(true,"请扫描资产号!");
					E.Focus(txtCode);
					return;
				}
				if(E.ExecSQL("update Asset set UserID='"+Login.UserID+"' where BarCodes='"+txtCode.Text.Trim()+"'"))
				{
					TextWriter w=new StreamWriter("Platform\\DataBank\\AssetPD.txt",true,System.Text.Encoding.Default);
					w.WriteLine(txtCode.Text.Trim()+";"+Login.UserID); 
					w.Flush();
					w.Close();
					TxtClear();
				}
				else
				{
					E.Beep("",50,2670,2);
					E.MessageShow(true,"保存失败,请重新保存!");
					E.Focus(txtCode);
					return;
				}
			}
		}

		private void btnQuery_Click(object sender, System.EventArgs e)
		{
			Query();
		}

		private void btnModifyStatus_Click(object sender, System.EventArgs e)
		{
			if(txtCode.Text.Trim()=="" )
			{
				E.Beep("",50,2670,2);
				E.MessageShow(true,"条码不能空,请输入或扫描!"); 
				E.Focus(txtCode);
				return ;
			}
			if (UserID=="")
			{
				if(!Query())
				   return;
			}
			ChooseStatus chooseStatus=new ChooseStatus();
			try
			{
				if (chooseStatus.ShowDialog()==DialogResult.OK)
				{
					if (txtStatus.Text!=ChooseStatus.StatusName)
					if(E.ExecSQL("update Asset set Status='"+ChooseStatus.StatusName+"' where BarCodes='"+txtCode.Text.Trim()+"'"))
					{
						TextWriter w=new StreamWriter("Platform\\DataBank\\AssetZTTZ.txt",true,System.Text.Encoding.Default);
						w.WriteLine(txtCode.Text.Trim()+";"+ChooseStatus.StatusNo+";"+Login.UserID); 
						w.Flush();
						w.Close();
						SqlCeCommand cmd=null;
						try
						{
							cmd=E.conn.CreateCommand();
							cmd.CommandText="select Count(BarCodes) from ZTTZ where BarCodes='"+txtCode.Text.Trim()+"'";
							//MessageBox.Show(cmd.CommandText);
							if (E.conn.State==ConnectionState.Closed)
								E.conn.Open();
							int ICount=0;
							try
							{
								ICount=(int)cmd.ExecuteScalar();
							}
							catch{}
							if (ICount>0)
							{
								cmd.CommandText="update ZTTZ set Status='"+ChooseStatus.StatusNo+"',UserID='"+Login.UserID+"' where BarCodes='"+txtCode.Text.Trim()+"'";
								//MessageBox.Show(cmd.CommandText);
								try
								{
									cmd.ExecuteNonQuery();
								}
								catch
								{
									E.Beep("",50,2670,2);
									E.MessageShow(true,"保存失败,请重新保存!");
									return;
								}
							}
							else
							{
								cmd.CommandText="insert into ZTTZ(BarCodes,Status,UserID) values('"+txtCode.Text.Trim()+"','"+ChooseStatus.StatusNo+"','"+Login.UserID+"')";
								//MessageBox.Show(cmd.CommandText);
								try
								{
									cmd.ExecuteNonQuery();
								}
								catch
								{
									E.Beep("",50,2670,2);
									E.MessageShow(true,"保存失败,请重新保存!");
									return;
								}
							}
						}
						finally
						{
							if (cmd!=null)
								cmd.Dispose();
						}
						txtStatus.Text=ChooseStatus.StatusName;
					}
					else
					{
						E.Beep("",50,2670,2);
						E.MessageShow(true,"更改失败,请重新更改!");
						E.Focus(txtCode);
						return;
					}
				}
			}
			finally
			{
			    chooseStatus.Dispose();
			}
		}

		
		
	}
}

⌨️ 快捷键说明

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