示例#1
0
        public void EditParameter(mst_subject_parameters mst)
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    string query = @"UPDATE mst_subject_parameters 
                                    SET 
                                        subject_id = @subject_id,
                                        parameter_id = @parameter_id,
                                        parameter_name = @parameter_name
                                    WHERE
                                        parameter_id = @parameter_id
                                            AND session = (SELECT 
                                                session
                                            FROM
                                                mst_session
                                            WHERE
                                                session_finalize = 'Y'
                                                    AND session_active = 'Y')";

                    con.Execute(query, mst);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public void AddParameters(mst_subject_parameters mst)
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    mst_sessionMain sess = new mst_sessionMain();

                    string session = sess.findActive_Session();

                    string duplicate = @"SELECT 
                                            COUNT(*)
                                        FROM
                                            mst_subject_parameters
                                        WHERE
                                            subject_id = @subject_id
                                                AND parameter_name = @parameter_name
                                                AND session = (SELECT 
                                                    session
                                                FROM
                                                    mst_session
                                                WHERE
                                                    session_active = 'Y')";

                    int dup = con.ExecuteScalar <int>(duplicate, new { mst.subject_id, mst.parameter_name });

                    if (dup > 0)
                    {
                        throw new DuplicateWaitObjectException();
                    }
                    else
                    {
                        string query = @"INSERT INTO `mst_subject_parameters`
                                    (`session`,
                                    `parameter_id`,
                                    `subject_id`,
                                    `parameter_name`)
                                    VALUES
                                    (@session,
                                    @parameter_id,
                                    @subject_id,
                                    @parameter_name);";

                        string maxid = @"SELECT 
                                            IFNULL(MAX(parameter_id), 0) + 1
                                        FROM
                                            mst_subject_parameters
                                        WHERE
                                            session = @session";

                        //                var id = con.Query<mst_section>(maxid).ToString().Trim();

                        int id = con.ExecuteScalar <int>(maxid, new { session = session });



                        mst.parameter_id   = id;
                        mst.parameter_name = mst.parameter_name.Trim();

                        con.Execute(query, new
                        {
                            mst.parameter_id,
                            mst.parameter_name,
                            mst.subject_id,
                            session = session
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }