Exemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (lbAlertOptions.Items.Count > 0)
            {
                EmailConf stringListEmail = new EmailConf();

                try
                {
                    if (stringListEmail.StringListEmail().Trim().Length > 1)
                    {
                        if (cbOptionCheck.SelectedIndex != -1)
                        {
                            DateMonit       = DateTime.Now.AddSeconds(Convert.ToDouble(numericUpDown2.Value));
                            button3.Text    = "Monitored";
                            ActiveButton    = true;
                            combineCombobox = comboBox2.SelectedItem + ":" + comboBox3.SelectedItem + ":" + comboBox4.SelectedItem;


                            Microsoft.Win32.RegistryKey key;
                            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("MD_DISC_ALERT_DATE");
                            key.SetValue("Hour", comboBox2.SelectedItem);
                            key.SetValue("Minute", comboBox3.SelectedItem);
                            key.SetValue("Second", comboBox4.SelectedItem);
                            key.SetValue("NumericMinute", numericUpDown2.Value);
                            key.Close();
                        }
                        else
                        {
                            MessageBox.Show("You must select 'Options - When to check the disc'", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("You must load emial list and save IT!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                catch
                {
                    MessageBox.Show("You must load emial list and save IT!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("You must add Alert Options!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            label2.Text = DateTime.Now.ToLongTimeString();
            //if (ActiveButton == true)
            //{
            //    if (System.DateTime.Now.ToLongTimeString() == textBox1.Text)
            //    {

            //        MessageBox.Show("To small hard disc");
            //    }
            //}
            if (DateTime.Now > Reflesh)
            {
                Reflesh = DateTime.Now.AddSeconds(5);
                DriveInfo[] refleshDrvs = DriveInfo.GetDrives();
                listBox1.Items.Clear();
                foreach (var Drv in refleshDrvs)
                {
                    if (Drv.IsReady)
                    {
                        listBox1.Items.Add("Disc name: " + Drv.Name + " available: " + (Convert.ToDecimal(Drv.AvailableFreeSpace) / 1024 / 1024 / 1024).ToString("n2") +
                                           " GB with " + (Convert.ToDecimal(Drv.TotalSize) / 1024 / 1024 / 1024).ToString("n2") + " GB, this is: "
                                           + (((Convert.ToDecimal(Drv.AvailableFreeSpace) / 1024 / 1024 / 1024) / (Convert.ToDecimal(Drv.TotalSize) / 1024 / 1024 / 1024)) * 100).ToString("n2") + "%");
                    }
                }
            }



            if (ActiveButton == true)
            {
                if (cbOptionCheck.SelectedIndex == 0)
                {
                    DateTime changeCombine = DateTime.Parse((DateMonit.ToString("dd/MM/yyyy") + " " + combineCombobox));

                    if (changeCombine <= DateTime.Now)
                    {
                        DateMonit = DateTime.Parse((DateTime.Now.AddDays(1).ToString("dd/MM/yyyy") + " " + combineCombobox));

                        DriveInfo[] yDrvs = DriveInfo.GetDrives();
                        foreach (var Drv in yDrvs)
                        {
                            if (Drv.IsReady)
                            {
                                if (!DiscNameAndPercent.TryGetValue("" + Drv.Name + "", out int actualValue))
                                {
                                    // We don't have this disc : )
                                }
                                else
                                {
                                    if ((((Convert.ToDecimal(Drv.AvailableFreeSpace) / 1024 / 1024 / 1024) / (Convert.ToDecimal(Drv.TotalSize) / 1024 / 1024 / 1024)) * 100) >= (Convert.ToDecimal(DiscNameAndPercent["" + Drv.Name + ""])))
                                    {
                                        //  MessageBox.Show("" + (Convert.ToDecimal(DiscNameAndPercent["" + Drv.Name + ""]) + ""));
                                    }//["" + Drv.Name.Substring(0, Drv.Name.Length - 1) + ""]
                                    else
                                    {
                                        try
                                        {
                                            Microsoft.Win32.RegistryKey key;
                                            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("MD_DISC_ALERT_DATE");

                                            MessageBox.Show("wysyłamy wiadomość na temat dysku: " + Drv.Name + "");
                                            int        port       = Int32.Parse(key.GetValue("Port").ToString());
                                            SmtpClient mailServer = new SmtpClient(key.GetValue("SMTP").ToString(), port);
                                            mailServer.EnableSsl = true;

                                            mailServer.Credentials = new System.Net.NetworkCredential(key.GetValue("Name").ToString(), key.GetValue("Password").ToString());

                                            MailMessage msg = new MailMessage();
                                            msg.From = new MailAddress(key.GetValue("Name").ToString(), key.GetValue("Signature").ToString());

                                            EmailConf stringListEmail = new EmailConf();
                                            string    emaile          = stringListEmail.ToString();


                                            foreach (string email in EmailConf.ListEmail)
                                            {
                                                msg.To.Add(email);
                                            }


                                            msg.Subject = "Ticket - Warning Server - low capacity";
                                            msg.Body    = "Welcome, there is not enough disk space: " + Drv.Name + " ";

                                            mailServer.Send(msg);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (DateMonit <= DateTime.Now)
                    {
                        DateMonit = DateTime.Now.AddMinutes(Convert.ToDouble(numericUpDown2.Value));


                        DriveInfo[] yDrvs = DriveInfo.GetDrives();
                        foreach (var Drv in yDrvs)
                        {
                            if (Drv.IsReady)
                            {
                                if (!DiscNameAndPercent.TryGetValue("" + Drv.Name + "", out int actualValue))
                                {
                                    // We don't have this disc : )
                                }
                                else
                                {
                                    if ((((Convert.ToDecimal(Drv.AvailableFreeSpace) / 1024 / 1024 / 1024) / (Convert.ToDecimal(Drv.TotalSize) / 1024 / 1024 / 1024)) * 100) >= (Convert.ToDecimal(DiscNameAndPercent["" + Drv.Name + ""])))
                                    {
                                        //  MessageBox.Show("" + (Convert.ToDecimal(DiscNameAndPercent["" + Drv.Name + ""]) + ""));
                                    }//["" + Drv.Name.Substring(0, Drv.Name.Length - 1) + ""]
                                    else
                                    {
                                        try
                                        {
                                            Microsoft.Win32.RegistryKey key;
                                            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("MD_DISC_ALERT_DATE");

                                            MessageBox.Show("wysyłamy wiadomość na temat dysku: " + Drv.Name + "");
                                            int        port       = Int32.Parse(key.GetValue("Port").ToString());
                                            SmtpClient mailServer = new SmtpClient(key.GetValue("SMTP").ToString(), port);
                                            mailServer.EnableSsl = true;

                                            mailServer.Credentials = new System.Net.NetworkCredential(key.GetValue("Name").ToString(), key.GetValue("Password").ToString());

                                            MailMessage msg = new MailMessage();
                                            msg.From = new MailAddress(key.GetValue("Name").ToString(), key.GetValue("Signature").ToString());

                                            EmailConf stringListEmail = new EmailConf();
                                            string    emaile          = stringListEmail.ToString();


                                            foreach (string email in EmailConf.ListEmail)
                                            {
                                                msg.To.Add(email);
                                            }


                                            msg.Subject = "Ticket - Warning Server - low capacity";
                                            msg.Body    = "Welcome, there is not enough disk space: " + Drv.Name + " ";

                                            mailServer.Send(msg);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }