turnrule.pas

来自「pasa人力资源考勤管理系统」· PAS 代码 · 共 1,474 行 · 第 1/4 页

PAS
1,474
字号
  if (Turn=0) or (Kind=0) then
    begin
      showmessage('轮班规则和轮班周期不能为0') ;
      exit;
    end;
  ary2.SQL.Text :='select * from turn02010 where ruleno='''+ADoturnrule.fieldbyname('ruleno').asstring+'''' ;
  ary2.Open ;
  if not ary2.Eof then
    begin
      ban[1] :=ary2.fieldbyname('classno1').asstring ;
      ban[2] :=ary2.fieldbyname('classno2').asstring ;
      ban[3] :=ary2.fieldbyname('classno3').asstring ;
      ban[4] :=ary2.fieldbyname('classno4').asstring ;
      ban[5] :=ary2.fieldbyname('classno5').asstring ;
      ban[6] :=ary2.fieldbyname('classno6').asstring ;
      ban[7] :=ary2.fieldbyname('classno7').asstring ;
      ban[8] :=ary2.fieldbyname('classno8').asstring ;
      Tban[1] :='' ;
      Tban[2] :='' ;
      Tban[3] :='' ;
      Tban[4] :='' ;
      Tban[5] :='' ;
      Tban[6] :='' ;
      Tban[7] :='' ;
      Tban[8] :='' ;
      Jban[1] :=Adoturnrule.fieldbyname('sche11').asstring ;
      Jban[2] :=ADoturnrule.fieldbyname('sche12').asstring ;
      Jban[3] :=ADoturnrule.fieldbyname('sche13').asstring ;
      Jban[4] :=ADoturnrule.fieldbyname('sche14').asstring ;
      Jban[5] :=ADoturnrule.fieldbyname('sche15').asstring ;
      Jban[6] :=ADoturnrule.fieldbyname('sche16').asstring ;
      Jban[7] :=ADoturnrule.fieldbyname('sche17').asstring ;
      Jban[8] :=ADoturnrule.fieldbyname('sche18').asstring ;
    end
  else begin
      ary1.free ;
      ary2.Close ;
      ary2.Free ;
  end;
  ary2.Close ;
  for i:=1 to kind do //多少个班次
    begin
      date1:=strtodate(maskedit1.text) ;
      sd :=strtodate(maskedit1.text) ;
      whichclass :=ban[i] ;
      t :=Lt ;
      if i=1 then
        k :=ki
      else
        k :=i ;
      while (date1<=strtodate(maskedit2.text)) do
        begin
          decodedate(sd,year,month,day) ;
          decodedate(date1,year1,month1,day1) ;
          ary1.Close ;
          ary1.SQL.Text :='select * from pub06010 where comcode='''+combobox1.text+''' and comdate='''+datetostr(date1)+''' ' ;
          ary1.open ;
          if ADoturnrule.FieldByName('rest').asboolean or ary1.Eof or (not ADoturnrule.FieldByName('Norestbu').asboolean and not ADoturnrule.FieldByName('rest').asboolean) then   //节假日是否参与轮休
            begin
               decodedate(date1+1,year2,month2,day2) ;
              if (((month2-month<>0) and (day2=1 )) or ((month2-month=0) and (day2-Adoturnrule.FieldByName('month15').asinteger=1 )) ) and (jban[k]<>'') and (whichclass<>Jban[k]) then //交接班次的日期
                whichclass :=Jban[k]
              else if (((month1-month<>0) and (day1=1)) or ((month1-month=0) and (day1-Adoturnrule.FieldByName('month15').asinteger=1))) then    //跨到下一个班次
               begin
                sd :=date1 ;
                t :=t+1 ;
                if t mod turn=0 then  //往下面轮
                begin
                  k :=(k+1) mod kind ;
                  if k=0 then k :=kind ;
                  whichclass :=ban[k];
                end else whichclass :=ban[k] ;
               end
              else whichclass :=ban[k] ;
            end;
{          Ary2.SQL.Text :='insert turn01010 select '''+ADoturnrule.fieldbyname('ruleno').asstring+''','''+datetostr(date1)+''','''+ban[i]+''', '+
          'everyday,gotime1,outtime1,add1,continue1 ,decrease1,daytime1,ot1,gotime2,outtime2 ,add2 ,continue2,decrease2 ,daytime2,ot2,gotime3,outtime3,add3,continue3,'+
	  'decrease3,daytime3,ot3,gotime4,outtime4,add4,continue4,decrease4,daytime4,ot4,gotime5,outtime5,add5,continue5,decrease5,daytime5,ot5,''0'',''0'','''+pubworkname+''','''+formatdatetime('yyyy/mm/dd',now)+''','+
          'outuncertain1,outuncertain2,outuncertain3,outuncertain4,outuncertain5,vary1,vary2,vary3,vary4,vary5,leg1,leg2,leg3,leg4,leg5,walk1,walk2,walk3,walk4,walk5 from atd01010 where '+
          'scheno='''+whichclass+''' ' ;}

           Ary2.SQL.Text :='insert turn01010 select '''+ADoturnrule.fieldbyname('ruleno').asstring+''','''+datetostr(date1)+''','''+ban[i]+''', '+
          'everyday,gotime1,outtime1,add1,continue1 ,decrease1,daytime1,ot1,gotime2,outtime2 ,add2 ,continue2,decrease2 ,daytime2,ot2,gotime3,outtime3,add3,continue3,'+
	  'decrease3,daytime3,ot3,gotime4,outtime4,add4,continue4,decrease4,daytime4,ot4,gotime5,outtime5,add5,continue5,decrease5,daytime5,ot5,''0'',''0'','''+pubworkname+''','''+formatdatetime('yyyy/mm/dd',now)+''','+
          'outuncertain1,outuncertain2,outuncertain3,outuncertain4,outuncertain5,vary1,vary2,vary3,vary4,vary5,leg2,leg3,leg4,leg5,walk2,walk3,walk4,walk5,unatdxia from atd01010 where '+
          'scheno='''+whichclass+''' ' ;







          ary2.ExecSQL ;
          date1 :=date1+1 ;
          end;
      Tban[i] :=whichclass ;
     //  i :=i+1 ;
    end;
    if not ADoturnrule.FieldByName('rest').asboolean then //轮班人员节假日不上班
    begin
    ary1.Close ;
    ary1.SQL.Text :='select comdate from pub06010 where comcode='''+combobox1.Text+'''' ;
    ary1.Open ;
    while not ary1.Eof do
      begin
        ary2.SQL.Text :='update turn01010 set flag1=''X'' where ruleno='''+ADoturnrule.fieldbyname('ruleno').asstring+''' and rdate='''+ary1.fieldbyname('comdate').asstring+''' ';
        ary2.ExecSQL ;
        ary1.Next ;
      end;
    end;
    ary1.Close ;
    ary1.SQL.Text :='update turn02010 set flag=''1'',Tclassno1='''+Tban[1]+''',Tclassno2='''+Tban[2]+''',Tclassno3='''+Tban[3]+''',Tclassno4='''+Tban[4]+''','+
    ' Tclassno5='''+Tban[5]+''',Tclassno6='''+Tban[6]+''',Tclassno7='''+Tban[7]+''',Tclassno8='''+Tban[8]+''',Sdate='''+maskedit1.text+''',Edate='''+maskedit2.text+''','+
    ' Ldate='''+datetostr(strtodate(maskedit2.text)+k)+''',Lastday='''+inttostr(turn-(t mod turn))+''' where ruleno='''+ADoturnrule.fieldbyname('ruleno').asstring+''' ' ;
    ary1.ExecSQL ;
    ary1.Free ;
    ary2.Free ;
except
  ary1.Free ;
  ary2.free ;
  showmessage('对不起,产生轮班表时出错') ;
end;
end;

procedure TFormturnrule.tbnsortClick(Sender: TObject);
begin
  Adoturnrule.Close ;
  Adoturnrule.open ;
  Adoturn.Close ;
  Adoturn.Open ;
end;

procedure TFormturnrule.tbninputClick(Sender: TObject);
begin
  panel2.Visible := not panel2.Visible ;
  if panel2.Visible then
    dbedit5.SetFocus ;
end;

procedure TFormturnrule.ToolButton5Click(Sender: TObject);
begin
  panel1.Visible :=not panel1.Visible ;
  if panel1.Visible then
    maskedit1.SetFocus ;
end;

procedure TFormturnrule.SpeedButton1Click(Sender: TObject);
begin
  panel1.Visible :=false ;
end;

procedure TFormturnrule.ToolButton4Click(Sender: TObject);
begin
  close;
end;

procedure TFormturnrule.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  dbgrid_keypress(sender,key);
end;

procedure TFormturnrule.ADOturnruleBeforeDelete(DataSet: TDataSet);
var aqy :Tadoquery ;
begin
  if Application.MessageBox ('如果您确定删除这个轮班规则,将会删除这个规则的轮班表','警告',mb_ok+mb_iconerror) =idok then
  begin
    aqy :=Tadoquery.Create (self) ;
    aqy.Connection :=datamod.Database1 ;
    aqy.SQL.Add ('delete from turn02010 where ruleno='''+trim(dbedit5.Text)+''' ') ;
    aqy.SQL.Add ('delete from turn01010 where ruleno='''+trim(dbedit5.text)+''' ') ;// and '+
                   // 'rdate>='''+maskedit1.Text+''' and rdate <='''+maskedit2.Text +''' ') ;
    aqy.ExecSQL ;
    aqy.Close ;
    aqy.Free ;
  end
  else
    ADoturnrule.Cancel ;
end;

procedure TFormturnrule.ADOturnruleBeforePost(DataSet: TDataSet);
var aqy:Tadoquery ;
    t1,t2,t3,t4,t5,t6,t7,t8:string;
    i:integer ;
begin
  t1:=trim(dbcombobox19.text) ;
  t2:=trim(dbcombobox20.text) ;
  t3:=trim(dbcombobox21.text) ;
  t4:=trim(dbcombobox22.text) ;
  t5:=trim(dbcombobox23.text) ;
  t6:=trim(dbcombobox24.text) ;
  t7:=trim(dbcombobox25.text) ;
  t8:=trim(dbcombobox26.text) ;
  i :=0 ;
  if t1<>'' then i:=i+1;
  if t2<>'' then i:=i+1;
  if t3<>'' then i:=i+1;
  if t4<>'' then i:=i+1;
  if t5<>'' then i:=i+1;
  if t6<>'' then i:=i+1;
  if t7<>'' then i:=i+1;
  if t8<>'' then i:=i+1;
  if i<>ADoturnrule.FieldByName('schenum').asinteger then
   begin
    showmessage('你输入的轮班的班次代号个数不一致') ;
    abort ;
    exit ;
   end;
  if ADoturnrule.State =dsedit then
    if Application.MessageBox('如果确定修改存盘的话,这将会删除你产生的轮班表','修改资料', mb_yesno+MB_ICONINFORMATION)<>idyes then
      begin
        abort ;
        exit ;
      end;
  aqy:=Tadoquery.Create (self) ;
  aqy.connection :=datamod.database1 ;
  aqy.SQL.Add('Delete from turn01010 where ruleno='''+dbedit5.Text+''' ') ;
  aqy.SQL.Add('Delete from turn02010 where ruleno='''+dbedit5.text+''' ') ;
  aqy.ExecSQL ;
  aqy.Close ;
  aqy.SQL.Text :=('insert turn02010 values('''+dbedit5.Text+''','''+t1+''','''+t1+''','''+t2+''','''+t2+''','+
                      ' '''+t3+''','''+t3+''','''+t4+''','''+t4+''','''+t5+''','''+t5+''','''+t6+''','''+t6+''','+
                      ' '''+t7+''','''+t7+''','''+t8+''','''+t8+''',NULL,NULL,NULL,''0'',''0'') ') ;

  aqy.ExecSQL ;
  aqy.Close ;
  aqy.Free ;
  if Adoturnrule.FieldByName('dayormonth').asstring ='月' then
   begin
    if checkbox1.Checked then
      Adoturnrule.FieldByName('monthkind').asstring :='2'
    else if checkbox2.Checked then
      Adoturnrule.FieldByName('monthkind').asstring :='1'
    else begin
      showmessage('您没有选择是哪一种类型的月') ;
      abort;
    end;
   end;
 if (Adoturnrule.FieldByName('dayormonth').asstring ='半月') and (trim(Adoturnrule.FieldByName('month15').asstring) ='') then
   begin
     showmessage('您选择了半月,但没有选择半月的分界点') ;
     abort ;
   end;
end;

procedure TFormturnrule.ADOturnruledayormonthChange(Sender: TField);
begin
  if (Adoturnrule.state=dsinsert) and (Adoturnrule.state=dsedit) and (Adoturnrule.FieldByName('dayormonth').asstring='半月') then
    Adoturnrule.FieldByName('circle').asinteger :=1 ;
end;

procedure TFormturnrule.DBComboBox18Exit(Sender: TObject);
begin
  if dbcombobox18.Text='月' then
    begin
    checkbox1.Enabled :=true ;
    checkbox2.Enabled :=true ;
    checkbox2.setfocus;
    end
  else begin
    checkbox1.Enabled :=false ;
    checkbox2.Enabled :=false ;
  end;
  if dbcombobox18.Text='月中' then
  begin
    dbedit2.Enabled :=true;
    dbedit2.setfocus;
  end else dbedit2.Enabled :=false ;
  if dbcombobox18.text='日' then
     dbedit6.setfocus;
end;

procedure TFormturnrule.DsturnruleDataChange(Sender: TObject;
  Field: TField);
begin
  if adoturnrule.FieldByName('dayormonth').asstring='月' then
    if adoturnrule.FieldByName('monthkind').asstring='2' then
      checkbox1.Checked :=true
    else if adoturnrule.FieldByName('monthkind').asstring='1' then
      checkbox2.Checked :=true ;
  dbedit7.OnChange(dbedit7);
end;

procedure TFormturnrule.DateTimePicker2CloseUp(Sender: TObject);
begin
  if (Adoturnrule.State=dsinsert) or (Adoturnrule.State=dsedit) then
    Adoturnrule.FieldByName('lastrq').asstring :=datetostr(DateTimePicker2.Date) ;
end;

procedure TFormturnrule.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=vk_f1 then
  begin
   Application.helpfile :=extractfilepath(application.exename) +'help\pasahelp.hlp';
   application.HelpJump('SHM_contents0025');
  end;
  if (key=VK_Control) and tbninput.enabled then tbninput.OnClick(self);
end;

procedure TFormturnrule.DBCheckBox2Click(Sender: TObject);
begin
  if dbcheckbox2.Checked and dbcheckbox1.Checked then
    dbcheckbox1.Checked :=false ;
end;

procedure TFormturnrule.DBCheckBox1Click(Sender: TObject);
begin
  if dbcheckbox2.Checked and dbcheckbox1.Checked then
    dbcheckbox2.Checked :=false ;
end;

procedure TFormturnrule.CheckBox1Click(Sender: TObject);
begin
  if checkbox1.Checked and checkbox2.checked then checkbox2.Checked :=false ;
end;

procedure TFormturnrule.CheckBox2Click(Sender: TObject);
begin
  if checkbox2.Checked and checkbox1.checked then checkbox1.Checked :=false ;
end;

procedure TFormturnrule.tbnprintClick(Sender: TObject);
begin
   pplabel26.caption:='制表人:'+pubworkname;
   ppreport1.print;
end;

procedure TFormturnrule.ppReport1PreviewFormCreate(Sender: TObject);
begin
   tppreport(sender).PreviewForm.WindowState:=wsMaximized;
end;

procedure TFormturnrule.Edit1Exit(Sender: TObject);
begin
   adoturnrule.Locate('ruleno',edit1.text,[]);
end;

procedure TFormturnrule.DBEdit7Change(Sender: TObject);
var i:integer;
begin
  for i:=1 to 8 do
  begin
     TLabel(findcomponent('label'+inttostr(i))).visible:=false;
     TDBCombobox(findcomponent('dbcombobox'+inttostr(i+18))).visible:=false;
     TDBCombobox(findcomponent('dbcombobox'+inttostr(i+26))).visible:=false;
  end;
  if (trim(dbedit7.text)<>'') then
    if strtoint(trim(dbedit7.text))>8 then showmessage('最多只能有8种班次参与轮班,请输入1~8之间的数字')
    else begin
      for i:=1 to strtoint(trim(dbedit7.text)) do
      begin
         TLabel(findcomponent('label'+inttostr(i))).visible:=true;
         TDBCombobox(findcomponent('dbcombobox'+inttostr(i+18))).visible:=true;
         TDBCombobox(findcomponent('dbcombobox'+inttostr(i+26))).visible:=true;
      end;
    end;
end;

procedure TFormturnrule.DBGrid2MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
   DBGrid2.Hint:='当前资料笔数:'+inttostr(DBGrid2.Datasource.Dataset.RecordCount);
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?