public JsonResult GetFunction()
        {
            List<Function> functions = new List<Function>();
            try
            {
                int typeId = 1;
                Int32.TryParse(Request.Form["Type"] ?? "-1", out typeId);
                Function function = new Function { FunctionType = typeId };
                if (!string.IsNullOrEmpty(Request.Form["TopValue"]))
                {
                    function.TopValue = Convert.ToInt32(Request.Form["TopValue"]);
                }

                functionMgr = new FunctionMgr(connectionString);
                functions = functionMgr.Query(function);
            }
            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(functions);
        }
 public JsonResult GetGroup()
 {
     try
     {
         functionMgr = new FunctionMgr(connectionString);
         List<Function> functions = functionMgr.Query(new Function { FunctionType = 1 });
         var groups = from f in functions
                      group f by f.FunctionGroup into c
                      select new { FunctionGroup = c.Key };
         return Json(groups);
     }
     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("[]");
     }
 }
        public HttpResponseBase GetFgroupAuthority(int type=1)
        {
            string json = string.Empty;
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["RowId"]))
                {
                    //所有模組、按鈕
                    functionMgr = new FunctionMgr(connectionString);
                    List<Function> all = functionMgr.Query(new Function(), type, Convert.ToInt32(Request.Form["RowId"]));

                    //該組別擁有權限的模組、按鈕
                    functionGroupMgr = new FunctionGroupMgr(connectionString);
                    AuthorityQuery query = new AuthorityQuery { GroupId = Convert.ToInt32(Request.Form["RowId"]) };
                    List<Function> functions = functionGroupMgr.GroupAuthorityQuery(query, type);
                    //所有模組
                    var groups = from f in all
                                 where f.FunctionType == 1
                                 group f by f.FunctionGroup into fgroup
                                 select new { Fgroup = fgroup.Key };
                    //所有頁面
                    var pages = from f in all
                               where f.FunctionType!=2
                               select f;
                    //所有按鈕
                    var tools = from f in all
                               where f.FunctionType == 2
                               select f;
                    StringBuilder strJson = new StringBuilder("[");
                    foreach (var g in groups)
                    {
                        strJson.Append("{FunctionGroup:\"" + g.Fgroup + "\",items:[");
                        foreach (var p in pages.Where(m=>m.FunctionGroup==g.Fgroup))
                        {
                            bool isAuth = functions.Where(m => m.RowId == p.RowId).Count() > 0;
                            strJson.Append("{RowId:" + p.RowId + ",Name:\"" + p.FunctionName + "\",checked:\"" + isAuth + "\",tools:[");
                            foreach (var t in tools.Where(m=>m.TopValue==p.RowId))
                            {
                                isAuth = functions.Where(m => m.RowId == t.RowId).Count() > 0;
                                strJson.Append("{RowId:" + t.RowId + ",Name:\"" + t.FunctionName + "\",checked:\"" + isAuth + "\"}");
                            }
                            strJson.Append("]}");
                        }
                        strJson.Append("]}");
                    }
                    strJson.Append("]");
                    json = strJson.ToString().Replace("}{", "},{");
                }
            }
            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(json);
            this.Response.End();
            return this.Response;
        }
        public JsonResult GetAuthorityToolByUrl()
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.Form["Url"]))
                {
                    functionMgr = new FunctionMgr(connectionString);
                    Function fun = functionMgr.Query(new Function { FunctionCode = Request.Form["Url"] }).FirstOrDefault();
                    if (fun != null)
                    {
                        string callId = (Session["caller"] as Caller).user_email;
                        AuthorityQuery query = new AuthorityQuery { Type = 2, CallId = callId };

                        query.RowId = fun.RowId;
                        functionGroupMgr = new FunctionGroupMgr(connectionString);
                        List<Function> functions = functionGroupMgr.CallerAuthorityQuery(query);
                        var result = from f in functions
                                     select new { id = f.FunctionCode, isEdit = f.UEdit };
                        return Json(result);
                    }
                }

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