예제 #1
0
        private void newEntryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var new_entry = new New_Entry())
            {
                new_entry.ShowDialog();

                if (new_entry.DialogResult == DialogResult.OK)
                {
                    Jobs.Add(new_entry.NewJob);

                    int index;
                    if (dataGridView1.Rows.Count == 0)
                    {
                        index = 1;
                    }
                    else
                    {
                        DataGridViewRow LastRow = dataGridView1.Rows[dataGridView1.Rows.Count - 1];
                        index = Convert.ToInt16(LastRow.Cells[0].Value) + 1;
                    }

                    ListOfIds.Add(index);

                    int             num = Jobs.Count();
                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dataGridView1);
                    row.Cells[0].Value = index.ToString();
                    row.Cells[1].Value = Jobs[num - 1].Started.ToString("yyyy-MM-dd HH:mm:ss");
                    row.Cells[2].Value = Jobs[num - 1].Finished.ToString("yyyy-MM-dd HH:mm:ss");
                    row.Cells[3].Value = Jobs[num - 1].Total;
                    row.Cells[4].Value = Jobs[num - 1].Assigned_by;
                    row.Cells[5].Value = Jobs[num - 1].Comment;

                    dataGridView1.Rows.Add(row);


                    using (var con = new SQLiteConnection(ConnectionString))
                    {
                        con.Open();

                        var sql = "INSERT INTO times(Started,Finished,Total,Assigned_by,Comment) VALUES('" + new_entry.NewJob.Started.ToString("yyyy-MM-dd HH:mm:ss")
                                  + "','" + new_entry.NewJob.Finished.ToString("yyyy-MM-dd HH:mm:ss") + "','" + new_entry.NewJob.Total + "','" + new_entry.NewJob.Assigned_by + "','" + new_entry.NewJob.Comment + "')";


                        var cmd = new SQLiteCommand(sql, con);
                        cmd.ExecuteNonQuery();

                        con.Close();
                    }
                    if (dataGridView1.Rows.Count > 0)
                    {
                        editSelectedToolStripMenuItem.Enabled   = true;
                        deleteSelectedToolStripMenuItem.Enabled = true;
                    }
                }
            }
        }
예제 #2
0
        private void editSelectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int id = dataGridView1.CurrentCell.RowIndex + 1;

            using (var new_entry = new New_Entry())
            {
                new_entry.FormText(Jobs[id - 1].Started.ToString("yyyy-MM-dd HH:mm:ss"),
                                   Jobs[id - 1].Finished.ToString("yyyy-MM-dd HH:mm:ss"),
                                   Jobs[id - 1].Assigned_by, Jobs[id - 1].Comment);

                new_entry.ShowDialog();

                if (new_entry.DialogResult == DialogResult.OK)
                {
                    Jobs[id - 1] = new_entry.NewJob;

                    DataGridViewRow row = dataGridView1.CurrentRow;

                    row.Cells[1].Value = Jobs[id - 1].Started.ToString("yyyy-MM-dd HH:mm:ss");
                    row.Cells[2].Value = Jobs[id - 1].Finished.ToString("yyyy-MM-dd HH:mm:ss");
                    row.Cells[3].Value = Jobs[id - 1].Total;
                    row.Cells[4].Value = Jobs[id - 1].Assigned_by;
                    row.Cells[5].Value = Jobs[id - 1].Comment;

                    using (var con = new SQLiteConnection(ConnectionString))
                    {
                        con.Open();

                        var sql = "UPDATE times SET Started='" + new_entry.NewJob.Started.ToString("yyyy-MM-dd HH:mm:ss") + "',Finished='" + new_entry.NewJob.Finished.ToString("yyyy-MM-dd HH:mm:ss") +
                                  "',Total='" + new_entry.NewJob.Total + "',Assigned_by='" + new_entry.NewJob.Assigned_by + "',Comment='" + new_entry.NewJob.Comment + "' WHERE Id=" + ListOfIds[id - 1] + "";

                        var cmd = new SQLiteCommand(sql, con);
                        cmd.ExecuteNonQuery();

                        con.Close();
                    }
                }
            }
        }