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

📄 mainunit.pas

📁 面对纵多的各种各样的资料
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  if not ShowInputFrm(False,s_NodeCaption) then Exit;
  ParentNode:=tv_Main.Selected;
  ParentNodeID:=PInteger(ParentNode.Data)^;
  New(p_NodeId);
  p_NodeId^:=GetAutoNO+1;
  NewNode:=tv_Main.Items.AddChildObject(ParentNode,s_NodeCaption,p_NodeId);
  NewNode.Text:=s_NodeCaption;
  NewNode.ImageIndex:=3;  //先默认为文本文件
  NewNode.SelectedIndex:=3;
  tv_Main.Selected:=NewNode;
  PageControl1.ActivePage:=ts_EditMode;

  //保存数据到treeDir
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('insert into TreeDir(ParentId,NodeCaption,ItemLevel,ItemKind,ItemIndex) ');
  ADOQuery1.SQL.Add('Values(:ParentId,:NodeCaption,:ItemLevel,:ItemKind,:ItemIndex)');
  ADOQuery1.Parameters.ParamByName('ParentId').Value:=IntToStr(ParentNodeID);
  ADOQuery1.Parameters.ParamByName('NodeCaption').Value:=s_NodeCaption;
  ADOQuery1.Parameters.ParamByName('ItemLevel').Value:=IntToStr(ParentNode.Level+1);
  ADOQuery1.Parameters.ParamByName('ItemKind').Value:=ITEM_KIND_TXTFILE;  //默认设置
  ADOQuery1.Parameters.ParamByName('ItemIndex').Value:=tv_Main.Items[tv_Main.Items.Count-1].Index+1;;
  ADOQuery1.ExecSQL;

    //保存数据到SaveFileData
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('insert into SaveFileData(FileId,FileData,FileType) ');
    ADOQuery1.SQL.Add('Values(:FileId,:FileData,:FileType)');
    ADOQuery1.Parameters.ParamByName('FileId').Value:=IntToStr(p_NodeId^);
    ADOQuery1.Parameters.ParamByName('FileData').Value:=Null;
    ADOQuery1.Parameters.ParamByName('FileType').Value:=ITEM_KIND_TXTFILE;
    ADOQuery1.ExecSQL;
    redt_Content.Text:='在这里填写内容,或者从文件到入.';

  ADOQuery1.Close;
end;

procedure TMainFrm.sbtn_OpenClick(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    edt_FileName.Text:=OpenDialog1.FileName;
    if UpperCase(ExtractFileExt(OpenDialog1.FileName))='.TXT' then
    begin
      redt_Content.Lines.LoadFromFile(OpenDialog1.FileName);
      PageControl1.ActivePage:=ts_EditMode;
    end
    else if (UpperCase(ExtractFileExt(OpenDialog1.FileName))='.HTML') or
             (UpperCase(ExtractFileExt(OpenDialog1.FileName))='.HTM') then
    begin
      wb_Content.Navigate(OpenDialog1.FileName);
      PageControl1.ActivePage:=ts_BrowserMode;
    end;
    sbtn_Save.Tag:=SAVE_TAG;
    edt_FileName.Clear;
  end;
end;

procedure TMainFrm.sbtn_SaveClick(Sender: TObject);
begin
  if tv_Main.Selected=nil then
  begin
    CustomDlg('目录树中没有选择与之对应的文件项.');
    Exit;
  end;
  SaveFileData(tv_Main.Selected);
end;

procedure TMainFrm.LoadFileData(ANode: TTreeNode);
var
  s_FileType:String;
  CurNodeId:Integer;
begin
  CurNodeId:=PInteger(ANode.Data)^;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('Select * From SaveFileData ');
  ADOQuery1.SQL.Add('Where FileId="'+IntToStr(CurNodeId)+'"');
  ADOQuery1.Open;
  if ADOQuery1.RecordCount>0 then
  begin
    s_FileType:=ADOQuery1.FieldValues['FileType'];
    if s_FileType=ITEM_KIND_TXTFILE then
    begin
      redt_Content.Clear;
      redt_Content.Text:=ADOQuery1.FieldByName('FileData').AsVariant;
    end;
  end;
end;

procedure TMainFrm.SaveFileData(ANode:TTreeNode);
var
  CurNodeId:Integer;
begin
  CurNodeId:=PInteger(ANode.Data)^;
  ADOQuery1.SQL.Clear;
  ADOQuery1.SQL.Add('Update SaveFileData Set FileData=:FileData,FileType=:FileType ');
  ADOQuery1.SQL.Add('Where FileId="'+IntToStr(CurNodeId)+'"');
  ADOQuery1.Parameters.ParamByName('FileData').Value:=Trim(redt_Content.Text);
  ADOQuery1.Parameters.ParamByName('FileType').Value:=ITEM_KIND_TXTFILE;
  ADOQuery1.ExecSQL;
  sbtn_Save.Enabled:=False;
end;

procedure TMainFrm.redt_ContentChange(Sender: TObject);
begin
  sbtn_Save.Enabled:=True;
end;

procedure TMainFrm.DisplayTxtToWB(AStr: String);
var
  //v: Variant;
  //HTMLDocument: IHTMLDocument2;
  s_HtmlSource:String;
begin
  {HTMLDocument := wb_Content.Document as IHTMLDocument2;
  v := VarArrayCreate([0, 0], varVariant);
  v[0] := AStr; // Here's your HTML string
  HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
  HTMLDocument.Close;}
  s_HtmlSource:='<html><head></head><body topmargin="0">';
  s_HtmlSource:=s_HtmlSource+'<table width="100%" height="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#0099FF" bordercolorlight="#0099FF"><tr><td bgcolor="#0099FF" height="20">';
  //显示标题
  s_HtmlSource:=s_HtmlSource+'标题为:'+tv_Main.Selected.Text;
  s_HtmlSource:=s_HtmlSource+'</td></tr><tr><td valign="top">';
  s_HtmlSource:=s_HtmlSource+'<pre>';
  s_HtmlSource:=s_HtmlSource+AStr;
  s_HtmlSource:=s_HtmlSource+'</pre>';
  s_HtmlSource:=s_HtmlSource+'</td></tr><tr><td bgcolor="#0099FF" height="20"><div align="center">CopyRight &copy; <a href="mailto:jacky_kch@etang.com">Jackiekuang</a>.</div></td></tr>';
  s_HtmlSource:=s_HtmlSource+'</table></body></html>';
  ProductWebPage(wb_Content,s_HtmlSource);
end;

procedure TMainFrm.sbtn_DeleteClick(Sender: TObject);
  procedure DelAllItem(ANode:TTreeNode);
  var
    i,NodeId:Integer;
    TempNode:TTreeNode;
  begin
    TempNode:=nil;
    for i:=0 to ANode.Count-1 Do
    begin
      if i=0 then
        TempNode:=ANode.getFirstChild
      else
        TempNode:=ANode.GetNextChild(TempNode);
      DelAllItem(TempNode);
    end;
    NodeId:=PInteger(ANode.Data)^;
    if IsDocNode(ANode) then
    begin
      ADOQuery1.SQL.Clear;
      ADOQuery1.SQL.Add('Delete From SaveFileData');
      ADOQuery1.SQL.Add('Where FileId="'+IntToStr(NodeId)+'"');
      ADOQuery1.ExecSQL;
    end;

    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('Delete From TreeDir');
    ADOQuery1.SQL.Add('Where Id='+IntToStr(NodeId));
    ADOQuery1.ExecSQL;
    ADOQuery1.Close;
  end;
begin
  if tv_Main.Selected=nil then Exit;
  if MessageBox(handle,PChar('确定要删除标签为:'+tv_Main.Selected.Text+'的节点吗?'),PChar('PDC提示你'),MB_YESNO+MB_ICONINFORMATION)=ID_YES then
  begin
    DelAllItem(tv_Main.Selected);
    tv_Main.Selected.Delete;
  end;
end;

function TMainFrm.IsDocNode(ANode: TTreeNode):Boolean;
var
  i_ImageIndex:Integer;
begin
  Result:=False;
  i_ImageIndex:=ANode.ImageIndex;
  if (i_ImageIndex=0) or (i_ImageIndex=1) then
  begin
    Result:=False;
  end
  else if (i_ImageIndex=2) or (i_ImageIndex=3) then //删除一个文件及关联
  begin
    Result:=True;
  end;
end;

procedure TMainFrm.sbtn_AboutClick(Sender: TObject);
begin
  ABoutFrm:=TABoutFrm.Create(Self);
  AboutFrm.ShowModal;
end;

procedure TMainFrm.ProductWebPage(const WebBrowser: TWebBrowser;
  const Html: string);
var
  Stream: IStream;
  hHTMLText: HGLOBAL;
  psi: IPersistStreamInit;
begin
  if not Assigned(WebBrowser.Document) then Exit;

  hHTMLText := GlobalAlloc(GPTR, Length(Html) + 1);
  if 0 = hHTMLText then RaiseLastWin32Error;
  CopyMemory(Pointer(hHTMLText),PChar(Html), Length(Html));
  OleCheck(CreateStreamOnHGlobal(hHTMLText, True, Stream));
  try
    OleCheck(WebBrowser.Document.
    QueryInterface(IPersistStreamInit, psi));
    try
      OleCheck(psi.InitNew);
      OleCheck(psi.Load(Stream));
    finally
      psi := nil;
    end;
  finally
    Stream := nil;
  end;
end;

procedure TMainFrm.DisplayWelToWB;
var
  s_HtmlSource:String;
begin
  s_HtmlSource:='<html><head></head><body topmargin="0">';
  s_HtmlSource:=s_HtmlSource+'<table width="85%" height="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#0099FF" bordercolorlight="#0099FF"><tr><td bgcolor="#0099FF" height="20">';
  //显示标题
  s_HtmlSource:=s_HtmlSource+'目录为:'+tv_Main.Selected.Text;
  s_HtmlSource:=s_HtmlSource+'</td></tr><tr><td>';
  s_HtmlSource:=s_HtmlSource+'<div align="center"><font color="#0000FF">';
  s_HtmlSource:=s_HtmlSource+'欢迎使用个人收集.';
  s_HtmlSource:=s_HtmlSource+'</font></div>';
  s_HtmlSource:=s_HtmlSource+'</td></tr><tr><td bgcolor="#0099FF" height="20"><div align="center">CopyRight &copy; <a href="mailto:jacky_kch@etang.com">Jackiekuang</a>.</div></td></tr>';
  s_HtmlSource:=s_HtmlSource+'</table></body></html>';
  ProductWebPage(wb_Content,s_HtmlSource);
end;

procedure TMainFrm.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePageIndex=0 then
  begin
    DisplayTxtToWB(redt_Content.Text);
  end;
end;

procedure TMainFrm.sbtn_BoldClick(Sender: TObject);
begin
  if redt_Content.SelText='' then Exit;
  if (Sender as TSpeedButton).Name='sbtn_Bold' then
  begin
    redt_Content.SelText:='<B>'+redt_Content.SelText+'</B>';
  end
  else if (Sender as TSpeedButton).Name='sbtn_Italic' then
  begin
    redt_Content.SelText:='<I>'+redt_Content.SelText+'</I>';
  end
  else if (Sender as TSpeedButton).Name='sbtn_Underline' then
  begin
    redt_Content.SelText:='<U>'+redt_Content.SelText+'</U>';
  end;
end;

procedure TMainFrm.sbtn_CutClick(Sender: TObject);
begin
  if (Sender As TSpeedButton).Name='sbtn_Cut' then
  begin
    redt_Content.CutToClipboard;
  end
  else if (Sender As TSpeedButton).Name='sbtn_Copy' then
  begin
    redt_Content.CopyToClipboard;
  end
  else if (Sender As TSpeedButton).Name='sbtn_Paste' then
  begin
    redt_Content.PasteFromClipboard;
  end;
end;

procedure TMainFrm.sbtn_SelAllClick(Sender: TObject);
begin
  redt_Content.SetFocus;
  redt_Content.SelectAll;
end;

procedure TMainFrm.sbtn_InsertTimeClick(Sender: TObject);
begin
  redt_Content.SelText:=DateToStr(Now())+' '+FormatDateTime('t',Now())+' '+GetWeekday(Now());
end;

function TMainFrm.GetWeekday(ADateTime:TDateTime): String;
var
  i_WeekNumber:Integer;
  s_WeekStr:String;
begin
  Result:='';
  i_WeekNumber := DayOfWeek(ADateTime);  // 获得星期几的信息
  case i_WeekNumber of
        1 :  s_WeekStr:= '星期天';
        2 :  s_WeekStr:= '星期一';
        3 :  s_WeekStr:= '星期二';
        4 :  s_WeekStr:= '星期三';
        5 :  s_WeekStr:= '星期四';
        6 :  s_WeekStr:= '星期五';
        7 :  s_WeekStr:='星期六';
  end;
  Result:=s_WeekStr;
end;



procedure TMainFrm.AdjustForm;
begin
  //控件适应;
  scaled := true;
  if (screen.width <> ScreenWidth) then

  begin
    height := longint(height) * longint(screen.height) DIV ScreenHeight;
    width := longint(width) * longint(screen.width) DIV ScreenWidth;
    scaleBy(screen.width, ScreenWidth);
  end;
  //字体适应
  {for i := componentCount - 1 downto 0 do
  begin
    with components[i] do
    begin
      if GetPropInfo(ClassInfo, 'font') <> nil  then
        font.size := (NewFormWidth DIV OldFormWidth) * font.size;
    end;
  end;}
end;

procedure TMainFrm.WMSysCommand(var Message: TMessage);
begin
  if Message.WParam = SC_ICON then  //最小化了
  begin
    Hide;
  end
  else
    inherited;
end;

procedure TMainFrm.LoadSysTray;
var
  nid: TNotifyIconData;
begin
  nid.cbSize := sizeof(nid); // nid变量的字节数
  nid.Wnd := Handle; // 主窗口句柄
  nid.uID := 0; // 内部标识,可设为任意数
  nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?
  nid.hIcon := Application.Icon.Handle; // 要加入的图标句柄,可任意指?

  nid.szTip := 'PDC个人资料收藏软件'; // 提示字符串
  nid.uCallbackMessage := WM_IconMessage; // 回调函数消息
  nid.uFlags := NIF_ICON or NIF_TIP or NIF_MESSAGE; // 指明哪些字段有?
  //将程序的窗口样式设为TOOL窗口,可避免在任务条上出现
  SetWindowLong(Application.Handle, GWL_EXSTYLE, WS_EX_TOOLWINDOW);
  if not Shell_NotifyIcon(NIM_ADD, @nid) then begin
    MessageBox(handle,PChar('托盘图标加载失败!'),PChar('PDC提示你'),MB_OK+MB_ICONINFORMATION);
    Application.Terminate;
  end;
end;

procedure TMainFrm.OnIconNotify(var Message: TMessage);
begin
  if Message.LParam=WM_LBUTTONDOWN then
  begin
    //ShowWindow(Application.Handle, SW_SHOW);
    MainFrm.Show;
    application.BringToFront;
  end;
end;

procedure TMainFrm.DelSysTray;
var
  nid: TNotifyIconData;
begin
  nid.cbSize := sizeof(nid); // nid变量的字节数
  nid.uID := 0; //内部标识,与加入小图标时的数一致
  nid.Wnd := Handle; //主窗口句柄
  Shell_NotifyIcon(NIM_DELETE, @nid); //去掉小图标
end; 


procedure TMainFrm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  DelSysTray;
end;

procedure TMainFrm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (ssCtrl in Shift) and (Key=67)  then
  begin
    if tv_Main.Selected=nil then
    begin
      CustomDlg('目录树中没有选择与之对应的文件项.');
      Exit;
    end;
    SaveFileData(tv_Main.Selected);
  end;
end;

end.

⌨️ 快捷键说明

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