示例#1
0
        private void buttonEnter_Click(object sender, EventArgs e)
        {
            MySqlCommand cmd = new MySqlCommand("call login(@email, @password);", cn);

            MySqlParameter email = new MySqlParameter();

            email           = cmd.Parameters.Add("@email", MySqlDbType.VarChar);
            email.Direction = ParameterDirection.Input;
            email.Value     = textBoxEmail.Text;

            MySqlParameter pw = new MySqlParameter();

            pw           = cmd.Parameters.Add("@password", MySqlDbType.VarChar);
            pw.Direction = ParameterDirection.Input;
            pw.Value     = textBoxPassword.Text;


            Uid = -2;

            try
            {
                Uid = Convert.ToInt32(cmd.ExecuteScalar().ToString());
            }
            catch (Exception)
            {
                MessageBox.Show("Вы ввели некорректные данные", "Неправильно введен email или пароль", MessageBoxButtons.OK);
                Uid = -2;
                textBoxEmail.Clear();
                textBoxPassword.Clear();
            }

            if (Uid > 0)
            {
                string str = "SELECT isAdmin from Users where id = " + Uid;
                cmd = new MySqlCommand(str, cn);
                string isAdmin = cmd.ExecuteScalar().ToString();
                if (isAdmin == "1")
                {
                    Form adminPage = new AdminPage(Uid);
                    adminPage.Show();
                }
                else
                {
                    Form userPage = new Form1(Uid);
                    userPage.Show();
                }
            }

            textBoxEmail.Clear();
            textBoxPassword.Clear();
        }
示例#2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                MySqlCommand cmd = new MySqlCommand("call updateRoom(@id, @roomTypeId, @capacity);", cn);

                MySqlParameter id = new MySqlParameter();
                id           = cmd.Parameters.Add("@id", MySqlDbType.Int32);
                id.Direction = ParameterDirection.Input;
                id.Value     = rid;

                MySqlParameter roomTypeId = new MySqlParameter();
                roomTypeId           = cmd.Parameters.Add("@roomTypeId", MySqlDbType.Int32);
                roomTypeId.Direction = ParameterDirection.Input;
                roomTypeId.Value     = comboBoxType.SelectedIndex + 1;

                MySqlParameter capacity = new MySqlParameter();
                capacity           = cmd.Parameters.Add("@capacity", MySqlDbType.Int32);
                capacity.Direction = ParameterDirection.Input;
                capacity.Value     = Convert.ToInt32(textBoxCapacity.Text);

                try
                {
                    var result = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Данные не были обновлены" + ex, "Редактирование данных", MessageBoxButtons.OK);
                }
                Form admPage = new AdminPage(Uid);
                admPage.Show();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Данные введены неверно", "Редактирование данных", MessageBoxButtons.OK);
            }
        }
示例#3
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            string checkEmail    = textBoxEmail.Text;
            string checkPassword = textBoxPassword.Text;

            if ((checkEmail.IndexOf("@") != checkEmail.LastIndexOf("@")) ||
                (checkEmail.IndexOf("@") == 0))
            {
                MessageBox.Show("Ваш почтовый адрес имеет неверный формат.", "Ошибка регистрации", MessageBoxButtons.OK);
                return;
            }
            if ((checkPassword.IndexOf(" ") >= 0) || (checkPassword == ""))
            {
                MessageBox.Show("Ваш пароль имеет неверный формат.", "Ошибка регистрации", MessageBoxButtons.OK);
                return;
            }
            if (!(checkEmail.EndsWith("@edu.spbstu.ru") || checkEmail.EndsWith("@ics2.ecd.spbstu.ru") || checkEmail.EndsWith("@dcn.icc.spbstu.ru")))
            {
                MessageBox.Show("Домен вашего почтового адреса не является доменом Университета. Для регистрации укашите почтовый адрес Университета.",
                                "Ошибка регистрации", MessageBoxButtons.OK);
                return;
            }

            MySqlCommand cmd = new MySqlCommand("call addUser(@email, @password, @fn, @ln, @fthn, @pnum, @isAdmin);", cn);

            MySqlParameter email = new MySqlParameter();

            email           = cmd.Parameters.Add("@email", MySqlDbType.VarChar);
            email.Direction = ParameterDirection.Input;
            email.Value     = textBoxEmail.Text;

            MySqlParameter passw = new MySqlParameter();

            passw           = cmd.Parameters.Add("@password", MySqlDbType.VarChar);
            passw.Direction = ParameterDirection.Input;
            passw.Value     = textBoxPassword.Text;

            MySqlParameter firstN = new MySqlParameter();

            firstN           = cmd.Parameters.Add("@fn", MySqlDbType.VarChar);
            firstN.Direction = ParameterDirection.Input;
            firstN.Value     = textBoxName.Text;

            MySqlParameter ln = new MySqlParameter();

            ln           = cmd.Parameters.Add("@ln", MySqlDbType.VarChar);
            ln.Direction = ParameterDirection.Input;
            ln.Value     = textBoxLastName.Text;

            MySqlParameter fatN = new MySqlParameter();

            fatN           = cmd.Parameters.Add("@fthn", MySqlDbType.VarChar);
            fatN.Direction = ParameterDirection.Input;
            fatN.Value     = textBoxFatherName.Text;

            MySqlParameter pN = new MySqlParameter();

            pN           = cmd.Parameters.Add("@pnum", MySqlDbType.VarChar);
            pN.Direction = ParameterDirection.Input;
            pN.Value     = textBoxCallNum.Text;

            int isAdmin = 0;

            if (checkBox2.Checked)
            {
                isAdmin = 1;
            }

            MySqlParameter isAdm = new MySqlParameter();

            isAdm           = cmd.Parameters.Add("@isAdmin", MySqlDbType.VarChar);
            isAdm.Direction = ParameterDirection.Input;
            isAdm.Value     = isAdmin;

            try
            {
                var result = cmd.ExecuteReader();
                while (result.Read())
                {
                    if (Convert.ToInt32(result["id_"].ToString()) == 0)
                    {
                        MessageBox.Show("Пользователь с данным почтовым адресом уже существует", "Ошибка в данных", MessageBoxButtons.OK);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Проверьте правильность введенных данных" + ex, "Ошибка в данных", MessageBoxButtons.OK);
            }

            AdminPage admPage = new AdminPage(Uid);

            admPage.tabControl1.SelectedIndex = 1;
            admPage.Show();
            this.Close();
        }
示例#4
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (TimeSpan.Parse(textBoxTimeStart.Text) >= TimeSpan.Parse(textBoxTimeEnd.Text))
                {
                    MessageBox.Show("Время начала не может быть позже времени окончания.",
                                    "Ошибка в данных.", MessageBoxButtons.OK);
                    return;
                }
                MySqlCommand cmd = new MySqlCommand("call updateBook1(@id, @roomId, @date, @stTime, @endTime, @purpose);", cn);

                MySqlParameter id = new MySqlParameter();
                id           = cmd.Parameters.Add("@id", MySqlDbType.Int32);
                id.Direction = ParameterDirection.Input;
                id.Value     = Bid;

                MySqlParameter roomId = new MySqlParameter();
                roomId           = cmd.Parameters.Add("@roomId", MySqlDbType.Int32);
                roomId.Direction = ParameterDirection.Input;
                roomId.Value     = Convert.ToInt32(textBoxRoom.Text);

                MySqlParameter date = new MySqlParameter();
                date           = cmd.Parameters.Add("@date", MySqlDbType.Date);
                date.Direction = ParameterDirection.Input;
                date.Value     = dateTimePicker1.Value;

                MySqlParameter stTime = new MySqlParameter();
                stTime           = cmd.Parameters.Add("@stTime", MySqlDbType.Time);
                stTime.Direction = ParameterDirection.Input;
                if (textBoxTimeEnd.Text.IndexOf(":") != textBoxTimeEnd.Text.LastIndexOf(":"))
                {
                    stTime.Value = TimeSpan.Parse(textBoxTimeStart.Text);
                }
                else
                {
                    stTime.Value = TimeSpan.Parse(textBoxTimeStart.Text + ":00");
                }

                MySqlParameter endTime = new MySqlParameter();
                endTime           = cmd.Parameters.Add("@endTime", MySqlDbType.Time);
                endTime.Direction = ParameterDirection.Input;
                if (textBoxTimeEnd.Text.IndexOf(":") != textBoxTimeEnd.Text.LastIndexOf(":"))
                {
                    endTime.Value = TimeSpan.Parse(textBoxTimeEnd.Text);
                }
                else
                {
                    endTime.Value = TimeSpan.Parse(textBoxTimeEnd.Text + ":00");
                }

                MySqlParameter purpose = new MySqlParameter();
                purpose           = cmd.Parameters.Add("@purpose", MySqlDbType.VarChar);
                purpose.Direction = ParameterDirection.Input;
                purpose.Value     = richTextBoxPurpose.Text;

                try
                {
                    var result = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка в формате введенных данных" + ex, "Ошибка в данных.", MessageBoxButtons.OK);
                    return;
                }

                Form adminPage = new AdminPage(Uid);
                adminPage.Show();
                this.Close();
            }
            catch (FormatException)
            {
                MessageBox.Show("Формат данных нарушен", "Ошибка в данных", MessageBoxButtons.OK);
            }
        }
示例#5
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                MySqlCommand cmd = new MySqlCommand("call addRoom(@id, @roomTypeId, @capacity, @isTechEquip, @techEquip);", cn);

                MySqlParameter id = new MySqlParameter();
                id           = cmd.Parameters.Add("@id", MySqlDbType.VarChar);
                id.Direction = ParameterDirection.Input;
                id.Value     = textBoxId.Text;

                int id_ = Convert.ToInt32(textBoxId.Text);

                int roomTypeId_ = 0;

                if (comboBoxType.SelectedItem.ToString() == "Лекционная")
                {
                    roomTypeId_ = 1;
                }
                else if (comboBoxType.SelectedItem.ToString() == "Учебная")
                {
                    roomTypeId_ = 2;
                }
                else
                {
                    roomTypeId_ = 3;
                }

                MySqlParameter roomTypeId = new MySqlParameter();
                roomTypeId           = cmd.Parameters.Add("@roomTypeId", MySqlDbType.VarChar);
                roomTypeId.Direction = ParameterDirection.Input;
                roomTypeId.Value     = roomTypeId_;

                MySqlParameter capacity = new MySqlParameter();
                capacity           = cmd.Parameters.Add("@capacity", MySqlDbType.VarChar);
                capacity.Direction = ParameterDirection.Input;
                capacity.Value     = Convert.ToInt32(textBoxCapacity.Text);

                int isTechEquip_ = 0;

                if (checkedListBoxBooking.CheckedItems.Count > 0)
                {
                    isTechEquip_ = 1;
                }

                MySqlParameter isTechEquip = new MySqlParameter();
                isTechEquip           = cmd.Parameters.Add("@isTechEquip", MySqlDbType.VarChar);
                isTechEquip.Direction = ParameterDirection.Input;
                isTechEquip.Value     = isTechEquip_;

                MySqlParameter techEquip = new MySqlParameter();
                techEquip           = cmd.Parameters.Add("@techEquip", MySqlDbType.VarChar);
                techEquip.Direction = ParameterDirection.Input;
                techEquip.Value     = "";

                try
                {
                    var result = cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Ошибка в данных" + ex, "Ошибка в данных", MessageBoxButtons.OK);
                }


                if (checkedListBoxBooking.CheckedItems.Count > 0)
                {
                    for (int i = 0; i < checkedListBoxBooking.CheckedItems.Count; i++)
                    {
                        if (checkedListBoxBooking.CheckedItems[i].ToString() == equipment[0])
                        {
                            MySqlCommand cmd1 = new MySqlCommand("call addEquipRoom(@idEqup, @idRoom);", cn);

                            MySqlParameter id1 = new MySqlParameter();
                            id1           = cmd1.Parameters.Add("@idRoom", MySqlDbType.Int32);
                            id1.Direction = ParameterDirection.Input;
                            id1.Value     = id_;

                            MySqlParameter idEq = new MySqlParameter();
                            idEq           = cmd1.Parameters.Add("@idEqup", MySqlDbType.Int32);
                            idEq.Direction = ParameterDirection.Input;
                            idEq.Value     = 1;

                            cmd1.ExecuteNonQuery();
                        }
                        else if (checkedListBoxBooking.CheckedItems[i].ToString() == equipment[1])
                        {
                            MySqlCommand cmd2 = new MySqlCommand("call addEquipRoom(@idEqup, @idRoom);", cn);

                            MySqlParameter id1 = new MySqlParameter();
                            id1           = cmd2.Parameters.Add("@idRoom", MySqlDbType.Int32);
                            id1.Direction = ParameterDirection.Input;
                            id1.Value     = id_;

                            MySqlParameter idEq = new MySqlParameter();
                            idEq           = cmd2.Parameters.Add("@idEqup", MySqlDbType.Int32);
                            idEq.Direction = ParameterDirection.Input;
                            idEq.Value     = 2;

                            cmd2.ExecuteNonQuery();
                        }
                        else if (checkedListBoxBooking.CheckedItems[i].ToString() == equipment[2])
                        {
                            MySqlCommand cmd3 = new MySqlCommand("call addEquipRoom(@idEqup, @idRoom);", cn);

                            MySqlParameter id1 = new MySqlParameter();
                            id1           = cmd3.Parameters.Add("@idRoom", MySqlDbType.Int32);
                            id1.Direction = ParameterDirection.Input;
                            id1.Value     = id_;

                            MySqlParameter idEq = new MySqlParameter();
                            idEq           = cmd3.Parameters.Add("@idEqup", MySqlDbType.Int32);
                            idEq.Direction = ParameterDirection.Input;
                            idEq.Value     = 3;

                            cmd3.ExecuteNonQuery();
                        }
                        else if (checkedListBoxBooking.CheckedItems[i].ToString() == equipment[3])
                        {
                            MySqlCommand cmd4 = new MySqlCommand("call addEquipRoom(@idEqup, @idRoom);", cn);

                            MySqlParameter id1 = new MySqlParameter();
                            id1           = cmd4.Parameters.Add("@idRoom", MySqlDbType.Int32);
                            id1.Direction = ParameterDirection.Input;
                            id1.Value     = id_;

                            MySqlParameter idEq = new MySqlParameter();
                            idEq           = cmd4.Parameters.Add("@idEqup", MySqlDbType.Int32);
                            idEq.Direction = ParameterDirection.Input;
                            idEq.Value     = 4;

                            cmd4.ExecuteNonQuery();
                        }
                    }
                }
                this.Close();
                AdminPage admPage = new AdminPage(Uid);
                admPage.tabControl1.SelectedIndex = 2;
                admPage.Show();
                this.Close();
            }
            catch (Exception)
            {
                MessageBox.Show("Данные введены неверно или данная аудитория уже существует.", "Ошибка в данных", MessageBoxButtons.OK);
            }
        }