?? 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 + -