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

📄 stock.cs

📁 《C#数据库项目案例导航》一书的配套光盘
💻 CS
📖 第 1 页 / 共 4 页
字号:
				this.textStockRemark.Enabled=true;
				this.textStockPrice.Enabled=true;
				
			}
			else
			{
				this.textStockId.Enabled=false;
				this.textProviderId.Enabled=false;
				this.textProductId.Enabled=false;
				this.textProductName.Enabled=false;
				this.textProviderName.Enabled=false;												
				this.textProductSpecity.Enabled=false;
				this.textProductUnit.Enabled=false;				
				this.textStockAmount.Enabled=false;
				this.textStockDate.Enabled=false;				
				this.textStockRemark.Enabled=false;
				this.textStockPrice.Enabled=false;
			}
		}

		private void ButtonEnableControl(bool valid)
		{
			if(valid)
			{
				this.btnCancel.Enabled=true;
				this.btnApply.Enabled=true;
			}
			else
			{
				this.btnCancel.Enabled=false;
				this.btnApply.Enabled=false;
			}
		}
						
		private void LoadDataSet()
		{
			DataSetStock objDataSetTemp=new DataSetStock();
			try
			{
				this.FillDataSet(objDataSetTemp);

			}
			catch (System.Exception E) 
			{
				// 在此处添加错误处理代码。
				this.ErrorHandle(E);
			}
			try
			{
				this.objDataSetStock.Clear();
				this.objDataSetStock.Merge(objDataSetTemp);
			}
			catch(System.Exception E) 
			{
				// 在此处添加错误处理代码。
				this.ErrorHandle(E);
			}
			
		}
		
		private void FillDataSet(DataSetStock dataset)
		{
			dataset.EnforceConstraints=false;
			try
			{
				this.sqlConnection1.Open();
				this.sqlDataAdapterStock.Fill(dataset);
				this.sqlDataAdapterProduct.Fill(dataset);
				this.sqlDataAdapterProvider.Fill(dataset);
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
		
			finally
			{
				dataset.EnforceConstraints=true;
				this.sqlConnection1.Close();
			}
		}

		private void Stock_Load(object sender, System.EventArgs e)
		{
			this.LoadDataSet();
			this.DatasetPostionChange();
			this.ButtonPositonChange();
			this.TextEnableControl(false);
			this.ButtonEnableControl(false);
		
		}
		
		private void btnNext_Click(object sender, System.EventArgs e)
		{
			this.BindingContext[this.objDataSetStock,"Stock"].Position+=1;
			this.BindingContext[this.objDataSetStock,"Provider"].Position+=1;
			this.ButtonPositonChange();
			this.DatasetPostionChange();

		}
		

		private void btnPrevious_Click(object sender, System.EventArgs e)
		{
			this.BindingContext[this.objDataSetStock,"Stock"].Position-=1;
			this.ButtonPositonChange();
			this.DatasetPostionChange();
		
		}

		private void btnFirst_Click(object sender, System.EventArgs e)
		{
			this.BindingContext[this.objDataSetStock,"Stock"].Position=0;
			this.ButtonPositonChange();
			this.DatasetPostionChange();
		}

		private void btnLast_Click(object sender, System.EventArgs e)
		{
			this.BindingContext[this.objDataSetStock,"Stock"].Position=this.BindingContext[this.objDataSetStock,"Stock"].Count-1;
			this.ButtonPositonChange();
			this.DatasetPostionChange();
		}		

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.BindingContext[this.objDataSetStock,"Stock"].AddNew();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			this.DatasetPostionChange();
			this.ButtonPositonChange();	
			this.TextEnableControl(true);
			this.ButtonEnableControl(true);
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			if((this.BindingContext[this.objDataSetStock,"Stock"].Count>0)&
				(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
			{
				try
				{
					int currentPosition=this.BindingContext[this.objDataSetStock,"Stock"].Position;
					this.objDataSetStock.Stock.Rows[currentPosition].Delete();
				}
				catch(System.Exception E)
				{
					this.ErrorHandle(E);
				}
				this.ButtonPositonChange();
				this.DatasetPostionChange();
			}
			else
				return;
		}

		
		private void btnModify_Click(object sender, System.EventArgs e)
		{
			this.TextEnableControl(true);
			this.ButtonEnableControl(true);
		
		}

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

		
		}
		
		public void UpdateDataSet()
		{
			this.BindingContext[this.objDataSetStock,"Stock"].EndCurrentEdit();
			DataSetStock objDataSetTemp=new DataSetStock();
			objDataSetTemp=(DataSetStock)(this.objDataSetStock.GetChanges());
			try
			{
				this.UpdateDataSource(objDataSetTemp);
				this.objDataSetStock.Merge(objDataSetTemp);
				this.objDataSetStock.AcceptChanges();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
		}
		

		public void UpdateDataSource(DataSetStock Changerows)
		{
			try
			{
				this.sqlConnection1.Open();
				this.sqlDataAdapterStock.Update(Changerows);
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.sqlConnection1.Close();

			}	
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.UpdateDataSet();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}			
			this.ButtonPositonChange();
			this.DatasetPostionChange();
			this.TextEnableControl(false);
			this.ButtonEnableControl(false);
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.BindingContext[this.objDataSetStock,"Stock"].CancelCurrentEdit();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}			
			this.DatasetPostionChange();
			this.TextEnableControl(false);
			this.TextEnableControl(false);
			this.ButtonEnableControl(false);
			
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}	


	}
}

⌨️ 快捷键说明

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