示例#1
0
            public static bool IsEmail(string email)
            {
                if (string.IsNullOrWhiteSpace(email))
                {
                    return(false);
                }

                return(EmailPattern.IsMatch(email));
            }
示例#2
0
    public static string SendEMailHR(string Detail, string EmployeeID, string Username)
    {
        EmailPattern SendEmail = new EmailPattern();

        string message = "Please contact IT!!";

        string        SrtConnString = WebConfigurationManager.ConnectionStrings["SageConnnetionString"].ConnectionString;
        SqlConnection db            = new SqlConnection(SrtConnString);

        try
        {
            db.Open();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(" SELECT Fname, ");
            sb.AppendLine(" Lname, ");
            sb.AppendLine(" Email, ");
            sb.AppendLine(" Department, ");
            sb.AppendLine(" Center, ");
            sb.AppendLine(" Position ");
            sb.AppendLine(" FROM CRM.dbo.vWSE_HR_EmployeeData as emp ");
            sb.AppendLine(" WHERE 1=1 ");
            sb.AppendLine(" and emp.PersonCode = '" + EmployeeID + "' ");

            SqlCommand sql   = new SqlCommand(sb.ToString(), db);
            DataTable  table = new DataTable();

            table.Load(sql.ExecuteReader());

            if (table.Rows.Count > 0)
            {
                StringBuilder BodyMessage = new StringBuilder();
                StreamReader  myFile      = new StreamReader(HttpContext.Current.Server.MapPath("../Template/htmlTemplate.html"));

                BodyMessage.Append(myFile.ReadToEnd());
                myFile.Close();

                string FName      = table.Rows[0]["Fname"].ToString();
                string Lname      = table.Rows[0]["Lname"].ToString();
                string Email      = table.Rows[0]["Email"].ToString();
                string Department = table.Rows[0]["Department"].ToString();
                string Center     = table.Rows[0]["Center"].ToString();
                string Position   = table.Rows[0]["Position"].ToString();

                BodyMessage.Replace("{EmpID}", EmployeeID);
                BodyMessage.Replace("{FName}", FName);
                BodyMessage.Replace("{LName}", Lname);
                BodyMessage.Replace("{Email}", Email);
                BodyMessage.Replace("{Department}", Department);
                BodyMessage.Replace("{Center}", Center);
                BodyMessage.Replace("{Position}", Position);
                BodyMessage.Replace("{Detail}", Detail);
                BodyMessage.Replace("{Sender}", FName);

                string mailto = ConfigurationManager.AppSettings["email"].ToString();
                string mailCC = ConfigurationManager.AppSettings["ccemail"].ToString();

                if (mailCC.Equals(""))
                {
                    mailCC += Email;
                }
                else
                {
                    mailCC += "," + Email;
                }

                sb = new StringBuilder();
                sb.AppendLine(" INSERT INTO HR_RequestInformation ");
                sb.AppendLine(" ( ");
                sb.AppendLine(" 	EmpID, ");
                sb.AppendLine(" 	Username, ");
                sb.AppendLine(" 	Message, ");
                sb.AppendLine(" 	CreatedDate ");
                sb.AppendLine(" ) ");
                sb.AppendLine(" VALUES ");
                sb.AppendLine(" ( ");
                sb.AppendLine(" 	@EmpID, ");
                sb.AppendLine(" 	@Username, ");
                sb.AppendLine(" 	@Message, ");
                sb.AppendLine(" 	GETDATE() ");
                sb.AppendLine(" ) ");

                sql = new SqlCommand(sb.ToString(), db);
                sql.Parameters.AddWithValue("EmpID", EmployeeID);
                sql.Parameters.AddWithValue("Username", Username);
                sql.Parameters.AddWithValue("Message", Detail);

                sql.ExecuteNonQuery();

                EmailPattern.SendMail("Request change employee infornmation", mailto, mailCC, BodyMessage.ToString());

                message = "success";
            }
        }
        catch (Exception ex)
        {
            message = ex.Message + "<br/>" + ex.StackTrace;
        }
        finally
        {
            db.Close();
        }

        return(message);
    }
        public void LaunchYoutubeAdSkipper()
        {
            #region OneTimeSetUp

            User user = PromptPswdProcessor();

            while (user == null)
            {
                Console.WriteLine("Try again. ");
                user = PromptPswdProcessor();
            }

            Console.WriteLine("\n\nThank you, execution continues ... \n\n");

            LaunchDriver();

            var refreshHandler = new ZRefreshMarkerHandler(this);

            #endregion

            #region Local Functions and Utilities

            Action <By> ClickAndWait = locator =>
            {
                refreshHandler.AddRefreshMarker();
                driver.BlurAllInputs();
                Clickable(locator).Click();
                refreshHandler.WaitUntilInvisibilityOfRefreshMarker();
            };

            Func <bool> InvalidFieldExists =
                () => driver.FindElements(By.CssSelector("[aria-live='assertive'][aria-atomic='true']")).FirstOrDefault(e => e.Displayed && !String.IsNullOrEmpty(e.Text)) != null;

            By          SkipAdLocator = By.CssSelector("button.videoAdUiSkipButton");
            Func <bool> AdExists      = () => driver.FindElements(SkipAdLocator).Any();

            #endregion

            #region Act

            driver.Navigate().GoToUrl("https://www.youtube.com/");
            wait.WithJs();
            Clickable(By.CssSelector("#buttons > ytd-button-renderer > a")).Click();
            wait.WithJs();

            Clickable(By.Id("identifierId")).SendKeys(user.UserName);
            ClickAndWait(By.Id("identifierNext"));

            while (InvalidFieldExists()) // check success status
            {
                Console.WriteLine("\n\nBad email :( ... ReEnter information in the form");

                do
                {
                    Console.WriteLine("\n\nBad email ... ReEnter information in the form");
                    user.UserName = ReEnterInformation();
                } while (user.UserName == null || EmailPattern.Match(user.UserName).Value == "");

                Clickable(By.Id("identifierId")).ClearAndSendKeys(user.UserName);
                ClickAndWait(By.Id("identifierNext"));
            }

            Clickable(By.CssSelector("#password input[type='password']")).SendKeys(user.PassWord);
            ClickAndWait(By.Id("passwordNext"));

            while (InvalidFieldExists()) // check success status
            {
                Console.WriteLine("\n\nBad Password :( ... ReEnter information in the form");
                do
                {
                    Console.WriteLine("\n\nBad Password ... ReEnter information in the form");
                    user.PassWord = ReEnterInformation(true);
                } while (user.PassWord == null);

                Clickable(By.CssSelector("#password input[type='password']")).ClearAndSendKeys(user.PassWord);
                ClickAndWait(By.Id("passwordNext"));
            }

            wait.Until(d => d.Url.Contains("https://www.youtube.com/"));
            //HandleAlert(driver);

            /*
             * using (PowerShell ps1 = PowerShell.Create())
             * {
             *  ps1.AddScript(System.IO.File.ReadAllText(@"PowerShellControl\ScheduleRadioShutdown.ps1"));
             *  ps1.BeginInvoke();
             * }
             */

            wait.WithJs();
            driver.FindElements(By.Id("guide-icon")).FirstOrDefault(e => e.Displayed && e.Enabled).Click();
            Clickable(By.CssSelector("a[title='Conversations']")).Click();
            Clickable(By.CssSelector("a#thumbnail.ytd-playlist-thumbnail")).Click();
            Clickable(By.CssSelector("button[aria-label='Shuffle playlist']")).Click();

            while (driver.WindowHandles.Count > 0)
            {
                if (AdExists())
                {
                    wait.Timeout = TimeSpan.FromSeconds(30);
                    Clickable(SkipAdLocator).Click();
                    wait.Timeout = TimeSpan.FromSeconds(15);
                }
                Thread.Sleep(TimeSpan.FromSeconds(3));
            }


            #endregion
        }