Beispiel #1
0
        //добавить студента
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            string sql = "INSERT INTO student " +
                         " (fam, im, ot, gr_id, sex) " +
                         " VALUES ('','','',@gr_id,1)";

            main.global_command = new SqlCommand(sql, main.global_connection);
            main.global_command.Parameters.Add("@gr_id", SqlDbType.Int).Value =
                grupa_set.Rows[grupa_list.SelectedIndex][0];
            main.global_command.ExecuteNonQuery();

            sql = "select @@identity";
            main.global_command = new SqlCommand(sql, main.global_connection);
            SqlDataReader id = main.global_command.ExecuteReader();

            id.Read();
            int st_id = Convert.ToInt32(id[0]);

            id.Close();

            student_edit se = new student_edit();

            se.grupa_id   = Convert.ToInt32(grupa_set.Rows[grupa_list.SelectedIndex][0]);
            se.fakult_str = fakult_prefix.Text;
            se.stud_id    = st_id;
            se.newstud    = true;

            int kurs = (int)grupa_set.Rows[grupa_list.SelectedIndex][2];

            DateTime dt = new DateTime(DateTime.Now.Year, 1, 1);

            se.born_date.Value = dt.AddYears(-(18 + kurs));

            DialogResult rs = se.ShowDialog();

            if (rs != DialogResult.OK)
            {
                fill_students();
                se.Dispose();
                return;
            }

            //fill_grupa();
            fill_students();
            se.Dispose();
        }
Beispiel #2
0
        //редактирование данных студента
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (student_grid.Rows.Count == 0)
            {
                return;
            }

            int row = student_grid.CurrentCell.RowIndex;

            if (row < 0)
            {
                return;
            }

            DataRow rr = student_set.Rows[row];

            student_edit se = new student_edit();

            se.stud_id  = Convert.ToInt32(rr[0]);
            se.grupa_id = Convert.ToInt32(grupa_set.Rows[grupa_list.SelectedIndex][0]);
            se.newstud  = false;

            se.fam.Text                = rr[1].ToString();
            se.im.Text                 = rr[2].ToString();
            se.ot.Text                 = rr[3].ToString();
            se.zach.Text               = rr[5].ToString();
            se.fakult_str              = fakult_prefix.Text;
            se.phone.Text              = rr[8].ToString();
            se.email.Text              = rr[9].ToString();
            se.work_place_box.Text     = rr["work_place"].ToString();
            se.graduated_from_box.Text = rr["graduated_from"].ToString();

            se.dateTimePicker1.MaxDate = main.starts[0];
            DateTime val = Convert.ToDateTime(rr["draddate"]);

            if (val >= main.starts[0])
            {
                val = val.AddMonths(-3);
            }
            se.dateTimePicker1.Value = val;

            if (se.zach.Text.Trim().Length == 0)
            {
                int    start = start_number.SelectedIndex + 1;
                string yeaR  = year.Text.Substring(2, 2);

                se.zach.Text = start.ToString() + "-" +
                               fakult_prefix.Text + "-" + kurs_list.Text + "-" + yeaR;
            }

            se.mother_box.Text = rr["mother_info"].ToString();
            se.father_box.Text = rr["father_info"].ToString();
            se.prikaz_box.Text = rr["prik"].ToString();

            se.status_id = Convert.ToInt32(rr["statid"]);

            if (Convert.ToInt32(rr["army"]) == 1)
            {
                se.radioButton4.Checked = true;
            }
            else
            {
                se.radioButton3.Checked = true;
            }

            if (Convert.ToInt32(rr["isdatepr"]) == -1)
            {
                int      gkurs = Convert.ToInt32(rr["gkurs"]);
                DateTime strt  = new DateTime(DateTime.Now.Year - gkurs, 9, 1, 12, 0, 0);
                DateTime endd  = strt.AddYears(5);

                se.enter_date_box.Value = strt;
                se.end_date_box.Value   = endd;
            }
            else
            {
                se.enter_date_box.Value = Convert.ToDateTime(rr["start_date"]);
                se.end_date_box.Value   = Convert.ToDateTime(rr["end_date"]);
            }

            bool sex = (bool)rr[10];

            if (sex)
            {
                se.male.Checked = true;
            }
            else
            {
                se.female.Checked = true;
            }

            int kurs = (int)grupa_set.Rows[grupa_list.SelectedIndex][2];

            DateTime dt = new DateTime(DateTime.Now.Year, 1, 1);
            DateTime db = Convert.ToDateTime(rr[11]);

            if (db.Date == main.server_date.Date)
            {
                se.born_date.Value = dt.AddYears(-(18 + kurs));
            }
            else
            {
                se.born_date.Value = db;
            }

            DialogResult rs = se.ShowDialog();

            fill_grupa();
            fill_students();
            //cmd.Dispose();
            se.Dispose();

            if (leave_rownum < student_grid.Rows.Count)
            {
                student_grid.Rows[leave_rownum].Cells[0].Selected = true;
            }
        }