Exemplo n.º 1
0
        private void btn_Export_Click(object sender, EventArgs e)
        {
            //SAVE FILE

            using (SaveFileDialog save = new SaveFileDialog()
            {
                Filter = "Csv|*.csv", ValidateNames = true
            })
            {
                if (save.ShowDialog() == DialogResult.OK)
                {
                    var         csv = new StringBuilder();
                    DF_requests req = new DF_requests();

                    using (var sw = new StreamWriter(save.FileName))
                    {
                        var writer = new CsvWriter(sw);
                        writer.WriteHeader(typeof(DF_requests));
                        for (int i = 0; i < dataGridView.RowCount; i++)
                        {
                            req.Date        = Convert.ToDateTime(dataGridView.Rows[i].Cells[0].Value);
                            req.Intended_to = dataGridView.Rows[i].Cells[1].Value.ToString();
                            req.Subject     = dataGridView.Rows[i].Cells[2].Value.ToString();
                            req.Message     = dataGridView.Rows[i].Cells[3].Value.ToString();
                            req.Status      = dataGridView.Rows[i].Cells[4].Value.ToString();
                            writer.WriteRecord(req);
                        }
                    }

                    MessageBox.Show("Saved", "mes", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemplo n.º 2
0
        private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 5)
            {
                using (Entities db = new Entities())
                {
                    string intendedTo = dataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
                    string subject    = dataGridView.Rows[e.RowIndex].Cells[2].Value.ToString();


                    DF_requests df_request = db.DF_requests.FirstOrDefault(s => s.Intended_to == intendedTo && s.Subject == subject);
                    if (df_request.Status.Contains("Open"))
                    {
                        df_request.Status = "Close";

                        db.SaveChanges();
                        MessageBox.Show("data updated");
                        reloadGrid();
                    }
                }
            }
        }