/// <summary> /// 更新一条数据 /// </summary> public bool Update(Cl_MidAttendce model) { using (IDbConnection conn = OpenConnection()) { const string sqlwhere = @"UPDATE Cl_MidAttendce SET CourseId = @courseid,UserId = @userid,CreateTime = @createtime,Time = @time WHERE Id=@Id"; var param = new { model.CourseId, model.UserId, model.CreateTime, model.Time, model.Id }; return(conn.Execute(sqlwhere, param) > 0); } }
/// <summary> /// 增加一条数据 /// </summary> public void Add(Cl_MidAttendce model) { using (IDbConnection conn = OpenConnection()) { const string sqlwhere = @"INSERT INTO Cl_MidAttendce (CourseId,UserId,CreateTime,Time) VALUES (@courseid,@userid,@createtime,@time) SELECT @@IDENTITY AS Id"; var param = new { model.CourseId, model.UserId, model.CreateTime, model.Time }; decimal id = conn.Query <decimal>(sqlwhere, param).FirstOrDefault(); model.Id = decimal.ToInt32(id); } }
/// <summary> /// 添加签到表 /// </summary> /// <param name="CourseId">课程ID</param> /// <param name="DataTable"></param> public string AddAttendces(int CourseId, DataTable dtlist) { int cg = 0; int sb = 0; for (int i = 0; i < dtlist.Rows.Count; i++) { try { int userid = Convert.ToInt32(dtlist.Rows[i][1].ToString()); string starttime = dtlist.Rows[i][4].ToString(); string endtime = dtlist.Rows[i][5].ToString(); if (starttime == "--" || string.IsNullOrEmpty(starttime)) { starttime = "2050-1-1"; } if (endtime == "--" || string.IsNullOrEmpty(endtime)) { endtime = "2000-1-1"; } //Co_Course coUser = AttDB.GetCoAndUser(CourseId, userid); Sys_User leamodel = GetLeaderIdByUserId(userid); decimal GetScore = 0; decimal AttLessLength = 0; string whereStr = string.Format(" where cco.CourseId={0} and cco.UserId={1}", CourseId, userid); Cl_CourseOrder Comodel = CoDB.GetmodelbyAtt(whereStr); //判断考勤之后的流程是否已经开始走下去了 //if (Comodel == null || Comodel.LearnStatus == 0) //{ if (Comodel == null) { Comodel = new Cl_CourseOrder(); Comodel.CourseId = CourseId; Comodel.UserId = userid; Comodel.OrderTime = DateTime.Now; Comodel.OrderStatus = 3; Comodel.IsLeave = 0; if (leamodel == null) { Comodel.ApprovalUser = ""; } else { Comodel.ApprovalUser = leamodel.JobNum; } Comodel.ApprovalMemo = ""; Comodel.ApprovalFlag = 0; Comodel.ApprovalDateTime = DateTime.Now; Comodel.ApprovalLimitTime = DateTime.Now; Comodel.OrderTimes = 0; Comodel.LearnStatus = 0; Comodel.GetScore = GetScore; Comodel.PassStatus = 0; Comodel.IsAppoint = 0; Comodel.OrderEndTime = DateTime.Now; Comodel.AttScore = 0; Comodel.AttFlag = 0; CoDB.Add(Comodel); } else { if (Comodel.OrderStatus == 0 || Comodel.OrderStatus == 2) { Comodel.OrderStatus = 3; } else if (Comodel.OrderStatus == 1 && Comodel.IsLeave == 1 && Comodel.ApprovalFlag == 1 && Comodel.ApprovalLimitTime > Comodel.ApprovalDateTime) { Comodel.OrderStatus = 3; } else if (Comodel.TimeOutLeaveApprovalFlag == 1) { Comodel.OrderStatus = 3; } //Comodel.OrderTime = DateTime.Now; //Comodel.GetScore = GetScore; //Comodel.OrderEndTime = DateTime.Now; CoDB.Update(Comodel); } Cl_Attendce attmodel = clAttDB.GetCl_Attendce(CourseId, userid); if (attmodel == null) { attmodel = new Cl_Attendce(); attmodel.CourseId = CourseId; attmodel.UserId = userid; attmodel.StartTime = DateTime.Parse(starttime); attmodel.EndTime = DateTime.Parse(endtime); attmodel.OnlineStartTime = DateTime.Parse(starttime); attmodel.OnlineEndTime = DateTime.Parse(endtime); attmodel.LessLength = AttLessLength; if (leamodel == null) { attmodel.ApprovalUser = ""; } else { attmodel.ApprovalUser = leamodel.JobNum; } attmodel.ApprovalMemo = ""; attmodel.ApprovalFlag = 0; attmodel.ApprovalDateTime = DateTime.Now; clAttDB.AddAttendce(attmodel); } else { attmodel.StartTime = DateTime.Parse(starttime); attmodel.EndTime = DateTime.Parse(endtime); attmodel.OnlineStartTime = DateTime.Parse(starttime); attmodel.OnlineEndTime = DateTime.Parse(endtime); attmodel.LessLength = AttLessLength; if (leamodel == null) { attmodel.ApprovalUser = ""; } else { attmodel.ApprovalUser = leamodel.JobNum; } attmodel.ApprovalMemo = ""; attmodel.ApprovalFlag = 0; attmodel.ApprovalDateTime = DateTime.Now; clAttDB.UpdateAttendce(attmodel); } if (dtlist.Columns.Count > 6) { for (int j = 0; j < (dtlist.Columns.Count - 6); j++) { string where = string.Format(" where CourseId={0} and UserId={1} and Time={2}", CourseId, userid, j + 1); Cl_MidAttendce clmmodel = clMidDB.GetModel(where); string lintime = dtlist.Rows[i][j + 6].ToString(); if (lintime == "--" || string.IsNullOrEmpty(lintime)) { lintime = "2000-1-1"; } if (clmmodel == null) { clmmodel = new Cl_MidAttendce(); clmmodel.CourseId = CourseId; clmmodel.UserId = userid; clmmodel.CreateTime = DateTime.Parse(lintime); clmmodel.Time = j + 1; clMidDB.Add(clmmodel); } else { clmmodel.CreateTime = DateTime.Parse(lintime); clMidDB.Update(clmmodel); } } } cg += 1; //} //else //{ // sb += 1; //} } catch (Exception ex) { sb += 1; } } return("成功" + cg + "条,失败" + sb + "条"); }