Пример #1
0
        private void savedevicetask(HttpContext context)
        {
            Foresight.DataAccess.Device_Task device = null;
            int ID = 0;

            int.TryParse(context.Request.Params["ID"], out ID);
            if (ID > 0)
            {
                device = Foresight.DataAccess.Device_Task.GetDevice_Task(ID);
            }
            if (device == null)
            {
                device             = new Foresight.DataAccess.Device_Task();
                device.TaskAddTime = DateTime.Now;
                device.TaskAddMan  = WebUtil.GetUser(context).RealName;
                device.IsAPPShow   = true;
                device.IsAPPSend   = false;
            }
            device.DeviceID            = getIntValue(context, "hdDeviceID");
            device.TaskFrom            = getValue(context, "tdTaskFrom");
            device.TaskType            = getValue(context, "tdTaskType");
            device.TaskLevel           = getValue(context, "tdTaskLevel");
            device.TaskStatus          = getIntValue(context, "tdTaskStatus");
            device.TaskChargeManID     = getIntValue(context, "tdTaskChargeMan");
            device.TaskChargeManName   = context.Request["tdTaskChargeManName"];
            device.TaskChargeManPhone  = getValue(context, "tdTaskChargeManPhone");
            device.TaskContent         = getValue(context, "tdTaskContent");
            device.TaskTime            = getTimeValue(context, "tdTaskTime");
            device.TaskCompleteTime    = getTimeValue(context, "tdTaskCompleteTime");
            device.TaskCompleteContent = getValue(context, "tdTaskCompleteContent");

            HttpFileCollection uploadFiles = context.Request.Files;
            List <Foresight.DataAccess.DeviceTask_Image> filelist = new List <Foresight.DataAccess.DeviceTask_Image>();

            for (int i = 0; i < uploadFiles.Count; i++)
            {
                HttpPostedFile postedFile = uploadFiles[i];
                string         FileName   = postedFile.FileName;
                if (FileName != "" && FileName != null)
                {
                    string   fileOriName = FileName;
                    string[] filearray   = FileName.Split(':');
                    if (filearray.Length > 1)
                    {
                        fileOriName = System.IO.Path.GetFileName(FileName);
                    }
                    string extension = System.IO.Path.GetExtension(FileName).ToLower();
                    string fileName  = DateTime.Now.ToFileTime().ToString() + extension;
                    string filepath  = "/upload/device/";
                    string rootPath  = HttpContext.Current.Server.MapPath("~" + filepath);
                    if (!System.IO.Directory.Exists(rootPath))
                    {
                        System.IO.Directory.CreateDirectory(rootPath);
                    }
                    string Path = rootPath + fileName;
                    postedFile.SaveAs(Path);
                    Foresight.DataAccess.DeviceTask_Image attach = new Foresight.DataAccess.DeviceTask_Image();
                    attach.FileOriName      = fileOriName;
                    attach.AttachedFilePath = filepath + fileName;
                    attach.AddTime          = DateTime.Now;
                    filelist.Add(attach);
                }
            }
            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    device.Save(helper);
                    foreach (var item in filelist)
                    {
                        item.DeviceTaskID = device.ID;
                        item.Save(helper);
                    }
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("DeviceHandler", "命令: savedevicetask", ex);
                    helper.Rollback();
                    WebUtil.WriteJson(context, new { status = false });
                    return;
                }
            }
            WebUtil.WriteJson(context, new { status = true, ID = device.ID });
        }
Пример #2
0
        //执行巡检任务生成
        public static int DoCheckTask()
        {
            int      count   = 0;
            DateTime NowDate = DateTime.Now;
            var      devices = Foresight.DataAccess.Device.GetDevices().Where(p => p.DeviceStatus == 1 && p.FirstCheckDate > DateTime.MinValue && p.CheckCount > 0 && !string.IsNullOrEmpty(p.CheckCycle)).ToArray();

            if (devices.Length == 0)
            {
                return(count);
            }
            var setting = DeviceSetting.GetDeviceSettingByCode(Utility.EnumModel.DeviceSettingCode.checktimesetup.ToString());
            List <Foresight.DataAccess.Device_Task>          tasklist      = new List <Device_Task>();
            List <Foresight.DataAccess.Device_TaskOperation> operationlist = new List <Device_TaskOperation>();
            List <Foresight.DataAccess.Device> devicelist = new List <Foresight.DataAccess.Device>();
            var appusers = Foresight.DataAccess.User.GetAPPUserList();

            foreach (var device in devices)
            {
                DateTime ThisCheckTime = device.FirstCheckDate;
                var      check_log     = Foresight.DataAccess.Device_TaskOperation.GetTopDevice_TaskOperation("check", device.ID);
                if (check_log != null)
                {
                    ThisCheckTime = check_log.ThisOperationTime;
                }
                DateTime NextCheckTime = DateTime.MinValue;
                DateTime NextAllowTime = GetNextCheckTime(setting, ThisCheckTime, device, out NextCheckTime);
                if (NextAllowTime > NowDate)
                {
                    continue;
                }
                var task = new Foresight.DataAccess.Device_Task();
                task.DeviceID   = device.ID;
                task.TaskFrom   = Utility.EnumModel.DeviceTaskFromDefine.system.ToString();
                task.TaskType   = Utility.EnumModel.DeviceTaskTypeDefine.system_check.ToString();
                task.TaskLevel  = "紧急";
                task.TaskStatus = 1;
                var user = appusers.FirstOrDefault(p => p.UserID == device.CheckUserID);
                task.TaskChargeManID    = user == null ? int.MinValue : user.UserID;
                task.TaskChargeManName  = user == null ? string.Empty : user.RealName;
                task.TaskChargeManPhone = user == null ? string.Empty : user.PhoneNumber;
                task.TaskContent        = string.Empty;
                task.TaskTime           = NextCheckTime;
                task.IsAPPSend          = false;
                task.IsAPPShow          = true;
                tasklist.Add(task);
                var operation = new Foresight.DataAccess.Device_TaskOperation();
                operation.DeviceID          = device.ID;
                operation.OperationType     = "check";
                operation.AddTime           = NowDate;
                operation.ThisOperationTime = NextCheckTime;
                operationlist.Add(operation);
                device.LastCheckDate = device.ThisCheckDate;
                device.ThisCheckDate = NextCheckTime;
                devicelist.Add(device);
            }
            using (SqlHelper helper = new SqlHelper())
            {
                try
                {
                    helper.BeginTransaction();
                    foreach (var item in tasklist)
                    {
                        item.Save(helper);
                        count++;
                    }
                    foreach (var item in operationlist)
                    {
                        item.Save(helper);
                    }
                    foreach (var item in devicelist)
                    {
                        item.Save(helper);
                    }
                    helper.Commit();
                }
                catch (Exception ex)
                {
                    LogHelper.WriteError("巡检任务生成", "DoXunJianTask", ex);
                    helper.Rollback();
                }
            }
            return(count);
        }