public JsonResult UpdateActiveMarketCategory()
        {
            try
            {
                int id = Convert.ToInt32(Request.Params["id"] ?? "0");
                int activeValue = Convert.ToInt32(Request.Params["active"] ?? "0");
                _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
                MarketCategory model = _marketCategoryMgr.GetMarketCategoryList(new MarketCategory { market_category_id = Convert.ToUInt32(id) }).FirstOrDefault();
                model.market_category_status = activeValue;
                model.muser = (Session["caller"] as Caller).user_id;
                model.modified = DateTime.Now;
                if (_marketCategoryMgr.UpdateMarketCategory(model) > 0)
                {
                    return Json(new { success = "true" });
                }
                else
                {
                    return Json(new { success = "false" });
                }
            }
            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" });
            }

        }
        public HttpResponseBase ImportMarketCategory()
        {
            int j = 0;
            string json = string.Empty;//json字符串

            try
            {
                if (Request.Files["ImportFileMsg"] != null && Request.Files["ImportFileMsg"].ContentLength > 0)//判斷文件是否為空
                {
                    HttpPostedFileBase excelFile = Request.Files["ImportFileMsg"];//獲取文件流
                    FileManagement fileManagement = new FileManagement();//實例化 FileManagement
                    string fileLastName = excelFile.FileName;
                    string newExcelName = Server.MapPath(excelPath) + "MarketCategory" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名
                    excelFile.SaveAs(newExcelName);//上傳文件
                    DataTable dt = new DataTable();
                    NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName);
                    dt = helper.SheetData();
                    DataRow[] dr = dt.Select("market_category <> ''"); //定义一个DataRow数组,读取ds里面所有行
                    int rowsnum = dt.Rows.Count;

                    if (rowsnum == 0)
                    {
                        json = "{success:false,msg:0}";//此表內沒有數據或數據有誤,請檢查后再次匯入!
                        this.Response.Clear();
                        this.Response.Write(json);
                        this.Response.End();
                        return this.Response;
                    }
                    else
                    {

                        _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
                        j = _marketCategoryMgr.MarketCategoryImport(dr);
                        if (j > 0)
                        {
                            json = "{success:true,msg:1}";//操作成功共匯入total條數據
                        }
                        else
                        {
                            json = "{success:false,msg:2}";//匯入失敗,請檢查是否重複匯入!
                        }

                    }
                }
                else//當直接點擊時會產生,
                {
                    json = "{success:true,msg:3}";//未找到該文件
                    this.Response.Clear();
                    this.Response.Write(json);
                    this.Response.End();
                    return this.Response;

                }
            }
            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,msg:\"" + ex.ToString() + "\"}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetMarketCategoryCount()
        {
            string jsonStr = String.Empty;
            _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
            if (!String.IsNullOrEmpty(Request.Params["code"]))
            {
                try
                {
                    List<MarketCategoryQuery> store = _marketCategoryMgr.GetMarketCategoryList(new MarketCategory { market_category_code = Request.Params["code"].ToString() });
                    jsonStr = "{success:true,count:" + store.Count + "}";
                }
                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}";
                }
            }

            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase DeleteMarketCategory()
        {
            string jsonStr = String.Empty;
            _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
            if (!String.IsNullOrEmpty(Request.Params["rowID"]))
            {
                try
                {
                    bool isBool = true;
                    foreach (string item in Request.Params["rowID"].Split('|'))
                    {
                        if (!string.IsNullOrEmpty(item))
                        {
                            List<MarketCategoryQuery> store = _marketCategoryMgr.GetMarketCategoryList(new MarketCategory { market_category_father_id = Convert.ToInt32(item) });
                            if (store.Count > 0)
                            {
                                isBool = false;
                                break;
                            }
                        }
                    }
                    if (isBool)
                    {
                        if (_marketCategoryMgr.DeleteMarketCategory(Request.Params["rowID"].ToString()) > 0)
                        {
                            jsonStr = "{success:true,msg:0}";
                        }
                        else
                    {
                            jsonStr = "{success:false,msg:0}";
                    }
                    }
                    else
                    {
                        jsonStr = "{success:true,msg:1}";//妄圖刪除父類別,該斬!
                    }

                }
                catch (Exception ex)
                {
                    Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                    logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                    logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                    log.Error(logMessage);
                    jsonStr = "{success:false}";
                }
            }

            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase SaveMarketCategory()
        {

            string json = string.Empty;
            try
            {
                _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
                MarketCategory query = new MarketCategory();
                // MarketCategoryQuery model = new MarketCategoryQuery();
                if (!string.IsNullOrEmpty(Request.Params["market_category_id"]))
                {
                    query.market_category_id = Convert.ToUInt32(Request.Params["market_category_id"]);
                    //model = _marketCategoryMgr.GetMarketCategoryList(query).FirstOrDefault();
                }

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

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

                if (!string.IsNullOrEmpty(Request.Params["market_category_name"]))
                {
                    query.market_category_name = Request.Params["market_category_name"].ToString();
                }
                if (!string.IsNullOrEmpty(Request.Params["market_category_sort"]))
                {
                    query.market_category_sort = Convert.ToInt32(Request.Params["market_category_sort"]);
                }
                if (!string.IsNullOrEmpty(Request.Params["market_category_status"]))
                {
                    query.market_category_status = Convert.ToInt32(Request.Params["market_category_status"]);
                }



                int result = 0;
                if (query.market_category_id == 0)//新增
                {
                    query.kuser = (Session["caller"] as Caller).user_id;
                    query.muser = query.kuser;
                    query.created = DateTime.Now;
                    query.modified = query.created;
                    result = _marketCategoryMgr.InsertMarketCategory(query);

                }
                else//修改 
                {
                    query.muser = (Session["caller"] as Caller).user_id;
                    query.modified = DateTime.Now;
                    result = _marketCategoryMgr.UpdateMarketCategory(query);
                }
                if (result > 0)
                {
                    json = "{success:true}";
                }
                else
                {
                    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}";
            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }
        /// <summary>
        /// 獲取上一層父類別編號
        /// </summary>
        /// <returns>數據庫操作結果</returns>
        public JsonResult GetLastFatherId()
        {
            string jsonStr = string.Empty;
            try
            {
                MarketCategoryQuery model = new MarketCategoryQuery();

                if (!string.IsNullOrEmpty(Request.Params["fid"]))
                {
                    model.market_category_id = Convert.ToUInt32(Request.Params["fid"].ToString());
                }
                _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
                MarketCategoryQuery store = _marketCategoryMgr.GetMarketCategoryList(model).FirstOrDefault();

                return Json(new { success = "true", result = store.market_category_father_id, fatherName = store.market_category_father_name });
            }
            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" });
            }

        }
        public HttpResponseBase GetMarketCategoryList()
        {
            string jsonStr = string.Empty;
            int tranInt = 0;
            try
            {
                MarketCategoryQuery query = new MarketCategoryQuery();
                query.Start = Convert.ToInt32(Request.Params["start"] ?? "0");
                query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "0");

                query.market_category_father_id = Convert.ToInt32(Request.Params["father_id"] ?? "0");

                if (!string.IsNullOrEmpty(Request.Params["search"]))
                {
                    if (int.TryParse(Request.Params["search"].ToString(), out tranInt))
                    {
                        query.market_category_code = Request.Params["search"].ToString();
                    }
                    else
                    {
                        query.market_category_name = Request.Params["search"].ToString();
                    }
                }
                int totalCount = 0;
                _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);

                List<MarketCategoryQuery> store = _marketCategoryMgr.GetMarketCategoryList(query, out totalCount);

                IsoDateTimeConverter timeConverter = new IsoDateTimeConverter();
                //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式     
                timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
                jsonStr = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(store, 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);
                jsonStr = "{success:false}";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr.ToString());
            this.Response.End();
            return this.Response;
        }
        public HttpResponseBase GetFrontCatagory()
        {
            //Response.Cache.SetOmitVaryStar(true);
            List<MarketCategoryQuery> categoryList = new List<MarketCategoryQuery>();
            List<ProductCategoryCustom> cateList = new List<ProductCategoryCustom>();
            string resultStr = "";
            try
            {
                _marketCategoryMgr = new MarketCategoryMgr(mySqlConnectionString);
                MarketCategory category = new MarketCategory();
                category.IsPage = false;
                categoryList = _marketCategoryMgr.GetMarketCategoryList(category);//查詢美安的所有節點
                cateList = getCate(categoryList, 0);
                GetFrontCateList(categoryList, ref cateList);

                resultStr = JsonConvert.SerializeObject(cateList);

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

            this.Response.Clear();
            this.Response.Write(resultStr);
            this.Response.End();
            return this.Response;
        }