Example #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();
        }
Example #2
0
        private void productComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int max = (int)PostgreSQL.executeScalar("SELECT max_ilosc FROM dostawca_dostarcza_produkt WHERE kod_prod=" + getProductId() + " AND kod_dost=" + supplierId);

            currentPrice = (double)PostgreSQL.executeScalar("SELECT cena_hurt FROM dostawca_dostarcza_produkt WHERE kod_prod=" + getProductId() + " AND kod_dost=" + supplierId);

            countUpDown.Maximum = max;
            priceTextBox.Text   = (currentPrice * (float)countUpDown.Value).ToString() + " zl";
        }
 private bool haveEnoughProducts()
 {
     foreach (ListViewItem item in listView1.Items)
     {
         int noOfProducts = (int)PostgreSQL.executeScalar("SELECT ilosc FROM produkt WHERE kod_prod=" + item.SubItems[0].Text);
         if (noOfProducts < int.Parse(item.SubItems[2].Text))
         {
             return(false);
         }
     }
     return(true);
 }
        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();
        }
Example #5
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";
            }
        }