private void BtnSubmit_Click(object sender, RoutedEventArgs e) { if (TbEmail.Text.Length == 0) { Errormessage.Text = "Enter an email."; TbEmail.Focus(); } else if (!Regex.IsMatch(TbEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { Errormessage.Text = "Enter a valid email."; TbEmail.Select(0, TbEmail.Text.Length); TbEmail.Focus(); } else { string email = TbEmail.Text; string password = Passb.Password; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["InternetShop.Properties.Settings.DbCarConnectionString"].ConnectionString); con.Open(); SqlCommand cmd = new SqlCommand("Select * from Users where email='" + email + "' and password='******'", con); cmd.CommandType = CommandType.Text; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = cmd; DataSet dataSet = new DataSet(); adapter.Fill(dataSet); if (dataSet.Tables[0].Rows.Count > 0) { string username = dataSet.Tables[0].Rows[0]["name"].ToString() + " " + dataSet.Tables[0].Rows[0]["surname"].ToString(); // FACTORY METHOD and Proxy //for proxy // create some features for some users var features = new FeaturesOperator(); // Pattern MEMENTO // save state that user is authorizate originator.State = email; caretaker.Memento = originator.CreateMemento(); var t = new ShowProductsWindow(caretaker, features); // Session for concrete creator ( for email and login); t.Show(); // t.FactoryMethod(); //welcome.TextBlockName.Text = username;//Sending value from one form to another form. Close(); } else { Errormessage.Text = "Sorry! Please enter existing emailid/password."; } con.Close(); } }
public ShowProductsWindow(Caretaker caretaker = null, FeaturesOperator features = null) { InitializeComponent(); _caretaker = caretaker; _features = features; if (features != null) { TvCategory.ItemsSource = Request(); } else { TvCategory.ItemsSource = CategoryCreator.GetCreatorList(); } if (_caretaker.Memento.State != null && _caretaker.Memento.State != "") { BtnSignIn.Content = _caretaker.Memento.State; } }