📄 factoryschedule.cs
字号:
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 16);
this.label4.TabIndex = 32;
this.label4.Text = "开始日期";
//
// label5
//
this.label5.Location = new System.Drawing.Point(392, 296);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(32, 16);
this.label5.TabIndex = 33;
this.label5.Text = "备注";
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tBtnFirst,
this.tBtnPre,
this.tBtnNext,
this.tBtnLast,
this.tBtnNew,
this.tBtnEdit,
this.tBtnDelete,
this.tBtnSubmit,
this.tBtnCancel,
this.tBtnQuit});
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(584, 41);
this.toolBar1.TabIndex = 34;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// tBtnFirst
//
this.tBtnFirst.ImageIndex = 0;
this.tBtnFirst.Text = "首记录";
this.tBtnFirst.ToolTipText = "首记录";
//
// tBtnPre
//
this.tBtnPre.ImageIndex = 1;
this.tBtnPre.Text = "上一记录";
this.tBtnPre.ToolTipText = "上一记录";
//
// tBtnNext
//
this.tBtnNext.ImageIndex = 2;
this.tBtnNext.Text = "下一记录";
this.tBtnNext.ToolTipText = "下一记录";
//
// tBtnLast
//
this.tBtnLast.ImageIndex = 3;
this.tBtnLast.Text = "尾记录";
this.tBtnLast.ToolTipText = "尾记录";
//
// tBtnNew
//
this.tBtnNew.ImageIndex = 4;
this.tBtnNew.Text = "新增";
this.tBtnNew.ToolTipText = "新增";
//
// tBtnEdit
//
this.tBtnEdit.ImageIndex = 5;
this.tBtnEdit.Text = "修改";
this.tBtnEdit.ToolTipText = "修改";
//
// tBtnDelete
//
this.tBtnDelete.ImageIndex = 6;
this.tBtnDelete.Text = "删除";
this.tBtnDelete.ToolTipText = "删除";
//
// tBtnSubmit
//
this.tBtnSubmit.ImageIndex = 7;
this.tBtnSubmit.Text = "提交";
this.tBtnSubmit.ToolTipText = "提交";
//
// tBtnCancel
//
this.tBtnCancel.ImageIndex = 8;
this.tBtnCancel.Text = "取消";
this.tBtnCancel.ToolTipText = "取消";
//
// tBtnQuit
//
this.tBtnQuit.ImageIndex = 9;
this.tBtnQuit.Text = "退出";
this.tBtnQuit.ToolTipText = "退出";
//
// txt5
//
this.txt5.Location = new System.Drawing.Point(432, 296);
this.txt5.Multiline = true;
this.txt5.Name = "txt5";
this.txt5.ReadOnly = true;
this.txt5.Size = new System.Drawing.Size(100, 104);
this.txt5.TabIndex = 35;
this.txt5.Text = "";
//
// FactorySchedule
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(584, 453);
this.Controls.Add(this.txt5);
this.Controls.Add(this.txt2);
this.Controls.Add(this.txt1);
this.Controls.Add(this.txt3);
this.Controls.Add(this.txt4);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.label5);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Controls.Add(this.label4);
this.Name = "FactorySchedule";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【工厂日历】";
this.Load += new System.EventHandler(this.FactorySchedule_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//----------初始化窗体时读入所有数据-------------
private void FactorySchedule_Load(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%";
da1.SelectCommand.Parameters[1].Value="%%";
da1.Fill(dataSet11);
tempTable=dataSet11.工厂日历.Copy();//保存一个备份,以便新增时获得最后一条数据
//为数据集添加数据项浏览控制
cmOrders=(CurrencyManager) BindingContext[dataSet11,"工厂日历"];
}
//------------工具栏事件处理代码---------------
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();
//设置非空字段的初始值
DataRow newRow=tempTable.Rows[tempTable.Rows.Count-1];//取最后一行的数据
txt1.Text=newRow["年份"].ToString();//年份与上一条记录相同,允许修改
int orderID=System.Convert.ToInt32(newRow["计划期"].ToString().Trim())+1;//计划期自动+1
txt2.Text=orderID.ToString();
int dateID=System.Convert.ToInt32(newRow["结束日期"].ToString().Trim())+2;//开始日期是上一次结束日期后的两天
txt3.Text=dateID.ToString();
txt4.Text=dateID.ToString();//结束日期不能为空,默认为与开始日期同一天
//设置按钮
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(txt4.Text.Trim()=="")//检查不能为空的字段,其他几个字段已经设置默认值
{
MessageBox.Show("请选择结束日期!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
cmOrders.EndCurrentEdit();//结束当前编辑状态
if(dataSet11.GetChanges()!=null)
{
try
{
da1.Update(dataSet11);
tempTable.Clear();//保存备份
tempTable=dataSet11.工厂日历.Copy();
SetModifyMode(false);
}
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;
txt2.ReadOnly=!blnModify;
txt3.ReadOnly=!blnModify;
txt4.ReadOnly=!blnModify;
txt5.ReadOnly=!blnModify;
//设置表格的只读模式
dataGrid1.ReadOnly=!blnModify;
//编辑时不允许搜索数据
btnSearch.Enabled=!blnModify;
}
//----------根据输入搜索数据----------
private void btnSearch_Click(object sender, System.EventArgs e)
{
da1.SelectCommand.Parameters[0].Value="%%";
da1.SelectCommand.Parameters[1].Value="%%";
//根据用户在文本框中的输入来设置SQL查询的参数
if(txt6.Text.Trim()!="")
{
da1.SelectCommand.Parameters[0].Value="%"+txt6.Text.Trim()+"%";
}
if(txt7.Text.Trim()!="")
{
da1.SelectCommand.Parameters[1].Value="%"+txt7.Text.Trim()+"%";
}
//清空数据表,并根据新设置的查询参数重新填充
dataSet11.工厂日历.Clear();
da1.Fill(dataSet11);
}
//---其他窗体调用时关闭工具栏,不允许数据修改----
public void closeToolbar()
{
toolBar1.Enabled=false;
}
//------其他窗体中选择工厂日历时,双击表格选择--------
private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
{
int i=dataGrid1.CurrentRowIndex;
if(callForm==1)//由主需求计划窗体调用
{
RequirePlan.sYear=dataSet11.工厂日历.Rows[i]["年份"].ToString().Trim();
RequirePlan.sOrder=dataSet11.工厂日历.Rows[i]["计划期"].ToString().Trim();
RequirePlan.sBegin=dataSet11.工厂日历.Rows[i]["开始日期"].ToString().Trim();
RequirePlan.sEnd=dataSet11.工厂日历.Rows[i]["结束日期"].ToString().Trim();
}
if(callForm==2)//由主生产计划窗体调用
{
ProducePlan.sYear=dataSet11.工厂日历.Rows[i]["年份"].ToString().Trim();
ProducePlan.sOrder=dataSet11.工厂日历.Rows[i]["计划期"].ToString().Trim();
ProducePlan.sBegin=dataSet11.工厂日历.Rows[i]["开始日期"].ToString().Trim();
ProducePlan.sEnd=dataSet11.工厂日历.Rows[i]["结束日期"].ToString().Trim();
}
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -