Example #1
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            mainPage mainpage = new mainPage();
            //check this stockroom is already exist?
            string          checkId = $"SELECT count(id) as kontrol FROM stockroom WHERE id = {int.Parse(cmbId.SelectedItem.ToString())} OR name = '{txtName.Text}'";
            MySqlDataReader reader  = database.Reader(checkId);

            count();

            try
            {
                while (reader.Read())
                {
                    if (int.Parse(reader[0].ToString()) < 1 && countStockroom < 4)
                    {
                        //if number of warehouse < 4
                        if (int.Parse(txtCapacity.Text) > 0 && int.Parse(txtCapacity.Text) < 200)
                        {
                            //if capacity under 200
                            string query = $"INSERT INTO stockroom (id,name,capacity) " +
                                           $"VALUES ('{int.Parse(cmbId.SelectedItem.ToString())}','{txtName.Text}','{int.Parse(txtCapacity.Text)}')";
                            database.ExecuteQuery(query);
                            mainpage.draw();
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Capacity must be under 200(max)!");
                        }
                    }
                    else
                    {
                        MessageBox.Show("This Stockroom already exist or you have reached max Stockroom (4)!");
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("err" + MessageBox.Show(err.Message) + MessageBoxButtons.OK + MessageBoxIcon.Error);
            }
            finally
            {
                database.Disconnect();
            }
        }
Example #2
0
        private void deleteButton_Click(object sender, EventArgs e)
        {
            mainPage mainpage = new mainPage();
            string   query    = $"DELETE FROM {mainPage.productType} WHERE id = '{prdTable.SelectedRows[0].Cells[0].Value.ToString()}' AND warehouse = '{mainPage.store}'";

            try
            {
                //execute query and draw buttons/graphbuttons
                database.ExecuteQuery(query);
                prdTable.DataSource = database.ListDatas(mainPage.productType, mainPage.store).Tables[0];
                mainpage.draw();
            }
            catch (Exception err)
            {
                MessageBox.Show("err" + MessageBox.Show(err.Message) + MessageBoxButtons.OK + MessageBoxIcon.Error);
            }
            finally
            {
                database.Disconnect();
            }
        }
Example #3
0
        public void logButton_Click(object sender, EventArgs e)
        {
            username = txtUsername.Text;//set to global variable 'username'

            string query = $"SELECT count(username) as kontrol FROM users WHERE username = '******' AND userPass = '******'";

            try
            {
                if (string.IsNullOrWhiteSpace(txtUsername.Text) == true || string.IsNullOrWhiteSpace(txtPass.Text) == true)
                {
                    MessageBox.Show("Textfields cannot be null and must not contain spaces", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MySqlDataReader reader = database.Reader(query);
                    while (reader.Read())
                    {
                        if (reader[0].ToString() == "1")
                        {
                            this.Hide();
                            mainPage mainPage = new mainPage();
                            mainPage.Show();
                        }
                        else
                        {
                            MessageBox.Show("User not found");
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("err" + MessageBox.Show(err.Message) + MessageBoxButtons.OK + MessageBoxIcon.Error);
            }
            finally
            {
                database.Disconnect();
            }
        }