public JsonResult Create(AttendType obj)
 {
     try
     {
         NSession.SaveOrUpdate(obj);
         NSession.Flush();
     }
     catch (Exception ee)
     {
         return Json(new { IsSuccess = false, ErrorMsg = "出错了" });
     }
     return Json(new { IsSuccess = true });
 }
 public void NoAttend(DateTime LastAttend)
 {
     TimeSpan day = DateTime.Now.Date - LastAttend;
     for (int i = 1; i < day.Days; i++)
     {
         AttendType obj = new AttendType() { CurrentDate = DateTime.Now.Date.AddDays(-i), UserId = CurrentUser.Id, UserCode = CurrentUser.Code, RealName = CurrentUser.Realname };
         NSession.Save(obj);
         NSession.Flush();
     }
 }
        //签到操作
        public JsonResult AttendOn(int id, string code = "")
        {
            string ip = GetIP();
            DateTime AttentTime = DateTime.Now;
            int userid = CurrentUser.Id;
            string usercode = CurrentUser.Code;
            string realname = CurrentUser.Realname;
            if (code != "")
            {
                IList<UserType> users = NSession.CreateQuery("from UserType where Code='" + code + "'").List<UserType>();
                if (users.Count > 0)
                {
                    userid = users[0].Id;
                    usercode = users[0].Code;
                    realname = users[0].Realname;
                }
                else
                {
                    return Json(new { Msg = code + " 编号不存在!" }, JsonRequestBehavior.AllowGet);
                }
            }
            AttendType obj = new AttendType() { CurrentDate = AttentTime.Date, UserId = userid, UserCode = usercode, RealName = realname };
            try
            {

                IList<AttendType> list = NSession.CreateQuery("from AttendType where UserId='" + obj.UserId + "' and CurrentDate='" + obj.CurrentDate + "'").List<AttendType>();
                if (IsOK(ip))
                {
                    //IList<AttendType> objList = NSession.CreateQuery("from AttendType " + " where UserId=\'" + obj.UserId + "\'  order by CurrentDate desc ")
                    //.List<AttendType>();
                    //if (objList.Count > 0)
                    //{
                    //   //NoAttend(objList[0].CurrentDate);
                    //}
                    if (list.Count > 0)
                    {
                        obj = list[0];
                    }
                    obj.IP = ip;
                }
                else
                    return Json(new { Msg = "请使用公司网络打卡!" }, JsonRequestBehavior.AllowGet);

                switch (id)
                {
                    case 0:
                        if (string.IsNullOrEmpty(obj.AMStart))
                        {
                            obj.AMStart = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        else
                            return Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet);
                        break;
                    case 1:
                        if (string.IsNullOrEmpty(obj.AMEnd))
                        {
                            obj.AMEnd = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        else
                            return Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet);
                        break;
                    case 2:
                        if (string.IsNullOrEmpty(obj.PMStart))
                        {
                            obj.PMStart = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        else
                            return Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet);
                        break;
                    case 3:
                        if (string.IsNullOrEmpty(obj.PMEnd))
                        {
                            obj.PMEnd = AttentTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        else
                            return Json(new { Msg = "请不要重复打卡!" }, JsonRequestBehavior.AllowGet);
                        break;
                }
                NSession.SaveOrUpdate(obj);
                NSession.Flush();
            }
            catch (Exception ee)
            {
                return Json(new { Msg = "出错了" }, JsonRequestBehavior.AllowGet);
            }
            return Json(new { Msg = obj.RealName + " 签到成功:" + AttentTime.ToString("yyyy-MM-dd HH:mm:ss") }, JsonRequestBehavior.AllowGet);

        }