示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            Personal_create f = new Personal_create();

            f.ShowDialog();

            if (!f.access)
            {
                return;
            }

            surname    = f.surname;
            name       = f.name;
            patronymic = f.patronymic;
            telephone  = f.telephone;
            age        = f.age;
            sex        = f.sex;
            birthday   = f.birthday;

            SqlConnection cn = new SqlConnection();

            cn.ConnectionString = address;
            try
            {
                cn.Open();
            }
            catch
            {
                MessageBox.Show(@"Нет соединения с базой данных!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                string     strSql = String.Format(@"INSERT INTO Personal(Surname, Name, Patronymic, Telephone, Age, Sex, Birthday) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", surname, name, patronymic, telephone, age, sex, birthday);
                SqlCommand cmd    = new SqlCommand(strSql, cn);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("Непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string         str     = "SELECT Surname, Name, Patronymic, Telephone, Age, Sex, Birthday, Id_personal FROM Personal";
            SqlCommand     cm      = new SqlCommand(str, cn);
            SqlDataAdapter adapter = new SqlDataAdapter(cm);

            dataset.Reset();
            adapter.Fill(dataset);
            cn.Close();
            dataGridView1.Update();
            bind.DataSource          = dataset.Tables[0];
            dataGridView1.DataSource = bind;
        }
示例#2
0
        private void button2_Click(object sender, EventArgs e)
        {
            Personal_create f = new Personal_create();

            f.ShowDialog();

            if (!f.access)
            {
                return;
            }

            surname    = f.surname;
            name       = f.name;
            patronymic = f.patronymic;
            telephone  = f.telephone;
            age        = f.age;
            sex        = f.sex;
            birthday   = f.birthday;

            SqlConnection cn = new SqlConnection();

            cn.ConnectionString = address;
            try
            {
                cn.Open();
            }
            catch
            {
                MessageBox.Show(@"Нет соединения с базой данных!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                string strSql = String.Format(@"UPDATE Personal SET 
                Surname = '{0}', Name = '{1}', Patronymic = '{2}', Telephone = '{3}', Age = '{4}', Sex = '{5}', Birthday = '{6}' WHERE Id_personal = '{7}'", surname, name, patronymic,
                                              telephone, age, sex, birthday, Id_personal);
                SqlCommand cmd = new SqlCommand(strSql, cn);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("Непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            label1.Text = "Добро пожаловать, " + surname + " " + name + "!";
        }
示例#3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow == null)
            {
                return;
            }

            Personal_create f = new Personal_create();

            f.ShowDialog();
            if (!f.access)
            {
                return;
            }
            surname    = f.surname;
            name       = f.name;
            patronymic = f.patronymic;
            telephone  = f.telephone;
            age        = f.age;
            sex        = f.sex;
            birthday   = f.birthday;

            SqlConnection cn = new SqlConnection();

            cn.ConnectionString = address;
            try
            {
                cn.Open();
            }
            catch
            {
                MessageBox.Show(@"Нет соединения с базой данных!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                Id_personal = (int)dataGridView1.CurrentRow.Cells[7].Value;
                //UPDATE emails SET lname='Ivanov', fname='Ivan' WHERE id='1';
                string strSql = String.Format(@"UPDATE Personal SET 
                Surname = '{0}', Name = '{1}', Patronymic = '{2}', Telephone = '{3}', Age = '{4}', Sex = '{5}', Birthday = '{6}' WHERE Id_personal = '{7}'", surname, name, patronymic,
                                              telephone, age, sex, birthday, Id_personal);
                SqlCommand cmd = new SqlCommand(strSql, cn);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("Непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string         str     = "SELECT Surname, Name, Patronymic, Telephone, Age, Sex, Birthday, Id_personal FROM Personal";
            SqlCommand     cm      = new SqlCommand(str, cn);
            SqlDataAdapter adapter = new SqlDataAdapter(cm);

            dataset.Reset();
            adapter.Fill(dataset);
            cn.Close();
            dataGridView1.Update();
            bind.DataSource          = dataset.Tables[0];
            dataGridView1.DataSource = bind;
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            Personal_create f = new Personal_create();

            f.ShowDialog();

            if (!f.access)
            {
                return;
            }

            surname    = f.surname;
            name       = f.name;
            patronymic = f.patronymic;
            telephone  = f.telephone;
            age        = f.age;
            sex        = f.sex;
            birthday   = f.birthday;

            SqlConnection cn = new SqlConnection();

            cn.ConnectionString = address;
            try
            {
                cn.Open();
            }
            catch
            {
                MessageBox.Show(@"Нет соединения с базой данных!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                string     strSql = String.Format(@"INSERT INTO Personal(Surname, Name, Patronymic, Telephone, Age, Sex, Birthday) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')", surname, name, patronymic, telephone, age, sex, birthday);
                SqlCommand cmd    = new SqlCommand(strSql, cn);
                cmd.ExecuteNonQuery();
            }
            catch
            {
                MessageBox.Show("Непредвиденная ошибка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            button1.Visible = false;
            button2.Visible = true;
            button3.Visible = true;
            //label3.Visible = false;
            label1.Text = "Добро пожаловать, " + surname + " " + name + "!";
            label3.Text = "Измените Ваши персональные данные или перейдите к следующему шагу:";
            string         str     = "SELECT Surname, Name, Patronymic, Telephone, Age, Sex, Birthday, Id_personal FROM Personal";
            SqlCommand     cm      = new SqlCommand(str, cn);
            SqlDataAdapter adapter = new SqlDataAdapter(cm);

            dataset.Reset();
            adapter.Fill(dataset);
            cn.Close();
            bind.DataSource = dataset.Tables[0];
            int count = bind.Count;

            Id_personal = (int)dataset.Tables[0].Rows[count - 1].ItemArray[7];
        }