예제 #1
0
        /// <summary>
        /// 添加请假记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Response AddQJRecord(Request <QJRecord> request)
        {
            Response <QJRecord> response = new Response <QJRecord>();

            try
            {
                if (request != null && request.Data != null)
                {
                    QJRecord model = request.Data;
                    model.UserID = new Utility().GetUserID(cookieKey);
                    //model.Year = model.STime.Year;
                    //model.Month = model.STime.Month;
                    model.Type         = IsEnoughRestHours(model.UserID, model.STime.Year, model.Hours, request.RequestKey) ? LeaveType.Rest : LeaveType.Leave;
                    model.AddTime      = DateTime.Now;
                    model.ModifiedTime = DateTime.Now;
                    dbContext.QJRecords.Add(model);
                    if (dbContext.SaveChanges() > 0)
                    {
                        log.AddLog(LogType.Info, "AddQJRecord,添加请假成功:" + JsonConvert.SerializeObject(model), request.RequestKey);
                        if (model.Type == LeaveType.Rest)
                        {
                            var qid = dbContext.QJRecords.Select(o => o.QID).Max();
                            txlogic.SubtractHours(qid, model.STime, model.Hours, model.Remark, request.RequestKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.ErrorMsg = "添加失败,系统异常!";
                log.AddLog(LogType.Error, "AddQJRecord,添加请假异常:" + ex.Message, request.RequestKey);
            }
            return(response);
        }
예제 #2
0
        /// <summary>
        /// 删除请假记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Response DelQJRecord(Request <int> request)
        {
            Response <QJRecord> response = new Response <QJRecord>();

            try
            {
                if (request != null)
                {
                    Request <int> req = new Request <int>()
                    {
                        RequestKey  = request.RequestKey,
                        RequsetTime = request.RequsetTime,
                        Data        = request.Data
                    };
                    QJRecord model = GetQJRecordById(req).Result;
                    dbContext.QJRecords.Remove(model);
                    if (dbContext.SaveChanges() > 0)
                    {
                        log.AddLog(LogType.Info, "DelQJRecord,删除请假成功:" + JsonConvert.SerializeObject(model), request.RequestKey);
                        if (model.Type == LeaveType.Rest)
                        {
                            txlogic.DelTXHours(model.QID, OAType.QingJia, request.RequestKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.ErrorMsg = "删除失败,系统异常!";
                log.AddLog(LogType.Error, "DelQJRecord,删除请假异常:" + ex.Message, request.RequestKey);
            }
            return(response);
        }
예제 #3
0
        /// <summary>
        /// 修改请假记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public Response EditQJRecord(Request <QJRecord> request)
        {
            Response <QJRecord> response = new Response <QJRecord>();

            try
            {
                if (request != null && request.Data != null)
                {
                    QJRecord      data = request.Data;
                    Request <int> req  = new Request <int>()
                    {
                        RequestKey  = request.RequestKey,
                        RequsetTime = request.RequsetTime,
                        Data        = data.QID
                    };
                    QJRecord model   = GetQJRecordById(req).Result;
                    var      orgType = model.Type;
                    model.STime                  = data.STime;
                    model.ETime                  = data.ETime;
                    model.Hours                  = data.Hours;
                    model.Remark                 = data.Remark;
                    model.ModifiedTime           = DateTime.Now;
                    model.Type                   = IsEnoughRestHours(model.UserID, model.STime.Year, model.Hours, request.RequestKey) ? LeaveType.Rest : LeaveType.Leave;
                    dbContext.Entry(model).State = EntityState.Modified;
                    if (dbContext.SaveChanges() > 0)
                    {
                        log.AddLog(LogType.Info, "EditQJRecord,修改请假成功:" + JsonConvert.SerializeObject(model), request.RequestKey);
                        if (orgType == LeaveType.Rest && model.Type == LeaveType.Rest)
                        {
                            txlogic.EditTXHours(model.QID, OAType.QingJia, model.STime, 0 - model.Hours, model.Remark, request.RequestKey);
                        }
                        else if (orgType == LeaveType.Leave && model.Type == LeaveType.Rest)
                        {
                            txlogic.SubtractHours(model.QID, model.STime, model.Hours, model.Remark, request.RequestKey);
                        }
                        else if (orgType == LeaveType.Rest && model.Type == LeaveType.Leave)
                        {
                            txlogic.DelTXHours(model.QID, OAType.QingJia, request.RequestKey);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.ErrorMsg = "修改失败,系统异常!";
                log.AddLog(LogType.Error, "EditQJRecord,修改请假异常:" + ex.Message, request.RequestKey);
            }
            return(response);
        }
예제 #4
0
 /// <summary>
 /// 添加请假记录
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public ActionResult AddQJ(QJRecord data)
 {
     if (Request.HttpMethod == "POST")
     {
         Response           response = new Entity.Response();
         Request <QJRecord> request  = new Request <QJRecord>();
         request.Data        = data;
         request.RequestKey  = Guid.NewGuid().ToString();
         request.RequsetTime = DateTime.Now;
         response            = logic.AddQJRecord(request);
         return(Json(new { response }));
     }
     else
     {
         return(View());
     }
 }
예제 #5
0
 /// <summary>
 /// 删除请假记录
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public ActionResult DeleteQJ(QJRecord data)
 {
     if (Request.HttpMethod == "POST")
     {
         Response response = new Entity.Response();
         if (data != null)
         {
             Request <int> request = new Request <int>();
             request.Data        = data.QID;
             request.RequestKey  = Guid.NewGuid().ToString();
             request.RequsetTime = DateTime.Now;
             response            = logic.DelQJRecord(request);
         }
         return(Json(new { response }));
     }
     else
     {
         return(View());
     }
 }