📄 updata_man.cs
字号:
this.toolBarButton13.ImageIndex = 2;
this.toolBarButton13.Text = "保存";
this.toolBarButton13.ToolTipText = "保存";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// cob_sex
//
this.cob_sex.Location = new System.Drawing.Point(144, 152);
this.cob_sex.Name = "cob_sex";
this.cob_sex.Size = new System.Drawing.Size(121, 20);
this.cob_sex.TabIndex = 37;
//
// txt_qy
//
this.txt_qy.Location = new System.Drawing.Point(456, 112);
this.txt_qy.Name = "txt_qy";
this.txt_qy.Size = new System.Drawing.Size(112, 21);
this.txt_qy.TabIndex = 30;
this.txt_qy.Text = "";
//
// txt_lx
//
this.txt_lx.Location = new System.Drawing.Point(456, 144);
this.txt_lx.Name = "txt_lx";
this.txt_lx.Size = new System.Drawing.Size(112, 21);
this.txt_lx.TabIndex = 31;
this.txt_lx.Text = "";
//
// txt_sex
//
this.txt_sex.Location = new System.Drawing.Point(168, 152);
this.txt_sex.Name = "txt_sex";
this.txt_sex.Size = new System.Drawing.Size(112, 21);
this.txt_sex.TabIndex = 28;
this.txt_sex.Text = "";
//
// txt_sl
//
this.txt_sl.Location = new System.Drawing.Point(456, 72);
this.txt_sl.Name = "txt_sl";
this.txt_sl.TabIndex = 36;
this.txt_sl.Text = "";
//
// btn_sure
//
this.btn_sure.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
this.btn_sure.ForeColor = System.Drawing.Color.Blue;
this.btn_sure.Location = new System.Drawing.Point(240, 488);
this.btn_sure.Name = "btn_sure";
this.btn_sure.Size = new System.Drawing.Size(80, 24);
this.btn_sure.TabIndex = 21;
this.btn_sure.Text = "刷新";
this.btn_sure.Click += new System.EventHandler(this.btn_sure_Click);
//
// updata_man
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
this.ClientSize = new System.Drawing.Size(712, 533);
this.Controls.Add(this.txt_sl);
this.Controls.Add(this.txt_bz);
this.Controls.Add(this.txt_lx);
this.Controls.Add(this.txt_qy);
this.Controls.Add(this.txt_sex);
this.Controls.Add(this.txtname);
this.Controls.Add(this.txtID);
this.Controls.Add(this.toolBar3);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.btn_cancel);
this.Controls.Add(this.btn_sure);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.ForeColor = System.Drawing.Color.Blue;
this.MaximizeBox = false;
this.Name = "updata_man";
this.Text = "修改用户界面";
this.Load += new System.EventHandler(this.updata_man_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void btn_sure_Click(object sender, System.EventArgs e)
{
StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
string sn=sr.ReadLine();
SqlConnection conn=new SqlConnection(sn);
SqlDataAdapter da=new SqlDataAdapter("select * from dzxxb",conn);
DataSet ds=new DataSet();
da.Fill(ds,"dzxxb");
this.dataGrid1.SetDataBinding(ds,"dzxxb");
}
private void ClearFields()
{
this.txtID.Text="";
this.txtname.Text="";
this.txt_sex.Text="";
this.txt_lx.Text="";
this.txt_sl.Text="";
this.txt_qy.Text="";
this.txt_bz.Text="";
}
private void updata_man_Load(object sender, System.EventArgs e)
{
StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
string sn=sr.ReadLine();
SqlConnection conn=new SqlConnection(sn);
string sql="select * from dzxxb ";
SqlDataAdapter da=new SqlDataAdapter(sql,conn);
ds=new DataSet();
da.Fill(ds,"dzxxb");
// this.dataGrid1.SetDataBinding(ds,"dzxxb");
this.dataGrid1.DataSource=ds.Tables["dzxxb"].DefaultView;
SetModifyMode();
}
private void btn_cancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void SetModifyMode()
{
this.txtID.ReadOnly=true;
this.txt_sex.ReadOnly=true;
this.txtname.ReadOnly=true;
this.txt_sl.ReadOnly=true;
this.txt_qy.ReadOnly=true;
this.txt_lx.ReadOnly=true;
this.txt_bz.ReadOnly=true;
}
private void toolBar3_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button.Text=="保存")
{
StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
string sn=sr.ReadLine();
SqlConnection conn=new SqlConnection(sn);
try
{
SqlCommand comm=new SqlCommand("update_dzxxb",conn);
comm.CommandType=CommandType.StoredProcedure;
comm.Parameters.Add("@dzbh",(this.txtID.Text));
comm.Parameters.Add("@xm",(this.txtname.Text));
comm.Parameters.Add("@xb",(this.txt_sex.Text));
comm.Parameters.Add("@dzlb",(this.txt_lx.Text));
comm.Parameters.Add("@jssl",(this.txt_sl.Text));
comm.Parameters.Add("@jsqy",(this.txt_qy.Text));
comm.Parameters.Add("@bz",(this.txt_bz.Text));
conn.Open();
comm.ExecuteNonQuery();
ds.Tables["dzxxb"].Rows[this.dataGrid1.CurrentCell.RowNumber][1]=this.txtname.Text;
ds.Tables["dzxxb"].Rows[this.dataGrid1.CurrentCell.RowNumber][3]=this.txt_sl.Text;
ds.Tables["dzxxb"].Rows[this.dataGrid1.CurrentCell.RowNumber][4]=this.txt_qy.Text;
ds.Tables["dzxxb"].Rows[this.dataGrid1.CurrentCell.RowNumber][5]=this.txt_lx.Text;
MessageBox.Show("已经成功更新");
ClearFields();
}
catch(SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
if(e.Button.Text=="修改")
{
this.txt_sex.ReadOnly=false;
this.txtname.ReadOnly=false;
this.txt_sl.ReadOnly=false;
this.txt_qy.ReadOnly=false;
this.txt_lx.ReadOnly=false;
this.txt_bz.ReadOnly=false;
this.txtID.Focus();
StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
string sn=sr.ReadLine();
SqlConnection conn=new SqlConnection(sn);
SqlCommand comm=new SqlCommand("update_dzxxb",conn);
comm.Parameters.Add("@dzbh",(this.txtID.Text));
comm.Parameters.Add("@xm",(this.txtname.Text));
comm.Parameters.Add("@xb",(this.txt_sex.Text));
comm.Parameters.Add("@dzlb",(this.txt_lx.Text));
comm.Parameters.Add("@jssl",(this.txt_sl.Text));
comm.Parameters.Add("@jsqy",(this.txt_qy.Text));
comm.Parameters.Add("@bz",(this.txt_bz.Text));
}
}
private void dataGrid1_Click_1(object sender, System.EventArgs e)
{
int curRow=this.dataGrid1.CurrentCell.RowNumber;
this.txtID.Text=this.dataGrid1[this.dataGrid1.CurrentRowIndex,0].ToString();
this.txtname.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,1].ToString();
this.txt_sex.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,2].ToString();
this.txt_lx.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,5].ToString();
this.txt_sl.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,3].ToString();
this.txt_qy.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,4].ToString();
this.txt_bz.Text=this.dataGrid1[this.dataGrid1.CurrentCell.RowNumber,6].ToString();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -