private void btnSubmit_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtStatus.Text) && !string.IsNullOrWhiteSpace(txtStatus.Text)) { //create a new DB instance DBUtility db = new DBUtility(); //write the new value to the database. db.AddNewEntry(txtStatus.Text); //hide the form and resume running in the taskbar. notifyIcon.Visible = true; txtStatus.Text = "Tell me your life story."; this.Hide(); } }
/// <summary> /// Creates the time tracker table if it does not already exist. /// </summary> private void CreateTimeTrackerTable() { StringBuilder createTableCommand = new StringBuilder(); createTableCommand.Append("IF (NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'Entries'))"); createTableCommand.Append("BEGIN "); createTableCommand.Append(" CREATE TABLE [dbo].[Entries]( "); createTableCommand.Append(" [ID] [int] IDENTITY(1,1) NOT NULL, "); createTableCommand.Append(" [Comments] [varchar](500) NOT NULL, "); createTableCommand.Append(" [rw_udt_ts] [datetime] NOT NULL "); createTableCommand.Append(" ) ON [PRIMARY] "); createTableCommand.Append("END "); DBUtility dbUtil = new DBUtility(); try { dbUtil.InsertNewRecordIntoTable(createTableCommand.ToString(), new List<SqlParameter>()); } catch (Exception ex) { lblError.Text = "Error creating table."; lblError.Visible = true; } }