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

📄 departselect.pas

📁 一个基于局域网的公司公文管理系统
💻 PAS
字号:
unit departselect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, ComCtrls,GlobalUnit,adodb;

type
  TFrmdepartSel = class(TForm)
    ListView1: TListView;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ListView2: TListView;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    procedure BitBtn2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmdepartSel: TFrmdepartSel;

implementation

{$R *.dfm}

procedure TFrmdepartSel.BitBtn2Click(Sender: TObject);
begin   //"取消"
close;
end;

procedure TFrmdepartSel.Button1Click(Sender: TObject);
var     //">"
Item: TListItem;
Item2: TListItem;
begin
  Item:= ListView1.Selected;
  if (Item<>nil) then
  begin
      Item2:=ListView2.Items.Add;
      Item2.Caption:=Item.Caption;
      Item2.SubItems.Add(Item.SubItems[0]);
      Item.Delete;
  end;
end;

procedure TFrmdepartSel.Button2Click(Sender: TObject);
var  //"<"
Item: TListItem;
Item2: TListItem;
begin
  Item2:= ListView2.Selected;
  if (Item2<>nil) then
  begin
      Item:=ListView1.Items.Add;
      Item.Caption:=Item2.Caption;
      Item.SubItems.Add(Item2.SubItems[0]);
      Item2.Delete;
  end;
end;

procedure TFrmdepartSel.Button3Click(Sender: TObject);
var     //">>"
  Item: TListItem;
   Item2: TListItem;
begin
  Item := ListView1.Selected;
  while Item <> nil do
  begin
      Item2:=ListView2.Items.Add;
      Item2.Caption:=Item.Caption;
      Item2.SubItems.Add(Item.SubItems[0]);
      Item := ListView1.GetNextItem(Item, sdAll, [isSelected]);
  end;
  while ListView1.Selected<>nil do
    ListView1.Selected.Delete;

end;


procedure TFrmdepartSel.Button4Click(Sender: TObject);
var   //"<<"
  Item: TListItem;
   Item2: TListItem;
begin
  Item := ListView2.Selected;
  while Item <> nil do
  begin
      Item2:=ListView1.Items.Add;
      Item2.Caption:=Item.Caption;
      Item2.SubItems.Add(Item.SubItems[0]);
      Item := ListView2.GetNextItem(Item, sdAll, [isSelected]);
  end;
  while ListView2.Selected<>nil do
    ListView2.Selected.Delete;

end;
procedure TFrmdepartSel.BitBtn1Click(Sender: TObject);
var    //"确定"
qrTemp:TAdoQuery;
qrTemp1:TAdoQuery;
ListItem: TListItem;
i:integer;
ii:integer;
tem_uintid:string;
tem_uintname:string;
strSQL:string;
strSQL1:string;
aname:string;
apath:string;
begin
/////////////////////////////////////////////////// 主文件
    strSQL:='delete from ent_file2 where  iindex='+inttostr(iindex)+' and unit_id='+inttostr(unit_id);
    qrTemp:=TAdoQuery.Create(nil);
    qrTemp.Connection :=G_ADOConnection;
    qrTemp.SQL.Clear;
    qrTemp.SQL.Text:=strSQL;
    try
    qrTemp.ExecSQL;
    except
      ShowMessage('主文件表删除不成功!');
    end;
    for i:=0 to  ListView2.Items.Count-1 do
      begin
        tem_uintid:=ListView2.Items[i].Caption;
        tem_uintname:=ListView2.Items[i].SubItems[0];
        strSQL:='insert into ent_file2(unit_id,unit_id2,iindex,title,path, creater,time,iclass,memo) values('+inttostr(unit_id)+','+tem_uintid+','+inttostr(iindex)+','''+ title+''','''+path+''','''+ creater+''','''+datetimetostr(time)+''','+inttostr(iclass)+','''+memo+''')';
        qrTemp.SQL.Clear;
        qrTemp.SQL.Text:=strSQL;
        try
          qrTemp.ExecSQL;
        except
          ShowMessage('主文件表插入数据不成功!');
          close;
        end;
      end;
/////////////////////////////////////////////////// 文件附件
    strSQL:='delete from ent_accessary2 where  iindex='+inttostr(iindex)+' and unit_id='+inttostr(unit_id);
    qrTemp.SQL.Clear;
    qrTemp.SQL.Text:=strSQL;
    try
    qrTemp.ExecSQL;
    except
      ShowMessage('附件表删除不成功!');
    end;
    strSQL1:='select name,path from ent_accessary where  iindex='+inttostr(iindex)+' and unit_id='+inttostr(unit_id);
    qrTemp1:=TAdoQuery.Create(nil);
    qrTemp1.Connection :=G_ADOConnection;
    qrTemp1.SQL.Clear;
    qrTemp1.SQL.Text:=strSQL1;
    try
       qrTemp1.Open;
    except
       close;//关闭
    end;
    if qrTemp1.RecordCount<=0 then
       close;  //关闭
    for i:=0 to  ListView2.Items.Count-1 do
      begin
        tem_uintid:=ListView2.Items[i].Caption;
        tem_uintname:=ListView2.Items[i].SubItems[0];
        try
           qrTemp1.First;
           while not qrTemp1.Eof do
           begin
              aname:=qrTemp1.fieldbyname('name').AsString;
              apath:=qrTemp1.fieldbyname('path').AsString;
              strSQL:='insert into ent_accessary2(unit_id,unit_id2,iindex,name,path) values('+inttostr(unit_id)+','+tem_uintid+','+inttostr(iindex)+','''+ aname+''','''+apath+''')';
              qrTemp.SQL.Clear;
              qrTemp.SQL.Text:=strSQL;
              qrTemp.ExecSQL;
              qrTemp1.Next;
           end;
        except
          ShowMessage('附件表插入数据不成功!');
          close;
        end;
      end;
      close;
end;

procedure TFrmdepartSel.FormShow(Sender: TObject);
var
qrTemp:TAdoQuery;
ListItem: TListItem;
i:integer;
begin
     ListView2.Items.Clear;
     ListView1.Items.Clear;
//////////////////////////////////////////////// 填listview1
    qrTemp:=TAdoQuery.Create(nil);
    qrTemp.Connection :=G_ADOConnection;
    qrTemp.SQL.Text:='select * from ent_unit where unit_id<>'+inttostr(g_unit_id)+' and unit_id not in(select unit_id2 from ent_file2 where  iindex='+inttostr(iindex)+' and unit_id='+inttostr(unit_id)+')';
    qrTemp.Open;
    if qrTemp.RecordCount>0 then
    begin
    qrTemp.First;
    for i:=0 to  qrTemp.RecordCount-1 do
      begin
         ListItem:=ListView1.Items.Add;
         try
            ListItem.Caption:=qrTemp.fieldbyname('unit_id').AsString;
            ListItem.SubItems.Add(qrTemp.fieldbyname('unit_name').AsString);
            qrTemp.Next;
         except
          qrTemp.Close;//
          exit;
         end;
      end;
    end;
//////////////////////////////////////// 填listview2
    qrTemp.Close;
    qrTemp.SQL.Clear;
    qrTemp.SQL.Text:='select * from ent_unit where unit_id in(select unit_id2 from ent_file2 where  iindex='+inttostr(iindex)+' and unit_id='+inttostr(unit_id)+')';
//    ShowMessage(qrTemp.SQL.Text);
    qrTemp.Open;
    if qrTemp.RecordCount>0 then
    begin
    qrTemp.First;
    for i:=0 to  qrTemp.RecordCount-1 do
      begin
         ListItem:=ListView2.Items.Add;
         try
            ListItem.Caption:=qrTemp.fieldbyname('unit_id').AsString;
            ListItem.SubItems.Add(qrTemp.fieldbyname('unit_name').AsString);
            qrTemp.Next;
         except
          qrTemp.Close;//
          exit;
         end;
      end;
    end;
//////////////////////////////////
end;

end.

⌨️ 快捷键说明

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