예제 #1
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="btn"></param>
        /// <returns></returns>
        public static bool UpdateStudent(Students Stu)
        {
            Students Stuto = StudentData.GetStudentsByID(Stu.ID); //获取对象

            Cloner <Students, Students> .CopyTo(Stu, Stuto);      //代码克隆,把前台或者的值也就是变更内容复制到目标对象,不做变更的数据不变

            return(MsSqlMapperHepler.Update(Stuto, DBKeys.PRX));
        }
예제 #2
0
        /// <summary>
        /// 保存考勤记录,正常考勤扣除课时
        /// </summary>
        /// <param name="ar"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static bool saveStudentAttendance(List <AttendanceRecord> ar, string userid)
        {
            bool         ret = false;
            DBRepository db  = new DBRepository(DBKeys.PRX);

            try{
                db.BeginTransaction();//事务开始

                foreach (AttendanceRecord value in ar)
                {
                    if (value == null)
                    {
                        continue;
                    }
                    AttendanceRecord btnto = AttendaceData.GetAttendanceRecordByStudentClass(value.StudentID, value.ClassID, value.ClassIndex); //获取对象

                    if (value.ClockTime != null)                                                                                                //正常打卡扣除课时
                    {
                        Enroll enroll = db.Query <Enroll>("select * from Enroll where StudentID = '" + value.StudentID + "' and ClassID = '" + value.ClassID + "'").FirstOrDefault();
                        if (enroll != null)
                        {
                            //-----添加课时变化日志记录 begin
                            TransferRecord tr = new TransferRecord();//添加课时变化日志记录
                            tr.StudentID   = enroll.StudentID;
                            tr.BeforeHours = enroll.ClassHour - enroll.UsedHour;
                            tr.AfterHours  = enroll.ClassHour - enroll.UsedHour - 1;
                            tr.TypeID      = 5;//ERP考勤操作
                            tr.CreateTime  = DateTime.Now;
                            tr.CreatorId   = userid;
                            tr.ENID        = enroll.ID;
                            tr.ClassID     = enroll.ClassID;
                            db.Insert(tr);
                            //-----添加课时变化日志记录 end


                            enroll.UsedHour = enroll.UsedHour + 1;
                            db.Update(enroll);



                            Students s = StudentData.GetStudentsByID(value.StudentID);               //获取学员
                            if (s.StateID != null && (s.StateID.Value == 1 || s.StateID.Value == 3)) //冻结和未读状态下
                            {
                                s.StateID = 2;                                                       //改成在读
                                db.Update <Students>(s);
                            }
                            ClassList cl = db.Query <ClassList>("select * from ClassList where ClassID = '" + value.ClassID + "' and ClassIndex = " + value.ClassIndex).FirstOrDefault();
                            cl.StateID = 2;//课时状态变成已上
                            db.Update <ClassList>(cl);
                        }
                        else
                        {
                            throw new Exception("获取报名记录错误");
                        }


                        //插入考勤记录---------------------------------
                        if (btnto == null)
                        {
                            btnto                  = new AttendanceRecord();
                            btnto.OutStatus        = 0;
                            btnto.ClockTime        = value.ClockTime;
                            btnto.AttendanceTypeID = 2;//考勤正常
                            btnto.CreateTime       = DateTime.Now;
                            btnto.CreatorId        = userid;
                            btnto.AttendanceWayID  = 3;//工作人员操作
                            btnto.ClassID          = value.ClassID;
                            btnto.ClassIndex       = value.ClassIndex;
                            btnto.StudentID        = value.StudentID;
                            btnto.Remark           = "更新考勤记录,识别成功,当前剩余课时:" + (enroll.ClassHour - enroll.UsedHour).ToString();
                            db.Insert(btnto);//新增考勤
                        }
                        else//如果之前有考勤记录了,且未打卡则更新打卡
                        {
                            if (btnto.ClockTime == null)//未打卡
                            {
                                btnto.OutStatus        = 0;
                                btnto.ClockTime        = value.ClockTime;
                                btnto.AttendanceTypeID = 2;//考勤正常
                                btnto.UpdateTime       = DateTime.Now;
                                btnto.UpdatorId        = userid;
                                btnto.AttendanceWayID  = 3;//工作人员操作
                                btnto.ClassID          = value.ClassID;
                                btnto.ClassIndex       = value.ClassIndex;
                                btnto.StudentID        = value.StudentID;
                                btnto.Remark           = "更新考勤记录,识别成功,当前剩余课时:" + (enroll.ClassHour - enroll.UsedHour).ToString();
                                db.Update(btnto);//更新
                            }
                            else
                            {
                                throw new Exception("已有考勤记录!");
                            }
                        }
                    }
                    if (value.ClockTime == null)//未打卡
                    {
                        Enroll enroll = db.Query <Enroll>("select * from Enroll where StudentID = '" + value.StudentID + "' and ClassID = '" + value.ClassID + "'").FirstOrDefault();

                        if (enroll != null && value.AttendanceTypeID == 3)//缺勤状态还是要扣课时,同时更新报名记录的小号课时
                        {
                            //-----添加课时变化日志记录 begin
                            TransferRecord tr = new TransferRecord();//添加课时变化日志记录
                            tr.StudentID   = enroll.StudentID;
                            tr.BeforeHours = enroll.ClassHour - enroll.UsedHour;
                            tr.AfterHours  = enroll.ClassHour - enroll.UsedHour - 1;
                            tr.TypeID      = 5;//ERP考勤操作
                            tr.CreateTime  = DateTime.Now;
                            tr.CreatorId   = userid;
                            tr.ENID        = enroll.ID;
                            tr.ClassID     = enroll.ClassID;
                            db.Insert(tr);
                            //-----添加课时变化日志记录 end

                            enroll.UsedHour = enroll.UsedHour + 1;
                            db.Update(enroll);
                            ClassList cl = db.Query <ClassList>("select * from ClassList where ClassID = '" + value.ClassID + "' and ClassIndex = " + value.ClassIndex).FirstOrDefault();
                            cl.StateID = 2;//课时状态变成已上
                            db.Update <ClassList>(cl);
                        }

                        //新增考勤记录--------------------------------------------------------------
                        if (btnto == null)
                        {
                            btnto = new AttendanceRecord();
                            btnto.AttendanceTypeID = value.AttendanceTypeID;


                            btnto.CreateTime      = DateTime.Now;
                            btnto.CreatorId       = userid;
                            btnto.AttendanceWayID = 3;//工作人员操作
                            btnto.ClassID         = value.ClassID;
                            btnto.ClassIndex      = value.ClassIndex;
                            btnto.StudentID       = value.StudentID;
                            btnto.Remark          = "更新考勤记录,识别成功,当前剩余课时:" + (enroll.ClassHour - enroll.UsedHour).ToString();
                            db.Insert(btnto);//新增考勤
                        }
                        else//如果之前有考勤记录了,且未打卡则更新打卡
                        {
                            if (btnto.ClockTime == null)//已打卡,不允许改成请假
                            {
                                btnto.AttendanceTypeID = value.AttendanceTypeID;

                                btnto.UpdateTime      = DateTime.Now;
                                btnto.UpdatorId       = userid;
                                btnto.AttendanceWayID = 3;//工作人员操作
                                btnto.ClassID         = value.ClassID;
                                btnto.ClassIndex      = value.ClassIndex;
                                btnto.StudentID       = value.StudentID;
                                btnto.Remark          = "更新考勤记录,识别成功,当前剩余课时:" + (enroll.ClassHour - enroll.UsedHour).ToString();
                                db.Update(btnto);//更新
                            }
                            else
                            {
                                throw new Exception("已有考勤记录!");
                            }
                        }
                    }
                }

                db.Commit();  //事务提交
                db.Dispose(); //资源释放
                ret = true;   //新增成功
            }
            catch (Exception ex)
            {
                db.Rollback();
                db.Dispose();//资源释放
                throw new Exception(ex.Message + "。" + ex.InnerException.Message);
            }


            return(ret);
        }