ScoreService.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. public class ScoreService
  11. {
  12. /// <summary>
  13. /// 添加分数
  14. /// </summary>
  15. /// <param name="s"></param>
  16. public bool AddScore(Scores s)
  17. {
  18. string sql = "INSERT INTO Score(Nid,NName,Score,Weak,Uid,InputTime,STid,STName)VALUES(@Nid,@NName,@Score,@Weak,@Uid,@InputTime,@STid,@STName)";
  19. SqlParameter[] parameter = new SqlParameter[] {
  20. new SqlParameter("@Nid",s.Nid),
  21. new SqlParameter("@NName",s.NName),
  22. new SqlParameter("@Score",s.Score),
  23. new SqlParameter("@Weak",s.Wake),
  24. new SqlParameter("@Uid",s.Uid),
  25. new SqlParameter("@InputTime",s.InputTime),
  26. new SqlParameter("@STid",s.STid),
  27. new SqlParameter("@STName",s.STName),
  28. };
  29. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  30. return true;
  31. else
  32. return false;
  33. }
  34. /// <summary>
  35. /// 根据用户id获取该用户指定时间的评分信息
  36. /// </summary>
  37. /// <param name="id"></param>
  38. /// <returns></returns>
  39. public List<ViewScore> getScoreByUID(int id, string time)
  40. {
  41. List<ViewScore> vss = new List<ViewScore>();
  42. string sql = "select * from setDataType where Name in ('办公桌面','安全防范能源消耗','请假次数','行为规范','礼貌礼节')";
  43. SetDataTypeService sdtss = new SetDataTypeService();
  44. SetDataService setDatasv = new SetDataService();
  45. List<SetDataType> sdts = sdtss.excuteSql(sql, null);
  46. if (sdts != null)
  47. {
  48. List<SetData> sds = new List<SetData>();
  49. for (int i = 0; i < sdts.Count; i++)
  50. {
  51. ViewScore vs = new ViewScore();
  52. Scores s = new Scores();
  53. //根据每个考察类型和时间查询指定用户的分数信息
  54. SqlParameter[] parameter = new SqlParameter[]{
  55. new SqlParameter("@Uid",id),
  56. new SqlParameter("@time",time),
  57. new SqlParameter("@sTid",sdts[i].Id)
  58. };
  59. List<Scores> scores = excuteSql("select * from Score where Uid=@Uid and InputTime=@time and sTid=@sTid", CommandType.Text, parameter);
  60. if (scores != null&&scores.Count>0)
  61. s = scores[0];
  62. vs.Sdt = sdts[i];
  63. vs.Sc = s;
  64. vss.Add(vs);
  65. }
  66. }
  67. return vss;
  68. }
  69. /// <summary>
  70. /// 返回实体的集合
  71. /// </summary>
  72. /// <param name="sql"></param>
  73. /// <param name="commandType"></param>
  74. /// <param name="parameter"></param>
  75. /// <returns></returns>
  76. private List<Scores> excuteSql(string sql, CommandType commandType, SqlParameter[] parameter)
  77. {
  78. return ServiceBase<Scores>.excuteSql(new Scores(), "Scores", sql, CommandType.Text, parameter);
  79. }
  80. /// <summary>
  81. /// 根据考察类型和时间获取员工的评分信息
  82. /// </summary>
  83. /// <param name="p"></param>
  84. /// <param name="p_2"></param>
  85. /// <param name="stid"></param>
  86. /// <returns></returns>
  87. public List<Scores> getScoreBySTID(string time, int uid, int stid)
  88. {
  89. SqlParameter[] parameter = new SqlParameter[]{
  90. new SqlParameter("@Uid",uid),
  91. new SqlParameter("@time",time),
  92. new SqlParameter("@sTid",stid)
  93. };
  94. return excuteSql("select * from Score where Uid=@Uid and InputTime=@time and sTid=@stid", CommandType.Text, parameter);
  95. }
  96. }
  97. }