private void btnSendEmail_Click(object sender, RoutedEventArgs e)
        {
            string ppcHostname;
            string ppcAdminPw;
            int targetIdField;
            bool mustTargetSpecificUsername;
            string specificUsername;
            string smtpHostname;
            string senderAddress;
            bool inputIsValid = true;
            ServerCommandProxy serverProxy;

            txtblockOutput.Inlines.Clear();

            ppcHostname = txtboxPpcServer.Text;
            if (String.IsNullOrEmpty(ppcHostname))
            {
                txtblockOutput.Inlines.Add("You must enter the PaperCut server hostname.\r\n");
                inputIsValid = false;
            }

            ppcAdminPw = pwdboxPpcAdminPw.Password;
            if (String.IsNullOrEmpty(ppcAdminPw))
            {
                txtblockOutput.Inlines.Add("You must enter the PaperCut admin password.\r\n");
                inputIsValid = false;
            }

            smtpHostname = txtboxSmtpServer.Text;
            if (String.IsNullOrEmpty(smtpHostname))
            {
                txtblockOutput.Inlines.Add("You must enter the SMTP server hostname.\r\n");
                inputIsValid = false;
            }

            senderAddress = txtboxSenderAddress.Text;
            if (!IsValidEmail(senderAddress))
            {
                txtblockOutput.Inlines.Add("You must enter a valid sender address.\r\n");
                inputIsValid = false;
                return;
            }

            targetIdField = cmboxTargetIDField.SelectedIndex;
            mustTargetSpecificUsername = chckboxTargetSpecificUser.IsChecked.Value;
            specificUsername = txtboxTargetSpecificUser.Text;

            if (inputIsValid)
            {
                try
                {
                    serverProxy = new ServerCommandProxy(ppcHostname, 9191, ppcAdminPw);
                    if (PaperCutProxyWrapper.ConnectionEstablished(serverProxy))
                    {
                        PaperCutHelper ppcUtility = new PaperCutHelper(serverProxy);
                        txtblockOutput.Inlines.Add("Connection to PaperCut established.\r\n");

                        int totalUsers = serverProxy.GetTotalUsers();
                        Console.WriteLine(String.Format("Retrieved {0} users from PaperCut.", totalUsers));
                        Console.WriteLine("########################################\r\n");

                        if (mustTargetSpecificUsername)
                        {
                            ppcUtility.SendSingleEmail(targetIdField, specificUsername, smtpHostname, senderAddress);
                            Console.WriteLine(String.Format("Notification email sent to {0}.", specificUsername));
                            Console.WriteLine("\n########################################\r\n");
                        }
                        else
                        {
                            ppcUtility.SendMultipleEmails(targetIdField, smtpHostname, senderAddress);
                            Console.WriteLine(String.Format("Notification emails sent to {0} users.", totalUsers));
                            Console.WriteLine("\n########################################\r\n");
                        }
                    }
                }
                catch (Exception)
                {
                    txtblockOutput.Inlines.Add("Connection to PaperCut cannot be established,\r\n"
                                                + "or cannot send email.");
                }
            }
        }
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            string ppcHostname;
            string ppcAdminPw;
            int targetIdField;
            bool updateOnlyIfBlank;
            int numberOfChars;
            bool mustTargetSpecificUsername;
            string specificUsername;
            bool inputIsValid = true;
            ServerCommandProxy serverProxy;

            txtblockOutput.Inlines.Clear();

            ppcHostname = txtboxPpcServer.Text;
            if (String.IsNullOrEmpty(ppcHostname))
            {
                txtblockOutput.Inlines.Add("You must enter the PaperCut server hostname.\r\n");
                inputIsValid = false;
            }

            ppcAdminPw = pwdboxPpcAdminPw.Password;
            if (String.IsNullOrEmpty(ppcAdminPw))
            {
                txtblockOutput.Inlines.Add("You must enter the PaperCut admin password.\r\n");
                inputIsValid = false;
            }

            targetIdField = cmboxTargetIDField.SelectedIndex;
            updateOnlyIfBlank = chckboxUpdateIfBlank.IsChecked.Value;
            mustTargetSpecificUsername = chckboxTargetSpecificUser.IsChecked.Value;
            specificUsername = txtboxTargetSpecificUser.Text;

            try
            {
                numberOfChars = Int16.Parse(txtboxIDLength.Text.ToString());
                if (numberOfChars < 4 || numberOfChars > 10)
                {
                    txtblockOutput.Inlines.Add("You must enter a length between 4 and 10.\r\n");
                    inputIsValid = false;
                }
                else
                {
                    inputIsValid = true;
                }
            }
            catch (Exception)
            {
                txtblockOutput.Inlines.Add("You must enter a length between 4 and 10.\r\n");
                return;
            }

            if (inputIsValid)
            {
                try
                {
                    serverProxy = new ServerCommandProxy(ppcHostname, 9191, ppcAdminPw);
                    if (PaperCutProxyWrapper.ConnectionEstablished(serverProxy))
                    {
                        PaperCutHelper ppcUtility = new PaperCutHelper(serverProxy);
                        txtblockOutput.Inlines.Add("Connection to PaperCut established.\r\n");

                        int totalUsers = serverProxy.GetTotalUsers();
                        Console.WriteLine(String.Format("Retrieved {0} users from PaperCut.", totalUsers));
                        Console.WriteLine("########################################\r\n");

                        if (mustTargetSpecificUsername)
                        {
                            ppcUtility.UpdateSingleCardNumber(updateOnlyIfBlank, targetIdField, specificUsername, numberOfChars);
                        }
                        else
                        {
                            ppcUtility.UpdateAllCardNumbers(updateOnlyIfBlank, targetIdField, numberOfChars);
                        }
                    }
                }
                catch (Exception)
                {
                    txtblockOutput.Inlines.Add("Connection to PaperCut cannot be established.\r\n");
                }
            }
        }