Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zlotaraczka.Model
- {
- public class Worker
- {
- public string name ="";
- public string surname ="";
- public void GetWorkers()
- {
- //string imieszuk = "Baran";
- try
- {
- if (App.connection != null && App.connection.State == ConnectionState.Closed)
- {
- App.connection.Open();
- }
- SqlCommand comm = new SqlCommand("SELECT name FROM worker", App.connection);
- //SqlCommand comm = new SqlCommand("SELECT * from usterka;", App.connection);
- SqlDataReader reader = comm.ExecuteReader();
- if (reader.Read())
- {
- name = reader.GetValue(1).ToString();
- surname = reader.GetValue(2).ToString();
- }
- reader.Close();
- //connection.Close();
- }
- catch (Exception)
- {
- //connection.Close();
- }
- }
- public void AddWorker(int id, string imie, string nazwisko, string rozpoczecie, string zakonczenie)
- {
- try
- {
- SqlDataAdapter adapter = new SqlDataAdapter();
- string select = "INSERT into worker (id_worker, name, surname) values(@id_worker, @name, @surname)";
- SqlCommand cmd = new SqlCommand(select, App.connection);
- if (App.connection != null && App.connection.State == ConnectionState.Closed)
- {
- App.connection.Open();
- }
- SqlCommand comm = new SqlCommand(select, App.connection);
- comm.Parameters.AddWithValue("@id_worker", id);
- comm.Parameters.AddWithValue("@name", imie);
- comm.Parameters.AddWithValue("@surname", nazwisko);
- comm.ExecuteNonQuery();
- App.connection.Close();
- //connection.Close();
- }
- catch (Exception)
- {
- App.connection.Close();
- //connection.Close();
- }
- }
- public void DeleteWorker(int id_worker)
- {
- try
- {
- SqlCommand comm = new SqlCommand("DELETE FROM worker WHERE id_worker='" + id_worker + "'");
- SqlDataAdapter adapter = new SqlDataAdapter();
- App.connection.Open();
- comm.ExecuteNonQuery();
- App.connection.Close();
- //connection.Close();
- }
- catch (Exception)
- {
- App.connection.Close();
- //connection.Close();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement