Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorShop"/> class.
        /// </summary>
        /// <param name="id">The <see cref="ShopID"/>.</param>
        /// <param name="existing">The <see cref="EditorShop"/> to copy the values from.</param>
        public EditorShop(ShopID id, EditorShop existing)
        {
            _id = id;

            Name = existing.Name;
            CanBuy = existing.CanBuy;

            _items = new List<ItemTemplateID>(existing._items);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditorShop"/> class.
        /// </summary>
        /// <param name="id">The <see cref="ShopID"/>.</param>
        /// <param name="existing">The <see cref="EditorShop"/> to copy the values from.</param>
        public EditorShop(ShopID id, EditorShop existing)
        {
            _id = id;

            Name   = existing.Name;
            CanBuy = existing.CanBuy;

            _items = new List <ItemTemplateID>(existing._items);
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the Click event of the btnShopNew control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnShopNew_Click(object sender, EventArgs e)
        {
            const string confirmMsg = "Are you sure you wish to create a new shop?";

            if (MessageBox.Show(confirmMsg, "Create new?", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            // Ask if they want to clone the selected object
            var clone = false;

            if (pgShop.SelectedObject != null)
            {
                const string cloneMsg = "Do you wish to copy the values from the currently selected shop?";
                clone = MessageBox.Show(cloneMsg, "Clone?", MessageBoxButtons.YesNo) == DialogResult.Yes;
            }

            // Get the next free ID
            var id = ReserveFreeShopID(_dbController);

            // Create the template
            EditorShop newShop;

            if (clone)
            {
                // Clone from existing template
                try
                {
                    newShop = new EditorShop(id, (EditorShop)pgShop.SelectedObject);
                }
                catch (Exception)
                {
                    // If cloning fails, make sure we delete the ID we reserved before returning the exception
                    _dbController.GetQuery <DeleteShopQuery>().Execute(id);
                    throw;
                }
            }
            else
            {
                // Create new template using the default table values (the row already exists since we reserved it)
                newShop = new EditorShop(id, _dbController);
            }

            // Set the new shop
            pgShop.SelectedObject = newShop;
        }