Пример #1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());

            using (var db = new LanchoneteEntityContainer())
            {
                Saidas s = db.Saidas.FirstOrDefault(u => u.Id == id);
                descricaotxt.Text = s.Descricao.ToString();
                datasaidalb.Text  = s.Datasaida.ToShortDateString();
                idsaidalb.Text    = s.Id.ToString();
                valortxt.Text     = s.Valor.ToString();
                descricaotxt.Focus();
            }
            salvarbtn.Enabled = true;
        }
Пример #2
0
        private void salvarbtn_Click(object sender, EventArgs e)
        {
            double valor = Convert.ToDouble(valortxt.Text.ToString());

            using (var db = new LanchoneteEntityContainer())
            {
                if (idsaidalb.Text == "-")
                {
                    Saidas s = new Saidas();
                    s.Datasaida = DateTime.Now;
                    s.Descricao = descricaotxt.Text.ToString();
                    s.Valor     = valor;
                    try
                    {
                        db.Saidas.Add(s);
                        db.SaveChanges();
                        MessageBox.Show("Saída cadastrada com sucesso !");
                        inicio();
                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                        return;
                    }
                }
                else
                {
                    int    id = Convert.ToInt32(idsaidalb.Text.ToString());
                    Saidas s  = db.Saidas.FirstOrDefault(u => u.Id == id);
                    s.Descricao = descricaotxt.Text.ToString();
                    s.Valor     = valor;
                    try
                    {
                        db.SaveChanges();
                        MessageBox.Show("Saída Atualizada com sucesso !");
                        inicio();
                        return;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                        return;
                    }
                }
            }
        }