Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Forms;
- namespace Adatbazis
- {
- static class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new frmBejelentkezes());
- }
- }
- }
- //2.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace Adatbazis
- {
- public partial class frmFoAblak : Form
- {
- private string user;
- private int restr;
- private string connection;
- public string Connection
- {
- get { return connection; }
- set { connection = value; }
- }
- public int Restr
- {
- get { return restr; }
- set { restr = value; }
- }
- public string User
- {
- get { return user; }
- set { user = value; }
- }
- public frmFoAblak()
- {
- InitializeComponent();
- }
- private void btnExit_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void frmFoAblak_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- private void frmFoAblak_Shown(object sender, EventArgs e)
- {
- this.Text = "Nyilvántartás - " + User +
- " a bejelntkezett felhasználó";
- // ha csak sima felhasználó
- if (Restr == 2) {
- menuEgyesevel.Enabled = false;
- importálásToolStripMenuItem.Enabled = false;
- }
- }
- private void menuLista_Click(object sender, EventArgs e)
- {
- frmLista fLista = new frmLista();
- fLista.Connection = this.Connection;
- fLista.ShowDialog();
- }
- private void menuEgyesevel_Click(object sender, EventArgs e)
- {
- frmEgyes fEgyes = new frmEgyes();
- fEgyes.Connection = this.Connection;
- fEgyes.ShowDialog();
- }
- private void exportálásToolStripMenuItem_Click(object sender, EventArgs e)
- {
- frmExport fExport = new frmExport();
- fExport.Connection = this.Connection;
- fExport.ShowDialog();
- }
- private void importálásToolStripMenuItem_Click(object sender, EventArgs e)
- {
- frmImport fImport = new frmImport();
- fImport.Connection = this.Connection;
- fImport.ShowDialog();
- }
- }
- }
- //3.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace Adatbazis
- {
- public partial class frmBejelentkezes : Form
- {
- private string server = "localhost";
- private string uid = "root";
- private string password = "";
- private string database = "proba";
- private string connString = string.Empty;
- private MySqlConnection conn = null;
- private MySqlDataReader dr = null;
- public frmBejelentkezes()
- {
- InitializeComponent();
- }
- private void tbUser_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char) 13 )
- {
- tbPassword.Focus();
- }
- }
- private void tbPassword_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char) 13)
- {
- btnLogin.PerformClick();
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void frmBejelentkezes_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- private void frmBejelentkezes_Shown(object sender, EventArgs e)
- {
- tbUser.Focus();
- }
- private void btnLogin_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(tbUser.Text))
- {
- MessageBox.Show("Felhasználó nevet meg kell adni!",
- "Hiba", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- tbUser.Focus();
- return;
- }
- try
- {
- connString = string.Format(
- "server={0};uid={1};password={2};database={3};",
- server, uid, password, database
- );
- conn = new MySqlConnection(connString);
- conn.Open();
- string select = "select * from users where user=\'" +
- tbUser.Text + "\' and password=\'" + tbPassword.Text + "\'";
- MySqlCommand cmd = new MySqlCommand(select, conn);
- dr = cmd.ExecuteReader();
- int rows = 0;
- while (dr.Read())
- {
- rows++;
- }
- if (rows > 0)
- {
- //MessageBox.Show("Sikeres bejelentkezése!");
- MessageBox.Show("Sikeres belépés!", "Információ",
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- frmFoAblak f = new frmFoAblak();
- f.User = tbUser.Text;
- f.Connection = connString;
- if (dr.GetInt32(3) == 1)
- {
- // admin
- f.Restr = 1;
- //MessageBox.Show("Admin");
- f.BackColor = Color.Red;
- }
- else
- {
- // user
- f.Restr = 2;
- //MessageBox.Show("User");
- }
- f.Show();
- this.Hide();
- }
- else
- {
- MessageBox.Show("Sikertelen belépés!", "Hiba",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch(MySqlException ex)
- {
- MessageBox.Show(ex.Message.ToString(), "Hiba",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- if (dr != null)
- {
- dr.Close();
- }
- if (conn != null)
- {
- conn.Close();
- }
- }
- }
- }
- }
- //4.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace Adatbazis
- {
- public partial class frmEgyes : Form
- {
- private MySqlConnection conn = null;
- private MySqlDataAdapter da = null;
- private MySqlCommand mcd = null;
- private DataSet ds = null;
- private DataTable dt = new DataTable();
- private int i = 0;
- private string connection;
- public string Connection
- {
- get { return connection; }
- set { connection = value; }
- }
- public frmEgyes()
- {
- InitializeComponent();
- }
- public void Zarol()
- {
- btnModosit.Enabled = false;
- btnSzerkeszt.Enabled = false;
- btnTorol.Enabled = false;
- btnFel.Enabled = false;
- }
- public void labelNullazas()
- {
- tbVezeteknev.Text = "";
- tbKeresztnev.Text = "";
- tbTelefon.Text = "";
- tbEmail.Text = "";
- tbID.Text = "";
- }
- public void modMegnyit()
- {
- if (tbVezeteknev.ReadOnly == true)
- {
- tbVezeteknev.ReadOnly = false;
- tbKeresztnev.ReadOnly = false;
- tbTelefon.ReadOnly = false;
- tbEmail.ReadOnly = false;
- btnFirst.Enabled = false;
- btnLast.Enabled = false;
- btnRev.Enabled = false;
- btnFor.Enabled = false;
- btnModosit.Enabled = true;
- btnTorol.Enabled = true;
- btnFel.Enabled = true;
- btnLabelUres.Enabled = true;
- }
- }
- public void modBezar()
- {
- if (tbVezeteknev.ReadOnly == false)
- {
- tbVezeteknev.ReadOnly = true;
- tbKeresztnev.ReadOnly = true;
- tbTelefon.ReadOnly = true;
- tbEmail.ReadOnly = true;
- btnFirst.Enabled = true;
- btnLast.Enabled = true;
- btnRev.Enabled = true;
- btnFor.Enabled = true;
- btnModosit.Enabled = false;
- btnTorol.Enabled = false;
- btnFel.Enabled = false;
- btnLabelUres.Enabled = false;
- }
- }
- public void adatFrissit()
- {
- string select = "select * from names";
- ds = new DataSet();
- dt.Clear();
- da = new MySqlDataAdapter(select, conn);
- da.Fill(dt);
- }
- private void frmEgyes_Shown(object sender, EventArgs e)
- {
- conn = new MySqlConnection(this.Connection);
- try
- {
- string select = "select * from names";
- conn.Open();
- ds = new DataSet();
- da = new MySqlDataAdapter(select, conn);
- da.Fill(dt);
- // hibakezelés ha nincs benne adat
- ShowData();
- if (tbVezeteknev.Text == "")
- {
- Zarol();
- }
- }
- catch (Exception)
- {
- throw;
- }
- btnModosit.Enabled = false;
- btnTorol.Enabled = false;
- btnFel.Enabled = false;
- btnLabelUres.Enabled = false;
- }
- private void btnVisszalepes_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- public void ShowData()
- {
- tbID.Text = dt.Rows[i][0].ToString();
- tbVezeteknev.Text = dt.Rows[i][1].ToString();
- tbKeresztnev.Text = dt.Rows[i][2].ToString();
- tbEmail.Text = dt.Rows[i][4].ToString();
- tbTelefon.Text = dt.Rows[i][3].ToString();
- }
- private void btnFirst_Click(object sender, EventArgs e)
- {
- i = 0;
- ShowData();
- }
- private void btnRev_Click(object sender, EventArgs e)
- {
- if (i != 0)
- {
- i--;
- ShowData();
- }
- }
- private void btnFor_Click(object sender, EventArgs e)
- {
- if (i < dt.Rows.Count - 1)
- {
- i++;
- ShowData();
- }
- else
- {
- MessageBox.Show("Vége");
- }
- }
- private void btnLast_Click(object sender, EventArgs e)
- {
- i = dt.Rows.Count - 1;
- ShowData();
- }
- private void btnSzerkeszt_Click(object sender, EventArgs e)
- {
- modMegnyit();
- }
- private void btnModosit_Click(object sender, EventArgs e)
- {
- string parancs = "update names set veznev='" + tbVezeteknev.Text + "', kernev='" + tbKeresztnev.Text + "', telefon='" + tbTelefon.Text + "', email='" + tbEmail.Text + "' where id=" + tbID.Text + "";
- mcd = new MySqlCommand(parancs, conn);
- if (mcd.ExecuteNonQuery() == 1)
- {
- MessageBox.Show("Siker");
- adatFrissit();
- modBezar();
- }
- }
- private void btnTorol_Click(object sender, EventArgs e)
- {
- string parancs = "delete from names where id=" + tbID.Text + "";
- mcd = new MySqlCommand(parancs, conn);
- if (mcd.ExecuteNonQuery() == 1)
- {
- MessageBox.Show("Siker");
- labelNullazas();
- adatFrissit();
- modBezar();
- }
- }
- private void btnFel_Click(object sender, EventArgs e)
- {
- string parancs = "insert into `names` (`veznev`,`kernev`,`telefon`,`email`) values ('" + tbVezeteknev.Text + "','" + tbKeresztnev.Text + "','" + tbTelefon.Text + "','" + tbEmail.Text + "')";
- mcd = new MySqlCommand(parancs, conn);
- if (mcd.ExecuteNonQuery() == 1)
- {
- MessageBox.Show("Siker");
- labelNullazas();
- adatFrissit();
- modBezar();
- }
- }
- private void btnLabelUres_Click(object sender, EventArgs e)
- {
- labelNullazas();
- }
- private void btnMegse_Click(object sender, EventArgs e)
- {
- adatFrissit();
- modBezar();
- }
- }
- }
- //5.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- using System.IO;
- namespace Adatbazis
- {
- public partial class frmExport : Form
- {
- private MySqlConnection conn = null;
- private MySqlDataAdapter da = null;
- private MySqlCommand mcd = null;
- private DataSet ds = null;
- private DataTable dt = new DataTable();
- private int i = 0;
- private string connection;
- private FileStream file;
- private StreamWriter fileKi;
- public string Connection
- {
- get { return connection; }
- set { connection = value; }
- }
- public frmExport()
- {
- InitializeComponent();
- }
- private void frmExport_Shown(object sender, EventArgs e)
- {
- }
- private void btnKilep_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btnExport_Click(object sender, EventArgs e)
- {
- try
- {
- if (saveDialog.ShowDialog() == DialogResult.OK)
- {
- // adatbázis rész
- conn = new MySqlConnection(this.Connection);
- string select = "select * from names";
- conn.Open();
- ds = new DataSet();
- da = new MySqlDataAdapter(select, conn);
- da.Fill(dt);
- // file rész
- file = new FileStream(saveDialog.FileName, FileMode.Create);
- fileKi = new StreamWriter(file);
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- string adat = "";
- for (int j = 0; j < 5; j++)
- {
- if (j != 4)
- {
- adat += dt.Rows[i][j].ToString() + ",";
- }
- else
- {
- adat += dt.Rows[i][j].ToString();
- }
- }
- fileKi.WriteLine(adat);
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- if (fileKi != null)
- {
- fileKi.Close();
- file.Close();
- MessageBox.Show("Bezárva!");
- }
- }
- }
- }
- }
- //6.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace Adatbazis
- {
- public partial class frmLista : Form
- {
- private MySqlConnection conn = null;
- private MySqlDataAdapter da = null;
- private DataSet ds = null;
- private string connection;
- public string Connection
- {
- get { return connection; }
- set { connection = value; }
- }
- public frmLista()
- {
- InitializeComponent();
- }
- private void frmLista_FormClosing(object sender, FormClosingEventArgs e)
- {
- }
- private void btnClose_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void frmLista_Shown(object sender, EventArgs e)
- {
- conn = new MySqlConnection(this.Connection);
- try
- {
- string select = "select veznev, kernev, telefon, email from names";
- conn.Open();
- ds = new DataSet();
- da = new MySqlDataAdapter(select, conn);
- da.Fill(ds, "names");
- dgvAdatok.DataSource = ds.Tables["names"];
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement