Advertisement
Guest User

C# Application for DB

a guest
May 16th, 2016
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using MySql.Data.MySqlClient;
  10. using iTextSharp.text;
  11. using iTextSharp.text.pdf;
  12. using System.IO;
  13.  
  14. namespace WindowsFormsApplication1
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void button1_Click(object sender, EventArgs e)
  24.         {
  25.             // Get the text
  26.  
  27.             string text = textBoxRecenicaUnos.Text;
  28.  
  29.             if (text != "")
  30.             {
  31.                 // Open SQL Conn
  32.                 MySqlConnection MyCon;
  33.                 MySqlCommand upit;
  34.                 string arg = "datasource=localhost;port=3306;username=root;password=";
  35.                 MySqlDataReader res;
  36.                 MyCon = new MySqlConnection(arg);
  37.                 // INSERT
  38.                 string insert = "USE recenica; INSERT INTO recenica (VAL) VALUES('" + text + "');";
  39.                 upit = new MySqlCommand(insert, MyCon);
  40.                 MyCon.Open();
  41.                 res = upit.ExecuteReader();
  42.             }
  43.         }
  44.  
  45.         // Export sve iz baze
  46.         private void button2_Click(object sender, EventArgs e)
  47.         {
  48.             comboBox1.Items.Clear();
  49.             comboBox1.Enabled = true;
  50.  
  51.             // Open SQL Conn
  52.             MySqlConnection MyCon;
  53.             MySqlCommand upit;
  54.             string arg = "datasource=localhost;port=3306;username=root;password=";
  55.             MySqlDataReader res;
  56.             MyCon = new MySqlConnection(arg);
  57.             // SELECT
  58.            
  59.             string insert = "USE recenica; SELECT VAL FROM recenica;";
  60.             upit = new MySqlCommand(insert, MyCon);
  61.             MyCon.Open();
  62.             res = upit.ExecuteReader();
  63.             while (res.Read())
  64.             {
  65.                 string a = res["VAL"].ToString();
  66.                 comboBox1.Items.Add(a);
  67.             }
  68.         }
  69.  
  70.         private void button3_Click(object sender, EventArgs e)
  71.         {
  72.             string resss = "";
  73.  
  74.                         // Open SQL Conn
  75.             MySqlConnection MyCon;
  76.             MySqlCommand upit;
  77.             string arg = "datasource=localhost;port=3306;username=root;password=";
  78.             MySqlDataReader res;
  79.             MyCon = new MySqlConnection(arg);
  80.             // SELECT
  81.            
  82.             string insert = "USE recenica; SELECT VAL FROM recenica;";
  83.             upit = new MySqlCommand(insert, MyCon);
  84.             MyCon.Open();
  85.             res = upit.ExecuteReader();
  86.             while (res.Read())
  87.             {
  88.                 string a = res["VAL"].ToString();
  89.                 resss += a;
  90.                 resss += "\n";
  91.             }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.             Document doc = new Document(PageSize.A4);
  98.             currpath = Directory.GetCurrentDirectory();
  99.             var output = new FileStream(currpath + "RECENICE.pdf", FileMode.Create);
  100.             var writer = PdfWriter.GetInstance(doc, output);
  101.  
  102.             doc.AddTitle("Sve recenice iz Baze");
  103.             doc.AddSubject("Evo svih recenica: ---");
  104.  
  105.             doc.AddAuthor("Dragos i Nikola");
  106.  
  107.             doc.Open();
  108.             doc.Add(new Paragraph(resss));
  109.  
  110.             doc.Close();
  111.  
  112.         }
  113.  
  114.  
  115.    
  116.         public  string currpath { get; set; }}
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement