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

📄 produceplan.cs

📁 生产管理系统 包括库存管理 销售管理 生产管理 日历管理 等功能
💻 CS
📖 第 1 页 / 共 5 页
字号:
			dataSet11.主生产计划.Clear();
			da1.Fill(dataSet11);
		}


		//------------根据物料编号查询并显示物料名称----------------
		private void txt1_TextChanged(object sender, System.EventArgs e)
		{			
			if(txt1.Text!="")
			{
				string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
				SqlConnection cn=new SqlConnection(strConn);
				cn.Open();
				SqlCommand cmd=cn.CreateCommand();
				cmd.CommandText="select 物料名称 from 物料主文件 where 物料编号='"+txt1.Text.Trim()+"'";
				txt4.Text=Convert.ToString(cmd.ExecuteScalar());
			}
			else
				txt4.Text="";
		}

		//------------调出窗体,选择物料--------------
		private void selBtn1_Click(object sender, System.EventArgs e)
		{
			SelectMaterial.callForm=2;
			SelectMaterial selFrm=new SelectMaterial();
			selFrm.ShowDialog();
			SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
		}
		//---------将选择得到的物料编号和名称填入文本框----------
		private void selBtn1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			txt1.Text=mID;
			txt4.Text=mName;
			SendKeys.Send("{Tab}");
		}
		//------------调出窗体,选择工厂日历--------------
		private void selBtn2_Click(object sender, System.EventArgs e)
		{
			FactorySchedule.callForm=2;//表示由主需求窗体调用
			FactorySchedule newFrm=new FactorySchedule();
			newFrm.closeToolbar();//该窗体仅供选择,不能编辑
			newFrm.Text+=",双击表格首列选择";
			newFrm.ShowDialog();
			SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件		
		}

		//---------将选择得到的工厂日历信息填入文本框----------
		private void selBtn2_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			txt2.Text=sYear;
			txt5.Text=sOrder;
			txt3.Text=sBegin;
			txt6.Text=sEnd;
		}

		//---------------设置工具栏操作--------------
		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if (e.Button.ToolTipText == "首记录")
			{
				this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行
				cmOrders.Position = 0;
				this.dataGrid1.Select(cmOrders.Position); //选中当前行
				this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标
				return;
				
			}
			if (e.Button.ToolTipText == "上一记录")
			{
				if (cmOrders.Position >= 0)
				{
					this.dataGrid1.UnSelect(cmOrders.Position); 
					cmOrders.Position--;
					this.dataGrid1.Select(cmOrders.Position);      
					this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
				}
				return;
			}
			if (e.Button.ToolTipText == "下一记录")
			{
				if (cmOrders.Position <= cmOrders.Count-1)
				{
					this.dataGrid1.UnSelect(cmOrders.Position); 
					cmOrders.Position++;
					this.dataGrid1.Select(cmOrders.Position);       
					this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
				}
				return;
			}
			if (e.Button.ToolTipText == "尾记录")
			{
				this.dataGrid1.UnSelect(cmOrders.Position); 
				cmOrders.Position = cmOrders.Count-1;
				this.dataGrid1.Select(cmOrders.Position);       
				this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
				return;
			}
			if(e.Button.ToolTipText=="新增")
			{		

				cmOrders.AddNew();
				txt15.Text="正常";//新增加的生产计划默认状态为正常,且不允许修改                				
				//设置按钮
				SetModifyMode(true);
			}
			if(e.Button.ToolTipText=="修改")
			{
				SetModifyMode(true);
			}
			if(e.Button.ToolTipText=="删除")
			{
				
				DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
				if(result==DialogResult.OK)
					if(cmOrders.Count>0)
						cmOrders.RemoveAt(cmOrders.Position);						
					else
						MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
			if(e.Button.ToolTipText=="提交")
			{
				if (this.txt1.Text.Trim() == "")//检查不能为空的字段
				{
					MessageBox.Show("请先选择物料!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
					return;
				}
				if (this.txt2.Text.Trim() == "")//检查不能为空的字段
				{
					MessageBox.Show("请先选择计划期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
					return;
				}
				
				if (this.txt12.Text.Trim() == "")//检查不能为空的字段
				{
					MessageBox.Show("MPS数量不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
					return;
				}
				
				cmOrders.EndCurrentEdit();//结束当前编辑操作并提交修改
				if (dataSet11.GetChanges()!=null)
				{
					try
					{
						this.da1.Update(dataSet11);
					}
					catch(Exception express)
					{
						MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
						dataSet11.RejectChanges();
					}
				}
				return;		
			}
			
			if (e.Button.ToolTipText == "取消")
			{
				try
				{
					cmOrders.CancelCurrentEdit();//取消编辑
					SetModifyMode(false);
				}
				catch(Exception express)
				{
					MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				return;
			}

			if(e.Button.ToolTipText=="退出")
			{
				if(dataSet11.HasChanges())
				{
					DialogResult result=MessageBox.Show("数据集有被修改但尚未提交的数据,是否提交?","确认",MessageBoxButtons.OKCancel);
					if(result==DialogResult.OK)
						da1.Update(dataSet11);
				}
				this.Close();
			}
		}
		//--------------对控件的Enable属性做设置---------------
		private void SetModifyMode(bool blnModify)
		{
			//设置文本框
			txt7.ReadOnly=!blnModify;
			txt12.ReadOnly=!blnModify;
			txt13.ReadOnly=!blnModify;
			txt14.ReadOnly=!blnModify;
			txt11.ReadOnly=!blnModify;
			
			txtMemo.ReadOnly=!blnModify;
			//设置表格的只读模式
			dataGrid1.ReadOnly=!blnModify;

			//编辑时不允许搜索数据
			btnSearch.Enabled=!blnModify;
			//允许使用选择按钮
			selBtn1.Enabled=blnModify;
			selBtn2.Enabled=blnModify;	

		}

		//--------------从主需求计划向主生长计划导入数据--------------
		private void importBtn_Click(object sender, System.EventArgs e)
		{
			string inOrder,inSec;//取得当前指向的主需求计划的物料编号和计划期数据
			inOrder=dataSet21.主需求计划.Rows[dataGrid2.CurrentRowIndex]["物料编号"].ToString().Trim();
			inSec=dataSet21.主需求计划.Rows[dataGrid2.CurrentRowIndex]["计划期"].ToString().Trim();
			//向主生产计划中导入
			string strConn = "server=localhost;Integrated Security=SSPI;database=mrpbook";
			SqlConnection cn=new SqlConnection(strConn);
			cn.Open();
			SqlCommand cmd=cn.CreateCommand();
			cmd.CommandText="insert into 主生产计划([物料编号], [年份], [计划期], [开始日期], [结束日期], [需求数量], [MPS数量], [状态], [备注]) select 物料编号,年份,计划期, 开始日期,结束日期,需求数量,需求数量,状态,备注 from 主需求计划"+" where (物料编号='"+inOrder+"')and(计划期='"+inSec+"')";
			int inResult=cmd.ExecuteNonQuery();
			if(inResult!=-1)//删除已经导入后的主需求计划中的数据
			{
				MessageBox.Show("从主需求计划向主生产计划导入数据成功!");
				cmd.CommandText="delete from 主需求计划"+" where (物料编号='"+inOrder+"')and(计划期='"+inSec+"')";
				cmd.ExecuteNonQuery();
				//刷新数据
				dataSet11.Clear();
				dataSet21.Clear();
				da1.Fill(dataSet11);
				da2.Fill(dataSet21);
			}			
		}
	}
}

⌨️ 快捷键说明

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