public BizLogicMsg Save_Ext(JsonMCE_Depr jsonEntity) { if (LocalMode) { BizLogicMsg msg = new BizLogicMsg(); using (IDbConnection connection = IDALProvider.IDAL.PopConnection()) { using (IDbTransaction transaction = connection.BeginTransaction()) { try { EntityObject_MCE_B_ASSETS_DEPR entity = new EntityObject_MCE_B_ASSETS_DEPR(); if (!string.IsNullOrEmpty(jsonEntity.ID)) { entity.ID = jsonEntity.ID; entity = HelperObject_MCE_B_ASSETS_DEPR.Get(entity); if (entity == null) { throw new Exception("获取数据出错."); } } entity.CODE = jsonEntity.CODE; entity.DEPT_ID = jsonEntity.DEPT_ID; entity.USER_ID = jsonEntity.USER_ID; if (!string.IsNullOrEmpty(jsonEntity.CREATE_DATE)) { entity.CREATE_DATE = DateTime.Parse(jsonEntity.CREATE_DATE); } entity.FINANCE_CYCLE = jsonEntity.FINANCE_CYCLE; entity.COMMENTS = jsonEntity.COMMENTS; entity.STATE = 1; if (string.IsNullOrEmpty(jsonEntity.ID)) { entity.CREATE_TIME = DateTime.Now; entity.CREATE_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID; int amount = HelperObject_MCE_B_ASSETS_DEPR.Save(entity, transaction); } else { entity.MODIFY_TIME = DateTime.Now; entity.MODIFY_USER_ID = Ipedf.Web.BizLogic.SystemLogic.Proxy.CurrentUser.ID; int amount = HelperObject_MCE_B_ASSETS_DEPR.Update(entity, transaction); } if (!string.IsNullOrEmpty(jsonEntity.ID)) { CauseObject_MCE_B_ASSETS_DEPR_D pDeprDetail = new CauseObject_MCE_B_ASSETS_DEPR_D(); pDeprDetail.BASE_ID = jsonEntity.ID; HelperObject_MCE_B_ASSETS_DEPR_D.Delete(pDeprDetail, transaction); } if (jsonEntity.children != null && jsonEntity.children.Count > 0) { foreach (JsonMceDepr_D item in jsonEntity.children) { EntityObject_MCE_B_ASSETS_DEPR_D entity_D = new EntityObject_MCE_B_ASSETS_DEPR_D(); if (!string.IsNullOrEmpty(item.ID)) { entity_D.ID = item.ID; entity_D = HelperObject_MCE_B_ASSETS_DEPR_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.ASSETS_CODE = item.ASSETS_CODE; entity_D.CURRENCY_ID = item.CURRENCY_ID; entity_D.ORIGINAL_VALUE = item.ORIGINAL_VALUE; entity_D.NET_VALUE = item.NET_VALUE; entity_D.MONEY = item.MONEY; entity_D.NEW_NET_VALUE = item.NEW_NET_VALUE; HelperObject_MCE_B_ASSETS_DEPR_D.Save(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_DEPR> smgr = new ServiceManager <ServiceContract_MCE_B_ASSETS_DEPR>(ServiceUri)) { return(smgr.Service.Save_Ext(jsonEntity)); } } }
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; // string strID = request["id"].ToString(); 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_Depr entity = JsonConvert.DeserializeObject <JsonMCE_Depr>(rsb.ToString()); if (string.IsNullOrEmpty(entity.CODE)) { throw new Exception("参数错误,单号不能为空."); } if (string.IsNullOrEmpty(entity.DEPT_ID)) { throw new Exception("参数错误,计提科室不能为空."); } if (string.IsNullOrEmpty(entity.FINANCE_CYCLE)) { throw new Exception("参数错误,财务月份不能为空."); } if (entity.children != null && entity.children.Count > 0) { foreach (JsonMceDepr_D item in entity.children) { if (string.IsNullOrEmpty(item.ASSETS_ID)) { throw new Exception("参数错误,设备不能为空."); } } } else { // throw new Exception("没有明细数据"); } CauseObject_MCE_B_ASSETS_DEPR p = new CauseObject_MCE_B_ASSETS_DEPR(); p.DEPT_ID = entity.DEPT_ID; p.FINANCE_CYCLE = entity.FINANCE_CYCLE; string strCondition = ""; if (!string.IsNullOrEmpty(entity.ID)) { strCondition = strCondition + " and MCE_B_ASSETS_DEPR.ID<>'" + entity.ID + "'"; p.SetCustomCondition(strCondition); } DisplayObject_MCE_B_ASSETS_DEPR[] list = BizLogicObject_MCE_B_ASSETS_DEPR.Proxy.Query(p); if (list != null && list.Length > 0) { throw new Exception("计提科室:[" + list[0].DEPT_ID_NAME + "],财务月份[" + list[0].FINANCE_CYCLE + "]已经存在."); } BizLogicMsg msg = BizLogicObject_MCE_B_ASSETS_DEPR.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(); } }