private void BtnDelete_Click(object sender, EventArgs e)
 {
     if (Block)
     {
         return;
     }
     if (SitesDataGrid.CurrentCell != null && SitesDataGrid.CurrentCell.RowIndex >= 0)
     {
         int selected = (int)SitesDataGrid.Rows[SitesDataGrid.CurrentCell.RowIndex].Tag;
         if (ConfirmDelete() == true)
         {
             SiteClass site = SitesManager.GetByIndex(selected);
             if (site != null)
             {
                 if (site.operation == UpdateOperation.ADD_NEW)
                 {
                     SitesManager.Delete(site);
                 }
                 else
                 {
                     site.operation = UpdateOperation.DELETE;
                     SitesManager.UpdateSite(site);
                 }
             }
             InitializeEditor();
         }
     }
     else
     {
         MessageBox.Show("Please select a site!");
     }
 }
        private void BtnPause_Click(object sender, EventArgs e)
        {
            if (Block)
            {
                return;
            }
            if (SitesDataGrid.CurrentCell != null && SitesDataGrid.CurrentCell.RowIndex >= 0)
            {
                int       selected = (int)SitesDataGrid.Rows[SitesDataGrid.CurrentCell.RowIndex].Tag;
                SiteClass site     = SitesManager.GetByIndex(selected);
                if (site != null)
                {
                    site.IsActive = site.IsActive ? false : true;
                    if (site.operation != UpdateOperation.ADD_NEW)
                    {
                        site.operation = UpdateOperation.CHANGED;
                    }

                    SitesManager.UpdateSite(site);
                }
            }
            else
            {
                MessageBox.Show("Please select a site!");
            }
        }
        private void Save_Click(object sender, EventArgs e)
        {
            if (Block)
            {
                return;
            }
            if (SitesDataGrid.CurrentCell != null && SitesDataGrid.CurrentCell.RowIndex >= 0)
            {
                int    selected = (int)SitesDataGrid.Rows[SitesDataGrid.CurrentCell.RowIndex].Tag;
                string nameInpx = nameInp.Text;
                if (nameInpx.Length > 20)
                {
                    MessageBox.Show("Site name is too long, max can have 20 characters.");
                    return;
                }

                string websiteInpx = websiteInp.Text;
                if (websiteInpx.Length > 200)
                {
                    MessageBox.Show("Site URL is too long, max can have 200 characters.");
                    return;
                }

                if (!CheckURLValid(websiteInpx))
                {
                    MessageBox.Show("Site URL invalid please use somthing like this:http://example.com");
                    return;
                }
                SiteClass site = SitesManager.GetByIndex(selected);
                if (site != null)
                {
                    site.WebsiteName = nameInpx;
                    site.Url         = websiteInpx;
                    site.Time        = (uint)secondsDrop.Value;
                    site.Region      = (CountryList)region.SelectedIndex;
                    site.Referral    = (ReferralType)Referral.SelectedIndex;
                    if (site.operation != UpdateOperation.ADD_NEW)
                    {
                        site.operation = UpdateOperation.CHANGED;
                    }

                    SitesManager.UpdateSite(site);
                    InitializeEditor();
                }
            }
        }
 private void ListBox1_SelectionChanged(object sender, EventArgs e)
 {
     if (Block)
     {
         return;
     }
     if (SitesDataGrid.CurrentCell != null && SitesDataGrid.CurrentCell.RowIndex >= 0)
     {
         int       selected = (int)SitesDataGrid.Rows[SitesDataGrid.CurrentCell.RowIndex].Tag;
         SiteClass site     = SitesManager.GetByIndex(selected);
         if (site != null)
         {
             nameInp.Text           = site.WebsiteName;
             websiteInp.Text        = site.Url;
             secondsDrop.Value      = site.Time;
             hitsLabel.Text         = site.ViewCount.ToString();
             btnPause.Text          = site.IsActive ? "Start" : "Pause";
             AlexaRankLabel.Text    = GetAlexa(site.Url);
             region.SelectedIndex   = (int)site.Region >= 255 ? 0 : (int)site.Region;
             Referral.SelectedIndex = (int)site.Referral >= 255 ? 0 : (int)site.Referral;
             labelStatus.Text       = site.IsActive ? "Paused" : "Started";
         }
     }
 }