private void timerRefresh_Tick(object sender, EventArgs e) { DEvents DEvsToday = null; foreach (var evs in EData.EventList.EventList) { if (evs.Date == dateTimePicker1.Value) { DEvsToday = evs; } } //selected rows if (DEvsToday == null) { return; } if (dataGridViewEvent.CurrentRow != null) { dataGridViewEvent.CurrentRow.Selected = false; } int count = 0; foreach (var ev in DEvsToday.Items) { int i = 0; foreach (DataGridViewRow itr in dataGridViewEvent.Rows) { string name = (itr.Cells[0].Value == null) ? "" : itr.Cells[0].Value.ToString(); string evName = ev.Content; if (name == evName) { count++; dataGridViewEvent.Rows[i].Selected = true; } i++; } } dataGridViewEvent.Refresh(); ((Timer)sender).Enabled = false; }
private void LoadCurEvents() { LoadCurEventList(); CurDEvents = new DEvents(); CurDEvents.Date = dateTimePicker1.Value.Date; NextDEvents = new DEvents(); NextDEvents.Date = dateTimePicker1.Value.AddDays(1).Date; foreach (var evs in EData.EventList.EventList) { if (evs.Date == dateTimePicker1.Value.Date) { CurDEvents = evs; } else if (evs.Date == dateTimePicker1.Value.AddDays(1).Date) { NextDEvents = evs; } } LoadListDEvent(CurDEvents.Plans, dataGridViewCurPlan); LoadListDEvent(CurDEvents.Items, dataGridViewCurResult); LoadListDEvent(NextDEvents.Plans, dataGridViewNextPlan); }
private void SaveListDEvent(List <DEvent> ListDEvent, DataGridView DGV) { DEvents CurEvs = new DEvents(); DEvents PreEvs = null; foreach (var evs in EData.EventList.EventList) { if (evs.Date == dateTimePicker1.Value.Date) { CurEvs = evs; PreEvs = new DEvents(); PreEvs.Date = evs.Date; foreach (DEvent itr in evs.Items) { PreEvs.Items.Add(itr); } break; } } CurEvs.Date = dateTimePicker1.Value; CurEvs.Items.Clear(); for (int i = 0; i < dataGridViewEvent.SelectedRows.Count; i++) { string eventName = dataGridViewEvent.SelectedRows[i].Cells[0].Value.ToString(); // EventData in DataSource DEvent ev = null; foreach (var itr in CurEvents) { if (itr.Content == eventName) { //ev = itr; ev = new DEvent(itr.Content, itr.Duration, itr.StartTime, itr.EndTime); if (ev.StartTime > dateTimePicker1.Value || ev.StartTime == null || ev.StartTime == DateTime.MinValue) { ev.StartTime = dateTimePicker1.Value; } if (ev.EndTime < dateTimePicker1.Value || ev.EndTime == null || ev.EndTime == DateTime.MinValue) { ev.EndTime = dateTimePicker1.Value; } break; } } if (ev == null) { continue; } // EventData in xml DEvent PreEv = null; if (PreEvs != null) { foreach (var itr in PreEvs.Items) { if (itr.Content == eventName) { PreEv = itr; break; } } } if (PreEv == null) { if (ev.StartTime > dateTimePicker1.Value || ev.StartTime == null || ev.StartTime == DateTime.MinValue) { ev.StartTime = dateTimePicker1.Value; } if (ev.EndTime < dateTimePicker1.Value || ev.EndTime == null || ev.EndTime == DateTime.MinValue) { ev.EndTime = dateTimePicker1.Value; } ev.Duration += 1; } CurEvs.Items.Add(ev); } if (PreEvs == null) { int curDiaryIndex = EData.EventList.EventList.Count; for (int i = 0; i < EData.EventList.EventList.Count; i++) { if (dateTimePicker1.Value < EData.EventList.EventList[i].Date) { curDiaryIndex = i; break; } } EData.EventList.EventList.Insert(curDiaryIndex, CurEvs); } EData.Save(EData.EventList); }
// --- Event --- private void SaveEvent() { //if (CheckVaildEvent() == false) //{ // return; //} DEvents CurDEvs = null; DEvents NextDEvs = null; foreach (var evs in EData.EventList.EventList) { if (evs.Date == dateTimePicker1.Value.Date) { CurDEvs = evs; } else if (evs.Date == dateTimePicker1.Value.AddDays(1).Date) { NextDEvs = evs; } } if (CurDEvs == null) { int curDiaryIndex = EData.EventList.EventList.Count; for (int i = 0; i < EData.EventList.EventList.Count; i++) { if (dateTimePicker1.Value < EData.EventList.EventList[i].Date) { curDiaryIndex = i; break; } } EData.EventList.EventList.Insert(curDiaryIndex, CurDEvents); } if (NextDEvs == null) { int nextDiaryIndex = EData.EventList.EventList.Count; for (int i = 0; i < EData.EventList.EventList.Count; i++) { if (dateTimePicker1.Value.AddDays(1).Date < EData.EventList.EventList[i].Date) { nextDiaryIndex = i; break; } } EData.EventList.EventList.Insert(nextDiaryIndex, NextDEvents); } foreach (var ev in CurDEvents.Items) { if (ev.Status != "") { int statusCode = Convert.ToInt32(DConvert.ToDoble(ev.Status)); switch (statusCode) { case -1: ev.Status = "放弃"; break; case 0: break; case 1: ev.Status = "完成"; break; default: ev.Status = statusCode.ToString() + "%"; break; } } } EData.Save(EData.EventList); //SaveListDEvent(CurDEvents.Plans, dataGridViewCurPlan); //SaveListDEvent(CurDEvents.Items, dataGridViewCurResult); //SaveListDEvent(NextDEvents.Plans, dataGridViewNextPlan); LoadCurEvents(); //dataGridViewEvent.Sort(dataGridViewEvent.Columns[3], ListSortDirection.Ascending); //FormClearEvent(); }
private void LoadCurEventList() { CurEvents.Clear(); DEvents DEvsToday = null; foreach (var evs in EData.EventList.EventList) { if (evs.Date >= new DateTime(dateTimePicker1.Value.Year, dateTimePicker1.Value.Month, 1) && evs.Date <= dateTimePicker1.Value) { foreach (DEvent ev in evs.Items) { bool exist = false; foreach (DEvent curEv in CurEvents) { if (curEv.Content == ev.Content) { ev.Duration = curEv.Duration + 1; if (string.IsNullOrEmpty(ev.Status) && !string.IsNullOrEmpty(curEv.Status)) { ev.Status = curEv.Status; } CurEvents.Remove(curEv); CurEvents.Insert(0, ev); exist = true; break; } } if (!exist) { ev.Duration = 1; CurEvents.Insert(0, ev); } } } if (evs.Date == dateTimePicker1.Value) { DEvsToday = evs; } } dataGridViewEvent.Columns.Clear(); BindingSource bs = new BindingSource(); bs.DataSource = CurEvents; dataGridViewEvent.DataSource = bs; dataGridViewEvent.Columns["Content"].FillWeight = 200; dataGridViewEvent.Columns["StartTime"].Visible = false; dataGridViewEvent.Columns["EndTime"].Visible = false; dataGridViewEvent.Columns["Description"].Visible = false; dataGridViewEvent.Refresh(); //selected rows if (DEvsToday == null) { return; } if (dataGridViewEvent.CurrentRow != null) { dataGridViewEvent.CurrentRow.Selected = false; } int count = 0; foreach (var ev in DEvsToday.Items) { int i = 0; foreach (DataGridViewRow itr in dataGridViewEvent.Rows) { string name = (itr.Cells[0].Value == null) ? "" : itr.Cells[0].Value.ToString(); string evName = ev.Content; if (name == evName) { count++; dataGridViewEvent.Rows[i].Selected = true; } i++; } } dataGridViewEvent.Columns["Content"].FillWeight = 200; dataGridViewEvent.Columns["StartTime"].Visible = false; dataGridViewEvent.Columns["EndTime"].Visible = false; dataGridViewEvent.Columns["Description"].Visible = false; dataGridViewEvent.Refresh(); }