Exemplo n.º 1
0
        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();
        }