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

📄 wscontrols.pas

📁 Workflow Studio是一款专为商业进程管理(BPM)设计的Delphi VCL框架。通过Workflow Studio你可以轻易地将工作流与BPM功能添加到你的应用程序里。这样能使你或你的最
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  FWorkDefs.Free;
  FTasks.Free;
  inherited;
end;

procedure TTaskListView.UpdateColumns;
begin
  Columns.Clear;
  With Columns.Add do
  begin
    Caption := _str(SColumnKey);
    Width := 40;
  end;
  with Columns.Add do
  begin
    Caption := _str(SColumnName);
    Width := 100;
  end;
  with Columns.Add do
  begin
    Caption := _str(SColumnWorkflow);
    Width := 100;
  end;
  with Columns.Add do
  begin
    Caption := _str(SColumnSubject);
    Width := 220;
  end;
  with Columns.Add do
  begin
    Caption := _str(SColumnStatus);
    Width := 100;
  end;
  with Columns.Add do
  begin
    Caption := _str(SColumnUser);
    Width := 100;
  end;
end;

function TTaskListView.GetSelectedTask: TTaskInstance;
begin
  result := nil;
  if SelCount = 1 then
    result := TaskFromItem(Selected);
end;

procedure TTaskListView.LoadFromDatabase;
var
  AKey: string;
begin
  UpdateDefinitionNames;

  AKey := 'xxx';
  if SelectedTask <> nil then
    AKey := SelectedTask.Key;
  FTasks.Clear; 
  WorkflowStudio.TaskManager.LoadTaskInstanceList(FTasks, FFilterType, FFilterKey, FOnlyCompleted);
  UpdateItems;
  SelectItemByKey(AKey);
end;

procedure TTaskListView.UpdateDefinitionNames;
begin
  WorkflowStudio.WorkflowManager.LoadWorkflowDefinitionList(FWorkDefs);
end;

procedure TTaskListView.SelectItemByKey(AKey: string);
var
  c: integer;
begin
  Selected := nil;
  for c := 0 to Items.Count - 1 do
    if (TaskFromItem(Items[c]) <> nil) and
      (TaskFromItem(Items[c]).Key = AKey) then
    begin
      Selected := Items[c];
      break;
    end;
end;

procedure TTaskListView.SelectItemByTask(ATask: TTaskInstance);
var
  c: integer;
begin
  Selected := nil;
  for c := 0 to Items.Count - 1 do
    if (TaskFromItem(Items[c]) <> nil) and
      (TaskFromItem(Items[c]) = ATask) then
    begin
      Selected := Items[c];
      break;
    end;
end;

function TTaskListView.TaskFromItem(AItem: TListItem): TTaskInstance;
begin
  {$WARNINGS OFF}
  result := TTaskInstance(AItem.Data);
  {$WARNINGS ON}
end;

procedure TTaskListView.UpdateItems;
var
  c: integer;
  ATask: TTaskInstance;
begin
  Items.BeginUpdate;
  try
    {Save the old selected task}
    ATask := SelectedTask;

    {clear and recreate the items}
    Items.Clear;
    for c := 0 to FTasks.Count - 1 do
      UpdateTaskItem(Items.Add, FTasks[c].Task);

    {recover the previously selected workflow definition, if it's the same}
    SelectItemByTask(ATask);
  finally
    Items.EndUpdate;
  end;
end;

procedure TTaskListView.UpdateTaskItem(AItem: TListItem;
  ATask: TTaskInstance);
var
  WorkDef: TWorkflowDefinition;
  AUser: TWorkflowUser;
  AGroup: TWorkflowGroup;
begin
  AItem.Caption := ATask.Key;
  AItem.SubItems.Add(ATask.TaskDef.Name);

  WorkDef := FWorkDefs.FindByKey(ATask.DefinitionKey);
  if WorkDef <> nil then
    AItem.SubItems.Add(WorkDef.Name)
  else
    AItem.SubItems.Add('');

  AItem.SubItems.Add(ATask.TaskDef.Subject);
  AItem.SubItems.Add(ATask.Status);

  {ATask.UserId can be an id for user or group}
  AGroup := WorkflowStudio.UserManager.Groups.FindById(ATask.UserId);
  AUser := WorkflowStudio.UserManager.Users.FindById(ATask.UserID);
  if AGroup <> nil then
    AItem.Subitems.Add(AGroup.GroupName)
  else
  if AUser <> nil then
    AItem.SubItems.Add(AUser.UserName)
  else
    AItem.SubItems.Add(ATask.UserId);

  {$WARNINGS OFF}
  AItem.Data := ATask;
  {$WARNINGS ON}
end;

procedure TTaskListView.Loaded;
begin
  inherited;
  UpdateColumns;
end;

{ TLVAttachmentItems }

procedure TLVAttachmentItems.Update(Item: TCollectionItem);
begin
  if GetOwner is TAttachmentListView then
    TAttachmentListView(GetOwner).UpdateItems;
end;

{ TAttachmentListView }

(*function TAttachmentListView.AddAttachmentItem: TListItem;
var
  NewAttachment: TAttachmentItem;
begin
  FAttachs.BeginUpdate;
  try
    NewAttachment := FAttachs.Add;
    //NewAttachment.Name := FWorkDefs.FindNewName;
  finally
    FAttachs.EndUpdate;
  end;
  SelectItemByAttachment(NewAttachment);
  result := Selected;
end;*)

function TAttachmentListView.AttachmentFromItem(
  AItem: TListItem): TAttachmentItem;
begin
  {$WARNINGS OFF}
  result := TAttachmentItem(AItem.Data);
  {$WARNINGS ON}
end;

constructor TAttachmentListView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FLargeExts := TStringList.Create;
  FLargeImages := TImageList.Create(Self);
  FLargeImages.Width := 32;
  FLargeImages.Height := 32;
  LargeImages := FLargeImages;
  FSmallExts := TStringList.Create;
  FSmallImages := TImageList.Create(Self);
  FSmallImages.Width := 16;
  FSmallImages.Height := 16;
  SmallImages := FSmallImages;
  FAttachs := TLVAttachmentItems.Create(Self);
  MultiSelect := true;
end;

procedure TAttachmentListView.CreateWnd;
begin
  inherited;
  DragAcceptFiles(Handle, FAllowDropFiles);
end;

destructor TAttachmentListView.Destroy;
begin
  FLargeExts.Free;
  FLargeImages.Free;
  FSmallExts.Free;
  FSmallImages.Free;
  FAttachs.Free;
  inherited;
end;

procedure TAttachmentListView.DropMsg(var msg: TWMDropFiles);
const
  Max_Buf = 255;
var
  FileCount: integer;
  i: integer;
  FileBuffer: array[0..Max_Buf] of char;
  FileName : string;
begin
  FileCount := DragQueryFile(Msg.Drop, $FFFFFFFF, nil, 0);

  for i := 0 to FileCount - 1 do
  begin
    //FileName := copy(Files, 0, DragQueryFile(Msg.Drop, i, Files, 255));
    DragQueryFile(msg.Drop, i, FileBuffer, Max_Buf);
    FileName := FileBuffer;
    AddFile(FileName);
    //  Do something
  end;

  msg.Result:=0;
  DragFinish(msg.Drop);
end;

function TAttachmentListView.AddFile(AFileName: string): TAttachmentItem;
begin
  result := nil;
  if FileExists(AFileName) and (FAttachs <> nil) then
  begin
    FAttachs.BeginUpdate;
    try
      result := FAttachs.AddFile(AFileName);
    finally
      FAttachs.EndUpdate;
    end;
    SelectItemByAttachment(result);
  end;
end;

function TAttachmentListView.GetSelectedAttachment: TAttachmentItem;
begin
  result := nil;
  if SelCount = 1 then
    result := AttachmentFromItem(Selected);
end;

procedure TAttachmentListView.SelectItemByAttachment(
  AAttach: TAttachmentItem);
var
  c: integer;
begin
  Selected := nil;
  for c := 0 to Items.Count - 1 do
    if Assigned(AttachmentFromItem(Items[c])) and
      (AttachmentFromItem(Items[c]) = AAttach) then
    begin
      Selected := Items[c];
      break;
    end;
end;

procedure TAttachmentListView.SetAttachments(
  const Value: TAttachmentItems);
begin
  FAttachs.Assign(Value);
end;

procedure TAttachmentListView.UpdateAttachmentItem(AItem: TListItem;
  AAttach: TAttachmentItem);
begin
  AItem.Caption := AAttach.Name;
  {$WARNINGS OFF}
  AItem.Data := AAttach;
  {$WARNINGS ON}
  AItem.ImageIndex := ImageIndexByExt(AAttach.Extension);
end;

function TAttachmentListView.ImageIndexByExt(AExt: string): integer;
var
  i: integer;
  AImageList: TCustomImageList;
  AImageExts: TStrings;
  AIconType: TIconType;
  AIcon: TIcon;
begin
  result := -1;
  Case ViewStyle of
    vsIcon:
      begin
        AImageList := LargeImages;
        AImageExts := FLargeExts;
        AIconType := itLarge;
      end;
    vsSmallIcon, vsList, vsReport:
      begin
        AImageList := SmallImages;
        AImageExts := FSmallExts;
        AIconType := itSmall;
      end;
  else
    Exit;
  end;

  if not Assigned(AImageList) or not Assigned(AImageExts) then
    Exit;

  i := AImageExts.IndexOf(AExt);
  {if it doesn't exist in the list, then add it}
  if i = -1 then
  begin
    AIcon := GetExtIcon(AExt, AIconType);

    (*{set image size if it's the first image}
    if AImageList.Count = 0 then
    begin
      AImageList.Width := AIcon.Width;
      AImageList.Height := AIcon.Height;
    end;*)

    result := AImageList.AddIcon(AIcon);
    AIcon.Free;
  end else
  begin
    {$WARNINGS OFF}
    result := integer(AImageExts.Objects[i]);
    {$WARNINGS ON}
  end;
end;

procedure TAttachmentListView.UpdateItems;
var
  c: integer;
  AAttach: TAttachmentItem;
begin
  if FAttachs <> nil then
  begin
    Items.BeginUpdate;
    try
      {Save the old selected attachment item}
      AAttach := SelectedAttachment;

      {clear and recreate the items}
      Items.Clear;
      for c := 0 to FAttachs.Count - 1 do
        UpdateAttachmentItem(Items.Add, FAttachs[c]);

      {recover the previously selected attachment item, if it's the same}
      SelectItemByAttachment(AAttach);
    finally
      Items.EndUpdate;
    end;
  end;
end;

procedure TAttachmentListView.DeleteSelecteds;
var
  c: integer;
  AList: TObjectList;
begin
  FAttachs.BeginUpdate;
  AList := TObjectList.Create(false);
  try
    for c := 0 to Items.Count - 1 do
      if Items[c].Selected then
        AList.Add(AttachmentFromItem(Items[c]));

    for c := 0 to AList.Count - 1 do
      AList.Items[c].Free;
      //TAttachmentItem(AList[c]).Free;
  finally
    AList.Free;
    FAttachs.EndUpdate;
  end;
end;

procedure TAttachmentListView.Loaded;
begin
  inherited Loaded;
  LargeImages := FLargeImages;
  SmallImages := FSmallImages;
  AdjustColumns;
end;

procedure TAttachmentListView.AdjustColumns;
begin
  Columns.Clear;
  with Columns.Add do
  begin
    Caption := _str(SFileName);
    Width := 150;
    AutoSize := true;
  end;
end;

procedure TAttachmentListView.OpenSelecteds(AllowEdit: boolean);
var
  c: integer;
  TempPath: string;
  Buffer: string;
  Temp: string;
begin
  SetLength(Buffer, MAX_PATH);
  SetLength(Temp, MAX_PATH);
  SetLength(Buffer, GetTempPath(MAX_PATH, PChar(Buffer)));
  GetTempFileName(PChar(Buffer), 'ws', 0, PChar(Temp));
  SetLength(Temp, StrLen(PChar(Temp)));
  TempPath := ChangeFileExt(Temp, '');
  if ForceDirectories(TempPath) then
  begin
    for c := 0 to Items.Count - 1 do
      if Items[c].Selected then
        AttachmentFromItem(Items[c]).Open(AllowEdit, TempPath);
  end;
end;

procedure TAttachmentListView.SetFAllowDropFiles(const Value: boolean);
begin
  FAllowDropFiles := Value;
  if Handle <> 0 then
    DragAcceptFiles(Handle, FAllowDropFiles);
end;

{ TTaskFieldPanel }

⌨️ 快捷键说明

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