Пример #1
0
        // click handler for all controls inside the admins panel
        private async void handlerAdmins_Click(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(PictureBox))
            {
                PictureBox pic = (PictureBox)sender;
                txtDebug.AppendText(pic.Name + " clicked[Admin handler]\r\n");

                if (pic.Name == "addAdmin")
                {
                    FormUser formUser = new FormUser();
                    //formUser.Reset();
                    if (formUser.ShowDialog() == DialogResult.OK)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=5&rnd={1}&mail={2}&pass={3}&name={4}&active={5}",
                                                                                      ServerURL, rndlogin, formUser.UserMail, formUser.UserPass, formUser.UserName, (formUser.UserActive) ? "1" : "0")));
                    }

                    return;
                }

                string[] words = pic.Name.Split('_');
                if (words.Length != 2)
                {
                    return;
                }
                string action = words[0];
                string random = words[1];

                switch (action)
                {
                case "Inactive":
                    if (MessageBox.Show("Esta seguro de que quiere desactivar a este Administrador?", "Importante", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=7&rnd={1}&user={2}&active=0", ServerURL, rndlogin, random)));
                    }
                    break;

                case "Active":
                    if (MessageBox.Show("Esta seguro de que quiere activar a este Administrador?", "Importante", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=7&rnd={1}&user={2}&active=1", ServerURL, rndlogin, random)));
                    }
                    break;

                case "Delete":
                    if (MessageBox.Show("Esta seguro de que quiere borrar este Administrador?", "Importante", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=6&rnd={1}&user={2}", ServerURL, rndlogin, random)));
                    }
                    break;

                case "Edit":
                    User     admin    = GetAdminByRandom(random);
                    FormUser formUser = new FormUser();
                    formUser.LoadData(admin.Mail, admin.Pass, admin.Name, admin.Active);
                    if (formUser.ShowDialog() == DialogResult.OK)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=7&rnd={1}&mail={2}&pass={3}&name={4}&active={5}&user={6}",
                                                                                      ServerURL, rndlogin, formUser.UserMail, formUser.UserPass, formUser.UserName, (formUser.UserActive) ? "1" : "0", random)));
                    }
                    break;
                }
            }
        }
Пример #2
0
        // click handler for all controls inside the users panel
        private async void handlerUsers_Click(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(PictureBox))
            {
                PictureBox pic = (PictureBox)sender;
                txtDebug.AppendText(pic.Name + " clicked[User handler]\r\n");

                if (pic.Name == "addUser")
                {
                    FormUser formUser = new FormUser();
                    //formUser.Reset();
                    if (formUser.ShowDialog() == DialogResult.OK)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=2&rnd={1}&mail={2}&pass={3}&name={4}&active={5}",
                                                                                      ServerURL, rndlogin, formUser.UserMail, formUser.UserPass, formUser.UserName, (formUser.UserActive) ? "1" : "0")));
                    }

                    return;
                }

                string[] words = pic.Name.Split('_');
                if (words.Length != 2)
                {
                    return;
                }
                string action = words[0];
                string random = words[1];

                switch (action)
                {
                case "Inactive":
                    if (MessageBox.Show("Esta seguro de que quiere desactivar a este Usuario?", "Importante", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=4&rnd={1}&user={2}&active=0", ServerURL, rndlogin, random)));
                    }
                    break;

                case "Active":
                    if (MessageBox.Show("Esta seguro de que quiere activar a este Usuario?", "Importante", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=4&rnd={1}&user={2}&active=1", ServerURL, rndlogin, random)));
                    }
                    break;

                case "Delete":
                    if (MessageBox.Show("Esta seguro de que quiere borrar este Usuario?", "Importante", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=3&rnd={1}&user={2}", ServerURL, rndlogin, random)));

                        if (selected == random)
                        {
                            selected = "";
                            rndquery = "x";
                        }
                    }
                    break;

                case "Edit":
                    User     user     = GetUserByRandom(random);
                    FormUser formUser = new FormUser();
                    formUser.LoadData(user.Mail, user.Pass, user.Name, user.Active);
                    if (formUser.ShowDialog() == DialogResult.OK)
                    {
                        await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}admin.cgi?cmd=4&rnd={1}&mail={2}&pass={3}&name={4}&active={5}&user={6}",
                                                                                      ServerURL, rndlogin, formUser.UserMail, formUser.UserPass, formUser.UserName, (formUser.UserActive) ? "1" : "0", random)));
                    }
                    break;
                }
            }
            else // Label
            {
                Label lbl = (Label)sender;
                txtDebug.AppendText(lbl.Name + " clicked[User handler]\r\n");

                string[] words = lbl.Name.Split('_');
                if (words.Length != 2)
                {
                    return;
                }
                string action = words[0];
                string random = words[1];

                if (action == "Name")
                {
                    selected = random;
                    rndquery = random;
                    // load stats
                    try
                    {
                        DateTime today = DateTime.Today;
                        string   csv   = await webClient.GetHTTPStringPTaskAsync(new Uri(String.Format("{0}user.cgi?cmd=8&rnd={1}&date={2}&sum=day",
                                                                                                       ServerURL, rndquery, String.Format("{0}-{1:D2}", today.Year, today.Month))));

                        if (csv != null)
                        {
                            LoadStatsOnDGV(dgv_user_day, csv, "user_day");
                        }
                    }
                    catch
                    {
                        // error msg
                        dgv_user_day.Rows.Clear();
                    }
                    timer_Tick(null, null);
                }
            }
        }