private void btnGravar_Click(object sender, EventArgs e) { if (dgvTask.Tag == null) { /*String teste; * teste = DateTime.Parse(txtData.Text, new CultureInfo("en-US")).ToString(); * teste = Convert.ToDateTime(txtData.Text).ToString("yyyy/MM/dd");*/ if (dgvTask.Tag == null) { Dictionary <string, object> dataTask = new Dictionary <string, object>(); dataTask.Add("data", dtpData.Value); dgvTask.Tag = SqlConn.ExecuteScalar(SqlGenerate.InsertDataTask(), dataTask); } } for (int i = 0; i < dgvTask.RowCount - 1; i++) { DataGridViewRow r = dgvTask.Rows[i]; int teste = int.Parse(r.Cells["clnId"].Value == null ? "0" : r.Cells["clnId"].Value.ToString()); var task = new DailyTask(int.Parse(r.Cells["clnId"].Value == null?"0":r.Cells["clnId"].Value.ToString()), int.Parse(dtpData.Tag == null ? "0":dtpData.Tag.ToString()), DateTime.Parse(r.Cells["clnData"].Value.ToString()), r.Cells["clnTitulo"].Value.ToString(), Convert.ToDouble(r.Cells["clnHora"].Value, new CultureInfo("en-US")), r.Cells["clnDescricao"].Value.ToString()); Dictionary <string, object> dataTaskDesc = new Dictionary <string, object>(); dataTaskDesc.Add("id", task.Id); dataTaskDesc.Add("idTask", task.IdTask); dataTaskDesc.Add("titulo", task.Titulo); dataTaskDesc.Add("descricao", task.Descricao); dataTaskDesc.Add("hora", task.Hora); if (task.Id == 0) { SqlConn.ExecuteNonQuery(SqlGenerate.InsertDescriptionTask(), dataTaskDesc); } else { SqlConn.ExecuteNonQuery(SqlGenerate.UpdatetDescriptionTask(), dataTaskDesc); } } LimpaCampos(); }
private void btnExcluir_Click(object sender, EventArgs e) { if (dgvTask.SelectedRows.Count > 0) { Dictionary <string, object> dataTaskDesc = new Dictionary <string, object>(); dataTaskDesc.Add("idDesc", Convert.ToInt32(dgvTask.CurrentRow.Cells["clnIdDesc"].Value)); dataTaskDesc.Add("idTask", Convert.ToInt32(dtpData.Tag)); if (dgvTask.CurrentRow.Cells["clnIdDesc"].Value != null) { SqlConn.ExecuteNonQuery(SqlGenerate.DeleteDescription(), dataTaskDesc); } dgvTask.Rows.RemoveAt(dgvTask.CurrentRow.Index); if ((dgvTask.SelectedRows.Count - 1) == 0) //Se não tem mais descrições, deleta task { SqlConn.ExecuteNonQuery(SqlGenerate.DeleteTask(), dataTaskDesc); } } else { MessageBox.Show("Selecione um registro para exclusão."); } }