예제 #1
0
 private void viewCourseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Fundamental.Course_View frm = new Fundamental.Course_View();
     frm.MdiParent = this;
     frm.Show();
 }
예제 #2
0
        private void Edit_Course_Btn_Click(object sender, EventArgs e)
        {
            /*
             * if (clsCash.IsPermissionId("P01") == false)
             * {
             *  MessageBox.Show("คุณไม่มีสิทธิ์เพิ่มผู้ใช้ใหม่ กรุณาติดต่อผู้ดูแลระบบ...");
             *  return;
             * }
             * */

            if (txt_CourseName.Text.Trim() == "")
            {
                MessageBox.Show("Please enter Course name", "Pilot Training Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txt_CourseName.Focus();
                return;
            }

            if (txt_CourseDescription.Text.Trim() == "")
            {
                MessageBox.Show("Please enter Course Description", "Pilot Training Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txt_CourseDescription.Focus();
                return;
            }


            if (MessageBox.Show("Are you sure to create new course" + txt_CourseName.Text.Trim() + " yes/no?", "Pilot Training Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                Tr = Conn.BeginTransaction();
                try
                {
                    string sql;
                    Sbd = new StringBuilder();
                    Sbd.Remove(0, Sbd.Length);
                    Sbd.Append("UPDATE Course_Head ");
                    Sbd.Append("SET Course_Name = @Course_Name,");
                    Sbd.Append("Course_Description = @Course_Description,");
                    Sbd.Append("Course_Modified_By = @Course_Modified_By,");
                    Sbd.Append("Course_Modified_Date = @Course_Modified_Date,");
                    Sbd.Append("Course_Amend = @Course_Amend ");
                    Sbd.Append("WHERE Course_Head_ID = @Course_Head_ID ");

                    Sbd.Append("DELETE Course_Details WHERE Course_Head_ID = @Course_Head_ID");
                    string sqlAdd;
                    sqlAdd = Sbd.ToString();
                    Cmd    = new SqlCommand();
                    //com.Parameters.Clear();
                    Cmd.CommandText = sqlAdd;
                    Cmd.CommandType = CommandType.Text;
                    Cmd.Connection  = Conn;
                    Cmd.Transaction = Tr;

                    Cmd.Parameters.Add("@Course_Head_ID", SqlDbType.NChar).Value          = txtCourseId.Text.Trim();
                    Cmd.Parameters.Add("@Course_Name", SqlDbType.NChar).Value             = txt_CourseName.Text.Trim();
                    Cmd.Parameters.Add("@Course_Description", SqlDbType.NChar).Value      = txt_CourseDescription.Text.Trim();
                    Cmd.Parameters.Add("@Course_Create_By", SqlDbType.NChar).Value        = userId;
                    Cmd.Parameters.Add("@Course_Create_Date", SqlDbType.DateTime).Value   = DateTime.Now;
                    Cmd.Parameters.Add("@Course_Modified_By", SqlDbType.NChar).Value      = userId;
                    Cmd.Parameters.Add("@Course_Modified_Date", SqlDbType.DateTime).Value = DateTime.Now;
                    Cmd.Parameters.Add("@Course_Amend", SqlDbType.Int).Value = amend + 1;
                    Cmd.ExecuteNonQuery();

                    for (int i = 0; i <= dgv_SelectModules.Rows.Count - 1; i++)
                    {
                        Sbd.Remove(0, Sbd.Length);
                        Sbd.Append("INSERT INTO Course_Details ");
                        Sbd.Append("(Course_Head_ID, SubjectId ) ");
                        Sbd.Append("VALUES ");
                        Sbd.Append("(@Course_Head_ID, @SubjectId) ");

                        sql = Sbd.ToString();

                        Cmd.Parameters.Clear();
                        Cmd.CommandText = sql;
                        Cmd.Parameters.Add("@Course_Head_ID", SqlDbType.NVarChar).Value = txtCourseId.Text.Trim();
                        Cmd.Parameters.Add("@SubjectId", SqlDbType.NVarChar).Value      = dgv_SelectModules.Rows[i].Cells[2].Value.ToString();

                        Cmd.ExecuteNonQuery();
                    }
                    MessageBox.Show("Course updated successfully", "Pilot Training Message", MessageBoxButtons.OK, MessageBoxIcon.None);
                    Tr.Commit();
                    Fundamental.Course_View frm = new Course_View();
                    Close();
                    frm.MdiParent = this;
                    frm.Show();
                    //frm.ShowDialog();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to update course" + ex.Message, "Pilot Training Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    Tr.Rollback();
                }
            }
        }