/// <summary> /// 新增对象 /// </summary> /// <param name="entity">实体</param> /// <returns>true=成功;false=失败</returns> public bool Insert(PatrolReportHeader entity) { SQLEntities context = new SQLEntities(); bool success = false; using (TransactionScope trans = new TransactionScope()) { try { context.PatrolReportHeader.AddObject(entity); trans.Complete(); success = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } } try { if (success) { //提交保存 context.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } context.Dispose(); return(success); }
/// <summary> /// 复制对象 /// </summary> /// <param name="source"></param> /// <returns></returns> public PatrolReportHeader Copy(PatrolReportHeader source) { PatrolReportHeader target = new PatrolReportHeader(); target.Contaction1 = source.Contaction1; target.Contaction2 = source.Contaction2; target.ContactorName1 = source.ContactorName1; target.ContactorName2 = source.ContactorName2; target.ContactorType1 = source.ContactorType1; target.ContactorType2 = source.ContactorType2; target.ContactType1 = source.ContactType1; target.ContactType2 = source.ContactType2; target.CreatedAt = source.CreatedAt; target.Creator = source.Creator; target.IsAvailable = source.IsAvailable; target.IsEmergency = source.IsEmergency; target.MakerCD = source.MakerCD; target.MachineNO = source.MachineNO; target.MachineStatus = source.MachineStatus; target.MachineType = source.MachineType; target.PatrolNO = source.PatrolNO; target.Remarks = source.Remarks; target.ReportDate = source.ReportDate; target.Reporter = source.Reporter; target.ReportStatus = source.ReportStatus; target.ReportUri = source.ReportUri; target.UpdatedAt = source.UpdatedAt; target.Updator = source.Updator; target.WorkedTimes = source.WorkedTimes; target.WorkNO = source.WorkNO; target.Province = source.Province; target.City = source.City; target.Address = source.Address; return(target); }
/// <summary> /// 根据用户名称查询唯一用户 /// </summary> /// <param name="searchInfo">带有PatrolNo的查询对象</param> /// <returns>指定UserCD值的个人信息</returns> public static PatrolReportHeader Select(PatrolReportHeader searchInfo) { if (searchInfo == null || searchInfo.PatrolNO == String.Empty) { return(null); } return(controller.Select(searchInfo)); }
/// <summary> /// 删除记录 /// </summary> /// <param name="entity">删除对象 主键必须设置</param> /// <returns></returns> public static bool Delete(PatrolReportHeader entity) { if (entity != null) { return(controller.Delete(entity)); } return(false); }
/// <summary> /// 更新记录 /// </summary> /// <param name="entity">要更新对象</param> /// <param name="updateKeys">更新列表</param> /// <returns>true=成功,false=失败</returns> public static bool Update(PatrolReportHeader entity, Hashtable updateKeys) { if (entity != null && updateKeys != null && updateKeys.Count > 0) { return(controller.Update(entity, updateKeys)); } return(false); }
/// <summary> /// 新增记录 /// </summary> /// <param name="entity">新增对象</param> /// <returns>true=成功,false=失败</returns> public static bool Insert(PatrolReportHeader entity) { if (entity != null) { return(controller.Insert(entity)); } return(false); }
public static PatrolReportHeader GetInstance(string patrolno) { if (patrolno == null || patrolno == String.Empty) { return(null); } PatrolReportHeader header = new PatrolReportHeader(); header.PatrolNO = patrolno; return(controller.Select(header)); }
public static bool InsertPatrol(PatrolReportHeader header, List <PatrolReportDetail> detailList) { SQLEntities context = new SQLEntities(); bool success = false; if (header != null && detailList != null && detailList.Count > 0) { using (TransactionScope trans = new TransactionScope()) { try { context.PatrolReportHeader.AddObject(header); foreach (PatrolReportDetail item in detailList) { context.PatrolReportDetail.AddObject(item); } trans.Complete(); success = true; } catch (Exception ex) { MyLog.Error("{{" + header.Reporter + "}}新建特巡报告错误" + ex.Message); Console.WriteLine(ex.Message); } } } try { if (success) { //提交保存 context.SaveChanges(); MyLog.Log("{{" + header.Reporter + "}}保存特巡报告成功"); Console.WriteLine("保存特巡报告成功"); } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("保存特巡报告异常"); MyLog.Error("{{" + header.Reporter + "}}保存特巡报告错误" + ex.Message); success = false; } context.Dispose(); return(success); }
/// <summary> /// 根据查询条件查询单条记录 /// </summary> /// <param name="searchInfo">查询条件,主键查询</param> /// <returns></returns> public PatrolReportHeader Select(PatrolReportHeader searchInfo) { PatrolReportHeader instance = null; try { SQLEntities context = new SQLEntities(); instance = context.PatrolReportHeader.Where("it.PatrolNO=@PatrolNO", new ObjectParameter("PatrolNO", searchInfo.PatrolNO)).First(); context.Dispose(); } catch (Exception ex) { Console.WriteLine(" 查询特巡异常:" + ex.Message); } return(instance); }
/// <summary> /// 测试特巡报告头部 /// </summary> public static void TestPatrolReportHeader(string report) { PatrolReportHeaderHelper ph = new PatrolReportHeaderHelper(); PatrolReportHeader target = new PatrolReportHeader(); target.PatrolNO = rule.GenerateNO("PRN"); target.Contaction1 = "13876486456"; target.Contaction2 = "15687894851"; target.ContactorName1 = "王猛"; target.ContactorName2 = "天龙"; target.ContactorType1 = "0"; target.ContactorType2 = "1"; target.ContactType1 = "1"; target.ContactType2 = "0"; target.CreatedAt = DateTime.Now; target.Creator = "Admin"; target.IsAvailable = "1"; target.IsEmergency = "0"; target.MakerCD = "01"; target.MachineNO = "001859"; target.MachineStatus = "0"; target.MachineType = "101"; target.Remarks = "备注信息"; target.ReportDate = "20170706"; target.Reporter = report; target.ReportStatus = "0"; target.ReportUri = "http://www.baidu.com"; target.UpdatedAt = DateTime.Now; target.Updator = "admin"; target.WorkedTimes = new Random().Next(100, 500); target.WorkNO = DateTime.Now.Millisecond.ToString(); bool issure = ph.Insert(target); if (issure) { TestPatrolReportDetail(target.PatrolNO); } //查询 //PatrolReportHeader s = ph.Select(target); }
/// <summary> /// 取得特巡报告头部数据 /// </summary> /// <param name="source"></param> /// <returns></returns> private static PatrolReportHeader getHeader(ReqUploadPatrolInformation source) { PatrolReportHeader ret = new PatrolReportHeader(); //前端获取 ret.Province = source.province; ret.City = source.city; ret.Address = source.address; ret.Contaction1 = source.phone_number1; ret.Contaction2 = source.phone_number2; ret.ContactorName1 = source.contactor_name1; ret.ContactorName2 = source.contactor_name2; ret.ContactorType1 = source.contact_type_code1; ret.ContactorType2 = source.contact_type_code2; ret.ContactType1 = source.phone_type_code1; ret.ContactType2 = source.phone_type_code2; DateTime date = DateTime.Now; ret.Creator = source.user_id; ret.IsEmergency = source.is_urgent; ret.MachineNO = source.model_id; ret.MachineStatus = source.model_status_code; ret.MachineType = source.model_code; ret.Remarks = source.remarks; ret.Reporter = source.user_id; ret.ReportUri = ""; ret.WorkedTimes = Convert.ToDouble(source.worked_times); //自动设置 ret.PatrolNO = PatrolReportHeaderRule.GenerateNO(); ret.IsAvailable = "1"; ret.MakerCD = "01"; ret.ReportStatus = "0"; ret.ReportDate = date.ToString("yyyyMMdd"); ret.CreatedAt = date; return(ret); }
/// <summary> /// 根据更新列表更新实体 /// </summary> /// <param name="entity">实体</param> /// <param name="updateKeys">更新字段列表 键值对</param> /// <returns>true=成功,false=失败</returns> public bool Update(PatrolReportHeader entity, Hashtable updateKeys) { SQLEntities context = new SQLEntities(); bool success = false; using (TransactionScope trans = new TransactionScope()) { try { Console.WriteLine(entity.PatrolNO); PatrolReportHeader instance = context.PatrolReportHeader.Where("it.PatrolNO=@PatrolNO", new ObjectParameter("PatrolNO", entity.PatrolNO)).First(); //更新数据操作 SetUpdateValue(instance, updateKeys); trans.Complete(); success = true; } catch (Exception ex) { Console.WriteLine(ex.Message); } } try { if (success) { //提交保存 context.SaveChanges(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } context.Dispose(); return(success); }
/// <summary> /// 取得特巡点检详细信息 /// </summary> /// <param name="source"></param> /// <param name="header"></param> /// <returns></returns> private static List <PatrolReportDetail> getDetailList(ReqUploadPatrolInformation source, PatrolReportHeader header, String dirName) { List <PatrolReportDetail> list = new List <PatrolReportDetail>(); if (source != null && source.check_list != null && source.check_list.Count > 0 && header != null) { for (int i = 0; i < source.check_list.Count; i++) { PicInfo item = source.check_list[i]; PatrolReportDetail instance = new PatrolReportDetail(); //前端获取 instance.IsImportant = item.is_important; instance.LocationCode = item.location_code; instance.SpotCode = item.spot_code; instance.Status = item.spot_status_code; instance.Remarks = item.part_remarks; instance.QuestionLevel = item.level_code; instance.PicUrl = dirName + "/" + item.pic_url; Console.WriteLine(instance.PicUrl); //自动设置 instance.PatrolNO = header.PatrolNO; instance.SubNO = i; instance.IsSelected = "0"; //加入列表 list.Add(instance); } } return(list); }
/// <summary> /// 上传特巡报告 /// </summary> /// <param name="data"></param> /// <returns></returns> public Stream UploadPatrolInformation(Stream data) { #region 查找数据 ResUploadPatrolInformation response = new ResUploadPatrolInformation(); bool success = false; try { DataContractJsonSerializer json = new DataContractJsonSerializer(typeof(ReqUploadPatrolInformation)); //读取器 StreamReader sr = new StreamReader(data); string dataString = String.Empty; while (!sr.EndOfStream) { dataString = sr.ReadToEnd(); Console.WriteLine(dataString); #region 日志输出 CommonInfo.Log(dataString); #endregion //反序列化json为对象注意顺序很重要 ReqUploadPatrolInformation request = new ReqUploadPatrolInformation(); MemoryStream temp = new MemoryStream(Encoding.UTF8.GetBytes(dataString)); request = json.ReadObject(temp) as ReqUploadPatrolInformation; //关闭临时流 temp.Close(); //调用用户更新密码接口 if (request != null) { #region **********(此处加入代码) 根据查询条件 加入业务逻辑代码************* // 身份验证 if (request.user_id != String.Empty && request.token != String.Empty) { PatrolReportHeader header = ReportService.getHeader(request); List <PatrolReportDetail> detailList = ReportService.getDetailList(request, header, request.dir_name); success = PatrolEntity.InsertPatrol(header, detailList); if (success) { //将点检图片存到正式文件夹 if (request.dir_name != null && request.dir_name != String.Empty) { string saveDir = CommonInfo.ImageSaveUrl + "/" + request.dir_name; string tempDir = CommonInfo.ImageTempUrl + "/" + request.dir_name; if (Directory.Exists(tempDir)) { if (success) { //将临时文件夹拷贝到正式文件夹 Directory.Move(tempDir, saveDir); success = true; //事务成功完成 response.patrol_id = request.patrol_id; } } } } } #endregion } } sr.Close(); Console.WriteLine(data); } catch (Exception ex) { Console.WriteLine(ex.Message); #region 日志输出 CommonInfo.Error("上传特巡报告错误" + ex.Message); #endregion } //返回消息体 if (success) { response.SetSuccess(); } else { ////默认是失败 //response.SetFailed(); } //将消息序列化为Json格式数据 DataContractJsonSerializer obj2Json = new DataContractJsonSerializer(typeof(ResUploadPatrolInformation)); MemoryStream ms = new MemoryStream(); obj2Json.WriteObject(ms, response); //注意一定要设置流的位置到开始位置,否则没有消息输出 ms.Position = 0; return(ms); #endregion }
/// <summary> /// 记录需要更新的字段 /// </summary> /// <param name="update"></param> private static void SetUpdateValue(PatrolReportHeader current, Hashtable updateKeys) { foreach (DictionaryEntry item in updateKeys) { switch (item.Key.ToString().ToLower()) { case "patrolno": current.PatrolNO = item.Value.ToString(); break; case "reportdate": current.ReportDate = item.Value.ToString(); break; case "reporter": current.Reporter = item.Value.ToString(); break; case "reportstatus": current.ReportStatus = item.Value.ToString(); break; case "makercd": current.MakerCD = item.Value.ToString(); break; case "machinetype": current.MachineType = item.Value.ToString(); break; case "machineno": current.MachineNO = item.Value.ToString(); break; case "workedtimes": current.WorkedTimes = Convert.ToDouble(item.Value); break; case "machinestatus": current.MachineStatus = item.Value.ToString(); break; case "isemergency": current.IsEmergency = item.Value.ToString(); break; case "remarks": current.Remarks = item.Value.ToString(); break; case "contactortype1": current.ContactorType1 = item.Value.ToString(); break; case "contactorname1": current.ContactorName1 = item.Value.ToString(); break; case "contacttype1": current.ContactType1 = item.Value.ToString(); break; case "contaction1": current.Contaction1 = item.Value.ToString(); break; case "contactortype2": current.ContactorType2 = item.Value.ToString(); break; case "contactorname2": current.ContactorName2 = item.Value.ToString(); break; case "contacttype2": current.ContactType2 = item.Value.ToString(); break; case "contaction2": current.Contaction2 = item.Value.ToString(); break; case "workno": current.WorkNO = item.Value.ToString(); break; case "reporturi": current.ReportUri = item.Value.ToString(); break; case "province": current.Province = item.Value.ToString(); break; case "city": current.City = item.Value.ToString(); break; case "address": current.Address = item.Value.ToString(); break; case "isavailable": current.IsAvailable = item.Value.ToString(); break; case "creator": current.Creator = item.Value.ToString(); break; case "createdat": current.CreatedAt = Convert.ToDateTime(item.Value); break; case "updator": current.Updator = item.Value.ToString(); break; case "updatedat": current.UpdatedAt = Convert.ToDateTime(item.Value); break; default: break; } } }