Exemple #1
0
        protected override void okButton_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count == 0)
            {
                MessageBox.Show("Nie wybrano żadnych produktów");
            }
            else
            {
                string price     = priceTextBox.Text.Substring(0, priceTextBox.Text.IndexOf(' '));
                int    noOfOrder = (int)PostgreSQL.executeScalar("INSERT INTO zamowienie_dostawy(kod_dost, koszt, status) values("
                                                                 + getSupplierId() + ",'"
                                                                 + price + "','"
                                                                 + statusComboBox.Text + "') "
                                                                 + "RETURNING nr_zamowienia"
                                                                 );

                foreach (ListViewItem item in listView1.Items)
                {
                    PostgreSQL.executeCommand("INSERT INTO zamowienie_dostawy_zawiera_produkt values("
                                              + item.SubItems[0].Text + ","
                                              + noOfOrder + ","
                                              + item.SubItems[2].Text + ")"
                                              );

                    PostgreSQL.executeScalar("UPDATE dostawca_dostarcza_produkt SET "
                                             + "max_ilosc=max_ilosc-" + item.SubItems[2].Text + " "
                                             + "WHERE kod_dost=" + getSupplierId() + " "
                                             + "AND kod_prod=" + item.SubItems[0].Text
                                             );
                }
            }

            this.Close();
        }
        protected override void okButton_Click(object sender, EventArgs e)
        {
            string newStatus = statusComboBox.Text;

            if (newStatus == "Opłacone")
            {
                newStatus = "Oplacone";
            }
            else if (newStatus == "Wysłane")
            {
                newStatus = "Wyslane";
            }

            if (newStatus == "Skompletowane" || newStatus == "Wyslane")
            {
                if (haveEnoughProducts())
                {
                    foreach (ListViewItem i in listView1.Items)
                    {
                        PostgreSQL.executeCommand("UPDATE produkt SET ilosc=ilosc-" + i.SubItems[2].Text + " WHERE kod_prod=" + i.SubItems[0].Text);
                    }
                    PostgreSQL.executeCommand("UPDATE zamowienie_detaliczne SET status='" + newStatus + "' WHERE nr_zamowienia=" + orderId);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("W magazynie nie ma wystarczającej ilości produktów");
                }
            }
            else
            {
                PostgreSQL.executeCommand("UPDATE zamowienie_detaliczne SET status='" + newStatus + "' WHERE nr_zamowienia=" + orderId);
                this.Close();
            }
        }
Exemple #3
0
 private void removeProductButton_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         PostgreSQL.executeCommand("DELETE FROM produkt WHERE kod_prod=" + listView1.SelectedItems[0].Text);
         updateListView1();
     }
 }
Exemple #4
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(loginTextBox.Text) ||
                string.IsNullOrWhiteSpace(loginTextBox.Text) ||
                string.IsNullOrEmpty(passwordTextBox.Text) ||
                string.IsNullOrWhiteSpace(passwordTextBox.Text))
            {
                MessageBox.Show("Login i hasło nie mogą być puste!");
            }
            else
            {
                try
                {
                    int.Parse(loginTextBox.Text);

                    NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT haslo, typuzytkownika FROM uzytkownik WHERE kod_uz=" + loginTextBox.Text);
                    reader.Read();
                    byte[]        password     = (byte[])reader[0];
                    string        userType     = reader[1].ToString();
                    HashAlgorithm alg          = SHA1.Create();
                    byte[]        passwordHash = alg.ComputeHash(Encoding.UTF8.GetBytes(passwordTextBox.Text));
                    reader.Close();

                    if (!passwordIsGood(password, passwordHash))
                    {
                        MessageBox.Show("Błąd logowania, zły login lub hasło");
                    }
                    else
                    {
                        this.Hide();
                        if (userType == "Admin")
                        {
                            AdminWindow window = new AdminWindow();
                            window.ShowDialog();
                        }
                        else if (userType == "Uzytkownik")
                        {
                            UserWindow window = new UserWindow(int.Parse(loginTextBox.Text));
                            window.ShowDialog();
                        }
                        else
                        {
                            EmployeeWindow window = new EmployeeWindow();
                            window.ShowDialog();
                        }
                        this.Close();
                    }
                }
                catch (FormatException ex)
                {
                    MessageBox.Show("Zabronione znaki w polu ID (" + ex.Message + ")");
                }
                catch (InvalidOperationException ex)
                {
                    MessageBox.Show("Nie ma w bazie użytkownika o podanym numerze ID (" + ex.Message + ")");
                }
            }
        }
        public ClientOrderDetails(ListViewItem item)
        {
            orderId   = int.Parse(item.SubItems[0].Text);
            oldStatus = item.SubItems[3].Text;
            InitializeComponent();

            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM uzytkownik WHERE kod_uz=" + item.SubItems[1].Text);

            while (reader.Read())
            {
                clientComboBox.Items.Add(reader[0] + ". " + reader[1] + " " + reader[2]);
            }
            clientComboBox.SelectedIndex = 0;
            clientComboBox.Enabled       = false;

            priceTextBox.Text = item.SubItems[2].Text;

            string status = item.SubItems[3].Text;

            if (status == "Nowe")
            {
                statusComboBox.Items.Add("Nowe");
                statusComboBox.Items.Add("Oplacone");
                statusComboBox.Items.Add("Skompletowane");
                statusComboBox.Items.Add("Wyslane");
            }
            else if (status == "Oplacone")
            {
                statusComboBox.Items.Add("Oplacone");
                statusComboBox.Items.Add("Skompletowane");
                statusComboBox.Items.Add("Wyslane");
            }
            else if (status == "Skompletowane")
            {
                statusComboBox.Items.Add("Skompletowane");
                statusComboBox.Items.Add("Wyslane");
            }
            else
            {
                statusComboBox.Items.Add("Wyslane");
            }
            statusComboBox.SelectedIndex = 0;

            reader = PostgreSQL.executeCommand("SELECT p.kod_prod, p.nazwa, z.ilosc, p.cena FROM zamowienie_detaliczne_zawiera_produkt z "
                                               + "JOIN produkt p USING(kod_prod) "
                                               + "WHERE nr_zamowienia=" + orderId
                                               );
            while (reader.Read())
            {
                ListViewItem i = listView1.Items.Add(new ListViewItem(reader[0].ToString()));
                i.SubItems.Add(reader[1].ToString());
                i.SubItems.Add(reader[2].ToString());
                i.SubItems.Add(((int)reader[2] * (double)reader[3]).ToString());
            }

            addButton.Hide();
        }
Exemple #6
0
        private void saveChangesButton_Click(object sender, EventArgs e)
        {
            PostgreSQL.executeCommand("UPDATE dostawca SET "
                                      + "nazwa='" + supplierNameTextBox.Text + "',"
                                      + "nr_konta=" + supplierAccountTextBox.Text
                                      + "WHERE kod_dost=" + supplierIdTextBox.Text
                                      );

            this.Close();
        }
Exemple #7
0
 private void removeProductButton_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count > 0)
     {
         ListViewItem item = listView1.SelectedItems[0];
         PostgreSQL.executeCommand("DELETE FROM dostawca_dostarcza_produkt WHERE "
                                   + "kod_dost=" + supplierIdTextBox.Text
                                   + " AND kod_prod=" + item.SubItems[0].Text);
         updateListView();
     }
 }
Exemple #8
0
        public UserWindow(int id)
        {
            InitializeComponent();
            userId         = id;
            chosenProducts = new Dictionary <int, int>();
            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM uzytkownik WHERE kod_uz=" + userId);

            reader.Read();
            titleLabel.Text = reader[1] + " " + reader[2] + "    ";
            reader.Close();
        }
Exemple #9
0
        private void ClientOrdersWindow_Load(object sender, EventArgs e)
        {
            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM zamowienie_detaliczne WHERE kod_uz=" + userId);

            while (reader.Read())
            {
                ListViewItem item = listView1.Items.Add(new ListViewItem(reader[0].ToString()));
                item.SubItems.Add(reader[2].ToString());
                item.SubItems.Add(reader[3].ToString());
                item.SubItems.Add(reader[4].ToString());
            }
        }
Exemple #10
0
        private void updateListView()
        {
            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM produkt");

            while (reader.Read())
            {
                ListViewItem item = listView1.Items.Add(new ListViewItem(reader[0].ToString()));
                item.SubItems.Add(reader[3].ToString());
                item.SubItems.Add(reader[2].ToString());
                item.SubItems.Add(reader[1].ToString());
                item.SubItems.Add(reader[4].ToString());
            }
        }
Exemple #11
0
        private void updateListView1()
        {
            listView1.Items.Clear();
            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM produkt");

            while (reader.Read())
            {
                ListViewItem item = listView1.Items.Add(reader[0].ToString());
                for (int i = 1; i < reader.FieldCount; ++i)
                {
                    item.SubItems.Add(reader[i].ToString());
                }
            }
        }
        public DeliveryOrder_Details(ListViewItem order)
        {
            orderId   = int.Parse(order.SubItems[0].Text);
            oldStatus = order.SubItems[3].Text;

            supplierComboBox.Items.Add(order.SubItems[1].Text + ". "
                                       + PostgreSQL.executeScalar("SELECT nazwa FROM dostawca WHERE kod_dost=" + order.SubItems[1].Text));
            supplierComboBox.Enabled       = false;
            supplierComboBox.SelectedIndex = 0;

            priceTextBox.Text    = order.SubItems[2].Text;
            priceTextBox.Enabled = false;

            string status = order.SubItems[3].Text;

            if (status == "Nowe")
            {
                statusComboBox.Items.Add("Nowe");
                statusComboBox.Items.Add("Opłacone");
                statusComboBox.Items.Add("Otrzymane");
            }
            else if (status == "Oplacone")
            {
                statusComboBox.Items.Add("Opłacone");
                statusComboBox.Items.Add("Otrzymane");
            }
            else
            {
                statusComboBox.Items.Add("Otrzymane");
            }
            statusComboBox.SelectedIndex = 0;

            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT kod_prod, nazwa, z.ilosc, d.cena_hurt "
                                                                + "FROM zamowienie_dostawy_zawiera_produkt z "
                                                                + "JOIN produkt p USING(kod_prod) "
                                                                + "JOIN dostawca_dostarcza_produkt d USING(kod_prod) "
                                                                + "WHERE nr_zamowienia=" + order.SubItems[0].Text + " "
                                                                + "AND kod_dost=" + order.SubItems[1].Text
                                                                );

            while (reader.Read())
            {
                ListViewItem item = listView1.Items.Add(new ListViewItem(reader[0].ToString()));
                item.SubItems.Add(reader[1].ToString());
                item.SubItems.Add(reader[2].ToString());
                item.SubItems.Add(((int)reader[2] * (double)reader[3]).ToString());
            }

            addButton.Hide();
        }
        private void updateListView4()
        {
            listView4.Items.Clear();

            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM zamowienie_detaliczne");

            while (reader.Read())
            {
                ListViewItem item = listView4.Items.Add(reader[0].ToString());
                for (int i = 1; i < reader.FieldCount; ++i)
                {
                    item.SubItems.Add(reader[i].ToString().Replace(',', '.'));
                }
            }
        }
Exemple #14
0
        private void CartWindow_Load(object sender, EventArgs e)
        {
            foreach (var product in chosenProducts)
            {
                NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT kod_prod, nazwa, cena FROM produkt WHERE kod_prod=" + product.Key);
                while (reader.Read())
                {
                    ListViewItem item = listView1.Items.Add(reader[0].ToString());
                    item.SubItems.Add(reader[1].ToString());
                    item.SubItems.Add(product.Value.ToString());
                    item.SubItems.Add(reader[2].ToString());

                    updateTotalPrice();
                }
            }
        }
Exemple #15
0
        private void updateListView()
        {
            listView1.Items.Clear();
            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT p.kod_prod, p.nazwa, d.max_ilosc, d.cena_hurt FROM produkt p join dostawca_dostarcza_produkt d using(kod_prod) WHERE kod_dost=" + supplierIdTextBox.Text);

            while (reader.Read())
            {
                ListViewItem item = listView1.Items.Add(reader[0].ToString());
                for (int j = 1; j < reader.FieldCount; ++j)
                {
                    item.SubItems.Add(reader[j].ToString().Replace(',', '.'));
                }
            }

            listView1.Refresh();
        }
 public override void updateProductButton_MouseClick(object sender, MouseEventArgs e)
 {
     try
     {
         PostgreSQL.executeCommand("INSERT INTO produkt(cena, opis, nazwa, ilosc) VALUES ("
                                   + float.Parse(priceBox.Text.Replace(',', '.')) + ","
                                   + "'" + describeBox.Text + "',"
                                   + "'" + nameBox.Text + "',"
                                   + int.Parse(countBox.Text) + ")"
                                   );
         this.Close();
     }
     catch (FormatException ex)
     {
         MessageBox.Show(ex.Message + "\n");
     }
 }
Exemple #17
0
        public SupplierProductForm(string id)
        {
            supplierId = id;
            InitializeComponent();

            NpgsqlDataReader reader = PostgreSQL.executeCommand("(SELECT kod_prod, nazwa FROM produkt) "
                                                                + "EXCEPT (SELECT kod_prod, nazwa FROM dostawca_dostarcza_produkt NATURAL JOIN produkt WHERE kod_dost=" + id + ")");

            while (reader.Read())
            {
                productComboBox.Items.Add(reader[0] + ". " + reader[1]);
            }
            if (productComboBox.Items.Count > 0)
            {
                productComboBox.SelectedIndex = 0;
            }
        }
 public override void updateProductButton_MouseClick(object sender, MouseEventArgs e)
 {
     try
     {
         PostgreSQL.executeCommand("UPDATE produkt SET "
                                   + "cena=" + float.Parse(priceBox.Text.Replace(',', '.')) + ","
                                   + "opis='" + describeBox.Text + "',"
                                   + "nazwa='" + nameBox.Text + "',"
                                   + "ilosc=" + int.Parse(countBox.Text) + " "
                                   + "WHERE kod_prod=" + item.SubItems[0].Text
                                   );
         this.Close();
     }
     catch (FormatException ex)
     {
         MessageBox.Show(ex.Message + "\n");
     }
 }
Exemple #19
0
 private void okButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(supplierNameTextBox.Text))
     {
         MessageBox.Show("Pole 'Nazwa' nie może być puste!");
     }
     else if (string.IsNullOrWhiteSpace(supplierAccountTextBox.Text))
     {
         MessageBox.Show("Pole 'Numer konta' nie może byc puste!");
     }
     else
     {
         PostgreSQL.executeCommand("INSERT INTO dostawca(nazwa, nr_konta) VALUES ("
                                   + "'" + supplierNameTextBox.Text + "',"
                                   + "'" + supplierAccountTextBox.Text + "')"
                                   );
         this.Close();
     }
 }
Exemple #20
0
        private void AddSupplierOrder_Load(object sender, EventArgs e)
        {
            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT * FROM produkt NATURAL JOIN dostawca_dostarcza_produkt WHERE kod_dost=" + supplierId);

            while (reader.Read())
            {
                if (!forbiddenProducts.Contains((int)reader[0]))
                {
                    productComboBox.Items.Add(reader[0] + ". " + reader[3]);
                }
            }

            if (productComboBox.Items.Count > 0)
            {
                productComboBox.SelectedItem = productComboBox.Items[0];
            }
            else
            {
                MessageBox.Show("Ten dostawca nie dostarcza żadnych produktów");
            }
        }
Exemple #21
0
        private void okButton_Click(object sender, EventArgs e)
        {
            try
            {
                string product = productComboBox.Items[productComboBox.SelectedIndex].ToString();
                product = product.Substring(0, product.IndexOf('.'));

                PostgreSQL.executeCommand("INSERT INTO dostawca_dostarcza_produkt values("
                                          + supplierId + ","
                                          + product + ","
                                          + float.Parse(priceTextBox.Text) + ","
                                          + int.Parse(countTextBox.Text) + ")"
                                          );

                this.Close();
            }
            catch (FormatException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #22
0
        public DeliveryOrder_Add()
        {
            InitializeComponent();
            alreadySelectedProducts = new List <int>();

            NpgsqlDataReader reader = PostgreSQL.executeCommand("SELECT kod_dost, nazwa FROM dostawca");

            while (reader.Read())
            {
                supplierComboBox.Items.Add(reader[0] + ". " + reader[1]);
            }

            if (supplierComboBox.Items.Count > 0)
            {
                supplierComboBox.SelectedIndex = 0;
            }

            statusComboBox.Enabled = false;
            statusComboBox.Items.Add("Nowe");
            statusComboBox.SelectedIndex = 0;
        }
Exemple #23
0
        private void removeOrderButton_Click(object sender, EventArgs e)
        {
            if (listView3.SelectedItems.Count > 0)
            {
                string orderId    = listView3.SelectedItems[0].SubItems[0].Text;
                string supplierId = listView3.SelectedItems[0].SubItems[1].Text;

                if (listView3.SelectedItems[0].SubItems[3].Text == "Nowe")
                {
                    Dictionary <string, string> numberToAdd = new Dictionary <string, string>();
                    NpgsqlDataReader            reader      = PostgreSQL.executeCommand("SELECT * FROM zamowienie_dostawy_zawiera_produkt WHERE nr_zamowienia=" + orderId);
                    while (reader.Read())
                    {
                        numberToAdd[reader[0].ToString()] = reader[2].ToString();
                    }

                    foreach (var pair in numberToAdd)
                    {
                        PostgreSQL.executeCommand("UPDATE dostawca_dostarcza_produkt "
                                                  + "SET max_ilosc=max_ilosc+" + pair.Value + " "
                                                  + "WHERE kod_dost=" + supplierId + " "
                                                  + "AND kod_prod=" + pair.Key
                                                  );
                    }

                    PostgreSQL.executeCommand("DELETE FROM zamowienie_dostawy_zawiera_produkt WHERE nr_zamowienia=" + orderId);
                    PostgreSQL.executeCommand("DELETE FROM zamowienie_dostawy WHERE nr_zamowienia=" + orderId);

                    updateListView3();
                }
                else
                {
                    MessageBox.Show("Nie można usunąć zamówienia, które zostało opłacone lub dostarczone");
                }
            }
        }
Exemple #24
0
        private void cartButton_Click(object sender, EventArgs e)
        {
            CartWindow window = new CartWindow(chosenProducts);

            if (window.ShowDialog() == DialogResult.OK)
            {
                int orderId = (int)PostgreSQL.executeScalar("INSERT INTO zamowienie_detaliczne(kod_uz, koszt, status) values ("
                                                            + userId + ","
                                                            + window.totalPrice + ","
                                                            + "'Nowe') RETURNING nr_zamowienia");

                foreach (var product in chosenProducts)
                {
                    PostgreSQL.executeCommand("INSERT INTO zamowienie_detaliczne_zawiera_produkt values("
                                              + product.Key + ","
                                              + orderId + ","
                                              + product.Value + ")"
                                              );
                }

                chosenProducts.Clear();
                cartButton.Text = "Koszyk";
            }
        }
        protected override void okButton_Click(object sender, EventArgs e)
        {
            string newStatus;

            if (statusComboBox.Text == "Opłacone")
            {
                newStatus = "Oplacone";
            }
            else
            {
                newStatus = statusComboBox.Text;
            }
            PostgreSQL.executeCommand("UPDATE zamowienie_dostawy SET status='" + newStatus + "' WHERE nr_zamowienia=" + orderId);

            if (newStatus == "Otrzymane" && oldStatus != "Otrzymane")
            {
                foreach (ListViewItem item in listView1.Items)
                {
                    PostgreSQL.executeCommand("UPDATE produkt SET ilosc=ilosc+" + item.SubItems[2].Text + " WHERE kod_prod=" + item.SubItems[0].Text);
                }
            }

            this.Close();
        }