Beispiel #1
0
        protected void ButtonDeleteContinent_Click(object sender, EventArgs e)
        {
            this.LabelContinentErrors.Text = string.Empty;

            if (string.IsNullOrWhiteSpace(this.ListBoxContinents.SelectedValue))
            {
                this.LabelContinentErrors.Text = "No continent selected.";
                return;
            }

            string confirmValue = Request.Form["confirm-value"];

            if (confirmValue == "No")
            {
                return;
            }

            using (var context = new WorldEntities())
            {
                int continentId = int.Parse(this.ListBoxContinents.SelectedValue);
                var continent   = context.Continents.FirstOrDefault(c => c.ContinentId == continentId);
                if (continent != null)
                {
                    context.Continents.Remove(continent);
                    context.SaveChanges();
                    Response.Redirect(Request.RawUrl);
                }
                else
                {
                    this.LabelContinentErrors.Text = "No continent found with id=" + continentId;
                }
            }
        }
Beispiel #2
0
        protected void ButtonUpdateContinent_Click(object sender, EventArgs e)
        {
            this.LabelContinentErrors.Text = string.Empty;

            if (string.IsNullOrWhiteSpace(this.ListBoxContinents.SelectedValue))
            {
                this.LabelContinentErrors.Text = "No continent selected.";
                return;
            }

            string newContinentName = this.TextBoxContinentName.Text.Trim();

            if (string.IsNullOrWhiteSpace(newContinentName))
            {
                this.LabelContinentErrors.Text = "No continent name specified.";
                return;
            }

            using (var context = new WorldEntities())
            {
                int continentId = int.Parse(this.ListBoxContinents.SelectedValue);
                var continent   = context.Continents.FirstOrDefault(c => c.ContinentId == continentId);
                if (continent != null)
                {
                    continent.ContinentName = newContinentName;
                    context.Entry <Continent>(continent).State = EntityState.Modified;
                    context.SaveChanges();
                    Response.Redirect(Request.RawUrl);
                }
                else
                {
                    this.LabelContinentErrors.Text = "No continent found with id=" + continentId;
                }
            }
        }
Beispiel #3
0
        protected void ButtonDeleteContinent_Click(object sender, EventArgs e)
        {
            string newName = Server.HtmlEncode(this.TextBoxUpdateContinent.Text);

            if (string.IsNullOrWhiteSpace(newName))
            {
                Response.Write("Please enter name to delete continent!");
                return;
            }

            var           selectedContinentId = this.ListBoxContinents.SelectedItem.Value;
            WorldEntities db = new WorldEntities();

            var continent = db.Continents.FirstOrDefault(c => c.ContinentId.ToString() == selectedContinentId);

            if (continent == null)
            {
                Response.Write("Selected continent was not found!");
                return;
            }

            db.Entry <Continent>(continent).State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();

            Response.Redirect(Request.RawUrl);
        }
Beispiel #4
0
        protected void ButtonAddContinent_Click(object sender, EventArgs e)
        {
            string newName = this.TextBoxUpdateContinent.Text;

            if (string.IsNullOrWhiteSpace(newName))
            {
                Response.Write("Please enter name to Create continent!");
                return;
            }

            if (newName.Length > 20)
            {
                Response.Write("Continent name must be less than 20 symbols!");
            }

            WorldEntities db = new WorldEntities();

            Continent newContinent = new Continent()
            {
                ContinentName = newName
            };

            db.Continents.Add(newContinent);
            db.SaveChanges();

            Response.Redirect(Request.RawUrl);
        }
Beispiel #5
0
    public override void DoTask()
    {
        WorldEntities     entitieTarget = target.GetComponent <WorldEntities>();
        Building          building      = target.GetComponent <Building>();
        WorldStaticObject staticObject  = target.GetComponent <WorldStaticObject>();

        if (entitieTarget != null)
        {
            entitieTarget.TakeDommage(GameState.instance.allDommage, actor);
            if (entitieTarget.healthCurrent < 0)
            {
                CancelTask(TaskBlockage.done);
            }
        }
        else if (building != null)
        {
            building.TakeDommage(actor.GetTool().stats.damagePerSec);
            if (building.structurePointCurrent < 0)
            {
                CancelTask(TaskBlockage.done);
            }
        }

        else
        {
        }
    }
Beispiel #6
0
 public FightMTask(WorldEntities _actor, WorldObject _target)
 {
     target              = _target;
     actor               = _actor;
     taskSpeed           = GameState.instance.combatSpeed;
     unavailablePosition = new List <Vector2Int>();
 }
Beispiel #7
0
 public BuildTask(Building _target, WorldEntities _actor)
 {
     construction        = _target;
     actor               = _actor;
     taskSpeed           = GameState.instance.buildSpeed;
     type                = TaskType.build;
     unavailablePosition = new List <Vector2Int>();
 }
Beispiel #8
0
 public GatherTask(ResourceNodes _target, WorldEntities _actor)
 {
     nodeTarget          = _target;
     actor               = _actor;
     taskSpeed           = GameState.instance.gatherSpeed;
     requiredTool        = _target.requiredTool;
     type                = TaskType.gather;
     unavailablePosition = new List <Vector2Int>();
 }
Beispiel #9
0
 public void EntityDie(WorldEntities _entity)
 {
     if (_entity.isCitizen)
     {
         Citizen cit = (Citizen)_entity;
         citizens.Remove(cit);
     }
     else
     {
         Ennemy ene = (Ennemy)_entity;
         ennemys.Remove(ene);
     }
 }
Beispiel #10
0
 public void TakeDommage(float _dommage, WorldEntities _actor)
 {
     healthCurrent -= _dommage;
     if (state.arrangedTask != null)
     {
         if (state.arrangedTask.type == Task.TaskType.none)
         {
             state.arrangedTask = new FightMTask(this, _actor);
         }
     }
     else
     {
         state.arrangedTask = new FightMTask(this, _actor);
     }
 }
Beispiel #11
0
        private bool IsValidCountryLanguages(string[] languages)
        {
            WorldEntities db = new WorldEntities();
            Language      curLanguage;

            foreach (var language in languages)
            {
                curLanguage = db.Languages.FirstOrDefault(x => x.LanguageName == language);
                if (curLanguage == null)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #12
0
        public override void InitBlueprint(Blueprint blueprint)
        {
            this.Blueprint   = blueprint;
            HasInitBlueprint = true;
            HasInit          = HasInitGPU & HasInitBlueprint;

            Light?.Init(Blueprint);
            State.Rooms.Init(blueprint);
            blueprint.Changes.SetFlag(BlueprintGlobalChanges.ROOM_CHANGED);
            blueprint.Changes.SetFlag(BlueprintGlobalChanges.OUTDOORS_LIGHTING_CHANGED);
            Architecture               = new WorldArchitecture(blueprint);
            Entities                   = new WorldEntities(blueprint);
            Platform                   = new WorldPlatformNull(blueprint);
            State.Platform             = Platform;
            State.Changes              = blueprint.Changes;
            blueprint.Changes.Subworld = true;
        }
Beispiel #13
0
        protected void ButtonAddContinent_Click(object sender, EventArgs e)
        {
            this.LabelContinentErrors.Text = string.Empty;

            string newContinentName = this.TextBoxNewContinentName.Text.Trim();

            if (string.IsNullOrWhiteSpace(newContinentName))
            {
                this.LabelContinentErrors.Text = "No continent name specified.";
                return;
            }

            using (var context = new WorldEntities())
            {
                context.Continents.Add(new Continent
                {
                    ContinentName = newContinentName
                });

                context.SaveChanges();
                Response.Redirect(Request.RawUrl);
            }
        }
Beispiel #14
0
        protected void ButtonAddCountry_Click(object sender, EventArgs e)
        {
            WorldEntities context = null;

            this.LabelCountryErrors.Text = string.Empty;

            try
            {
                string countryId = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewCountryId");
                this.ValidateCountryId(countryId);

                string countryName = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewCountryName");
                this.ValidateName(countryName);

                float  latitude;
                string latitudeAsString = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewLatitude");
                this.ValidateGeoCoordinate(latitudeAsString, out latitude);

                float  longitude;
                string longitudeAsString = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewLongitude");
                this.ValidateGeoCoordinate(longitudeAsString, out longitude);

                float  area;
                string areaAsString = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewSurfaceArea");
                this.ValidateArea(areaAsString, out area);

                int    population;
                string populationAsString = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewPopulation");
                this.ValidatePopulation(populationAsString, out population);

                context = new WorldEntities();

                int continentId = int.Parse(this.ListBoxContinents.SelectedValue);

                FileUpload flagImageUpload = this.GetFooterRowControl(this.GridViewCountries, "FileUploadNewCountryFlag") as FileUpload;
                byte[]     fileData        = this.GetUploadedFile(flagImageUpload.PostedFile);

                var country = new Country
                {
                    CountryId   = countryId,
                    CountryName = countryName,
                    Latitude    = latitude,
                    Longitude   = longitude,
                    SurfaceArea = area,
                    ContinentId = continentId,
                    Population  = population,
                    FlagImage   = fileData
                };

                string   newLanguageNames = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxNewLanguages");
                string[] languageNames    = newLanguageNames.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string languageName in languageNames)
                {
                    var language = context.Languages.FirstOrDefault(l => string.Compare(l.LanguageName, languageName, true) == 0);
                    if (language == null)
                    {
                        language = new Language
                        {
                            LanguageName = languageName
                        };

                        context.Languages.Add(language);
                        context.SaveChanges();
                    }

                    country.Languages.Add(language);
                }

                context.Countries.Add(country);

                context.SaveChanges();
                Response.Redirect(Request.RawUrl);
            }
            catch (Exception ex)
            {
                this.LabelCountryErrors.Text = ex.Message;
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
Beispiel #15
0
        protected void GridViewCountries_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            WorldEntities context = null;

            this.LabelCountryErrors.Text = string.Empty;

            try
            {
                string countryName = (this.GridViewCountries.Rows[e.RowIndex].FindControl("TextBoxCountryName") as TextBox).Text;
                this.ValidateName(countryName);

                float  latitude;
                string latitudeAsString = (this.GridViewCountries.Rows[e.RowIndex].FindControl("TextBoxLatitude") as TextBox).Text;
                this.ValidateGeoCoordinate(latitudeAsString, out latitude);

                float  longitude;
                string longitudeAsString = (this.GridViewCountries.Rows[e.RowIndex].FindControl("TextBoxLongitude") as TextBox).Text;
                this.ValidateGeoCoordinate(longitudeAsString, out longitude);

                float  area;
                string areaAsString = (this.GridViewCountries.Rows[e.RowIndex].FindControl("TextBoxSurfaceArea") as TextBox).Text;
                this.ValidateArea(areaAsString, out area);

                int    population;
                string populationAsString = (this.GridViewCountries.Rows[e.RowIndex].FindControl("TextBoxPopulation") as TextBox).Text;
                this.ValidatePopulation(populationAsString, out population);

                context = new WorldEntities();

                string selectedCountryId = this.GridViewCountries.DataKeys[e.RowIndex].Value.ToString();

                var country = context.Countries.FirstOrDefault(c => c.CountryId == selectedCountryId);
                if (country != null)
                {
                    var postedFile = (this.GridViewCountries.Rows[e.RowIndex].FindControl("FileUploadChangeFlag") as FileUpload).PostedFile;

                    if (postedFile != null && postedFile.ContentLength > 0)
                    {
                        byte[] data = this.GetUploadedFile(postedFile);

                        country.FlagImage = data;

                        context.Entry <Country>(country).State = EntityState.Modified;

                        context.SaveChanges();
                    }

                    country.Languages.Clear();

                    string   newLanguageNames = this.GetTextBoxText(this.GridViewCountries, e.RowIndex, "TextBoxLanguages");
                    string[] languageNames    = newLanguageNames.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string languageName in languageNames)
                    {
                        var language = context.Languages.FirstOrDefault(l => string.Compare(l.LanguageName, languageName, true) == 0);
                        if (language == null)
                        {
                            language = new Language
                            {
                                LanguageName = languageName
                            };

                            context.Languages.Add(language);
                            context.SaveChanges();
                        }

                        country.Languages.Add(language);
                    }

                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                this.LabelCountryErrors.Text = ex.Message;
                e.Cancel = true;
            }
            finally
            {
                if (context != null)
                {
                    context.Dispose();
                }
            }
        }
Beispiel #16
0
        protected void ButtonAddCountry_Click(object sender, EventArgs e)
        {
            string newCountryID = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxAddCountryId");

            if (!IsValidCountryId(newCountryID))
            {
                return;
            }

            string newCountryName = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxAddCountry");

            if (!IsValidCountryName(newCountryName))
            {
                return;
            }

            string newCountryLatitude = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxAddLatitude");
            float  latitude;

            if (!float.TryParse(newCountryLatitude, out latitude))
            {
                Response.Write("Enter correct latitude!");
                return;
            }

            string newCountryLongitude = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxAddLongitude");
            float  longitude;

            if (!float.TryParse(newCountryLongitude, out longitude))
            {
                Response.Write("Enter correct longitude!");
                return;
            }

            string newCountrySurfaceArea = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxAddSurfaceArea");
            int    surfaceArea;

            if (!int.TryParse(newCountrySurfaceArea, out surfaceArea))
            {
                Response.Write("Enter correct Surface Area (int number)!");
                return;
            }

            string newCountryPopulation = this.GetFooterRowTextBoxText(this.GridViewCountries, "TextBoxAddPopulation");
            int    population;

            if (!int.TryParse(newCountryPopulation, out population))
            {
                Response.Write("Enter correct population (int number)!");
                return;
            }

            ListBox listBoxLanguages = this.GridViewCountries.FooterRow.FindControl("ListBoxAddLanguages") as ListBox;

            int[] listBoxLanguagesIndices = listBoxLanguages.GetSelectedIndices();

            if (listBoxLanguagesIndices.Length < 1)
            {
                Response.Write("Correct Country is required!");
                return;
            }

            Country newCountry = new Country()
            {
                CountryId   = newCountryID,
                CountryName = newCountryName,
                Latitude    = latitude,
                Longitude   = longitude,
                SurfaceArea = surfaceArea,
                Population  = population
            };

            WorldEntities db                     = new WorldEntities();
            var           allLanguages           = listBoxLanguages.Items;
            string        currSelectedLanguageId = string.Empty;
            Language      currLanguage;

            foreach (int languageIndex in listBoxLanguagesIndices)
            {
                currSelectedLanguageId = allLanguages[languageIndex].Value;
                currLanguage           = db.Languages.FirstOrDefault(lang => lang.LanguageId.ToString() == currSelectedLanguageId);

                if (currLanguage == null)
                {
                    Response.Write("Invalid Country entered!");
                    return;
                }

                newCountry.Languages.Add(currLanguage);
            }

            var selectedContinentId = this.ListBoxContinents.SelectedItem.Value;

            var continent = db.Continents.FirstOrDefault(c => c.ContinentId.ToString() == selectedContinentId);

            if (continent == null)
            {
                Response.Write("Selected continent was not found!");
                return;
            }

            newCountry.Continent = continent;

            FileUpload fileUploadControl = this.GridViewCountries.FooterRow.FindControl("FileUploadFlagChange") as FileUpload;

            byte[] fileData = this.GetUploadedFile(fileUploadControl.PostedFile);
            newCountry.FlagImage = fileData;

            db.Countries.Add(newCountry);
            db.SaveChanges();

            Response.Redirect(Request.RawUrl);
        }