public EditVendorPaymentsWindow(VendorPaymentData vendorPaymentToEdit)
        {
            InitializeComponent();

            _vendorPaymentToEdit = vendorPaymentToEdit;
            nameDataTB.Text = _vendorPaymentToEdit.vendorName;
            addressDataTB.Text = _vendorPaymentToEdit.vendorAddress;
            custIdTB.Text = _vendorPaymentToEdit.vendorId;
            paymentAmountTB.Text = _vendorPaymentToEdit.paymentAmount.ToString();
        }
        private void EditVendorPayments(VendorPaymentData _vendorPaymentToEdit)
        {
            msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");
            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlConnection.Open();
                msqlCommand.CommandText = "UPDATE vendor_payment SET payment_amount='" + _vendorPaymentToEdit.paymentAmount + "' WHERE payment_id='" + _vendorPaymentToEdit.paymentId + "'; ";

                msqlCommand.ExecuteNonQuery();

            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
        }
        private void ConnectInsertTovendorPaymentTable(VendorPaymentData vendorDataObject)
        {
            //define the connection reference and initialize it
            msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");

            try
            {
                //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();

                //define the connection used by the command object
                msqlCommand.Connection = msqlConnection;

                //open the connection
                msqlConnection.Open();

                FeedvendorData(msqlCommand, vendorDataObject);

            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                msqlConnection.Close();

            }
        }
        public AddNewVendorPaymentWindow()
        {
            InitializeComponent();

            vendorPaymentData = new VendorPaymentData();
        }
        void FeedvendorData(MySql.Data.MySqlClient.MySqlCommand msqlCommand, VendorPaymentData cusomerDataObject)
        {
            //define the command text
            msqlCommand.CommandText = "INSERT INTO vendor_payment(vendor_id,payment_amount,payment_date,payment_id)"
                + "VALUES (@vendor_id,@payment_amount,@payment_date,@payment_id)";

            msqlCommand.Parameters.AddWithValue("@vendor_id", cusomerDataObject.vendorId);
            msqlCommand.Parameters.AddWithValue("@payment_id", cusomerDataObject.paymentId);
            msqlCommand.Parameters.AddWithValue("@payment_amount", cusomerDataObject.paymentAmount);
            msqlCommand.Parameters.AddWithValue("@payment_date", cusomerDataObject.paymentDate);

            msqlCommand.ExecuteNonQuery();
        }
 void addVendorPaymentWindowObject_OnAddVendorPaymentData(VendorPaymentData addVendorPaymentWindowObject)
 {
     addVendorPaymentWindowObject.serialNo = (_vendorPaymentCollection.Count + 1).ToString();
     _vendorPaymentCollection.Add(addVendorPaymentWindowObject);
 }
        private void FetchVendorPaymentData()
        {
            msqlConnection = new MySql.Data.MySqlClient.MySqlConnection("server=localhost;user id=root;Password=technicise;database=sptdb;persist security info=False");
            try
            {   //define the command reference
                MySql.Data.MySqlClient.MySqlCommand msqlCommand = new MySql.Data.MySqlClient.MySqlCommand();
                msqlCommand.Connection = msqlConnection;

                msqlConnection.Open();

                msqlCommand.CommandText = "Select vendors.vendor_id, vendors.vendor_address, vendors.ph_no,vendors.vendor_name, vendor_payment.payment_id, vendor_payment.payment_amount, vendor_payment.payment_date FROM vendors,vendor_payment WHERE vendor_payment.vendor_id = vendors.vendor_id;";

                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();
                _vendorPaymentCollection.Clear();
                while (msqlReader.Read())
                {
                    VendorPaymentData addVendorPaymentWindowObject = new VendorPaymentData();

                    addVendorPaymentWindowObject.serialNo = (_vendorPaymentCollection.Count + 1).ToString();
                    addVendorPaymentWindowObject.vendorId = msqlReader.GetString("vendor_id");
                    addVendorPaymentWindowObject.paymentId = msqlReader.GetString("payment_id");
                    addVendorPaymentWindowObject.vendorName = msqlReader.GetString("vendor_name");
                    addVendorPaymentWindowObject.vendorAddress = msqlReader.GetString("vendor_address");
                    addVendorPaymentWindowObject.vendorPhone = msqlReader.GetString("ph_no");
                    addVendorPaymentWindowObject.paymentAmount = msqlReader.GetDouble("payment_amount");
                    addVendorPaymentWindowObject.paymentDate = msqlReader.GetDateTime("payment_date");
                    _vendorPaymentCollection.Add(addVendorPaymentWindowObject);
                }

            }
            catch (Exception er)
            {
                MessageBox.Show(er.Message);
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
        }
 void editWindow_OnEditVendorPaymentData(VendorPaymentData returnEditedVendorPaymentData)
 {
     //finding the element
     VendorPaymentData vData = _vendorPaymentCollection.Where(item => item.paymentId.Equals(returnEditedVendorPaymentData.paymentId)).First();
     //finding the element position
     int itemIdex = _vendorPaymentCollection.IndexOf(vData);
     //remove the element so that the list gets refreshed
     _vendorPaymentCollection.RemoveAt(itemIdex);
     //insert the edited element at same position
     _vendorPaymentCollection.Insert(itemIdex, returnEditedVendorPaymentData);
 }