Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

Please, do not DELETE until 30th of May.

$
0
0
Please, do NOT DELETE this thread/discussion until 30th of May, this code is really important for me and this is the only one place where it can be stored, don't ask why ... :D

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 System.Data.SqlClient; using System.Data.Sql; namespace

{ public partial class MkuN : Form { string connectionString = Properties.Settings.Default.connectionString; DB_metody db; public MkuN() { db = new DB_metody(connectionString); InitializeComponent(); } int x; private void comboBox1_Click(object sender, EventArgs e) { comboBox1.Items.Clear(); SqlConnection sqlConn = new SqlConnection(connectionString); sqlConn.Open(); SqlCommand cmd = new SqlCommand("SELECT id_prijemka,date,id_sklad FROM Prijemka;", sqlConn); SqlDataReader srdr = cmd.ExecuteReader(); srdr.Read(); try { while (srdr.Read() != null) { comboBox1.Items.Add(srdr.GetValue(0) + " " + srdr.GetValue(1) + " " + srdr.GetValue(2)); } } catch (Exception ex) { srdr.Close(); } sqlConn.Close(); } private void button1_Click(object sender, EventArgs e) { string text = comboBox1.Text; string text2 = comboBox2.Text; string pom = ""; string pom2 = ""; for (int i = 0; i < text.Length; i++) { if (text[i] == ' ') { break; } pom += text[i]; } for (int z = 0; z < text2.Length; z++) { if (text2[z] == ' ') { break; } pom2 += text2[z]; } SqlConnection sqlConn = new SqlConnection(connectionString); sqlConn.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Vaz_tab WHERE prijemka_id = '" + pom + "';", sqlConn); DataTable t = new DataTable(); da.Fill(t); dataGridView1.DataSource = t; } private void textBox1_TextChanged(object sender, EventArgs e) { } private void comboBox2_Click(object sender, EventArgs e) { comboBox2.Items.Clear(); SqlConnection sqlConn = new SqlConnection(connectionString); sqlConn.Open(); SqlCommand cmd = new SqlCommand("SELECT id_material,typ_id,nazev,pocet,cena FROM Material;", sqlConn); SqlDataReader srdr = cmd.ExecuteReader(); try { while (srdr.Read()) { comboBox2.Items.Add(srdr.GetValue(0) + " " + srdr.GetValue(1) + " " + srdr.GetValue(2) + " " + srdr.GetValue(3) + " " + srdr.GetValue(4)); } } catch (Exception ex) { srdr.Close(); } sqlConn.Close(); } private void MkuN_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { string text = comboBox1.Text; string text2 = comboBox2.Text; string pom = ""; string pom2 = ""; for (int i = 0; i < text.Length; i++) { if (text[i] == ' ') { break; } pom += text[i]; } for (int z = 0; z < text2.Length; z++) { if (text2[z] == ' ') { break; } pom2 += text2[z]; } int id_matik = int.Parse(pom2); int id_prije = int.Parse(pom); int id_pocet = int.Parse(textBox1.Text); using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand("my_sp_AddNewMat", con)) { try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@id_mat", SqlDbType.Int).Value = id_matik; cmd.Parameters.Add("@id_Prijemky", SqlDbType.Int).Value = id_prije; cmd.Parameters.Add("@pocet_mat", SqlDbType.Int).Value = id_pocet; con.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("Úspěšně přidáno!"); } catch(Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show("Nelze přidat, akce ukončena!"); } } } SqlConnection sqlConn = new SqlConnection(connectionString); sqlConn.Open(); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Vaz_tab WHERE prijemka_id = '" + pom + "';", sqlConn); DataTable t = new DataTable(); da.Fill(t); dataGridView1.DataSource = t; comboBox2.Items.Clear(); textBox1.Clear(); } private void button3_Click(object sender, EventArgs e) { AddPrij add = new AddPrij(); add.Show(); } private void button4_Click(object sender, EventArgs e) { this.Hide(); } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } } }


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace 
{
    class DB_metody
    {
   string key = "";
   SqlConnection sqlconn;
   public SqlConnection Sqlconn
   {
       get { return sqlconn; }
       set { sqlconn = value; }
   }
        public DB_metody(string key)
        {
            this.key = key;
            sqlconn = new SqlConnection(key);        
        }
        public void InsertMat(int typ_id, string nazev, int cena)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("INSERT INTO Material (typ_id,nazev,cena,pocet) VALUES ('" + typ_id + "','" + nazev + "','" + cena + "','" +0+ "');", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void InsertSklad(string ulice, string mesto, string c_pop, string psc)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("INSERT INTO Sklad (ulice,mesto,c_pop,psc) VALUES ('" + ulice + "','" + mesto + "','" + c_pop + "','" + psc+"');", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void InsertPrijemka(string datum, int id_sklad, int zamestnanec_id)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("INSERT INTO Prijemka (date, id_sklad,zamestnanec_id) VALUES ('" + datum + "','" + id_sklad + "','" + zamestnanec_id +"');", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void InsertZamestnanci(string jmeno,string prijmeni, string rod_cislo)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("INSERT INTO Zamestnanci (jmeno, prijmeni,rod_cislo) VALUES ('" + jmeno + "','" + prijmeni + "','" + rod_cislo + "');", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
       /* public void PrijemZbozi(int prijemka_id, int material_id, int pocet_kusu)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("INSERT INTO Vaz_tab (prijemka_id, material_id, pocet_kusu) VALUES ('" + prijemka_id + "','" + material_id + "','" + pocet_kusu + "');", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        */
        // Prijem zbozi netreba, zajistuje procedura na serveru my_sp_AddNewMat
            public void AddTyp(string nazev)
            {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("INSERT INTO Typ_materialu (nazev) VALUES ('" + nazev + "');", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void DeleteMaterial(int id_material)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("DELETE FROM Material WHERE id_material=" + id_material + ";", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void DeleteSklad(int id_sklad)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("DELETE FROM Sklad WHERE id_sklad=" + id_sklad + ";", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void DeletePrijemka(int id_prijemka)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("DELETE FROM Prijemka WHERE id_prijemka=" + id_prijemka + ";", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void DeleteVaz(int id_vaz_tab)
        {
            try
            {
                Pripojeni();
                SqlCommand cmd = new SqlCommand("DELETE FROM Vaz_tab WHERE id_vaz_tab=" + id_vaz_tab + ";", sqlconn);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                KonecPripojeni();
            }
        }
        public void Pripojeni()
        {
            sqlconn.Open();
        }
        public void KonecPripojeni()
        {
            sqlconn.Close();
        }
    }
}

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 System.Configuration; using System.Data.Sql; using System.Data.SqlClient; namespace

<appSettings><add key="P@ssw0rd" value="Data Source=NAZEVPC\INSTANCE;Initial Catalog=DATABAZE;User ID=sa;Password=pass"/></appSettings></configuration>

{ public partial class Prihlasovani : Form { SqlConnection conn; public Prihlasovani() { InitializeComponent(); } private void button1_Click_1(object sender, EventArgs e) { string connectionString; bool ConnEnabled = false; List<string[]> cstringy = new List<string[]>(); for (int i = 0; i < ConfigurationSettings.AppSettings.Keys.Count; i++) { cstringy.Add(ConfigurationSettings.AppSettings.GetValues(i)); } for (int i = 0; i < ConfigurationSettings.AppSettings.Keys.Count; i++) { string vstup = maskedTextBox1.Text; for (int z = 0; z < ConfigurationSettings.AppSettings.Keys.Count; z++) { if (vstup == ConfigurationSettings.AppSettings.AllKeys.ElementAt(i).ToString()) { string[] f = cstringy.ElementAt(i); connectionString = f[0]; ConnEnabled = true; conn = new SqlConnection(connectionString); conn.Open(); } } if (ConnEnabled) { MessageBox.Show("Připojení povoleno"); Menu menu = new Menu(); menu.Show(); this.Hide(); return; } } MessageBox.Show("Přihlášení NEBYLO povoleno z důvodu špatně zadaných údajů"); }



Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>