📄 form2.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 团委组织部信息系统
{
public partial class Form2 : Form
{
SqlDataAdapter da;
DataSet ds;
string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
public Form2()
{
InitializeComponent();
}
SqlConnection sqlConnection1;
private void Form2_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“tuanweizuzhibu_infDataSet.bumenshezhi_inf”中。您可以根据需要移动或移除它。
this.bumenshezhi_infTableAdapter.Fill(this.tuanweizuzhibu_infDataSet.bumenshezhi_inf);
// TODO: 这行代码将数据加载到表“tuanweizuzhibu_infDataSet.liuyan_inf”中。您可以根据需要移动或移除它。
// TODO: 这行代码将数据加载到表“tuanweizuzhibu_infDataSet.work_inf”中。您可以根据需要移动或移除它。
this.work_infTableAdapter.Fill(this.tuanweizuzhibu_infDataSet.work_inf);
// TODO: 这行代码将数据加载到表“tuanweizuzhibu_infDataSet.erjibuzhang_inf”中。您可以根据需要移动或移除它。
// TODO: This line of code loads data into the 'tuanweizuzhibu_infDataSet.tuanweibuzhang_inf' table. You can move, or remove it, as needed.
this.tuanweibuzhang_infTableAdapter.Fill(this.tuanweizuzhibu_infDataSet.tuanweigebu_inf);
// TODO: This line of code loads data into the 'tuanweizuzhibu_infDataSet.zuzhibu_inf' table. You can move, or remove it, as needed.
this.zuzhibu_infTableAdapter.Fill(this.tuanweizuzhibu_infDataSet.zuzhibu_inf);
String connString = "Data Source=.;Initial Catalog= tuanweizuzhibu_inf; Integrated Security= True";
sqlConnection1 = new System.Data.SqlClient.SqlConnection(connString);
Cl();
}
private void 团委组织部ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e) //组织部信息查询
{
string connectionstring1 = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
string commandstring1 = @"select * from zuzhibu_inf where 学号 like'%" + textBox1.Text + "%'or 姓名 like'%" + textBox1.Text + "%' or 学院 like'%" + textBox1.Text + "%'or 专业 like'%" + textBox1.Text + "%'or 班级 like'%" + textBox1.Text + "%'or 手机号码 like'%" + textBox1.Text + "%'or 寝室号 like'%" + textBox1.Text + "%'or 寝室电话 like'%" + textBox1.Text + "%'or 职务 like'%" + textBox1.Text + "%'";
da = new SqlDataAdapter(commandstring1, connectionstring1);
ds = new DataSet();
da.Fill(ds, "zuzhibu_inf");
dataGridView2.DataSource = ds.Tables["zuzhibu_inf"];
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e) //团委各部门信息查询
{
int i = comboBox2.SelectedIndex;
SqlCommand sqlcmd = new SqlCommand();
switch (i)
{
case 0: sqlcmd.CommandText = "select * from tuanweigebu_inf where 学号= @ID"; break;
case 1: sqlcmd.CommandText = "select * from tuanweigebu_inf where 姓名= @ID"; break;
case 2: sqlcmd.CommandText = "select * from tuanweigebu_inf where 学院= @ID"; break;
case 4: sqlcmd.CommandText = "select * from tuanweigebu_inf where 班级= @ID"; break;
case 5: sqlcmd.CommandText = "select * from tuanweigebu_inf where 所属部门= @ID"; break;
case 6: sqlcmd.CommandText = "select * from tuanweigebu_inf where 担任职务= @ID"; break;
case 7: sqlcmd.CommandText = "select * from tuanweigebu_inf where 手机号码= @ID"; break;
}
sqlcmd.Parameters.AddWithValue("@ID", textBox2.Text);
sqlConnection1.Open();
sqlcmd.Connection = sqlConnection1;
SqlDataAdapter sa = new SqlDataAdapter();
sa.SelectCommand = sqlcmd;
DataSet ds = new DataSet();
sa.Fill(ds, "tuanweigebu_inf");
dataGridView1.DataSource = ds.Tables["tuanweigebu_inf"];
sqlConnection1.Close();
}
private void Cl() //关闭所有的GroupBox
{
groupBox1.Visible = false;
groupBox2.Visible = false;
groupBox3.Visible = false;
groupBox4.Visible = false;
groupBox5.Visible = false;
groupBox6.Visible = false;
}
private void 成员信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
Cl();
groupBox1.Visible = true;
}
private void 部门设置ToolStripMenuItem_Click(object sender, EventArgs e)
{
Cl();
groupBox3.Visible = true;
}
private void 成员信息更新ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.Show();
}
private void 部门成员信息管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form4 f4 = new Form4();
f4.Show();
}
private void 部长信息管理ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form6 f6 = new Form6();
f6.Show();
}
private void button3_Click(object sender, EventArgs e)
{
string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
string commandstring = @"select * from erjibuzhang_inf where colleage like'" + comboBox3.Text + "'";
da = new SqlDataAdapter(commandstring, connectionstring);
ds = new DataSet();
da.Fill(ds, "erjibuzhang_inf");
dataGridView3.DataSource = ds.Tables["erjibuzhang_inf"];
}
private void 部长信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
Cl();
groupBox2.Visible = true;
}
private void 项目查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
Cl();
groupBox5.Visible = true;
}
private void groupBox3_Enter(object sender, EventArgs e)
{
}
private void groupBox5_Enter(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
string commandstring = @"select * from work_inf where Year = '" + comboBox1.Text + "' and Months = '" + comboBox4.Text + "' ";
da = new SqlDataAdapter(commandstring, connectionstring);
ds = new DataSet();
da.Fill(ds, "work_inf");
work_infDataGridView.DataSource = ds.Tables["work_inf"];
}
private void groupBox2_Enter(object sender, EventArgs e)
{
}
private void dataGridView3_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void 在此留言ToolStripMenuItem1_Click(object sender, EventArgs e)
{
Cl();
groupBox4.Visible = true;
}
private void 查看所有留言ToolStripMenuItem_Click(object sender, EventArgs e)
{
留言查看 ff = new 留言查看();
ff.Show();
}
private void button5_Click(object sender, EventArgs e)
{
string commandstring = @"select * from liuyan_inf";
if (textBox4.Text == "")
{ MessageBox.Show("请输入留言主题!"); }
else
{
SqlConnection conn = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand(commandstring, conn);
int prime = 0;
conn.Open();
if (prime == 0)
try
{
da = new SqlDataAdapter(commandstring, connectionstring);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "liuyan_inf");
DataTable mytable = ds.Tables["liuyan_inf"];
//dataGridView1.DataSource = ds.Tables["liuyan_inf"];
DataRow myrow = ds.Tables["liuyan_inf"].NewRow();
myrow[0] = textBox3.Text.ToString();
myrow[1] = textBox4.Text.ToString();
myrow[2] = richTextBox1.Text.ToString();
mytable.Rows.Add(myrow);
da.Update(ds, "liuyan_inf");
ds.AcceptChanges();
MessageBox.Show("留言成功,感谢你的留言!");
// dataGridView4.DataSource = ds.Tables["stores"];
textBox3.Text = "";
textBox4.Text = "";
richTextBox1.Text = "";
}
catch (SqlException ex)
{
MessageBox.Show("留言失败:" + ex.Message, "出现错误",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
conn.Close();
}
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
string connectionstring = @"data source=localhost;Initial catalog=tuanweizuzhibu_inf;integrated security=SSPI;";
string commandstring = @"select * from bumenshezhi_inf where 部门Id like'%" + textBox5.Text + "%'or 部门名称 like'%" + textBox5.Text + "%' or 部长姓名 like'%" + textBox5.Text + "%'";
da = new SqlDataAdapter(commandstring, connectionstring);
ds = new DataSet();
da.Fill(ds, "bumenshezhi_inf");
dataGridView5.DataSource = ds.Tables["bumenshezhi_inf"];
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
{
}
private void monthsLabel_Click(object sender, EventArgs e)
{
}
private void yearLabel_Click(object sender, EventArgs e)
{
}
private void 项目更新ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form8 f8 = new Form8();
f8.Show();
}
private void groupBox6_Enter(object sender, EventArgs e)
{
}
private void 部门设置查询ToolStripMenuItem_Click_1(object sender, EventArgs e)
{
Cl();
groupBox6.Visible = true;
}
private void 部门设置管理ToolStripMenuItem1_Click(object sender, EventArgs e)
{
Form5 f5 = new Form5();
f5.Show();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -