root/trunk/BazaZamowien/Premie/AdminFormPremie.cs @ 915

Wersja 710, 5.8 KB (wprowadzona przez dorota, 18 years temu)

baza zamowien i premii 1.0.0.1

Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Data.SqlClient;
6using System.Drawing;
7using System.Text;
8using System.Windows.Forms;
9using BazaZamowien.Classes;
10using BazaZamowien.PREMIEDataSetTableAdapters;
11
12namespace BazaZamowien
13{
14   
15    public partial class AdminFormPremie : Form
16    {
17        UsersTableAdapter usersAdapter = new UsersTableAdapter();
18        GrupyTableAdapter grupyAdapter = new GrupyTableAdapter();
19        GrupaDzialTableAdapter grupyDzialAdapter = new GrupaDzialTableAdapter();
20        DzialyTableAdapter dzialAdapter = new DzialyTableAdapter();
21       
22        public AdminFormPremie()
23        {
24            InitializeComponent();
25
26            usersAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
27            grupyAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
28            grupyDzialAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
29            dzialAdapter.Connection.ConnectionString = ConnString.getConnString().PremieConnStr;
30        }
31
32        private void AdminFormPremie_Load(object sender, EventArgs e)
33        {
34            dzialyWGrupieListBox.DisplayMember = "Dzial";
35            dzialyWGrupieListBox.ValueMember = "IDE";
36
37            grupyListBox.SelectedValueChanged += new System.EventHandler(this.grupyListBox_SelectedValueChanged);
38
39            usersListBox.DisplayMember = "login";
40            usersListBox.ValueMember = "IDEPracownik";
41            usersListBox.DataSource = usersAdapter.GetData();
42
43            grupyListBox.DisplayMember = "NazwaGrupy";
44            grupyListBox.ValueMember = "IDE";
45            grupyListBox.DataSource = grupyAdapter.GetData();
46
47            dzialyListBox.DisplayMember = "Dzial";
48            dzialyListBox.ValueMember = "IDE";           
49            dzialyListBox.DataSource = dzialAdapter.GetData();
50           
51        }
52
53        private void edytujUzytkownikaButton_Click(object sender, EventArgs e)
54        {
55            if (usersListBox.SelectedValue != null)
56            {
57                int ide = Convert.ToInt32(usersListBox.SelectedValue);
58                UserAddFormPremie userAddFromPremie = new UserAddFormPremie(ide);
59                userAddFromPremie.ShowDialog();
60            }
61        }
62
63        private void dodajUzytkownikaButton_Click(object sender, EventArgs e)
64        {
65            UserAddFormPremie userAddFromPremie = new UserAddFormPremie(0);
66            userAddFromPremie.ShowDialog();
67        }
68
69        private void grupyListBox_SelectedValueChanged(object sender, EventArgs e)
70        {
71            if (grupyListBox.SelectedValue != null)
72            {
73                int IDEgrupy = Convert.ToInt32(grupyListBox.SelectedValue);
74                dzialyWGrupieListBox.DataSource = dzialAdapter.GetDataByIDEGrupy(IDEgrupy);
75            }
76        }
77
78        private void dodajGrupeButton_Click(object sender, EventArgs e)
79        {
80            if (textBox1.Text != "")
81            {
82                try
83                {
84                    grupyAdapter.Insert(textBox1.Text);
85                    grupyListBox.DataSource = grupyAdapter.GetData();
86                }
87                catch (SqlException e1)
88                {
89                    if (e1.Number == 2627)
90                    {
91                        MessageBox.Show("Istnieje ju¿ grupa o takiej nazwie");
92                    }
93                }
94
95            }
96        }
97
98        private void usunGrupeButton_Click(object sender, EventArgs e)
99        {
100            if (grupyListBox.SelectedValue != null)
101            {
102                int IDEgrupy = Convert.ToInt32(grupyListBox.SelectedValue);
103
104                if (PremieUtils.iloscDzialowWGrupie(IDEgrupy) == 0 && PremieUtils.iloscUzytkownikowWGrupie(IDEgrupy)==0 )
105                {
106                    grupyAdapter.Delete(IDEgrupy);
107                    grupyListBox.DataSource = grupyAdapter.GetData();
108                }
109                else
110                {
111                    MessageBox.Show("Nie mo¿na usun¹æ grupy do której przypisano u¿ytkowników lub dzia³y.");
112                }
113            }
114
115        }
116
117        private void dodajDzialDoGrupyButton_Click(object sender, EventArgs e)
118        {
119            if ((grupyListBox.SelectedValue != null) & (dzialyListBox.SelectedValue != null))
120            {
121                try
122                {
123                    int IDEGrupy = Convert.ToInt32(grupyListBox.SelectedValue);
124                    int IDEDzialu = Convert.ToInt32(dzialyListBox.SelectedValue);
125                    grupyDzialAdapter.Insert(IDEGrupy, IDEDzialu);
126                    dzialyWGrupieListBox.DataSource = dzialAdapter.GetDataByIDEGrupy(IDEGrupy);
127                }
128                catch (SqlException e1)
129                {
130                    if (e1.Number == 2627)
131                    {
132                        MessageBox.Show("Grupie ju¿ przydzielono ten dzia³");
133                    }
134                }
135            }
136        }
137
138        private void usunDzialZGrupyButton_Click(object sender, EventArgs e)
139        {
140            if ((grupyListBox.SelectedValue != null) & (dzialyWGrupieListBox.SelectedValue != null))
141            {
142                try
143                {
144                    int IDEGrupy = Convert.ToInt32(grupyListBox.SelectedValue);
145                    int IDEDzialu = Convert.ToInt32(dzialyWGrupieListBox.SelectedValue);
146                    grupyDzialAdapter.Delete(IDEGrupy, IDEDzialu);
147                    dzialyWGrupieListBox.DataSource = dzialAdapter.GetDataByIDEGrupy(IDEGrupy);
148                }
149                catch (SqlException e1)
150                {
151                }
152            }
153        }
154
155    }
156}
Notatka: Zobacz TracBrowser aby uzyskać więcej informacji.