Exemplo n.º 1
0
        private void FindLike(string execcomm) // Обновление вывода
        {
            MainWindow.studInfo.Clear();       // очищаем всё, если там что-то будет
            string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=phones;Integrated Security=True";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand();
                command.CommandText = execcomm;
                command.Connection  = connection;
                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        MainWindow.StudentInfo fileInfo = new MainWindow.StudentInfo();
                        fileInfo.Id              = Convert.ToInt32(reader.GetValue(0));
                        fileInfo.Name            = Convert.ToString(reader.GetValue(1));
                        fileInfo.Surname         = Convert.ToString(reader.GetValue(2));
                        fileInfo.Dadname         = Convert.ToString(reader.GetValue(3));
                        fileInfo.Group           = Convert.ToString(reader.GetValue(4));
                        fileInfo.Mphone          = Convert.ToInt32(reader.GetValue(5));
                        fileInfo.Hphone          = Convert.ToInt32(reader.GetValue(6));
                        fileInfo.Adress          = Convert.ToString(reader.GetValue(7));
                        FileInfoView.ItemsSource = MainWindow.studInfo;
                        MainWindow.studInfo.Add(fileInfo);
                    }
                }

                reader.Close();
            }
        }
Exemplo n.º 2
0
        private void AddUserBtn(object sender, RoutedEventArgs e)
        {
            try
            {
                string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=phones;Integrated Security=True";
                int    uniqueID         = 0;
                if (MainWindow.studInfo.Count > 0)
                {
                    uniqueID = MainWindow.studInfo[MainWindow.studInfo.Count - 1].Id + 1;
                }
                string name    = txname.Text;
                string surname = txsurname.Text;
                string dadname = txdadname.Text;
                string group   = groupBox.Text + "-" + txgroup.Text;
                //int mphone = Convert.ToInt32(txmob.Text);
                //int hphone = Convert.ToInt32(txhom.Text);
                string adress = txadress.Text;

                string sqlExpression = "INSERT INTO studTables (Id, Name, Surname, Dadname, [Group], Adress) VALUES (" + uniqueID + ", '" + name + "', '" + surname + "', '" + dadname + "', '" + group + "', '" + adress + "')";
                MessageBox.Show(sqlExpression);


                if (groupBox.Text != "")
                {
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        connection.Open();
                        SqlCommand command = new SqlCommand(sqlExpression, connection);
                        int        number  = command.ExecuteNonQuery();
                        MessageBox.Show("Добавлено объектов: " + Convert.ToString(number));
                        MainWindow.StudentInfo fileInfo = new MainWindow.StudentInfo();
                        fileInfo.Id      = uniqueID;
                        fileInfo.Name    = name;
                        fileInfo.Surname = surname;
                        fileInfo.Dadname = dadname;
                        fileInfo.Group   = group;
                        //fileInfo.Mphone = mphone;
                        //fileInfo.Hphone = hphone;
                        fileInfo.Adress = adress;
                        MainWindow.studInfo.Add(fileInfo);

                        Page3Numbers phonePage = new Page3Numbers {
                            frame = this.frame
                        };                              //Открываем добавление номерков
                        Page3Numbers.studId = uniqueID; // студентик
                        if (MainWindow.phoneInfo.Count > 0)
                        {
                            Page3Numbers.uniqueID = MainWindow.phoneInfo[MainWindow.phoneInfo.Count - 1].Id + 1;;  // мобилка
                        }
                        else
                        {
                            Page3Numbers.uniqueID = uniqueID;
                        }

                        frame.Content = phonePage; //открываем мобилку страничную добавку
                    }
                }
                else
                {
                    MessageBox.Show("Не выбрана специальность", "ОШИБКА");
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Неверный ввод", "ОШИБКА");
            }
        }