public ActionResult Reserve(int id, FormCollection form)
 {
     try
     {
         DateTime begTime = Convert.ToDateTime(form["Time"].Split('~')[0].Trim());
         DateTime endTime = Convert.ToDateTime(form["Time"].Split('~')[1].Trim());
         string   rid     = form["ResourceID"];
         bool     add     = false;
         var      obj     = dc.Set <T_ResourceStatus>().Where(a => a.ID == id).FirstOrDefault();
         if (obj == null)
         {
             //开始时间处于区间
             int count = dc.Set <T_ResourceStatus>().Where(a =>
                                                           (begTime > a.RentBeginTime && begTime < a.RentEndTime) ||
                                                           (endTime > a.RentBeginTime && endTime < a.RentEndTime) &&
                                                           a.ResourceID == rid).Count();
             if (count > 0)
             {
                 return(Json(Result.Fail(msg: "存在使用时间冲突,请选择有效时间段!")));
             }
             obj              = new T_ResourceStatus();
             obj.SysID        = 3;
             obj.BusinessID   = Guid.NewGuid().ToString();
             obj.BusinessType = 5;
             add              = true;
         }
         else
         {
             int count = dc.Set <T_ResourceStatus>().Where(a =>
                                                           (begTime > a.RentBeginTime && begTime < a.RentEndTime) ||
                                                           (endTime > a.RentBeginTime && endTime < a.RentEndTime) &&
                                                           a.ResourceID == rid && a.ID != id).Count();
             if (count > 0)
             {
                 return(Json(Result.Fail(msg: "存在使用时间冲突,请选择有效时间段!")));
             }
         }
         if (!TryUpdateModel(obj, "", form.AllKeys, new string[] { "ID", "BusinessID", "SysID", "BusinessType", "Enable" }))
         {
             return(Json(Result.Fail()));
         }
         obj.RentBeginTime = begTime;
         obj.RentEndTime   = endTime;
         obj.UpdateTime    = DateTime.Now;
         obj.UpdateUser    = user.Account;
         if (add)
         {
             dc.Set <T_ResourceStatus>().Add(obj);
         }
         if (dc.SaveChanges() > 0)
         {
             return(Json(Result.Success()));
         }
         return(Json(Result.Fail()));
     }
     catch (Exception ex)
     {
         return(Json(Result.Exception(exmsg: ex.StackTrace)));
     }
 }
 public JsonResult CUse(FormCollection form)
 {
     try
     {
         T_ResourceStatus status = new T_ResourceStatus();
         if (!TryUpdateModel(status, "", form.AllKeys))
         {
             return(Json(Result.Fail(msg: "操作数据失败,请检查数据的准确性!")));
         }
         var begin = status.RentBeginTime;
         var end   = status.RentEndTime;
         if (begin > end || CheckTime(begin, end, status.ResourceID))
         {
             return(Json(Result.Fail(msg: "时间冲突,请选择正确的时间!")));
         }
         status.SysID        = 3;
         status.RentType     = 1;
         status.BusinessID   = Guid.NewGuid().ToString();
         status.BusinessType = 5;
         status.Status       = 1;
         status.UpdateTime   = DateTime.Now;
         status.UpdateUser   = user.Account;
         dc.Set <T_ResourceStatus>().Add(status);
         dc.SaveChanges();
         return(Json(Result.Success()));
     }
     catch (Exception ex)
     {
         return(Json(Result.Exception(exmsg: ex.StackTrace)));
     }
 }