示例#1
0
        public static List<Location> List(int levelId = 0)
        {
            List<Location> list = new List<Location>();

            using (SqlCommand cmd = new SqlCommand()
            {
                CommandType = CommandType.Text,
                CommandText =
                    "select l.*, v.Name Name2 from Location l inner join Level v on v.LevelId=l.LevelId " +
                    "where @levelId=0 or l.LevelId=@levelId order by v.Name, l.Name;",
            })
            {
                cmd.Parameters.AddWithValue("@levelId", levelId);
                cmd.ExecuteReaderExt((r) =>
                {
                    Location loc = new Location();
                    loc._initFromRow(r);
                    string name2 = r.StringOrBlank("Name2").Trim();
                    loc.Name = string.Format("{0} : {1}",
                        name2 == "" ? string.Format("Level {0}", loc.LevelId) : name2,
                        loc.Name
                        );
                    list.Add(loc);
                    return true;
                });
            }

            return list;
        }
示例#2
0
        public override async Task ProcessRequestAsync(HttpContext context)
		{
			HttpRequest request = context.Request;
			HttpResponse response = context.Response;

            int frameId = request.IntOrZero("frame");
            int panelId = request.IntOrZero("panel");
            int displayId = request.IntOrZero("display");
            string culture = request.StringOrBlank("culture");

			string json = "";
				
			try
			{
                // set culture
                Powerbi powerbi = new Powerbi(frameId);
                Location location = new Location(displayId);

                if (string.IsNullOrWhiteSpace(culture))
                    culture = location.Culture;
                
                if (!string.IsNullOrWhiteSpace(culture))
                {
                    System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo(culture);
                    System.Threading.Thread.CurrentThread.CurrentCulture = cultureInfo;
                    System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo;
                }

                JavaScriptSerializer jss = new JavaScriptSerializer();
                json = jss.Serialize(new
                {
                    accessToken = await powerbi.GetAccessTokenAsync(),
                });
			}

            catch (Exception ex)
			{
                JavaScriptSerializer s = new JavaScriptSerializer();
                json = s.Serialize(new
                {
                    Error = ex.Message,
                    //Stack = ex.StackTrace,
                    Data = new
                    {
                        FrameId = frameId,
                        PanelId = panelId,
                        DisplayId = displayId,
                        Culture = culture,
                        Details = ex.GetType() == typeof(AzureTokenException) ? (ex as AzureTokenException).Details : null,
                    },
                });
			}

            response.Clear();
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.Cache.SetSlidingExpiration(true);
            response.Cache.SetNoStore();
            response.ContentType = "application/json";
			response.Write(json);
            response.Flush();
        }
示例#3
0
		public static List<Location> List(int levelId = 0)
		{
			List<Location> list = new List<Location>();
			string sql = string.Format(
				"select l.*, v.Name Name2 from Location l inner join Level v on v.LevelId=l.LevelId " +
                "WHERE {0}=0 or l.LevelId={0} order by v.Name, l.Name;",
				levelId
				);
			using (DataSet ds = DataAccess.RunSql(sql))
			{
				list.Capacity = ds.Tables[0].Rows.Count;

				// list level locations
				foreach (DataRow r in ds.Tables[0].Rows)
				{
					Location loc = new Location();
					loc._initFromRow(r);
                    string name2 = r.StringOrBlank("Name2").Trim();
                    loc.Name = string.Format("{0} : {1}",
                        name2 == "" ? string.Format("Level {0}", loc.LevelId) : name2,
                        loc.Name
                        );
                    list.Add(loc);
				}
			}
			return list;
		}