private void button_editar_Click(object sender, EventArgs e) { int rowCount = this.dataGridView_mes.RowCount; int rowIndex = this.mesRowSelected; if (rowIndex < (rowCount - 1)) { int id_pagamento = Convert.ToInt32(this.dataGridView_mes.Rows[rowIndex].Cells[0].Value.ToString()); int id_matricula = Convert.ToInt32(this.dataGridView_mes.Rows[rowIndex].Cells[1].Value.ToString()); int ano = Convert.ToInt32(this.dataGridView_mes.Rows[rowIndex].Cells[4].Value.ToString()); int mes = Convert.ToInt32(this.dataGridView_mes.Rows[rowIndex].Cells[5].Value.ToString()); decimal valor = Convert.ToDecimal(this.textBox_evalor.Text); DateTime data = DateTime.Now; string status = "PAGO"; Pagamento pagamento = new Pagamento(); pagamento.IdPagamento = id_pagamento; pagamento.IdMatricula = id_matricula; pagamento.Valor = valor; pagamento.Ano = ano; pagamento.Mes = mes; pagamento.DataPagamento = data; pagamento.StatusPag = status; this.pagamentoControl.Alterar(pagamento); MessageBox.Show("Pagamento Editado com Sucesso!"); } }
public void Alterar(Pagamento pagamento) { using (SqlConnection connection = new SqlConnection(this.string_connection)) { using (SqlCommand command = new SqlCommand()) { string sql = @"UPDATE TB_PAGAMENTO SET VALOR = @VALOR, DATA_PAGAMENTO = @DATA, STATUS_PAG = @STATUS WHERE ID_PAGAMENTO = @PAGAMENTO AND ID_MATRICULA = @MATRICULA AND ANO = @ANO AND MES = @MES"; command.Connection = connection; command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@PAGAMENTO", pagamento.IdPagamento); command.Parameters.AddWithValue("@MATRICULA", pagamento.IdMatricula); command.Parameters.AddWithValue("@VALOR", pagamento.Valor); command.Parameters.AddWithValue("@DATA", pagamento.DataPagamento); command.Parameters.AddWithValue("@ANO", pagamento.Ano); command.Parameters.AddWithValue("@MES", pagamento.Mes); command.Parameters.AddWithValue("@STATUS", pagamento.StatusPag); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } }
public void Inserir(Pagamento pagamento) { int matricula = pagamento.IdMatricula; // verifica pagamento atrasado this.PagamentoAtrasado(matricula); // efetua o pagamento this.pagamentoDB.Inserir(pagamento); }
public void Alterar(Pagamento pagamento) { this.pagamentoDB.Alterar(pagamento); }
private void button_pagar_Click(object sender, EventArgs e) { int rowCount = this.dataGridView_cliente.RowCount; int rowIndex = this.rowSelected; if (rowIndex < (rowCount - 1)) { string str_mat = this.dataGridView_cliente.Rows[this.rowSelected].Cells[0].Value.ToString(); int matricula = Convert.ToInt32(str_mat); decimal valor = Convert.ToDecimal(this.textBox_valor.Text); DateTime data = DateTime.Now; int ano = Convert.ToInt32(this.maskedTextBox1.Text); int mes = this.comboBox_mes.SelectedIndex + 1; string status = "PAGO"; Pagamento pagamento = new Pagamento(); pagamento.IdMatricula = matricula; pagamento.Valor = valor; pagamento.DataPagamento = data; pagamento.Ano = ano; pagamento.Mes = mes; pagamento.StatusPag = status; this.pagamentoControl.Inserir(pagamento); MessageBox.Show("Pagamento Efetuado"); } }
public void Inserir(Pagamento pagamento) { using (SqlConnection connection = new SqlConnection(this.string_connection)) { using (SqlCommand command = new SqlCommand()) { string sql = @"INSERT INTO TB_PAGAMENTO (ID_MATRICULA, VALOR, DATA_PAGAMENTO, ANO, MES, STATUS_PAG) VALUES (@MATRICULA, @VALOR, @DATA, @ANO, @MES, @STATUS)"; command.Connection = connection; command.CommandText = sql; command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@MATRICULA", pagamento.IdMatricula); command.Parameters.AddWithValue("@VALOR", pagamento.Valor); command.Parameters.AddWithValue("@DATA", pagamento.DataPagamento); command.Parameters.AddWithValue("@ANO", pagamento.Ano); command.Parameters.AddWithValue("@MES", pagamento.Mes); command.Parameters.AddWithValue("@STATUS", pagamento.StatusPag); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } } }