public BizLogicMsg Save_Ext(JsonMCE_MT_PLAN json) { if (LocalMode) { BizLogicMsg msg = new BizLogicMsg(); using (IDbConnection connection = IDALProvider.IDAL.PopConnection()) { using (IDbTransaction transaction = connection.BeginTransaction()) { try { EntityObject_MCE_B_ASSETS_MT_PLAN entity = new EntityObject_MCE_B_ASSETS_MT_PLAN(); if (!string.IsNullOrEmpty(json.ID)) { entity.ID = json.ID; entity = HelperObject_MCE_B_ASSETS_MT_PLAN.Get(entity); if (entity == null) { throw new Exception("获取数据出错."); } } entity.CODE = json.CODE; entity.NAME = json.NAME; entity.MTN_TYPE_ID = json.MTN_TYPE_ID; entity.MTN_COMPANY_ID = json.MTN_COMPANY_ID; if (!string.IsNullOrEmpty(json.EXECUTE_PERIOD)) { entity.EXECUTE_PERIOD = int.Parse(json.EXECUTE_PERIOD); } entity.MTN_TYPE_ID = json.MTN_TYPE_ID; if (!string.IsNullOrEmpty(json.CREATE_DATE)) { entity.CREATE_DATE = DateTime.Parse(json.CREATE_DATE); } if (!string.IsNullOrEmpty(json.CREATE_DATE)) { entity.EXECUTE_PERIOD_UNIT = int.Parse(json.EXECUTE_PERIOD_UNIT); } entity.APPLY_USER_ID = json.APPLY_USER_ID; entity.COMMENTS = json.COMMENTS; entity.PLAN_STATE = json.PLAN_STATE; entity.STATE = json.STATE; if (string.IsNullOrEmpty(json.ID)) { entity.CREATE_TIME = DateTime.Now; entity.CREATE_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID; int amount = HelperObject_MCE_B_ASSETS_MT_PLAN.Save(entity, transaction); } else { int amount = HelperObject_MCE_B_ASSETS_MT_PLAN.Update(entity, transaction); } if (json.DELETEIDS != null && json.DELETEIDS.Count > 0) { foreach (string strID in json.DELETEIDS) { EntityObject_MCE_B_ASSETS_MT_PLAN_D entity_D = new EntityObject_MCE_B_ASSETS_MT_PLAN_D(); if (!string.IsNullOrEmpty(strID)) { entity_D.ID = strID; entity_D = HelperObject_MCE_B_ASSETS_MT_PLAN_D.Get(entity_D); if (entity_D == null) { throw new Exception("获取数据出错."); } else { HelperObject_MCE_B_ASSETS_MT_PLAN_D.Delete(entity_D, transaction); } } } } if (json.children != null && json.children.Count > 0) { foreach (JsonMCE_MT_PLAN_D item in json.children) { EntityObject_MCE_B_ASSETS_MT_PLAN_D entity_D = new EntityObject_MCE_B_ASSETS_MT_PLAN_D(); if (!string.IsNullOrEmpty(item.ID)) { entity_D.ID = item.ID; entity_D = HelperObject_MCE_B_ASSETS_MT_PLAN_D.Get(entity_D); if (entity_D == null) { throw new Exception("获取数据出错."); } } entity_D.BASE_ID = entity.ID; entity_D.ASSETS_ID = item.ASSETS_ID; entity_D.ASSET_CODE = item.ASSET_CODE; entity_D.SPEC = item.SPEC; entity_D.DEPT_ID = item.DEPT_ID; entity_D.ITEM_ID = item.ITEM_ID; entity_D.SEQ_NUMBER = item.SEQ_NUMBER; entity_D.COMMENTS = item.COMMENTS; if (string.IsNullOrEmpty(item.ID)) { HelperObject_MCE_B_ASSETS_MT_PLAN_D.Save(entity_D, transaction); } else { HelperObject_MCE_B_ASSETS_MT_PLAN_D.Update(entity_D, transaction); } } } msg.Message = entity.ID; transaction.Commit(); } catch (Exception expt) { transaction.Rollback(); msg = new BizLogicMsg(false, expt.Message); Error(expt); } finally { IDALProvider.IDAL.PushConnection(connection); } } } return(msg); } else { using (ServiceManager <ServiceContract_MCE_B_ASSETS_MT_PLAN> smgr = new ServiceManager <ServiceContract_MCE_B_ASSETS_MT_PLAN>(ServiceUri)) { return(smgr.Service.Save_Ext(json)); } } }
public void ProcessRequest(HttpContext context) { //允许跨域 context.Response.AddHeader("Access-Control-Allow-Origin", "*"); JSON_MSG jsonMsg = new JSON_MSG(); try { context.Response.ContentType = "text/plain"; HttpRequest request = context.Request; StringBuilder rsb = new StringBuilder(); int bytelengg = (int)request.InputStream.Length; using (var reader = new StreamReader(request.InputStream, Encoding.UTF8)) { var read = new Char[bytelengg]; var count = reader.Read(read, 0, bytelengg); while (count > 0) { var str = new string(read, 0, count); rsb.Append(str); count = reader.Read(read, 0, bytelengg); } reader.Close(); reader.Dispose(); request.InputStream.Close(); request.InputStream.Dispose(); } if (string.IsNullOrEmpty(rsb.ToString())) { throw new Exception("参数错误."); } JsonMCE_MT_PLAN entity = JsonConvert.DeserializeObject <JsonMCE_MT_PLAN>(rsb.ToString()); if (string.IsNullOrEmpty(entity.CODE)) { throw new Exception("参数错误,计划编号不能为空."); } if (string.IsNullOrEmpty(entity.NAME)) { throw new Exception("参数错误,计划名称不能为空."); } if (string.IsNullOrEmpty(entity.MTN_TYPE_ID)) { throw new Exception("参数错误,保养类别不能为空."); } if (string.IsNullOrEmpty(entity.APPLY_USER_ID)) { throw new Exception("参数错误,负责人不能为空."); } if (string.IsNullOrEmpty(entity.EXECUTE_PERIOD_UNIT)) { throw new Exception("参数错误,周期类别不能为空."); } if (string.IsNullOrEmpty(entity.EXECUTE_PERIOD)) { throw new Exception("参数错误,执行周期不能为空."); } string pattern = @"^[0-9]*[1-9][0-9]*$"; if (!Regex.IsMatch(entity.EXECUTE_PERIOD, pattern)) { throw new Exception("参数错误,执行周期必须为正整数."); } if (string.IsNullOrEmpty(entity.CREATE_DATE)) { throw new Exception("参数错误,下次执行日期不能为空."); } if (entity.children != null && entity.children.Count > 0) { foreach (JsonMCE_MT_PLAN_D item in entity.children) { if (string.IsNullOrEmpty(item.ASSETS_ID)) { throw new Exception("参数错误,设备名称不能为空."); } if (string.IsNullOrEmpty(item.ITEM_ID)) { throw new Exception("参数错误,项目名称不能为空."); } } } else { throw new Exception("没有明细数据"); } BizLogicMsg msg = BizLogicObject_MCE_B_ASSETS_MT_PLAN.Proxy.Save_Ext(entity); if (!msg.Succeed) { throw new Exception(msg.Message); } jsonMsg.Succeed = 1; jsonMsg.Message = msg.Message; //jsonMsg.Message = "提交成功."; } catch (Exception ex) { jsonMsg.Succeed = 0; jsonMsg.Message = ex.Message; } finally { context.Response.Write(JsonConvert.SerializeObject(jsonMsg)); context.Response.End(); } }