private void populateProgressList(int taskid) { listBoxProgress.Items.Clear(); progress = new ArrayList(); SQL.selectProgressByTask(taskid); try { if (SQL.read.HasRows) { while (SQL.read.Read()) { // Create taskInfo object and add to arrayList Data.ProgressInfo progressInfo = new Data.ProgressInfo(SQL.read[0].ToString(), SQL.read[1].ToString(), SQL.read[2].ToString(), int.Parse(SQL.read[3].ToString())); progress.Add(progressInfo); // add to list box listBoxProgress.Items.Add(String.Format("Date: {0} | Description: {1}", FormHelper.getDateFromDT(progressInfo.reportDate), progressInfo.description)); } } else { listBoxProgress.Items.Add(String.Format("No progress found...")); } } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine(ex.StackTrace); } }
private void processProgress() { SQL.selectProgressByTask(int.Parse(task.taskid)); progressArr = new ArrayList(); try { if (SQL.read.HasRows) { while (SQL.read.Read()) { Data.ProgressInfo progress = new Data.ProgressInfo(SQL.read[0].ToString(), SQL.read[1].ToString(), SQL.read[2].ToString(), int.Parse(SQL.read[3].ToString())); progressArr.Add(progress); // add to listbox listBoxProgress.Items.Add(String.Format("Date: {0} - {1}", FormHelper.getDateFromDT(progress.reportDate), progress.description)); } } else { listBoxProgress.Items.Add(String.Format("No progress...")); } } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine(ex.StackTrace); } }
//------------------------------------------------------------- // INSERTS -- //------------------------------------------------------------- public static void insertProgress(Data.ProgressInfo progress) { con.Close(); String query = "INSERT INTO progress VALUES(@description, CAST(GETDATE() AS Date), @taskid)"; try { SqlCommand command = new SqlCommand(query, con); command.Parameters.AddWithValue("@description", progress.description); command.Parameters.AddWithValue("@taskid", progress.taskid); con.Open(); SqlCommand dateSet = new SqlCommand("SET DATEFORMAT dmy", con); dateSet.ExecuteNonQuery(); command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(ex); } }
private void buttonConfirm_Click(object sender, EventArgs e) { if (textBoxDescription.Text.Equals("")) { MessageBox.Show("Please enter a description"); return; } Data.ProgressInfo progress = new Data.ProgressInfo(null, textBoxDescription.Text, null, taskid); // add progress to database try { SQL.insertProgress(progress); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(ex); MessageBox.Show("Error adding progress"); return; } this.Close(); }