Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.StudentTable model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into StudentTable(");
            strSql.Append("Username,Password,Name,Sex,Major)");
            strSql.Append(" values (");
            strSql.Append("@Username,@Password,@Name,@Sex,@Major)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Username", SqlDbType.VarChar,  50),
                new SqlParameter("@Password", SqlDbType.VarChar,  50),
                new SqlParameter("@Name",     SqlDbType.NVarChar, 50),
                new SqlParameter("@Sex",      SqlDbType.NVarChar, 50),
                new SqlParameter("@Major",    SqlDbType.NVarChar, 50)
            };
            parameters[0].Value = model.Username;
            parameters[1].Value = model.Password;
            parameters[2].Value = model.Name;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.Major;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.StudentTable DataRowToModel(DataRow row)
 {
     Model.StudentTable model = new Model.StudentTable();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["Username"] != null)
         {
             model.Username = row["Username"].ToString();
         }
         if (row["Password"] != null)
         {
             model.Password = row["Password"].ToString();
         }
         if (row["Name"] != null)
         {
             model.Name = row["Name"].ToString();
         }
         if (row["Sex"] != null)
         {
             model.Sex = row["Sex"].ToString();
         }
         if (row["Major"] != null)
         {
             model.Major = row["Major"].ToString();
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        public string Import(HttpPostedFileBase file)
        {
            if (file == null)
            {
                return("文件为空");
            }

            var    fileName = file.FileName;
            var    filePath = Server.MapPath(string.Format("~/{0}", "StudentFile"));
            string path     = Path.Combine(filePath, fileName);

            file.SaveAs(path);

            DataTable excelTable = new DataTable();

            excelTable = ImportExcel.GetExcelDataTable(path);

            DataTable dbdata = new DataTable();

            dbdata.Columns.Add("id");
            dbdata.Columns.Add("username");
            dbdata.Columns.Add("password");
            dbdata.Columns.Add("name");
            dbdata.Columns.Add("sex");
            dbdata.Columns.Add("major");

            for (int i = 0; i < excelTable.Rows.Count; i++)
            {
                DataRow dr  = excelTable.Rows[i];
                DataRow dr_ = dbdata.NewRow();
                dr_["id"]       = 0;
                dr_["username"] = dr["学号"];
                dr["密码"]        = encryptPwd(dr["密码"].ToString());
                dr_["password"] = dr["密码"];
                dr_["name"]     = dr["姓名"];
                dr_["sex"]      = dr["性别"];
                dr_["major"]    = dr["专业"];
                dbdata.Rows.Add(dr_);
            }

            RemoveEmpty(dbdata);

            List <Model.StudentTable> list = student.DataTableToList(dbdata);

            if (list.Count > 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    Model.StudentTable studentModel = list[i];
                    student.Add(studentModel);
                }
            }

            return("导入成功");
        }
Exemplo n.º 4
0
        public override ActionResult AjaxList()
        {
            int start  = 0;
            int length = 0;

            start  = Convert.ToInt32(Request.Params["start"]);
            length = Convert.ToInt32(Request.Params["length"]);

            var strSql = "Username = '******'";

            BLL.StudentTable          bllStudent  = new BLL.StudentTable();
            List <Model.StudentTable> studentList = bllStudent.DataTableToList(bllStudent.GetList(strSql).Tables[0]);

            if (studentList.Count > 0)
            {
                Model.StudentTable studentModel = studentList[0];

                strSql = "Major = N'" + studentList[0].Major + "' and Nowstate = N'已开启'";
            }

            List <Model.ExamTable> list = exam.DataTableToList(exam.GetListByPage(strSql, "", start + 1, start + length).Tables[0]);
            int filterTotal             = exam.GetRecordCount(strSql);
            int total = exam.GetRecordCount("");

            return(this.Json(new
            {
                result = 1,
                data = new
                {
                    draw = Request.Params["draw"],
                    recordsTotal = total,
                    recordsFiltered = filterTotal,
                    data = list.Select(o => new
                    {
                        ID = o.ID,
                        Teacher = o.Teacher,
                        Major = o.Major,
                        Start = o.Start,
                        Last = o.Last,
                        Filepath = o.Filepath,
                    })
                }
            }));
        }
Exemplo n.º 5
0
        public override ActionResult Info(int id)
        {
            bool result = false;

            Model.StudentTable model = student.GetModel(id);
            if (model != null)
            {
                result = true;
            }

            if (result)
            {
                return(this.Json(new { result = 1, data = model }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(this.Json(new { result = 0, msg = "请求条目不存在" }));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.StudentTable model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update StudentTable set ");
            strSql.Append("Username=@Username,");
            strSql.Append("Password=@Password,");
            strSql.Append("Name=@Name,");
            strSql.Append("Sex=@Sex,");
            strSql.Append("Major=@Major");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Username", SqlDbType.VarChar,  50),
                new SqlParameter("@Password", SqlDbType.VarChar,  50),
                new SqlParameter("@Name",     SqlDbType.NVarChar, 50),
                new SqlParameter("@Sex",      SqlDbType.NVarChar, 50),
                new SqlParameter("@Major",    SqlDbType.NVarChar, 50),
                new SqlParameter("@ID",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Username;
            parameters[1].Value = model.Password;
            parameters[2].Value = model.Name;
            parameters[3].Value = model.Sex;
            parameters[4].Value = model.Major;
            parameters[5].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.StudentTable GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Username,Password,Name,Sex,Major from StudentTable ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Model.StudentTable model = new Model.StudentTable();
            DataSet            ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        public ActionResult Create(Model.StudentTable model)
        {
            bool result = false;

            if (!String.IsNullOrEmpty(model.Username) && !String.IsNullOrEmpty(model.Password) && !String.IsNullOrEmpty(model.Name))
            {
                model.Password = encryptPwd(model.Password);

                var state = student.Add(model);
                if (state != 0)
                {
                    result = true;
                }
            }

            if (result)
            {
                return(this.Json(new { result = 1, data = "" }));
            }
            else
            {
                return(this.Json(new { result = 0, msg = "新建失败" }));
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.StudentTable model)
 {
     return(dal.Update(model));
 }
Exemplo n.º 10
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.StudentTable model)
 {
     return(dal.Add(model));
 }