⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 room.pas

📁 pasa人力资源考勤管理系统
💻 PAS
📖 第 1 页 / 共 4 页
字号:
               if datamod.adoquery1.fieldbyname('roomer').asboolean=true then et.Color:=clgreen;
               et.BorderStyle:=bsnone;
             end;
            et.visible:=true;
           end;
         end;
       datamod.adoquery1.Close;
       if sender=combobox1 then
         begin
          combobox1.text:=copy(treeview1.Selected.Text,1,pos(' ',treeview1.Selected.text)-1);
          if combobox1.Text =combobox2.text then
            combobox1.onchange(sender);
         end
       else if sender=combobox2 then
         begin
          combobox2.text:=copy(treeview1.Selected.Text,1,pos(' ',treeview1.Selected.text)-1);
          if combobox2.text=combobox1.text then
            combobox2.OnChange(sender);
         end;
     end;

end;

procedure Tformroom.Edit2DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var msno,sno,cxroom:string;  //选取节点中的工号,cxroom是sender中的宿舍编号
    Targetnode:Ttreenode;
    aqy3,aqy4:Tadoquery;
begin
  accept:=true;  //允许拖入
  if (source=treeview1) and (length((sender as tedit).text)>2) then
    accept:=false;
  TargetNode := TreeView1.GetNodeAt (X, Y);   //获得节点
  if (Source = treeview1) and (TargetNode<> nil) then
    if pos('000',treeview1.selected.parent.text)=1 then
      begin
        sno:=trim(copy(treeview1.selected.text,1,pos(' ',treeview1.selected.text)-1));
        with datamod.adoquery1 do
          begin
            sql.clear;
            sql.add('select sexname from per24010 where workno='''+sno+''' and leave=0 ');
            open;
          end;
          if strtoint(trim(copy((sender as Tedit).name,5,2)))<29 then
            cxroom:=combobox1.text
          else
            cxroom:=combobox2.text;
           with datamod.adoquery2 do
             begin
               sql.clear;
               sql.add('select roomkind from rom03010 where roomno='''+cxroom+''' ');
               open;
             end;
          if (not datamod.adoquery1.eof) and (not datamod.adoquery2.eof) then
            //用户在输入性别名称时,可能不一样
           if  ((datamod.adoquery1.fields[0].asstring='男') and (datamod.adoquery2.fields[0].Asstring='女')) or ((datamod.adoquery1.fields[0].asstring='女') and (datamod.adoquery2.fields[0].Asstring='男')) then
             accept:=false;

         datamod.adoquery1.close;
         datamod.adoquery2.close;
         end;

  if source=treeview1 then exit;  //从combobox2中拖放人员
  aqy3:=Tadoquery.create(self);
  aqy4:=Tadoquery.create(self);
  aqy3.Connection :=datamod.Database1;
  aqy4.Connection :=datamod.Database1;
  if strtoint(copy((source as Tedit).name,5,2))>28 then
  begin
    if length(trim((source as tedit).text))<=2 then exit;
    msno:= trim((source as tedit).hint);
    aqy3.sql.text:='select sexname from per24010 where workno='''+msno+''' and leave=0 ';
    aqy3.open;
    aqy4.sql.text:='select roomkind from rom03010 where roomno='''+trim(combobox1.text)+''' ';
    aqy4.open;
    if (not aqy3.eof) and (not aqy4.eof) then
      if  ((aqy3.fields[0].asstring='男') and (aqy4.fields[0].Asstring='女')) or ((aqy3.fields[0].asstring='女') and (aqy4.fields[0].Asstring='男')) then
        accept:=false;
     aqy3.close;
     aqy4.close;
 //////
    msno:= trim((sender as tedit).hint);
    aqy3.sql.text:='select sexname from per24010 where workno='''+msno+''' and leave=0 ';
    aqy3.open;
    aqy4.sql.text:='select roomkind from rom03010 where roomno='''+trim(combobox2.text)+''' ';
    aqy4.open;
    if (not aqy3.eof) and (not aqy4.eof) then
      if  ((aqy3.fields[0].asstring='男') and (aqy4.fields[0].Asstring='女')) or ((aqy3.fields[0].asstring='女') and (aqy4.fields[0].Asstring='男')) then
        accept:=false;
  end;
  aqy3.close;
  aqy4.close;
  aqy3.free;
  aqy4.free;

end;

procedure Tformroom.SpeedButton1Click(Sender: TObject);
var c1s,c2s:string;
begin
  c1s:='';c2s:='';
  c1s:=combobox1.Text;
  c2s:=combobox2.text;
  if trim(c1s)<>'' then  newbed(combobox1);
  if trim(c2s)<>'' then  newbed(combobox2);
  treeview1.Items.Clear;
  showtree(sender);
  if trim(c1s)<>'' then
    begin
     combobox1.Text :=c1s;
     combobox1.OnChange(sender);
     combxkeydown(combobox1);
    end;
  if trim(c2s)<>'' then
    begin
     combobox2.text:=c2s;
     combobox1.onchange(sender);
     combxkeydown(combobox2);
    end;
end;

procedure Tformroom.Edit1DragDrop(Sender, Source: TObject; X, Y: Integer);
var sname:string;
    TargetNode:ttreenode;
    i,j:integer;
    bed1:tedit;
begin
   sname:='';
   for i:=1 to 56 do
   begin
     if source=Tedit(findcomponent('edit'+inttostr(i))) then
     begin
       bed1:=Tedit(findcomponent('edit'+inttostr(i)));
       with bed1 do
       begin
         if i>28 then
           j:=i-28
         else
           j:=i;
         sname:=bed1.text;ygno:=bed1.Hint;bed1.hint:=inttostr(j); bed1.text :=inttostr(j);
         if length(sname)<=2 then exit;
         if length((sender as tedit).text)>2 then
          begin
           bed1.text:=(sender as tedit).text;
           bed1.Hint:=(sender as tedit).hint;
          end;
       end;
     end;
   end;

    TargetNode := TreeView1.GetNodeAt (X, Y);
    if (Source = treeview1) and (TargetNode<> nil) then
       if pos('000',treeview1.selected.parent.text)=1 then
         begin
           sname:=trim(copy(treeview1.selected.Text,pos(' ',treeview1.selected.Text),14));
           ygno:=trim(copy(treeview1.selected.text,1,pos(' ',treeview1.selected.text)-1));
           treeview1.selected.Delete;
         end;

    if length(sname)<=2 then exit;
    for i:=1 to 56 do
    begin
      if sender=Tedit(findcomponent('edit'+inttostr(i))) then
        begin
          bed1:=Tedit(findcomponent('edit'+inttostr(i)));
          with bed1 do
          begin
            bed1.Text:=sname;
            bed1.Hint:=ygno;
          end;
        end;
    end;
    
end;

procedure Tformroom.Edit29DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var sno:string;
    aqy1,aqy2:Tadoquery;
begin
  accept:=true;
  if source=treeview1 then exit;
  aqy1:=Tadoquery.create(self);
  aqy2:=Tadoquery.create(self);
  aqy1.Connection :=datamod.Database1;
  aqy2.Connection :=datamod.Database1;
  if strtoint(copy((source as Tedit).name,5,2))<29 then
  begin
    if length(trim((source as tedit).text))<2 then exit;
    sno:= trim((source as tedit).hint);
    aqy1.sql.text:='select sexname from per24010 where workno='''+sno+''' and leave=0 ';
    aqy1.open;
    aqy2.sql.text:='select roomkind from rom03010 where roomno='''+trim(combobox2.text)+''' ';
    aqy2.open;
    if (not aqy1.eof) and (not aqy2.eof) then
      if  ((aqy1.fields[0].asstring='男') and (aqy2.fields[0].Asstring='女')) or ((aqy1.fields[0].asstring='女') and (aqy2.fields[0].Asstring='男')) then
        accept:=false;
    aqy1.close;
    aqy2.close;
 ////
    sno:= trim((sender as tedit).hint);
    aqy1.sql.text:='select sexname from per24010 where workno='''+sno+''' and leave=0 ';
    aqy1.open;
    aqy2.sql.text:='select roomkind from rom03010 where roomno='''+trim(combobox1.text)+''' ';
    aqy2.open;
    if (not aqy1.eof) and (not aqy2.eof) then
      if  ((aqy1.fields[0].asstring='男') and (aqy2.fields[0].Asstring='女')) or ((aqy1.fields[0].asstring='女') and (aqy2.fields[0].Asstring='男')) then
        accept:=false;

  end;
  aqy1.close;
  aqy2.close;
  aqy1.free;
  aqy2.free;
end;

procedure Tformroom.ComboBox1Exit(Sender: TObject);
begin
  if not roomnoAt(combobox1) then
    Application.messagebox('没有此宿舍编号','提示',mb_ok+mb_iconinformation)
  else
    combobox1.OnChange(sender);
end;
//判断窗舍编号是否存在
function Tformroom.roomnoAt(sender:Tobject):boolean;
var i:integer;
begin
  for i:=0 to (sender as Tcombobox).Items.Count -1 do
   if trim((sender as tcombobox).Text)=trim((sender as Tcombobox).items[i]) then
     begin
       roomnoAt:=true;
       exit;
     end;
  //(sender as Tcombobox).setfocus;
  roomnoAt:=false;
end;

procedure Tformroom.ComboBox2Exit(Sender: TObject);
begin
  if not roomnoAt(combobox2) then
    Application.messagebox('没有此宿舍编号','提示',mb_ok+mb_iconinformation)
  else
    combobox2.OnChange(sender);
end;

//根据拖放的记录重新产排列数据库rom02010中的员工住宿状况
procedure Tformroom.newbed(sender:Tobject);
var aqy1,aqy2:Tadoquery;
    i,roomcan,s:integer;
    c12s:string;   //c12s是存放combobox1中的宿舍编号和combobox2中的宿舍编号
    edit:tedit;
begin
  s:=0;
  roomcan:=0;  //定义宿舍能住多少人
  c12s:='';
  if sender=combobox2 then  //处理的是combobox1中的宿舍编号
    begin
      s:=28;c12s:=combobox2.Text;    //当调用该过程的参数是combobox2时,就负于它28
    end
  else if sender=combobox1 then
    begin
      s:=0;c12s:=combobox1.text;
    end;
  if c12s='' then exit;   //宿舍编号是空,不向下运行
  aqy1:=Tadoquery.create(application);
  aqy2:=Tadoquery.create(application);
  aqy1.Connection :=datamod.ADOQuery1.Connection;
  aqy2.Connection :=datamod.adoquery1.connection;
  aqy2:=datamod.adoquery1;
  aqy2.sql.clear;
  aqy2.sql.add('select * from rom03010 where roomno='''+c12s+''' ');
  aqy2.open;
  if not aqy2.Eof then
    roomcan:=strtoint(aqy2.fieldbyname('roomcan').asstring);
  aqy2.close;
  if roomcan=0 then
      exit;

  //检查该房间是第一次住人,还是已经住人
  //if not aqy1.eof then后面的语句是处理的是(已经住人的状况),else后面是第一次住人的状况
  aqy1.SQL.Clear;
  aqy1.SQL.add('select * from Vrom02010 where roomno='''+c12s+''' ');
  aqy1.open;
  if not aqy1.Eof then
     for i:=1 to roomcan do
     begin
      datamod.adoquery1.SQL.Clear;
      datamod.adoquery2.sql.Clear;
      edit:=Tedit(findcomponent('edit'+inttostr(i+s))) ;
      with edit do
      begin
       if length(edit.text)>2 then
         if (not aqy1.Locate ('bedno',inttostr(i),[])) then
         //在该宿舍中没有找到此床号,并且现在如果它上面有员工
           datamod.adoquery1.SQL.add('insert rom02010 values('''+aqy1.fieldbyname('roomno').asstring+''','''+inttostr(i)+''','''+edit.hint+''',case when '+inttostr(ord(edit.color))+'=32768 then 1 else 0 end)')
         else
           datamod.adoquery1.sql.Add('update rom02010 set workno='''+edit.hint+''',roomer=case when '+inttostr(ord(edit.color))+'=32768 then 1 else 0 end where roomno='''+aqy1.fieldbyname('roomno').asstring+''' and bedno='''+inttostr(i)+''' ')
       else
         datamod.adoquery2.SQL.Add('delete rom02010 where roomno='''+aqy1.fieldbyname('roomno').asstring+''' and bedno='''+inttostr(i)+''' ');
      end;
       //first
       if datamod.adoquery2.SQL.Text <>'' then   //巳经移走的员工,把它的床位资料删除
         datamod.adoquery2.ExecSQL;
       if datamod.adoquery1.sql.Text <>'' then
         datamod.adoquery1.ExecSQL;
     end
  else       //处理的是第一次住人的状况
    for i:=1 to roomcan do
     begin
       datamod.adoquery1.sql.clear;
       edit:=Tedit(findcomponent('edit'+inttostr(i+s))) ;
       with edit do
       begin
         if length(edit.text)>2 then
           datamod.adoquery1.SQL.add('insert rom02010 values('''+c12s+''','''+inttostr(i)+''','''+edit.hint+''',case when '+inttostr(ord(edit.color))+'=32768 then 1 else 0 end)');
       end;
       if datamod.adoquery1.sql.text<>'' then
          datamod.adoquery1.execsql;
     end;
   aqy1.Close;
end;

procedure Tformroom.n11Click(Sender: TObject);
begin
  Edit1.onDblClick(TEdit(Findcomponent(bname))); //bname是要设置宿舍长的那一个edit的名字
end;

procedure Tformroom.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  IF button=mbright then
    begin
      bname:=(sender as TEdit).name;
      btext:= (sender as TEdit).text;
      if Tedit(findcomponent(bname)).color=clgreen then
        popupmenu1.items[0].Caption:='取消宿舍长'
      else
        popupmenu1.items[0].Caption:='设置宿舍长';
    end;
end;

procedure Tformroom.Edit1DblClick(Sender: TObject);
var i,s:integer;
    bed:Tedit;
    clr:Tcolor;
begin
  clr:=rgb(0,0,0);
  s:=strtoint(copy((sender as tedit).name,5,2));
  if (sender as tedit).color=clgreen then
    if s<29 then
       begin
        (sender as tedit).color:=clyellow;
         exit;
       end
    else if s>=29 then
       begin
        (sender as tedit).color:=clwhite;
        exit;
       end;
  //if (strtoint(copy((sender as tedit).name,5,2))>=1)and (strtoint(copy((sender as tedit).name,5,2))<=28)then
  if s<29 then
    begin
     s:=0;
     clr:=clyellow;
    end
  else if s>29 then
    begin
     s:=28;
     clr:=clwhite;
    end;
  for i:=1 to yedit do  //yedit是存放的这样床位有多少个
  begin
    bed:=Tedit(findcomponent('edit'+inttostr(i+s)));
    with bed do
      begin
        bed.color:=clr;
      end;
  end;
  (sender as tedit).color:=clgreen;
end;


procedure Tformroom.DBGrid3TitleClick(Column: TColumn);
begin
   if f='DESC' then
     f:='ASC'
   else
     f:='DESC';
   datamod.ADOroomnow.Sort :=column.FieldName+' '+f;
end;

procedure Tformroom.oTitleClick(Column: TColumn);
begin
   if f='DESC' then
     f:='ASC'
   else
     f:='DESC';
   datamod.ADOroom1.Sort :=column.FieldName+' '+f;
end;

procedure Tformroom.DBGrid2TitleClick(Column: TColumn);
begin
   if f='DESC' then
     f:='ASC'
   else
     f:='DESC';
   datamod.ADOroom2.Sort :=column.FieldName+' '+f;
end;

procedure Tformroom.tbnsortClick(Sender: TObject);
var i:1..5;
begin
  if manyfield then
   begin
     manyfield:=false;
     tbnsort.hint:='设定多字段排序';
     popupmenu2.Items[0].Enabled :=false;
     popupmenu2.Items[1].Enabled :=false;

⌨️ 快捷键说明

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