Ejemplo n.º 1
0
        public async Task <IActionResult> EditStone(uint menuId, uint actionId)
        {
            uint db = (uint)HttpContext.Session.GetInt32("world");

            using (var conn = StoneMenu.GetWorldDb(db))
            {
                var menu = (await conn.QueryAsync <StoneMenu>(
                                "SELECT * FROM `pomelo_teleport_template` " +
                                "WHERE `menu_id` = @menuId AND `action_id` = @actionId;",
                                new { menuId, actionId })).SingleOrDefault();
                if (menu == null)
                {
                    return(Prompt(x =>
                    {
                        x.Title = "没有找到菜单";
                        x.Details = "您指定的宝石菜单没有找到,请返回重试";
                        x.StatusCode = 404;
                    }));
                }

                using (var conn2 = CustomCurrency.GetAuthDb())
                {
                    var currencies = await conn2.QueryAsync <CustomCurrency>(
                        "SELECT * FROM `pomelo_currency`;");

                    ViewBag.Currencies = currencies;
                }

                return(View(menu));
            }
        }
Ejemplo n.º 2
0
    protected void FromForm()
    {
        CustomCurrency cc = new CustomCurrency();

        cc.ID          = Convert.ToInt32(hdnCCId.Value, CultureInfo.InvariantCulture);
        cc.UserName    = Page.User.Identity.Name;
        cc.DisplayName = txtRuleName.Text.Trim();
        CustomCurrency.LimitType lt = CustomCurrency.LimitType.Minimum;
        if (Enum.TryParse <CustomCurrency.LimitType>(cmbLimitType.SelectedValue, out lt))
        {
            cc.CurrencyLimitType = lt;
        }
        cc.RequiredEvents = decMinEvents.Value;
        cc.EventType      = (CustomCurrency.CustomCurrencyEventType)Convert.ToInt32(cmbEventTypes.SelectedValue, CultureInfo.InvariantCulture);
        cc.TimespanType   = SelectedTimespanType;
        cc.ExpirationSpan = cc.TimespanType.IsAligned() ? 0 : Convert.ToInt32(txtTimeFrame.Text, CultureInfo.CurrentCulture);

        cc.ModelsRestriction   = IDsFromList(lstModels);
        cc.AircraftRestriction = IDsFromList(lstAircraft);
        cc.CatClassRestriction = (CategoryClass.CatClassID)Enum.Parse(typeof(CategoryClass.CatClassID), cmbCatClass.SelectedValue);
        cc.CategoryRestriction = cmbCategory.SelectedValue.Trim();

        cc.TextRestriction     = txtContainedText.Text;
        cc.AirportRestriction  = txtAirport.Text;
        cc.PropertyRestriction = IDsFromList(lstProps);

        m_cc = cc;
    }
    protected void ToForm()
    {
        CustomCurrency cc = Currency;

        hdnCCId.Value               = cc.ID.ToString(CultureInfo.InvariantCulture);
        txtRuleName.Text            = cc.DisplayName;
        cmbLimitType.SelectedValue  = cc.CurrencyLimitType.ToString();
        txtNumEvents.Text           = cc.RequiredEvents.ToString(CultureInfo.CurrentCulture);
        cmbEventTypes.SelectedValue = ((int)cc.EventType).ToString(CultureInfo.InvariantCulture);
        SelectedTimespanType        = cc.TimespanType;
        txtTimeFrame.Text           = cc.TimespanType.IsAligned() ? string.Empty : cc.ExpirationSpan.ToString(CultureInfo.InvariantCulture);

        foreach (ListItem li in lstModels.Items)
        {
            li.Selected = cc.ModelsRestriction.Contains(Convert.ToInt32(li.Value, CultureInfo.InvariantCulture));
        }
        foreach (ListItem li in lstAircraft.Items)
        {
            li.Selected = cc.AircraftRestriction.Contains(Convert.ToInt32(li.Value, CultureInfo.InvariantCulture));
        }
        cmbCategory.SelectedValue = cc.CategoryRestriction;
        cmbCatClass.SelectedValue = cc.CatClassRestriction.ToString();

        btnAddCurrencyRule.Visible = cc.ID <= 0;    // only show the add button if we're doing a new currency.
    }
Ejemplo n.º 4
0
    protected void ToForm()
    {
        CustomCurrency cc = Currency;

        hdnCCId.Value              = cc.ID.ToString(CultureInfo.InvariantCulture);
        txtRuleName.Text           = cc.DisplayName;
        cmbLimitType.SelectedValue = cc.CurrencyLimitType.ToString();
        if (cc.EventType.IsIntegerOnly())
        {
            decMinEvents.EditingMode = Controls_mfbDecimalEdit.EditMode.Integer;
            decMinEvents.IntValue    = (int)cc.RequiredEvents;
        }
        else
        {
            decMinEvents.EditingMode = Controls_mfbDecimalEdit.EditMode.Decimal;
            decMinEvents.Value       = cc.RequiredEvents;
        }

        cmbEventTypes.SelectedValue = ((int)cc.EventType).ToString(CultureInfo.InvariantCulture);
        SelectedTimespanType        = cc.TimespanType;
        txtTimeFrame.Text           = cc.TimespanType.IsAligned() ? string.Empty : cc.ExpirationSpan.ToString(CultureInfo.InvariantCulture);

        foreach (ListItem li in lstModels.Items)
        {
            li.Selected = cc.ModelsRestriction.Contains(Convert.ToInt32(li.Value, CultureInfo.InvariantCulture));
        }
        foreach (ListItem li in lstAircraft.Items)
        {
            li.Selected = cc.AircraftRestriction.Contains(Convert.ToInt32(li.Value, CultureInfo.InvariantCulture));
        }
        cmbCategory.SelectedValue = cc.CategoryRestriction;
        cmbCatClass.SelectedValue = cc.CatClassRestriction.ToString();

        txtAirport.Text       = cc.AirportRestriction;
        txtContainedText.Text = cc.TextRestriction;
        if (cc.PropertyRestriction != null)
        {
            HashSet <int> hsPropsChecked = new HashSet <int>(cc.PropertyRestriction);
            foreach (ListItem li in lstProps.Items)
            {
                int propID = Convert.ToInt32(li.Value, CultureInfo.InvariantCulture);
                li.Selected = cc.PropertyRestriction.Contains(propID);
                hsPropsChecked.Remove(propID);
            }

            // Add in any properties that were not found above!  (I.e., blacklisted or otherwise not favorite)
            IEnumerable <CustomPropertyType> rgBlackListProps = CustomPropertyType.GetCustomPropertyTypes(hsPropsChecked);
            foreach (CustomPropertyType cpt in rgBlackListProps)
            {
                lstProps.Items.Add(new ListItem(cpt.Title, cpt.PropTypeID.ToString(CultureInfo.InvariantCulture))
                {
                    Selected = true
                });
            }
        }

        btnAddCurrencyRule.Visible = cc.ID <= 0;    // only show the add button if we're doing a new currency.
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes an aircraft from the user's list.  Does NOT remove the underlying aircraft.
        /// </summary>
        /// <param name="AircraftID">The ID of the aircraft to delete</param>
        /// <returns>The updated list of aircraft for the user.</returns>
        public Aircraft[] FDeleteAircraftforUser(int AircraftID)
        {
            if (String.IsNullOrEmpty(User))
            {
                throw new MyFlightbookException("No user specified for Deleteaircraft");
            }

            AircraftStats acs = new AircraftStats(User, AircraftID);

            // if the user has no flights with this aircraft, simply remove it from their list and be done
            if (acs.UserFlights != 0)
            {
                throw new MyFlightbookException(Resources.Aircraft.errAircraftInUse);
            }
            else
            {
                new DBHelper().DoNonQuery("DELETE FROM useraircraft WHERE userName=?username AND idAircraft=?aircraftID",
                                          (comm) =>
                {
                    comm.Parameters.AddWithValue("username", User);
                    comm.Parameters.AddWithValue("aircraftID", AircraftID);
                }
                                          );
                InvalidateCache();
            }

            // Delete any deadlines associated with this aircraft
            foreach (DeadlineCurrency dc in DeadlineCurrency.DeadlinesForUser(User, AircraftID))
            {
                dc.FDelete();
            }

            // And delete any custom currencies associated with the aircraft
            foreach (CustomCurrency cc in CustomCurrency.CustomCurrenciesForUser(User))
            {
                List <int> ids = new List <int>(cc.AircraftRestriction);

                if (ids.Contains(AircraftID))
                {
                    ids.Remove(AircraftID);
                    cc.AircraftRestriction = ids;
                    cc.FCommit();
                }
            }

            // we don't actually delete the aircraft; no need to do so, even if it's not used by anybody because
            // (a) we can't force caches of aircraft lists to be invalid and,
            // (b) no harm from keeping it - if somebody re-uses the tailnumber, it will re-use the existing flight.

            return(GetAircraftForUser());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Support()
        {
            using (var conn = CustomCurrency.GetAuthDb())
            {
                var result = await conn.QueryAsync <CustomCurrency>(
                    "SELECT " +
                    "   `pomelo_currency`.`entry`, `pomelo_currency`.`name`, " +
                    "   `pomelo_currency`.`comment`, `pomelo_currency_owned`.`amount` " +
                    "FROM " +
                    "   `pomelo_currency`" +
                    "   LEFT JOIN " +
                    "       `pomelo_currency_owned` " +
                    "   ON " +
                    "       `pomelo_currency_owned`.`currency` = `pomelo_currency`.`entry` " +
                    "WHERE " +
                    "   `accid` = @accid;", new { accid = Account.Id });

                return(View(result.ToList()));
            }
        }
Ejemplo n.º 7
0
 protected void gvCustomCurrency_RowCommand(Object sender, CommandEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (String.Compare(e.CommandName, "_Delete", StringComparison.OrdinalIgnoreCase) == 0)
     {
         IEnumerable <CustomCurrency> rgCurrency = CustomCurrency.CustomCurrenciesForUser(Page.User.Identity.Name);
         int id = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture);
         foreach (CustomCurrency cc in rgCurrency)
         {
             if (cc.ID == id)
             {
                 cc.FDelete();
                 gvCustomCurrency.EditIndex = -1;
                 RefreshCustomCurrencyList();
                 break;
             }
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Replaces one aircraft for another for the user.  The old aircraft is not migrated if any existing flights use it.
        /// </summary>
        /// <param name="acNew">The new aircraft</param>
        /// <param name="acOld">The old aircraft</param>
        /// <param name="fMigrateFlights">True to migrate any existing flights.  If false, the old flights (and the old aircraft) may remain.</param>
        public void ReplaceAircraftForUser(Aircraft acNew, Aircraft acOld, bool fMigrateFlights)
        {
            if (acNew == null)
            {
                throw new ArgumentNullException("acNew");
            }
            if (acOld == null)
            {
                throw new ArgumentNullException("acOld");
            }

            if (acNew.AircraftID == acOld.AircraftID)
            {
                return;
            }

            // Add the new aircraft first
            FAddAircraftForUser(acNew);

            // Migrate any flights, if necessary...
            if (fMigrateFlights)
            {
                List <Aircraft> lstAc = new List <Aircraft>(GetAircraftForUser());

                // make sure we are populated with both old and new so that UpdateFlightAircraftForUser works.
                // (This can happen if you have one version of an aircraft and you go to add another version of it;
                // they won't both be there, but the query used in UpdateFlightAircraftForUser wants them both present.
                if (!lstAc.Exists(ac => ac.AircraftID == acNew.AircraftID))
                {
                    lstAc.Add(acNew);
                }
                if (!lstAc.Exists(ac => ac.AircraftID == acOld.AircraftID))
                {
                    lstAc.Add(acOld);
                }
                CachedAircraft = lstAc.ToArray();   // we'll nullify the cache below.

                LogbookEntry.UpdateFlightAircraftForUser(this.User, acOld.AircraftID, acNew.AircraftID);

                // Migrate any custom currencies associated with the aircraft
                foreach (CustomCurrency cc in CustomCurrency.CustomCurrenciesForUser(User))
                {
                    List <int> lst = new List <int>(cc.AircraftRestriction);

                    for (int i = 0; i < lst.Count; i++)
                    {
                        if (lst[i] == acOld.AircraftID)
                        {
                            lst[i] = acNew.AircraftID;
                            cc.AircraftRestriction = lst;
                            cc.FCommit();
                            break;
                        }
                    }
                }

                // And migrate any deadlines associated with the aircraft
                foreach (DeadlineCurrency dc in DeadlineCurrency.DeadlinesForUser(User, acOld.AircraftID))
                {
                    dc.AircraftID = acNew.AircraftID;
                    dc.FCommit();
                }

                try
                {
                    // Then delete the old aircraft.  Ignore any errors
                    FDeleteAircraftforUser(acOld.AircraftID);
                }
                catch (MyFlightbookException)
                {
                    InvalidateCache();
                }
            }
        }
Ejemplo n.º 9
0
    private void InitForm()
    {
        if (!m_fNeedsInit)
        {
            return;
        }

        m_fNeedsInit = false;

        foreach (CustomCurrencyTimespanType t in Enum.GetValues(typeof(CustomCurrencyTimespanType)))
        {
            cmbMonthsDays.Items.Add(new ListItem(t.DisplayString(), t.ToString()));
        }

        UserAircraft           ua    = new UserAircraft(Page.User.Identity.Name);
        IEnumerable <Aircraft> lstAc = ua.GetAircraftForUser();

        lstAircraft.DataSource = lstAc;
        lstAircraft.DataBind();

        List <ListItem> lstCurrencyEvents = new List <ListItem>();

        foreach (var value in Enum.GetValues(typeof(CustomCurrency.CustomCurrencyEventType)))
        {
            lstCurrencyEvents.Add(new ListItem(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(CustomCurrency.EventTypeLabel(1, (CustomCurrency.CustomCurrencyEventType)value)), ((int)value).ToString(CultureInfo.CurrentCulture)));
        }

        lstCurrencyEvents.Sort(delegate(ListItem a, ListItem b) { return(a.Text.CompareCurrentCultureIgnoreCase(b.Text)); });
        foreach (ListItem li in lstCurrencyEvents)
        {
            cmbEventTypes.Items.Add(li);
        }

        lstModels.DataSource = MakeModel.ModelsForAircraft(lstAc);
        lstModels.DataBind();

        IEnumerable <CategoryClass> rgCatClass = CategoryClass.CategoryClasses();

        cmbCatClass.DataSource = rgCatClass;
        cmbCatClass.DataBind();

        List <CustomPropertyType> lstCpt = new List <CustomPropertyType>(CustomPropertyType.GetCustomPropertyTypes(Page.User.Identity.Name));

        lstCpt.RemoveAll(cpt => !cpt.IsFavorite);
        lstProps.DataSource = lstCpt;
        lstProps.DataBind();

        // Get the categories (as opposed to catclass); this is something of a hack, but it avoids an extra DB call
        Dictionary <string, string> dictCategories = new Dictionary <string, string>();

        foreach (CategoryClass cc in rgCatClass)
        {
            dictCategories[cc.Category] = cc.Category;
        }
        List <string> lst = new List <string>(dictCategories.Keys);

        lst.Sort();
        foreach (string category in lst)
        {
            cmbCategory.Items.Add(new ListItem(category, category));
        }
    }
Ejemplo n.º 10
0
 public void RefreshCustomCurrencyList()
 {
     gvCustomCurrency.DataSource = CustomCurrency.CustomCurrenciesForUser(Page.User.Identity.Name);
     gvCustomCurrency.DataBind();
 }