public HttpResponseBase DeleteCertificateCategory() { string json = string.Empty; CertificateCategoryQuery query = new CertificateCategoryQuery(); string id = string.Empty; string fid = string.Empty; string frowIDs = string.Empty; _inspectionReport = new InspectionReportMgr(mySqlConnectionString); try { if (!string.IsNullOrEmpty(Request.Params["ids"])) { string rowIDs = (Request.Params["ids"]); if (_inspectionReport.BeforeDelete(rowIDs))//判斷數據是否已被使用,如果使用則不能刪除 { #region 刪除 if (!string.IsNullOrEmpty(Request.Params["rid"])) { //子類 id = Request.Params["rid"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["frid"])) { //父類 fid = Request.Params["frid"].ToString(); } query.rowIDs = id.Substring(0, id.Length - 1); string[] fids = fid.Split(','); for (int i = 0; i < fids.Length - 1; i++) { if (!frowIDs.Contains(fids[i])) { frowIDs = frowIDs + fids[i] + ","; } } #region 刪除子類 if (_inspectionReport.DeleteCertificateCategory(query) <= 0) { json = "{success:true,msg:0}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } #endregion #region 判斷父類對應的子類是否存在 string[] fidss = frowIDs.Split(','); for (int j = 0; j < fidss.Length - 1; j++) { query.frowID = Convert.ToInt32(fidss[j]); if (_inspectionReport.CheckOnly(query) <= 0) { query.frowIDs = query.frowIDs + fidss[j] + ","; } } if (!string.IsNullOrEmpty(query.frowIDs)) { query.frowIDs = query.frowIDs.Substring(0, query.frowIDs.Length - 1); } #endregion #region 刪除不存在子類的父類 if (!string.IsNullOrEmpty(query.frowIDs) && query.frowIDs.Length > 0) { if (_inspectionReport.DeleteCCByTransaction(query)) { json = "{success:true,msg:1}"; } else { json = "{success:true,msg:0}"; } } #endregion else { json = "{success:true,msg:1}"; } #endregion } else { json = "{success:true,msg:-1}"; } } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); json = "{success:false}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }