Advertisement
Kouuds

Untitled

Sep 11th, 2017
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using MySql.Data.MySqlClient;
  7. using MySql.Data;
  8. using System.Data;
  9. using System.Windows.Forms;
  10.  
  11. namespace ProjetoControledefiado
  12. {
  13.     class conexao
  14.     {
  15.  
  16.         string consulta_baixa = Properties.Settings.Default.strinconsulta;
  17.  
  18.         string strincaminho = Properties.Settings.Default.strinconn;
  19.  
  20.         private MySqlConnection dbconexao;
  21.  
  22.         public void cadastro(Modelo mo)
  23.         {
  24.  
  25.             try
  26.             {
  27.                 dbconexao = new MySqlConnection(strincaminho);
  28.                 dbconexao.Open();
  29.  
  30.                 string inserir = "INSERT INTO cpagar(data_compra,data_alvo,fornecedor,valor,tipo,pagamento,data_pagamento)values('" + mo.Data_Compra + "','" + mo.Data_Alvo + "','" + mo.Fornecedor + "','" + mo.Valor + "','" + mo.Tipo + "','" + mo.Pagamento + "','" + mo.Data_Pagamento + "')";
  31.  
  32.                 MySqlCommand comandos = new MySqlCommand(inserir, dbconexao);
  33.  
  34.                 comandos.ExecuteNonQuery();
  35.  
  36.                 dbconexao.Close();
  37.             }
  38.  
  39.             catch (Exception ex)
  40.             {
  41.                 throw new Exception("Erro de Comandos" + ex.Message);
  42.             }
  43.         }
  44.         public void cadastro_aprazo(Modelo mo)
  45.         {
  46.  
  47.             try
  48.             {
  49.                 dbconexao = new MySqlConnection(strincaminho);
  50.                 dbconexao.Open();
  51.  
  52.                 string inserir = "INSERT INTO cpagar(data_compra,data_alvo,fornecedor,valor,tipo)values('" + mo.Data_Compra + "','" + mo.Data_Alvo + "','" + mo.Fornecedor + "','" + mo.Valor + "','" + mo.Tipo + "')";
  53.  
  54.                 MySqlCommand comandos = new MySqlCommand(inserir, dbconexao);
  55.  
  56.                 comandos.ExecuteNonQuery();
  57.  
  58.                 dbconexao.Close();
  59.             }
  60.             catch (Exception ex)
  61.             {
  62.                 throw new Exception("Erro de Comandos" + ex.Message);
  63.             }
  64.  
  65.         }
  66.  
  67.         public void update(Modelo mo)
  68.         {
  69.             try
  70.             {
  71.                 dbconexao = new MySqlConnection(strincaminho);
  72.                 dbconexao.Open();
  73.  
  74.                 string inserir = Properties.Settings.Default.strinupdate;
  75.  
  76.                 MySqlCommand comandos = new MySqlCommand(inserir, dbconexao);
  77.  
  78.                 comandos.ExecuteNonQuery();
  79.  
  80.                 dbconexao.Close();
  81.             }
  82.             catch (Exception ex)
  83.             {
  84.                 throw new Exception("Erro de Comandos" + ex.Message);
  85.             }
  86.         }
  87.  
  88.         public void datagrid_fiado(DataGridView data)
  89.         {
  90.             MySqlCommand comandos = new MySqlCommand();
  91.             dbconexao = new MySqlConnection(strincaminho);
  92.             dbconexao.Open();
  93.             comandos.Connection = dbconexao;
  94.  
  95.             comandos.CommandText = "Select * From cpagar where Pagamento = 'F' order by data_compra desc;";
  96.  
  97.             try
  98.             {
  99.                 MySqlDataAdapter selecionar = new MySqlDataAdapter();
  100.                 selecionar.SelectCommand = comandos;
  101.                 DataTable dadostabela = new DataTable();
  102.                 selecionar.Fill(dadostabela);
  103.                 BindingSource formulario = new BindingSource();
  104.                 formulario.DataSource = dadostabela;
  105.                 data.DataSource = formulario;
  106.                 selecionar.Update(dadostabela);
  107.             }
  108.             catch (Exception ex)
  109.             {
  110.                 MessageBox.Show(ex.Message);
  111.             }
  112.         }
  113.  
  114.         public void datagrid_consulta(DataGridView data)
  115.         {
  116.             MySqlCommand comandos = new MySqlCommand();
  117.             dbconexao = new MySqlConnection(strincaminho);
  118.             dbconexao.Open();
  119.             comandos.Connection = dbconexao;
  120.  
  121.             comandos.CommandText = Properties.Settings.Default.strinconsulta;
  122.  
  123.             try
  124.             {
  125.                 MySqlDataAdapter selecionar = new MySqlDataAdapter();
  126.                 selecionar.SelectCommand = comandos;
  127.                 DataTable dadostabela = new DataTable();
  128.                 selecionar.Fill(dadostabela);
  129.                 BindingSource formulario = new BindingSource();
  130.                 formulario.DataSource = dadostabela;
  131.                 data.DataSource = formulario;
  132.                 selecionar.Update(dadostabela);
  133.             }
  134.             catch (Exception ex)
  135.             {
  136.                 MessageBox.Show(ex.Message);
  137.             }
  138.  
  139.         }
  140.  
  141.        
  142.  
  143.  
  144.     }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement