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; }