private void ReadDB(DateTime targetDate, EComboButton choice) { String sql = String.Format("SELECT * FROM calendar WHERE date = '{0}'", targetDate.ToString("yyyy-MM-dd")); var conn = new SQLiteConnection(App.filePath); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(sql, conn); SQLiteDataReader rdr = cmd.ExecuteReader(); string content = null; //처음 작성하는 날짜의 경우에는 DB검색 결과가 없다. 그러므로 서브윈도우를 무조건적으로 공백으로 //초기화 해주어 새로고침 효과를 낸다. if (subWindow != null) { subWindow.CalendarTextBox.Text = ""; subWindow.ReportTextBox.Text = ""; subWindow.ServiceTextBox.Text = ""; } while (rdr.Read()) { switch (choice) { case EComboButton.Calendar: if (subWindow != null) { subWindow.CalendarTextBox.Text = rdr["calendar"].ToString(); subWindow.ReportTextBox.Text = rdr["report"].ToString(); subWindow.ServiceTextBox.Text = rdr["service"].ToString(); } content = rdr["calendar"].ToString(); break; case EComboButton.Report: if (subWindow != null) { subWindow.CalendarTextBox.Text = rdr["calendar"].ToString(); subWindow.ReportTextBox.Text = rdr["report"].ToString(); subWindow.ServiceTextBox.Text = rdr["service"].ToString(); } content = rdr["report"].ToString(); break; case EComboButton.Service: if (subWindow != null) { subWindow.CalendarTextBox.Text = rdr["calendar"].ToString(); subWindow.ReportTextBox.Text = rdr["report"].ToString(); subWindow.ServiceTextBox.Text = rdr["service"].ToString(); } content = rdr["service"].ToString(); break; } } rdr.Close(); conn.Close(); textBox.Text = content; }
private void dtTimeClock_Tick(object sender, EventArgs e) { Task t1 = new Task(() => { string sql = null; string textValue = ""; EComboButton choice = EComboButton.Calendar; string dateString = null; DateTime datetime = DateTime.Now; Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { textValue = textBox.Text; choice = GetCurrentSelectedChoice(); datetime = (DateTime)calendar.SelectedDate; dateString = datetime.ToString("yyyy-MM-dd"); })); switch (choice) { case EComboButton.Calendar: sql = String.Format("INSERT INTO calendar (" + "date, calendar) values ('{0}', '{1}') ON CONFLICT(date) DO UPDATE SET calendar = '{2}'", dateString, textValue, textValue); break; case EComboButton.Report: sql = String.Format("INSERT INTO calendar (" + "date, report) values ('{0}', '{1}') ON CONFLICT(date) DO UPDATE SET report = '{2}'", dateString, textValue, textValue); break; case EComboButton.Service: sql = String.Format("INSERT INTO calendar (" + "date, service) values ('{0}', '{1}') ON CONFLICT(date) DO UPDATE SET service = '{2}'", dateString, textValue, textValue); break; } var conn = new SQLiteConnection(App.filePath); conn.Open(); SQLiteCommand command = new SQLiteCommand(sql, conn); command.ExecuteNonQuery(); conn.Close(); //저장 이후 타이머 중지 dtClockTime.Stop(); //변경된 데이터를 DB에 저장하였으므로 SubWindow또한 변경된 데이터로 갱신한다. Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate { switch (choice) { case EComboButton.Calendar: subWindow.CalendarTextBox.Text = textValue; break; case EComboButton.Report: subWindow.ReportTextBox.Text = textValue; break; case EComboButton.Service: subWindow.ServiceTextBox.Text = textValue; break; } })); }); t1.Start(); }