private void selectRuleButton_Click(object sender, EventArgs e)
 {
     specRuleLabel.Visible    = true;
     editSpecRuleText.Visible = true;
     saveEditRule.Visible     = true;
     editRule = (SpecialRule)specRuleCombo.SelectedItem;
     editSpecRuleText.Text = editRule.Rule;
 }
        public ActionResult DeleteConfirmed(int id)
        {
            SpecialRule specialRule = db.SpecialRules.Find(id);

            db.SpecialRules.Remove(specialRule);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        private void saveNewButton_Click(object sender, EventArgs e)
        {
            SpecialRule newSpecRule = new SpecialRule();

            newSpecRule.Rule = ruleText.Text;
            specRuleController.InsertSpecialRule(newSpecRule);
            ruleText.Clear();
        }
 public ActionResult Edit([Bind(Include = "SpecialRuleId,Name,Description")] SpecialRule specialRule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(specialRule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(specialRule));
 }
        public ActionResult Create([Bind(Include = "SpecialRuleId,Name,Description")] SpecialRule specialRule)
        {
            if (ModelState.IsValid)
            {
                db.SpecialRules.Add(specialRule);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(specialRule));
        }
        public ParameterForm(SpecialRule rule)
        {
            InitializeComponent();
            this.rule = rule;

            //Fill in the DGV from the special rule
            dgvParameters.DataSource          = rule.VariableTable;
            dgvParameters.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            //Fill the info box
            populateDescription();
        }
Example #7
0
 private void clbSpecials_ItemCheck(object sender, ItemCheckEventArgs e)
 {
     if (e.NewValue == CheckState.Checked)
     {
         var         rules = getSelectedRules();
         SpecialRule rule  = (SpecialRule)clbSpecials.Items[e.Index];
         if (!rule.specialRuleIsValid(this.ability, rules))
         {
             e.NewValue = e.CurrentValue;
         }
     }
 }
Example #8
0
 public GeneratorRule(
     Func <RandomLevelData, bool> varProblem,
     Func <RandomLevelData, bool> varSolution,
     float varChance        = 1f,
     bool varMandatory      = false,
     SpecialRule varSpecial = SpecialRule.None)
 {
     this.problem   = varProblem;
     this.solution  = varSolution;
     this.chance    = varChance;
     this.mandatory = varMandatory;
     this.special   = varSpecial;
 }
Example #9
0
        private void AddSpecRuleButton_Click(object sender, EventArgs e)
        {
            SpecialRulesInstance newSpecRule  = new SpecialRulesInstance();
            SpecialRule          basicNewRule = (SpecialRule)specRuleCombo.SelectedItem;

            newSpecRule.RuleID = basicNewRule.RuleID;
            newSpecRule.Rule   = basicNewRule.Rule;
            newSpecRule.Amount = (int)specRuleAmountCounter.Value;
            newCharacter.AddSpecialRule(newSpecRule);
            specRulesListBox.DataSource    = null;
            specRulesListBox.DataSource    = newCharacter.SpecialRules;
            specRulesListBox.DisplayMember = "fullString";
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SpecialRule specialRule = db.SpecialRules.Find(id);

            if (specialRule == null)
            {
                return(HttpNotFound());
            }
            return(View(specialRule));
        }
Example #11
0
        private void AddNewRuleButton_Click(object sender, EventArgs e)
        {
            SpecialRulesInstance ruleToAdd = new SpecialRulesInstance();
            SpecialRule          ruleText  = (SpecialRule)specRuleCombo.SelectedItem;

            ruleToAdd.Rule   = ruleText.Rule;
            ruleToAdd.RuleID = ruleText.RuleID;
            ruleToAdd.Amount = (int)specRuleAmountBox.Value;
            selectedCharacter.AddSpecialRule(ruleToAdd);
            charController.InsertSpecialRuleInstance(ruleToAdd, selectedCharacter.CharID);
            specRuleListBox.DataSource    = null;
            specRuleListBox.DataSource    = selectedCharacter.SpecialRules;
            specRuleListBox.DisplayMember = "fullString";
        }
Example #12
0
        public void InsertSpecialRule(SpecialRule specRule)
        {
            connection = dbControl.getConnection();

            connection.Open();

            using (MySqlCommand cmd = new MySqlCommand("INSERT INTO Special_Rules (rule) VALUES (@rule) ", connection))
            {
                cmd.Parameters.AddWithValue("@rule", specRule.Rule);


                int rows = cmd.ExecuteNonQuery();
            }
        }
Example #13
0
        public bool Equals(SpecialRule r)
        {
            if ((object)r == null)
            {
                return(false);
            }

            //If the names of the abilities match, they are considered equal
            if (this.Name == r.Name)
            {
                return(true);
            }

            return(false);
        }
Example #14
0
        public void UpdateSpecialRule(SpecialRule specRule)
        {
            connection = dbControl.getConnection();

            connection.Open();

            using (MySqlCommand cmd = new MySqlCommand("UPDATE Special_Rules SET rule = @rule WHERE rule_id = @ruleID", connection))
            {
                cmd.Parameters.AddWithValue("@ruleID", specRule.RuleID);
                cmd.Parameters.AddWithValue("@rule", specRule.Rule);


                int rows = cmd.ExecuteNonQuery();
            }
        }
Example #15
0
        public List <SpecialRule> getSpecialRules()
        {
            connection = dbControl.getConnection();

            connection.Open();

            sql = "Select * from Special_Rules";

            command = new MySqlCommand(sql, connection);

            dataReader = command.ExecuteReader();

            while (dataReader.Read())
            {
                SpecialRule newSpecRule = new SpecialRule(dataReader.GetInt16(0), dataReader.GetString(1));

                specialRules.Add(newSpecRule);
            }

            connection.Close();

            return(specialRules);
        }
    private DataLine Parse(IRow data, int index, ItemDefinition definition, List <string> primaryKeys)
    {
        var d0  = DateTime.Now;
        var res = new DataLine()
        {
            Line = index, Data = string.Empty
        };

        if (data.Cells.Count > this.typeIndex.Count)
        {
            this.errors.Add(new Error()
            {
                Linea     = index,
                ErrorType = "Data",
                Message   = "El número de celdas no es correcto"
            });
        }
        else
        {
            var message  = new StringBuilder("[");
            int contCell = 0;
            var itemData = new ItemBuilder(this.Item.ItemName, definition, this.instance.Name);
            foreach (var field in itemFields)
            {
                var    cell      = data.GetCell(contCell);
                string cellValue = "null";
                string testValue = string.Empty;
                if (cell != null)
                {
                    cellValue = GetCellValueForJson(this.typeIndex[contCell], cell, field.Length);
                    testValue = cellValue;

                    // GES-129 Eliminar comillas del inicio y final
                    if (testValue.StartsWith("\"", StringComparison.OrdinalIgnoreCase))
                    {
                        testValue = testValue.Substring(1);
                    }

                    if (testValue.EndsWith("\"", StringComparison.OrdinalIgnoreCase))
                    {
                        testValue = testValue.Substring(0, testValue.Length - 1);
                    }

                    // GES-238 los mails y urls deben cumplir el formato
                    if (field.DataType == FieldDataType.Email)
                    {
                        if (field.Required || !string.IsNullOrEmpty(testValue))
                        {
                            if (!Basics.EmailIsValid(testValue))
                            {
                                this.errors.Add(new Error()
                                {
                                    Linea     = index,
                                    ErrorType = "Data",
                                    Message   = string.Format(
                                        CultureInfo.InvariantCulture,
                                        "El email del campo {0} no es valido ({1}).",
                                        field.Label,
                                        testValue)
                                });
                            }
                        }
                    }

                    if (field.DataType == FieldDataType.Url)
                    {
                        if (field.Required || !string.IsNullOrEmpty(testValue))
                        {
                            Uri  uriResult;
                            bool result = Uri.TryCreate(testValue, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
                            if (!result)
                            {
                                testValue = "http://" + testValue;
                                result    = Uri.TryCreate(testValue, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
                                if (!result)
                                {
                                    this.errors.Add(new Error()
                                    {
                                        Linea     = index,
                                        ErrorType = "Data",
                                        Message   = string.Format(
                                            CultureInfo.InvariantCulture,
                                            "La dirección URL del campo {0} no es valida ({1}).",
                                            field.Label,
                                            testValue)
                                    });
                                }
                            }
                        }
                    }

                    if (this.typeIndex[contCell] == FieldDataType.Text || this.typeIndex[contCell] == FieldDataType.Textarea)
                    {
                        if (field.Length.HasValue)
                        {
                            if (testValue.Length > field.Length)
                            {
                                this.errors.Add(new Error()
                                {
                                    Linea     = index,
                                    ErrorType = "Data",
                                    Message   = string.Format(
                                        CultureInfo.InvariantCulture,
                                        "El campo {0} tiene una longitud superior a {1}.",
                                        field.Label,
                                        field.Length.Value)
                                });
                            }
                        }
                    }
                    //// END GES-129

                    // Sólo se comprueba el FK si el campo está informado
                    if (!string.IsNullOrEmpty(testValue))
                    {
                        // GES-130 Se comprueba que si es un foreignlist haya valor en la tabla referenciada

                        /*if (definition.ForeignValues.Any(fv => fv.LocalName == field.Name))
                         * {
                         *  ForeignList fl = definition.ForeignValues.Where(fv =>  fv.LocalName.Equals(field.Name, StringComparison.OrdinalIgnoreCase)).First();
                         *  if (DataPersistence.GetAllByField(Item.InstanceName, fl.ItemName, fl.ImportReference, testValue).Count == 0)
                         *  {
                         *      errors.Add(new Error()
                         *      {
                         *          ErrorType = "Data",
                         *          Linea = index,
                         *          Message = string.Format(
                         *              CultureInfo.InvariantCulture,
                         *              "El campo <strong>{0}</strong> no encuentra referencia sobre el valor &quot;<strong>{1}</strong>&quot;",
                         *              field.Label,
                         *              testValue)
                         *      });
                         *  }
                         * }*/
                    }

                    if (cellValue.Equals("\"FixedList\"", StringComparison.OrdinalIgnoreCase))
                    {
                        string dataCell  = cell.StringCellValue;
                        var    fixedItem = new FixedListItem();// DataPersistence.FixedListItemGetById(itemData.InstanceName, field.FixedListId, dataCell);

                        if (!string.IsNullOrEmpty(cell.StringCellValue) && fixedItem == null)
                        {
                            errors.Add(new Error()
                            {
                                ErrorType = "Data",
                                Linea     = index,
                                Message   = string.Format(
                                    CultureInfo.InvariantCulture,
                                    "El campo <strong>{0}</strong> tiene el valor &quot;<strong>{1}</strong>&quot; que no está en la lista de valores aceptados",
                                    field.Label,
                                    dataCell)
                            });
                        }
                        else
                        {
                            itemData[field.Name] = fixedItem.Id;
                            cellValue            = string.Format(CultureInfo.InvariantCulture, @"""{0}""", fixedItem.Description);
                            testValue            = cellValue.Replace("\"", string.Empty);
                        }
                    }
                    else
                    {
                        if (this.typeIndex[contCell] == FieldDataType.ImageGallery)
                        {
                            itemData.Add(field.Name, string.Empty);
                            testValue = string.Empty;
                        }
                        else if (field.DataType == FieldDataType.Boolean || field.DataType == FieldDataType.NullableBoolean)
                        {
                            if (!string.IsNullOrEmpty(testValue))
                            {
                                itemData.Add(field.Name, Convert.ToBoolean(testValue));
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(testValue))
                            {
                                itemData.Add(field.Name, testValue.Replace(@"\""", @""""));
                            }
                            else
                            {
                                itemData.Add(field.Name, cellValue);
                            }
                        }
                    }
                }

                message.AppendFormat(CultureInfo.InvariantCulture, @"{0}""{1}""", contCell > 0 ? "," : string.Empty, testValue);
                contCell++;
            }

            // Juan Castilla - Comprobar que la PK no esté ya en la carga
            string primaryKeyData = itemData.PrimaryKeyData;
            if (primaryKeys.Contains(primaryKeyData))
            {
                this.errors.Add(new Error()
                {
                    Linea     = index,
                    ErrorType = "Data",
                    Message   = "La clave ya aparece en otro registro de esta carga"
                });
            }
            else
            {
                primaryKeys.Add(primaryKeyData);
            }

            // Cofirmar que los campos obligatorios están rellenados
            foreach (var field in Item.Definition.Fields.Where(f => f.Required))
            {
                if (field.Name != "Id" && field.Name != "CompanyId")
                {
                    if (!itemData.ContainsKey(field.Name))
                    {
                        this.errors.Add(new Error()
                        {
                            Linea     = index,
                            ErrorType = "Data",
                            Message   = string.Format(CultureInfo.InvariantCulture, "El campo {0} es obligatorio", field.Label)
                        });
                    }
                    else if (itemData[field.Name] == null)
                    {
                        this.errors.Add(new Error()
                        {
                            Linea     = index,
                            ErrorType = "Data",
                            Message   = "El campo " + field.Label + " es obligatorio"
                        });
                    }
                }
            }

            if (itemData.Definition.ItemRules.Count > 0)
            {
                foreach (var rule in itemData.Definition.ItemRules)
                {
                    var complains = new SpecialRule(itemData, rule).Complains;
                    if (!complains.Success)
                    {
                        this.errors.Add(new Error()
                        {
                            Linea     = index,
                            ErrorType = "Data",
                            Message   = complains.MessageError
                        });
                    }
                }
            }

            message.Append("]");

            if (res.Data.Count() < 21)
            {
                res.Data = message.ToString();
            }

            this.dataFile.Add(res);
            this.itemsReaded.Add(itemData);
        }

        return(res);
    }