public HttpResponseBase GetCertificateCategory()
        {
            string json = string.Empty;
            int totalCount = 0;
            List<CertificateCategoryQuery> stores = new List<CertificateCategoryQuery>();
            CertificateCategoryQuery query = new CertificateCategoryQuery();
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["searchcontent"]))
                {
                    query.searchcon = Request.Params["searchcontent"].ToString().Trim();
                }
                _inspectionReport = new InspectionReportMgr(mySqlConnectionString);
                stores = _inspectionReport.GetCertificateCategoryList(query, out totalCount);
                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(stores, Newtonsoft.Json.Formatting.Indented, timeConverter) + "}";//返回json數據

            }
            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;
        }
Esempio n. 2
0
 public List<CertificateCategoryQuery> GetCertificateCategoryList(CertificateCategoryQuery query, out int totalCount)
 {
     try
     {
         return _inspectionReport.GetCertificateCategoryList(query, out totalCount);
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->GetCertificateCategoryList-->" + ex.Message, ex);
     }
 }
Esempio n. 3
0
 public int UpdateActive(CertificateCategoryQuery query)
 {
     try
     {
         return _inspectionReport.UpdateActive(query);
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->UpdateActive-->" + ex.Message, ex);
     }
 }
Esempio n. 4
0
 public int DeleteCertificateCategory(CertificateCategoryQuery query)
 {
     try
     {
         return _inspectionReport.DeleteCertificateCategory(query);
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->DeleteCertificateCategory-->" + ex.Message, ex);
     }
 }
Esempio n. 5
0
 public int UpdateActive(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("UPDATE certificate_category SET `status`='{0}' WHERE rowID='{1}'", query.status, query.rowID);
         return _access.execCommand(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->UpdateActive-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 6
0
 public int CheckOnly(CertificateCategoryQuery query)
 {
     List<CertificateCategoryQuery> list = new List<CertificateCategoryQuery>();
     try
     {
         list = _inspectionReport.CheckOnly(query);
         return list.Count;
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->CheckOnly-->" + ex.Message , ex);
     }
 }
Esempio n. 7
0
 public List<CertificateCategoryQuery> CheckOnly(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat(" SELECT rowID FROM certificate_category WHERE certificate_categoryfid='{0}'", query.frowID);
         return _access.getDataTableForObj<CertificateCategoryQuery>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->CheckOnly-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 8
0
 public bool DeleteCCByTransaction(CertificateCategoryQuery query)
 {
     try
     {
         if (_inspectionReport.DeleteCCByTransaction(query) > 0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->DeleteCCByTransaction-->" + ex.Message, ex);
     }
 }
Esempio n. 9
0
 public List<CertificateCategoryQuery> GetCertificateCategoryList(CertificateCategoryQuery query, out int totalCount)
 {
     StringBuilder sb = new StringBuilder();
     StringBuilder sbwhere = new StringBuilder();
     StringBuilder sbcount = new StringBuilder();
     totalCount = 0;
     try
     {
         sb.AppendFormat(@" SELECT cc.rowID,cc.certificate_categoryname AS certificate_category_childname,cc.certificate_categorycode AS certificate_category_childcode,cc.certificate_categoryfid as frowID ,cc2.certificate_categoryname,cc2.certificate_categorycode,u.user_username as k_user_tostring,cc.k_date,cc.`status` ");
         sbwhere.Append(" FROM certificate_category cc ");
         sbwhere.AppendFormat(" LEFT JOIN (SELECT cc1.rowID,cc1.certificate_categoryname,cc1.certificate_categorycode,cc1.certificate_categoryfid FROM certificate_category cc1 WHERE cc1.certificate_categoryfid=0 ) cc2 ON cc2.rowID=cc.certificate_categoryfid ");
         sbwhere.Append(" LEFT JOIN manage_user u ON u.user_id=cc.k_user  ");
         sbwhere.AppendFormat(" where cc.certificate_categoryfid<>0 ");
         sbcount.Append(" select count(cc.rowID) as totalCount ");
         if (!string.IsNullOrEmpty(query.searchcon))
         {
             sbwhere.AppendFormat(" and (cc.certificate_categoryname like N'%{0}%' OR cc.certificate_categorycode like N'%{0}%' or cc2.certificate_categoryname like N'%{0}%' OR cc2.certificate_categorycode like N'%{0}%') ",query.searchcon);
         }
         if (query.IsPage)
         {
             sbcount.Append(sbwhere.ToString());
             DataTable dt = new DataTable();
             dt = _access.getDataTable(sbcount.ToString());
             if (dt != null && dt.Rows.Count > 0)
             {
                 totalCount = Convert.ToInt32(dt.Rows[0]["totalCount"]);
             }
         }
         sbwhere.AppendFormat(" limit {0},{1} ", query.Start, query.Limit);
         sb.Append(sbwhere.ToString());
         return _access.getDataTableForObj<CertificateCategoryQuery>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->GetCertificateCategoryList-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 10
0
        public int DeleteCCByTransaction(CertificateCategoryQuery query)
        {
            StringBuilder sql = new StringBuilder();
            try
            {
                sql.AppendFormat(" DELETE FROM certificate_category WHERE rowID in ({0}); ", query.frowIDs);//刪除大類
                MySqlConnection conn = new MySqlConnection(connStr);//在这里CONN_STRING也就是连接Mysql数据库的语句
                conn.Open();//打开
                MySqlCommand command = conn.CreateCommand();//在这里也可以写成MySqlCommand command=new MySqlCommand();

                MySqlTransaction transaction = null;
                transaction = conn.BeginTransaction(); //这两句也可以写成  MySqlTransaction transaction =new MySqlTransaction();
                command.Connection = conn;
                command.Transaction = transaction;
                int count = 0;

                try
                {
                    command.CommandText = sql.ToString();
                    count = command.ExecuteNonQuery();
                    transaction.Commit(); //进行执行
                }
                catch
                {

                    transaction.Rollback();//发生异常进行回滚
                }

                return count;
            }
            catch (Exception ex)
            {
                throw new Exception("InspectionReportDao-->DeleteCCByTransaction-->" + ex.Message + sql.ToString(), ex);
            }
        }
Esempio n. 11
0
 public bool CheckCode(CertificateCategoryQuery query)
 {
     try
     {
         List<CertificateCategoryQuery> list = new List<Model.Query.CertificateCategoryQuery>();
         list=_inspectionReport.CheckCode(query);
         if (list != null && list.Count > 0)
         {
             return true;
         }
         else {
             return false;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->CheckCode-->" + ex.Message, ex);
     }
 }
Esempio n. 12
0
 public bool Update(CertificateCategoryQuery query)
 {
     try
     {
         int res = _inspectionReport.Update(query);
         if (res > 0)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->Update-->" + ex.Message, ex);
     }
 }
Esempio n. 13
0
 public int GetNewCertificateCategoryId(CertificateCategoryQuery query)
 {
     try
     {
         DataTable dt = _inspectionReport.GetNewCertificateCategoryId(query);
         return Convert.ToInt32(dt.Rows[0][0]);
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->GetNewCertificateCategoryId-->" + ex.Message, ex);
     }
 }
Esempio n. 14
0
 public int DeleteCertificateCategory(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("DELETE FROM certificate_category WHERE rowID in ({0})", query.rowIDs);
         return _access.execCommand(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->DeleteCertificateCategory-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 15
0
 public int UpdateCertificateCategory(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("UPDATE certificate_category SET certificate_categorycode='{0}' ", query.certificate_categorycode);
         if (!string.IsNullOrEmpty(query.certificate_categoryname))
         {
             sb.AppendFormat(" ,certificate_categoryname='{0}' ", query.certificate_categoryname);
         }
         sb.AppendFormat(" WHERE rowID='{0}' ",query.frowID);
         return _access.execCommand(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->UpdateCertificateCategory-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 16
0
 public int AddSave(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("INSERT INTO certificate_category (certificate_categoryname,certificate_categorycode,certificate_categoryfid,k_user,k_date,status) VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", query.certificate_category_childname, query.certificate_category_childcode, query.frowID,query.k_user,Common.CommonFunction.DateTimeToString(query.k_date),1);
         return _access.execCommand(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->AddSave-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 17
0
 public List<CertificateCategoryQuery> CheckBigCode(CertificateCategoryQuery query)
 {
     string folder = string.Empty;
     try
     {
         return _inspectionReport.CheckCode(query);
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->CheckBigCode-->" + ex.Message, ex);
     }
 }
Esempio n. 18
0
 public List<CertificateCategoryQuery> GetLsit(CertificateCategoryQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat(" SELECT cc.rowID FROM certificate_category cc WHERE cc.certificate_categoryfid='{0}' AND cc.certificate_categorycode='{1}';", query.frowID,query.certificate_category_childcode);
         return _access.getDataTableForObj<CertificateCategoryQuery>(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->GetLsit-->" + sql.ToString() + ex.Message, ex);
     }
 }
Esempio n. 19
0
 public List<CertificateCategoryQuery> GetType2Store(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("SELECT cc.certificate_categoryname,cc.rowID AS frowID,cc.certificate_categorycode FROM certificate_category cc WHERE cc.certificate_categoryfid='{0}';", query.rowID);
         return _access.getDataTableForObj<CertificateCategoryQuery>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->GetType1Store-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 20
0
 public List<CertificateCategoryQuery> CheckCode(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.Append("SELECT cc.certificate_categoryname,cc.rowID FROM certificate_category cc WHERE  1=1");
         if (!string.IsNullOrEmpty(query.certificate_categorycode))
         {
             sb.AppendFormat(" and cc.certificate_categorycode='{0}' ", query.certificate_categorycode);
         }
         else if (!string.IsNullOrEmpty(query.certificate_category_childcode))
         {
             sb.AppendFormat(" and cc.certificate_categorycode='{0}' ", query.certificate_category_childcode);
         }
         return _access.getDataTableForObj<CertificateCategoryQuery>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->CheckCode-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 21
0
 public List<CertificateCategoryQuery> CheckChildName(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("SELECT cc.certificate_categoryname FROM certificate_category cc WHERE cc.certificate_categoryfid<>0 AND cc.certificate_categoryname='{0}'", query.certificate_category_childname);
         return _access.getDataTableForObj<CertificateCategoryQuery>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->CheckChildName-->" + ex.Message + sb.ToString(), ex);
     }
 }
        public JsonResult UpdateActive()
        {
            try
            {
                CertificateCategoryQuery query = new CertificateCategoryQuery();
                if (!string.IsNullOrEmpty(Request.Params["id"]))
                {
                    query.rowID = Convert.ToInt32(Request.Params["id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["active"]))
                {
                    query.status = Convert.ToInt32(Request.Params["active"]);
                }
                _inspectionReport = new InspectionReportMgr(mySqlConnectionString);
                int res = _inspectionReport.UpdateActive(query);
                if (res > 0)
                {
                    return Json(new { success = "true", msg = "" });
                }
                else
                {
                    return Json(new { success = "false", msg = "" });
                }
            }
            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);
                return Json(new { success = "false", msg = "" });
            }

        }
Esempio n. 23
0
 public bool BeforeDelete( string rowIDs)
 {
     string json = string.Empty;
     bool b = false;
     CertificateCategoryQuery query = new CertificateCategoryQuery();
     try
     {
         if (rowIDs.IndexOf("|") != -1)
         {
             foreach (string id in rowIDs.Split('|'))
             {
                 if (!string.IsNullOrEmpty(id))
                 {
                     string[] data = id.Split(',');
                     query = new CertificateCategoryQuery();
                     query.rowID = Convert.ToInt32(data[0]);
                     query.frowID = Convert.ToInt32(data[1]);
                     DataTable _dt = _inspectionReport.BeforeDelete(query);
                     if (_dt.Rows.Count > 0)
                     {
                         b = false;
                         break;
                     }
                     else
                     {
                         json = "{success:true,msg:'1'}";
                         b = true;
                     }
                 }
             }
         }
       return b;
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->BeforeDelete-->" + ex.Message, ex);
     }
 }
Esempio n. 24
0
 public int Update(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("UPDATE certificate_category SET certificate_categorycode='{0}',certificate_categoryname='{1}',certificate_categoryfid='{2}' WHERE rowID='{3}'", query.certificate_category_childcode,query.certificate_category_childname,query.frowID,query.rowID);
         return _access.execCommand(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->Update-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 25
0
 public List<CertificateCategoryQuery> GetLsit(CertificateCategoryQuery query)
 {
     string json = string.Empty;
     DataTable _dt = new DataTable();
     try
     {
         return _inspectionReport.GetLsit(query);
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportMgr-->GetLsit-->" + ex.Message, ex);
     }
 }
Esempio n. 26
0
 public List<CertificateCategoryQuery> GetCertificateCategoryInfo(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("SELECT cc.certificate_categoryname,cc.certificate_categorycode,cc.rowID FROM certificate_category cc WHERE cc.rowID='{0}'",query.rowID);
         //if (query.frowID > 0)
         //{
         //    sb.AppendFormat(" and cc.certificate_categoryfid='{0}' ",query.frowID);
         //}
         return _access.getDataTableForObj<CertificateCategoryQuery>(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->GetCertificateCategoryInfo-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 27
0
 public DataTable BeforeDelete(CertificateCategoryQuery query)
 {
     StringBuilder sql = new StringBuilder();
     try
     {
         sql.AppendFormat(" select rowID from inspection_report where certificate_type1='{0}' and certificate_type2='{1}';",query.frowID,query.rowID);
         return _access.getDataTable(sql.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->BeforeDelete-->" + sql.ToString() + ex.Message, ex);
     }
 }
Esempio n. 28
0
 public DataTable GetNewCertificateCategoryId(CertificateCategoryQuery query)
 {
     StringBuilder sb = new StringBuilder();
     try
     {
         sb.AppendFormat("INSERT INTO certificate_category (certificate_categorycode,certificate_categoryfid,certificate_categoryname,k_user,k_date,status) VALUES('{0}','{1}','{2}','{3}','{4}','{5}');select @@identity", query.certificate_categorycode,query.frowID,query.certificate_categoryname,query.k_user,Common.CommonFunction.DateTimeToString(query.k_date),1);
         return _access.getDataTable(sb.ToString());
     }
     catch (Exception ex)
     {
         throw new Exception("InspectionReportDao-->GetNewCertificateCategoryId-->" + ex.Message + sb.ToString(), ex);
     }
 }
Esempio n. 29
0
        public List<CertificateCategoryQuery> GetStore(CertificateCategoryQuery query)
        {
            try
            {
                return _inspectionReport.GetStore(query);
            }
            catch (Exception ex)
            {
                throw new Exception("InspectionReportMgr-->GetStore-->" + ex.Message, ex);
            }
 
        }
        public HttpResponseBase InspectionReportSave()
        {
            string json = string.Empty;
            List<CertificateCategoryQuery> list = new List<CertificateCategoryQuery>();
            List<CertificateCategoryQuery> oldlist = new List<CertificateCategoryQuery>();
            List<CertificateCategoryQuery> oldbiglist = new List<CertificateCategoryQuery>();
            _inspectionReport = new InspectionReportMgr(mySqlConnectionString);
            try
            {
                CertificateCategoryQuery query = new CertificateCategoryQuery();
                string fid = string.Empty;
                if (!string.IsNullOrEmpty(Request.Params["frowname"]))
                {
                    fid = Request.Params["frowname"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["rowID"]))
                {
                    query.rowID = Convert.ToInt32(Request.Params["rowID"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["frowID"]))
                {
                    query.frowID = Convert.ToInt32(Request.Params["frowID"].ToString());
                }
                if (!string.IsNullOrEmpty(Request.Params["f_code"]))
                {
                    query.certificate_categorycode = Request.Params["f_code"].ToString().ToUpper();
                }
                if (!string.IsNullOrEmpty(Request.Params["child_name"]))
                {
                    query.certificate_category_childname = Request.Params["child_name"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["child_code"]))
                {
                    query.certificate_category_childcode = Request.Params["child_code"].ToString().ToUpper();
                }
                uint unum = 0;
                if (uint.TryParse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString(), out unum))
                {
                    query.k_user = unum;
                }
                query.k_date = DateTime.Now;
                int isnum = 0;
                //查詢小類信息以供編輯時查重
                CertificateCategoryQuery oldquery = new CertificateCategoryQuery();
                oldquery.rowID = query.rowID;
                oldlist = _inspectionReport.GetCertificateCategoryInfo(oldquery);
                //查詢大類信息以供編輯時查重
                CertificateCategoryQuery oldbigquery = new CertificateCategoryQuery();
                oldbigquery.rowID = query.frowID;
                oldbiglist = _inspectionReport.GetCertificateCategoryInfo(oldbigquery);
                #region 編輯處理
                if (query.rowID != 0)
                {//編輯
                    #region 編輯時選擇大類非編輯大類
                    if (int.TryParse(fid, out isnum))//編輯選擇大類
                    {
                        bool res = true;
                        query.frowID = isnum;
                        query.certificate_categoryname = string.Empty;
                        if (oldbiglist.Count > 0 && oldbiglist[0].certificate_categorycode != query.certificate_categorycode)//檔大類code被編輯時
                        {
                            //檢查大類code是否重複
                            CertificateCategoryQuery bigquery = new CertificateCategoryQuery();
                            bigquery.certificate_categorycode = query.certificate_categorycode;
                            res = _inspectionReport.CheckCode(bigquery);
                            if (res)
                            {
                                json = "{success:true,type:1,msg:'證書-大類CODE不能重複!'}";
                                this.Response.Clear();
                                this.Response.Write(json);
                                this.Response.End();
                                return this.Response;
                            }
                        }
                        
                    }
                    #endregion
                    #region 編輯時修改大類
                    else
                    {
                        query.certificate_categoryname = fid;
                        if (_inspectionReport.CheckCertificateCategoryName(query))
                        {
                            json = "{success:true,type:1,msg:'證書-大類名稱不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        //檢查大類code是否重複
                        if (oldbiglist.Count > 0 && oldbiglist[0].certificate_categorycode != query.certificate_categorycode)
                        {
                            CertificateCategoryQuery bigquery = new CertificateCategoryQuery();
                            bigquery.certificate_categorycode = query.certificate_categorycode;
                            if (_inspectionReport.CheckCode(bigquery))
                            {
                                json = "{success:true,type:1,msg:'證書-大類CODE不能重複!'}";
                                this.Response.Clear();
                                this.Response.Write(json);
                                this.Response.End();
                                return this.Response;
                            }
                        }
                    }
                    #endregion
                    #region 編輯時檔小類名稱修改時
                    if (oldlist.Count > 0 && oldlist[0].certificate_categoryname != query.certificate_category_childname)//證書-小類被修改
                    {
                        if (_inspectionReport.CheckChildName(query))//檔小類名稱存在時
                        {
                            json = "{success:true,type:1,msg:'證書-小類名稱不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    #endregion
                    #region  編輯時檔小類code修改時
                    if (oldlist[0].certificate_categorycode != query.certificate_category_childcode)//檔小類code被修改時
                    {
                        CertificateCategoryQuery smallquery = new CertificateCategoryQuery();
                        smallquery.certificate_categorycode = query.certificate_category_childcode;
                        if (_inspectionReport.CheckCode(smallquery))
                        {
                            json = "{success:true,type:1,msg:'證書-小類CODE不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                    }
                    #endregion
                    #region 判斷大類小類code是否一樣
                    if (query.certificate_category_childcode == query.certificate_categorycode)
                    {
                        json = "{success:true,type:1,msg:'證書-小類名稱不能重複!'}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    #endregion
                    #region 更新大類
                    //更新大類
                    int istrue = _inspectionReport.UpdateCertificateCategory(query);
                    if (istrue <= 0)
                    {
                        json = "{success:true,type:0,msg:'證書-大類修改失敗!'}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    #endregion
                    #region 更新小類
                    if (_inspectionReport.Update(query))
                    {
                        json = "{success:true,type:0,msg:'修改成功!'}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    else
                    {
                        json = "{success:true,type:0,msg:'修改失敗!'}";
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }

                }
                #endregion
                #endregion
                #region 新增處理
                else
                { //新增
                    bool res = true;
                    #region 大類是選擇出來的
                    if (int.TryParse(fid, out isnum))
                    {

                        query.frowID = isnum;
                        //檢查證書-大類code是否重複
                        if (oldbiglist.Count > 0 && oldbiglist[0].certificate_categorycode != query.certificate_categorycode)//大類code被修改
                        {
                            CertificateCategoryQuery bigquery = new CertificateCategoryQuery();
                            bigquery.certificate_categorycode = query.certificate_categorycode;
                            res = _inspectionReport.CheckCode(bigquery);
                            if (res)
                            {
                                json = "{success:true,type:1,msg:'證書-大類CODE不能重複!'}";
                                this.Response.Clear();
                                this.Response.Write(json);
                                this.Response.End();
                                return this.Response;
                            }
                        }
                        //檢查小類名稱是否重複
                        res = _inspectionReport.CheckChildName(query);
                        if (res)
                        {
                            json = "{success:true,type:1,msg:'證書-小類名稱不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        //檢查小類code是否重複
                        CertificateCategoryQuery smallquery = new CertificateCategoryQuery();
                        smallquery.certificate_categorycode = query.certificate_category_childcode;
                        res = _inspectionReport.CheckCode(smallquery);
                        if (res)
                        {
                            json = "{success:true,type:1,msg:'證書-小類CODE不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        int num = _inspectionReport.UpdateCertificateCategory(query);//更新大類信息
                        if (num <= 0)
                        {
                            json = "{success:true,type:0,msg:'證書-大類新增失敗!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        #region 新增小類
                        if (_inspectionReport.AddSave(query) > 0)//新增保存
                        {
                            json = "{success:true,type:0,msg:'新增成功!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        else
                        {
                            json = "{success:true,type:0,msg:'新增失敗!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        #endregion
                    }
                    #endregion
                    #region 大類也是新增
                    else
                    {
                        query.certificate_categoryname = fid;
                        if (_inspectionReport.CheckCertificateCategoryName(query))
                        {
                            json = "{success:true,type:1,msg:'證書-大類名稱不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        CertificateCategoryQuery bigquery = new CertificateCategoryQuery();
                        bigquery.certificate_categorycode = query.certificate_categorycode;
                        if (_inspectionReport.CheckCode(bigquery))
                        {
                            json = "{success:true,type:1,msg:'證書-大類CODE不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        //檢查小類名稱是否重複
                        if (query.certificate_category_childcode == query.certificate_categorycode)
                        {
                            json = "{success:true,type:1,msg:'證書-小類名稱不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        res = _inspectionReport.CheckChildName(query);
                        if (res)
                        {
                            json = "{success:true,type:1,msg:'證書-小類名稱不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        //檢查小類code是否重複
                        CertificateCategoryQuery smallquery = new CertificateCategoryQuery();
                        smallquery.certificate_categorycode = query.certificate_category_childcode;
                        res = _inspectionReport.CheckCode(smallquery);
                        if (res)
                        {
                            json = "{success:true,type:1,msg:'證書-小類CODE不能重複!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        #region 新增大類
                        query.frowID = 0;
                        query.frowID = _inspectionReport.GetNewCertificateCategoryId(query);
                        if (query.frowID <= 0)
                        {
                            json = "{success:true,type:0,msg:'證書-大類新增失敗!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        #endregion
                        #region 新增小類
                        if (_inspectionReport.AddSave(query) > 0)//新增保存
                        {
                            json = "{success:true,type:0,msg:'新增成功!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        else
                        {
                            json = "{success:true,type:0,msg:'新增失敗!'}";
                            this.Response.Clear();
                            this.Response.Write(json);
                            this.Response.End();
                            return this.Response;
                        }
                        #endregion
                    }
                    #endregion
                    
                    //#region 新增大類
                    //int num = _inspectionReport.UpdateCertificateCategory(query);//更新大類信息
                    //if (num <= 0)
                    //{
                    //    json = "{success:true,type:0,msg:'證書-大類新增失敗!'}";
                    //    this.Response.Clear();
                    //    this.Response.Write(json);
                    //    this.Response.End();
                    //    return this.Response;
                    //}
                    //#endregion
                   
                }
                #endregion
            }
            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;
        }