Xt_Cssds.pas
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit Xt_Cssds;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, DB, DBClient, Grids, DBGridEh, ExtCtrls, StdCtrls, DBCtrlsEh,
  6.   Mask, DBCtrls, Buttons;
  7. type
  8.   TXt_Cssd = class(TForm)
  9.     GroupBox1: TGroupBox;
  10.     Label2: TLabel;
  11.     Label4: TLabel;
  12.     Label35: TLabel;
  13.     Label37: TLabel;
  14.     Label5: TLabel;
  15.     SpeedButton21: TSpeedButton;
  16.     SpeedButton23: TSpeedButton;
  17.     Refresh: TSpeedButton;
  18.     SpeedButton25: TSpeedButton;
  19.     Panel6: TPanel;
  20.     DBGridEh6: TDBGridEh;
  21.     DataSource1: TDataSource;
  22.     ClientDataSet1: TClientDataSet;
  23.     Label3: TLabel;
  24.     DBEditEh1: TDBEditEh;
  25.     DBEditEh3: TDBEditEh;
  26.     DBEditEh5: TDBEditEh;
  27.     DBEditEh2: TDBEditEh;
  28.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  29.     procedure SpeedButton25Click(Sender: TObject);
  30.     procedure RefreshClick(Sender: TObject);
  31.     procedure SpeedButton21Click(Sender: TObject);
  32.     procedure DBEditEh3Exit(Sender: TObject);
  33.     procedure SpeedButton23Click(Sender: TObject);
  34.   private
  35.     { Private declarations }
  36.   public
  37.     { Public declarations }
  38.   end;
  39. var
  40.   Xt_Cssd: TXt_Cssd;
  41. implementation
  42. {$R *.dfm}
  43. procedure TXt_Cssd.FormClose(Sender: TObject; var Action: TCloseAction);
  44. begin
  45.  Clientdataset1.Active:=false;
  46.  Action:=cafree;
  47.  xt_Cssd:=Nil;
  48. end;
  49. procedure TXt_Cssd.SpeedButton25Click(Sender: TObject);
  50. begin
  51.  Close;
  52. end;
  53. procedure TXt_Cssd.RefreshClick(Sender: TObject);
  54. begin
  55.  Clientdataset1.Active:=false;
  56.  Clientdataset1.Active:=true;
  57. end;
  58. procedure TXt_Cssd.SpeedButton21Click(Sender: TObject);
  59. begin
  60.  Clientdataset1.Edit;
  61. end;
  62. procedure TXt_Cssd.DBEditEh3Exit(Sender: TObject);
  63. begin
  64.  if Clientdataset1.FieldByName('lb_dmlx').AsBoolean then
  65.    begin
  66.     if length(DbEditeh3.Text)<>1 then
  67.       begin
  68.        dbediteh3.Text:='';
  69.        application.MessageBox('一级编码'+#13#10+'只能输入一位代码','提示',mb_Ok+mb_iconinformation);
  70.        exit;
  71.       end;
  72.     end;  
  73. end;
  74. procedure TXt_Cssd.SpeedButton23Click(Sender: TObject);
  75. var
  76.   Hint,s_dmgz:string;//提示符
  77.   str,str2:string;//用于接收数据
  78.   tempstr:string;//显示编码规则的字符串
  79.   i,j,tempN,s_lbdmcd:Integer;//s_lbdmcd类别代码长度
  80. begin
  81.    str:=DbEditeh3.Text;
  82.    str2:=Clientdataset1.FieldByName('lbjs_sm').AsString;
  83.    s_dmgz:=Clientdataset1.FieldByName('lb_dmgz').AsString;
  84.    s_lbdmcd:=Clientdataset1.FieldByName('lb_dmcd').AsInteger;
  85.  if trim(DBEditeh3.Text)='' then
  86.    begin
  87.     application.MessageBox('类别说明不能为空','提示',mb_ok+mb_iconinformation);
  88.     Exit;
  89.    end;
  90.   if Clientdataset1.FieldByName('lb_dmlx').AsBoolean then
  91.    begin
  92.    if length(DbEditeh3.Text)<>1 then
  93.      begin
  94.       dbediteh3.Text:=str2;
  95.       application.MessageBox('一级编码'+#13#10+'只能输入一位代码','提示',mb_Ok+mb_iconinformation);
  96.       exit;
  97.      end;
  98.    end;
  99.   //验证是否符合规则
  100.   Clientdataset1.Edit;
  101.   for i:=1 to length(str) do
  102.    begin
  103.     for j:=1 to strToInt(str[i]) do
  104.         tempstr:=tempstr+'#';
  105.      if i<length(str) then
  106.         tempstr:=TempStr+'/';
  107.       DbEditeh5.Text:=tempstr;
  108.       tempN:=tempN+strtoINt(str[i]);
  109.       if tempN>s_lbdmcd then
  110.        begin
  111.          hint:='本类别总长度不能超过'+intToStr(s_lbdmcd);
  112.          application.MessageBox(Pchar(Hint),'提示',mb_Ok+mb_iconinformation);
  113.          Dbediteh3.Text:=str2;
  114.          Dbediteh5.Text:=s_dmgz;
  115.          exit;
  116.        end;
  117.    end;
  118.  if Clientdataset1.ApplyUpdates(0)=0 then
  119.   begin
  120.     application.MessageBox('数据修改成功','提示',mb_ok+mb_iconinformation);
  121.   end
  122.  else
  123.   begin
  124.     application.MessageBox('数据修改失败','提示',mb_ok+mb_iconinformation);
  125.     exit;
  126.   end;
  127. end;
  128. end.