[前言]
先说一下灵感,当你有任务不得不作的时候,就必须有灵感,因此本篇博客的灵感就是怎么用C#语言获取一周的历史数据,并好看的显示在芝麻大的窗体上。
[需求]
1.点击所有已完成:默认显示七天所有完成的番茄
2.点击重要紧急:显示完成的和中断的7天的记录
3.其余同理
4.显示界面(like this)
[逻辑]
UI层:传出当前日期,象限
BLL层:封装数据,调用DAL方法返回给UI
DAL层:连接数据库查找咱们要的数据返回给BLL
图:
[代码]
// 默认显示所有已完成内容
int quadrant = cboPlanlevel.SelectedIndex;
//将信息日期完成和中断,给ImplementEntity保存
T_ImplementEntity enImplement = new T_ImplementEntity();
enImplement.Is_Finish = quadrant;
enImplement.Date = DateTime.Now.ToShortDateString();
//传入BLL层
HistoricalBLL historicalbll = new HistoricalBLL();
List<T_ImplementEntity> finish = new List<T_ImplementEntity>();
finish = historicalbll.InquiaryImplementHistroy(enImplement);
//处理返回的结果,显示查询内容
if (finish.Count == 0)
{
txtHistory.Text = "没有想要的数据!";
txtHistory.SelectionAlignment = HorizontalAlignment.Center;
}
else
{
txtHistory.Text = "";
txtHistory.Text = finish[0].Date.ToString() + " " + "完成了" + finish.Count + "个番茄" + System.Environment.NewLine;
Graphics g = txtHistory.CreateGraphics();
g.DrawLine(new Pen(new SolidBrush(Color.Black)), 10, 20, 80, 20);
this.Invalidate();
for (int i = 0; i < finish.Count; i++)
{
if (finish[i].Date == DateTime.Now.ToShortDateString())
{
Console.WriteLine(txtHistory.Text += finish[i].Tomato_Starttime.ToString() + " - " + finish[i].Tomato_Endtime.ToString() + " " + finish[i].Tomato_Name + System.Environment.NewLine);
}
}
}
//去掉窗体边框后的鼠标拖动事件
Point mouseOff;//鼠标移动位置变量
bool leftFlag;//标签是否为左键
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOff = new Point(-e.X, -e.Y);//获得变量的值
leftFlag = true;
}
}
private void panel1_MouseMove_1(object sender, MouseEventArgs e)
{
if (leftFlag)
{
Point mouseSet = Control.MousePosition;
mouseSet.Offset(mouseOff.X, mouseOff.Y);//设置移动后的位置
Location = mouseSet;
}
}
private void panel1_MouseUp_1(object sender, MouseEventArgs e)
{
if (leftFlag)
{
leftFlag = false;//释放鼠标后标注为false
}
}
[总结]
总结有需求就有解决的办法,而咱们要作的是怎样用简单的办法把事情办得最有效,须要不断学习。