Esempio n. 1
0
        private void UpdateListViewLine()
        {
            ListViewItem lvi;

            if (listView1.SelectedItems.Count > 0)
            {
                lvi = listView1.SelectedItems[0];

                if (currentObj is EDWorld)
                {
                    EDWorld planet = (EDWorld)currentObj;
                    lvi.SubItems[0].Text = planet.objectName;
                    lvi.SubItems[1].Text = planet.Description;
                    lvi.SubItems[2].Text = planet.gravity.ToString("0.00");
                    lvi.SubItems[3].Text = planet.arrivalPoint.ToString("0");
                }
                if (currentObj is EDStar)
                {
                    EDStar star = (EDStar)currentObj;
                    lvi.SubItems[0].Text = star.objectName;
                    lvi.SubItems[1].Text = star.Description;
                    lvi.SubItems[2].Text = "";
                    lvi.SubItems[3].Text = star.arrivalPoint.ToString("0");
                }
            }
        }
Esempio n. 2
0
        private void UpDateListView()
        {
            listView1.Items.Clear();

            foreach (var ob in edObjects)
            {
                if (ob is EDPlanet)
                {
                    EDPlanet planet = (EDPlanet)ob;
                    ListViewItem lvi;
                    lvi = listView1.Items.Add(planet.objectName);
                    lvi.SubItems.Add(planet.Description);

                    lvi.SubItems.Add(planet.gravity.ToString("0.00"));
                    lvi.SubItems.Add(planet.arrivalPoint.ToString("0"));

                    lvi.UseItemStyleForSubItems = false;


                    for (int ii = 0; ii < mlist.Count; ii++)
                    {
                        ListViewItem.ListViewSubItem lvsi;
                        if (planet.materials[mlist[ii].material])
                            lvsi = lvi.SubItems.Add("X");
                        else
                            lvsi = lvi.SubItems.Add(" ");

                        lvsi.BackColor = mlist[ii].RareityColor;
                    }

                    lvi.Tag = planet;
                }
                if (ob is EDStar)
                {
                    EDStar planet = (EDStar)ob;
                    ListViewItem lvi;
                    lvi = listView1.Items.Add(planet.objectName);
                    lvi.SubItems.Add(planet.Description);

                    lvi.SubItems.Add("");  // Gravity
                    lvi.SubItems.Add(planet.arrivalPoint.ToString("0"));

                    lvi.UseItemStyleForSubItems = false;

                    
                    for (int ii = 0; ii < mlist.Count; ii++)
                    {
                        ListViewItem.ListViewSubItem lvsi;
                         lvsi = lvi.SubItems.Add("");
                        lvsi.BackColor = Color.Gray;
                    }
                    
                    lvi.Tag = planet;
                }
            }
            if (edObjects.Count>0)
                listView1.Items[0].Selected = true;
        }
Esempio n. 3
0
 private void toolStripButtonAddStar_Click(object sender, EventArgs e)
 {
     EDStar obj = new EDStar();
     obj.system = textBoxSystemName.Text;
     obj.commander = edForm.CommanderName;
     edObjects.Add(obj);
     CurrentItem = edObjects.Count - 1;
     UpDateListView();
 }
Esempio n. 4
0
        public bool StoreStar(EDStar edobj)
        {
            dynamic jo = new JObject();

            jo.system            = edobj.system;
            jo.updater           = edobj.updater;
            jo.star              = edobj.objectName;
            jo.spectral_class    = edobj.Description;
            jo.spectral_subclass = edobj.subclass;
            jo.solar_mass        = edobj.mass;
            jo.solar_radius      = edobj.radius;
            jo.surface_temp      = edobj.surfaceTemp;
            jo.star_age          = edobj.star_age;
            jo.orbit_period      = edobj.orbitPeriod;
            jo.arrival_point     = edobj.arrivalPoint;
            jo.luminosity        = edobj.luminosity;
            jo.notes             = edobj.notes;
            jo.image_url         = edobj.image_url;

            JObject joPost = new JObject(new JProperty("star", jo));

            if (edobj.id == 0)
            {
                var response = RequestSecurePost(joPost.ToString(), "api/v2/stars");
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject jo2 = (JObject)JObject.Parse(response.Body);
                    JObject obj = (JObject)jo2["star"];
                    edobj.id = obj["id"].Value <int>();
                }
                else if ((int)response.StatusCode == 422)
                {
                    // Surprise, record is already there for some reason!
                    // I may create an api method on the server that negates the need to check for
                    // this at some point
                    // - Greg

                    var queryParam = $"system={jo.system}&star={jo.star}&updater={jo.updater}";
                    response = RequestGet($"api/v2/stars?{queryParam}");
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        JObject jo2 = (JObject)JObject.Parse(response.Body);
                        JObject obj = (JObject)jo2["stars"][0];
                        edobj.id = obj["id"].Value <int>();

                        response = RequestSecurePatch(joPost.ToString(), "api/v2/stars/" + edobj.id.ToString());
                    }
                }
            }
            else
            {
                var response = RequestSecurePatch(joPost.ToString(), "api/v2/stars/" + edobj.id.ToString());
            }
            return(true);
        }
Esempio n. 5
0
        private void UpdateEDObject(EDObject obj)
        {
            if (obj is EDWorld)
            {
                EDWorld planet = (EDWorld)obj;
                planet.objectName = textBoxName.Text;
                planet.ObjectType = obj.String2ObjectType(comboBoxType.Text);

                var culture = CultureInfo.InvariantCulture;
                planet.mass            = float.Parse(textBoxMass.Text.Replace(",", "."), culture);
                planet.gravity         = float.Parse(textBoxGravity.Text.Replace(",", "."), culture);
                planet.radius          = float.Parse(textBoxRadius.Text.Replace(",", "."), culture);
                planet.surfaceTemp     = Int16.Parse(textBoxSurfaceTemp.Text, culture);
                planet.arrivalPoint    = float.Parse(textBoxArrivalPoint.Text.Replace(",", "."), culture);
                planet.surfacePressure = float.Parse(textBoxSurfaceTemp.Text.Replace(",", "."), culture);

                planet.atmosphere = planet.AtmosphereStr2Enum(comboBoxAtmosphere.Text);
                planet.vulcanism  = planet.VulcanismStr2Enum(comboBoxVulcanism.Text);

                //GetMaterials(ref planet, checkedListBox1);
                //GetMaterials(ref planet, checkedListBox2);
                //GetMaterials(ref planet, checkedListBox3);
                //GetMaterials(ref planet, checkedListBox4);
            }

            if (obj is EDStar)
            {
                EDStar star = (EDStar)obj;
                star.objectName = textBoxStarName.Text;
                star.ObjectType = obj.String2ObjectType(comboBoxStarType.Text);
                star.subclass   = textBoxStarSubClass.Text;

                var culture = CultureInfo.InvariantCulture;
                star.mass         = float.Parse(textBoxStarMass.Text.Replace(",", "."), culture);
                star.radius       = float.Parse(textBoxS_Radius.Text.Replace(",", "."), culture);
                star.arrivalPoint = float.Parse(textBoxS_ArrivalPoint.Text.Replace(",", "."), culture);

                star.star_age    = float.Parse(textBox_StarAge.Text.Replace(",", "."), culture);
                star.surfaceTemp = int.Parse(textBoxStarTemp.Text, culture);
                star.orbitPeriod = float.Parse(textBoxStarOrbitPeriod.Text.Replace(",", "."), culture);
                star.luminosity  = textBoxStarLuminosity.Text;
                star.notes       = textBoxStarNote.Text;
            }



            UpdateListViewLine();
        }
Esempio n. 6
0
        public List <EDStar> GetAllStars(string system)
        {
            List <EDStar> listObjects = new List <EDStar>();
            string        query       = "api/v2/stars";

            if (!String.IsNullOrEmpty(system))
            {
                query = query + "?system=" + HttpUtility.UrlEncode(system);
            }

            var response = RequestGet(query);
            var json     = response.Body;

            JArray  jArray  = null;
            JObject jObject = null;

            if (json != null && json.Length > 5)
            {
                jObject = (JObject)JObject.Parse(json);
            }

            if (jObject == null)
            {
                return(listObjects);
            }


            jArray = (JArray)jObject["stars"];


            foreach (JObject jo in jArray)
            {
                EDStar obj = new EDStar();

                if (obj.ParseJson(jo))
                {
                    listObjects.Add(obj);
                }
            }


            return(listObjects);
        }
Esempio n. 7
0
        private void UpdateListViewLine()
        {
            ListViewItem lvi;

            if (listView1.SelectedItems.Count > 0)
            {
                lvi = listView1.SelectedItems[0];

                if (currentObj is EDPlanet)
                {
                    EDPlanet planet = (EDPlanet)currentObj;
                    lvi.SubItems[0].Text = planet.objectName;
                    lvi.SubItems[1].Text = planet.Description;
                    lvi.SubItems[2].Text = planet.gravity.ToString("0.00");
                    lvi.SubItems[3].Text = planet.arrivalPoint.ToString("0");


                    for (int ii = 0; ii < mlist.Count; ii++)
                    {
                        if (planet.materials[mlist[ii].material])
                            lvi.SubItems[3 + ii].Text = "X";
                        else
                            lvi.SubItems[3 + ii].Text = " ";
                    }
                }
                if (currentObj is EDStar)
                {
                    EDStar star = (EDStar)currentObj;
                    lvi.SubItems[0].Text = star.objectName;
                    lvi.SubItems[1].Text = star.Description;
                    lvi.SubItems[2].Text = "";
                    lvi.SubItems[3].Text = star.arrivalPoint.ToString("0");


                    for (int ii = 0; ii < mlist.Count; ii++)
                    {
                        lvi.SubItems[3 + ii].Text = "";
                    }
                }
            }
        }
Esempio n. 8
0
        public List<EDStar> GetAllStars(string system)
        {
            List<EDStar> listObjects = new List<EDStar>();
            string query = "api/v1/star_surveys";

            if (!String.IsNullOrEmpty(system))
                query = query + "/?q[system]=" + HttpUtility.UrlEncode(system);

            var response = RequestGet(query);
            var json = response.Body;

            JArray jArray = null;
            JObject jObject = null;
            if (json != null && json.Length > 5)
                jObject = (JObject)JObject.Parse(json);

            if (jObject == null)
                return listObjects;

            jArray = (JArray)jObject["star_surveys"];

            foreach (JObject jo in jArray)
            {
                EDStar obj = new EDStar();

                if (obj.ParseJson(jo))
                    listObjects.Add(obj);
            }

            return listObjects;
        }
Esempio n. 9
0
        public bool StoreStar(EDStar edobj)
        {
            dynamic jo = new JObject();

            jo.system = edobj.system;
            jo.commander = edobj.commander;
            jo.star = edobj.objectName;
            jo.star_type = edobj.Description;
            jo.subclass = edobj.subclass;
            jo.solar_mass = edobj.mass;
            jo.solar_radius = edobj.radius;
            jo.star_age = edobj.star_age;
            jo.orbit_period = edobj.orbitPeriod;
            jo.arrival_point = edobj.arrivalPoint;
            jo.luminosity = edobj.luminosity;
            jo.note = edobj.notes;
            jo.surface_temp = edobj.surfaceTemp;

            JObject joPost = new JObject(new JProperty("star_survey", jo));

            if (edobj.id == 0)
            {
                var response = RequestSecurePost(joPost.ToString(), "api/v1/star_surveys");
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject jo2 = (JObject)JObject.Parse(response.Body);
                    JObject obj = (JObject)jo2["star_survey"];
                    edobj.id = obj["id"].Value<int>();
                }
                else if ((int)response.StatusCode == 422)
                {
                    // Surprise, record is already there for some reason!
                    // I may create an api method on the server that negates the need to check for
                    // this at some point
                    // - Greg

                    var queryParam = $"q[system]={jo.system}&q[star]={jo.star}&q[commander]={jo.commander}";
                    response = RequestGet($"api/v1/star_surveys?{queryParam}");
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        JObject jo2 = (JObject)JObject.Parse(response.Body);
                        JObject obj = (JObject)jo2["star_surveys"][0];
                        edobj.id = obj["id"].Value<int>();

                        response = RequestSecurePatch(joPost.ToString(), "api/v1/star_surveys/" + edobj.id.ToString());
                    }

                }
            }
            else
            {
                var response = RequestSecurePatch(joPost.ToString(), "api/v1/star_surveys/" + edobj.id.ToString());
            }
            return true;
        }
Esempio n. 10
0
        private void UpdateObject(int v)
        {
            if (v < 0)
            {
                return;
            }

            currentObj = edObjects[v];
            if (currentObj.IsPlanet)
            {
                panelPlanets.Visible = true;
                panelStar.Visible    = false;
            }
            else
            {
                panelPlanets.Visible = false;
                panelStar.Visible    = true;
            }


            if (currentObj is EDWorld)
            {
                EDWorld planet = (EDWorld)currentObj;

                textBoxName.Text = currentObj.objectName;


                var nr = (from str in dictComboPlanetDesc where str.Value == planet.Description select str.Key).FirstOrDefault <int>();
                comboBoxType.SelectedIndex = nr;

                textBoxMass.Text   = planet.mass.ToString("0.0000");
                textBoxRadius.Text = planet.radius.ToString("0");

                if (planet.gravity == 0)
                {
                    planet.gravity = (float)CalcG(planet.mass, planet.radius);
                }

                textBoxGravity.Text     = planet.gravity.ToString("0.00");
                textBoxSurfaceTemp.Text = planet.surfaceTemp.ToString("0");
                textBoxPreasure.Text    = planet.surfacePressure.ToString("0.00");

                textBoxArrivalPoint.Text   = planet.arrivalPoint.ToString("0");
                textBoxOrbitPeriod.Text    = planet.orbitPeriod.ToString("0.0");
                textBoxRotationPeriod.Text = planet.rotationPeriod.ToString("0.0");
                textBoxSemiMajorAxis.Text  = planet.semiMajorAxis.ToString("0.00");
                textBoxArrivalPoint.Text   = planet.arrivalPoint.ToString("0.0");
                textBoxRock.Text           = planet.rockPct.ToString("0.0");
                textBoxMetal.Text          = planet.metalPct.ToString("0.0");
                textBoxIce.Text            = planet.icePct.ToString("0.0");


                try
                {
                    comboBoxAtmosphere.SelectedIndex = (int)planet.atmosphere;
                    comboBoxVulcanism.SelectedIndex  = (int)planet.vulcanism;
                }
                catch (Exception)
                {
                }
                //SetMaterials(planet, checkedListBox1);
                //SetMaterials(planet, checkedListBox2);
                //SetMaterials(planet, checkedListBox3);
                //SetMaterials(planet, checkedListBox4);
            }
            if (currentObj is EDStar)
            {
                EDStar star = (EDStar)currentObj;

                textBoxStarName.Text = star.objectName;

                var nr = (from str in dictComboStarDesc where str.Value == star.Description select str.Key).FirstOrDefault <int>();
                comboBoxStarType.SelectedIndex = nr;
                textBoxStarSubClass.Text       = star.subclass;
                textBoxStarMass.Text           = star.mass.ToString();
                textBoxS_Radius.Text           = star.radius.ToString();
                textBox_StarAge.Text           = star.star_age.ToString("0");
                textBoxStarOrbitPeriod.Text    = star.orbitPeriod.ToString();
                textBoxS_ArrivalPoint.Text     = star.arrivalPoint.ToString("0");
                textBoxStarNote.Text           = star.notes;
                textBoxStarLuminosity.Text     = star.luminosity;
                textBoxStarTemp.Text           = star.surfaceTemp.ToString("0");
            }
        }
Esempio n. 11
0
 private void toolStripButtonAddStar_Click(object sender, EventArgs e)
 {
     EDStar obj = new EDStar();
     obj.system = textBoxSystemName.Text;
     obj.commander = edForm.CommanderName;
     edObjects.Add(obj);
     CurrentItem = edObjects.Count - 1;
     UpDateListView();
 }
Esempio n. 12
0
        private void UpdateObject(int v)
        {
            if (v < 0)
                return;

            currentObj = edObjects[v];
            if (currentObj.IsPlanet)
            {
                panelPlanets.Visible = true;
                panelStar.Visible = false;
            }
            else
            {
                panelPlanets.Visible = false;
                panelStar.Visible = true;
            }


            if (currentObj is EDPlanet)
            {
                EDPlanet planet = (EDPlanet)currentObj;

                textBoxName.Text = currentObj.objectName;


                var nr = (from str in dictComboPlanetDesc where str.Value == planet.Description select str.Key).FirstOrDefault<int>();
                comboBoxType.SelectedIndex = nr;

                textBoxGravity.Text = planet.gravity.ToString("0.00");
                textBoxRadius.Text = planet.radius.ToString("0");
                textBoxArrivalPoint.Text = planet.arrivalPoint.ToString("0");

                try
                {
                    comboBoxAtmosphere.SelectedIndex = (int)planet.atmosphere;
                    comboBoxVulcanism.SelectedIndex = (int)planet.vulcanism;
                }
                catch (Exception)
                {

                }
                SetMaterials(planet, checkedListBox1);
                SetMaterials(planet, checkedListBox2);
                SetMaterials(planet, checkedListBox3);
                SetMaterials(planet, checkedListBox4);
            }
            if (currentObj is EDStar)
            {
                EDStar star = (EDStar)currentObj;

                textBoxStarName.Text = star.objectName;

                var nr = (from str in dictComboStarDesc where str.Value == star.Description select str.Key).FirstOrDefault<int>();
                comboBoxStarType.SelectedIndex = nr;
                textBoxStarSubClass.Text = star.subclass;
                textBoxStarMass.Text = star.mass.ToString();
                textBoxS_Radius.Text = star.radius.ToString();
                textBox_StarAge.Text = star.star_age.ToString("0");
                textBoxStarOrbitPeriod.Text = star.orbitPeriod.ToString();
                textBoxS_ArrivalPoint.Text = star.arrivalPoint.ToString("0");
                textBoxStarNote.Text = star.notes;
                textBoxStarLuminosity.Text = star.luminosity;
                textBoxStarTemp.Text = star.surfaceTemp.ToString("0");
            }
        }