Ejemplo n.º 1
0
        public bool Delete(EDPlanet obj)
        {
            if (obj.id > 0)
                return DeletePlanetID(obj.id);

            return true;
        }
Ejemplo n.º 2
0
        public List<EDPlanet>GetAllPlanets(string system)
        {
            List<EDPlanet> listObjects = new List<EDPlanet>();
            string query = "api/v1/world_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["world_surveys"];

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

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

            return listObjects;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
 private void GetMaterials(ref EDPlanet obj, CheckedListBox box)
 {
     for (int i = 0; i < box.Items.Count; i++)
     {
         string item = (string)box.Items[i];
         MaterialEnum mat = obj.MaterialFromString(item);
         obj.materials[mat] =  box.GetItemChecked(i);
     }
 }
Ejemplo n.º 5
0
        public bool Delete(EDPlanet obj)
        {
            if (obj.id > 0)
            {
                return(DeletePlanetID(obj.id));
            }

            return(true);
        }
Ejemplo n.º 6
0
 private void GetMaterials(ref EDPlanet obj, CheckedListBox box)
 {
     for (int i = 0; i < box.Items.Count; i++)
     {
         string item = (string)box.Items[i];
         MaterialEnum mat = obj.MaterialFromString(item);
         obj.materials[mat] =  box.GetItemChecked(i);
     }
 }
Ejemplo n.º 7
0
        private void toolStripButtonAdd_Click(object sender, EventArgs e)
        {
            EDPlanet obj = new EDPlanet();
            obj.system = textBoxSystemName.Text;
            obj.commander = edForm.CommanderName;
            edObjects.Add(obj);
            CurrentItem = edObjects.Count - 1;
            UpDateListView();

        }
Ejemplo n.º 8
0
        public ObjectTypesEnum ShortName2ObjectType(string v)
        {
            EDPlanet ed = new EDPlanet();

            foreach (ObjectTypesEnum mat in Enum.GetValues(typeof(ObjectTypesEnum)))
            {
                ed.ObjectType = mat;
                if (v.ToLower().Equals(ed.ShortName.ToLower()))
                {
                    return(mat);
                }
            }

            return(ObjectTypesEnum.UnknownObject);
        }
Ejemplo n.º 9
0
        public ObjectTypesEnum String2ObjectType(string v)
        {
            EDPlanet ed = new EDPlanet();

            if (v == null)
            {
                return(ObjectTypesEnum.UnknownObject);
            }

            if (objectAliases.ContainsKey(v.ToLower()))
            {
                return(objectAliases[v.ToLower()]);
            }


            return(ObjectTypesEnum.UnknownObject);
        }
Ejemplo n.º 10
0
        private void UpdateEDObject(EDObject obj)
        {
            if (obj is EDPlanet)
            {
                EDPlanet planet = (EDPlanet)obj;
                planet.objectName = textBoxName.Text;
                planet.ObjectType = obj.String2ObjectType(comboBoxType.Text);

                var culture = new CultureInfo("en-US");
                planet.gravity = float.Parse(textBoxGravity.Text.Replace(",", "."), culture);
                planet.radius = float.Parse(textBoxRadius.Text.Replace(",", "."), culture);
                planet.arrivalPoint = float.Parse(textBoxArrivalPoint.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 = new CultureInfo("en-US");
                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();
        }
Ejemplo n.º 11
0
        public List <EDPlanet> GetAllPlanets(string system)
        {
            List <EDPlanet> listObjects = new List <EDPlanet>();
            string          query       = "api/v1/world_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["world_surveys"];


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

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


            return(listObjects);
        }
Ejemplo n.º 12
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 = "";
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public bool StorePlanet(EDPlanet edobj)
        {
            dynamic jo = new JObject();

            jo.system = edobj.system;
            jo.commander = edobj.commander;
            jo.world = edobj.objectName;
            jo.world_type = edobj.Description;
            jo.terraformable = edobj.terraformable;
            if (edobj.gravity>0)
                jo.gravity = edobj.gravity;
            jo.terrain_difficulty = edobj.terrain_difficulty;
            jo.notes = edobj.notes;

            if (edobj.arrivalPoint>0)
                jo.arrival_point = edobj.arrivalPoint;

            jo.atmosphere_type = edobj.atmosphere.ToString();
            jo.vulcanism_type = edobj.vulcanism.ToString();

            if (edobj.radius>0)
                jo.radius = edobj.radius;

            jo.reserve = edobj.Reserve;
            jo.mass = edobj.mass;
            jo.surface_temp = edobj.surfaceTemp;
            jo.surface_pressure = edobj.surfacePressure;
            jo.orbit_period = edobj.orbitPeriod;
            jo.rotation_period = edobj.rotationPeriod;
            jo.semi_major_axis = edobj.semiMajorAxis;
            jo.rock_pct = edobj.rockPct;
            jo.metal_pct = edobj.metalPct;
            jo.ice_pct = edobj.metalPct;

            jo.carbon = edobj.materials[MaterialEnum.Carbon];
            jo.iron = edobj.materials[MaterialEnum.Iron];
            jo.nickel = edobj.materials[MaterialEnum.Nickel];
            jo.phosphorus = edobj.materials[MaterialEnum.Phosphorus];
            jo.sulphur = edobj.materials[MaterialEnum.Sulphur];
            jo.arsenic = edobj.materials[MaterialEnum.Arsenic];
            jo.chromium = edobj.materials[MaterialEnum.Chromium];
            jo.germanium = edobj.materials[MaterialEnum.Germanium];
            jo.manganese = edobj.materials[MaterialEnum.Manganese];
            jo.selenium = edobj.materials[MaterialEnum.Selenium];
            jo.vanadium = edobj.materials[MaterialEnum.Vanadium];
            jo.zinc = edobj.materials[MaterialEnum.Zinc];
            jo.zirconium = edobj.materials[MaterialEnum.Zirconium];
            jo.cadmium = edobj.materials[MaterialEnum.Cadmium];
            jo.mercury = edobj.materials[MaterialEnum.Mercury];
            jo.molybdenum = edobj.materials[MaterialEnum.Molybdenum];
            jo.niobium = edobj.materials[MaterialEnum.Niobium];
            jo.tin = edobj.materials[MaterialEnum.Tin];
            jo.tungsten = edobj.materials[MaterialEnum.Tungsten];
            jo.antimony = edobj.materials[MaterialEnum.Antimony];
            jo.polonium = edobj.materials[MaterialEnum.Polonium];
            jo.ruthenium = edobj.materials[MaterialEnum.Ruthenium];
            jo.technetium = edobj.materials[MaterialEnum.Technetium];
            jo.tellurium = edobj.materials[MaterialEnum.Tellurium];
            jo.yttrium = edobj.materials[MaterialEnum.Yttrium];

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

            if (edobj.id == 0)
            {
                var response = RequestSecurePost(joPost.ToString(), "api/v1/world_surveys");
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject jo2 = (JObject)JObject.Parse(response.Body);
                    JObject obj = (JObject)jo2["world_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[world]={jo.world}&q[commander]={jo.commander}";
                    response = RequestGet($"api/v1/world_surveys?{queryParam}");
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        JObject jo2 = (JObject)JObject.Parse(response.Body);
                        JObject obj = (JObject)jo2["world_surveys"][0];
                        edobj.id = obj["id"].Value<int>();

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

                }
            }
            else
            {
                var response = RequestSecurePatch(joPost.ToString(), "api/v1/world_surveys/" + edobj.id.ToString());
            }
            return true;
        }
Ejemplo n.º 14
0
        public ObjectTypesEnum String2ObjectType(string v)
        {
            EDPlanet ed = new EDPlanet();

            if (objectAliases.ContainsKey(v.ToLower()))
                return objectAliases[v.ToLower()];

            return ObjectTypesEnum.UnknownObject;
        }
Ejemplo n.º 15
0
 private void toolStripButtonAdd_Click(object sender, EventArgs e)
 {
     EDPlanet obj = new EDPlanet();
     obj.system = textBoxSystemName.Text;
     obj.commander = edForm.CommanderName;
     edObjects.Add(obj);
     CurrentItem = edObjects.Count - 1;
     UpDateListView();
 }
Ejemplo n.º 16
0
        public ObjectTypesEnum ShortName2ObjectType(string v)
        {
            EDPlanet ed = new EDPlanet();

            foreach (ObjectTypesEnum mat in Enum.GetValues(typeof(ObjectTypesEnum)))
            {
                ed.ObjectType = mat;
                if (v.ToLower().Equals(ed.ShortName.ToLower()))
                    return mat;

            }

            return ObjectTypesEnum.UnknownObject;
        }
Ejemplo n.º 17
0
        public bool StorePlanet(EDPlanet edobj)
        {
            dynamic jo = new JObject();

            jo.system        = edobj.system;
            jo.commander     = edobj.commander;
            jo.world         = edobj.objectName;
            jo.world_type    = edobj.Description;
            jo.terraformable = edobj.terraformable;
            if (edobj.gravity > 0)
            {
                jo.gravity = edobj.gravity;
            }
            jo.terrain_difficulty = edobj.terrain_difficulty;
            jo.notes = edobj.notes;

            if (edobj.arrivalPoint > 0)
            {
                jo.arrival_point = edobj.arrivalPoint;
            }

            jo.atmosphere_type = edobj.atmosphere.ToString();
            jo.vulcanism_type  = edobj.vulcanism.ToString();



            if (edobj.radius > 0)
            {
                jo.radius = edobj.radius;
            }

            jo.reserve          = edobj.Reserve;
            jo.mass             = edobj.mass;
            jo.surface_temp     = edobj.surfaceTemp;
            jo.surface_pressure = edobj.surfacePressure;
            jo.orbit_period     = edobj.orbitPeriod;
            jo.rotation_period  = edobj.rotationPeriod;
            jo.semi_major_axis  = edobj.semiMajorAxis;
            jo.rock_pct         = edobj.rockPct;
            jo.metal_pct        = edobj.metalPct;
            jo.ice_pct          = edobj.metalPct;


            jo.carbon     = edobj.materials[MaterialEnum.Carbon];
            jo.iron       = edobj.materials[MaterialEnum.Iron];
            jo.nickel     = edobj.materials[MaterialEnum.Nickel];
            jo.phosphorus = edobj.materials[MaterialEnum.Phosphorus];
            jo.sulphur    = edobj.materials[MaterialEnum.Sulphur];
            jo.arsenic    = edobj.materials[MaterialEnum.Arsenic];
            jo.chromium   = edobj.materials[MaterialEnum.Chromium];
            jo.germanium  = edobj.materials[MaterialEnum.Germanium];
            jo.manganese  = edobj.materials[MaterialEnum.Manganese];
            jo.selenium   = edobj.materials[MaterialEnum.Selenium];
            jo.vanadium   = edobj.materials[MaterialEnum.Vanadium];
            jo.zinc       = edobj.materials[MaterialEnum.Zinc];
            jo.zirconium  = edobj.materials[MaterialEnum.Zirconium];
            jo.cadmium    = edobj.materials[MaterialEnum.Cadmium];
            jo.mercury    = edobj.materials[MaterialEnum.Mercury];
            jo.molybdenum = edobj.materials[MaterialEnum.Molybdenum];
            jo.niobium    = edobj.materials[MaterialEnum.Niobium];
            jo.tin        = edobj.materials[MaterialEnum.Tin];
            jo.tungsten   = edobj.materials[MaterialEnum.Tungsten];
            jo.antimony   = edobj.materials[MaterialEnum.Antimony];
            jo.polonium   = edobj.materials[MaterialEnum.Polonium];
            jo.ruthenium  = edobj.materials[MaterialEnum.Ruthenium];
            jo.technetium = edobj.materials[MaterialEnum.Technetium];
            jo.tellurium  = edobj.materials[MaterialEnum.Tellurium];
            jo.yttrium    = edobj.materials[MaterialEnum.Yttrium];

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

            if (edobj.id == 0)
            {
                var response = RequestSecurePost(joPost.ToString(), "api/v1/world_surveys");
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    JObject jo2 = (JObject)JObject.Parse(response.Body);
                    JObject obj = (JObject)jo2["world_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[world]={jo.world}&q[commander]={jo.commander}";
                    response = RequestGet($"api/v1/world_surveys?{queryParam}");
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        JObject jo2 = (JObject)JObject.Parse(response.Body);
                        JObject obj = (JObject)jo2["world_surveys"][0];
                        edobj.id = obj["id"].Value <int>();

                        response = RequestSecurePatch(joPost.ToString(), "api/v1/world_surveys/" + edobj.id.ToString());
                    }
                }
            }
            else
            {
                var response = RequestSecurePatch(joPost.ToString(), "api/v1/world_surveys/" + edobj.id.ToString());
            }
            return(true);
        }
Ejemplo n.º 18
0
        private void button1_Click(object sender, EventArgs e)
        {
            //FormSagCarinaMission frm = new FormSagCarinaMission(this);
            //            frm.Show();

            //SystemViewForm frm = new SystemViewForm();
            //frm.Show();

            EdMaterializer mat = new EdMaterializer();

            mat.GetAllPlanets(null);

            EDPlanet obj = new EDPlanet();

            obj.commander = "Test";
            obj.system = "Fine Ring Sector JH-V C2-4";
            obj.objectName = "A 3";
            obj.ObjectType = ObjectTypesEnum.HighMetalContent;
            obj.arrivalPoint = 0;
            obj.gravity = 0.13f;

            obj.materials[MaterialEnum.Carbon] = true;
            obj.materials[MaterialEnum.Iron] = true;
            obj.materials[MaterialEnum.Nickel] = true;
            obj.materials[MaterialEnum.Phosphorus] = true;
            obj.materials[MaterialEnum.Sulphur] = true;
            obj.materials[MaterialEnum.Germanium] = true;
            obj.materials[MaterialEnum.Selenium] = true;
            obj.materials[MaterialEnum.Vanadium] = true;
            obj.materials[MaterialEnum.Cadmium] = true;
            obj.materials[MaterialEnum.Molybdenum] = true;
            obj.materials[MaterialEnum.Tin] = true;
            obj.materials[MaterialEnum.Polonium] = true;

            mat.DeletePlanetID(5);
            mat.DeletePlanetID(6);
            mat.DeletePlanetID(7);

            mat.StorePlanet(obj);
        }
Ejemplo n.º 19
0
        private void toolStripButtonAddPlanet_Click(object sender, EventArgs e)
        {
            int nr = dataGridViewPlanet.Rows.Add();

            DataGridViewRow newRow = (DataGridViewRow)dataGridViewPlanet.Rows[nr];

            DataGridViewComboBoxCell cmbCell = (DataGridViewComboBoxCell)newRow.Cells[1];
            cmbCell.Value = dictComboShortNames[0];
            cmbCell = (DataGridViewComboBoxCell)newRow.Cells[3];
            cmbCell.Value = "Unknown";

            var edobj = new EDPlanet();
            edobj.system = currentSystem;
            dataGridViewPlanet.Rows[nr].Tag = edobj;
        }
Ejemplo n.º 20
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");
            }
        }