状态点与具体时间之间的处理
本帖最后由 wuzj8839 于 2013-01-26 21:22:31 编辑 有一个问题问一下大家。程序中要定义一个时间,它要求是可以状态点:比方说“会后10天”,“会后20天”等,也可以是具体的时间。我现在是这样处理的,定义几个时间点对应着这几个状态点,然后作为时间格式存在数据库中。那就是在取出来的时候,翻译成对应的状态点,具体时间就显示时间。数据量大了后,几千条同时读取就会很慢。
然后再datagridview中显示。
方法如下
from o in data.Select_gztj_By室(n, m + 1)
select new TJ()
{
gztj = o,
计划时间 = B.ToTime(o.计划时间),
入库时间 = B.ToTime(o.入库时间)
};
public class TJ
{
public TJ()
{
}
public TJ(工作统计 gz)
{
this.gztj = gz;
this.计划时间 = B.ToTime(gz.计划时间);
this.入库时间 = B.ToTime((DateTime)gz.入库时间);
}
public 工作统计 gztj { get; set; }
public string 计划时间 { get; set; }
public string 入库时间 { get; set; }
public bool 选择 { get; set; }
}
public string ToTime(DateTime dt)
{
try
{
if (!dt.Equals(null))
{
DateTime yu = new DateTime(2000, 1, 1);
if (dt.CompareTo(yu) > 0)
{
int y, m, r;
string mm, rr, s;
y = dt.Year;
m = dt.Month;
r = dt.Day;
if (m < 10)
mm = string.Format("0{0}", m);
else
mm = m.ToString();
if (r < 10)
rr = string.Format("0{0}", r);
else
rr = r.ToString();
s = string.Format("{0}-{1}-{2}", y, mm, rr);
return s;
}
else
{
return Dictionary.sj[dt];
}
}
else
{
return "";
}
}
catch
{
return "";
}
}
public static Dictionary<DateTime, string> sj = new Dictionary<DateTime, string>();
public List<TJ> ju(IEnumerable<工作统计> a)
{
List<TJ> q = new List<TJ>();
foreach (var o in a)
{
q.Add(new TJ(o));
}
return q;
}