📄 customerform.cs
字号:
this.label5.Location = new System.Drawing.Point(16, 104);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(56, 16);
this.label5.TabIndex = 13;
this.label5.Text = "客户简称";
//
// textBox10
//
this.textBox10.Location = new System.Drawing.Point(88, 104);
this.textBox10.Name = "textBox10";
this.textBox10.Size = new System.Drawing.Size(112, 21);
this.textBox10.TabIndex = 12;
this.textBox10.Text = "";
//
// textBox9
//
this.textBox9.Location = new System.Drawing.Point(88, 144);
this.textBox9.Name = "textBox9";
this.textBox9.Size = new System.Drawing.Size(112, 21);
this.textBox9.TabIndex = 11;
this.textBox9.Text = "";
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(120, 232);
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(256, 21);
this.textBox8.TabIndex = 10;
this.textBox8.Text = "";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(88, 184);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(112, 21);
this.textBox7.TabIndex = 9;
this.textBox7.Text = "";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(312, 24);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(112, 21);
this.textBox6.TabIndex = 8;
this.textBox6.Text = "";
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(576, 16);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(112, 21);
this.textBox5.TabIndex = 7;
this.textBox5.Text = "";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(88, 64);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(112, 21);
this.textBox4.TabIndex = 6;
this.textBox4.Text = "";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(88, 16);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(112, 21);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(16, 64);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 16);
this.label4.TabIndex = 4;
this.label4.Text = "客户名称";
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 24);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 16);
this.label3.TabIndex = 2;
this.label3.Text = "客户编号:";
//
// customerForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(768, 549);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox2,
this.dataGrid1,
this.groupBox1,
this.toolBar1});
this.Name = "customerForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "[客户信息维护]";
this.Load += new System.EventHandler(this.customerForm_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void DataGridStateControl()
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.AlternatingBackColor = Color.LightGray;
ts.MappingName = this.ds.Tables[0].TableName;
ts.AllowSorting = false;
this.dataGrid1.TableStyles.Add(ts);
}
private void DataBingingsFunction()
{
this.textBox3.DataBindings.Add("Text",ds.Tables[0],"客户编号");
this.textBox4.DataBindings.Add("Text",ds.Tables[0],"客户名称");
this.textBox5.DataBindings.Add("Text",ds.Tables[0],"业务联系人");
this.textBox6.DataBindings.Add("Text",ds.Tables[0],"企业法人");
this.textBox7.DataBindings.Add("Text",ds.Tables[0],"邮政编码");
this.textBox8.DataBindings.Add("Text",ds.Tables[0],"客户地址");
this.textBox9.DataBindings.Add("Text",ds.Tables[0],"工商注册号");
this.textBox10.DataBindings.Add("Text",ds.Tables[0],"客户简称");
this.textBox11.DataBindings.Add("Text",ds.Tables[0],"银行帐号");
this.textBox12.DataBindings.Add("Text",ds.Tables[0],"电话");
this.textBox13.DataBindings.Add("Text",ds.Tables[0],"电子邮件");
this.textBox14.DataBindings.Add("Text",ds.Tables[0],"开户银行");
this.textBox15.DataBindings.Add("Text",ds.Tables[0],"传真");
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if (e.Button.ToolTipText == "首记录")
{
this.dataGrid1.UnSelect(cmAmend.Position); //取消选中指定行
cmAmend.Position = 0;
this.dataGrid1.Select(cmAmend.Position); //选中指定行
this.dataGrid1.CurrentRowIndex = cmAmend.Position; //移动表头指示图标
return;
}
if (e.Button.ToolTipText == "上一个记录")
{
if (cmAmend.Position > 0)
{
this.dataGrid1.UnSelect(cmAmend.Position);
cmAmend.Position--;
this.dataGrid1.Select(cmAmend.Position);
this.dataGrid1.CurrentRowIndex = cmAmend.Position;
}
return;
}
if (e.Button.ToolTipText == "下一个记录")
{
if (cmAmend.Position < cmAmend.Count-1)
{
this.dataGrid1.UnSelect(cmAmend.Position);
cmAmend.Position++;
this.dataGrid1.Select(cmAmend.Position);
this.dataGrid1.CurrentRowIndex = cmAmend.Position;
}
return;
}
if (e.Button.ToolTipText == "末记录")
{
this.dataGrid1.UnSelect(cmAmend.Position);
cmAmend.Position = cmAmend.Count-1;
this.dataGrid1.Select(cmAmend.Position);
this.dataGrid1.CurrentRowIndex = cmAmend.Position;
return;
}
if(e.Button.ToolTipText=="退出")
{
this.Close();
}
if (e.Button.ToolTipText == "新增记录")
{
cmAmend.AddNew();
return;
}
if (e.Button.ToolTipText == "删除记录")
{
if (MessageBox.Show(" 确实要删除这条记录吗?","询问",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
if (cmAmend.Count > 0)
cmAmend.RemoveAt(cmAmend.Position);
else
{
MessageBox.Show("没有可以删除的数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
return;
}
}
if (e.Button.ToolTipText == "保存修改")//保存对数据所作的修改
{
try
{
int row = this.dataGrid1.CurrentCell.RowNumber;
//将当前所在行往下移动一行,为便于实现同步保存
//(否则会出现修改的最后一行无法保存,因为它还处于编辑状态)
this.dataGrid1.CurrentCell = new DataGridCell(row+1,0);
if (this.ds.HasChanges())
{
this.link.UpdateDataBase(this.ds.GetChanges(),sendTableName);
MessageBox.Show("数据修改成功!","信息");
}
else
{
MessageBox.Show("没有需要修改的数据!");
return;
}
}
catch
{
MessageBox.Show("数据保存失败,请确认所有信息输入完整且正确!","提示");
return;
}
}
if (e.Button.ToolTipText == "提交记录")
{
if (this.textBox3.Text.Trim() == ""||this.textBox4.Text.Trim()==""||this.textBox5.Text.Trim()==""||this.textBox6.Text.Trim()==""||this.textBox7.Text.Trim()==""||this.textBox8.Text.Trim()==""||this.textBox9.Text.Trim()==""||this.textBox11.Text.Trim()==""||this.textBox12.Text.Trim()==""||this.textBox14.Text.Trim()=="")//检查不能为空的字段
{
MessageBox.Show("带*号的栏目不能为空!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
cmAmend.EndCurrentEdit();//结束当前编辑操作并提交修改
if (ds.GetChanges() != null)
{
try
{
this.link.UpdateDataBase(this.ds.GetChanges(),sendTableName);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
this.ds.Tables [0].RejectChanges();
}
}
return;
}
}
private void customerForm_Load(object sender, System.EventArgs e)
{
}
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);
ds.Tables[0].DefaultView.RowFilter = strRowFilter;
}
private void label7_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -