コード例 #1
0
        private void btnSaveStudies_Click(object sender, EventArgs e)
        {
            starth    = cmb_startTimeStudiesH.Text;
            startm    = cmb_startTimeStudiesM.Text;
            starttime = starth + startm;
            endh      = cmb_EndTimeStudiesH.Text;
            endm      = cmb_EndTimeStudiesM.Text;
            endtime   = endh + endm;

            SqlConnection con = new SqlConnection();

            if (txt_levelStudies.Text == "" || txt_specialty.Text == "" || txt_specialty.Text == "")

            {
                if (MondayStudies.Checked == true || TuesdayStudies.Checked == true || wednesdayStudies.Checked == true || ThursdayStudies.Checked == true || fridayStudies.Checked == true || SaturdayStudies.Checked == true || SundayStudies.Checked == true)
                {
                    MessageBox.Show("Please fill all fields");
                    return;
                }
            }
            else
            {
                try
                {
                    con.ConnectionString = @"Data Source=DESKTOP-69MM1NJ\SQLEXPRESS;Initial Catalog=NadhamniDB;Integrated Security=True;Pooling=False";
                    con.Open();
                    SqlCommand cmd = new SqlCommand("insert into Studies(LevelOfStudies,Speciality,Establishment,DaysOfStud,StartTime,EndTime,UserName) values(@LevelOfStudies,@Speciality,@Establishment,@DaysOfStud,@StartTime,@EndTime,@UserName)", con);
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@levelOfStudies", txt_levelStudies.Text);
                    cmd.Parameters.AddWithValue("@Speciality", txt_specialty.Text);
                    cmd.Parameters.AddWithValue("@Establishment", txt_establishment.Text);
                    cmd.Parameters.AddWithValue("@DaysOfStud", days);
                    cmd.Parameters.AddWithValue("@StartTime", starttime);
                    cmd.Parameters.AddWithValue("@EndTime", endtime);
                    cmd.Parameters.AddWithValue("@UserName", Home.FK);

                    //Execute Command
                    cmd.ExecuteNonQuery();
                    //MessageBox.Show("success");

                    SuccessJob stud1 = new SuccessJob();
                    stud1.Show();

                    /*Dashboard d = new Dashboard();
                     * d.Show();
                     * this.Hide();*/
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }
            }
        }