Levelcode-IBRCAD/IBRCAD/frm_pagamentocompra.cs

142 lines
5.0 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;
using BLL;
using MLL;
using Modelo;
namespace IBRCAD
{
public partial class frm_pagamentocompra : Form
{
int pco_cod;
public frm_pagamentocompra()
{
InitializeComponent();
}
private void Frm_pagamentocompra_Load(object sender, EventArgs e)
{
}//load
private void Btn_localizarcompra_Click(object sender, EventArgs e)
{
frm_consultacompra fc = new frm_consultacompra();
fc.ShowDialog();
if (fc.codigo != 0)
{
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
BLLCompra bcompra = new BLLCompra(cx);
BLLFornecedor bfor = new BLLFornecedor(cx);
ModeloCompra mcompra = bcompra.CarregaModeloCompra(fc.codigo);
txtcodvenda.Text = mcompra.ComCod.ToString();
dtp_data_venda.Value = mcompra.ComData;
txtValor.Text = mcompra.ComTotal.ToString();
ModeloFornecedor modeloF = bfor.CarregaModeloFornecedor(mcompra.ForCod);
txtcliente.Text = modeloF.ForNome;
BLLparcelascompra bparcelas = new BLLparcelascompra(cx);
DataTable parcelas = bparcelas.localizar(mcompra.ComCod);
dgv_parcelas.DataSource = bparcelas.localizar(mcompra.ComCod);
this.orgcampos(dgv_parcelas);
//for (int i = 0; i < parcelas.Rows.Count; i++)
//{
// string icod = tabela.Rows[i]["pro_cod"].ToString();
// string inome = tabela.Rows[i]["pro_nome"].ToString();
// string iqtde = tabela.Rows[i]["itc_qtde"].ToString();
// string ivalorU = tabela.Rows[i]["itc_valor"].ToString();
// double valorTotal = Convert.ToDouble(tabela.Rows[i]["itc_qtde"]) * Convert.ToDouble(tabela.Rows[i]["itc_valor"]);
// string[] it = new string[] { icod, inome, iqtde, ivalorU, valorTotal.ToString() };
// this.dgCompras.Rows.Add(it);
//}
}
}//localizar parcelas
private void orgcampos(DataGridView dg)
{
dg.Columns[0].Width = 100;
dg.Columns[0].HeaderText = "Cód. parcelas";
dg.Columns[1].Width = 60;
dg.Columns[1].HeaderText = "Valor(R$)";
dg.Columns[2].Width = 100;
dg.Columns[2].HeaderText = "Pagamento";
dg.Columns[3].Width = 100;
dg.Columns[3].HeaderText = "Vencimendo";
dg.Columns[4].Visible = false;
}//organizar campos
private void limpar()
{
dgv_parcelas.DataSource = null;
this.txtcodvenda.Text = "";
this.txtcliente.Text = "";
this.txtValor.Text = "";
this.dtp_data_venda.Value = DateTime.Now;
this.dt_recebimento.Value = DateTime.Now;
this.dtp_data_venda.Enabled = false;
this.dt_recebimento.Enabled = false;
this.btn_receber.Enabled = false;
}
private void Btn_receber_Click(object sender, EventArgs e)
{
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
if (this.pco_cod == 0)
{
MessageBox.Show("Selecione a parcela a ser paga clicando na mesma na listagem");
}
else
{
BLLparcelascompra bllp = new BLLparcelascompra(cx);
int comcod = Convert.ToInt32(txtcodvenda.Text);
int pcocod = this.pco_cod;
DateTime data = dt_recebimento.Value;
bllp.EfetuaPagamentoParcelas(comcod, pcocod, data);
this.pco_cod = 0;
MessageBox.Show("Pagamento Realizado com Sucesso!", "Pagamento efetuado");
dgv_parcelas.DataSource = bllp.localizar(comcod);
this.orgcampos(dgv_parcelas);
this.limpar();
}
}
private void Dgv_parcelas_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0 && dgv_parcelas.Rows[e.RowIndex].Cells[2].Value.ToString() == "")
{
this.btn_receber.Enabled = true;
this.pco_cod = Convert.ToInt32(dgv_parcelas.Rows[e.RowIndex].Cells[0].Value);
}
else
{
this.btn_receber.Enabled = false;
}
}
private void Btn_cancelar_Click(object sender, EventArgs e)
{
this.limpar();
}
private void Btn_imprimir_Click(object sender, EventArgs e)
{
//printDGV.Print_DataGridView(dgv_parcelas);
}
private void pb_exit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}