public HttpResponseBase SaveInspectionRe()
        {
            string json = "{success:'false',msg:'5'}";
            try
            {
                _inspectionReport = new InspectionReportMgr(mySqlConnectionString);
                InspectionReportQuery query = new InspectionReportQuery();
                InspectionReportQuery oldQuery = new InspectionReportQuery();
                if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                {
                    query.product_id = Convert.ToUInt32(Request.Params["product_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["brand_id"]))
                {
                    query.brand_id = Convert.ToUInt32(Request.Params["brand_id"]);
                }

                if (!string.IsNullOrEmpty(Request.Params["certificate_type1"]))
                {
                    query.certificate_type1 = Request.Params["certificate_type1"];
                }
                if (!string.IsNullOrEmpty(Request.Params["certificate_type2"]))
                {
                    query.certificate_type2 = Request.Params["certificate_type2"];
                }
                if (!string.IsNullOrEmpty(Request.Params["certificate_expdate"]))
                {
                    query.certificate_expdate = Convert.ToDateTime(Request.Params["certificate_expdate"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["certificate_desc"]))
                {
                    query.certificate_desc = Request.Params["certificate_desc"];
                }
                if (!string.IsNullOrEmpty(Request.Params["certificate_filename"]))
                {
                    query.certificate_filename = Request.Params["certificate_filename"];
                }
                if (!string.IsNullOrEmpty(Request.Params["rowID"]))
                {
                    query.rowID = Convert.ToInt32(Request.Params["rowID"]);
                    oldQuery = _inspectionReport.oldQuery(query);
                }
                if (!string.IsNullOrEmpty(Request.Params["sort"]))
                {
                    query.sort = Convert.ToInt32(Request.Params["sort"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["old_sort"]))
                {
                    query.old_sort = Convert.ToInt32(Request.Params["old_sort"]);
                }
                query.k_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                query.m_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id;
                #region 排序是否重複
                if (_inspectionReport.IsSortExist(query) || query.old_sort == query.sort)//sort不重複
                {
                    if (!_inspectionReport.IsExist(query))
                    {

                        HttpPostedFileBase picFile = Request.Files["certificate_filename"];
                        //檢查上傳的圖片名稱和拼出來的圖片名稱是否一樣,不一樣則不能上傳
                        //拼成圖片名稱

                        #region 上傳圖片
                        try
                        {
                            string path = Server.MapPath(xmlPath);
                            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
                            SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format");
                            SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element");
                            SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue");
                            SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME");
                            SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD");
                            //擴展名、最小值、最大值
                            string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value;
                            string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value;
                            string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value;
                            string localInspectionReportPath = imgLocalPath + InspectionReportPath;//圖片存儲地址
                            FileManagement fileLoad = new FileManagement();
                            if (Request.Files.Count > 0)
                            {
                                HttpPostedFileBase file = Request.Files[0];
                                string fileName = string.Empty;//當前文件名
                                string fileExtention = string.Empty;//當前文件的擴展名

                                //
                                //文件夾名稱
                                string[] dirPath = new string[2];
                                dirPath[0] = query.brand_id.ToString() + "/".ToString();
                                dirPath[1] = query.product_id.ToString() + "/".ToString();
                                //
                                fileName = fileLoad.NewFileName(file.FileName);
                                if (fileName != "")
                                {

                                    string[] mapPath = new string[2];
                                    mapPath[0] = _inspectionReport.GetType1Folder(query);
                                    mapPath[1] = _inspectionReport.GetType2Folder(query);
                                    string NewFileName = string.Empty;
                                    NewFileName = query.brand_id + "-" + query.product_id + "-" + mapPath[0].Replace('/', ' ').Replace(" ", "") + "-" + mapPath[1].Replace('/', ' ').Replace(" ", "");
                                    #region 判斷圖片名稱是否正確,正確則保存
                                    if (picFile.FileName.Substring(0, picFile.FileName.LastIndexOf(".")) == NewFileName)
                                    {
                                        fileName = fileName.Substring(0, fileName.LastIndexOf("."));
                                        fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString();

                                        string ServerPath = string.Empty;
                                        //判斷目錄是否存在,不存在則創建
                                        FTP f_cf = new FTP();
                                        CreateFolder(localInspectionReportPath, dirPath);
                                        //壓縮圖片 源文件
                                        string sourcePath = Server.MapPath(imgLocalServerPath + InspectionReportPath + dirPath[0] + dirPath[1] + fileName + fileExtention);

                                        if (!Directory.Exists(Server.MapPath(imgLocalServerPath + InspectionReportPath + dirPath[0] + dirPath[1])))
                                        {
                                            Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + InspectionReportPath + dirPath[0] + dirPath[1]));
                                        }

                                        file.SaveAs(sourcePath);
                                        fileName = NewFileName + fileExtention;
                                        NewFileName = localInspectionReportPath + dirPath[0] + dirPath[1] + NewFileName + fileExtention;
                                        ServerPath = Server.MapPath(imgLocalServerPath + InspectionReportPath + dirPath[0] + dirPath[1]);
                                        string ErrorMsg = string.Empty;
                                        if (query.rowID != 0)
                                        {
                                            string oldFileName = oldQuery.certificate_filename;
                                            CommonFunction.DeletePicFile(ServerPath + oldFileName);
                                            FTP ftp = new FTP(localInspectionReportPath + dirPath[0] + dirPath[1], ftpuser, ftppwd);
                                            List<string> tem = ftp.GetFileList();
                                            if (tem.Contains(oldFileName))
                                            {
                                                FTP ftps = new FTP(localInspectionReportPath + dirPath[0] + dirPath[1] + oldFileName, ftpuser, ftppwd);
                                                ftps.DeleteFile(localInspectionReportPath + dirPath[0] + dirPath[1] + oldFileName);
                                            }
                                        }
                                        try
                                        {
                                            Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件
                                            bool result = fileLoad.ZIPUpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd, sourcePath);
                                            if (result)//上傳成功
                                            {
                                                query.certificate_filename = fileName;
                                                //刪除本地圖片
                                                CommonFunction.DeletePicFile(sourcePath);
                                                json = _inspectionReport.SaveInspectionRe(query);
                                            }
                                        }
                                        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);
                                            query.certificate_filename = oldQuery.certificate_filename;
                                        }
                                        if (!string.IsNullOrEmpty(ErrorMsg))
                                        {
                                            string jsonPic = string.Empty;
                                            jsonPic = "{success:true,msg:\"" + ErrorMsg + "\"}";
                                            this.Response.Clear();
                                            this.Response.Write(jsonPic);
                                            this.Response.End();
                                            return this.Response;
                                        }
                                    }
                                    else
                                    {
                                        json = "{success:'false',msg:'3'}";//圖片名稱不對
                                    }
                                    #endregion
                                }
                                else
                                {
                                    query.certificate_filename = oldQuery.certificate_filename;
                                    json = _inspectionReport.SaveInspectionRe(query);
                                }

                            }
                        }
                        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);
                            query.certificate_filename = oldQuery.certificate_filename;
                        }
                        #endregion


                        //  picFile.SaveAs();
                    }
                    else
                    {
                        json = "{success:'false',msg:'2'}";//重複數據
                    }
                }
                else
                {
                    json = "{success:'false',msg:'4'}";//重複數據
                }



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