Ejemplo n.º 1
0
        public void SaveGeneralItemInfo(EditGeneralInfo info, EditModelSave editModelSave)
        {
            var item = SelectItem(editModelSave.ItemNumber, false);

            if (item.Item.Name != info.NewItemName)
            {
                RecordChange(item.Item.Id, "UPDATE", "name", item.Item.Name, info.NewItemName);
            }

            if (item.Item.RarityId != info.NewRarity)
            {
                RecordChange(item.Item.Id, "UPDATE", "rarity", item.Item.RarityId.ToString(), info.NewRarity.ToString());
            }

            if (item.Item.CategoryId != info.NewCategory)
            {
                RecordChange(item.Item.Id, "UPDATE", "category", item.Item.CategoryId.ToString(), info.NewCategory.ToString());
            }

            if (item.Item.TypeId != info.NewType)
            {
                RecordChange(item.Item.Id, "UPDATE", "type", item.Item.TypeId.ToString(), info.NewType.ToString());
            }

            if (item.Item.Removed != Convert.ToInt32(info.NewRemovedStatus))
            {
                RecordChange(item.Item.Id, "UPDATE", "removed", Convert.ToString(item.Item.Removed), Convert.ToString(Convert.ToInt32(info.NewRemovedStatus)));
            }

            int removed = 0;

            if (info.NewRemovedStatus)
            {
                removed = 1;
            }
            List <Parameter> parameters = new List <Parameter>();

            parameters.Add(new Parameter {
                Identifier = "@id", Value = editModelSave.ItemNumber
            });
            parameters.Add(new Parameter {
                Identifier = "@locname", Value = info.NewItemName
            });
            parameters.Add(new Parameter {
                Identifier = "@rarity", Value = info.NewRarity
            });
            parameters.Add(new Parameter {
                Identifier = "@category", Value = info.NewCategory
            });
            parameters.Add(new Parameter {
                Identifier = "@type", Value = info.NewType
            });
            parameters.Add(new Parameter {
                Identifier = "@removed", Value = removed
            });
            var result = DB.ExecuteSQL("UPDATE item SET item.name = @locname, item.raritynumber = @rarity, item.categorynumber = @category, item.typenumber = @type, item.removed = @removed WHERE item.id = @id", parameters);
        }
Ejemplo n.º 2
0
        public void SaveRecipe(EditModelSave editModelSave, List <EditItem> items)
        {
            if (editModelSave.RecipeNumber == 0)
            {
                var result = DB.Insert("recipe", new string[] { "itemnumber", "factionnumber" }, new object[] { editModelSave.ItemNumber, editModelSave.FactionNumber });
                editModelSave.RecipeNumber = (int)result.LastInsertedId;
            }

            foreach (var item in items)
            {
                if (item.OldId > 0)
                {
                    if (item.Id > 0)
                    {
                        // New Item Id is above 0 so we update this item
                        List <Parameter> parameters = new List <Parameter>();
                        parameters.Add(new Parameter
                        {
                            Identifier = "@recipenumberWhere",
                            Value      = editModelSave.RecipeNumber
                        });
                        parameters.Add(new Parameter {
                            Identifier = "@recipeitemnumber", Value = item.RecipeItemNumber
                        });

                        var rs = DB.Update("recipeitem",
                                           new string[] { "itemnumber", "number" },
                                           new object[] { item.Id, item.Number },
                                           "recipenumber = @recipenumberWhere AND recipeitem.id = @recipeitemnumber",
                                           parameters);
                    }
                    else
                    {
                        // New Item Id is 0 (or below) we delete this item
                        List <Parameter> parameters = new List <Parameter>();
                        parameters.Add(new Parameter
                        {
                            Identifier = "@recipenumberWhere",
                            Value      = editModelSave.RecipeNumber
                        });
                        parameters.Add(new Parameter {
                            Identifier = "@recipeitemnumber", Value = item.RecipeItemNumber
                        });
                        var result =
                            DB.ExecuteSQL(
                                "DELETE FROM recipeitem WHERE recipenumber = @recipenumberWhere AND recipeitem.id = @recipeitemnumber;",
                                parameters);
                    }
                }
                if (item.OldId == 0)
                {
                    if (item.Id > 0 && item.Number > 0)
                    {
                        DB.Insert("recipeitem", new string[] { "recipenumber", "itemnumber", "number" },
                                  new object[] { editModelSave.RecipeNumber, item.Id, item.Number });
                    }
                }
            }

            if (editModelSave.OldFactionNumber > 0 && editModelSave.FactionNumber > 0 && editModelSave.FactionNumber != editModelSave.OldFactionNumber)
            {
                List <Parameter> parameters = new List <Parameter>();
                parameters.Add(new Parameter {
                    Identifier = "@factionnumber", Value = editModelSave.FactionNumber
                });
                parameters.Add(new Parameter {
                    Identifier = "@recipenumber", Value = editModelSave.RecipeNumber
                });
                var result = DB.ExecuteSQL("UPDATE recipe SET recipe.factionnumber = @factionnumber WHERE recipe.id = @recipenumber", parameters);
            }
        }