private void Button_Click(object sender, RoutedEventArgs e) { //добавление данных о пользователе в БД, если все данные введены верно if (PasswordTB.Password == RepPasswordTB.Password) { DB dB = new DB(Properties.Settings.Default.CinemaDBConnectionString); object login = dB.ExecuteScalarQuery($"SELECT Логин FROM Пользователь WHERE Логин = '{LoginTB.Text}'"); if (login == null) { int rows = dB.ExecuteQuery($"INSERT INTO [Пользователь] Values(N'{LoginTB.Text}', N'{PasswordTB.Password}', N'{EmailTB.Text}', N'{PhoneTB.Text}', 0, 0, N'{LastNameTB.Text}', N'{FirstNameTB.Text}', N'{MiddleNameTB.Text}')"); if (rows == 1) { MessageBox.Show("Регистрация прошла успешно!"); LastNameTB.Clear(); FirstNameTB.Clear(); MiddleNameTB.Clear(); EmailTB.Clear(); PhoneTB.Clear(); LoginTB.Clear(); PasswordTB.Clear(); RepPasswordTB.Clear(); AddText(); } } else { MessageBox.Show("Такой логин уже существует!"); } } else { MessageBox.Show("Пароли не совпадают!"); } }
private void EmailTB_KeyDown(object sender, System.Windows.Input.KeyEventArgs e) { var tb = sender as TextBox; if (e.Key == Key.Enter) { tb.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); PhoneTB.SelectAll(); } }
public void ClearAllFieldsOnEditContactForm() { //Clearing Existing data from all mandatory fields FirstName.Clear(); LastName.Clear(); PreferredNameTB.Clear(); PhoneTB.Clear(); MobileTB.Clear(); EmailTB.Clear(); FaxTB.Clear(); EmailTB.Clear(); StreetTB.Clear(); CityTB.Clear(); PostcodeTB.Clear(); CountryTB.Clear(); }
private void Button_Click(object sender, RoutedEventArgs e) { if (FirstNameTB.Text != "" || EmailTB.Text != "" || PhoneTB.Text != "" || LoginTB.Text != "" || PasswordTB.Password != "" || RepPasswordTB.Password != "") { if (PasswordTB.Password == RepPasswordTB.Password) { using (SqlConnection connection = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=E:\OlineCinema\OlineCinema\CinemaDB.mdf;Integrated Security=True")) { try { connection.Open(); } catch { MessageBox.Show("Ошибка соединения с базой данных!"); return; } string query = $"INSERT INTO [Пользователь] Values('{LoginTB.Text}', '{PasswordTB.Password}', '{EmailTB.Text}', '{PhoneTB.Text}', 0, 0, '{LastNameTB.Text}', '{FirstNameTB.Text}', '{MiddleNameTB.Text}')"; SqlCommand command = new SqlCommand(query, connection); command.ExecuteNonQuery(); MessageBox.Show("Регистрация прошла успешно!"); LastNameTB.Clear(); FirstNameTB.Clear(); MiddleNameTB.Clear(); EmailTB.Clear(); PhoneTB.Clear(); LoginTB.Clear(); PasswordTB.Clear(); RepPasswordTB.Clear(); } } else { MessageBox.Show("Пароли не свопадают!"); } } else { MessageBox.Show("Есть незаполненные поля!"); } }
//private void textBox1_TextChanged(object sender, EventArgs e) //{ // if (!System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, "^[a-zA-Z]")) // { // MessageBox.Show("This textbox accepts only alphabetical characters"); // textBox1.Text.Remove(textBox1.Text.Length - 1); // } //} #region Testcase-2 Save Edit Contact with Invalid Data public void EditContactWithInvalidData(string NavTo) { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Customer"); //string navigateTo = NavTo; if (NavTo == "EditContact") { NavigateToEditContactForm(); } else { NavigateToEditBillingForm(); } ClearAllFieldsOnEditContactForm(); FirstName.SendKeys(ExcelLib.ReadData(2, "FirstName")); LastName.SendKeys(ExcelLib.ReadData(2, "LastName")); PhoneTB.SendKeys(ExcelLib.ReadData(2, "Phone")); EmailTB.SendKeys(ExcelLib.ReadData(2, "Email")); StreetTB.SendKeys(ExcelLib.ReadData(2, "Street")); CityTB.SendKeys(ExcelLib.ReadData(2, "City")); PostcodeTB.SendKeys(ExcelLib.ReadData(2, "Post")); CountryTB.SendKeys(ExcelLib.ReadData(2, "Country")); Driver.wait(2); SaveContactBtn.Click(); #region Validate FirstName Textfield with Invalid data try { //FirstName textfield with Invalid data IWebElement Fname = Driver.driver.FindElement(By.CssSelector ("#ContactEditForm > div > div:nth-child(8) > table > tbody > tr:nth-child(1) > td:nth-child(1) > div > span > span")); bool FstName_error_msg = Fname.Displayed; string msge = Fname.Text; string expected_err = ExcelLib.ReadData(2, "Invalid_err"); // Assert.AreEqual("The FirstName accepts only alphabetical characters", msge); if (FstName_error_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "FirstName: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, " FirstName: Error diplayed for Invalid data is not correct"); } } //if (!System.Text.RegularExpressions.Regex.IsMatch(FirstName.Text, "^[a-zA-Z]")) //{ // MessageBox.Show("This textbox accepts only alphabetical characters"); // textBox1.Text.Remove(textBox1.Text.Length - 1); //} } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "FirstName: Error message for Invalid data is missing"); } #endregion #region Validate LastName Textfield with Invalid Data try { //LastName textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/div[1]/table/tbody/tr[1]/td[2]/div/span/span")); bool LstName_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(3, "Invalid_err"); // Assert.AreEqual("The FirstName accepts only alphabetical characters", msge); if (LstName_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "LastName: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, " LastName: Error diplayed for Invalid data is not correct"); } } //if (!System.Text.RegularExpressions.Regex.IsMatch(FirstName.Text, "^[a-zA-Z]")) //{ // MessageBox.Show("This textbox accepts only alphabetical characters"); // textBox1.Text.Remove(textBox1.Text.Length - 1); //} } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "LastName: Error message for Invalid data is missing"); } #endregion #region Validate Phone Textfield with Invalid data try { //Phone textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/div[2]/table/tbody/tr[1]/td[1]/div/span/span")); bool Phone_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(4, "Invalid_err"); if (Phone_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Phone: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Phone: Error diplayed for Invalid data is not correct"); } } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Phone: Error message for Invalid data is missing"); } #endregion #region Validate Email textfield with Invalid data try { //Email textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/div[2]/table/tbody/tr[2]/td[1]/div/span/span")); bool Email_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(5, "Invalid_err"); if (Email_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Email: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Email: Error diplayed for Invalid data is not correct"); } } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Email: Error message for Invalid data is missing"); } #endregion #region Validate Street Textfield with Invalid data try { //Street textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/table/tbody/tr[1]/td[1]/div/span/span")); bool Street_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(6, "Invalid_err"); if (Street_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Street: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Street: Error diplayed for Invalid data is not correct"); } } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Street: Error message for Invalid data is missing"); } #endregion #region Validate City Textfield with Invalid data try { //City textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/table/tbody/tr[1]/td[2]/div/span/span")); bool City_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(7, "Invalid_err"); if (City_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "City: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "City: Error diplayed for Invalid data is not correct"); } } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "City: Error message for Invalid data is missing"); } #endregion #region Validate PostCode Textfield with Invalid data try { //PostCode textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/table/tbody/tr[2]/td[1]/div/span/span")); bool Pcode_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(8, "Invalid_err"); if (Pcode_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "PostCode: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "PostCode: Error diplayed for Invalid data is not correct"); } } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "PostCode: Error message for Invalid data is missing"); } #endregion #region Validate Country Textfield with Invalid data try { //Country textfield with Invalid data IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/table/tbody/tr[2]/td[2]/div/span/span")); bool Country_err_msg = j.Displayed; string msge = j.Text; string expected_err = ExcelLib.ReadData(9, "Invalid_err"); if (Country_err_msg == true) { if (msge == expected_err) { Console.WriteLine(" Error diplayed for Invalid data is correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Country: Error diplayed for Invalid data is correct"); } else { Console.WriteLine(" Error diplayed for Invalid data is not correct"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Country: Error diplayed for Invalid data is not correct"); } } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Country: Error message for Invalid data is missing"); } #endregion }
public void SaveEditContactwithValidData(string NavTo) { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Customer"); //string navigateTo = NavTo; if (NavTo == "EditContact") { NavigateToEditContactForm(); } else { NavigateToEditBillingForm(); } Driver.wait(2); ClearAllFieldsOnEditContactForm(); FirstName.SendKeys(ExcelLib.ReadData(10, "FirstName")); LastName.SendKeys(ExcelLib.ReadData(10, "LastName")); PhoneTB.SendKeys(ExcelLib.ReadData(10, "Phone")); EmailTB.SendKeys(ExcelLib.ReadData(10, "Email")); StreetTB.SendKeys(ExcelLib.ReadData(10, "Street")); CityTB.SendKeys(ExcelLib.ReadData(10, "City")); PostcodeTB.SendKeys(ExcelLib.ReadData(10, "Post")); CountryTB.SendKeys(ExcelLib.ReadData(10, "Country")); Driver.wait(2); try { // Check if User is able to save SaveContactBtn.Click(); Driver.driver.SwitchTo().ParentFrame(); Driver.wait(2); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Save button clicked succesfully"); } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Unable to save contact details"); } try { //Check is Edit client window closes and control switches back to Edit Client window IWebElement x = Driver.driver.FindElement(By.XPath("html/body/div[4]/h2")); string iframe_title = x.Text; Console.WriteLine(iframe_title); Assert.AreEqual("Customer", iframe_title); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Sucessully switched back to the Edit Client iframe with CUSTOMER title"); } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Switch back to Parent iframe(Edit Client) failed"); } try { //Check if Edit contact/ Edit Billing Contact textfield is disabled and loaded with contact details if (NavTo == "EditContact") { // for Edit Contact Textfield IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[2]/div/input")); bool Txtbox_status = j.Enabled; Console.WriteLine(Txtbox_status); Assert.AreEqual("False", Convert.ToString(Txtbox_status)); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Test Pass: Edit contact Textbox is disabled as it is populated by contact details"); } else { // for Edit Biling Contact Textfield IWebElement j = Driver.driver.FindElement(By.XPath("html/body/div[4]/form/div/div[4]/div/input")); bool Txtbox_status = j.Enabled; Console.WriteLine(Txtbox_status); Assert.AreEqual("False", Convert.ToString(Txtbox_status)); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Test Pass: EditBilling Contact Textbox is disabled as it is populated by contact details"); } } catch (Exception e) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Fail: Edit contact Textbox is still enabled and blank"); } }
public void Verify_Max_Lth_Phn_Fld(string NavTo) { ExcelLib.PopulateInCollection(Test.Base.ExcelPath, "Customer"); int Phn_no_lnght = 0; //string navigateTo = NavTo; if (NavTo == "EditContact") { NavigateToEditContactForm(); } else { NavigateToEditBillingForm(); } try { //IWebElement Title = Driver.driver.FindElement(By.Id("contactDetailWindow_wnd_title")); //bool StillOnCurrentFrame = true; //Console.WriteLine(Title.Text); //Thread.Sleep(1000); PhoneTB.Clear(); Driver.wait(3); PhoneTB.SendKeys(ExcelLib.ReadData(6, "Phone")); Driver.wait(3); string x = ExcelLib.ReadData(6, "Phone"); Phn_no_lnght = x.Length; Console.WriteLine("{0}", Phn_no_lnght); SaveContactBtn.Click(); if (Phn_no_lnght > 15 || Phn_no_lnght < 7) { bool Error_Displayed = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/div[2]/table/tbody/tr[1]/td[1]/div/span/span")).Displayed; string Actual_err_msge = Driver.driver.FindElement(By.XPath("html/body/div[1]/form/div/div[2]/table/tbody/tr[1]/td[1]/div/span/span")).Text; string Expctd_err_msge = ExcelLib.ReadData(8, "Phone"); if (Error_Displayed == true) { if (Actual_err_msge == Expctd_err_msge) { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Failed, Phone no. should be between 7-15 numeric characters"); Console.WriteLine("Phone no. should be between 7-15 numeric characters"); } else { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Failed, Incorrect Error message. It should be \"Phone no. should be between 7-15 numeric characters\""); Console.WriteLine("Phone no. should be between 7-15 numeric characters"); } } } else { Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Pass, "Phone textfield only accepts and save data between 7-15 numeric characters"); Console.WriteLine("Test Pass"); } } catch (Exception e) { if (NavTo == "EditContact") { Console.WriteLine("No error message displayed"); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Fail: User is able to save Phone no.with less than 7 or more than 15 numeric charaters. And No error message dispayed"); } else { string length = "No. of numeric characters used is " + Convert.ToString(Phn_no_lnght) + "."; Console.WriteLine("Phone no. Length is: {0}, No error message displayed", Phn_no_lnght); Test.Base.test.Log(RelevantCodes.ExtentReports.LogStatus.Fail, "Test Fail : Phone no. Length is, No error message displayed", length); } } }