void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.login_screen = ((WpfApp2.login)(target)); return; case 2: this.login_ID = ((System.Windows.Controls.Label)(target)); return; case 3: this.password = ((System.Windows.Controls.Label)(target)); return; case 4: this.login_input = ((System.Windows.Controls.TextBox)(target)); return; case 5: this.password_input = ((System.Windows.Controls.TextBox)(target)); return; } this._contentLoaded = true; }
//when user try to enter data it will first verify and then allow user to insert data into database private void Button_Click_1(object sender, RoutedEventArgs e) { if (username.Text.Length == 0) { errorusername.Text = "Enter username."; username.Focus(); } else if (password.Password.Length == 0) { errorpassword.Text = "Enter a password."; password.Focus(); } else //to validate email if (!Regex.IsMatch(email.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]$")) { erroremail.Text = "Enter a valid email."; email.Select(0, email.Text.Length); email.Focus(); } else if (username.Text.Length != 0 && password.Password.Length != 0 && email.Text.Length != 0) { dc = new DataClasses1DataContext(); login lg = new login(); lg.type = combobox.SelectedItem.ToString(); lg.username = username.Text; lg.password = password.Password; lg.email = email.Text; dc.logins.InsertOnSubmit(lg); dc.SubmitChanges(); MessageBox.Show("Data Saved Successfully!!"); // lg.Id = Convert.ToInt32(""); combobox.SelectedItem = ""; username.Text = ""; password.Password = ""; email.Text = ""; errorusername.Text = ""; errorpassword.Text = ""; erroremail.Text = ""; myadmingrid2.ItemsSource = dc.logins; } }
//this will populate data into user input so one can change data like update and delete private void myadmingrid_SelectedCellsChanged2(object sender, SelectedCellsChangedEventArgs e) { delete2.IsEnabled = true; update.IsEnabled = true; int row; DataClasses1DataContext dt = new DataClasses1DataContext(); login tb = new login(); tb = myadmingrid2.SelectedItem as login; if (tb == null) { // MessageBox.Show("Hii"); } else { row = Convert.ToInt32(tb.Id); // MessageBox.Show(row.ToString()); string row1 = Convert.ToString(tb.Id); var selectQuery = from rows in dt.logins where rows.Id == row select rows; foreach (var c in selectQuery) { combobox.Text = c.type; username.Text = c.username; password.Password = c.password; email.Text = c.email; } dt.SubmitChanges(); } }
void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) { switch (connectionId) { case 1: this.login_screen = ((WpfApp2.login)(target)); return; case 2: this.login_ID = ((System.Windows.Controls.Label)(target)); return; case 3: this.password = ((System.Windows.Controls.Label)(target)); return; case 4: this.textBox = ((System.Windows.Controls.TextBox)(target)); return; case 5: this.passwordBox = ((System.Windows.Controls.PasswordBox)(target)); return; case 6: this.bt_login = ((System.Windows.Controls.Button)(target)); #line 14 "..\..\login.xaml" this.bt_login.Click += new System.Windows.RoutedEventHandler(this.bt_login_Click); #line default #line hidden return; } this._contentLoaded = true; }
//to update data private void callupdate() { DataClasses1DataContext dt = new DataClasses1DataContext(); login tb = new login(); tb = myadmingrid2.SelectedItem as login; int row = Convert.ToInt32(tb.Id); var selectQuery = from rows in dt.logins where rows.Id == row select rows; foreach (var c in selectQuery) { c.type = combobox.Text; c.username = username.Text; c.password = password.Password; c.email = email.Text; myadmingrid2.ItemsSource = dt.logins; } // loadgrid(); dt.SubmitChanges(); MessageBox.Show("Updated Data Successfully!!"); }
private void calldelete() { int row; dc = new DataClasses1DataContext(); login lg = new login(); lg = myadmingrid2.SelectedItem as login; if (MessageBox.Show("Do you want to delete data?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (lg == null) { // MessageBox.Show("Hii"); } else { row = Convert.ToInt32(lg.Id); var selectQuery = from rows in dc.logins where rows.Id == row select rows; foreach (var c in selectQuery) { dc.logins.DeleteOnSubmit(c); dc.SubmitChanges(); } MessageBox.Show("Data Deleted Successfully!!"); delete2.IsEnabled = false; myadmingrid2.ItemsSource = dc.logins; } } else { // Do not close the window } //MessageBox.Show(row.ToString()); }
partial void Deletelogin(login instance);
partial void Updatelogin(login instance);
partial void Insertlogin(login instance);