示例#1
0
        private void updatePriceBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(articlePriceTxtBox.Text))
            {
                CustomMessageBox.ShowDialog(this, Properties.Resources.emptyInputErrorMsg);
                return;
            }

            DialogResult result = CustomDialog.ShowDialog(this, $"Da li ste sigurni da želite da \nunesete novu cenu za ovaj artikal?\n\nNova cena: {articlePriceTxtBox.Text} RSD");

            if (result == DialogResult.No || result == DialogResult.Cancel)
            {
                return;
            }

            MySqlCommand mySqlCommand = new MySqlCommand
            {
                CommandText = @$ "SELECT `value` FROM `prices` 
                                JOIN `articles` ON `prices`.`fk_article_id` = `articles`.`id_article` 
                                WHERE `fk_article_id` = @fkArticleId AND `status` = 'aktivna'"
            };

            mySqlCommand.Parameters.AddWithValue("@fkArticleId", _articleId);

            decimal lastPrice = Convert.ToDecimal(DbConnection.getValue(mySqlCommand));

            if (lastPrice == (Convert.ToDecimal(articlePriceTxtBox.Text)))
            {
                CustomMessageBox.ShowDialog(this, $"Cena {lastPrice.ToString()} RSD je već aktivna!");
                return;
            }

            mySqlCommand.CommandText = "UPDATE `prices` SET `status` = 'neaktivna' WHERE `fk_article_id` = @fkArticleId";

            DbConnection.executeQuery(mySqlCommand);

            mySqlCommand.CommandText = "INSERT INTO `prices` (`value`, `fk_article_id`) VALUES (@articlePrice, @fkArticleId)";
            mySqlCommand.Parameters.AddWithValue("@articlePrice", articlePriceTxtBox.Text);
            DbConnection.executeQuery(mySqlCommand);

            fillDGV();
        }
示例#2
0
 public static DialogResult ShowDialog(IWin32Window owner, string text)
 {
     using var customDialog = new CustomDialog(text);
     return(customDialog.ShowDialog(owner));
 }
        private void createBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(articleNameTxtBox.Text) || string.IsNullOrWhiteSpace(articleSortTxtBox.Text) ||
                string.IsNullOrWhiteSpace(articlePriceITxtBox.Text) || string.IsNullOrWhiteSpace(articleOrganicCmbBox.Text) ||
                string.IsNullOrWhiteSpace(articlePriceIITxtBox.Text) || string.IsNullOrWhiteSpace(articlePriceIIITxtBox.Text)
                )
            {
                CustomMessageBox.ShowDialog(this, Properties.Resources.emptyInputErrorMsg);
                return;
            }

            Article article = new Article(0, articleNameTxtBox.Text, articleSortTxtBox.Text, string.Empty, articleOrganicCmbBox.Text, Convert.ToDecimal(articlePriceITxtBox.Text), Convert.ToDecimal(articlePriceIITxtBox.Text), Convert.ToDecimal(articlePriceIIITxtBox.Text));

            DialogResult result = CustomDialog.ShowDialog(this, $"Da li ste sigurni da želite da kreirate artikal\nIme: {article._name}\nSorta: {article._sort}\nKontrolisana proizvodnja: {article._organic}\nCena I klase: {article._priceI} RSD\nCena II klase: {article._priceII} RSD\nCena III klase: {article._priceIII} RSD\n");

            if (result == DialogResult.No || result == DialogResult.Cancel)
            {
                return;
            }


            MySqlCommand mySqlCommand = new MySqlCommand {
            };


            mySqlCommand.CommandText = "INSERT INTO `articles` (`article_name`, `sort`, `organic`, `category`) VALUES (@articleName, @articleSort, @articleOrganic, @category); SELECT LAST_INSERT_ID()";
            mySqlCommand.Parameters.AddWithValue("@articleName", article._name);
            mySqlCommand.Parameters.AddWithValue("@articleSort", article._sort);
            mySqlCommand.Parameters.AddWithValue("@articleOrganic", article._organic);
            mySqlCommand.Parameters.AddWithValue("@category", "I");

            int articleId1 = Convert.ToInt32(DbConnection.getValue(mySqlCommand));

            mySqlCommand.Parameters.RemoveAt("@category");
            mySqlCommand.Parameters.AddWithValue("@category", "II");


            int articleId2 = Convert.ToInt32(DbConnection.getValue(mySqlCommand));

            mySqlCommand.Parameters.RemoveAt("@category");
            mySqlCommand.Parameters.AddWithValue("@category", "III");

            int articleId3 = Convert.ToInt32(DbConnection.getValue(mySqlCommand));

            mySqlCommand.CommandText = @"INSERT INTO `prices` (`value`, `fk_article_id`) VALUES (@articlePriceI, @articleId1);
                                         INSERT INTO `prices` (`value`, `fk_article_id`) VALUES (@articlePriceII, @articleId2);
                                         INSERT INTO `prices` (`value`, `fk_article_id`) VALUES (@articlePriceIII, @articleId3);";

            mySqlCommand.Parameters.AddWithValue("@articleId1", articleId1);
            mySqlCommand.Parameters.AddWithValue("@articlePriceI", article._priceI);

            mySqlCommand.Parameters.AddWithValue("@articleId2", articleId2);
            mySqlCommand.Parameters.AddWithValue("@articlePriceII", article._priceII);

            mySqlCommand.Parameters.AddWithValue("@articleId3", articleId3);
            mySqlCommand.Parameters.AddWithValue("@articlePriceIII", article._priceIII);

            DbConnection.executeQuery(mySqlCommand);

            mySqlCommand.Parameters.Clear();

            Close();
        }