关键字:Reporting Service,Façade,ASP.NET Session
Reporting Service:
以前的项目中用到sqlserver2005下的business studio创建reporting service 报表(*.rdlc),那是单独的报表项目,始终是要集成到应用程序中的,而且那之下创建单独的报表项目其发布和集成并不方便,牵扯到windows权限,数据源更新等问题。
前些天在
codeProject
偶然看到一篇在
asp.net
中创建
rdlc Drill-though
报表并用
ms
的
ReportViewer
服务器控件查看报表的文章,才晓得原来
ms
的报表可以这么方便直接在
web
项目中创建并轻松集成到
asp.net
应用中去,和原来在
vs2003
中的
crystal report
有的一比,个人认为就创建中国式报表(用到
n
多表格),还是
ms
的报表方便,其表格处理方面较
crystal
方便的多,在
cs
代码中操作控制
reportviewer
的报表数据源填充,设置,报表的显示等和
crystal
都差不多,当然个人所用的报表都是一般的报表,并未涉及十分复杂专业的财务报表。
ReportDataSource level1datasource
=
new
ReportDataSource(
"
DrillThroughDataSet_Show_OrderDetails
"
,
Level1DataSet.Tables[
0
]);
localreport.DataSources.Clear();
localreport.DataSources.Add(level1datasource);
localreport.Refresh();
Façade模式下session管理:
文章参见Manage ASP.NET Session with Façade Pattern,直接用字符串作session key值是最不合理的做法,定义字符串常量(const)作为session key值是稍微改进的做法,在ruby中则方便了,用symbol即 ‘:string’,相同的字符串只有个symbol(即使多处定义)。在进一步的改进便是将const字符串定义于单独的static class中,当然最后就是用façade模式了。
Facade Session Sample
public static class MyApplicationSession
{
# region Private Constants
//---------------------------------------------------------------------
private const string userAuthorisation = "UserAuthorisation";
private const string teamManagementState = "TeamManagementState";
private const string startDate = "StartDate";
private const string endDate = "EndDate";
//---------------------------------------------------------------------
# endregion
# region Public Properties
//---------------------------------------------------------------------
/// <summary>
/// The Username is the domain name and username of the current user.
/// </summary>
public static string Username
{
get { return HttpContext.Current.User.Identity.Name; }
}
/// <summary>
/// UserAuthorisation contains the authorisation information for
/// the current user.
/// </summary>
public static UserAuthorisation UserAuthorisation
{
get
{
UserAuthorisation userAuth
= (UserAuthorisation)HttpContext.Current.Session[userAuthorisation];
// Check whether the UserAuthorisation has expired
if (
userAuth == null ||
(userAuth.Created.AddMinutes(
MyApplication.Settings.Caching.AuthorisationCache.CacheExpiryMinutes))
< DateTime.Now
)
{
userAuth = UserAuthorisation.GetUserAuthorisation(Username);
UserAuthorisation = userAuth;
}
return userAuth;
}
private set
{
HttpContext.Current.Session[userAuthorisation] = value;
}
}
/// <summary>
/// TeamManagementState is used to store the current state of the
/// TeamManagement.aspx page.
/// </summary>
public static TeamManagementState TeamManagementState
{
get
{
return (TeamManagementState)HttpContext.Current.Session[teamManagementState];
}
set
{
HttpContext.Current.Session[teamManagementState] = value;
}
}
/// <summary>
/// StartDate is the earliest date used to filter records.
/// </summary>
public static DateTime StartDate
{
get
{
if (HttpContext.Current.Session[startDate] == null)
return DateTime.MinValue;
else
return (DateTime)HttpContext.Current.Session[startDate];
}
set
{
HttpContext.Current.Session[startDate] = value;
}
}
/// <summary>
/// EndDate is the latest date used to filter records.
/// </summary>
public static DateTime EndDate
{
get
{
if (HttpContext.Current.Session[endDate] == null)
return DateTime.MaxValue;
else
return (DateTime)HttpContext.Current.Session[endDate];
}
set
{
HttpContext.Current.Session[endDate] = value;
}
}
//---------------------------------------------------------------------
# endregion
}
另外,看到一篇介绍不用递归取给定串所有指定长度子串的很有新意的算法,这种算法主要就是将所有字串看为和唯一数字一一对应,然后从0遍历到‘指定’大小的数字,并同时将数字转成串,例如既定串为‘abcd’,则子串dac = 4*4!2+1*4!1+2*4!0,即将子串看作既定字符串长度进制的数字,前述dac就等于4('abcd'中第四位)乘以4(进制基数radix=4即既定串的长度)的2(3-1=2)次幂,加......,文章上源码如下:
BruteForce
using System;
using System.Collections;
using System.Text;
namespace Hacking
{
/// <summary>
/// 此实现将charset(串或子串)解释成唯一数字,如"abcd"为串,则 dac = 4*4!2+1*4!1+3*4!0
/// (the fourth element in the array (d=4) times the length of the array (4 chars=4)
/// to the power of the length of the string minus one (3-1=2) (3 chars + the first element of the array timesetc).
/// 采取遍历所有子数字的过程,并于其中将数字转换为对应charset中字符,以实现取子串
/// </summary>
public class Bruteforce : IEnumerable
{
public string charset = "abcdefghijklmnopqrstuvwxyz";//the string we want to permutate
private int _max;
/// <summary>
/// the maximum length of chars of what we want to bruteforce
/// should be more than min
/// </summary>
public int max
{
get { return _max; }
set { _max = value; }
}
private int _min;
/// <summary>
/// the minumum length of chars of what we want to bruteforce
/// should be less than max
/// </summary>
public int min
{
get { return _min; }
set { _min = value; }
}
/// <summary>
/// The GetEnumerator function to make our class Ienumerable
/// </summary>
/// <returns>string x which is the factoradic permutation that corresponds with the enumerator i</returns>
public System.Collections.IEnumerator GetEnumerator()
{
for (int x = min; x <= max; x++)
{
// reset counter when we restart at a length
ulong counter = 0;
//counter that counts from 0 to the length of our array to the power of the length that we bf
while (counter < (ulong)Math.Pow((double)charset.Length, (double)x))
{
string a = factoradic(counter, x - 1);
yield return a;
counter++;
}
}
}
/// <summary>
/// first arg is a number ; second is the (length-1) of the string
/// </summary>
/// <param name="l"></param>
/// <param name="power"></param>
/// <returns>result is the index of the factoradic of length n-1</returns>
private string factoradic(ulong l, int power)
{
StringBuilder sb = new StringBuilder();
sb.Capacity = power + 1;//set the maximum capacity of our stringbuilder object
while (power >= 0)
{
int len = this.charset.Length;//
ulong q = l / (ulong)Math.Pow((double)len, (double)power);
ulong m = l % (ulong)Math.Pow((double)len, (double)power);
sb = sb.Append(this.charset[(int)q]);
l = m;
power--;
}
return sb.ToString();
}
}
}
测试示例
using System;
using System.Collections.Generic;
using System.Text;
using Hacking;
namespace example
{
class Program
{
static void Main(string[] args)
{
Bruteforce b = new Bruteforce();
b.min = 2;
b.max = 4;
b.charset = "abcdefghijklmnopqrstuvwxyz0123456789";
string target= "abc1";
foreach (string result in b)
{
Console.Write(result +"\r");
if (result == target)
{
Console.WriteLine("target found:" + result);
return;
}
}
}
}
}