Example #1
0
        /*******************************************************************************************/
        private async void Deactivate()
        {
            Class.Email emClass = new Class.Email();

            if (MessageBox.Show("Do you really want to deactivate this license?\nContact the developer for assistance if needed.", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
            {
                if (License != tbLicense.Text.Trim())
                {
                    MessageBox.Show("The License you entered is incorrect.", "Incorrect License Key", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    this.IsEnabled = true;
                }
                else if (License == tbLicense.Text.Trim())
                {
                    if (lClass.IsFirebaseConnected())
                    {
                        await emClass.SendMail(Globals.USE_EMAIL_GMAIL, Globals.EmailSenderUsername, Globals.EmailSenderPassword, Email, "Score Manager License Deactivated", Globals.MSG_DEACTIVATE);

                        if (emClass.IsSuccessSendMail)
                        {
                            await lClass.DeactivateFirebase(License);

                            lClass.Deactivate(License);

                            MessageBox.Show(String.Format("Your License: {0}, has been deactivated. \nYou will be redirected to login screen.", License), "Deactivate Success", MessageBoxButton.OK, MessageBoxImage.Information);
                            isDeactivate = true;
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("Cannot proceed. Please check Internet connection and try again.", "Try Again", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
            }
            else
            {
                this.IsEnabled = false;
            }
        }
Example #2
0
        private void SendEmailGroup()
        {
            Class.Email emClass = new Class.Email();
            emClass.LoadEmailSettings(out int UseMail, out string EmailAddr1, out string EmailPass1, out string EmailAddr2, out string EmailPass2, out string EmailFoot);

            string EmailAddr = "";
            string EmailPass = "";

            switch (UseMail)
            {
            case Globals.USE_EMAIL_GMAIL:
            {
                EmailAddr = EmailAddr1;
                EmailPass = EmailPass1;
                break;
            }

            case Globals.USE_EMAIL_MAPUA:
            {
                EmailAddr = EmailAddr2;
                EmailPass = EmailPass2;
                break;
            }

            default:
            {
                break;
            }
            }

            if (string.IsNullOrEmpty(EmailAddr) || string.IsNullOrWhiteSpace(EmailPass))
            {
                MessageBox.Show("Email Settings is not set. Please go to settings and update the email info.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                if (dgExams.SelectedIndex != -1 && dgTerms.SelectedIndex != -1 && _studTable != null)
                {
                    string confirmationmsg = "";
                    for (int i = 0; i < _studTable.Count; i++)
                    {
                        confirmationmsg += String.Format("{0} {1}\n", _studTable[i].ID, _studTable[i].NAME);
                    }
                    if (MessageBox.Show(String.Format("Email will be sent to {0} students. \n\n{1}\n\nYou can continue to work. Just don't close the application while the emails are sending. Do you want to proceed?", _studTable.Count, confirmationmsg), "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        string Result = "";
                        mWin.isWorking = true;
                        //progressBar.IsIndeterminate = true;

                        if (lScores.Count != 0)
                        {
                            //Declare a new BackgroundWorker
                            BackgroundWorker       worker      = new BackgroundWorker();
                            List <Models._Student> lErrorMails = new List <Models._Student>();
                            List <string>          lErrorInfo  = new List <string>();

                            worker.DoWork += async(o, ea) =>
                            {
                                string subject = String.Format("{0} {1} {2}", Globals.EmailSubject, _e.NAME, _t.TERM);
                                string scores  = "";

                                int           offset         = 0;
                                List <string> lStudentEmails = new List <string>();
                                bool          isSuccess      = false;

                                for (int x = 0; x < _studTable.Count; x++)
                                {
                                    scores = "";

                                    try
                                    {
                                        for (int i = 0; i < _subjTable.Count; i++)
                                        {
                                            scores += String.Format("{0} = {1}\n", _subjTable[i].CODE, lScores[i + offset].ToString());
                                        }
                                    }
                                    catch
                                    {
                                        lErrorMails.Add(_studTable[x]);
                                        lErrorInfo.Add("Score not set.");
                                    }

                                    offset += _subjTable.Count;

                                    string body = String.Format("{0} {1} \n\n{2}\n\n{3}\n\n{4}"
                                                                , _e.NAME
                                                                , _t.TERM
                                                                , _studTable[x].NAME + "\n" + _studTable[x].ID + "\n" + _studTable[x].PROGRAM
                                                                , scores
                                                                , EmailFoot
                                                                );

                                    await emClass.SendMail(UseMail, EmailAddr, EmailPass, _studTable[x].EMAIL, subject, body);

                                    isSuccess = emClass.IsSuccessSendMail;

                                    if (!isSuccess)
                                    {
                                        lErrorMails.Add(_studTable[x]);
                                        lErrorInfo.Add("Invalid Email.");
                                    }

                                    int percent = (int)(((double)(x + 1) / _studTable.Count) * 1000);
                                    //worker.ReportProgress(percent, String.Format("{0} / {1}", x+1, _studTable.Count));
                                }

                                if (lErrorMails.Count > 0)
                                {
                                    string ErrorFile = String.Format("{0}_{1}_{2}.txt", _e.NAME, _t.TERM, DateTime.Now.ToShortDateString() + DateTime.Now.ToLongTimeString());
                                    ErrorFile = ErrorFile.Replace("/", "");
                                    ErrorFile = ErrorFile.Replace(":", "");
                                    ErrorFile = ErrorFile.Replace(" ", "");
                                    Result    = "Errors Found:\n";
                                    for (int i = 0; i < lErrorMails.Count; i++)
                                    {
                                        Result += String.Format("{0}. [{1} {2}] {3} \n\n", i + 1, lErrorMails[i].ID, lErrorMails[i].NAME, lErrorInfo[i]);
                                    }
                                    log.WriteToFileErrors(ErrorFile, Result);
                                    Result += String.Format("Error saved at {0}{1}", Globals.PATH_EMAIL_ERRORS, ErrorFile);
                                }
                                else
                                {
                                    Result = "Emails successfuly sent! No Errors.";
                                }

                                MessageBox.Show(Result, "Email Result", MessageBoxButton.OK, MessageBoxImage.Information);
                                mWin.isWorking = false;
                            };

                            /*worker.WorkerReportsProgress = true;
                             *
                             * worker.ProgressChanged += (o, ea) =>
                             * {
                             *  progressBar.Value = ea.ProgressPercentage;
                             *  txtSendStatus.Text = (string)ea.UserState;
                             * };*/

                            worker.RunWorkerCompleted += (o, ea) =>
                            {
                                //txtSendStatus.Text = "";
                                //progressBar.Value = 0;
                                //this.IsEnabled = true;
                            };

                            //txtSendStatus.Text = "Sending...";
                            //this.IsEnabled = false;
                            worker.RunWorkerAsync();
                        }
                        else
                        {
                            MessageBox.Show("Scores for this exam are not yet set. Kindly go to Scores Page and update this student's scores and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select enter the student number, select the exam/class and term to be emailed and try again.", "Try Again", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }
Example #3
0
        private void SendEmail()
        {
            Class.Email emClass = new Class.Email();
            emClass.LoadEmailSettings(out int UseMail, out string EmailAddr1, out string EmailPass1, out string EmailAddr2, out string EmailPass2, out string EmailFoot);

            string EmailAddr = "";
            string EmailPass = "";

            switch (UseMail)
            {
            case Globals.USE_EMAIL_GMAIL:
            {
                EmailAddr = EmailAddr1;
                EmailPass = EmailPass1;
                break;
            }

            case Globals.USE_EMAIL_MAPUA:
            {
                EmailAddr = EmailAddr2;
                EmailPass = EmailPass2;
                break;
            }

            default:
            {
                break;
            }
            }

            if (string.IsNullOrEmpty(EmailAddr) || string.IsNullOrWhiteSpace(EmailPass))
            {
                MessageBox.Show("Email Settings is not set. Please go to settings and update the email info.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                if (dgExams.SelectedIndex != -1 && dgTerms.SelectedIndex != -1 && _st != null)
                {
                    if (MessageBox.Show(String.Format("Email will be sent to:\n{0}\n{1}\n\nDo you want to proceed?", _st.NAME, _st.EMAIL), "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        string Result = "";
                        if (lScores.Count != 0)
                        {
                            //Declare a new BackgroundWorker
                            BackgroundWorker worker = new BackgroundWorker();

                            worker.DoWork += async(o, ea) =>
                            {
                                string subject = String.Format("{0} {1} {2}", Globals.EmailSubject, _e.NAME, _t.TERM);
                                string scores  = "";

                                for (int i = 0; i < _subjTable.Count; i++)
                                {
                                    scores += String.Format("{0} = {1}\n", _subjTable[i].CODE, lScores[i].ToString());
                                }
                                string body = String.Format("{0} {1} \n\n{2}\n\n{3}\n\n{4}"
                                                            , _e.NAME
                                                            , _t.TERM
                                                            , _st.NAME + "\n" + _st.ID + "\n" + _st.PROGRAM
                                                            , scores
                                                            , EmailFoot
                                                            );

                                bool isSuccess = false;
                                await emClass.SendMail(UseMail, EmailAddr, EmailPass, _st.EMAIL, subject, body);

                                isSuccess = emClass.IsSuccessSendMail;

                                if (isSuccess)
                                {
                                    Result = "Email has been sent successfully!";
                                }
                                else
                                {
                                    Result = "Email has failed!";
                                }


                                MessageBox.Show(Result, "Email Status", MessageBoxButton.OK, MessageBoxImage.Information);
                            };

                            worker.RunWorkerCompleted += (o, ea) =>
                            {
                                txtSendStatus.Text = "";
                                this.IsEnabled     = true;
                            };

                            txtSendStatus.Text = "Sending...";
                            this.IsEnabled     = false;
                            worker.RunWorkerAsync();
                        }
                        else
                        {
                            MessageBox.Show("Scores for this exam are not yet set. Kindly go to Scores Page and update this student's scores and try again.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select enter the student number, select the exam/class and term to be emailed and try again.", "Try Again", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
            }
        }