using DeviceRepairAndOptimization.Models; using DeviceRepairAndOptimization.Utils; using Newtonsoft.Json; using System; using System.Collections.Generic; namespace DeviceRepairAndOptimization.Data { public class DriveInformationMaintenance { private static DriveInformationMaintenance manager; public static DriveInformationMaintenance Instance() { if (manager == null) manager = new DriveInformationMaintenance(); return manager; } /// /// 获取全部数据 /// /// public List GetAll() { List lst = null; try { switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": #region api APIResponseData result = ApiHelper.Instance.SendMessage(new CsharpHttpHelper.HttpItem { URL = ServiceRoute.GetAllDeviceData, Method = "Post", ContentType = "application/json; charset=utf-8" }); if (result.Code == 1) { lst = JsonConvert.DeserializeObject>(result.Data + ""); } else { throw new Exception(result.Message); } #endregion break; case "sql": #region sql lst = Drives.DrivesAccess.Instance().GetAll(); #endregion break; default: break; } } catch (Exception ex) { throw ex; } return lst; } /// /// 查询数据 /// /// /// public DriveInfomationModel GetDataByAutoID(int AutoID) { DriveInfomationModel t = null; try { switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": #region api APIResponseData result = ApiHelper.Instance.SendMessage(new CsharpHttpHelper.HttpItem { URL = "api/drive/GetDataByAutoID", Method = "Post", ContentType = "application/json; charset=utf-8", Postdata = $"{{\"filtervalue\":{AutoID}}}" }); if (result.Code == 1) { t = JsonConvert.DeserializeObject(result.Data + ""); } else { throw new Exception(result.Message); } #endregion break; case "sql": #region sql t = Drives.DrivesAccess.Instance().GetDataByAutoID(AutoID); #endregion break; default: break; } } catch (Exception ex) { throw ex; } return t; } /// /// 设定设备的点检表 /// /// 点检表编号 /// 设备编号数组 /// public bool SetFormVersion(int MaintenanceFormVersionId, int[] DriveIds) { bool isSuccess = false; try { switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": string postData = JsonConvert.SerializeObject(new { maintenanceformversionid = MaintenanceFormVersionId, driveids = DriveIds }); APIResponseData result = ApiHelper.Instance.PostWebRequest(ServiceRoute.BindFormVersion, postData, GlobalInfo.token); if (result.Code == 1) { bool.TryParse(result.Data + "", out isSuccess); } else { throw new Exception(result.Message); } break; case "sql": isSuccess = Drives.DrivesAccess.Instance().SetFormVersion(MaintenanceFormVersionId, DriveIds); break; default: break; } } catch (Exception ex) { throw ex; } return isSuccess; } /// /// 通过主键编号查询设备信息 /// /// /// public DriveInfomationModel GetModelByEquipmentID(int KeyId) { DriveInfomationModel entity = null; try { switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": #region api APIResponseData result = ApiHelper.Instance.SendMessage(new CsharpHttpHelper.HttpItem { URL = ServiceRoute.GetCurrentMonthPlans, Method = "post", ContentType = "application/json; charset=utf-8", Postdata = JsonConvert.SerializeObject(new { equipmentid = KeyId }) }); if (result.Code == 1) { entity = JsonConvert.DeserializeObject(result.Data + ""); } else { throw new Exception(result.Message); } #endregion break; case "sql": #region sql entity = Drives.DrivesAccess.Instance().GetModelByEquipmentID(KeyId); break; #endregion default: break; } } catch (Exception ex) { throw ex; } return entity; } /// /// 修改设备信息 /// /// /// public bool UpdateDriveInformation(Dictionary data) { byte[] byteArray = data.toByteArray(); bool isSuccess = false; try { switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": #region api APIResponseData result = ApiHelper.Instance.SendMessage(new CsharpHttpHelper.HttpItem { URL = ServiceRoute.UpdateDeviceInfo, Method = "post", ContentType = "application/json", Postdata = JsonConvert.SerializeObject(byteArray) }); if (result.Code == 1) { isSuccess = true; } else { throw new Exception(result.Message); } #endregion break; case "sql": #region sql isSuccess = Drives.DrivesAccess.Instance().UpdateDriveInformation(data); break; #endregion default: break; } } catch (Exception ex) { throw ex; } return isSuccess; } /// /// 通过设备编号查询设备信息 /// /// /// public DriveInfomationModel GetModelByEquipmentID(string EquipmentID) { DriveInfomationModel entity = null; try { switch (Models.Config.Configurations.Properties.ConnType?.ToLower()) { case "api": APIResponseData result = ApiHelper.Instance.SendMessage(new CsharpHttpHelper.HttpItem { URL = ServiceRoute.GetDeviceByEquipmentID, Method = "post", ContentType = "application/json; charset=utf-8", Postdata = JsonConvert.SerializeObject(new { equipmentid = EquipmentID }) }); if (result.Code == 1) { entity = JsonConvert.DeserializeObject(result.Data + ""); } else { return null; } break; case "sql": entity = Drives.DrivesAccess.Instance().GetModelByEquipmentID(EquipmentID); break; default: break; } } catch (Exception ex) { throw ex; } return entity; } } }