//TODO 也许该与GetTrainingLog整合 internal static List <TTrainingLogInfo> LoadTrainingLog(Guid gTrainingID) { var lst = new List <TTrainingLogInfo>(); using (var context = new TrainingSign_Entities()) { var qry = from p in context.tbl_trainee from t in context.tbl_training from c in context.tbl_course where t.id == gTrainingID && p.ref_training_id == t.id && t.ref_course_id == c.id select new { id = p.id, workid = p.workid, cn_name = p.name, dept_name = p.department, organ_name = p.organizer, course_no = c.course_no, course_context = c.course_context, plan_start_time = t.plan_start_time, plan_end_time = t.plan_end_time, signinTime = p.signinTime }; var its = from x in qry.AsEnumerable() select new TTrainingLogInfo { id = x.id, workid = x.workid, cn_name = x.cn_name, dept_name = x.dept_name, organ_name = x.organ_name, course_no = x.course_no, course_context = x.course_context, training_time = LocalFormatStr.GetLocalTimeStrHHMM(x.plan_start_time.Value) + (x.plan_end_time.HasValue ? "~" + LocalFormatStr.GetLocalTimeStrHHMM(x.plan_end_time.Value) : ""), signin_time = x.signinTime.HasValue ? LocalFormatStr.GetLocalTimeStr(x.signinTime.Value) : "" }; return(its.Any() ? its.ToList() : lst); } }
internal static List <TTrainingByTime> LoadTrainingDateByCourseID(string sCourID, string sMonth) { var lst = new List <TTrainingByTime>(); Guid gid = Guid.Empty; if (!Guid.TryParse(sCourID, out gid)) { return(lst); } int nYear = 0; int nMon = 0; int iPos = sMonth.IndexOf('-'); if (iPos > 0) { var str = sMonth.Substring(0, iPos); nYear = int.Parse(str); str = sMonth.Substring(iPos + 1); nMon = int.Parse(str); } using (var context = new TrainingSign_Entities()) { var its = from t in context.tbl_training.AsEnumerable() where t.ref_course_id == gid && t.plan_start_time.HasValue && (t.plan_end_time.Value.Year == nYear && t.plan_start_time.Value.Month == nMon) orderby t.plan_start_time descending select new TTrainingByTime { id = t.id, text = LocalFormatStr.GetLocalTimeStrHHMM(t.plan_start_time.Value) + (t.plan_end_time.HasValue ? "~" + LocalFormatStr.GetLocalTimeStrHHMM(t.plan_end_time.Value) : "") }; return(its.Any() ? its.ToList() : lst); } }
internal static IList <TPersonInfo> LoadByTrainingID(Guid gTrainingID, int pageSize, int iPage = -1) { using (var context = new TrainingSign_Entities()) { IQueryable <tbl_trainee> qry = null; if (iPage <= 0) { qry = from x in context.tbl_trainee where x.ref_training_id == gTrainingID orderby x.signinTime descending select x; } else { qry = (from x in context.tbl_trainee where x.ref_training_id == gTrainingID orderby x.signinTime descending select x ).Skip((iPage - 1) * pageSize).Take(pageSize); } if (qry.Any()) { var items = from p in qry.AsEnumerable() select new TPersonInfo { extra = p.id, //注意 workid = p.workid, cn_name = p.name, org_name = p.department, oper_time_str = !p.signinTime.HasValue ? "" : LocalFormatStr.GetLocalTimeStr(p.signinTime.Value) }; return(items.ToList()); } return(null); } }
/// <summary> /// /// </summary> /// <param name="snr"></param> /// <param name="gTrainingID"></param> /// <param name="empInfo"></param> /// <param name="serr"></param> /// <returns> /// 0 -- 失败 /// 1 -- 签到成功 /// -1 -- 已经签到过 /// </returns> internal static int Add(string snr, Guid gTrainingID, out TPersonInfo empInfo, out string serr) { empInfo = null; serr = string.Empty; var info = WorkIDInfo.GetEmployeeInfo(snr); if (null == info) { serr = "没有找到此员工信息"; return(0); } //insert int nRet = -1; using (var context = new TrainingSign_Entities()) { //由于部门解释还是有问题,用来避免由于部门名称过长而插入失败, //这里的限制与 tbl_trainee的department列一致 var sDept = StringUtility.LimitStr(info.shortDepartment, 80); //insert var entity = new tbl_trainee() { ref_training_id = gTrainingID , workid = info.empID , name = info.cnName , department = sDept , signinTime = DateTime.Now //,organizer //,memo }; if (!context.tbl_trainee.Any(x => x.ref_training_id == entity.ref_training_id && 0 == string.Compare(x.workid, entity.workid, StringComparison.InvariantCultureIgnoreCase))) { try { context.tbl_trainee.Add(entity); context.SaveChanges(); nRet = 1; empInfo = new TPersonInfo { extra = entity.id, //!注意 workid = entity.workid, cn_name = entity.name, org_name = entity.department, oper_time_str = LocalFormatStr.GetLocalTimeStr(entity.signinTime.Value) }; } catch (Exception ex) { //serr = ex.Message; serr = "添加员工签到失败"; } } else { //已经签到过 empInfo = new TPersonInfo { workid = entity.workid, cn_name = entity.name, org_name = entity.department, oper_time_str = "" }; } } return(nRet); }