2012-5-29

---------ֹľ
create or replace procedure sr_setscore_marking(mepid number) as
roomid_ number; epid_ number;userid_ number;ep_score number;passgrade_ number;
ispassed_ number default 0;blockid_ number;classid_ number;courseid_ number;
cursor epblocks is select id from exampaperblock where exampaperid = epid_;
begin
     -- һ ȡϢ
     select roomid,epid,userid,classid into roomid_,epid_,userid_,classid_ from study_quizinfo where id = mepid;
     --2 Ծֵ
         open epblocks;
             loop
                fetch epblocks into blockid_ ; --ȡֵ
                exit when epblocks%notfound; --ûм¼ʱ˳ѭ
                sr_blockscore_set_marking(mepid,blockid_ );
             end loop;
         close epblocks;
     -- 3 õֵܷ
     select sum(myscore) into ep_score from study_blocks where sqid = mepid;
     select rep.passgrade into passgrade_ from study_quizinfo sqi,exam_reps rep where rep.epid=sqi.epid and rep.roomid= sqi.roomid and sqi.id = mepid;
     if ep_score >=passgrade_ then
        ispassed_ := 1;
     end if;
     -- 4 ¼Ծֵ
     update study_quizinfo set myscore = nvl(ep_score,0),status =3,ispassed =nvl(ispassed_,0) where id = mepid ;
     -- 5 ¼ֵ
     sr_seteroom(userid_ ,roomid_);
     --6 ѧֵĹ
     -----1Ȳ鿴ôûѵ
     -----2о͵
     if classid_ > 0 then
        user_ispass_class2(classid_,userid_);
     end if;
end ;


----------------ֵ趨
create or replace procedure sr_blockscore_set_marking(sqid_ number,blockid_ number) as
ispassed_ number default 0;qid_ number;qtype_ number;u_myanswer varchar2(4000) ;q_rulestr varchar2(4000);
q_answer varchar2(4000);bl_score number;bl_size number;score_ number;
cursor questions is select q.id,ebq.rulestring,q.answer,q.qtype from question q left join exampaperblockquestion ebq on ebq.questionid=
      q.id where ebq.blockid = blockid_ and q.qtype = 7;
begin
     -- ???? ????????
     --select random, eachscore,type,rulestring into bl_random , bl_eachscore, bl_type,bl_rulestr  from exampaperblock where id = u_bl_id;
     --2 ????????
       open questions;
           loop
              fetch questions into qid_,q_rulestr,q_answer,qtype_ ; --??
              exit when questions%notfound; --??????????
              select sum(sq.myscore) into score_ from study_questions sq left join question q on q.id = sq.qid where q.parentid = qid_ and sq.sqid =sqid_ and sq.blockid=blockid_;
              update study_questions set myscore = nvl(score_,0) ,status= 1 where sqid =sqid_ and blockid=blockid_ and qid= qid_;
           end loop;
        close questions;
     -- 3 ???????
     select sum(myscore) into bl_score from (select sq.* from study_questions sq left join question q on q.id = sq.qid where q.parentid=0) where sqid =sqid_    and blockid= blockid_;
     -- 4 ??????
     update study_blocks set myscore = nvl(bl_score,0) where blockid = blockid_ and sqid= sqid_;
end ;


2012-5-30

----------------
alter table QUESTIONLIB_OP_USER
  add constraint questionlib_op_user_pk_depid foreign key (DEPID)
  references question_lib (ID) on delete cascade;

----------------
alter table EROOMLIB_OP_USER
  add constraint eroomlib_op_user_pk_depid foreign key (DEPID)
  references eroom_lib (ID) on delete cascade;

----------------γ̿
alter table COURSE_OP_TYPE
  add constraint course_op_user_pk_ctypeid foreign key (ctypeid)
  references course_type (ID) on delete cascade;

---------------ѵ
alter table CLASS_OP_TYPE
  add constraint class_op_user_pk_ctypeid foreign key (ctypeid)
  references elclasstype (ID) on delete cascade;

----------------
alter table KNOWLEDGE_OP_TYPE
  add constraint knowledge_op_user_pk_ctypeid foreign key (ctypeid)
  references knowledgetype (ID) on delete cascade;

----------------ſ
alter table NEWSTYPE_OP_TYPE
  add constraint newstype_op_user_pk_ctypeid foreign key (ctypeid)
  references newstype (ID) on delete cascade;

----------------Ծ
alter table EXAMPAPERLIB_OP_USER
  add constraint exampaperlib_op_user_pk_depid foreign key (DEPID)
  references exampaperlib (ID) on delete cascade;

----------------ſ
alter table DEPARTMENT_OP_USER
  add constraint department_op_user_pk_depid foreign key (DEPID)
  references department (ID) on delete cascade;

2012-6-2
alter table busilogs add opid number(8) default 0 not null;-------------------------
  
  
2012-6-5
  
--ѧԱļ¼
create table study_room_record
(
  ID         number not null primary key,
  ROOMID     NUMBER not null,
  USERID     NUMBER not null,
  ISPASSED   NUMBER default 0 not null,
  STATUS     NUMBER default 0 not null,
  MYSCORE    NUMBER(20,2) default 0 not null
);

create sequence study_room_record_sequence
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 10;

create trigger auto_id_study_room_record before insert on study_room_record for each row 
when (new.id is null)
begin
     select study_room_record_sequence.nextval into :new.id from dual;
end;

--ѧԱԾ
create table study_exampaper
(
  userid     number not null,
  epid       NUMBER not null,
  roomid     number not null,
  classid    number default 0 not null
);


alter table study_quizinfo add mrrid number(8) default 0 not null;----------------------

2012-6-6


alter table exam_room add passmanner number(1) default 0 not null;-------------------------ͨʽ
alter table study_questions add opstatus number(1) default 0 not null;---------------


----------------------------------ÿɼ
create or replace procedure sr_seteroom_score(userid_ number,roomid_ number) as
  er_pg_ number;
  er_tscore_ number;
  qp_ispassed number;qp_tscore number; er_ispassed number default 0 ;
   courseid_ number; classid_ number;passmanner_ number;passedcount number default 0;
   maxScore_ float;avgScore_ float;er_score float;
--ѵγ
cursor class_courses is SELECT  cc.courseid,cc.classid FROM class_course cc left join study_room sr on sr.classid = cc.classid and  cc.eroomid=sr.roomid where sr.roomid = roomid_ and isdel!=-1;
 begin
     select passgrade,passmanner into er_pg_,passmanner_ from exam_room where id = roomid_ ;
     --ѯǷм¼ͨ
     select count(ispassed) into passedcount from study_room_record where roomid=roomid_ and userid=userid_ and ispassed=1;
     --жǷм¼ͨ
     if passedcount >0 then
        select max(myscore),avg(myscore) into maxScore_,avgScore_ from study_room_record where roomid=roomid_ and userid=userid_ and ispassed=1;
        er_ispassed:=1;
     else
        select max(myscore),avg(myscore) into maxScore_,avgScore_ from study_room_record where roomid=roomid_ and userid=userid_ and ispassed=0;
     end if;
     
     if passmanner_ =0  then--߷
        er_score:=maxScore_;
     else --ƽ
        er_score:=avgScore_;
     end if;
     update study_room set myscore = nvl(er_score,0),status =2,ispassed =nvl(er_ispassed,0) where roomid = roomid_ and userid = userid_;
     --ذ󶨵ĿĿγ̽ȼ
     open class_courses;
             loop
                fetch class_courses into  courseid_, classid_ ; --ȡֵ
                exit when class_courses%notfound; --ûм¼ʱ˳ѭ
                s_course_tprocess(userid_,courseid_,classid_ );
             end loop;
     close class_courses;
end ;


------------------------------ÿ¼
create or replace procedure sr_seteroom_record(userid_ number,roomid_ number,mrrid_ number) as
  er_pg_ number;
  er_tscore_ number;
  qp_ispassed number;qp_tscore number; er_ispassed number default 0 ;recordispassed number default 1;
   courseid_ number; classid_ number; mycount_ number default 0;curcount_ number default 0; status_ number;recordStatus_ number default 1;
cursor quizpassed is select ispassed,status from study_quizinfo where roomid = roomid_ and userid = userid_ and mrrid=mrrid_;
--ѵγ
 begin
     select passgrade into er_pg_ from exam_room where id = roomid_ ;
     --select sum(ep.ep_tscore) into er_tscore_ from exam_reps reps left join exampaper ep on ep.id = reps.epid where reps.roomid =roomid_;
     select sum(ep.ep_tscore) into er_tscore_ from study_exampaper se left join exampaper ep on ep.id = se.epid where se.roomid =roomid_ and se.userid=userid_;
     select sum(myscore) into qp_tscore from study_quizinfo where roomid = roomid_ and userid = userid_ and mrrid=mrrid_;
     open quizpassed;
             loop
                fetch quizpassed into qp_ispassed,status_; --ȡֵ
                exit when quizpassed%notfound; --ûм¼ʱ˳ѭ
                --exit when qp_ispassed =0;
                if status_=1 then
                  mycount_:=mycount_+1;
                end if;
                if status_>1 then
                  mycount_:=mycount_+2;
                end if;
                if qp_ispassed=0 then
                  recordispassed:=-1;
                end if;
                curcount_:=curcount_+1;
             end loop;
     close quizpassed;
     if er_tscore_ =0 then
        er_tscore_ := 1;
     end if;
     if recordispassed = 1 and curcount_>0 and qp_tscore * 100 / er_tscore_ >= er_pg_ then
        er_ispassed := 1;
     end if;
     if mycount_=curcount_*2 then
       recordStatus_:=2;
     end if;
     update study_room_record set myscore = nvl(qp_tscore,0),status =recordStatus_,ispassed =nvl(er_ispassed,0) where id=mrrid_;
end ;



-------------------------óɼ
create or replace procedure sr_setscore(mepid number) as
roomid_ number; epid_ number;userid_ number;ep_score number;passgrade_ number;
ispassed_ number default 0;blockid_ number;random_ number;b_rulestr varchar2(4000);qscore_ number;btype_ number ;mrrid_ number;
cursor epblocks is select id,random,rulestring,eachscore,type from exampaperblock where exampaperid = epid_;
begin
     -- һ ȡϢ
     select roomid,epid,userid,mrrid into roomid_,epid_,userid_,mrrid_ from study_quizinfo where id = mepid;
     --2 Ծֵ
         open epblocks;
             loop
                fetch epblocks into blockid_  ,random_  , b_rulestr  ,qscore_  ,btype_ ; --ȡֵ
                exit when epblocks%notfound; --ûм¼ʱ˳ѭ
                sr_blockscore_set(mepid,userid_ ,blockid_  ,random_  , b_rulestr  ,qscore_  ,btype_  );
             end loop;
         close epblocks;
     -- 3 õֵܷ
     select sum(myscore) into ep_score from study_blocks where sqid = mepid;
     select rep.passgrade into passgrade_ from study_quizinfo sqi,exam_reps rep where rep.epid=sqi.epid and rep.roomid= sqi.roomid and sqi.id = mepid;
     if ep_score >=passgrade_ then
        ispassed_ := 1;
     end if;
     -- 4 ¼Ծֵ
     update study_quizinfo set myscore = nvl(ep_score,0),status =2,ENDTIME= sysdate,ispassed =nvl(ispassed_,0) where id = mepid ;
     -- 5 ¼¼ֵ
     sr_seteroom_record(userid_ ,roomid_,mrrid_);
     -- 6 ¼ֵ
     --select passgrade into passgrade_ from exam_room where id = roomid_ ;
     --select sum(myscore) into ep_score from study_quizinfo where roomid = roomid_ and userid = userid_;
     --if ep_score >=passgrade_ then
     --   ispassed_ := 1;
     --end if;
     sr_seteroom_score(userid_ ,roomid_);
     --update study_room set myscore = nvl(ep_score,0),status =2,ispassed =nvl(ispassed_,0) where roomid = roomid_ and userid = userid_;
end ;


2012-6-8

--------------------ľ
create or replace procedure sr_setscore_marking(mepid number) as
roomid_ number; epid_ number;userid_ number;ep_score number;passgrade_ number;
ispassed_ number default 0;blockid_ number;classid_ number;courseid_ number;mrrid_ number;
cursor epblocks is select id from exampaperblock where exampaperid = epid_;
begin
     -- һ ȡϢ
     select roomid,epid,userid,classid,mrrid into roomid_,epid_,userid_,classid_,mrrid_ from study_quizinfo where id = mepid;
     --2 Ծֵ
         open epblocks;
             loop
                fetch epblocks into blockid_ ; --ȡֵ
                exit when epblocks%notfound; --ûм¼ʱ˳ѭ
                sr_blockscore_set_marking(mepid,blockid_ );
             end loop;
         close epblocks;
     -- 3 õֵܷ
     select sum(myscore) into ep_score from study_blocks where sqid = mepid;
     select rep.passgrade into passgrade_ from study_quizinfo sqi,exam_reps rep where rep.epid=sqi.epid and rep.roomid= sqi.roomid and sqi.id = mepid;
     if ep_score >=passgrade_ then
        ispassed_ := 1;
     end if;
     -- 4 ¼Ծֵ
     update study_quizinfo set myscore = nvl(ep_score,0),status =3,ispassed =nvl(ispassed_,0) where id = mepid ;
     -- 5 ¼ֵ
     --sr_seteroom(userid_ ,roomid_);
     sr_seteroom_record(userid_ ,roomid_,mrrid_);
     sr_seteroom_score(userid_ ,roomid_);
     --6 ѧֵĹ
     -----1Ȳ鿴ôûѵ
     -----2о͵
     if classid_ > 0 then
        user_ispass_class2(classid_,userid_);
     end if;
end ;


2012-6-14

alter table study_room add avgscore number(10,2) default 0 not null;--------------ƽɼ
alter table study_room add maxscore number(10,2) default 0 not null;--------------߳ɼ
alter table study_room add eroomcount number(4) default 0 not null;---------------ѿ

---------------ÿɼ(޸ѿ)
create or replace procedure sr_seteroom_score(userid_ number,roomid_ number) as
  er_pg_ number;
  er_tscore_ number;
  qp_ispassed number;qp_tscore number; er_ispassed number default 0 ;
   courseid_ number; classid_ number;passmanner_ number;passedcount number default 0;
   maxScore_ float;avgScore_ float;er_score float;srrcount_ number default 0;
--ѵγ
cursor class_courses is SELECT  cc.courseid,cc.classid FROM class_course cc left join study_room sr on sr.classid = cc.classid and  cc.eroomid=sr.roomid where sr.roomid = roomid_ and isdel!=-1;
 begin
     select passgrade,passmanner into er_pg_,passmanner_ from exam_room where id = roomid_ ;
     --ѯǷм¼ͨ
     select count(ispassed) into passedcount from study_room_record where roomid=roomid_ and userid=userid_ and ispassed=1;
     --жǷм¼ͨ
     if passedcount >0 then
        select max(myscore),avg(myscore) into maxScore_,avgScore_ from study_room_record where roomid=roomid_ and userid=userid_ and ispassed=1;
        er_ispassed:=1;
     else
        select max(myscore),avg(myscore) into maxScore_,avgScore_ from study_room_record where roomid=roomid_ and userid=userid_ and ispassed=0;
     end if;

     if passmanner_ =0  then--߷
        er_score:=maxScore_;
     else --ƽ
        er_score:=avgScore_;
     end if;
     --ѧԱƽֺ߷֣Ƿͨ
     select max(myscore),avg(myscore) into maxScore_,avgScore_ from study_room_record where roomid=roomid_ and userid=userid_;
     --ѧԱѿ  --¼Ѵ״̬
     --select count(id) into srrcount_ from study_room_record where roomid=roomid_ and userid=userid_ and status=2;
     select count(id) into srrcount_ from study_room_record where roomid=roomid_ and userid=userid_;
     --ѧԱϢ
     update study_room set myscore = nvl(er_score,0),status =2,ispassed =nvl(er_ispassed,0),avgscore=avgScore_,maxscore=maxScore_,eroomcount=srrcount_ where roomid = roomid_ and userid = userid_;
     --ذ󶨵ĿĿγ̽ȼ
     open class_courses;
             loop
                fetch class_courses into  courseid_, classid_ ; --ȡֵ
                exit when class_courses%notfound; --ûм¼ʱ˳ѭ
                s_course_tprocess(userid_,courseid_,classid_ );
             end loop;
     close class_courses;
end ;



2012-6-29

------------------ѵ
create table linetrainrecord_stuff
(
  ID            NUMBER not null,
  trainid       NUMBER not null,
  title         varchar(200), --
  stuffaddr     varchar(200) --ַ
);

alter table linetrainrecord_stuff
  add constraint linetrainrecord_stuff_ID_PK primary key (ID); 

create sequence linetrainrecord_stuff_sequence
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 10;

create or replace trigger auto_id_linetrainrecord_stuff  before insert on linetrainrecord_stuff for each row
when (new.id is null)
begin
      select linetrainrecord_stuff_sequence.nextval into :new.id from dual;
end;


----------------ѵ
alter table linetrainrecord_stuff
  add constraint LINETRAINRECORD_STUFF_ID_FK foreign key (trainid)
  references linetrainrecord(trainid) on delete cascade;

-----2012-7-16
-------------Ͽid
alter table knowledgetype add lid number default 0 not null;-------------------------
alter table knowledgetype add rid number default 0 not null;-------------------------



-----2012-7-18

---------------˸study_courseʱ ʱ䲻
create or replace procedure s_course_cp2 (userid_ number, courseid_ number ,classid_ number)
AS  ispassed_ number; c_time_ number; c_credit_ number; c_creditmod_ number;
    yxc_time_ number;  process_ number; mycredit_ number;
BEGIN
  -- ??????
  select  passed into ispassed_  from study_course where userid=userid_ and courseid =courseid_ and classid =classid_;
  if ispassed_= 0 then
      -- ??????
      select  during,credit,creditmod into  c_time_,c_credit_,  c_creditmod_ from course where id = courseid_ ;
      select sum(passtime) into yxc_time_ from (select * from study_cpage where userid =userid_ and classid=classid_) sc left join course_page cp on cp.id = sc.cpid where  cp.courseid=courseid_;

      process_ := (yxc_time_*100)/(60*c_time_);
      if  c_creditmod_=1 then
          mycredit_ := c_credit_*process_/100;
      else
          mycredit_ := 0;
      end if;
      update study_course set passtime = yxc_time_,process=process_,mycredit=mycredit_ where userid = userid_ and courseid=courseid_ and classid =classid_;

      -- ????????
      if yxc_time_>=c_time_*60 then
          mycredit_:= c_credit_;
          update study_course set passtime = c_time_*60 ,passed = 1,process = 100,mycredit=mycredit_ where userid = userid_ and courseid=courseid_ and classid =classid_;
      end if;
    end if;
END ;

-----------------------------˸study_courseʱ ʱ䲻
create or replace procedure s_course2(   userid_ number, courseid_ number, passtime_ number,classid_ number)
AS
 ispassed_ number ; c_time_  number ;yxc_time_ number ; process_ number;
BEGIN
 select  passed into ispassed_ from study_course where userid=userid_ and courseid =courseid_ and classid=classid_;
  if ispassed_ = 0 then
      -- ѧϰδ ¼
      select during into c_time_ from course where id = courseid_;
      select passtime into yxc_time_ from study_course where userid =  userid_ and courseid= courseid_ and classid=classid_;
      yxc_time_ := yxc_time_+passtime_;
      process_ := (yxc_time_*100)/(60*c_time_);
      update study_course set passtime = yxc_time_,process= process_ where userid =  userid_ and courseid= courseid_ and classid=classid_;
      -- 
      if  yxc_time_>=c_time_*60 then
          update study_course set passtime = c_time_*60 ,passed = 1,process = 100 where userid =userid_ and courseid=courseid_ and classid=classid_;
      end if;
      --¼ܽ

    end if;
    s_course_tprocess(userid_,courseid_,classid_);
END ;

--2012-7-19

--ɾݱ(ԭǿû)
alter table BASEDATAT
  drop constraint BASEDATAT_ID_PK;
--ݱ
alter table BASEDATAT
  add constraint BASEDATAT_ID_PK primary key (ID);
--ûĹֶθĳ
alter table ELUSER add tempcol number default 1;
update eluser set tempcol = jingzhong ;------ûֶַ
commit;
alter table ELUSER drop column JINGZHONG;
alter table ELUSER rename column tempcol to JingZhong;
alter table ELUSER
 add constraint ELUSER_jingzhong_fk foreign key (JINGZHONG)
  references basedatat (ID) on delete cascade;

--ûְֶθĳ
alter table ELUSER add tempcol number default 1;
update eluser set tempcol = zhiwu ;------ûְֶַ
commit;
alter table ELUSER drop column zhiwu;
alter table ELUSER rename column tempcol to zhiwu;
alter table ELUSER
 add constraint ELUSER_zhiwu_fk foreign key (zhiwu)
  references basedatat (ID) on delete cascade;

--ûְֶθĳ
alter table ELUSER add tempcol number default 1;
update eluser set tempcol = zhiji ;------ûְֶַ
commit;
alter table ELUSER drop column zhiji;
alter table ELUSER rename column tempcol to zhiji;
alter table ELUSER
  add constraint ELUSER_zhiji_fk foreign key (zhiji)
  references basedatat (ID) on delete cascade;

--ûĵֶθĳ
alter table ELUSER add tempcol number default 1;
update eluser set tempcol = dishi ;------ûֶַ
commit;
alter table ELUSER drop column dishi;
alter table ELUSER rename column tempcol to dishi;
alter table ELUSER
  add constraint ELUSER_dishi_fk foreign key (dishi)
  references basedatat (ID) on delete cascade;
  
  --2012-7-24
  
  --------ϰţѧԱԶȡϰ
create or replace procedure examprac_dep_set(userid_ number,depid_ number)
as
pracid_ number;exist_ number;
cursor pracids is select t1.pracid from (
select epd.pracid,dep.lid,dep.rid from examprac_dep epd inner join (select id from examprac where valid=1) ep on epd.pracid=ep.id left join department dep on epd.depid=dep.id
) t1,(select lid,rid from department where id=depid_) t2 where t2.lid>=t1.lid and t2.rid<=t1.rid;
begin
  open pracids;
    loop
      fetch pracids into pracid_;
      exit when pracids%notfound;
           select count(*) into exist_ from examprac_assign where eprid = pracid_ and userid = userid_;
           if exist_=0 then --жϸϰûзѧԱ
             insert into examprac_assign(eprid,userid)values(pracid_,userid_); --ѴϰѧԱ
           end if;
    end loop;
  close pracids;
end;

--2012-7-25

alter table study_exampaper add temp number(1) default 0 not null;------------
update study_exampaper set temp=status;-------------
alter table study_exampaper drop column status;----------------
alter table study_exampaper rename column temp to status;---------------


--2012-8-1
alter table study_quizinfo add activitystatus number(1) default 0 not null;---------------------

------------ѧԱѧϰ¼
create table study_course_record
(  
     id number not null,
     courseid number not null,--γid
     classid number not null,--ѵid
     cpid number default 0 not null,--½id
     userid number not null,
     begintime date not null,
     endtime date,
     status number(1) default 0 not null
);
alter table study_course_record  add constraint study_course_record_pk primary key (id) ;

create  sequence study_course_record_sequence
	increment by 1 -- ÿμӼ
	start with 1 -- 1ʼ
	nomaxvalue -- ֵ
	nocycle -- һֱۼӣѭ
	cache 10 ;
create trigger auto_id_study_course_record before insert on study_course_record for each row 
when (new.id is null)
begin
     select study_course_record_sequence.nextval into :new.id from dual;
end;

alter table study_exampaper add isdel number(1) default 0 not null;---------------Ƿɾ


--2012-8-2

---------------˿ɼѧԱԾֺܷͣɾԾ
create or replace procedure sr_seteroom_score(userid_ number,
                                              roomid_ number) as
  er_pg_      number;
  er_tscore_  number;
  qp_ispassed number; --Ծͨ
  qp_tscore   number; --Ծܷ
  er_ispassed number default 0;
  courseid_   number;
  classid_    number;
  er_score    float;
  --ѵγ
  cursor class_courses is
    SELECT cc.courseid, cc.classid
      FROM class_course cc
      left join study_room sr on sr.classid = cc.classid
                             and cc.eroomid = sr.roomid
     where sr.roomid = roomid_
       and isdel != -1;
  cursor seppassed is select ispassed from study_exampaper where roomid = roomid_ and userid = userid_ and isdel!=1;
begin
  select passgrade
    into er_pg_
    from exam_room
    where id = roomid_;
  --ȡϢ
    select sum(ep.ep_tscore) into er_tscore_ from (select * from study_exampaper where roomid=roomid_ and userid=userid_ and isdel!=1) reps  left join exampaper ep on ep.id = reps.epid where reps.roomid =roomid_;
     select sum(myscore) into qp_tscore from study_exampaper where roomid = roomid_ and userid = userid_  and isdel!=1;
     open seppassed;
             loop
                fetch seppassed into qp_ispassed;
                exit when seppassed%notfound;
                exit when qp_ispassed =0;
             end loop;
     close seppassed;
     if er_tscore_ =0 then
        er_tscore_ := 1;
     end if;
     if qp_ispassed = 1 and qp_tscore * 100 / er_tscore_ >= er_pg_ then
        er_ispassed := 1;
     end if;
  --ѧԱϢ
  update study_room
     set myscore    = nvl(qp_tscore, 0),
         status     = 2,
         ispassed   = nvl(er_ispassed, 0)
   where roomid = roomid_
     and userid = userid_;
  --ذ󶨵ĿĿγ̽ȼ
  open class_courses;
  loop
    fetch class_courses
      into courseid_, classid_; --ȡֵ
    exit when class_courses%notfound; --ûм¼ʱ˳ѭ
    s_course_tprocess(userid_, courseid_, classid_);
  end loop;
  close class_courses;
end;




--2012-8-10

alter table eprac_quizinfo add ispassed number(1) default 0 not null;-----------ϰǷͨ

-----------޸ϰֶͨispassedΪ1
create or replace procedure eprac_setscore(mepid number) as
roomid_ number; epid_ number;userid_ number;ep_score number;
blockid_ number;random_ number;b_rulestr varchar2(4000);qscore_ number;btype_ number ;pracScore_ number;ispassed_ number default 0;
cursor epblocks is select eb.id,eb.random,eb.rulestring,eb.eachscore,eb.type from eprac_quizinfo eq left join examprac pra
       on pra.id = eq.pracid left join exampaperblock eb on eb.exampaperid = pra.epid where eq.id = mepid;
begin
     -- ???? ????????
      select userid into  userid_ from eprac_quizinfo where id = mepid;
      select ep.ep_tscore*epr.passgrade/100 into pracScore_ from examprac epr left join eprac_quizinfo eq on epr.id=eq.pracid left join exampaper ep on epr.epid=ep.id where eq.id=mepid;--õķ
              --2 ??????????
         open epblocks;
             loop
                fetch epblocks into blockid_  ,random_  , b_rulestr  ,qscore_  ,btype_ ; --??
                exit when epblocks%notfound; --??????????
               eprac_blockscore_set(mepid ,userid_  ,blockid_  ,random_  , b_rulestr  ,qscore_  ,btype_  );
               end loop;
         close epblocks;
     -- 3 ???????
     select sum(myscore) into ep_score from eprac_blocks where pracqid = mepid;
     if ep_score>=pracScore_ then
       ispassed_:=1;
     end if;
     -- 4 ??????
     update eprac_quizinfo set myscore = nvl(ep_score,0), ENDTIME= sysdate,ispassed=ispassed_ where id = mepid ;
end ;

--2012-8-15

------Ϣ-ѧԱ
create table pop_eluser
(
  POPID  NUMBER not null,
  userid NUMBER not null
);
/
------Ϣ-
create table pop_room
(
  POPID  NUMBER not null,
  ROOMID NUMBER not null
);
/
------Ϣ-ѵ
create table pop_class
(
  POPID  NUMBER not null,
  classid NUMBER not null
);
/
------Ϣ-ű
create table pop_department
(
  POPID  NUMBER not null,
  depid NUMBER not null
);

------------ûԼɾ
alter table POP_ELUSER
  add constraint FK_POPELUSER_POPINFO_POPID foreign key (POPID)
  references popinfo (ID) on delete cascade;
------------űԼɾ
alter table POP_DEPARTMENT
  add constraint FK_POPDEPARTMENT_POPINFO_POPID foreign key (POPID)
  references popinfo (ID) on delete cascade;
------------Լɾ
alter table POP_ROOM
  add constraint FK_POPROOM_POPINFO_POPID foreign key (POPID)
  references popinfo (ID) on delete cascade;
------------ѵԼɾ
alter table POP_CLASS
  add constraint FK_POPCLASS_POPINFO_POPID foreign key (POPID)
  references popinfo (ID) on delete cascade;
  
  
--2012-8-17

------------ѧԱԼ¼
create table study_quizinfo_record
(  
     id number not null,
     sqid number not null,
     begintime date not null,
     endtime date,
     status number(1) default 0 not null
);
alter table study_quizinfo_record  add constraint study_quizinfo_record_pk primary key (id) ;--
--ж
create  sequence study_quizinfo_record_sequence
	increment by 1 -- ÿμӼ
	start with 1 -- 1ʼ
	nomaxvalue -- ֵ
	nocycle -- һֱۼӣѭ
	cache 10 ;
--idԶд
create trigger auto_id_study_quizinfo_record before insert on study_quizinfo_record for each row 
when (new.id is null)
begin
     select study_quizinfo_record_sequence.nextval into :new.id from dual;
end;
/
------------ѧԱϰ¼
create table eprac_quizinfo_record
(  
     id number not null,
     sqid number not null,
     begintime date not null,
     endtime date,
     status number(1) default 0 not null
);
alter table eprac_quizinfo_record  add constraint eprac_quizinfo_record_pk primary key (id) ;--
--ж
create  sequence eprac_quizinfo_record_sequence
	increment by 1 -- ÿμӼ
	start with 1 -- 1ʼ
	nomaxvalue -- ֵ
	nocycle -- һֱۼӣѭ
	cache 10 ;
--idԶд
create trigger auto_id_eprac_quizinfo_record before insert on eprac_quizinfo_record for each row 
when (new.id is null)
begin
     select eprac_quizinfo_record_sequence.nextval into :new.id from dual;
end;
/
------------ѧԱγϰ¼
create table cprac_quizinfo_record
(  
     id number not null,
     sqid number not null,
     begintime date not null,
     endtime date,
     status number(1) default 0 not null
);
alter table cprac_quizinfo_record  add constraint cprac_quizinfo_record_pk primary key (id) ;--
--ж
create  sequence cprac_quizinfo_record_sequence
	increment by 1 -- ÿμӼ
	start with 1 -- 1ʼ
	nomaxvalue -- ֵ
	nocycle -- һֱۼӣѭ
	cache 10 ;
--idԶд
create trigger auto_id_cprac_quizinfo_record before insert on cprac_quizinfo_record for each row 
when (new.id is null)
begin
     select cprac_quizinfo_record_sequence.nextval into :new.id from dual;
end;

--2012-8-21
--ѵҵˣѧԱѵ״̬Ϣ
create or replace procedure user_p_class_set2 (  classid_ number,userid_ number,diplomatime_ date , certificateno_ number)
as
ispassed_ int;iscf_ int;
BEGIN
    select count(*) into ispassed_ from study_class where classid= classid_ and userid=userid_ ;
    select count(*) into iscf_ from study_class where classid=classid_ and userid=userid_ and certificateno is not null ;
    if nvl(ispassed_,0)=0 then
       insert into study_class(classid,userid,applydate,status,certificateno) values(classid_,userid_,diplomatime_,2,nvl(certificateno_,0)+1) ;
    else
      if nvl(iscf_,0)=0 then
         update study_class set applydate= diplomatime_,status=2,certificateno=nvl(certificateno_,0)+1 where classid = classid_ and userid = userid_;
      else
         update study_class set status=2,certificateno=nvl(certificateno_,0) where classid = classid_ and userid = userid_;
      end if;
    end if;
END ;

alter table exampaper add isEditor number(1) default 0 not null;-----------ԾǷɱ༭

--2012-8-22
alter table eroom_registration add isAudit number(1) default 0 not null;-------------ĿǷҪ
alter table elclass_registration add isAudit number(1) default 0 not null;-------------ѵǷҪ

--2012-8-24
alter table study_course_record add passtime number default 0 not null;-----------------ѧԱѧϰ¼ʱ


--2012-9-4
--쳣
create or replace procedure s_course_tprocess(  userid_ number,courseid_ number,classid_  number)
as
    getcredit_ number; sispassed_ number;cispassed_ number;passed_ number;process_ number;cprocess_ number;
begin
    begin
      SELECT getcredit into getcredit_ FROM class_course where classid =classid_ and courseid= courseid_ and isdel!=-1;
      exception
         when no_data_found then
          cispassed_:=0;
          cprocess_:=0;
      end;
    begin
    select sc.passed,sc.process into cispassed_,cprocess_ from study_course sc where  sc.courseid= courseid_ and sc.userid= userid_ and sc.classid=classid_;
    exception
        when no_data_found then
        cispassed_:=0;
        cprocess_:=0;
    end;
    begin
      select sr.ispassed into sispassed_ from study_room sr left join class_course cc on sr.roomid = cc.eroomid where  cc.courseid= courseid_ and sr.userid= userid_ and sr.classid=classid_;
      exception
      when no_data_found then
          sispassed_:=0;
    end;
    cispassed_ := nvl(cispassed_,0);
    sispassed_ := nvl(sispassed_,0);
    if getcredit_ = 1 then
        process_ := cprocess_;
    elsif getcredit_ = 2 and sispassed_ =1 then
        process_:= 100;
    elsif getcredit_ = 3 then
        if sispassed_ =1 and cispassed_=1 then
          process_ := 100;
        elsif sispassed_=1 or cispassed_=1 then
          process_ := 50;
        end if;
    else
        process_:=0;
    end if;
    update study_course set tprocess = process_ where userid =userid_ and courseid=courseid_ and classid=classid_;
end;

--2012-9-5

---------------------------------ע
create table simpleRemack
(
  ID            NUMBER not null,
  type          NUMBER not null,--12ѵ
  typeid        NUMBER not null,
  createid      NUMBER not null,
  touserid      number not null,--id
  createtime    date not null,
  title         varchar2(200) not null,
  phone         varchar2(20),
  content       varchar2(2000)
);
alter table simpleRemack add constraint simpleRemack_ID_PK primary key (ID);
create sequence simpleRemack_sequence
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 10;
create or replace trigger auto_id_simpleRemack  before insert on simpleRemack for each row
when (new.id is null)
begin
      select simpleRemack_sequence.nextval into :new.id from dual;
end;
/
------------------------------ʱ洢
create table study_room_apply
(
  roomid          NUMBER not null,
  userid          NUMBER not null,
  status          NUMBER not null,
  createtime      date not null
);
------------------------------ѵ౨ʱ洢
create table study_class_apply
(
  classid          NUMBER not null,
  userid          NUMBER not null,
  status          NUMBER not null,
  createtime      date not null
);


--2012-9-11
create or replace procedure s_course_tprocess(  userid_ number,courseid_ number,classid_  number)
as
    getcredit_ number; sispassed_ number;cispassed_ number;passed_ number;process_ number;cprocess_ number;
begin
    begin
      SELECT getcredit into getcredit_ FROM class_course where classid =classid_ and courseid= courseid_ and isdel!=-1;
      exception
         when no_data_found then
          cispassed_:=0;
          cprocess_:=0;
      end;
    begin
    select sc.passed,sc.process into cispassed_,cprocess_ from study_course sc where  sc.courseid= courseid_ and sc.userid= userid_ and sc.classid=classid_;
    exception
        when no_data_found then
        cispassed_:=0;
        cprocess_:=0;
    end;
    begin
      select sr.ispassed into sispassed_ from study_room sr left join class_course cc on sr.roomid = cc.eroomid where  cc.courseid= courseid_ and sr.userid= userid_ and sr.classid=classid_;
      exception
      when no_data_found then
          sispassed_:=0;
    end;
    cispassed_ := nvl(cispassed_,0);
    sispassed_ := nvl(sispassed_,0);
    if getcredit_ = 1 then
        process_ := cprocess_;
    elsif getcredit_ = 2 and sispassed_ =1 then
        process_:= 100;
    elsif getcredit_ = 3 then
        if sispassed_ =1 and cispassed_=1 then
          process_ := 100;
        elsif sispassed_=1 or cispassed_=1 then
          process_ := 50;
        end if;
    else
        process_:=0;
    end if;
    sispassed_:=0;
    if process_=100 then
      sispassed_:=1;
    end if;
    update study_course set tprocess = process_,passed=sispassed_ where userid =userid_ and courseid=courseid_ and classid=classid_;
<<<<<<< .mine
end;


--2012-10-19
------------乤ֱ
create table exam_jingzhong(
   roomid int not null,
   jingzhong int not null,
   status int default 0 not null
);

--------------ѧԱԶȡӦĿ
create or replace procedure exam_jingzhong_set(userid_ number)
 as
  roomid_ number;exist_ number;classid_ number;epid_ number;
  cursor roomids is select roomid from exam_jingzhong where jingzhong=(select jingzhong from eluser where id=userid_);
  cursor epids is select epid from exam_reps where roomid=roomid_ and status=0;
begin
  open roomids;
    loop
      fetch roomids into roomid_;
      exit when roomids%notfound;
        select count(*) into exist_ from study_room where userid=userid_ and roomid=roomid_;
        if exist_=0 then-----жϿǷѾѧԱ
          select classid into classid_ from exam_room where id=roomid_;
          insert into study_room(roomid,userid,classid) values(roomid_,userid_,classid_);
          ---δɾԾ
          open epids;
            loop
              fetch epids into epid_;
              exit when epids%notfound;
                 select count(*) into exist_ from study_exampaper where userid=userid_ and roomid=roomid_ and epid=epid_;
                 if exist_=0 then
                   insert into study_exampaper(userid,epid,roomid,classid) values(userid_,epid_,roomid_,classid_);
                 end if;
            end loop;
          close epids;
        end if;
    end loop;
  close roomids;
end;

--2012-10-25
-----------Դ䲿ű
create table knowledge_dep(
   id int not null,
   status int default 0 not null
);



--2012-11-5
alter table eluser add email varchar2(50);

----------10099.99999999999999
create or replace procedure s_course_tprocess(  userid_ number,courseid_ number,classid_  number)
as
    getcredit_ number; sispassed_ number;cispassed_ number;passed_ number;process_ number;cprocess_ number(3,0);
begin
    begin
      SELECT getcredit into getcredit_ FROM class_course where classid =classid_ and courseid= courseid_ and isdel!=-1;
      exception
         when no_data_found then
          cispassed_:=0;
          cprocess_:=0;
      end;
    begin
    select sc.passed,sc.process into cispassed_,cprocess_ from study_course sc where  sc.courseid= courseid_ and sc.userid= userid_ and sc.classid=classid_;
    exception
        when no_data_found then
        cispassed_:=0;
        cprocess_:=0;
    end;
    begin
      select sr.ispassed into sispassed_ from study_room sr left join class_course cc on sr.roomid = cc.eroomid where  cc.courseid= courseid_ and sr.userid= userid_ and sr.classid=classid_;
      exception
      when no_data_found then
          sispassed_:=0;
    end;
    cispassed_ := nvl(cispassed_,0);
    sispassed_ := nvl(sispassed_,0);
    if getcredit_ = 1 then
        process_ := cprocess_;
    elsif getcredit_ = 2 and sispassed_ =1 then
        process_:= 100;
    elsif getcredit_ = 3 then
        if sispassed_ =1 and cispassed_=1 then
          process_ := 100;
        elsif sispassed_=1 or cispassed_=1 then
          process_ := 50;
        end if;
    else
        process_:=0;
    end if;
    sispassed_:=0;
    if process_=100 then
      sispassed_:=1;
    end if;
    update study_course set tprocess = process_,passed=sispassed_ where userid =userid_ and courseid=courseid_ and classid=classid_;
end;



--2012-11-19
alter table exam_room add depName varchar2(400);
alter table exam_room add jingzhong varchar2(50);
alter table elclass add depName varchar2(400);
alter table elclass add jingzhong varchar2(50);
----wsy
alter table exam_room add pwdneed number default 0 not null ;
alter table exam_room add pwd varchar(400)  ;
alter table exam_room add pwdtime date default sysdate;

--2012-11-22  wsy
alter table exam_room add cacheepsize number default -1 not null;
alter table exam_room add cacheeprefresh number default 0 not null;

--2012-11-23
<<<<<<< .mine
alter table study_room add begintime date;=======
end;


--2012-10-19
------------乤ֱ
create table exam_jingzhong(
   roomid int not null,
   jingzhong int not null,
   status int default 0 not null
);

--------------ѧԱԶȡӦĿ
create or replace procedure exam_jingzhong_set(userid_ number)
 as
  roomid_ number;exist_ number;classid_ number;epid_ number;
  cursor roomids is select roomid from exam_jingzhong where jingzhong=(select jingzhong from eluser where id=userid_);
  cursor epids is select epid from exam_reps where roomid=roomid_ and status=0;
begin
  open roomids;
    loop
      fetch roomids into roomid_;
      exit when roomids%notfound;
        select count(*) into exist_ from study_room where userid=userid_ and roomid=roomid_;
        if exist_=0 then-----жϿǷѾѧԱ
          select classid into classid_ from exam_room where id=roomid_;
          insert into study_room(roomid,userid,classid) values(roomid_,userid_,classid_);
          ---δɾԾ
          open epids;
            loop
              fetch epids into epid_;
              exit when epids%notfound;
                 select count(*) into exist_ from study_exampaper where userid=userid_ and roomid=roomid_ and epid=epid_;
                 if exist_=0 then
                   insert into study_exampaper(userid,epid,roomid,classid) values(userid_,epid_,roomid_,classid_);
                 end if;
            end loop;
          close epids;
        end if;
    end loop;
  close roomids;
end;

--2012-10-25
-----------Դ䲿ű
create table knowledge_dep(
   id int not null,
   status int default 0 not null
);



--2012-11-5
alter table eluser add email varchar2(50);

----------10099.99999999999999
create or replace procedure s_course_tprocess(  userid_ number,courseid_ number,classid_  number)
as
    getcredit_ number; sispassed_ number;cispassed_ number;passed_ number;process_ number;cprocess_ number(3,0);
begin
    begin
      SELECT getcredit into getcredit_ FROM class_course where classid =classid_ and courseid= courseid_ and isdel!=-1;
      exception
         when no_data_found then
          cispassed_:=0;
          cprocess_:=0;
      end;
    begin
    select sc.passed,sc.process into cispassed_,cprocess_ from study_course sc where  sc.courseid= courseid_ and sc.userid= userid_ and sc.classid=classid_;
    exception
        when no_data_found then
        cispassed_:=0;
        cprocess_:=0;
    end;
    begin
      select sr.ispassed into sispassed_ from study_room sr left join class_course cc on sr.roomid = cc.eroomid where  cc.courseid= courseid_ and sr.userid= userid_ and sr.classid=classid_;
      exception
      when no_data_found then
          sispassed_:=0;
    end;
    cispassed_ := nvl(cispassed_,0);
    sispassed_ := nvl(sispassed_,0);
    if getcredit_ = 1 then
        process_ := cprocess_;
    elsif getcredit_ = 2 and sispassed_ =1 then
        process_:= 100;
    elsif getcredit_ = 3 then
        if sispassed_ =1 and cispassed_=1 then
          process_ := 100;
        elsif sispassed_=1 or cispassed_=1 then
          process_ := 50;
        end if;
    else
        process_:=0;
    end if;
    sispassed_:=0;
    if process_=100 then
      sispassed_:=1;
    end if;
    update study_course set tprocess = process_,passed=sispassed_ where userid =userid_ and courseid=courseid_ and classid=classid_;
end;



--2012-11-19
alter table exam_room add depName varchar2(400);
alter table exam_room add jingzhong varchar2(50);
alter table elclass add depName varchar2(400);
alter table elclass add jingzhong varchar2(50);
----wsy
alter table exam_room add pwdneed number default 0 not null ;
alter table exam_room add pwd varchar(400)  ;
alter table exam_room add pwdtime date default sysdate;

--2012-11-22  wsy
alter table exam_room add cacheepsize number default -1 not null;
alter table exam_room add cacheeprefresh number default 0 not null;

--2012-11-23
alter table study_room add begintime date;

--2012-12-10
alter table exam_reps add sortid number default 0 not null;--Ծ

--2012-12-11
alter table message add isreply number(1) default 0 not null;--Ƿظ>>>>>>> .r2953
=======
alter table study_room add begintime date;

--2012-12-10
alter table exam_reps add sortid number default 0 not null;--Ծ

--2012-12-11
alter table message add isreply number(1) default 0 not null;--Ƿظ

--ͶƱϢ
create table pollInfo(
  id  number not null primary key,
  qid number not null,
  createrid number not null,
  title varchar2(100) not null,
  remack varchar2(500),
  stuViewResult number default 0 not null,--Ƿɿ
  createtime date default sysdate not null,
  begintime date not null,
  endtime date not null,
  status number default 0 not null
);
--ͶƱԱ
create table poll_assign(
  pollid number not null,
  userid number not null
);
--ѧԱͶƱѡϢ
create table poll_quizinfo(
  pollid number not null,
  userid number not null,
  answer varchar(20)
);
/
create sequence pollInfo_sequence
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 10;
/
create or replace trigger auto_id_pollInfo  before insert on pollInfo for each row
when (new.id is null)
begin
      select pollInfo_sequence.nextval into :new.id from dual;
end;

<<<<<<< .mine
>>>>>>> .r2974
=======

--2012-12-19
alter table elrole add createrid number default 1 not null;>>>>>>> .r3011
