public void LoadListingInfo(int listID)
        {
            try
            {
                currentListID = listID;
                new System.Threading.Thread(() =>
                {
                    LoadComboBoxes();
                    SetLoadingState(true);
                    DatabaseManager dbManager = new DatabaseManager();
                    AgentManager agManager = new AgentManager();
                    var listingInfo = dbManager.ReturnQuery("SELECT * FROM Listing WHERE List_ID = " + currentListID + " ORDER BY List_ID;");
                    foreach (var list in listingInfo)
                    {
                        DatabaseManager dbManager2 = new DatabaseManager();
                        var propertyInfo = dbManager2.ReturnQuery("SELECT * FROM Property WHERE Property_ID = " + Convert.ToInt32(list[1]) + " ORDER BY Property_ID;");
                        foreach (var property in propertyInfo)
                        {
                            DatabaseManager dbManager3 = new DatabaseManager();
                            var adressInfo = dbManager3.ReturnQuery("SELECT * FROM Address WHERE Address_ID = " + Convert.ToInt32(property[4]) + " ORDER BY Address_ID;");
                            foreach (var address in adressInfo)
                            {
                                DatabaseManager dbManager4 = new DatabaseManager();
                                if(Convert.ToInt32(property[2]) !=-1 && Convert.ToInt32(property[2]) !=0)
                                {
                                    var complexInfo = dbManager4.ReturnQuery("SELECT * FROM Complex WHERE Address_ID = " + Convert.ToInt32(address[0]) + " ORDER BY Complex_ID;");
                                    foreach (var complex in complexInfo)
                                    {
                                       DatabaseManager dbManager5 = new DatabaseManager();
                                       var clientInfo = dbManager5.ReturnQuery("SELECT * FROM Clients WHERE Client_ID = " + Convert.ToInt32(property[1]) + " ORDER BY Client_ID;");
                                       foreach (var client in clientInfo)
                                       {
                                           InsertIntoListingsView(client[1] + ", " + client[4], Convert.ToInt32(address[3]), address[1], address[2], Convert.ToInt32(property[2]), complex[1], property[3], property[5], property[6], property[7], property[9], property[10], property[11], (list[2]), Convert.ToInt32(list[4]), Convert.ToInt32(list[5]), Convert.ToInt32(property[8]), list[6]);
                                            LoadPropertyImages(Convert.ToInt32(list[1]));
                                       }
                                    }
                                }
                                else
                                {
                                        DatabaseManager dbManager5 = new DatabaseManager();
                                       var clientInfo = dbManager5.ReturnQuery("SELECT * FROM Clients WHERE Client_ID = " + Convert.ToInt32(property[1]) + " ORDER BY Client_ID;");
                                       foreach (var client in clientInfo)
                                       {
                                           InsertIntoListingsView(client[1] + ", " + client[4], Convert.ToInt32(address[3]), address[1], address[2], Convert.ToInt32(property[2]), "" , property[3], property[5], property[6], property[7], property[9], property[10], property[11], (list[2]), Convert.ToInt32(list[4]), Convert.ToInt32(list[5]), Convert.ToInt32(property[8]), list[6]);
                                            LoadPropertyImages(Convert.ToInt32(list[1]));
                                       }
                                }
                            }
                        }
                    }
                    SetLoadingState(false);
                }).Start();
            }
            catch
            {

            }
        }
        private void RefreshListings()
        {
            new System.Threading.Thread(() =>
            {
                SetLoadingState(true);
                ClearListingsGrid();
                DatabaseManager dbManager = new DatabaseManager();
                AgentManager agManager = new AgentManager();
                var listingInfo = dbManager.ReturnQuery("SELECT * FROM Listing WHERE Agent_ID = " + agManager.GetAgentID(GetCurrentAgent()) + " ORDER BY List_ID;");
                foreach (var list in listingInfo)
                {
                    DatabaseManager dbManager2 = new DatabaseManager();
                    var propertyInfo = dbManager2.ReturnQuery("SELECT Client_ID, Property_Unit_No, Address_ID, Complex_ID, Property_ID FROM Property WHERE Property_ID = " + Convert.ToInt32(list[1]) + " ORDER BY Property_ID;");
                    foreach (var property in propertyInfo)
                    {
                        DatabaseManager dbManager3 = new DatabaseManager();
                        var adressInfo = dbManager3.ReturnQuery("SELECT Address_ID, Address_Streetname, Address_Streetno FROM Address WHERE Address_ID = " + Convert.ToInt32(property[2]) + " ORDER BY Address_ID;");
                        foreach (var address in adressInfo)
                        {
                            DatabaseManager dbManager4 = new DatabaseManager();
                            if (Convert.ToInt32(property[3]) != 0 && Convert.ToInt32(property[3]) != -1)
                            {
                                var complexInfo = dbManager4.ReturnQuery("SELECT Complex_Name, Complex_ID FROM Complex WHERE Address_ID = " + Convert.ToInt32(address[0]) + " ORDER BY Complex_ID;");
                                foreach (var complex in complexInfo)
                                {
                                    DatabaseManager dbManager5 = new DatabaseManager();
                                    var clientInfo = dbManager5.ReturnQuery("SELECT Client_Email FROM Clients WHERE Client_ID = " + Convert.ToInt32(property[0]) + " ORDER BY Client_ID;");
                                    foreach (var client in clientInfo)
                                    {
                                        string yesNoSold;
                                        string yesNoNegotiable;
                                        if (Convert.ToInt32(list[4]) == 0)
                                            yesNoNegotiable = "No";
                                        else
                                            yesNoNegotiable = "Yes";
                                        if (Convert.ToInt32(list[5]) == 0)
                                            yesNoSold = "No";
                                        else
                                            yesNoSold = "Yes";

                                        InsertIntoListingsGrid(Convert.ToInt32(list[0]), client[0], address[1] + " " + address[2], complex[0] + " " + property[1], list[2], yesNoSold, yesNoNegotiable, list[6]);
                                    }
                                }
                            }
                            else
                            {
                                DatabaseManager dbManager5 = new DatabaseManager();
                                var clientInfo = dbManager5.ReturnQuery("SELECT Client_Email FROM Clients WHERE Client_ID = " + Convert.ToInt32(property[0]) + " ORDER BY Client_ID;");
                                foreach (var client in clientInfo)
                                {
                                    string yesNoSold;
                                    string yesNoNegotiable;
                                    if (Convert.ToInt32(list[4]) == 0)
                                        yesNoNegotiable = "No";
                                    else
                                        yesNoNegotiable = "Yes";
                                    if (Convert.ToInt32(list[5]) == 0)
                                        yesNoSold = "No";
                                    else
                                        yesNoSold = "Yes";
                                    InsertIntoListingsGrid(Convert.ToInt32(list[0]), client[0], address[1] + " " + address[2], "N/A", list[2], yesNoSold, yesNoNegotiable, list[6]);
                                }
                            }
                        }
                    }
                }
                SetLoadingState(false);
            }).Start();
        }