private bool SiteLevelCustomAuthenticationMethod(string userName, string password, out int doctorId)
        {
            bool boolReturnValue = false;
            doctorId = 0;

            using (MyDataClassesDataContext myDb = new MyDataClassesDataContext())
            {
                var webLoginPass = from w in myDb.Users_Doctors
                                   where 1 == 1 &&
                                         w.UserName == userName &&
                                         w.Password == password &&
                                         w.IsActive == true
                                   select w;

                foreach (var d in webLoginPass)
                {
                    doctorId = Convert.ToInt32(d.DoctorId);
                }

                if (webLoginPass.Count() == 1)
                {
                    boolReturnValue = true;
                }
                else
                {
                    boolReturnValue = false;
                }
            }

            return boolReturnValue;
        }
        private void InsertIntoUnitRegister(string ipAddress, string serialNumber,
            string name, string emailAddress, string phoneNumber, out string errorMessage)
        {
            errorMessage = string.Empty;

            using (MyDataClassesDataContext myDb = new MyDataClassesDataContext())
            {
                UnitRegister n = new UnitRegister();
                n.IPAddress = ipAddress;
                n.SerialNumber = serialNumber;
                n.Name = name;
                n.EmailAddress = emailAddress;
                n.PhoneNumber = phoneNumber;

                try
                { 
                    myDb.UnitRegisters.InsertOnSubmit(n);
                    myDb.SubmitChanges();
                }
                catch (Exception ex)
                {
                    errorMessage = String.Format("Exception caught in SendEmail(): {0}",
                    ex.ToString());
                }
            }
        }
                private string LoadDocusignForm()
        {
             String docuSignUrl = string.Empty;

            using (MyDataClassesDataContext myDb = new MyDataClassesDataContext())
            {

                
                // query
                var docData = from d in myDb.Users_Doctors
                              where d.DoctorId == Convert.ToInt32(this.Session["DoctorId"])
                              select d;

                // return data
                foreach (var d in docData)
                {

                    docuSignUrl = string.Format("https://na2.docusign.net/Member/PowerFormSigning.aspx?PowerFormId={0}", docuSignPowerformId);
                    docuSignUrl += string.Format("&Doctor_UserName={0}", d.DoctorName); 
                    docuSignUrl += string.Format("&Doctor_Email={0}", d.EmailAddress);
                    docuSignUrl += string.Format("&PhysicianName={0}", d.DoctorName);
                    docuSignUrl += string.Format("&PhysicianNPI={0}", d.NPINumber);
                    docuSignUrl += string.Format("&PhysicianAddress1={0}", d.Address1);
                    docuSignUrl += string.Format("&PhysicianAddress2={0}", d.Address2);
                    docuSignUrl += string.Format("&PhysicianCity={0}", d.City);
                    docuSignUrl += string.Format("&PhysicianState={0}", d.State);
                    docuSignUrl += string.Format("&PhysicianZipCode={0}", d.ZipCode);
                    docuSignUrl += string.Format("&PhysicianPhone={0}", d.PhoneNumber);
                }

            }

            return docuSignUrl;
        }
        private void InsertLogFile(int loginId, string ipAddress, string type, string log)
        {
            using (MyDataClassesDataContext myDb = new MyDataClassesDataContext())
            {
                LogFile newLog = new LogFile();
                newLog.UserId = loginId;
                newLog.IPAddress = ipAddress;
                newLog.Type = type;
                newLog.Log = log;
                newLog.DateTime = DateTime.Now.AddHours(-4);

                myDb.LogFiles.InsertOnSubmit(newLog);
                myDb.SubmitChanges();
            }
        }
        protected void RemoveEmailAddress_Click(object sender, EventArgs e)
        {
            // remove email address
            // add to RemoveEmailAddress Database
            using (MyDataClassesDataContext myDb = new MyDataClassesDataContext())
            {
                EmailAddressOptOut optOut = new EmailAddressOptOut();
                optOut.EmailAddress = this.EmailAddressLabel.Text;

                myDb.EmailAddressOptOuts.InsertOnSubmit(optOut);
                myDb.SubmitChanges();
            }


            // on success, goto Thank You Page
            Response.Redirect("/EmailOptOutThankYou.aspx");
        }
        private string Return_DoctorsName()
        {
            int loginDoctorId = Convert.ToInt32(this.Session["DoctorId"]);

            using (MyDataClassesDataContext myDB = new MyDataClassesDataContext())
            {
                var name = (from d in myDB.Users_Doctors
                            where d.DoctorId == loginDoctorId
                            select d.DoctorName).First();

                if (name.ToString() != null)
                {
                    return name.ToString();
                }
                else
                {
                    return "";
                }
            }
        }
        private string Return_DoctorsEMailAddress()
        {
            int loginDoctorId = Convert.ToInt32(this.Session["DoctorId"]);

            using (MyDataClassesDataContext myDB = new MyDataClassesDataContext())
            {
                var emailAddress = (from d in myDB.Users_Doctors
                            where d.DoctorId == loginDoctorId
                            select d.EmailAddress).First();

                if (emailAddress.ToString() != null)
                {
                    return emailAddress.ToString();
                }
                else
                {
                    return "";
                }
            }
        }
        // send email
        private void SendEmail()
        {
            String mailFromDisplay = string.Empty;
            String mailFrom = string.Empty;
            String userName = string.Empty;
            String password = string.Empty;
            String smtp = string.Empty;
            int smtpPort = 0;
            bool enableSsl = false;

            using (MyDataClassesDataContext myDb = new MyDataClassesDataContext())
            {
                var emailInfo = from ei in myDb.EmailSettings
                                select ei;

                foreach (var data in emailInfo)
                {
                    mailFromDisplay = "Website - Contact Us";
                    mailFrom = data.EmailAddress;
                    userName = data.UserName;
                    password = data.Password;
                    smtp = data.SMTP;
                    smtpPort = Convert.ToInt32(data.SMTP_Port);
                    enableSsl = Convert.ToBoolean(data.EnableSSL);
                }
            }
 
            MailMessage mail = new MailMessage();
            SmtpClient smtpServer = new SmtpClient(smtp);
            mail.From = new MailAddress(mailFrom, mailFromDisplay);

            // authenticate
            smtpServer.Port = smtpPort;
            smtpServer.Credentials = new System.Net.NetworkCredential(userName, password);
            smtpServer.EnableSsl = enableSsl;

            // send to ....
            if (GlobalVar.DebugMode == false)
            { 
                mail.To.Add("*****@*****.**");
                mail.To.Add("*****@*****.**");
            }
            else
            {
                mail.To.Add("*****@*****.**");
            }

            // build email
            mail.Subject = this.EmailSubject();
            mail.IsBodyHtml = true;
            mail.Body = this.EmailMessage();

            try
            {
                smtpServer.Send(mail);
                this.SendButton.Text = "Email Sent";
                this.SendLabel.Text = "";
            }
            catch (Exception ex)
            {
                this.SendLabel.Text = String.Format("Exception caught in SendEmail(): {0}",
                    ex.ToString());
            }
        }