?? teacher_information.cs
字號:
?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _7計應(yīng)的班級管理系統(tǒng)
{
public partial class teacher_information : Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBoxname;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.RadioButton radioButtonadd;
private System.Windows.Forms.RadioButton radioButtonchange;
private System.Windows.Forms.RadioButton radioButtondelete;
private System.Windows.Forms.Button buttonsave;
private System.Windows.Forms.Button buttonclear;
private System.Windows.Forms.Button buttonfresh;
private System.Windows.Forms.Button buttonexit;
private System.Windows.Forms.ListView listViewdisplay;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TextBox textBoxtext;
private System.Windows.Forms.TextBox textBoxteach;
private System.Windows.Forms.TextBox textBoxtel;
private System.Windows.Forms.TextBox textBoxzhicheng;
private System.Windows.Forms.TextBox textBoxsex;
private BindingManagerBase bmgr;
private System.Windows.Forms.Button buttonleft;
private System.Windows.Forms.Button buttonright;
DataSet dbrs = new DataSet();
public teacher_information()
{
InitializeComponent();
}
private void buttonsave_Click(object sender, EventArgs e)
{
Form1 load = new Form1();
if (load.Nowpower != "學(xué)生")
{
string strconn = "user id=sa;data source=localhost;integrated security=false;initial catalog=學(xué)生數(shù)據(jù)庫1";
SqlConnection conn = new SqlConnection(strconn);
SqlCommand cmd = conn.CreateCommand();
conn.Open();
string name = textBoxname.Text.Trim();
string sex = textBoxsex.Text.Trim();
string tel = textBoxtel.Text.Trim();
string zhicheng = textBoxzhicheng.Text.Trim();
string teach = textBoxteach.Text.Trim();
string beizhu = textBoxtext.Text.Trim();
try
{
if (radioButtonadd.Checked)
{
cmd.CommandText = "insert into teacher_information values('" + name + "','" + sex + "','" + tel + "','" + zhicheng + "','" + teach + "','" + beizhu + "')";
}
else if (radioButtonchange.Checked)
{
cmd.CommandText = "update teacher_information set 姓別='" + sex + "',聯(lián)系電話='" + tel + "',擔(dān)任科目='" + teach + "',備注='" + beizhu + "',職稱='" + zhicheng + "' where 姓名='" + name + "' ";
//cmd.CommandText="delete from teacher_information where 姓名='"+name+"'";
//cmd.ExecuteNonQuery();
//cmd.CommandText="insert into teacher_information values('"+name+"','"+sex+"','"+tel+"','"+zhicheng+"','"+teach+"','"+beizhu+"')";
}
else if (radioButtondelete.Checked)
{
cmd.CommandText = "delete from teacher_information where 姓名='" + name + "'";
}
else
MessageBox.Show("請選擇一個功能!");
SqlDataReader dr = cmd.ExecuteReader();
for (int i = 0; i < dr.FieldCount; i++)
{
ColumnHeader ch = new ColumnHeader();
ch.Text = dr.GetName(i);
listViewdisplay.Columns.Add(ch);
}
while (dr.Read())
{
ListViewItem item = new ListViewItem();
item.Text = dr.GetValue(0).ToString();
for (int i = 1; i < dr.FieldCount; i++)
{
item.SubItems.Add(dr.GetValue(i).ToString());
}
listViewdisplay.Items.Add(item);
}
dr.Close();
refresh();
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
finally
{
conn.Close();
}
}
else
MessageBox.Show("只有管理員有此權(quán)限!");
}
private void teacher_information_Load(object sender, EventArgs e)
{
refresh();
bind();
}
void refresh()
{
listViewdisplay.Clear();
SqlConnection conn = new SqlConnection("user id=sa;data source=localhost;integrated security=false;initial catalog=學(xué)生數(shù)據(jù)庫1");
SqlCommand cmd = new SqlCommand();
cmd = conn.CreateCommand();
cmd.CommandText = "select * from teacher_information";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
//if(dr==null)
//{
for (int i = 0; i < dr.FieldCount; i++)
{
ColumnHeader ch = new ColumnHeader();
ch.Text = dr.GetName(i);
listViewdisplay.Columns.Add(ch);
}
while (dr.Read())
{
ListViewItem item = new ListViewItem();
item.Text = dr.GetValue(0).ToString();
for (int i = 1; i < dr.FieldCount; i++)
{
item.SubItems.Add(dr.GetValue(i).ToString());
}
listViewdisplay.Items.Add(item);
}
//}
//else
// MessageBox.Show("沒有這樣的記錄!");
dr.Close();
conn.Close();
}
void bind()
{
SqlConnection conn = new SqlConnection("user id=sa;data source=localhost;integrated security=false;initial catalog=學(xué)生數(shù)據(jù)庫1");
SqlDataAdapter da = new SqlDataAdapter("select * from teacher_information", conn);
dbrs = new DataSet();
textBoxname.DataBindings.Clear();
textBoxsex.DataBindings.Clear();
textBoxtel.DataBindings.Clear();
textBoxzhicheng.DataBindings.Clear();
textBoxteach.DataBindings.Clear();
textBoxtext.DataBindings.Clear();
da.Fill(dbrs, "teacher_information");
textBoxname.DataBindings.Add("text", dbrs, "teacher_information.姓名");
textBoxsex.DataBindings.Add("text", dbrs, "teacher_information.姓別");
textBoxtel.DataBindings.Add("text", dbrs, "teacher_information.聯(lián)系電話");
textBoxzhicheng.DataBindings.Add("text", dbrs, "teacher_information.職稱");
textBoxteach.DataBindings.Add("text", dbrs, "teacher_information.擔(dān)任科目");
textBoxtext.DataBindings.Add("text", dbrs, "teacher_information.備注");
}
private void buttonclear_Click(object sender, EventArgs e)
{
textBoxname.Clear();
textBoxsex.Clear();
textBoxtel.Clear();
textBoxzhicheng.Clear();
textBoxteach.Clear();
textBoxtext.Clear();
listViewdisplay.Clear();
}
private void buttonfresh_Click(object sender, EventArgs e)
{
refresh();
bind();
}
private void buttonexit_Click(object sender, EventArgs e)
{
this.Hide();
}
private void buttonleft_Click(object sender, EventArgs e)
{
bmgr = this.BindingContext[dbrs, "teacher_information"];
bmgr.Position -= 1;
}
private void buttonright_Click(object sender, EventArgs e)
{
bmgr = this.BindingContext[dbrs, "teacher_information"];
bmgr.Position += 1;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -