Ejemplo n.º 1
0
        //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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        /// <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);
        }