public static int InsertOrUpdateT_WQX_REF_CHAR_ORG(global::System.String cHAR_NAME, global::System.String oRG_NAME, global::System.String cREATE_USER_ID, string dEFAULT_DETECT_LIMIT, string dEFAULT_UNIT, int? dEFAULT_ANAL_METHOD_IDX, string dEFAULT_SAMP_FRACTION, string dEFAULT_RESULT_STATUS, string dEFAULT_RESULT_VALUE_TYPE) { using (OpenEnvironmentEntities ctx = new OpenEnvironmentEntities()) { try { Boolean insInd = true; T_WQX_REF_CHAR_ORG a = new T_WQX_REF_CHAR_ORG(); if (ctx.T_WQX_REF_CHAR_ORG.Any(o => o.CHAR_NAME == cHAR_NAME && o.ORG_ID == oRG_NAME)) { //update case a = (from c in ctx.T_WQX_REF_CHAR_ORG where c.CHAR_NAME == cHAR_NAME && c.ORG_ID == oRG_NAME select c).FirstOrDefault(); insInd = false; } a.CHAR_NAME = cHAR_NAME; a.ORG_ID = oRG_NAME; if (dEFAULT_DETECT_LIMIT != null) a.DEFAULT_DETECT_LIMIT = dEFAULT_DETECT_LIMIT; if (dEFAULT_UNIT != null) a.DEFAULT_UNIT = dEFAULT_UNIT; if (dEFAULT_ANAL_METHOD_IDX != null) a.DEFAULT_ANAL_METHOD_IDX = dEFAULT_ANAL_METHOD_IDX; if (dEFAULT_SAMP_FRACTION != null) a.DEFAULT_SAMP_FRACTION = dEFAULT_SAMP_FRACTION; if (dEFAULT_RESULT_STATUS != null) a.DEFAULT_RESULT_STATUS = dEFAULT_RESULT_STATUS; if (dEFAULT_RESULT_VALUE_TYPE != null) a.DEFAULT_RESULT_VALUE_TYPE = dEFAULT_RESULT_VALUE_TYPE; if (insInd) //insert case { a.CREATE_DT = System.DateTime.Now; a.CREATE_USERID = cREATE_USER_ID; ctx.AddToT_WQX_REF_CHAR_ORG(a); } ctx.SaveChanges(); return 1; } catch (Exception ex) { return 0; } } }