示例#1
0
 //overload to take a SysObj for most pertinent items and use external json list
 public static List<SysObj> Search(JArray list, SysObj s, float? rad, long? popMin, long? popMax)
 {
     List<SysObj> sys = Search(list, s.id, s.name, s.x, s.y, s.z, rad, s.faction, popMin, popMax, s.government, s.allegiance,
         s.state, s.security, s.primary_economy, s.power, s.power_state, s.needs_permit, s.simbad_ref);
     return sys;
 }
 public Thread StartResult(List<SysObj> l, SysObj p, float? r, long? pI, long? pA, bool[] ck)
 {
     var t = new Thread(() => SendResult(l, p, r, pI, pA, ck));
     t.Start();
     return t;
 }
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            param = new SysObj();

            if (!textBoxName.ReadOnly)//system name pull
                param.name = textBoxName.Text.ToString();
            else
                param.name = null;

            if (!numericBoxR.ReadOnly && !numericBoxX.ReadOnly && !numericBoxY.ReadOnly && !numericBoxZ.ReadOnly)//coord and radius pull
            {
                //ConsoleWrite("coord value passed");
                rad = float.Parse(numericBoxR.Text.ToString());
                param.x = float.Parse(numericBoxX.Text.ToString());
                param.y = float.Parse(numericBoxY.Text.ToString());
                param.z = float.Parse(numericBoxZ.Text.ToString());
            }
            else
            {
                rad = null;
                param.x = null;
                param.y = null;
                param.z = null;
            }

            if (!textBoxFaction.ReadOnly) //faction pull
                param.faction = textBoxFaction.Text.ToString();
            else
                param.faction = null;

            if (!textBoxPMin.ReadOnly || !textBoxPMax.ReadOnly)//population min and max pull
            {
                //ConsoleWrite("pop value passed");
                popMin = long.Parse(textBoxPMin.Text.ToString());
                popMax = long.Parse(textBoxPMax.Text.ToString());
            }
            else
            {
                popMin = null;
                popMax = null;
            }

            if (advComboGov.SelectedIndex != 0)
                param.government = advComboGov.SelectedItem.ToString();
            else
                param.government = null;

            if (advComboAll.SelectedIndex != 0)
                param.allegiance = advComboAll.SelectedItem.ToString();
            else
                param.allegiance = null;

            if (advComboSec.SelectedIndex != 0)
                param.security = advComboSec.SelectedItem.ToString();
            else
                param.security = null;

            if (advComboEco.SelectedIndex != 0)
                param.primary_economy = advComboEco.SelectedItem.ToString();
            else
                param.primary_economy = null;

            if (advComboPow.SelectedIndex != 0)
                param.power = advComboPow.SelectedItem.ToString();
            else
                param.power = null;

            if (advComboPos.SelectedIndex != 0)
                param.power_state = advComboPos.SelectedItem.ToString();
            else
                param.power_state = null;

            if (advComboPer.SelectedIndex != 0)
            {
                if (advComboPer.SelectedItem.ToString() == "True")
                    param.needs_permit = 1;
                else
                    param.needs_permit = 0;
            }
            else
                param.needs_permit = null;

            checkList = new bool[] { checkCrd.Checked, checkPop.Checked, checkFac.Checked, checkGov.Checked, checkAll.Checked,
                checkSec.Checked, checkEco.Checked, checkPow.Checked, checkPos.Checked, checkPer.Checked,};
            ConsoleTextBox.Text = "";

            ConsoleWrite("Searching Query...");

            buttonReset.Enabled = false;
            buttonReset.UseWaitCursor = true;
            buttonHelp.Enabled = false;
            buttonHelp.UseWaitCursor = true;
            buttonQuit.Enabled = false;
            buttonQuit.UseWaitCursor = true;
            buttonSearch.Enabled = false;
            buttonSearch.UseWaitCursor = true;

            StartResult(list, param, rad, popMin, popMax, checkList);
        }
        public void SendResult(List<SysObj> l, SysObj p, float? r, long? pI, long? pA , bool[] ck)
        {
            List<SysObj> result = EDS.Search(l, p, r, pI, pA);

            ConsoleWrite("\nResults Found! Will now output\n");
            bool conf = true;
            if (result.Count >= 100)
            {
                var cf = MessageBox.Show("Warning! Output contains " + result.Count + " results. Continue?","Warning! Large Output!", MessageBoxButtons.YesNo);
                if (cf == DialogResult.No)
                    conf = false;
            }
            if (conf)
            {
                for (int cnt = 0; cnt < result.Count; cnt++)
                {
                    string s = "\nSystem Name: " + result[cnt].name;
                    if (ck[0])
                        s += "\nCoordinates: X: " + result[cnt].x + " Y: " + result[cnt].y + " Z: " + result[cnt].z;
                    if (!(p.x == null) && !(p.y == null) && !(p.z == null) && !(p.x == null))
                    {
                        double dist = Math.Sqrt(Math.Pow(p.x.Value - l[cnt].x.Value, 2) +
                            Math.Pow(p.y.Value - l[cnt].y.Value, 2) + Math.Pow(p.z.Value - l[cnt].z.Value, 2));
                        s += "\nDistance " + dist;
                    }
                    if (ck[1])
                        s += "\nPopulation: " + result[cnt].population;
                    if (ck[2])
                        s += "\nFaction Name: " + result[cnt].faction;
                    if (ck[3])
                        s += "\nGovernment: " + result[cnt].government;
                    if (ck[4])
                        s += "\nAllegiance: " + result[cnt].allegiance;
                    if (ck[5])
                        s += "\nSecurity: " + result[cnt].security;
                    if (ck[6])
                        s += "\nEconomy: " + result[cnt].primary_economy;
                    if (ck[7])
                        s += "\nPower: " + result[cnt].power;
                    if (ck[8])
                        s += "\nPower State: " + result[cnt].power_state;
                    if (ck[9])
                    {
                        s += "\nPermit: ";
                        if (result[cnt].needs_permit == 0)
                            s += "False";
                        else
                            s += "True";
                    }
                    s += "\nLast Updated: " + EDS.FromUnixTime(result[cnt].updated_at) + "\n";
                    ConsoleWrite(s);

                }
                ConsoleWrite("\nDone.");
            }
            else
                ConsoleWrite("\nOutput cancelled by user.");
            ButtonRelease();
        }