Commit befdafda kwwwvagaa

日历备忘测试代码增加单次、每天、每周、每月、每年的备忘要如何结合控件使用

1 个父辈 88186024
......@@ -303,7 +303,10 @@ namespace HZH_Controls.Controls
if (item.Value.Contains(e.Location))
{
if (AddClick != null)
{
AddClick(DateTime.Parse(CurrentTime.ToString("yyyy-MM-dd") + " " + item.Key + ":00:00"));
panMain.Invalidate();
}
return;
}
}
......@@ -358,7 +361,10 @@ namespace HZH_Controls.Controls
private void lblAdd_Click(object sender, EventArgs e)
{
if (AddClick != null)
{
AddClick(DateTime.Parse(CurrentTime.ToString("yyyy-MM-dd")));
panMain.Invalidate();
}
}
}
}
......@@ -28,23 +28,10 @@
/// </summary>
private void InitializeComponent()
{
this.ucCalendarNotes_Week1 = new HZH_Controls.Controls.UCCalendarNotes_Week();
this.ucCalendarNotes1 = new HZH_Controls.Controls.UCCalendarNotes();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// ucCalendarNotes_Week1
//
this.ucCalendarNotes_Week1.BackColor = System.Drawing.Color.White;
this.ucCalendarNotes_Week1.CurrentTime = new System.DateTime(2020, 8, 13, 22, 14, 47, 0);
this.ucCalendarNotes_Week1.DataSource = null;
this.ucCalendarNotes_Week1.Location = new System.Drawing.Point(530, 43);
this.ucCalendarNotes_Week1.Name = "ucCalendarNotes_Week1";
this.ucCalendarNotes_Week1.ShowCloseButton = true;
this.ucCalendarNotes_Week1.Size = new System.Drawing.Size(490, 405);
this.ucCalendarNotes_Week1.SplitLineColor = System.Drawing.Color.FromArgb(((int)(((byte)(153)))), ((int)(((byte)(153)))), ((int)(((byte)(153)))));
this.ucCalendarNotes_Week1.SplitTimeForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(153)))), ((int)(((byte)(153)))), ((int)(((byte)(153)))));
this.ucCalendarNotes_Week1.TabIndex = 3;
//
// ucCalendarNotes1
//
this.ucCalendarNotes1.BackColor = System.Drawing.Color.White;
......@@ -57,21 +44,32 @@
this.ucCalendarNotes1.TabIndex = 2;
this.ucCalendarNotes1.TipColor = System.Drawing.Color.Green;
this.ucCalendarNotes1.ClickNote += new HZH_Controls.Controls.UCCalendarNotes.ClickNoteEvent(this.ucCalendarNotes1_ClickNote);
this.ucCalendarNotes1.AddClick += new HZH_Controls.Controls.UCCalendarNotes_Week.AddNoteEvent(this.ucCalendarNotes1_AddClick);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(26, 428);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(287, 12);
this.label1.TabIndex = 3;
this.label1.Text = "*测试模拟一次、每天、每周、每月、每年的计划处理\r\n";
//
// UCTestCalendarNotes
//
this.Controls.Add(this.ucCalendarNotes_Week1);
this.Controls.Add(this.label1);
this.Controls.Add(this.ucCalendarNotes1);
this.Name = "UCTestCalendarNotes";
this.Size = new System.Drawing.Size(1076, 620);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private HZH_Controls.Controls.UCCalendarNotes ucCalendarNotes1;
private HZH_Controls.Controls.UCCalendarNotes_Week ucCalendarNotes_Week1;
private System.Windows.Forms.Label label1;
}
}
......@@ -12,24 +12,154 @@ namespace Test.UC
{
public partial class UCTestCalendarNotes : UserControl
{
List<NoteEntity> dataSource = new List<NoteEntity>();
public UCTestCalendarNotes()
{
InitializeComponent();
List<NoteEntity> dataSource = new List<NoteEntity>();
dataSource.Add(new NoteEntity() { Key = "1", BeginTime = DateTime.Now, Title = "aaaa", Note = "agaweas" });
dataSource.Add(new NoteEntity() { Key = "1", BeginTime = DateTime.Now, EndTime = DateTime.Now.AddHours(1), Title = "bbbb", Note = "bbbbdfasdfg" });
dataSource.Add(new NoteEntity() { Key = "1", BeginTime = DateTime.Now.AddHours(-3), EndTime = DateTime.Now.AddHours(-1), Title = "ccc", Note = "bbbbdfasdfg" });
dataSource.Add(new NoteEntity() { Key = "1", BeginTime = DateTime.Now.AddDays(-1), EndTime = DateTime.Now, Title = "ddd", Note = "bbbbdfasdfg" });
this.ucCalendarNotes1.CurrentTime = DateTime.Now;
List<TestEntity> lstDB = LoadData();
dataSource = GetShowData(lstDB);
this.ucCalendarNotes1.DataSource = dataSource;
this.ucCalendarNotes_Week1.DataSource = dataSource;
this.ucCalendarNotes_Week1.CurrentTime = DateTime.Now;
}
//这个相当于数据库数据
List<TestEntity> DBSource = new List<TestEntity>();
//从数据库读取数据
private List<TestEntity> LoadData()
{
if (DBSource.Count <= 0)
{
DBSource.Add(new TestEntity() { ID = 1, Title = "一次循环测试1", Msg = "一次循环测试1内容", LoopType = 0, BeginDateTime = DateTime.Now.AddDays(-1), EndDateTime = DateTime.Now });
DBSource.Add(new TestEntity() { ID = 2, Title = "一次循环测试2", Msg = "一次循环测试2内容", LoopType = 0, BeginDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddHours(2) });
DBSource.Add(new TestEntity() { ID = 3, Title = "每天循环测试1", Msg = "一次循环测试1内容", LoopType = 1, BeginDateTime = DateTime.Now.AddDays(-5), EndDateTime = DateTime.Now, LoopBeginTime = DateTime.Parse("2000-02-02 " + "05:05:05"), LoopDuration = new TimeSpan(1, 1, 1) });
DBSource.Add(new TestEntity() { ID = 4, Title = "每天循环测试2", Msg = "一次循环测试2内容", LoopType = 1, BeginDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddDays(5), LoopBeginTime = DateTime.Parse("2000-02-02 " + "10:05:05"), LoopDuration = new TimeSpan(1, 1, 1) });
DBSource.Add(new TestEntity() { ID = 5, Title = "每周循环测试1", Msg = "一次循环测试1内容", LoopType = 2, BeginDateTime = DateTime.Now.AddDays(-5), EndDateTime = DateTime.Now, LoopBeginTime = DateTime.Parse("2000-02-02 " + "05:05:05"), LoopDuration = new TimeSpan(30, 1, 1), LoopDayIndex = 1 });
DBSource.Add(new TestEntity() { ID = 6, Title = "每周循环测试2", Msg = "一次循环测试2内容", LoopType = 2, BeginDateTime = DateTime.Now, EndDateTime = DateTime.Now.AddDays(5), LoopBeginTime = DateTime.Parse("2000-02-02 " + "10:05:05"), LoopDuration = new TimeSpan(10, 1, 1), LoopDayIndex = 2 });
//每月、每年的和每周类似
}
return DBSource;
}
private List<NoteEntity> GetShowData(List<TestEntity> dbSource)
{
List<NoteEntity> lst = new List<NoteEntity>();
foreach (var item in dbSource)
{
if (item.LoopType == 0)
{
lst.Add(new NoteEntity() { Title = item.Title, Note = item.Msg, BeginTime = item.BeginDateTime, EndTime = item.EndDateTime, DataSource = item });
}
else if (item.LoopType == 1)
{
DateTime thisDt = item.BeginDateTime;
while (thisDt <= item.EndDateTime)
{
DateTime noteBeginTime = DateTime.Parse(thisDt.ToString("yyyy-MM-dd") + " " + item.LoopBeginTime.ToString("HH:mm:ss"));
DateTime noteEndTime = noteBeginTime.Add(item.LoopDuration);
if (noteBeginTime >= item.BeginDateTime && noteEndTime < item.EndDateTime)//当天的计划 是否在整个计划范围时间内
{
lst.Add(new NoteEntity() { Title = item.Title, Note = item.Msg, BeginTime = noteBeginTime, EndTime = noteEndTime, DataSource = item });
}
thisDt = thisDt.AddDays(1);
}
}
else if (item.LoopType == 2)
{
DateTime thisDt = item.BeginDateTime;
int thisWeek = (int)item.BeginDateTime.DayOfWeek;
if (thisWeek < item.LoopDayIndex)
{
thisDt = item.BeginDateTime.AddDays(item.LoopDayIndex - thisWeek);
}
else if (thisWeek > item.LoopDayIndex)
{
thisDt = item.BeginDateTime.AddDays(item.LoopDayIndex - thisWeek + 7);
}
thisDt = DateTime.Parse(thisDt.ToString("yyyy-MM-dd"));
while (thisDt <= item.EndDateTime)
{
DateTime noteBeginTime = DateTime.Parse(thisDt.ToString("yyyy-MM-dd") + " " + item.LoopBeginTime.ToString("HH:mm:ss"));
DateTime noteEndTime = noteBeginTime.Add(item.LoopDuration);
if (noteBeginTime >= item.BeginDateTime && noteEndTime < item.EndDateTime)//是否在整个计划范围时间内
{
lst.Add(new NoteEntity() { Title = item.Title, Note = item.Msg, BeginTime = noteBeginTime, EndTime = noteEndTime, DataSource = item });
}
thisDt = thisDt.AddDays(7);
}
}
//月,年类似周
}
return lst;
}
private bool ucCalendarNotes1_ClickNote(NoteEntity note)
{
MessageBox.Show("点击了备忘【"+note.Title+"】,你可以在这里对备忘编辑,修改,如果要修改,请返回true,否则返回false,如果要删除,删除后重新赋值ucCalendarNotes控件DataSource属性");
return default(bool);
TestEntity entity = (TestEntity)note.DataSource;
//对entity进行修改、删除操作
entity.Title += "修改1次;";
//加载数据
List<TestEntity> lstDB = LoadData();
//获取控件绑定数据
dataSource = GetShowData(lstDB);
this.ucCalendarNotes1.DataSource = dataSource;
MessageBox.Show("修改成功");
return true;
}
private void ucCalendarNotes1_AddClick(DateTime beginTime)
{
//弹出一个新增窗体,新增数据
//这一条模拟新增
DBSource.Add(new TestEntity() { ID = 111, Title = "每周循环测试111", Msg = "一次循环测试1内容", LoopType = 2, BeginDateTime = beginTime, EndDateTime = DateTime.Now.AddDays(20), LoopBeginTime = DateTime.Parse("2000-02-02 " + "01:05:05"), LoopDuration = new TimeSpan(5, 1, 1), LoopDayIndex = (int)beginTime.DayOfWeek });
//加载数据
List<TestEntity> lstDB = LoadData();
//获取控件绑定数据
dataSource = GetShowData(lstDB);
this.ucCalendarNotes1.DataSource = dataSource;
MessageBox.Show("添加成功");
}
}
public class TestEntity
{
public int ID { get; set; }
public string Title { get; set; }
public string Msg { get; set; }
/// <summary>
/// 0:一次 1:每天 2:每周 3:每月 4:每年
/// </summary>
public int LoopType { get; set; }
/// <summary>
/// 整个计划开始时间
/// </summary>
public DateTime BeginDateTime { get; set; }
/// <summary>
/// 整个计划结束时间
/// </summary>
public DateTime EndDateTime { get; set; }
/// <summary>
/// 每次循环开始时间,取时分秒部分
/// </summary>
public DateTime LoopBeginTime { get; set; }
/// <summary>
/// 每次循环时长,每天循环,次参数无效,
/// </summary>
public TimeSpan LoopDuration { get; set; }
/// <summary>
/// 每次循环的日期索引,
/// 每天循环,次参数无效,
/// 每周:星期几索引,周日=0...周六=6
/// 每月:天索引
/// 每年:天索引
/// </summary>
public int LoopDayIndex { get; set; }
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!