public static Boolean ExecuteInsertTableTemplate(string dbpath, ListTemplate lt) { Boolean ret = false; object obj; SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";"); con.Open(); SQLiteCommand com = new SQLiteCommand("INSERT INTO template (torder, name, template) VALUES (@torder, @name, @template)", con); com.Parameters.Add(sqliteParamInt64(com, "@torder", lt.Order)); com.Parameters.Add(sqliteParam(com, "@name", lt.Name)); com.Parameters.Add(sqliteParam(com, "@template", lt.Template)); try { obj = com.ExecuteNonQuery(); ret = true; } catch (Exception ex) { MessageBox.Show("database table template insert error!\n" + ex.Message); } finally { con.Close(); } return(ret); }
public NewWindow() { InitializeComponent(); TimeSpan ts1hour = TimeSpan.FromHours(1); DateTime due = System.DateTime.Now + ts1hour; dateBox.SelectedDate = due; hourBox.SelectedIndex = Int32.Parse(due.ToString("HH")); minuteBox.SelectedIndex = Int32.Parse(due.ToString("mm")) / 5; // add combobox tempplate item templateBox.DataContext = TemplateListViewModel.tlv; TemplateListViewModel.tlv.Entries.Clear(); var noneTemplate = new ListTemplate(); noneTemplate.Id = 0; noneTemplate.Name = Properties.Resources.NW_None; noneTemplate.Order = -1; noneTemplate.Template = ""; TemplateListViewModel.tlv.Entries.Add(noneTemplate); SQLiteClass.ExecuteSelectTableTemplate(SQLiteClass.dbpath, TemplateListViewModel.tlv); }
public static Boolean ExecuteUpdateTableTemplate(string dbpath, ListTemplate lt) { Boolean ret = false; SQLiteConnection con = new SQLiteConnection("Data Source=" + dbpath + ";"); con.Open(); SQLiteCommand com = new SQLiteCommand("UPDATE template set torder=@torder, name=@name, template=@template where id=@id", con); com.Parameters.Add(sqliteParamInt64(com, "@id", lt.Id)); com.Parameters.Add(sqliteParamInt64(com, "@torder", lt.Order)); com.Parameters.Add(sqliteParam(com, "@name", lt.Name)); com.Parameters.Add(sqliteParam(com, "@template", lt.Template)); try { com.ExecuteNonQuery(); ret = true; } catch (Exception ex) { MessageBox.Show("database table template update error!\n" + ex.Message); } finally { con.Close(); } return(ret); }
private void AutoGenerateLoaded(object sender, RoutedEventArgs e) { AutoGenerateTypeBox.SelectedIndex = (int)theAutoGenerate.Type; switch (theAutoGenerate.Type) { case (long)ListAutoGenerate.TypeName.A_Day_Of_Every_Month: AutoGenerateType1Panel.Visibility = Visibility.Collapsed; AutoGenerateType0Panel.Visibility = Visibility.Visible; dayBox.SelectedIndex = (int)theAutoGenerate.Number0 - 1; break; case (long)ListAutoGenerate.TypeName.A_Weekday_In_Every_Week: AutoGenerateType0Panel.Visibility = Visibility.Collapsed; AutoGenerateType1Panel.Visibility = Visibility.Visible; weekdayBox.SelectedIndex = (int)theAutoGenerate.Number1; break; } AutoGenerateName.Text = theAutoGenerate.Name; hourBox.SelectedIndex = (int)theAutoGenerate.Due_hour; minuteBox.SelectedIndex = (int)theAutoGenerate.Due_minute / 5; int priorityLen = theAutoGenerate.Priority.Length; if (priorityLen > 5) { priorityLen = 5; } priorityBox.SelectedIndex = 5 - priorityLen; // add combobox tempplate item templateBox.DataContext = TemplateListViewModel.tlv; TemplateListViewModel.tlv.Entries.Clear(); var noneTemplate = new ListTemplate(); noneTemplate.Id = 0; noneTemplate.Name = Properties.Resources.NW_None; noneTemplate.Order = -1; noneTemplate.Template = ""; TemplateListViewModel.tlv.Entries.Add(noneTemplate); SQLiteClass.ExecuteSelectTableTemplate(SQLiteClass.dbpath, TemplateListViewModel.tlv); // reflect the ID of template templateBox.SelectedIndex = (int)SQLiteClass.ExecuteSelectTemplateOrderFromID( SQLiteClass.dbpath, theAutoGenerate.Template) + 1; }
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); }