private void cstSaveBtn_Click(object sender, RoutedEventArgs e)
        {
            if (!cstNameTB.Text.Equals(string.Empty) &&
                !cstAdrsTB.Text.Equals(string.Empty) &&
                !cstCntctTB.Text.Equals(string.Empty))
                {
                    PSMSData.CustomerInfo newCustomer = new PSMSData.CustomerInfo();

                    newCustomer.id = GenerateId();

                    newCustomer.name = cstNameTB.Text;
                    newCustomer.address = cstAdrsTB.Text;
                    newCustomer.contact = cstCntctTB.Text;
                    newCustomer.remark = cstRmrkTB.Text;

                    PSMSDatabase.DbInteraction.DoRegisterNewCustomer(newCustomer);

                    //addCustmrEpndr.Visibility = Visibility.Collapsed;
                    //loginExpndr.Visibility = Visibility.Visible;
                    //loginExpndr.IsExpanded = true;
                    //dNBSNUserIDTB.Clear();
                    //dNBSNpassPB.Clear();
                    custErorMsgLbl.Content = "Successfully Added";
                    cstNameTB.Clear();
                    cstCntctTB.Clear();
                    cstAdrsTB.Clear();
                    cstRmrkTB.Clear();
                    fetchCustomerData();

                }
            else
            {
                custErorMsgLbl.Content = "Correctly Enter Info ";

            }
        }
        public static void EditCustomer(CustomerInfo newCustomer)
        {
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

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

                msqlCommand.CommandText = "UPDATE customer SET name=@name,address=@address,contact=@contact, remark = @remark WHERE id=@id";

                msqlCommand.Parameters.AddWithValue("@name", newCustomer.name);
                msqlCommand.Parameters.AddWithValue("@address", newCustomer.address);
                msqlCommand.Parameters.AddWithValue("@contact", newCustomer.contact);
                msqlCommand.Parameters.AddWithValue("@remark", newCustomer.remark);
                msqlCommand.Parameters.AddWithValue("@id", newCustomer.id);
                msqlCommand.ExecuteNonQuery();


            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
        }
        private void serchCustBtn_Click(object sender, RoutedEventArgs e)
        {
            if (srchNameTB.Text == "")
                fetchCustomerData();
            else
            {
                CustomerInfo custinfo = new CustomerInfo();
                custinfo.name = srchNameTB.Text;

                List<CustomerInfo> customers = DbInteraction.searchCustomerList(custinfo);

                _customerCollection.Clear();

                foreach (CustomerInfo customer in customers)
                {
                    _customerCollection.Add(customer);
                }
            }
        }
        private static List<CustomerInfo> searchAllCustomerList(CustomerInfo custinfo)
        {
            List<CustomerInfo> CustomerList = new List<CustomerInfo>();

            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

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

                msqlCommand.CommandText = "Select * From customer where name = @input or address = @input or remark = @input or contact = @input or id = @input ; ";

                 msqlCommand.Parameters.AddWithValue("@input", custinfo.name );
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    CustomerInfo Customer = new CustomerInfo();

                    Customer.id = msqlReader.GetString("id");
                    Customer.name = msqlReader.GetString("name");
                    Customer.address = msqlReader.GetString("address");
                    Customer.contact = msqlReader.GetString("contact");
                    Customer.remark = msqlReader.GetString("remark");
                    Customer.turnover = msqlReader.GetString("turnOver");
                    Customer.due = msqlReader.GetString("due");
                    CustomerList.Add(Customer);
                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return CustomerList;
        }
 public static List<CustomerInfo> searchCustomerList( CustomerInfo custinfo)
 {
     return searchAllCustomerList(custinfo);
 }
        private static List<CustomerInfo> QueryAllCustomerList()
        {
            List<CustomerInfo> CustomerList = new List<CustomerInfo>();

            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

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

                msqlCommand.CommandText = "Select * From customer GROUP BY NAME;";
                MySql.Data.MySqlClient.MySqlDataReader msqlReader = msqlCommand.ExecuteReader();

                while (msqlReader.Read())
                {
                    CustomerInfo Customer = new CustomerInfo();

                    Customer.id = msqlReader.GetString("id");
                    Customer.name = msqlReader.GetString("name");
                    Customer.address = msqlReader.GetString("address");
                    Customer.contact = msqlReader.GetString("contact");
                    Customer.remark = msqlReader.GetString("remark");
                    Customer.turnover = msqlReader.GetString("turnOver");
                    Customer.due = msqlReader.GetString("due");
                    CustomerList.Add(Customer);
                }

            }
            catch (Exception er)
            {
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }

            return CustomerList;
        }
        private static int DoRegisterNewCustomerindb(CustomerInfo NewCustomer)
        {
            int returnVal = 0;
            MySql.Data.MySqlClient.MySqlConnection msqlConnection = OpenDbConnection();

            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;

                msqlCommand.CommandText = "INSERT INTO customer(id,name,contact,address,remark) " + "VALUES(@id,@name,@contact,@address,@remark)";

                msqlCommand.Parameters.AddWithValue("@id", NewCustomer.id);
                msqlCommand.Parameters.AddWithValue("@name", NewCustomer.name);
                msqlCommand.Parameters.AddWithValue("@contact", NewCustomer.contact);
                msqlCommand.Parameters.AddWithValue("@address", NewCustomer.address);
                msqlCommand.Parameters.AddWithValue("@remark", NewCustomer.remark);


                msqlCommand.ExecuteNonQuery();

                returnVal = 1;
            }
            catch (Exception er)
            {
                returnVal = 0;
            }
            finally
            {
                //always close the connection
                msqlConnection.Close();
            }
            return returnVal;
        }
 public static int DoRegisterNewCustomer(CustomerInfo NewCustomer)
 {
     return DoRegisterNewCustomerindb(NewCustomer);
 }