public static void loadActivities() { activities.Clear(); if (!opened) { return; } string sql = "SELECT rowid, d,m,y, dEnd,mEnd,Yend, days,data FROM activities"; var cmd = new SQLiteCommand(sql, db); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var item = new ActivityRecord(); item.id = Convert.ToInt32(reader["rowid"]); item.d = Convert.ToInt32(reader["d"]); item.m = Convert.ToInt32(reader["m"]); item.y = Convert.ToInt32(reader["y"]); item.dEnd = Convert.ToInt32(reader["dEnd"]); item.mEnd = Convert.ToInt32(reader["mEnd"]); item.yEnd = Convert.ToInt32(reader["yEnd"]); item.days = Convert.ToSByte(reader["days"]); item.data = reader["data"].ToString(); activities[item.id] = item; } }
public static void insertActivity(ActivityRecord rec) { if (!opened) { return; } string sql = String.Format("INSERT INTO activities (d,m,y,dEnd,mEnd,Yend,days,data) VALUES ({0},{1},{2},{3},{4},{5},{6},'{7}')", rec.d, rec.m, rec.y, rec.dEnd, rec.mEnd, rec.yEnd, rec.days, s(rec.data) ); rec.id = Insert(sql); activities[rec.id] = rec; }
public static void updateActivity(ActivityRecord rec) { if (!opened) { return; } string sql = String.Format("UPDATE activities SET dEnd={0}, mEnd={1}, yEnd={2}, days={3}, data='{4}' WHERE rowid={5}", rec.dEnd, rec.mEnd, rec.yEnd, rec.days, s(rec.data), rec.id ); Save(sql); activities[rec.id] = rec; }
string ActivityLine(ActivityRecord rec) { string result = "• "; if (rec.yEnd > 0) { var today = new DateTime(year, month, day); var end = new DateTime(rec.yEnd, rec.mEnd, rec.dEnd); int days = (end - today).Days; result += String.Format("(deadline {0}) ", Extensions.DayInflex(days)); } result += rec.data; return(result); }
public ActivityUpdate(int id, int y, int m, int d) { InitializeComponent(); data = id == 0 ? new ActivityRecord() : Model.activities[id]; note = Model.activitiesData.Find(ad => ad.activityId == id && ad.y == y && ad.m == m && ad.d == d); if (note == null) { note = new ActivityDataRecord(); note.d = d; note.m = m; note.y = y; note.activityId = id; } }
public void SaveActivity(ActivityRecord rec, bool noteOn, ActivityDataRecord note) { if (rec.id == 0) { rec.y = year; rec.m = month; rec.d = day; Model.insertActivity(rec); } else { Model.updateActivity(rec); } if (noteOn) { Model.setActivityData(note); } else { Model.unsetActivityData(note); } ShowDayLog(day); }