Пример #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();
        }
Пример #2
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 + ")");
                }
            }
        }
Пример #3
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";
        }
Пример #4
0
        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();
        }
Пример #5
0
        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(',', '.'));
                }
            }
        }
Пример #6
0
 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");
     }
 }
Пример #7
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");
     }
 }
Пример #8
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();
     }
 }
Пример #9
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        //[STAThread]
        static void Main()
        {
            CultureInfo myCulture = (CultureInfo)Application.CurrentCulture.Clone();

            myCulture.NumberFormat.NumberDecimalSeparator = ".";
            myCulture.NumberFormat.NumberDecimalDigits    = 2;

            Thread.CurrentThread.CurrentCulture   = myCulture;
            Thread.CurrentThread.CurrentUICulture = myCulture;

            PostgreSQL.connect("shop", "localhost", "postgres", "qwe");

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new AdminWindow());
            //Application.Run(new UserWindow(2));
            Application.Run(new LoginWindow());

            PostgreSQL.close();
        }
Пример #10
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;
        }
Пример #11
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");
            }
        }
Пример #12
0
        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();
        }