Advertisement
Kouuds

Untitled

Sep 11th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.91 KB | None | 0 0
  1. public partial class for_compra : Form
  2.     {
  3.         conexao resultado = new conexao();
  4.  
  5.         public for_compra()
  6.         {
  7.             InitializeComponent();
  8.            
  9.         }
  10.  
  11.         private void for_compra_Load(object sender, EventArgs e)
  12.         {
  13.             cbox_tipo.SelectedIndex = 0;
  14.             cbox_pagamento.SelectedIndex = 0;
  15.         }
  16.  
  17.         private void cbox_pagamento_SelectedIndexChanged(object sender, EventArgs e)
  18.         {
  19.             if (cbox_pagamento.SelectedItem.ToString() == "a vista")
  20.             {
  21.                 lbl_fiado.Text = "P";
  22.                 txt_dpagamento.Text = "";
  23.                 txt_dpagamento.Text = DateTime.Now.ToShortDateString();
  24.                 txt_dpagamento.Enabled = true;
  25.             }
  26.             else
  27.             {
  28.  
  29.                 lbl_fiado.Text = "F";
  30.                 txt_dpagamento.Enabled = false;
  31.                 txt_dpagamento.Text = "";
  32.             }
  33.         }
  34.  
  35.         private void btn_cadastrar_Click(object sender, EventArgs e)
  36.         {
  37.            
  38.             try
  39.             {
  40.  
  41.              
  42.                 if (cbox_pagamento.SelectedItem.ToString() == "a vista")
  43.                 {
  44.                     btn_avista.PerformClick();
  45.                 }
  46.                 else
  47.                 {
  48.  
  49.                     btn_aprazo.PerformClick();
  50.                 }
  51.             }
  52.             catch (Exception ex)
  53.             {
  54.                 MessageBox.Show("Falha ao salvar no banco de dados :" + ex);
  55.             }
  56.            
  57.  
  58.  
  59.            
  60.         }
  61.  
  62.         private void button1_Click(object sender, EventArgs e)
  63.         {
  64.             this.Close();
  65.         }
  66.  
  67.        
  68.         private void txt_valor_KeyPress(object sender, KeyPressEventArgs e)
  69.         {
  70.             txt_valor.MaxLength = 7;
  71.  
  72.         }
  73.  
  74.         private void btn_avista_Click(object sender, EventArgs e)
  75.         {
  76.             var mo = new Modelo();
  77.             var con = new conexao();
  78.  
  79.             try
  80.             {
  81.                 if (Decimal.TryParse(txt_valor.Text.Replace(',','.'), out var valor))
  82.                     {
  83.                
  84.                     mo.Data_Compra = txt_dcompra.Text;
  85.                     mo.Data_Alvo = txt_dalvo.Text;
  86.                     mo.Fornecedor = txt_fornecedor.Text;
  87.                     mo.Valor = valor;
  88.                     mo.Tipo = cbox_tipo.Text;
  89.                     mo.Pagamento = lbl_fiado.Text;
  90.                     mo.Data_Pagamento = txt_dpagamento.Text;
  91.  
  92.                     con.cadastro(mo);
  93.  
  94.                     txt_fornecedor.Text = "";
  95.                     txt_valor.Text = "";
  96.                     MessageBox.Show("Dados gravados com sucesso!");
  97.                 }
  98.             }
  99.             catch (MySqlException ex)
  100.             {
  101.                 MessageBox.Show("Falha ao salvar no banco de dados :" + ex);
  102.             }
  103.  
  104.         }
  105.  
  106.         private void btn_aprazo_Click(object sender, EventArgs e)
  107.         {
  108.             var mo = new Modelo();
  109.             var con = new conexao();
  110.  
  111.             try
  112.             {
  113.                 if (Decimal.TryParse(txt_valor.Text.Replace(',', '.'), out var valor))
  114.                 {
  115.  
  116.                     mo.Data_Compra = txt_dcompra.Text;
  117.                     mo.Data_Alvo = txt_dalvo.Text;
  118.                     mo.Fornecedor = txt_fornecedor.Text;
  119.                     mo.Valor = valor;
  120.                     mo.Tipo = cbox_tipo.Text;
  121.                     mo.Pagamento = lbl_fiado.Text;
  122.                     mo.Data_Pagamento = txt_dpagamento.Text;
  123.  
  124.                     con.cadastro_aprazo(mo);
  125.  
  126.                     txt_fornecedor.Text = "";
  127.                     txt_valor.Text = "";
  128.                     MessageBox.Show("Dados gravados com sucesso!");
  129.                 }
  130.             }
  131.             catch (MySqlException ex)
  132.             {
  133.                 MessageBox.Show("Falha ao salvar no banco de dados :" + ex);
  134.             }
  135.         }
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement