📄 subjectsetting.cs
字号:
this.txt6.ReadOnly = true;
this.txt6.Size = new System.Drawing.Size(184, 21);
this.txt6.TabIndex = 1;
this.txt6.Text = "";
//
// label6
//
this.label6.Location = new System.Drawing.Point(104, 168);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(100, 16);
this.label6.TabIndex = 0;
this.label6.Text = "助记码";
//
// label7
//
this.label7.Location = new System.Drawing.Point(104, 224);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(100, 16);
this.label7.TabIndex = 0;
this.label7.Text = "科目类别";
//
// label8
//
this.label8.Location = new System.Drawing.Point(104, 288);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(100, 16);
this.label8.TabIndex = 0;
this.label8.Text = "余额方向";
//
// comboBox2
//
this.comboBox2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "科目表.余额方向"));
this.comboBox2.Enabled = false;
this.comboBox2.Items.AddRange(new object[] {
"借方",
"贷方"});
this.comboBox2.Location = new System.Drawing.Point(104, 304);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(184, 20);
this.comboBox2.TabIndex = 2;
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;initial catalo" +
"g=caiwubook;persist security info=False";
//
// SubjectSetting
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(616, 469);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.groupBox1);
this.Name = "SubjectSetting";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "【科目设置】";
this.Load += new System.EventHandler(this.SubjectSetting_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//-------------显示窗体,填充数据------------
private void SubjectSetting_Load(object sender, System.EventArgs e)
{
//为数据集添加数据项浏览控制-
cmOrders=(CurrencyManager) BindingContext[dataSet11,"科目表"];
//读入全部数据
da1.SelectCommand.Parameters[0].Value="%%";
da1.SelectCommand.Parameters[1].Value="%%";
da1.SelectCommand.Parameters[2].Value="%%";
da1.Fill(dataSet11);
}
//----------根据输入搜索数据----------
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(txt1.Text.Trim()!="")
{
da1.SelectCommand.Parameters[0].Value="%"+txt1.Text.Trim()+"%";
}
if(txt2.Text.Trim()!="")
{
da1.SelectCommand.Parameters[1].Value="%"+txt2.Text.Trim()+"%";
}
if(txt3.Text.Trim()!="")
{
da1.SelectCommand.Parameters[2].Value="%"+txt3.Text.Trim()+"%";
}
//清空数据表,并根据新设置的查询参数重新填充
dataSet11.科目表.Clear();
da1.Fill(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();
//设置默认值
comboBox1.SelectedIndex=0;
comboBox2.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(txt4.Text.Trim()=="")//检查非空字段
{
MessageBox.Show("科目代码不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
if(txt5.Text.Trim()=="")
{
MessageBox.Show("科目名称不能为空","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
cmOrders.EndCurrentEdit();
if(dataSet11.GetChanges()!=null)
{
try
{
da1.Update(dataSet11);
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();
}
}
//--------------对控件的属性做设置---------------
private void SetModifyMode(bool blnEdit)
{
//设置文本框和下拉列表框属性
txt4.ReadOnly=!blnEdit;
txt5.ReadOnly=!blnEdit;
txt6.ReadOnly=!blnEdit;
comboBox1.Enabled=blnEdit;
comboBox2.Enabled=blnEdit;
//设置搜索按钮属性
btnSearch.Enabled=!blnEdit;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -