📄 employeessform.cs
字号:
this.dataGrid2.Location = new System.Drawing.Point(0, 80);
this.dataGrid2.Name = "dataGrid2";
this.dataGrid2.Size = new System.Drawing.Size(464, 312);
this.dataGrid2.TabIndex = 2;
//
// groupBox2
//
this.groupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.textBox3,
this.label3});
this.groupBox2.Location = new System.Drawing.Point(0, 24);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(464, 48);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
//
// button2
//
this.button2.Image = ((System.Drawing.Bitmap)(resources.GetObject("button2.Image")));
this.button2.Location = new System.Drawing.Point(312, 16);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(32, 24);
this.button2.TabIndex = 2;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(168, 17);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(120, 21);
this.textBox3.TabIndex = 1;
this.textBox3.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(80, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 15);
this.label3.TabIndex = 0;
this.label3.Text = "管理员姓名";
//
// toolBar2
//
this.toolBar2.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton3,
this.toolBarButton4});
this.toolBar2.DropDownArrows = true;
this.toolBar2.ImageList = this.imageList1;
this.toolBar2.Name = "toolBar2";
this.toolBar2.ShowToolTips = true;
this.toolBar2.Size = new System.Drawing.Size(664, 25);
this.toolBar2.TabIndex = 0;
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 0;
this.toolBarButton3.ToolTipText = "保存修改";
//
// toolBarButton4
//
this.toolBarButton4.ImageIndex = 1;
this.toolBarButton4.ToolTipText = "删除";
//
// employeessForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(472, 423);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1});
this.Name = "employeessForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "[物流员工信息管理]";
this.Load += new System.EventHandler(this.employeessForm_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void tabPage1_Click(object sender, System.EventArgs e)
{
}
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = this.ds1.Tables[0].TableName;
ts.AllowSorting = false;
this.dataGrid1.TableStyles.Add(ts);
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button.ToolTipText == "保存修改")//保存对数据所作的修改
{
try
{
int row = this.dataGrid1.CurrentCell.RowNumber;
//将当前所在行往下移动一行,为便于实现同步保存
//(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
this.dataGrid1.CurrentCell = new DataGridCell(row+1,0);
if (this.ds1.HasChanges())
{
this.link1.UpdateDataBase(this.ds1.GetChanges(),sendTableName1);
MessageBox.Show("数据修改成功!","信息");
}
else
{
MessageBox.Show("没有需要修改的数据!");
return;
}
}
catch
{
MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
return;
}
}
if (e.Button.ToolTipText == "删除")//删除某条数据
{
if (MessageBox.Show("确实要删除这条记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int intRowNumber = this.dataGrid1.CurrentCell.RowNumber;
try
{
this.ds1.Tables[0].Rows[intRowNumber].Delete();
//此处传入只包含被改动过的DataRow的DataSet,减少更新数据量,提高程序性能
this.link1.UpdateDataBase(this.ds1.GetChanges(),sendTableName1);
MessageBox.Show("数据删除成功!","信息");
}
catch
{
MessageBox.Show("该数据不能删除!","提示");
string tempStrSQL = "select * from " + sendTableName1;
this.link1.SelectDataBase(tempStrSQL,sendTableName1);
return;
}
}
}
}
/*private void toolBar2_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button.ToolTipText == "保存修改")//保存对数据所作的修改
{
try
{
int row = this.dataGrid2.CurrentCell.RowNumber;
//将当前所在行往下移动一行,为便于实现同步保存
//(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
this.dataGrid2.CurrentCell = new DataGridCell(row+1,0);
if (this.ds2.HasChanges())
{
this.link2.UpdateDataBase(this.ds2.GetChanges(),sendTableName2);
MessageBox.Show("数据修改成功!","信息");
}
else
{
MessageBox.Show("没有需要修改的数据!");
return;
}
}
catch
{
MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
return;
}
}
if (e.Button.ToolTipText == "删除")//删除某条数据
{
if (MessageBox.Show("确实要删除这条记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
int intRowNumber = this.dataGrid2.CurrentCell.RowNumber;
try
{
this.ds2.Tables[0].Rows[intRowNumber].Delete();
//此处传入只包含被改动过的DataRow的DataSet,减少更新数据量,提高程序性能
this.link2.UpdateDataBase(this.ds2.GetChanges(),sendTableName2);
MessageBox.Show("数据删除成功!","信息");
}
catch
{
MessageBox.Show("该数据不能删除!","提示");
string tempStrSQL = "select * from " + sendTableName2;
this.link2.SelectDataBase(tempStrSQL,sendTableName2);
return;
}
}
}
}*/
private void button1_Click(object sender, System.EventArgs e)
{
string strRowFilter = "";
if(this.textBox1.Text.Trim() != "")//设置表的过滤条件
strRowFilter += "配送员姓名 like '%" + textBox1.Text.Trim() + "%' and ";
if(this.textBox2.Text.Trim() != "")
strRowFilter += "配送城市 like '%" + textBox2.Text.Trim() + "%' and ";
if(strRowFilter != "") // 存在查询条件
strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
ds1.Tables[0].DefaultView.RowFilter = strRowFilter;
}
/*private void button2_Click(object sender, System.EventArgs e)
{
string strRowFilter = "";
if(this.textBox3.Text.Trim() != "")//设置表的过滤条件
strRowFilter += "管理员姓名 like '%" + textBox3.Text.Trim() + "%' and ";
if(strRowFilter != "") // 存在查询条件
strRowFilter = strRowFilter.Substring(0,strRowFilter.Length-5);
ds2.Tables[0].DefaultView.RowFilter = strRowFilter;
}*/
private void employeessForm_Load(object sender, System.EventArgs e)
{
try
{
this.ds1 = link1.SelectDataBase(sendStrSQL1,sendTableName1);//创建数据库连接
dataGrid1.DataSource = ds1.Tables[0];
//this.ds2 = link2.SelectDataBase(sendStrSQL2,sendTableName2);
//dataGrid2.DataSource = ds2.Tables[0];
DataGridStateControl();
}
catch
{
MessageBox.Show("error","error");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -