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 ButtonNewWindowOk_Click(object sender, RoutedEventArgs e) { Int64 retId; NewWindowOk.IsEnabled = false; // template description update check var selectedTemplate = (ListTemplate)templateBox.SelectedItem; if ((selectedTemplate.Id > 0) && (!string.IsNullOrEmpty(NewDescriptionBox.Text)) && (!string.IsNullOrEmpty(selectedTemplate.Template))) { var result = MessageBox.Show(Properties.Resources.WH_AlreadyExists, "taskalu", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.No) { NewWindowOk.IsEnabled = true; return; } } DateTime due = (DateTime)dateBox.SelectedDate; DateTime dueDate = new DateTime(due.Year, due.Month, due.Day, hourBox.SelectedIndex, (minuteBox.SelectedIndex * 5), 0); if (TimeZoneInfo.Local.IsInvalidTime(dueDate)) { MessageBox.Show(Properties.Resources.MW_InvalidDate); } else { ListViewFile lvFile = new ListViewFile() { Name = NewTitleBox.Text, Description = NewDescriptionBox.Text, Memo = "", Priority = priorityBox.Text, DueDate = TimeZoneInfo.ConvertTimeToUtc(dueDate).ToString("yyyy-MM-dd HH:mm:ss"), Status = "Active", WorkHolder = WorkHolder.CreateWorkHolder(NewTitleBox.Text) }; if (!string.IsNullOrEmpty(selectedTemplate.Template)) { lvFile.Description = selectedTemplate.Template; } retId = SQLiteClass.ExecuteInsertTable(SQLiteClass.dbpath, lvFile); SQLiteClass.ExecuteInsertTableFTSString(SQLiteClass.dbpath, retId, "tasklist_name", Ngram.getNgramText(NewTitleBox.Text, 2)); SQLiteClass.ExecuteInsertTableFTSString(SQLiteClass.dbpath, retId, "tasklist_description", Ngram.getNgramText(NewDescriptionBox.Text, 2)); // copy template path if (selectedTemplate.Id > 0) { string workHolder = WorkHolder.CreateWorkHolder(NewTitleBox.Text); WorkHolder.CopyTemplatePathToWorkFolder(SQLiteClass.dbpath, selectedTemplate.Id, workHolder); } // Dialog box accepted; ウィンドウを閉じる this.DialogResult = true; } NewWindowOk.IsEnabled = true; }