private void savedevice(HttpContext context) { Foresight.DataAccess.Device device = null; int ID = 0; int.TryParse(context.Request.Params["ID"], out ID); if (ID > 0) { device = Foresight.DataAccess.Device.GetDevice(ID); } if (device == null) { device = new Foresight.DataAccess.Device(); device.AddTime = DateTime.Now; device.AddMan = WebUtil.GetUser(context).RealName; } device.DeviceNo = getValue(context, "tdDeviceNo"); device.DeviceTypeID = getIntValue(context, "tdDeviceType"); device.DeviceGroupID = getIntValue(context, "tdDeviceGroup"); device.ProjectID = getIntValue(context, "tdProjectName"); device.DeviceName = getValue(context, "tdDeviceName"); device.ModelNo = getValue(context, "tdModelNo"); device.DeviceStatus = getIntValue(context, "tdDeviceStatus"); device.DeviceLevel = getValue(context, "tdDeviceLevel"); device.RepairType = getValue(context, "tdRepairType"); device.Supplier = getValue(context, "tdSupplier"); device.SupplierMan = getValue(context, "tdSupplierMan"); device.SupplierPhone = getValue(context, "tdSupplierPhone"); device.RepairCompany = getValue(context, "tdRepairCompany"); device.RepairUserID = getIntValue(context, "tdRepairUser"); device.RepairUserPhone = getValue(context, "tdRepairUserPhone"); device.FirstRepairDate = getTimeValue(context, "tdFirstRepairDate"); device.RepairCount = getIntValue(context, "tdRepairCount"); device.RepairCycle = getValue(context, "tdRepairCycle"); device.CheckUserID = getIntValue(context, "tdCheckUser"); device.FirstCheckDate = getTimeValue(context, "tdFirstCheckDate"); device.CheckCount = getIntValue(context, "tdCheckCount"); device.CheckCycle = getValue(context, "tdCheckCycle"); device.Remark = getValue(context, "tdRemark"); device.ThisRepairDate = getTimeValue(context, "tdThisRepairDate"); device.ThisCheckDate = getTimeValue(context, "tdThisCheckDate"); device.TaskTypeID = getIntValue(context, "tdTaskType"); device.PurchaseDate = getTimeValue(context, "tdPurchaseDate"); device.GuaranteeDate = getValue(context, "tdGuaranteeDate"); device.GuaranteeEndDate = getTimeValue(context, "tdGuaranteeEndDate"); device.LocationPlace = getValue(context, "tdLocationPlace"); HttpFileCollection uploadFiles = context.Request.Files; List <Foresight.DataAccess.Device_Image> filelist = new List <Foresight.DataAccess.Device_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.Device_Image attach = new Foresight.DataAccess.Device_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.DeviceID = device.ID; item.Save(helper); } helper.Commit(); } catch (Exception ex) { Utility.LogHelper.WriteError("DeviceHandler", "命令: savedevice", ex); helper.Rollback(); WebUtil.WriteJson(context, new { status = false }); return; } } WebUtil.WriteJson(context, new { status = true, ID = device.ID }); }
public static DateTime GetNextCheckTime(DeviceSetting setting, DateTime StartTime, Foresight.DataAccess.Device device, out DateTime EndTime) { DateTime ResultTime = DateTime.MinValue; EndTime = DateTime.MinValue; if (device.CheckCycle.Equals(Utility.EnumModel.DeviceCycleType.day.ToString())) { EndTime = StartTime.AddDays(device.CheckCount); } else if (device.CheckCycle.Equals(Utility.EnumModel.DeviceCycleType.month.ToString())) { EndTime = StartTime.AddMonths(device.CheckCount); } if (setting == null || string.IsNullOrEmpty(setting.Parameters1) || string.IsNullOrEmpty(setting.Parameters2)) { ResultTime = EndTime; } else if (setting.Parameters2.Equals(Utility.EnumModel.DeviceCycleType.day.ToString())) { int beforecount = 0; int.TryParse(setting.Parameters1, out beforecount); ResultTime = EndTime.AddDays(-beforecount); } else if (setting.Parameters2.Equals(Utility.EnumModel.DeviceCycleType.month.ToString())) { int beforecount = 0; int.TryParse(setting.Parameters1, out beforecount); ResultTime = EndTime.AddMonths(-beforecount); } return(ResultTime); }