FIREBASE CONNECTED - ADD PRODUCT FORM

CRUD - Add Product FORM
 avatar
JohnDiaz
csharp
2 years ago
3.5 kB
5
Indexable
Never
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using FireSharp.Config;
using FireSharp.Interfaces;

namespace DiazCRUDFirebaseFinalTask.Forms.Menu
{
    public partial class frmAddProduct : Form
    {

        public frmAddProduct()
        {
            InitializeComponent();
        }

        IFirebaseConfig conf = new FirebaseConfig
        {
            AuthSecret = "wEzQIKxGu9hSox3plaNVlYioj6UoMn8qu4aN4StH",
            BasePath = "https://crud-finaltaskprelim-default-rtdb.firebaseio.com/"
        }; IFirebaseClient client;

        private void ClearFields()
        {
            txtProductName.Text = "";
            cbCategory.SelectedItem = null;
            dtPickerMfgDate.Value = new DateTime(2021, 11, 12);
            dtPickerExpDate.Value = new DateTime(2021, 11, 12);
            txtQuantity.Text = "";
            txtSellPrice.Text = "";
            richTextDescription.Text = "";
        }

        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            _ProductName = Product_Name(txtProductName.Text);
            _Category = cbCategory.Text;
            _MfgDate = dtPickerMfgDate.Value.ToString("yyyy-MM-dd");
            _ExpDate = dtPickerExpDate.Value.ToString("yyyy-MM-dd");
            _Description = richTextDescription.Text;
            _Quantity = Quantity(txtQuantity.Text);
            _SellPrice = SellingPrice(txtSellPrice.Text);
            showProductList.Add(new ProductClass(_ProductName, _Category, _MfgDate, _ExpDate, _SellPrice, _Quantity, _Description));
            gridViewProductList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            gridViewProductList.DataSource = showProductList;

            DialogResult res = MessageBox.Show(this, "Do you want to add this product to the database?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (res == DialogResult.Yes)
            {
                StudentInformationClass addprdct = new StudentInformationClass
                {
                    Product = txtProductName.Text,
                    Category = cbCategory.Text,
                    MfgDate = dtPickerMfgDate.Value.ToString("yyyy-MM-dd"),
                    ExpDate = dtPickerExpDate.Value.ToString("yyyy-MM-dd"),
                    Qty = txtQuantity.Text,
                    SellDate = txtSellPrice.Text
                };
                var inputData = client.Set("Products/" + txtProductName.Text, addprdct);
                MessageBox.Show("Product successfully Added", "System", MessageBoxButtons.OK, MessageBoxIcon.Information);

                _ProductName = Product_Name(txtProductName.Text);
                _Category = cbCategory.Text;
                _MfgDate = dtPickerMfgDate.Value.ToString("yyyy-MM-dd");
                _ExpDate = dtPickerExpDate.Value.ToString("yyyy-MM-dd");
                _Description = richTextDescription.Text;
                _Quantity = Quantity(txtQuantity.Text);
                _SellPrice = SellingPrice(txtSellPrice.Text);
                showProductList.Add(new ProductClass(_ProductName, _Category, _MfgDate, _ExpDate, _SellPrice, _Quantity, _Description));
                gridViewProductList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                gridViewProductList.DataSource = showProductList;
                ClearFields();
            }
        }
    }
}