private void button_tab3_add_Click(object sender, RoutedEventArgs e) { if (dataGrid_tab.SelectedItems.Count > 0) { if (table == 0) { if (form_number == 0) { AdminWindow f = (AdminWindow)form; f.id1 = Convert.ToInt32((dataGrid_tab.Columns[0].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text); } c.Text = (dataGrid_tab.Columns[2].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text; this.DialogResult = true; } if (table == 1) { if (form_number == 0) { AdminWindow f = (AdminWindow)form; f.id2 = Convert.ToInt32((dataGrid_tab.Columns[0].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text); } if (form_number == 1) { StaffWindow f = (StaffWindow)form; f.id2 = Convert.ToInt32((dataGrid_tab.Columns[0].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text); } c.Text = (dataGrid_tab.Columns[2].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text; this.DialogResult = true; } if (table == 2) { c.Text = (dataGrid_tab.Columns[0].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text; this.DialogResult = true; } if (table == 3) { if (form_number == 1) { StaffWindow f = (StaffWindow)form; f.id_k1 = Convert.ToInt32((dataGrid_tab.Columns[0].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text); } c.Text = (dataGrid_tab.Columns[6].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text; this.DialogResult = true; } if (table == 4) { if (form_number == 1) { StaffWindow f = (StaffWindow)form; f.id_k2 = Convert.ToInt32((dataGrid_tab.Columns[0].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text); } c.Text = (dataGrid_tab.Columns[6].GetCellContent(dataGrid_tab.Items[dataGrid_tab.SelectedIndex]) as TextBlock).Text; this.DialogResult = true; } } }
private void button_Click(object sender, RoutedEventArgs e) { if (textBox1.Text == "127.0.0.1") { if (checkBox.IsChecked == true) { connection = "Data Source=localhost; Database=Teploseti; User Id=" + textBox1_Copy.Text + "; password="******"Data Source=localhost;Database=Teploseti; Trusted_Connection=True"; } } else { if (checkBox.IsChecked == true) { connection = "Data Source=" + textBox1.Text + ";Database=Teploseti; User Id=" + textBox1_Copy.Text + "; password="******"Data Source=" + textBox1.Text + ";Database=Teploseti; Trusted_Connection=True"; } } try { context = new DBase(connection); var acc = context.Аккаунты.Where(c => c.Логин == textBox.Text).ToList(); if (acc.Count == 0) { MessageBox.Show("Login dosn't exist!"); return; } else { if ((acc[0].Логин == textBox.Text) && (acc[0].Хэш_пароль == getMD5String(passwordBox.Password))) { Properties.Settings.Default.login_db = textBox.Text; Properties.Settings.Default.ip_db = textBox1.Text; if (checkBox.IsChecked == true) { Properties.Settings.Default.mode = true; } else { Properties.Settings.Default.mode = false; } Properties.Settings.Default.login = textBox1_Copy.Text; Properties.Settings.Default.password = passwordBox1.Password; Properties.Settings.Default.Save(); if (acc[0].Администратор) { AdminWindow form = new AdminWindow(context, acc[0]); this.Hide(); form.ShowDialog(); this.Close(); } else { StaffWindow form = new StaffWindow(context, acc[0]); this.Hide(); form.ShowDialog(); this.Close(); } } else { MessageBox.Show("Wrong password!"); return; } } } catch (Exception ex) { MessageBox.Show("Error! " + ex.Message); return; } }