📄 requireplan.cs
字号:
//----------------设置工具栏处理代码---------------
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();
txt7.Text="0";//设置默认值
cm1.SelectedIndex=0;
//设置按钮
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.txt3.Text.Trim() == "")//检查不能为空的字段
{
MessageBox.Show("请先选择计划期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
if (this.txt7.Text.Trim() == "")//检查不能为空的字段
{
MessageBox.Show("需求数量不能为空!","提示",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)
{
//设置文本框
txt1.ReadOnly=!blnModify;
txt3.ReadOnly=!blnModify;
txt4.ReadOnly=!blnModify;
txt5.ReadOnly=!blnModify;
txt6.ReadOnly=!blnModify;
txt7.ReadOnly=!blnModify;
txtMemo.ReadOnly=!blnModify;
//设置表格的只读模式
dataGrid1.ReadOnly=!blnModify;
//编辑时不允许搜索数据
btnSearch.Enabled=!blnModify;
//允许使用选择按钮
selBtn1.Enabled=blnModify;
selBtn2.Enabled=blnModify;
//设置下拉列表框
cm1.Enabled=blnModify;
}
//---------------根据计划期等数据查询主需求计划信息---------------
private void btnSearch_Click(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%";
da1.SelectCommand.Parameters[1].Value="%%";
da1.SelectCommand.Parameters[2].Value="%%";
//根据用户在文本框中的输入来设置SQL查询的参数
if(txt8.Text.Trim()!="")
{
da1.SelectCommand.Parameters[0].Value="%"+txt8.Text.Trim()+"%";
}
if(txt9.Text.Trim()!="")
{
da1.SelectCommand.Parameters[1].Value="%"+txt9.Text.Trim()+"%";
}
if(txt10.Text.Trim()!="")
{
da1.SelectCommand.Parameters[2].Value="%"+txt10.Text.Trim()+"%";
}
//清空数据表,并根据新设置的查询参数重新填充
dataSet11.主需求计划.Clear();
da1.Fill(dataSet11);
}
//------------根据物料编号查询并显示物料名称----------------
private void txt1_TextChanged(object sender, System.EventArgs e)
{
if(txt1.Text!="")
{
string strConn="workstation id=localhost;packet size=4096;user id=sa;data source=NICOLAS;persist security info=False;initial catalog=mrpbook;";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
SqlCommand cmd=cn.CreateCommand();
cmd.CommandText="select 物料名称 from 物料主文件 where 物料编号='"+txt1.Text.Trim()+"'";
txt2.Text=Convert.ToString(cmd.ExecuteScalar());
}
else
txt2.Text="";
}
//------------调出窗体,选择物料--------------
private void selBtn1_Click(object sender, System.EventArgs e)
{
SelectMaterial.callForm=1;//表示由主需求计划窗体调用
SelectMaterial selFrm=new SelectMaterial();
selFrm.ShowDialog();
SendKeys.Send("{Tab}");//向活动应用程序发送Tab键,跳到下一控件
}
//---------将选择得到的物料编号和名称填入文本框----------
private void selBtn1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
txt1.Text=mID;
txt2.Text=mName;
SendKeys.Send("{Tab}");
}
//------------调出窗体,选择工厂日历--------------
private void selBtn2_Click(object sender, System.EventArgs e)
{
FactorySchedule.callForm=1;//表示由主需求窗体调用
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)
{
txt3.Text=sYear;
txt4.Text=sOrder;
txt5.Text=sBegin;
txt6.Text=sEnd;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -