예제 #1
0
        public ExtendedSearch(ManagerForm M_Form)
        {
            InitializeComponent();
            MForm = M_Form; //для передачи в другую форму

            string        way        = "Data Source=VICKY-PC\\SQLEXPRESS;Initial Catalog=TravelAgency;Integrated Security=True";
            string        query1     = "SELECT DISTINCT Country FROM Tour";
            string        query2     = "SELECT City FROM Tour";
            List <string> resultList = new List <string>();

            conn = new SqlConnection(way);
            conn.Open();

            SqlCommand command = new SqlCommand(query1, conn);

            dataReader = command.ExecuteReader();
            while (dataReader.Read())
            {
                resultList.Add(dataReader[0].ToString());
            }
            сomboBoxCountry.Items.AddRange(resultList.ToArray());
            resultList.Clear();
            dataReader.Close();

            command    = new SqlCommand(query2, conn);
            dataReader = command.ExecuteReader();
            while (dataReader.Read())
            {
                resultList.Add(dataReader[0].ToString());
            }
            comboBoxCity.Items.AddRange(resultList.ToArray());
            dataReader.Close();
            conn.Close();

            string[] typeOfAccommodation = { "Отель", "Апартаменты", "Апарт-Отель" };
            comboBoxAcType.Items.AddRange(typeOfAccommodation);
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string way       = "Data Source=VICKY-PC\\SQLEXPRESS;Initial Catalog=TravelAgency;Integrated Security=True";
            string tableName = null;

            if (UserComboBox.Text == "Руководитель" || UserComboBox.Text == "Менеджер")
            {
                tableName = "SELECT * FROM Staff";
            }
            else if (UserComboBox.Text == "Турист")
            {
                tableName = "SELECT * FROM TouristGroup";
            }
            else
            {
                MessageBox.Show("Неправильно выбран пользователь!");
                return;
            }

            SqlConnection conn = new SqlConnection(way);

            conn.Open();
            SqlCommand    askLogin = new SqlCommand(tableName, conn);
            SqlDataReader rdr      = askLogin.ExecuteReader();

            string password = null;

            while (rdr.Read())
            {
                if (UserComboBox.Text == rdr[1].ToString() && LastNameTextBox.Text == rdr[3].ToString())
                {
                    password = rdr[4].ToString(); //check User with this Lastname
                }
                else if (UserComboBox.Text == "Турист" && LastNameTextBox.Text == rdr[2].ToString())
                {
                    password = rdr[0].ToString(); //tourist password = num of group
                }
            }

            if (password == null)
            {
                MessageBox.Show("Данного пользователя не существует.");
                return;
            }
            else if (password != PasswordTextBox.Text)
            {
                MessageBox.Show("Неверный пароль!");
                return;
            }

            switch (UserComboBox.Text)
            {
            case "Руководитель":
            {
                this.Hide();
                HeadForm newHeadForm = new HeadForm();
                newHeadForm.Closed += (s, args) => this.Close();
                newHeadForm.Show();
                break;
            }

            case "Менеджер":
            {
                this.Hide();
                ManagerForm newManagerForm = new ManagerForm();
                newManagerForm.Closed += (s, args) => this.Close();
                newManagerForm.Show();
                break;
            }

            case "Турист":
            {
                TouristForm touristForm = new TouristForm(this);
                this.Hide();

                /*TouristFormMenu newTouristFormMenu = new TouristFormMenu(touristForm);
                 * newTouristFormMenu.Closed += (s, args) => this.Close();
                 * newTouristFormMenu.Show();*/
                touristForm.Closed += (s, args) => this.Close();
                touristForm.Show();
                break;
            }
            }
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
        }