public static DateTime CaluculateTheNextADayOfEveryMonth(ListAutoGenerate entry) { DateTime CheckedDate; DateTime.TryParseExact( entry.Checked_date, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out CheckedDate); Int32 theDay = (int)entry.Number0; Int32 theMonth = CheckedDate.Month; Int32 theYear = CheckedDate.Year; if (theDay <= CheckedDate.Day) { theMonth++; if (theMonth > 12) { theYear++; theMonth = 1; } } Int32 maxDay = DateTime.DaysInMonth(theYear, theMonth); if (theDay > maxDay) { theDay = maxDay; } return(new DateTime(theYear, theMonth, theDay)); }
public static int AutoGenerateTask(string dbpath, ListAutoGenerate entry, DateTime theDate) { int result = 0; DateTime dueDate = new DateTime(theDate.Year, theDate.Month, theDate.Day, (int)entry.Due_hour, (int)entry.Due_minute, 0); if (TimeZoneInfo.Local.IsInvalidTime(dueDate)) { dueDate = new DateTime(theDate.Year, theDate.Month, theDate.Day, 0, 0, 0); } ListViewFile lvFile = new ListViewFile() { Name = entry.Name, Description = "", Memo = "", Priority = entry.Priority, DueDate = TimeZoneInfo.ConvertTimeToUtc(dueDate).ToString("yyyy-MM-dd HH:mm:ss"), Status = "Active", WorkHolder = WorkHolder.CreateWorkHolder(entry.Name) }; if (entry.Template > 0) { var tlv = new TemplateListViewModel(); if (SQLiteClass.ExecuteSelectATableTemplate(dbpath, tlv, entry.Template)) { if (!string.IsNullOrEmpty(tlv.Entries[0].Template)) { lvFile.Description = tlv.Entries[0].Template; result += 1; } } } Int64 retId; retId = SQLiteClass.ExecuteInsertTable(dbpath, lvFile); if (retId > 0) { result += 2; } if (SQLiteClass.ExecuteInsertTableFTSString(dbpath, retId, "tasklist_name", Ngram.getNgramText(lvFile.Name, 2))) { result += 4; } if (SQLiteClass.ExecuteInsertTableFTSString(dbpath, retId, "tasklist_description", Ngram.getNgramText(lvFile.Description, 2))) { result += 8; } // copy template path if (entry.Template > 0) { string workHolder = WorkHolder.CreateWorkHolder(entry.Name); if (WorkHolder.CopyTemplatePathToWorkFolder(dbpath, entry.Template, workHolder) > 0) { result += 16; } } return(result); }
public static Boolean ExecuteSelectTableAutoGenerate(string dbpath, AutoGenerateListViewModel aglv) { Boolean ret = false; string sql = "SELECT * from autogenerate ORDER BY torder ASC"; SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";"); con.Open(); SQLiteCommand com = new SQLiteCommand(sql, con); try { SQLiteDataReader sdr = com.ExecuteReader(); while (sdr.Read() == true) { ListAutoGenerate lt = new ListAutoGenerate(); lt.Id = (Int64)sdr["id"]; lt.Order = (Int64)sdr["torder"]; lt.Type = (Int64)sdr["type"]; lt.Name = (string)sdr["name"]; lt.Priority = (string)sdr["priority"]; lt.Template = (Int64)sdr["template"]; lt.Number0 = (Int64)sdr["number0"]; lt.Number1 = (Int64)sdr["number1"]; lt.Due_hour = (Int64)sdr["due_hour"]; lt.Due_minute = (Int64)sdr["due_minute"]; lt.Checked_date = (string)sdr["checked_date"]; aglv.Entries.Add(lt); } sdr.Close(); ret = true; } catch (Exception ex) { MessageBox.Show("database table autogenerate select error!\n" + ex.Message); } finally { con.Close(); } return(ret); }
public static DateTime CaluculateTheNextAWeekDayOfEveryWeek(ListAutoGenerate entry) { DateTime CheckedDate; DateTime.TryParseExact( entry.Checked_date, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out CheckedDate); Int32 theWeekday = (int)entry.Number1; Int32 theDay = CheckedDate.Day; Int32 theMonth = CheckedDate.Month; Int32 theYear = CheckedDate.Year; Int32 plusDays = theWeekday - (int)CheckedDate.DayOfWeek; if (plusDays <= 0) { plusDays += 7; } return(new DateTime(theYear, theMonth, theDay) + new TimeSpan(plusDays, 0, 0, 0)); }
public static Boolean ExecuteInsertTableAutoGenerate(string dbpath, ListAutoGenerate lt) { Boolean ret = false; object obj; SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";"); con.Open(); SQLiteCommand com = new SQLiteCommand("INSERT INTO autogenerate (torder, type, name, priority, template, number0, number1, due_hour, due_minute, checked_date) VALUES (@torder, @type, @name, @priority, @template, @number0, @number1, @due_hour, @due_minute, @checked_date)", con); com.Parameters.Add(sqliteParamInt64(com, "@torder", lt.Order)); com.Parameters.Add(sqliteParamInt64(com, "@type", lt.Type)); com.Parameters.Add(sqliteParam(com, "@name", lt.Name)); com.Parameters.Add(sqliteParam(com, "@priority", lt.Priority)); com.Parameters.Add(sqliteParamInt64(com, "@template", lt.Template)); com.Parameters.Add(sqliteParamInt64(com, "@number0", lt.Number0)); com.Parameters.Add(sqliteParamInt64(com, "@number1", lt.Number1)); com.Parameters.Add(sqliteParamInt64(com, "@due_hour", lt.Due_hour)); com.Parameters.Add(sqliteParamInt64(com, "@due_minute", lt.Due_minute)); com.Parameters.Add(sqliteParam(com, "@checked_date", lt.Checked_date)); try { obj = com.ExecuteNonQuery(); ret = true; } catch (Exception ex) { MessageBox.Show("database table autogenerate insert error!\n" + ex.Message); } finally { con.Close(); } return(ret); }
public static Boolean ExecuteUpdateTableAutoGenerate(string dbpath, ListAutoGenerate lt) { Boolean ret = false; SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";"); con.Open(); SQLiteCommand com = new SQLiteCommand("UPDATE autogenerate set torder=@torder, type=@type, name=@name, priority=@priority, template=@template, number0=@number0, number1=@number1, due_hour=@due_hour, due_minute=@due_minute, checked_date=@checked_date where id=@id", con); com.Parameters.Add(sqliteParamInt64(com, "@id", lt.Id)); com.Parameters.Add(sqliteParamInt64(com, "@torder", lt.Order)); com.Parameters.Add(sqliteParamInt64(com, "@type", lt.Type)); com.Parameters.Add(sqliteParam(com, "@name", lt.Name)); com.Parameters.Add(sqliteParam(com, "@priority", lt.Priority)); com.Parameters.Add(sqliteParamInt64(com, "@template", lt.Template)); com.Parameters.Add(sqliteParamInt64(com, "@number0", lt.Number0)); com.Parameters.Add(sqliteParamInt64(com, "@number1", lt.Number1)); com.Parameters.Add(sqliteParamInt64(com, "@due_hour", lt.Due_hour)); com.Parameters.Add(sqliteParamInt64(com, "@due_minute", lt.Due_minute)); com.Parameters.Add(sqliteParam(com, "@checked_date", lt.Checked_date)); try { com.ExecuteNonQuery(); ret = true; } catch (Exception ex) { MessageBox.Show("database table autogenerate update error!\n" + ex.Message); } finally { con.Close(); } return(ret); }