コード例 #1
0
        public void AddExam(mst_exam mst)
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    mst_sessionMain session = new mst_sessionMain();

                    string query = @"INSERT INTO `mst_exam`
                                (session,
                                `exam_id`,
                                `exam_name`,
                                `max_no`,
                                `convert_to`)
                                VALUES
                                (@session,
                                @exam_id,
                                @exam_name,
                                @max_no,
                                @convert_to)";

                    string maxid = @"SELECT 
                                        IFNULL(MAX(exam_id), 0) + 1
                                    FROM
                                        mst_exam
                                    WHERE
                                        session = (SELECT
                                                session
                                            FROM
                                                mst_session
                                            WHERE
                                                session_finalize = 'Y')";



                    int id = con.ExecuteScalar <int>(maxid);

                    mst.session   = session.findFinal_Session();
                    mst.exam_id   = id;
                    mst.exam_name = mst.exam_name.Trim();

                    con.Execute(query, new
                    {
                        mst.session,
                        mst.exam_id,
                        mst.exam_name,
                        mst.max_no,
                        mst.convert_to
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public void EditExam(mst_exam mst)
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    mst_sessionMain session = new mst_sessionMain();

                    string query = "UPDATE mst_exam SET exam_name = @exam_name,max_no = @max_no,convert_to = @convert_to WHERE exam_id = @exam_id and session = @session ";

                    mst.session = session.findFinal_Session();

                    con.Execute(query, mst);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }