📄 form1.cs
字号:
this.label9.TabIndex = 24;
this.label9.Text = "职务:";
//
// JzSjTxt
//
this.JzSjTxt.Location = new System.Drawing.Point(344, 112);
this.JzSjTxt.Name = "JzSjTxt";
this.JzSjTxt.Size = new System.Drawing.Size(128, 21);
this.JzSjTxt.TabIndex = 27;
this.JzSjTxt.Text = "";
//
// label10
//
this.label10.Location = new System.Drawing.Point(280, 120);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(72, 16);
this.label10.TabIndex = 26;
this.label10.Text = "就职时间:";
//
// btn_search
//
this.btn_search.Location = new System.Drawing.Point(400, 16);
this.btn_search.Name = "btn_search";
this.btn_search.Size = new System.Drawing.Size(40, 23);
this.btn_search.TabIndex = 28;
this.btn_search.Text = "查找";
this.btn_search.Click += new System.EventHandler(this.btn_search_Click);
//
// XlTxt
//
this.XlTxt.Location = new System.Drawing.Point(400, 152);
this.XlTxt.Name = "XlTxt";
this.XlTxt.Size = new System.Drawing.Size(72, 21);
this.XlTxt.TabIndex = 30;
this.XlTxt.Text = "";
//
// label11
//
this.label11.Location = new System.Drawing.Point(360, 160);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(48, 16);
this.label11.TabIndex = 29;
this.label11.Text = "学历:";
//
// cmbzjmm
//
this.cmbzjmm.Items.AddRange(new object[] {
"团员",
"党员",
""});
this.cmbzjmm.Location = new System.Drawing.Point(232, 80);
this.cmbzjmm.Name = "cmbzjmm";
this.cmbzjmm.Size = new System.Drawing.Size(80, 20);
this.cmbzjmm.TabIndex = 31;
//
// label12
//
this.label12.Location = new System.Drawing.Point(24, 24);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(48, 16);
this.label12.TabIndex = 32;
this.label12.Text = "编号:";
//
// cmbnumber
//
this.cmbnumber.Location = new System.Drawing.Point(64, 16);
this.cmbnumber.Name = "cmbnumber";
this.cmbnumber.Size = new System.Drawing.Size(152, 20);
this.cmbnumber.TabIndex = 33;
this.cmbnumber.SelectedIndexChanged += new System.EventHandler(this.cmbnumber_SelectedIndexChanged);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 184);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(480, 160);
this.dataGrid1.TabIndex = 34;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(496, 358);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.cmbnumber);
this.Controls.Add(this.label12);
this.Controls.Add(this.cmbzjmm);
this.Controls.Add(this.XlTxt);
this.Controls.Add(this.label11);
this.Controls.Add(this.btn_search);
this.Controls.Add(this.JzSjTxt);
this.Controls.Add(this.label10);
this.Controls.Add(this.ZwTxt);
this.Controls.Add(this.label9);
this.Controls.Add(this.DmpTxt);
this.Controls.Add(this.label8);
this.Controls.Add(this.btn_amend);
this.Controls.Add(this.btn_delete);
this.Controls.Add(this.btn_add);
this.Controls.Add(this.btn_onload);
this.Controls.Add(this.btn_liulan);
this.Controls.Add(this.FileName);
this.Controls.Add(this.label7);
this.Controls.Add(this.JgTxt);
this.Controls.Add(this.label6);
this.Controls.Add(this.MinzuTxt);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.BirTxt);
this.Controls.Add(this.cmbsex);
this.Controls.Add(this.label2);
this.Controls.Add(this.TxtName);
this.Controls.Add(this.label1);
this.Controls.Add(this.label3);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.CmbBind();
}
private void CmbBind()
{
try
{
String strsql="select number from sun ";
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
this.cmbnumber.Items.Add(dr["number"].ToString());
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
//信息添加
private void btn_add_Click(object sender, System.EventArgs e)
{
try
{
String strsql="Insert into sun(name,sex,birth,zjmm,mz,jg,xueli,Dmp,zw,jztime) Values('"+this.TxtName.Text+"','"+this.cmbsex.SelectedItem.ToString()+"','"+this.BirTxt.Text+"','"+this.cmbzjmm.SelectedItem.ToString()+"','"+this.MinzuTxt.Text+"','"+this.JgTxt.Text+"','"+this.XlTxt.Text+"','"+this.DmpTxt.Text+"','"+this.ZwTxt.Text+"','"+this.JzSjTxt.Text+"')";
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
if(Convert.ToBoolean(cmd.ExecuteNonQuery()))
{
MessageBox.Show("添加成功");
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
private void btn_liulan_Click(object sender, System.EventArgs e)
{
if(this.openFileDialog1.ShowDialog()==DialogResult.OK)
{
this.FileName.Text=this.openFileDialog1.FileName;
this.path=this.openFileDialog1.FileName;
}
}
//图片上传
private void btn_onload_Click(object sender, System.EventArgs e)
{
try
{
SqlCommand cmd=new SqlCommand("insert into images(img_name) values(@data)",conn);
SqlParameter pa=new SqlParameter("@data",SqlDbType.Image);
FileStream fi=new FileStream(this.path,FileMode.Open,FileAccess.Read);
FileInfo f=new FileInfo(this.path);
byte[] a=new byte[(int)f.Length];
fi.Read(a,0,(int)f.Length);
pa.Value=a;
cmd.Parameters.Add(pa);
conn.Open();
if(Convert.ToBoolean(cmd.ExecuteNonQuery()))
{
MessageBox.Show("图片上传成功!");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
//信息修改
private void btn_amend_Click(object sender, System.EventArgs e)
{
try
{
String strsql="Update sun set name= '"+this.TxtName.Text+"',sex='"+this.cmbsex.SelectedItem.ToString()+"',birth='"+this.BirTxt.Text+"',zjmm='"+this.cmbzjmm.SelectedItem.ToString()+"',mz='"+this.MinzuTxt.Text+"',jg='"+this.JgTxt.Text+"',xueli='"+this.XlTxt.Text+"',Dmp='"+this.DmpTxt.Text+"',zw='"+this.ZwTxt.Text+"',jztime='"+this.JzSjTxt.Text+"' where number='"+this.cmbnumber.SelectedItem.ToString()+"'";
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
if(Convert.ToBoolean(cmd.ExecuteNonQuery()))
{
MessageBox.Show("修改成功!");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
//信息删除
private void btn_delete_Click(object sender, System.EventArgs e)
{
try
{
String strsql="delete sun where number='"+this.cmbnumber.SelectedItem.ToString()+"'";
SqlCommand cmd=new SqlCommand(strsql,conn);
conn.Open();
DialogResult result=MessageBox.Show(" 确定要删除吗?","删除提示!",MessageBoxButtons.YesNo);
if(result==DialogResult.Yes)
{
if(Convert.ToBoolean(cmd.ExecuteNonQuery()))
{
MessageBox.Show("删除成功!");
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
private void btn_search_Click(object sender, System.EventArgs e)
{
try
{
String strsql="select * from sun where name like '"+this.TxtName.Text+"'";
SqlDataAdapter da=new SqlDataAdapter(strsql,conn);
DataSet ds=new DataSet();
da.Fill(ds);
this.dataGrid1.DataSource=ds.Tables[0];
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
private void cmbnumber_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -