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); }
private void saveOrderOfTemplate(string dbpath, TemplateListViewModel tlv) { Int64 newOrder = 0; foreach (ListTemplate entry in tlv.Entries) { entry.Order = newOrder; SQLiteClass.ExecuteUpdateTableTemplate(dbpath, entry); newOrder++; } }
public static Boolean ExecuteSelectATableTemplate(string dbpath, TemplateListViewModel tlv, Int64 id) { Boolean ret = false; string sql = "SELECT * from template WHERE id = @id"; SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";"); con.Open(); SQLiteCommand com = new SQLiteCommand(sql, con); com.Parameters.Add(sqliteParamInt64(com, "@id", id)); try { SQLiteDataReader sdr = com.ExecuteReader(); while (sdr.Read() == true) { ListTemplate lt = new ListTemplate(); lt.Id = (Int64)sdr["id"]; lt.Order = (Int64)sdr["torder"]; lt.Name = (string)sdr["name"]; lt.Template = (string)sdr["template"]; tlv.Entries.Add(lt); } sdr.Close(); ret = true; } catch (Exception ex) { MessageBox.Show("database table template select error!\n" + ex.Message); } finally { con.Close(); } return(ret); }