C#学生信息管理系统

1.登录界面:

C#学生信息管理系统_第1张图片

 2.注册界面

C#学生信息管理系统_第2张图片

3.邮箱手机号正则表达式

4.main

C#学生信息管理系统_第3张图片

5.增加学生信息

 C#学生信息管理系统_第4张图片

 6.用户信息管理

C#学生信息管理系统_第5张图片

7.分页实现

代码:

center:


@{
    ViewBag.Title = "center";
}



    
    
    
    
    
    
    
    
   


    

学生信息管理系统

@Html.Partial("center2")
@Html.Partial("center1")

homecontrol

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication8798.daoimpl;
using WebApplication8798.Models;

namespace WebApplication8798.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult login()
        {
            return View();
        }
        [HttpGet()]
        public ActionResult login1(string username,string password)
        {
            loginuser user = new loginuser();
            user._username = username;
            user._password = password;
            studentDaoimpl imp = new studentDaoimpl();
            bool ret=imp.queryUser(user);
            if (ret)
            {

                return RedirectToAction("center");
            }
            else
            {
                return RedirectToAction("login");
            }
        }
        [HttpGet()]
        public ActionResult register1(string username, string password,string email)
        {
            loginuser user = new loginuser();
            user._username = username;
            user._password = password;
            user._email = email;
            studentDaoimpl imp = new studentDaoimpl();
            bool ret = imp.AddUser(user);
            if (ret)
            {

                return RedirectToAction("login");
            }
            else
            {
                return RedirectToAction("register");
            }
        }
        public ActionResult register()
        {
            return View();
        }
        [HttpGet()]
        public ActionResult deletestu(string sno)
            

        {
            studentDaoimpl imp = new studentDaoimpl();
            bool ret=imp.deleteStudent(sno);
            JsonResult ajaxres = new JsonResult();
            ajaxres.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            if (ret)
            {

                return RedirectToAction("student1");
            }
            else
            {
                return RedirectToAction("center");
            }
        }
        public ActionResult studentadd(FormCollection col)
        {
            Student stu = new Student();
            stu._sno = col["sno"];
            stu._sname = col["sname"];
            stu._classnum = Int32.Parse(col["classnum"]);
            stu._sex = col["sex"];
            stu._phone = col["phone"];
            stu._email = col["email"];
            //user.phone = col["phone"];
            //ViewBag.Message = "Your application description page.";
            //数据库判断
            studentDaoimpl userimpl = new studentDaoimpl();
            if (userimpl.addStudent(stu))
                return RedirectToAction("student1");
            else
                return RedirectToAction("student2");


        }
        public ActionResult student2()
        {
            return View();
        }
        public ActionResult center()
        {
            return View();
        }
        public ActionResult student1()
        {
            return View();
        }
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        [HttpGet()]
        public ActionResult test1(string val)
        {
            studentDaoimpl imp = new studentDaoimpl();
            List stu = imp.queryStudent();

            JsonResult ajaxres = new JsonResult();
            ajaxres.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            int size = stu.Count;
            string[] sno=new string[size];
       string[] sname=new string[size];
        int[] classnum=new int[size];
        string[] sex=new string[size];
        string[] phone=new string[size];
        string[] email=new string[size];
            for(int i = 0; i < stu.Count; i++)
            {
                sno[i] = stu[i]._sno;
                sname[i] = stu[i]._sname;
                classnum[i] = stu[i]._classnum;
                sex[i] = stu[i]._sex;
                phone[i] = stu[i]._phone;
                email[i] = stu[i]._email;
            }
            ajaxres.Data = new { sno = sno, sname = sname,classnum=classnum,sex=sex,phone=phone,email=email ,size=size};
            // String data1 = "67876877778";
            return ajaxres;

            
        }
        public ActionResult hgfghfg()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        public ActionResult jhgjgjfghfgfgh()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}

dao

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebApplication8798.Models;

namespace WebApplication8798.dao
{
    interface studentDao
    {
        List queryUser();
        bool queryUser(loginuser user);
        List queryStudent();
        bool addStudent(Student stu);
        bool AddUser(loginuser user);
        bool deleteStudent(string sno);
    }
}

daoimpl

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using WebApplication8798.dao;
using WebApplication8798.Models;

namespace WebApplication8798.daoimpl
{
    public class studentDaoimpl : studentDao
    {
        public bool addStudent(Student stu)
        {
            SqlConnection con = dataBase.databaseConnection.GetConnection();
            con.Open();
            SqlCommand command = new SqlCommand();
            command.CommandText = "insert into student1 values("+"'"+stu._sno+"'," + "'" + stu._sname + "'," + "'" + stu._classnum + "'," + "'" + stu._sex + "'," + "'" + stu._phone + "'," + "'" + stu._email + "');";
            command.Connection = con;
            int ret = command.ExecuteNonQuery();
            con.Close();
            if (ret == 1)
                return true;
            else
                return false;
            return true;
        }

        public bool AddUser(loginuser user)
        {
            SqlConnection con = dataBase.databaseConnection.GetConnection();
            con.Open();
            SqlCommand command = new SqlCommand();
            command.CommandText = "insert into loginuser values(" + "'" + user._username + "'," + "'" + user._password + "'," + "'" + user._email + "');";
            command.Connection = con;
            int ret = command.ExecuteNonQuery();
            con.Close();
            if (ret == 1)
                return true;
            else
                return false;
        }

        public bool deleteStudent(string sno)
        {
            SqlConnection con = dataBase.databaseConnection.GetConnection();
            con.Open();
            SqlCommand command = new SqlCommand();
            command.CommandText = "delete from student1 where sno='"+sno+"';";
            command.Connection = con;
            int ret = command.ExecuteNonQuery();
            con.Close();
            if (ret == 1)
                return true;
            else
                return false; 
        }

        public List queryStudent()
        {
            List stu = new List();
            SqlConnection con = dataBase.databaseConnection.GetConnection();
            con.Open();
            SqlCommand command = new SqlCommand();
            command.CommandText = "select * from student1";
            command.Connection = con;
            SqlDataReader sdr = command.ExecuteReader();
            while (sdr.Read())
            {
                
                Student s1 = new Student(sdr.GetString(0), sdr.GetString(1), sdr.GetInt32(2), sdr.GetString(3), sdr.GetString(4), sdr.GetString(5));
                stu.Add(s1);
            }
            return stu;
        }

        public List queryUser()
        {
            throw new NotImplementedException();
        }

        public bool queryUser(loginuser user)
        {
            //

            List stu = new List();
            SqlConnection con = dataBase.databaseConnection.GetConnection();
            con.Open();
            SqlCommand command = new SqlCommand();
            command.CommandText = "select * from loginuser where username='"+user._username+"' and password='"+user._password+"';";
            command.Connection = con;
            SqlDataReader sdr = command.ExecuteReader();
            bool ret1=true;
            
            if (sdr.Read())
                ret1 = true;
            else
                ret1 = false;
            return ret1;
        }
    }
}

mode

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication8798.Models
{
    public class Student
    {
        private string sno;
        private string sname;
        private int classnum;
        private string sex;
        private string phone;
        private string email;
        public string _sno
        {
            set { sno = value; }
            get { return sno; }
        }
        public string _sname
        {
            set { sname = value; }
            get { return sname; }
        }
        public int _classnum
        {
            set { classnum = value; }
            get { return classnum; }
        }
        public string _sex
        {
            set { sex = value; }
            get { return sex; }
        }
        public string _phone
        {
            set { phone = value; }
            get { return phone; }
        }
        public string _email
        {
            set { email = value; }
            get { return email; }
        }

        public Student(string sno, string sname, int classnum, string sex, string phone, string email)
        {
            this.sno = sno;
            this.sname = sname;
            this.classnum = classnum;
            this.sex = sex;
            this.phone = phone;
            this.email = email;
            
        }

        public Student()
        {
        }
    }
}

你可能感兴趣的:(软件工程,C#,前后端,ajax,软件工程,sqlserver)