protected void gvShareKeys_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            ShareKey sk = ShareKey.ShareKeyWithID(e.Keys[0].ToString());

            if (sk == null)
            {
                throw new InvalidOperationException("Unknown key: " + e.Keys[0].ToString());
            }
            sk.Name                   = (string)e.NewValues["Name"] ?? String.Empty;
            sk.CanViewCurrency        = (bool)e.NewValues["CanViewCurrency"];
            sk.CanViewTotals          = (bool)e.NewValues["CanViewTotals"];
            sk.CanViewFlights         = (bool)e.NewValues["CanViewFlights"];
            sk.CanViewAchievements    = (bool)e.NewValues["CanViewAchievements"];
            sk.CanViewVisitedAirports = (bool)e.NewValues["CanViewVisitedAirports"];
            if (sk.FCommit())
            {
                gvShareKeys.EditIndex = -1;
                RefreshSharekeys();
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void btnCreateShareLink_Click(object sender, EventArgs e)
        {
            ShareKey sk = new ShareKey(Page.User.Identity.Name)
            {
                Name                   = txtShareLinkName.Text,
                CanViewCurrency        = ckShareLinkCurrency.Checked,
                CanViewFlights         = ckShareLinkFlights.Checked,
                CanViewTotals          = ckShareLinkTotals.Checked,
                CanViewAchievements    = ckShareLinkAchievements.Checked,
                CanViewVisitedAirports = ckShareLinkAirports.Checked
            };

            try
            {
                sk.FCommit();
                txtShareLinkName.Text       = string.Empty;
                ckShareLinkCurrency.Checked = ckShareLinkFlights.Checked = ckShareLinkTotals.Checked = ckShareLinkAchievements.Checked = ckShareLinkAirports.Checked = true;
                gvShareKeys.EditIndex       = -1;
                RefreshSharekeys();
            }
            catch (MyFlightbookValidationException ex)
            {
                lblShareKeyErr.Text = ex.Message;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Returns a sharekey with the specified ID (guid).  CAN RETURN NULL IF NOT FOUND
        /// </summary>
        /// <param name="szID">The id of the sharekey to find</param>
        /// <returns>The sharekey, or null</returns>
        public static ShareKey ShareKeyWithID(string szID)
        {
            DBHelper dbh = new DBHelper("SELECT * FROM sharekeys WHERE GUID=?guid");
            ShareKey sk  = null;

            dbh.ReadRow(
                (comm) => { comm.Parameters.AddWithValue("guid", szID); },
                (dr) => { sk = new ShareKey(dr); });
            return(sk);
        }
 protected void gvShareKeys_RowCommand(object sender, CommandEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (String.Compare(e.CommandName, "_Delete", StringComparison.OrdinalIgnoreCase) == 0)
     {
         ShareKey sk = ShareKey.ShareKeyWithID(e.CommandArgument.ToString());
         if (sk != null)
         {
             sk.FDelete();
             RefreshSharekeys();
         }
     }
 }
 protected void RefreshSharekeys()
 {
     gvShareKeys.DataSource = ShareKey.ShareKeysForUser(Page.User.Identity.Name);
     gvShareKeys.DataBind();
 }