亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#實現(xiàn)簡單學生信息管理系統(tǒng)

 更新時間:2022年02月27日 08:11:41   作者:_shuai_  
這篇文章主要為大家詳細介紹了C#實現(xiàn)簡單學生信息管理系統(tǒng),具有一定的參考價值,感興趣的小伙伴們可以參考一下

 本文實例為大家分享了C#實現(xiàn)簡單學生信息管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

一、運行環(huán)境windows,使用vs編譯軟件

二、主要功能

登錄、添加學生信息、修改學生信息、刪除學生信息、查詢學生信息

三、實現(xiàn)步驟

1、登陸界面功能實現(xiàn)

老規(guī)矩,先貼下主要代碼:

 //構造方法
 public Login()
 {
 InitializeComponent();
 this.label3.Parent = this;
 this.label1.BackColor = Color.Transparent;
 this.label2.BackColor = Color.Transparent;
 this.label3.BackColor = Color.Transparent;
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
 }
 //對登錄按鈕的事件實現(xiàn)代碼
 private void button1_Click(object sender, EventArgs e)
 {
 string ss = ConfigurationManager.ConnectionStrings["Stu"].ToString();
 SqlConnection conn = new SqlConnection(ss);
 try
 {
 //開啟連接 
 conn.Open(); 
 // MessageBox.Show("數(shù)據(jù)庫連接成功!"); 
 }
 catch (Exception)
 {
 //MessageBox.Show("數(shù)據(jù)庫連接失敗!");
 } 
 String uname = txtName.Text.Trim();
 string pword = txtPass.Text.Trim();
 if(uname == ""|| pword == "")
 {
 MessageBox.Show("請輸入用戶名或密碼!");
 return;
 }
 else
 {
 SqlCommand cmd = conn.CreateCommand();
 SqlDataAdapter adp = new SqlDataAdapter();
 string sql2 = "select * from account where name='"+ uname + " 'and pass='" + pword + " ' ";
 cmd.CommandText = sql2;
 adp.SelectCommand = cmd;
 DataSet dat = new DataSet();
 adp.Fill(dat, "account");
 if(dat.Tables["account"].Rows.Count == 0)
 {
 MessageBox.Show("用戶名或密碼錯誤!");
 return;
 }
 else
 {
 Form1.isLogin = true;
 Form1.username = this.txtName.Text;
 this.Close();
 }
 cmd.Clone();
 }
 conn.Close();
 
 }
 //實現(xiàn)按ESC鍵關閉該窗口
 protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
 {
 switch (keyData)
 {
 case Keys.Escape:
 this.Close();//esc關閉窗體
 break;
 }
 return false;
 }
 //重置按鈕清空文本框
 private void button2_Click(object sender, EventArgs e)
 {
 txtName.Text = "";
 txtPass.Text = "";
 } 
 //密碼輸入完成后實現(xiàn)敲擊enter鍵觸發(fā)登錄按鈕
 private void txtPass_KeyDown(object sender, KeyEventArgs e)
 {
 if(e.KeyCode == Keys.Enter)
 {
 this.button1_Click(sender, e);
 }
 }
 //實現(xiàn)按enter鍵使焦點轉移到下一文本框,與tab鍵通用
 private void txtName_KeyPress(object sender, KeyPressEventArgs e)
 {
 if (e.KeyChar == (char)Keys.Enter)
 {
 SendKeys.Send("{tab}");
 }
 }

效果如下圖:

在這里插入圖片描述

2、主界面功能實現(xiàn)

主要代碼如下:

public static bool isLogin = false;
 int id;
 SqlConnection conn;
 SqlCommand cmd;
 SqlDataAdapter adp;
 DataSet dat;
 public static string username
 {
 get;
 set;
 }
 public Form1()
 {
 InitializeComponent();
 this.label1.BackColor = Color.Transparent;
 this.groupBox1.BackColor = Color.Transparent;
 this.groupBox2.BackColor = Color.Transparent;
 this.dataGridView1.BorderStyle = BorderStyle.None;
 this.dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
 
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
 this.Text += "| 管理員:" + username;
 string ss = ConfigurationManager.ConnectionStrings["Stu"].ToString();
 //建立數(shù)據(jù)庫連接
 conn = new SqlConnection(ss);
 try
 {
 //開啟連接 
 conn.Open();
 // MessageBox.Show("數(shù)據(jù)庫連接成功!"); 
 }
 catch (Exception)
 {
 MessageBox.Show("數(shù)據(jù)庫連接失敗!");
 }
 
 }

 private void Form1_Load(object sender, EventArgs e)
 {
 DataGridViewDataLoad();
 
 //this.stu_dentTableAdapter.Fill(this.students.Stu_dent);

 }

 private void DataGridViewDataLoad()
 {
 String sql1 = "select * from Stu_dent";
 adp = new SqlDataAdapter(sql1,conn);
 dat = new DataSet();
 adp.Fill(dat);
 dataGridView1.DataSource = dat.Tables[0];
 }

 private void button5_Click(object sender, EventArgs e)
 {
 string num = textBox1.Text.Trim();
 string name = textBox2.Text.Trim();
 String sql4 = "Select * from Stu_dent where 1=1";
 if(!String.IsNullOrEmpty(num))
 {
 sql4 += " and StuNum=" + num;
 }
 if(!String.IsNullOrEmpty(name))
 {
 sql4 += " and StuName like '%" + name + "%'";
 }
 adp = new SqlDataAdapter(sql4, conn);
 dat = new DataSet();
 adp.Fill(dat);
 dataGridView1.DataSource = dat.Tables[0];
 
 }
 protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
 {
 switch (keyData)
 {
 case Keys.Escape:
 this.Close();//esc關閉窗體
 break;
 }
 return false;
 }
 private void button1_Click(object sender, EventArgs e)
 {
 AddStudent addStudent = new AddStudent();
 addStudent.StartPosition = FormStartPosition.CenterScreen;
 //addStudent.Show();
 addStudent.ShowDialog();
 DataGridViewDataLoad();
 }

 private void button4_Click(object sender, EventArgs e)
 {
 this.Close();
 }

 private void button2_Click(object sender, EventArgs e)
 {
 MessageBox.Show("請在學生信息顯示框中雙擊所要刪除學生所在的那一行即可?。?!","提示");
 }
 private void button3_Click(object sender, EventArgs e)
 {
 MessageBox.Show("請在學生信息顯示框中單擊所要刪修改學生所在的那一行的任意文字區(qū)域即可!", "提示");
 }
 private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
 DialogResult result = MessageBox.Show("確定刪除該學生信息?", "刪除", MessageBoxButtons.OKCancel);
 if(result == DialogResult.OK)
 {
 id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
 Console.WriteLine(id);
 string sql2 = "delete from Stu_dent where ID=" + id;
 cmd = new SqlCommand(sql2, conn);
 cmd.ExecuteNonQuery();

 }
 DataGridViewDataLoad();
 }

 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
 id = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells[0].Value);
 UpdateStudent updatestudent = new UpdateStudent(id);
 updatestudent.StartPosition = FormStartPosition.CenterScreen;
 updatestudent.ShowDialog();
 DataGridViewDataLoad();
 }

效果如下:

3、添加學生信息功能實現(xiàn)

主要代碼如下:

public AddStudent()
 {
 InitializeComponent();
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
 string ss = ConfigurationManager.ConnectionStrings["Stu"].ToString();
 //建立數(shù)據(jù)庫連接
 conn = new SqlConnection(ss);
 try
 {
 //開啟連接 
 conn.Open();
 // MessageBox.Show("數(shù)據(jù)庫連接成功!"); 
 }
 catch (Exception)
 {
 MessageBox.Show("數(shù)據(jù)庫連接失敗!");
 }

 }

 private void AddStudent_Load(object sender, EventArgs e)
 {
 
 }

 private void label1_Click(object sender, EventArgs e)
 {

 }
 protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
 {
 switch (keyData)
 {
 case Keys.Escape:
 this.Close();//esc關閉窗體
 break;
 }
 return false;
 }
 private void button1_Click(object sender, EventArgs e)
 {
 string StuNum = textBox1.Text.Trim();
 string StuName = textBox2.Text.Trim();
 int StuAge;
 Int32.TryParse(textBox3.Text.Trim(), out StuAge);
 string StuClass = textBox5.Text.Trim();
 string StuPhone = textBox6.Text.Trim();
 string StuSex = radioButton1.Checked ? "男" : "女";
 if (String.IsNullOrEmpty(StuNum))
 {
 MessageBox.Show("學號不能為空!");
 }
 if (String.IsNullOrEmpty(StuName))
 {
 MessageBox.Show("姓名不能為空!");
 }
 
 if (String.IsNullOrEmpty(StuClass))
 {
 MessageBox.Show("班級不能為空!");
 }
 if (String.IsNullOrEmpty(StuPhone))
 {
 MessageBox.Show("聯(lián)系方式不能為空!");
 }
 string sql = string.Format("insert into Stu_dent values ('{0}','{1}','{2}','{3}','{4}','{5}')", StuNum, StuName,StuAge,StuSex, StuClass, StuPhone );
 cmd = new SqlCommand(sql, conn);
 int count = cmd.ExecuteNonQuery();
 if (count > 0)
 {
 MessageBox.Show("添加成功!");
 }
 else
 {
 MessageBox.Show("添加失??!");
 }
 this.Close();
 }

4、刪除學生信息功能實現(xiàn)

在這里采用雙擊所要刪除學生所在的那一行的任意位置即可

主要代碼如下:

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
 DialogResult result = MessageBox.Show("確定刪除該學生信息?", "刪除", MessageBoxButtons.OKCancel);
 if(result == DialogResult.OK)
 {
 id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
 Console.WriteLine(id);
 string sql2 = "delete from Stu_dent where ID=" + id;
 cmd = new SqlCommand(sql2, conn);
 cmd.ExecuteNonQuery();

 }
 DataGridViewDataLoad();
 }

效果如下圖(雙擊第一行進行刪除):

刪除前:

刪除后:

5、修改學生信息功能實現(xiàn)

在這里采用單擊所要修改學生所在行任意文字處即可

主要代碼如下:

public UpdateStudent(int id)
 {
 this.id = id;
 string ss = ConfigurationManager.ConnectionStrings["Stu"].ToString();
 conn = new SqlConnection(ss);
 try
 {
 //開啟連接 
 conn.Open();
 // MessageBox.Show("數(shù)據(jù)庫連接成功!"); 
 }
 catch (Exception)
 {
 MessageBox.Show("數(shù)據(jù)庫連接失敗!");
 }
 InitializeComponent();
 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
 }
 protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
 {
 switch (keyData)
 {
 case Keys.Escape:
 this.Close();//esc關閉窗體
 break;
 }
 return false;
 }
 private void UpdateStudent_Load(object sender, EventArgs e)
 {
 cmd = conn.CreateCommand();
 string sql1 = "select * from Stu_dent where ID=" + id;
 cmd.CommandText = sql1;
 reader = cmd.ExecuteReader();
 if(reader.HasRows)
 {
 reader.Read();
 textBox1.Text = reader.GetString(1);
 textBox2.Text = reader.GetString(2);
 textBox3.Text = reader.GetInt32(3).ToString();
 if(reader.GetString(4) == "男")
 {
 this.radioButton2.Checked = true;
 }
 else
 {
 this.radioButton1.Checked = true;
 }
 textBox5.Text = reader.GetString(5);
 textBox6.Text = reader.GetString(6);
 }

 reader.Close();
 
 }

 private void button1_Click(object sender, EventArgs e)
 {
 string StuNum = textBox1.Text.Trim();
 string StuName = textBox2.Text.Trim();
 int StuAge;
 Int32.TryParse(textBox3.Text.Trim(), out StuAge);
 string StuClass = textBox5.Text.Trim();
 string StuPhone = textBox6.Text.Trim();
 string StuSex = radioButton1.Checked ? "男" : "女";
 if (String.IsNullOrEmpty(StuName))
 {
 MessageBox.Show("姓名不能為空!");
 }

 if (String.IsNullOrEmpty(StuClass))
 {
 MessageBox.Show("班級不能為空!");
 }
 if (String.IsNullOrEmpty(StuPhone))
 {
 MessageBox.Show("聯(lián)系方式不能為空!");
 }
 string sql = string.Format("update Stu_dent set StuName='{0}',StuAge={1},StuSex='{2}',StuClass='{3}',StuPhone='{4}' where StuNum='{5}'", StuName, StuAge, StuSex, StuClass, StuPhone, StuNum);
 cmd = new SqlCommand(sql, conn);
 int count = cmd.ExecuteNonQuery();
 if (count > 0)
 {
 MessageBox.Show("修改成功!");
 }
 else
 {
 MessageBox.Show("修改失敗!");
 }
 this.Close();
 }

 private void button2_Click(object sender, EventArgs e)
 {
 cmd = conn.CreateCommand();
 string sql1 = "select * from Stu_dent where ID=" + id;
 cmd.CommandText = sql1;
 reader = cmd.ExecuteReader();
 if (reader.HasRows)
 {
 reader.Read();
 textBox1.Text = reader.GetString(1);
 textBox2.Text = reader.GetString(2);
 textBox3.Text = reader.GetInt32(3).ToString();
 if (reader.GetString(4) == "男")
 {
 this.radioButton2.Checked = true;
 }
 else
 {
 this.radioButton1.Checked = true;
 }
 textBox5.Text = reader.GetString(5);
 textBox6.Text = reader.GetString(6);
 }

 reader.Close();
 }

(在這里將郭某某的專業(yè)班級為例)

修改前:

修改后:

6、查詢學生信息功能實現(xiàn)

查詢功能就寫了兩種查詢方式

主要代碼如下:

private void button5_Click(object sender, EventArgs e)
 {
 string num = textBox1.Text.Trim();
 string name = textBox2.Text.Trim();
 String sql4 = "Select * from Stu_dent where 1=1";
 if(!String.IsNullOrEmpty(num))
 {
 sql4 += " and StuNum=" + num;
 }
 if(!String.IsNullOrEmpty(name))
 {
 sql4 += " and StuName like '%" + name + "%'";
 }
 adp = new SqlDataAdapter(sql4, conn);
 dat = new DataSet();
 adp.Fill(dat);
 dataGridView1.DataSource = dat.Tables[0];
 
 }

效果如下:

按學號查詢:

按姓名查詢:

總結:這是上完c#課后,自己無聊整著玩的,功能實現(xiàn)簡單易懂,比較容易,希望能對你的學習有所幫助。對了,每個窗體的背景圖片是我再網(wǎng)上隨便找的,你可以選擇你喜歡的背景。

更多學習資料請關注專題《管理系統(tǒng)開發(fā)》。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • C#使用async和await實現(xiàn)異步編程

    C#使用async和await實現(xiàn)異步編程

    本文詳細講解了C#使用async和await實現(xiàn)異步編程的方法,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-07-07
  • C#利用itext實現(xiàn)PDF頁面處理與切分

    C#利用itext實現(xiàn)PDF頁面處理與切分

    這篇文章主要介紹了如何在C#中使用itext做一個pdf的頁面大小一致性處理,然后再根據(jù)數(shù)據(jù)切分出需要的pdf,感興趣的小伙伴可以了解一下
    2022-04-04
  • 詳解C#的排列組合

    詳解C#的排列組合

    本文詳細介紹了C#中的排列組合以及具體實現(xiàn)代碼,如下所示,希望對大家有所幫助
    2016-11-11
  • 淺析c#范型中的特殊關鍵字where & default

    淺析c#范型中的特殊關鍵字where & default

    以下是對c#范型中的特殊關鍵字where和default進行了詳細的介紹,需要的朋友可以過來參考下
    2013-09-09
  • C#操作注冊表的方法詳解

    C#操作注冊表的方法詳解

    這篇文章主要介紹了C#操作注冊表的方法,結合實例形式較為詳細的分析了C#針對注冊表的創(chuàng)建、打開、讀取、寫入、修改、刪除等技巧,需要的朋友可以參考下
    2015-12-12
  • Unity3d實現(xiàn)Flappy Bird游戲

    Unity3d實現(xiàn)Flappy Bird游戲

    這篇文章主要為大家詳細介紹了Unity3d實現(xiàn)Flappy Bird游戲,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • c#如何利用定時器自動備份數(shù)據(jù)庫詳解

    c#如何利用定時器自動備份數(shù)據(jù)庫詳解

    在開發(fā)過程當中,你一定遇到文件損壞活或丟失的煩惱,而每天備份又很麻煩,你只要設置每天備份的時間,并將程序加入啟動項中,就可以自動完成備份,這篇文章主要給大家介紹了關于c#如何利用定時器自動備份數(shù)據(jù)庫的相關資料,需要的朋友可以參考下
    2021-10-10
  • C#/VB.NET 在PDF中添加文件包(Portfolio)的方法

    C#/VB.NET 在PDF中添加文件包(Portfolio)的方法

    這篇文章主要介紹了C#/VB.NET 在PDF中添加文件包(Portfolio)的方法,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2020-06-06
  • C#使用Datatable導出Excel

    C#使用Datatable導出Excel

    這篇文章主要為大家詳細介紹了C#使用Datatable導出Excel的方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Unity實現(xiàn)仿3D輪轉圖效果

    Unity實現(xiàn)仿3D輪轉圖效果

    這篇文章主要為大家詳細介紹了Unity實現(xiàn)仿3D輪轉圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01

最新評論