Ejemplo n.º 1
0
 public static void TestAddModule_sorce()
 {
     Entry_score temp=new Entry_score()
     {
         entry_id=1,
         student_id="13111089",
         score=5
     };
     Entry_scoreBS.AddEntry_score(temp);
 }
Ejemplo n.º 2
0
 public static void TestAddAndModify()
 {
     Entry_score test = new Entry_score()
     {
        entry_id = 1,
       student_id = "13111089",
       score = 4
      };
     //Entry_scoreBS.ModifyEntry_score(test);
     Console.WriteLine(Entry_scoreBS.AddEntry_score(test));
     List<Entry_score> list = Evaluation_entryBS.GetEntry_scoreList(1);
     foreach (var x in list)
     {
         Console.WriteLine(x.student_id);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 添加项目成绩
 /// </summary>
 /// <param name="model">要添加的项目成绩</param>
 ///<returns>成功返回true</returns>
 public static bool AddEntry_score(Entry_score model)
 {
     try
     {
         using (var db = new SEMSDBContext())
         {
             db.Entry_score.Add(model);
             /*db.Entry_score.Add(new Entry_score()
             {
                 entry_id=model.entry_id,
                 score=model.score,
                 student_id=model.student_id
             });*/
             db.SaveChanges();
         }
         return true;
     }
     catch (Exception e)
     {
         //throw e.InnerException;
         return false;
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 修改项目成绩
 /// </summary>
 /// <param name="model">修改后的model</param>
 public static bool ModifyEntry_score(string student_id, int entry_id, Entry_score model)
 {
     try
     {
         using (var db = new SEMSDBContext())
         {
             var temp = db.Entry_score.Find(student_id, entry_id);
             temp.score = model.score;
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 从excel批量导入特定项目成绩
        /// 说明:必须是“Sheet1”,必须有学号、得分列。
        /// </summary>
        /// <param name="entry_id">项目ID</param>
        /// <param name="fileName">excel文件的绝对路径</param>
        /// <returns>有效影添加或修改的记录数,为-1表示操作出错</returns>
        public static int ImportEntry_score(int entry_id, string fileName)
        {
            try
            {
                int ret = 0;
                using (var db = new SEMSDBContext())
                {
                    //string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=YES;IMEX=1'Data Source=" + fileName + ";";  //HDR=Yes,代表第一行是标题,不做为数据使用 ,如果用HDR=NO,则表示第一行不是标题,做为数据来使用。系统默认的是YES。IMEX=1,表示只读
                    string strConn = "Provider=Microsoft.ACE.OLEDB.12.0; Persist Security Info=False;Data Source=" + fileName + "; Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";
                    using (OleDbConnection conn = new OleDbConnection(strConn))
                    {

                        try
                        {
                            conn.Open();
                            string sql = "select * from [Sheet1$]";
                            OleDbCommand cmd = new OleDbCommand(sql, conn);
                            OleDbDataReader dr = cmd.ExecuteReader();
                            while (dr.Read())
                            {
                                Entry_score score = new Entry_score()
                                {
                                    entry_id = entry_id,
                                    score = int.Parse(dr["得分"].ToString()),// Convert.ToInt32(dr["得分"].ToString()),
                                    student_id = dr["学号"].ToString()
                                };
                                if (Entry_scoreBS.AddEntry_score(score))
                                {
                                    ret++;
                                }
                                else if (Entry_scoreBS.ModifyEntry_score(score.student_id, score.entry_id, score))
                                {
                                    ret++;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            throw e;
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
                return ret;
            }
            catch
            {
                return -1;
            }
        }