简单的东东

×TREEVIEW中取子节以上所有节点
  var
 st:string ;
 node:TTreeNode;
begin
  st:='' ;
  node := TreeV.Selected ;
  if not assigned(node) then
   exit ;
  while assigned(node) do
  begin
    st:='/'+node.Text+st ;
    node:=node.Parent ;
  end ;

********************************************************************
读写注册表

USES registry


procedure TMain_frm.FormCreate(Sender: TObject);
var
  Reg:TRegistry;
begin
   Reg:=TRegistry.Create;
   try
     Reg.RootKey:=HKEY_LOCAL_MACHINE;
     Reg.OpenKey('/Software/Snd/newsfxt',True);
     edtServerName.Text:=Reg.ReadString('ServerName');

     if Reg.ReadString('DataBaseName')<>'' then
       edtDataBaseName.Text:=Reg.ReadString('DataBaseName')
     else
       edtDataBaseName.Text:='newsfxt';

     edtUserName.Text:=Reg.ReadString('UserName');
     //edtPassWord.Text:=Reg.ReadString('PassWord');
     edtBackupPath.Text:=Reg.ReadString('BackupPath');
   finally
      Reg.Free;
   end;
end;

procedure TMain_frm.BitBtn1Click(Sender: TObject);
var
  Reg:TRegistry;
begin
  Reg:=TRegistry.Create;
  try
   Reg.RootKey:=HKEY_LOCAL_MACHINE;
   Reg.OpenKey('/Software/Snd/newsfxt',True);
   Reg.WriteString('ServerName',Trim(edtServerName.Text));
   Reg.WriteString('DataBaseName',Trim(edtDataBaseName.Text));
   Reg.WriteString('UserName',Trim(edtUserName.Text));
   if Trim(edtPassWord.Text)<>'' then
     Reg.WriteString('PassWord',Trim(edtPassWord.Text));
   Reg.WriteString('BackupPath',Trim(edtBackupPath.Text));
  finally
    Reg.Free;
  end;
  MessageDlg('设置成功!', mtInformation, [mbOK], 0);
  edtServerName.SetFocus;
end;

*************************************************************************

Close;
    SQL.Clear;
    SQL.Add('if not Exists (Select * from AdjustPay where did=:did and banc=:banc and date1=:date1)');
    SQL.Add('  insert Adjustpay (Pay,did,banc,date1) values (:pay,:did,:banc,:date1)');
    SQL.Add('else');
    SQL.Add('  Update AdjustPay set Pay=:Pay where did=:did and banc=:banc and date1=:date1');


*******************************************************************************
时间分解成年月日

DecodeDate(Now,ThisYear,CountMonth,CountDay);


*******************************************************************************
简单加密

const
  XorKey:array[0..7] of Byte=($B2,$09,$AA,$55,$93,$6D,$84,$47);
function Enc(Str:String):String;
var
  i,j:Integer;
begin
  Result:='';
  j:=0;
  for i:=1 to Length(Str) do
  begin
    Result:=Result+IntToHex(Byte(Str[i]) xor XorKey[j],2);
    j:=(j+1) mod 8;
  end;
end;
function Dec(Str:String):String;
var
  i,j:Integer;
begin
  Result:='';
  j:=0;
  for i:=1 to Length(Str) div 2 do
  begin
    Result:=Result+Char(StrToInt('$'+Copy(Str,i*2-1,2)) xor XorKey[j]);
    j:=(j+1) mod 8;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject); //加密
begin
  Edit2.Text:=Enc(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject); //解密
begin
  Edit3.Text:=Dec(Edit2.Text);
end;

********************************************************************************
权限控制

procedure TMainForm.FormShow(Sender: TObject);
var
  i,j:integer ;
  MFList:TStringList;
begin
  MFList:=TStringList.Create;
  MFList.Add('ddPeople');
  MFList.Add('SearchPeople');
  MFList.Add('AddLeave');
  MFList.Add('AddHoliday');
  MFList.Add('SendCard');
  MFList.Add('Communicate');
  MFList.Add('CountCard');
  MFList.Add('SearchCard');
  MFList.Add('ReadData');
  MFList.Add('DiapData');
  MFList.Add('EditChuqjl');
  MFList.Add('CountGWCQ');
  MFList.Add('CountYGCQ');
  MFList.Add('CountQX');
  MFList.Add('SearchChuqjl');
  MFList.Add('SearchNightR');
  MFList.Add('SearchBG');
  MFList.Add('ExchangeData');
  MFList.Add('CountDiao');
  MFList.Add('SearchDiao');
  MFList.Add('SetCalss');
  MFList.Add('SetNigth');
  MFList.Add('SetGW');
  MFList.Add('SetDingY');
  MFList.Add('SetShuak');
  MFList.Add('CanIni');
  MFList.Add('SetCOmm');
  MFList.Add('ChargeUser');
  MFList.Add('DBmaintain');

  with DM.ChangeQuery do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from kqxtpassword where id='+IntToStr(UserID));
    Open;
  end;


  for i:=0 to MainMenu.Items.Count-1 do
  begin
    for j:=0 to MainMenu.Items[i].Count-1 do
    begin
      if MainMenu.Items[i].Items[j].tag<99 then
        MainMenu.Items[i].Items[j].Visible:=
          DM.ChangeQuery.FieldByName(MFList.Strings[MainMenu.Items[i].Items[j].tag]).AsBoolean;
    end;
  end ;

  for i:=0 to ToolBar.ButtonCount-1 do
  begin
    if ToolBar.Buttons[i].Tag<90 then
      ToolBar.Buttons[i].Visible:=
        DM.ChangeQuery.FieldByName(MFList.Strings[ToolBar.Buttons[i].Tag]).AsBoolean;
  end;
******************************************************************************
select case的使用  

SELECT DISTINCT
      dutytype.dutyname, (CASE yuangxx.nightclassid WHEN - 1 THEN '无' ELSE
          (SELECT DISTINCT nightclass.name
         FROM nightclass
         WHERE nightclass.id = yuangxx.nightclassid) END) AS Expr1,
      iccard.iccardno AS Expr2, iccard.RiceFen AS Expr3, Yuangxx.*
FROM Yuangxx INNER JOIN
      iccard ON Yuangxx.ID = iccard.did INNER JOIN
      DutyType ON DutyType.ID = Yuangxx.DutyID
*******************************************************************************
修改表的列名
EXEC sp_rename 'gongsxx.[title]', 'bz', 'COLUMN'
                 表名    原列名  现列名  修改的是列

*************************************************************************************
取得员工对应的班次的ID
IF (SELECT banc FROM yuangxx WHERE id = 2) = - 1
    SELECT class.id FROM class, yuangxx, TGanW WHERE TGanW.ID_Banmc = class.id
 AND TGanW.did = yuangxx.did AND yuangxx.id = 2
ELSE
    SELECT class.ID FROM TGanW INNER JOIN Yuangxx ON TGanW.Did = Yuangxx.Did INNER JOIN
 class ON Yuangxx.BanC = class.subidx AND TGanW.ID_Banmc = class.parent AND yuangxx.id = 2

**************************************************************************************
在SQL语名内使用事务
 with DMForm.CountQuery do
  begin                                    //产量工资
    Close;                    //修改新老员工工资
    SQL.Clear;
    SQL.Add('declare @err int');
    SQL.Add('BEGIN TRAN');
    SQL.Add('UPDATE GZ SET IS_NEW=IS_NEW-'+FieldName
      +' WHERE DID=:DID AND BANC=:Banc AND DATE1=:Date1 '
      +' SELECT @ERR=@@ERROR '
      +' IF @ERR!=0 '
      +' BEGIN '
      +'   ROLLBACK TRAN '
      +'   RETURN '
      +' END ');
    SQL.Add('UPDATE GZ SET '+FieldName+'=0 WHERE DID=:DID AND BANC=:Banc AND DATE1=:Date1 '
      +' SELECT @ERR=@@ERROR '
      +' IF @ERR!=0 '
      +' BEGIN '
      +'   ROLLBACK TRAN '
      +'   RETURN '
      +' END ');
    SQL.Add('Update cbgz set '+FieldName+'=0 where did=:DID and Banc=:Banc and Date1=:Date1 '
      +' SELECT @ERR=@@ERROR '
      +' IF @ERR!=0 '
      +' BEGIN '
      +'   ROLLBACK TRAN '
      +'   RETURN '
      +' END ');
    SQL.Add('COMMIT TRAN ');
    paramByName('DID').AsInteger:=InputTable.FieldByName('gwh').AsInteger;
    ParamByName('Banc').AsInteger:=InputTable.FieldByName('banc').AsInteger;
    ParamByName('Date1').AsString:=DateTmp;
    ExecSQL;
**************************************************************************************
修改同一SQLSERVER上的另一数据库(YGGL)的表是在其前面加上YGGL..就可以访问不必另建连接


修改列的类型
exec YGGL..sp_columns @table_name = 'MeirCqjl', @column_name = 'KaoqXZID'
 if @@rowcount > 0
 alter table YGGL..MeirCqjl alter column KaoqXZID [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
GO
修改列名
exec YGGL..sp_columns @table_name = 'MeirCqjl', @column_name = 'KaoqXZID'
 if @@rowcount > 0
 EXEC YGGL..sp_rename 'MeirCqjl.[KaoqXZID]', 'KaoqXZ', 'COLUMN'
************************************************************************************
在SQL SERVER 的SQL语句中格式化日期

返回'MM'类型的月份
select substring(convert(char(10),getdate(),20),6,2)

返回'YYYY-MM-DD'类型的字符串
select convert(char(10),getdate(),20)

************************************************************************************
宁振单位目录树整休复制到同一节点下


复制全部节点到一目录下
---------------------------
信使服务
---------------------------
在 2004-11-17 15:11:27 从 SNDCFR 到 JAUNY 的消息

declare @MaxID integer

select @MaxID = Max(ID) from danwjgs

insert into danwjgs (

ID, Parent, subidx, name, f_key, f_val, chejianno

) select @MaxID + ID

, case parent when 0 then 0                    //到某一节点则将when 0 then 0改成when 0 then 节点ID

 else @MaxID + parent end,

 subidx, name, f_key, f_val, chejianno

 from danwjgs


---------------------------
确定  
---------------------------

复制全部节点到一目录下,并复制班次(好像有点问题)
---------------------------
信使服务
---------------------------
在 2005-1-26 8:54:47 从 SNDCFR 到 JAUNY 的消息

declare @MaxID integer

select @MaxID = Max(ID) from danwjgs

insert into danwjgs (

ID, Parent, subidx, name, f_key, f_val, chejianno

) select @MaxID + ID

, case parent when 0 then 335

 else @MaxID + parent end,

 subidx, name, f_key, f_val, chejianno

 from danwjgs

insert into tganw (

ID, Did, DingYS, ID_Banmc, AnSSB, AnSXB, ZhiDKQ, CheJGW

, ChangePay, CountFP, PayMode, effect_min, Late_min

, Once_min, AutoTime, GWCharacter, HLevel

)

select ID + @MaxID, case Did when 0 then 0 else Did + @MaxID end

, DingYS, ID_Banmc, AnSSB, AnSXB, ZhiDKQ, CheJGW, ChangePay

, CountFP, PayMode, effect_min, Late_min, Once_min

, AutoTime, GWCharacter, HLevel

 from tganw


---------------------------
确定  
---------------------------

阅读更多

没有更多推荐了,返回首页