private JArray getJsonForGrid(Models.question.G00010 actRow) { JArray ja = new JArray(); var itemObject = new JObject(); itemObject.Add("sysObjectId", actRow.sysObjectId.ToString()); if (actRow.RowStatus.ToString() == "M") { itemObject.Add("actUser", actRow.actUser.ToString()); itemObject.Add("actTime", actRow.actTime.ToString()); } else // "A" { itemObject.Add("creatUser", actRow.creatUser.ToString()); itemObject.Add("creatTime", actRow.creatTime.ToString()); } ja.Add(itemObject); return(ja); }
public ActionResult ActSingle(Models.question.G00010 actRow)//接收單筆資料方式 { ZhWebClassV3.UserData userData = ZhWebClassV3.UserHelper.GetUserData(); JObject jo; try { actRow.sysObjectId = ZhConfig.ZhIniObj.ACall_checkIsDBNull(actRow.sysObjectId); actRow.memo = ZhConfig.ZhIniObj.ACall_checkIsDBNull(actRow.memo); #region 判斷啟用中 值,不可重複 //RE0020 //errStr += ZhWebClassV1.CheckObj.Chk_ColumnValue(actRow.RowStatus.ToString(), "userGroup", "userGroupName", "使用者群組名稱", actRow.userGroupName.ToString(), "and sysUserGroupId !='" + actRow.sysUserGroupId.ToString() + "' and corpUser is null "); strSql.Clear(); if (actRow.RowStatus.ToString() == "A") { strSql.Append("select * from Q10_Objects where objectName='" + actRow.objectName.ToString() + "' and statusx='10' and creatUser='******' "); } else { strSql.Append("select * from Q10_Objects where objectName='" + actRow.objectName.ToString() + "' and statusx='10' and sysObjectId <> '" + actRow.sysObjectId.ToString() + "' and creatUser='******' "); } DataTable tbl_QueryData2 = ZhClass.SqlTool.GetDataTable(ZhConfig.GlobalSystemVar.StrConnection1, strSql.ToString(), "tbl_QueryData2"); if (tbl_QueryData2.Rows.Count > 0) { errStr = "啟用中之使用者群組名稱:【" + actRow.objectName.ToString() + "】,<br>不可重複 "; } else { errStr = ""; } if (errStr != "") { jo = new JObject(); jo.Add("status", "error"); jo.Add("error", errStr); return(Content(JsonConvert.SerializeObject(jo), "application/json")); } #endregion #region 設置 要傳入的 SqlParameter 資料 SqlParameter[] param = { new SqlParameter("sysObjectId", SqlDbType.Int, 4, ParameterDirection.InputOutput, false, 0, 0, "", DataRowVersion.Proposed, actRow.sysObjectId), new SqlParameter("objectId", SqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, actRow.objectId), new SqlParameter("objectName", SqlDbType.NVarChar, -1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, actRow.objectName), new SqlParameter("statusx", SqlDbType.VarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, actRow.statusx), new SqlParameter("memo", SqlDbType.NVarChar, -1, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, actRow.memo), new SqlParameter("creatUser", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, userData.sysUserId), new SqlParameter("actUser", SqlDbType.Int, 4, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Proposed, userData.sysUserId) }; #endregion strSql.Remove(0, strSql.Length); switch (actRow.RowStatus.ToString()) { case "A": strSql.Clear(); strSql.Append("insert into Q10_Objects (objectId,objectName,statusx,memo,creatUser,creatTime) values (@objectId,@objectName,@statusx,@memo,@creatUser,getdate())"); strSql.Append(" SELECT @sysObjectId = SCOPE_IDENTITY() "); actRow.creatUser = userData.userName; actRow.creatTime = DateTime.Now; errStr = SqlTool.ExecuteNonQuery(strSql.ToString(), param); if (errStr != "") { throw new Exception(errStr); } actRow.sysObjectId = param[0].Value; break; case "M": //,creatUser=@creatUser,creatTime=@creatTime strSql.Append("update Q10_Objects set objectId=@objectId,objectName=@objectName,statusx=@statusx,memo=@memo,actUser=@actUser,actTime=getdate() where sysObjectId=@sysObjectId"); actRow.actUser = userData.userName; actRow.actTime = DateTime.Now; errStr = SqlTool.ExecuteNonQuery(strSql.ToString(), param); if (errStr != "") { throw new Exception(errStr); } strSql.Remove(0, strSql.Length); strSql.Append("update Q10_userVsObject set statusx='" + actRow.statusx.ToString() + "' where sysObjectId='" + actRow.sysObjectId.ToString() + "' "); errStr = SqlTool.ExecuteNonQuery(strSql.ToString(), param); if (errStr != "") { throw new Exception(errStr); } break; } #region OperLog 異動群組資料 if (Convert.ToBoolean(ZhConfig.GlobalSystemVar.tbl_OperLogFlag.Rows.Find(funcId)["isOperLogEnable"]) && errStr == "") { #region Gen tbl_operLog1 Data (Add/Modify) DataTable tbl_operLog1 = userData.Get_tbl_operLogPart1(); tbl_operLog1.Columns.Add("sysObjectId", typeof(string)); DataRow operLogRow = tbl_operLog1.NewRow(); //operLogRow["rowId"] =0; operLogRow["actSerial"] = userData.actSerial; operLogRow["sysUserId"] = userData.sysUserId; operLogRow["actStatus"] = actRow.RowStatus.ToString(); operLogRow["sysObjectId"] = actRow.sysObjectId.ToString(); tbl_operLog1.Rows.Add(operLogRow); #endregion errStr = ZhWebClassSet.Log.LogSet.SaveOperLog(funcId, "Q10_Objects", tbl_operLog1); if (errStr != "") { throw new Exception(errStr); } } #endregion if (errStr == "") { //return Json("OK", JsonRequestBehavior.DenyGet); jo = new JObject(); jo.Add("status", "OK"); jo.Add("row", getJsonForGrid(actRow)); return(Content(JsonConvert.SerializeObject(jo), "application/json")); } else { //return Json(errStr, JsonRequestBehavior.DenyGet); jo = new JObject(); jo.Add("status", "error"); jo.Add("error", errStr); return(Content(JsonConvert.SerializeObject(jo), "application/json")); } } catch (Exception ex) { //return Json(ex.Message, JsonRequestBehavior.DenyGet); jo = new JObject(); jo.Add("status", "error"); jo.Add("error", ex.Message); return(Content(JsonConvert.SerializeObject(jo), "application/json")); } }