程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 學生管理系統,學生信息管理系統

學生管理系統,學生信息管理系統

編輯:C#入門知識

學生管理系統,學生信息管理系統


1.登錄窗體

基本控件:

label(標簽控件)

主要屬性:Image(在標簽上顯示的圖像)

Text(在標簽上顯示的文本)

TextBox(文本框控件)

主要屬性:PasswordChar(指示在作為密碼框時,文本框中顯示的字符,而不是實際輸入的文本)

Button(按鈕控件)

ComboBox(下拉框)屬性:SelectedItem:獲取當前選定的項

事件:Click(單擊控件時發生)

private void butStyle_Click(object sender, EventArgs e)
        {
            string str = "Data source=.;Initial catalog=Myschool;uid=sa";
            SqlConnection con = new SqlConnection(str);
            string sql = "select count(1) from student where studentName='" + txtUserName.Text + "' and LoginPwd='" + txtPwd.Text + "'";
            SqlCommand cmd = new SqlCommand(sql, con);
            try
            {
                con.Open();
                int count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count > 0)
                {
                  MessageBox.Show("登陸成功");
                    this.Hide();
                    FormMain frm = new FormMain();
                    frm.Show();
                }
            }
            catch (Exception)
            {

                MessageBox.Show("退出");
            }
            finally
            {
                con.Close();
            }

Sender是事件源,表示發生了這個事件的對象,事件發生中,事件源就是按鈕。

e是事件參數(EventArgs)對象,不同的事件會有不同的參數。

Close()方法是窗體類Form的一個方法,作用是關閉窗體。

2.Myschool管理員

01.給菜單欄中的“新增學生”菜單項添加事件處理程序,代碼如下

private void 新增學生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormStudent formStudent = new FormStudent();
            formStudent.Show();
        }

02.添加學生信息

 public void Save()
        {
            //添加學生
            string pwd = txtpwd.Text;
            string stuname = textname.Text;
            //性別
            string stugender = string.Empty;
            if (radioman.Checked)
            {
                stugender = "1";
            }
            else
            {
                stugender = "0";
            }
            //下拉框綁定數據
            int gid = GeadIdName();
            //聯系電話
            string StuPhone = textphone.Text;
            //地址
            string StuAddress = textAddress.Text;
            //日期
            DateTime dt = dateBirthday.Value;
            //郵箱
            string StuEmail = textEmail.Text;
            //LoginPwd, StudentName, Gender, GradeId, Phone, Address, Birthday, Email
            string sql = "insert into Student values('" + pwd + "','" + stuname + "','" + stugender + "'," + gid + ",'" + StuPhone + "','" + StuAddress + "','" + dt + "','" + StuEmail + "')";
            string str = "Data source=.;Initial catalog=Myschool;uid=sa;";
            SqlConnection con = new SqlConnection(str);
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            int count = cmd.ExecuteNonQuery();
            if (count > 0)
            {
                MessageBox.Show("添加成功");                 
            }
            con.Close();
        }

3.查詢學生信息

//查詢學生信息
        public void LodaDataListView(string sql)
        {
            string str = "data source=.;initial catalog=Myschool;uid=sa;";
            SqlConnection con = new SqlConnection(str);
            SqlCommand cmd = new SqlCommand(sql, con);
            try
            {
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr != null)
                {
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            int stuNo = Convert.ToInt32(dr["studentNo"]);
                            //姓名
                            string stuname = Convert.ToString(dr["studentName"]);
                            //性別
                            string stuGender = Convert.ToString(dr["Gender"]);
                            //年級名次
                            string stuGname = Convert.ToString(dr["Gradename"]);
                            ListViewItem LvItem = new ListViewItem(stuNo.ToString());
                            LvItem.SubItems.Add(stuname);
                            LvItem.SubItems.Add(stuGender);
                            LvItem.SubItems.Add(stuGname);
                            //讓lvItem和ListView關聯
                            lvlist.Items.Add(LvItem);
                        }
                        dr.Close();
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                con.Close();
            }

//窗體Load的事件中調用

private void Formselect_Load(object sender, EventArgs e)
        {
            string sql = "select StudentNO,StudentName,Gender,GradeName from Student,Grade where Student.GradeId=Grade.GradeId";
            LodaDataListView(sql);
        }

修改學生信息

public void upatae()
        {
            //添加學生
            string pwd = txtpwd.Text;
            string stuname = textname.Text;
            //性別
            string stugender = string.Empty;
            if (radioman.Checked)
            {
                stugender = "1";
            }
            else
            {
                stugender = "0";
            }
            //下拉框綁定數據
            int gid = GeadIdName();
            //聯系電話
            string StuPhone = textphone.Text;
            //地址
            string StuAddress = textAddress.Text;
            //日期
            DateTime dt = dateBirthday.Value;
            //郵箱
            string StuEmail = textEmail.Text;
            //LoginPwd, StudentName, Gender, GradeId, Phone, Address, Birthday, Email
            string sql = @"update Student set StudentName='" + stuname + "',Gender=" + stugender + ",GradeId='" + gid + "',phone='" + StuPhone + "',Address='" + StuAddress + "',Birthday='" + dt + "',Email='" + StuEmail
                + "' where studentNo='" + textNo.Text + "'";
            string str = "Data source=.;Initial catalog=Myschool;uid=sa;";
            SqlConnection con = new SqlConnection(str);
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            int count = cmd.ExecuteNonQuery();
            if (count > 0)
            {
                frmselect.selectData();
                MessageBox.Show("修改成功");
            }
            con.Close();
        }

//性別if判定:性別男為1 為女0.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved