示例#1
0
        public void EditSection(mst_section mst)
        {
            try
            {
                using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
                {
                    string query = @"UPDATE mst_section 
                                    SET 
                                        section_id = @section_id,
                                        class_id = @class_id,
                                        section_name = @section_name
                                    WHERE
                                        section_id = @section_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 AddSection(mst_section 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_section
                                        WHERE
                                            class_id = @class_id
                                                AND section_name = @section_name
                                                AND session = (SELECT 
                                                    session
                                                FROM
                                                    mst_session
                                                WHERE
                                                    session_active = 'Y')";

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

                    if (dup > 0)
                    {
                        throw new DuplicateWaitObjectException();
                    }
                    else
                    {
                        string query = "INSERT INTO mst_section(section_id,class_id,section_name,session) VALUES (@section_id,@class_id,@section_name,@session)";

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

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

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

                        if (id == 1)
                        {
                            id = 100;
                        }

                        mst.section_id   = id;
                        mst.Section_name = mst.Section_name.Trim();

                        con.Execute(query, new
                        {
                            mst.section_id,
                            mst.class_id,
                            mst.Section_name,
                            session = session
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }