/// <summary>
        /// 新增編輯類別信息
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase ProductCategorySave()
        {
            string json = string.Empty;
            string jsonStr = string.Empty;
            CategoryQuery cq = new CategoryQuery();
            IAreaPactetImplMgr _iareaPacketMgr = new AreaPacketMgr(mySqlConnectionString);
            string errorInfo = string.Empty;
            try
            {
                _proCategoryImplMgr = new CategoryMgr(mySqlConnectionString);
                if (!string.IsNullOrEmpty(Request.Params["category_id"]))
                {
                    cq.category_id = Convert.ToUInt32(Request.Params["category_id"]);
                }
                CategoryQuery oldCq = _proCategoryImplMgr.GetProductCategoryById(cq);
                if (oldCq != null)
                {
                    cq.banner_image = oldCq.banner_image;
                    cq.category_image_in = oldCq.category_image_in;
                    cq.category_image_out = oldCq.category_image_out;
                    cq.category_image_app = oldCq.category_image_app;
                }
                #region 上傳圖片

                try
                {
                    if (Request.Files.Count != 0)
                    {
                        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_MinValue");
                        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 localPromoPath = imgLocalPath + promoPath;//圖片存儲地址                             

                        for (int a = 0; a < Request.Files.Count; a++)
                        {
                            string fileName = string.Empty;     //當前文件名
                            string fileExtention = string.Empty;//當前文件的擴展名
                            HttpPostedFileBase file = Request.Files[a];
                            fileName = Path.GetFileName(file.FileName);
                            if (string.IsNullOrEmpty(fileName))
                            {
                                continue;
                            }

                            bool result = false;
                            string NewFileName = string.Empty;
                            string ServerPath = string.Empty;
                            string ErrorMsg = string.Empty;
                            string oldFileName = string.Empty;  //舊文件名
                            //生成隨機數,用於圖片的重命名
                            Random rand = new Random();
                            int newRand = rand.Next(1000, 9999);
                            fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                            NewFileName = newRand + fileExtention;

                            //判斷目錄是否存在,不存在則創建
                            CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));
                            fileName = NewFileName;
                            NewFileName = localPromoPath + NewFileName;//絕對路徑
                            ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                            FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                            List<string> tem = ftp.GetFileList();
                            try
                            {
                                //上傳
                                FileManagement fileLoad = new FileManagement();
                                result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                                if (result)//上傳成功
                                {
                                    switch (a)
                                    {
                                        case 0:
                                            cq.banner_image = fileName;
                                            break;
                                        case 1:
                                            cq.category_image_in = fileName;
                                            break;
                                        case 2:
                                            cq.category_image_out = fileName;
                                            break;
                                        case 3:
                                            cq.category_image_app = fileName;
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                else
                                {
                                    //圖片上傳失敗則圖片名稱為原有圖片名稱
                                    switch (a)
                                    {
                                        case 0:
                                            cq.banner_image = fileName;
                                            break;
                                        case 1:
                                            cq.category_image_in = fileName;
                                            break;
                                        case 2:
                                            cq.category_image_out = fileName;
                                            break;
                                        case 3:
                                            cq.category_image_app = fileName;
                                            break;
                                        default:
                                            break;
                                    }
                                    errorInfo += "第" + (a + 1) + "張" + ErrorMsg + "<br/>";                                
                                }
                            }
                            catch (Exception ex)
                            {
                                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                log.Error(logMessage);
                                jsonStr = "{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);
                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";
                  
                }


                #endregion              
                    if (!string.IsNullOrEmpty(Request.Params["comboFrontCage"]))
                    {
                        cq.category_father_id = Convert.ToUInt32(Request.Params["comboFrontCage"].ToString());
                    }

                    if (!string.IsNullOrEmpty(Request.Params["category_name"]))
                    {
                        cq.category_name = Request.Params["category_name"].ToString();
                    }

                    if (!string.IsNullOrEmpty(Request.Params["category_sort"]))
                    {
                        cq.category_sort = Convert.ToUInt32(Request.Params["category_sort"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["category_display"]))
                    {
                        cq.category_display = Convert.ToUInt32(Request.Params["category_display"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Params["categorylinkmode"]))
                    {
                        cq.category_link_mode = Convert.ToUInt32(Request.Params["categorylinkmode"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["category_link_url"]))
                    {
                        cq.category_link_url = Request.Params["category_link_url"].ToString();
                    }
                    //if (!string.IsNullOrEmpty(Request.Params["photo"]))
                    //{
                    //    #region 上傳圖片

                    //    try
                    //    {
                    //        if (Request.Files.Count != 0)
                    //        {
                    //            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_MinValue");
                    //            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 localPromoPath = imgLocalPath + promoPath;//圖片存儲地址
                    //            //生成隨機數,用於圖片的重命名
                    //            Random rand = new Random();
                    //            int newRand = rand.Next(1000, 9999);



                    //            //獲取上傳的圖片
                    //            HttpPostedFileBase file = Request.Files[0];
                    //            string fileName = string.Empty;//當前文件名
                    //            string fileExtention = string.Empty;//當前文件的擴展名

                    //            fileName = Path.GetFileName(file.FileName);
                    //            if (!string.IsNullOrEmpty(fileName))
                    //            {
                    //                bool result = false;
                    //                string NewFileName = string.Empty;

                    //                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                    //                //NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名
                    //                NewFileName = newRand + fileExtention;
                    //                string ServerPath = string.Empty;
                    //                //判斷目錄是否存在,不存在則創建
                    //                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                    //                //  returnName += promoPath + NewFileName;
                    //                fileName = NewFileName;
                    //                NewFileName = localPromoPath + NewFileName;//絕對路徑
                    //                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                    //                string ErrorMsg = string.Empty;

                    //                //上傳之前刪除已有的圖片
                    //                //string oldFileName = olderpcmodel.banner_image;
                    //                FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                    //                List<string> tem = ftp.GetFileList();
                    //                //if (tem.Contains(oldFileName))
                    //                //{
                    //                //    //FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd);
                    //                //    //ftps.DeleteFile(localPromoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                    //                //    //DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                    //                //}
                    //                try
                    //                {
                    //                    //上傳
                    //                    FileManagement fileLoad = new FileManagement();
                    //                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                    //                    if (result)//上傳成功
                    //                    {
                    //                        cq.banner_image = fileName;
                    //                    }
                    //                }
                    //                catch (Exception ex)
                    //                {
                    //                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    //                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                    //                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    //                    log.Error(logMessage);
                    //                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                    //                    //pacdModel.banner_image = olderpcmodel.banner_image;
                    //                }
                    //            }
                    //            else
                    //            {
                    //                //pacdModel.banner_image = olderpcmodel.banner_image;
                    //            }
                    //        }

                    //    }
                    //    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);
                    //        jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                    //        //pacdModel.banner_image = olderpcmodel.banner_image;
                    //    }


                    //    #endregion
                    //}
                    if (!string.IsNullOrEmpty(Request.Params["banner_status"]))
                    {
                        cq.banner_status = Convert.ToUInt32(Request.Params["banner_status"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["banner_link_mode"]))
                    {
                        cq.banner_link_mode = Convert.ToUInt32(Request.Params["banner_link_mode"].ToString());
                    }
                    if (!string.IsNullOrEmpty(Request.Params["banner_link_url"]))
                    {
                        cq.banner_link_url = Request.Params["banner_link_url"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Params["startdate"]))
                    {
                        cq.banner_show_start = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["startdate"].ToString()));
                    }
                    if (!string.IsNullOrEmpty(Request.Params["enddate"]))
                    {
                        cq.banner_show_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["enddate"].ToString()));
                    } 
                    if (!string.IsNullOrEmpty(Request.Params["short_description"]))
                    {
                        cq.short_description = Request.Params["short_description"].ToString();
                    }

                    if (string.IsNullOrEmpty(Request.Params["category_id"]))
                    {
                        cq.category_ipfrom = CommonFunction.GetClientIP();
                        cq.category_createdate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                        cq.category_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                        cq.status = 1;
                        _proCategoryImplMgr = new CategoryMgr(mySqlConnectionString);

                        int i = _proCategoryImplMgr.ProductCategorySave(cq);
                        if (i > 0)
                        {
                            json = "{success:true}";
                        }
                    }

                    else
                    {
                        //_proCategoryImplMgr = new CategoryMgr(mySqlConnectionString);
                        //cq.category_id = Convert.ToUInt32(Request.Params["category_id"]);
                        //CategoryQuery oldCq = _proCategoryImplMgr.GetProductCategoryById(cq);
                        //if (!string.IsNullOrEmpty(Request.Params["comboFrontCage"]))
                        //{
                        //    cq.category_father_id = Convert.ToUInt32(Request.Params["comboFrontCage"].ToString());
                        //}
                        //else
                        //{
                        //    cq.category_father_id = oldCq.category_father_id;
                        //}

                        //if (!string.IsNullOrEmpty(Request.Params["category_name"]))
                        //{
                        //    cq.category_name = Request.Params["category_name"].ToString();
                        //}
                        //else
                        //{
                        //    cq.category_name = oldCq.category_name;
                        //}

                        //if (!string.IsNullOrEmpty(Request.Params["category_sort"]))
                        //{
                        //    cq.category_sort = Convert.ToUInt32(Request.Params["category_sort"].ToString());
                        //}
                        //else
                        //{
                        //    cq.category_sort = oldCq.category_sort;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["category_display"]))
                        //{
                        //    cq.category_display = Convert.ToUInt32(Request.Params["category_display"]);
                        //}
                        //else
                        //{
                        //    cq.category_display = oldCq.category_display;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["categorylinkmode"]))
                        //{
                        //    cq.category_link_mode = Convert.ToUInt32(Request.Params["categorylinkmode"].ToString());
                        //}
                        //else
                        //{
                        //    cq.category_link_mode = oldCq.category_link_mode;
                        //}

                        //cq.category_link_url = Request.Params["category_link_url"].ToString();

                        //if (!string.IsNullOrEmpty(Request.Params["photo"]))
                        //{
                        //    #region 上傳圖片

                        //    try
                        //    {
                        //        if (Request.Files.Count != 0)
                        //        {
                        //            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_MinValue");
                        //            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 localPromoPath = imgLocalPath + promoPath;//圖片存儲地址
                        //            生成隨機數,用於圖片的重命名
                        //            Random rand = new Random();
                        //            int newRand = rand.Next(1000, 9999);



                        //            獲取上傳的圖片
                        //            HttpPostedFileBase file = Request.Files[0];
                        //            string fileName = string.Empty;//當前文件名
                        //            string fileExtention = string.Empty;//當前文件的擴展名

                        //            fileName = Path.GetFileName(file.FileName);
                        //            if (!string.IsNullOrEmpty(fileName))
                        //            {
                        //                bool result = false;
                        //                string NewFileName = string.Empty;

                        //                fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower();
                        //                NewFileName = pacdModel.event_id + newRand + fileExtention;//圖片重命名為event_id+4位隨機數+擴展名
                        //                NewFileName = newRand + fileExtention;
                        //                string ServerPath = string.Empty;
                        //                判斷目錄是否存在,不存在則創建
                        //                CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'));

                        //                  returnName += promoPath + NewFileName;
                        //                fileName = NewFileName;
                        //                NewFileName = localPromoPath + NewFileName;//絕對路徑
                        //                ServerPath = Server.MapPath(imgLocalServerPath + promoPath);
                        //                string ErrorMsg = string.Empty;

                        //                上傳之前刪除已有的圖片
                        //                string oldFileName = oldCq.banner_image;
                        //                FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd);
                        //                List<string> tem = ftp.GetFileList();
                        //                if (tem.Contains(oldFileName))
                        //                {
                        //                    FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd);
                        //                    ftps.DeleteFile(localPromoPath + oldFileName);//刪除ftp:71.159上的舊圖片
                        //                    DeletePicFile(ServerPath + oldFileName);//刪除本地圖片
                        //                }
                        //                try
                        //                {
                        //                    上傳
                        //                    FileManagement fileLoad = new FileManagement();
                        //                    result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd);
                        //                    if (result)//上傳成功
                        //                    {
                        //                        cq.banner_image = fileName;
                        //                    }
                        //                }
                        //                catch (Exception ex)
                        //                {
                        //                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                        //                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name + "->fileLoad.UpLoadFile()", ex.Source, ex.Message);
                        //                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                        //                    log.Error(logMessage);
                        //                    jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                        //                    cq.banner_image = oldCq.banner_image;
                        //                }
                        //            }
                        //            else
                        //            {
                        //                cq.banner_image = oldCq.banner_image;
                        //            }
                        //        }
                        //    }
                        //    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);
                        //        jsonStr = "{success:false,msg:'圖片上傳失敗'}";

                        //        cq.banner_image = oldCq.banner_image;
                        //    }


                        //    #endregion
                        //}
                        //else
                        //{
                        //    cq.banner_image = oldCq.banner_image;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["banner_status"]))
                        //{
                        //    cq.banner_status = Convert.ToUInt32(Request.Params["banner_status"].ToString());
                        //}
                        //else
                        //{
                        //    cq.banner_status = oldCq.banner_status;
                        //}
                        //if (!string.IsNullOrEmpty(Request.Params["banner_link_mode"]))
                        //{
                        //    cq.banner_link_mode = Convert.ToUInt32(Request.Params["banner_link_mode"].ToString());
                        //}
                        //else
                        //{
                        //    cq.banner_link_mode = oldCq.banner_link_mode;
                        //}

                        //cq.banner_link_url = Request.Params["banner_link_url"].ToString();
                        //cq.short_description = Request.Params["short_description"].ToString();
                        //cq.banner_show_start = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["startdate"].ToString()));

                        //cq.banner_show_end = Convert.ToUInt32(CommonFunction.GetPHPTime(Request.Params["enddate"].ToString()));

                        cq.category_ipfrom = CommonFunction.GetClientIP();
                        cq.category_updatedate = Convert.ToUInt32(CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                        int j = _proCategoryImplMgr.ProductCategorySave(cq);
                        if (j > 0)
                        {
                            json = "{success:true}";
                        }
                    }


            }
            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,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
Beispiel #2
0
        public HttpResponseBase GetWebContent()
        {
            string json = string.Empty;
            string jsonStr = string.Empty;
            EdmContentQuery cq = new EdmContentQuery();
            IAreaPactetImplMgr _iareaPacketMgr = new AreaPacketMgr(mySqlConnectionString);
            try
            {

                if (!string.IsNullOrEmpty(Request.Params["webtext"]))
                {
                    jsonStr = Request.Params["webtext"].ToString();
                    Uri httpURL = new Uri(jsonStr);
                    //HttpWebRequest类继承于WebRequest,并没有自己的构造函数,需通过WebRequest的Creat方法 建立,并进行强制的类型转换
                    httpReq = (HttpWebRequest)WebRequest.Create(httpURL);
                    //通过HttpWebRequest的GetResponse()方法建立HttpWebResponse,强制类型转换

                    httpResp = (HttpWebResponse)httpReq.GetResponse();
                    //GetResponseStream()方法获取HTTP响应的数据流,并尝试取得URL中所指定的网页内容
                    //若成功取得网页的内容,则以System.IO.Stream形式返回,若失败则产生ProtoclViolationException错 误。在此正确的做法应将以下的代码放到一个try块中处理。这里简单处理
                    Stream respStream = httpResp.GetResponseStream();
                    //返回的内容是Stream形式的,所以可以利用StreamReader类获取GetResponseStream的内容,并以

                    //StreamReader类的Read方法依次读取网页源程序代码每一行的内容,直至行尾(读取的编码格式:UTF8)
                    StreamReader respStreamReader = new StreamReader(respStream, Encoding.UTF8);
                    byteRead = respStreamReader.Read(cbuffer, 0, 256);

                    while (byteRead != 0)
                    {
                        string strResp = new string(cbuffer, 0, byteRead);
                        strBuff = strBuff + strResp;
                        byteRead = respStreamReader.Read(cbuffer, 0, 256);
                    }

                    respStream.Close();
                    json = strBuff;
                }


                //int i = 0;
                //if (i > 0)
                //{
                //   json = "{success:true}";
                //}
            }
            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 = "";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        /// <summary>
        /// 新增編輯區域包信息
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase AreaPactetSave()
        {
            string json = string.Empty;
            AreaPacket ap = new AreaPacket();
            IAreaPactetImplMgr _iareaPacketMgr = new AreaPacketMgr(mySqlConnectionString);
            try
            {

                if (string.IsNullOrEmpty(Request.Params["id"]))
                {
                    if (!string.IsNullOrEmpty(Request.Params["name"]))
                    {
                        ap.packet_name = Request.Params["name"].ToString();
                    }

                    if (!string.IsNullOrEmpty(Request.Params["element_type"]))
                    {
                        ap.element_type = Convert.ToInt32(Request.Params["element_type"]);
                    }

                    if (!string.IsNullOrEmpty(Request.Params["packet_desc"]))
                    {
                        ap.packet_desc = Request.Params["packet_desc"].ToString();
                    }
                    if (!string.IsNullOrEmpty(Request.Params["show_number"]))
                    {
                        ap.show_number = Convert.ToInt32(Request.Params["show_number"]);
                    }
                    if (!string.IsNullOrEmpty(Request.Params["packet_sort"]))
                    {
                        ap.packet_sort = Convert.ToInt32(Request.Params["packet_sort"].ToString());
                    }
                    ap.create_userid = (Session["caller"] as Caller).user_id;
                    ap.update_userid = (Session["caller"] as Caller).user_id;
                    ap.packet_createdate = DateTime.Now;
                    ap.packet_updatedate = DateTime.Now;
                    int i = _iareaPacketMgr.AreaPacketSave(ap);
                    if (i > 0)
                    {
                        json = "{success:true}";
                    }
                }
                else
                {
                    AreaPacket areaPacketTemp = new AreaPacket();
                    areaPacketTemp.packet_id = Convert.ToInt32(Request.Params["id"]);
                    AreaPacket oldap = _iareaPacketMgr.GetModelById(areaPacketTemp);
                    ap.packet_id = Convert.ToInt32(Request.Params["id"]);

                    ap.packet_name = Request.Params["name"].ToString();

                    if (!string.IsNullOrEmpty(Request.Params["element_type"]))
                    {
                        ap.element_type = Convert.ToInt32(Request.Params["element_type"]);
                    }
                    else
                    {
                        ap.element_type = oldap.element_type;
                    }

                    ap.packet_desc = Request.Params["packet_desc"].ToString();

                    ap.show_number = Convert.ToInt32(Request.Params["show_number"]);


                    ap.packet_sort = Convert.ToInt32(Request.Params["packet_sort"].ToString());

                    ap.update_userid = (Session["caller"] as Caller).user_id;
                    ap.packet_updatedate = DateTime.Now;
                    ap.packet_status = oldap.packet_status;
                    int j = _iareaPacketMgr.AreaPacketSave(ap);
                    if (j > 0)
                    {
                        json = "{success:true}";
                    }
                }


            }
            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:true,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public HttpResponseBase SaveProductConsultAnswer()
        {
            string path = Server.MapPath(xmlPath);
            SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path);
            SiteConfig Mail_From = _siteConfigMgr.GetConfigByName("Mail_From");
            SiteConfig Mail_Host = _siteConfigMgr.GetConfigByName("Mail_Host");
            SiteConfig Mail_Port = _siteConfigMgr.GetConfigByName("Mail_Port");
            SiteConfig Mail_UserName = _siteConfigMgr.GetConfigByName("Mail_UserName");
            SiteConfig Mail_UserPasswd = _siteConfigMgr.GetConfigByName("Mail_UserPasswd");
            string EmailFrom = Mail_From.Value;//發件人郵箱
            string SmtpHost = Mail_Host.Value;//smtp服务器
            string SmtpPort = Mail_Port.Value;//smtp服务器端口
            string EmailUserName = Mail_UserName.Value;//郵箱登陸名
            string EmailPassWord = Mail_UserPasswd.Value;//郵箱登陸密碼
            string json = string.Empty;
            string jsonStr = string.Empty;
            ProductConsultQuery query = new ProductConsultQuery();
            IAreaPactetImplMgr _iareaPacketMgr = new AreaPacketMgr(mySqlConnectionString);
            _productconsultMgr = new ProductConsultMgr(mySqlConnectionString);
            try
            {
                if (!string.IsNullOrEmpty(Request.Params["consult_id"]))
                {
                    query.consult_id = Convert.ToInt32(Request.Params["consult_id"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["answer_status"]))
                {
                    if (Convert.ToInt32(Request.Params["answer_status"]) == 2)
                    {
                        query.answer_status = 2;
                        query.answer_user = ((Caller)Session["caller"]).user_id;
                        query.delay_reason = Request.Params["delay_reason"].ToString();
                        _productconsultMgr.UpdateAnswerStatus(query);

                        json = "{success:true}";
                    }
                    
                    else
                    {
                        query.answer_status = 3;
                        if (!string.IsNullOrEmpty(Request.Params["status"]))
                        {
                            query.status = Convert.ToInt32(Request.Params["status"]);
                        }
                        if (!string.IsNullOrEmpty(Request.Params["is_sendEmail"]))
                        {
                            query.is_sendEmail = Convert.ToInt32(Request.Params["is_sendEmail"]);
                        }
                        if (!string.IsNullOrEmpty(Request.Params["consult_answer"]))
                        {
                            query.consult_answer = Request.Params["consult_answer"].ToString();
                        }
                        query.answer_date = DateTime.Now;
                        query.answer_user = ((Caller)Session["caller"]).user_id;
                        int i = _productconsultMgr.SaveProductConsultAnswer(query);
                        if (!string.IsNullOrEmpty(Request.Params["is_sendEmail"]))
                        {
                            int j = Convert.ToInt32(Request.Params["is_sendEmail"]);
                            if (j == 1 && i > 0)
                            {
                                string userName = string.Empty;
                                string product_name = string.Empty;
                                string consultInfo = string.Empty;
                                string answerInfo = string.Empty;
                                string consultUrl = string.Empty;
                                string productUrl = string.Empty;
                                string userEmail = string.Empty;
                                if (!string.IsNullOrEmpty(Request.Params["user_name"]))
                                {
                                    userName = Request.Params["user_name"].ToString();
                                }
                                if (!string.IsNullOrEmpty(Request.Params["user_email"]))
                                {
                                    userEmail = Request.Params["user_email"].ToString();
                                }
                                if (!string.IsNullOrEmpty(Request.Params["consult_info"]))
                                {
                                    consultInfo = Request.Params["consult_info"].ToString();
                                }
                                if (!string.IsNullOrEmpty(Request.Params["consult_answer"]))
                                {
                                    answerInfo = Request.Params["consult_answer"].ToString();
                                }
                                if (!string.IsNullOrEmpty(Request.Params["product_url"]))
                                {
                                    productUrl = Request.Params["product_url"].ToString();
                                }
                                if (!string.IsNullOrEmpty(Request.Params["product_id"]))
                                {
                                    query.product_id = Convert.ToUInt32(Request.Params["product_id"]);
                                }
                                if (!string.IsNullOrEmpty(Request.Params["consult_url"]))
                                {
                                    consultUrl = Request.Params["consult_url"].ToString();
                                }
                                if (!string.IsNullOrEmpty(Request.Params["item_id"]))
                                {
                                    query.item_id = Convert.ToInt32(Request.Params["item_id"].ToString());
                                }

                                ProductConsultQuery queryTemp = _productconsultMgr.GetProductInfo(query);
                                FileStream fs = new FileStream(Server.MapPath("../ImportUserIOExcel/productConsultAnwser.html"), FileMode.OpenOrCreate, FileAccess.Read);
                                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                                string strTemp = sr.ReadToEnd();
                                sr.Close();
                                fs.Close();
                                //if (queryTemp.spec_name1 == "" && queryTemp.spec_name2 == "")
                                //{
                                //    product_name = queryTemp.brand_name + queryTemp.product_name;
                                //}
                                //else
                                //{
                                //    product_name = queryTemp.brand_name + queryTemp.product_name + "(" + queryTemp.spec_name1 + "  " + queryTemp.spec_name2 + ")";
                                //}
                                product_name = queryTemp.product_name;
                                strTemp = strTemp.Replace("{{$username$}}", userName);
                                strTemp = strTemp.Replace("{{$productName$}}", product_name);
                                strTemp = strTemp.Replace("{{$consultInfo$}}", consultInfo);
                                strTemp = strTemp.Replace("{{$consultAnwser$}}", answerInfo);
                                strTemp = strTemp.Replace("{{$productUrl$}}", productUrl);
                                sendmail(EmailFrom, FromName, userEmail, userName, EmailTile, strTemp, "", SmtpHost, Convert.ToInt32(SmtpPort), EmailUserName, EmailPassWord);
                            }
                        }

                        if (i > 0)
                        {
                            json = "{success:true}";
                        }
                    }
                }
            }
            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:true,data:[]}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }