打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
如何建立通用控件类
unit hxcancelfrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, DB, ADODB, cxPlatformTypes,Menus,cxDBUtils, 
  Dialogs, StdCtrls, cxDialogs, cxQuery, cxRuntimecore, cxCore, cxSysUtils, cxModuleBaseFrm, comobj, cxShellApi,cxshellcombobox,cxCheckComboBox, ExtCtrls, ComCtrls, cxListView,cxTL,cxCheckBox,cxRadioGroup,cxTrackBar,cxCalendar;
type
 TControlClass =class of TControl;
  TControlFactory=class
  public
   
  class function createControlObj(AOwner:TWinControl ;ControlClass:TControlClass;left,top,width,height:integer):TControl;
  end;  
  
  Thxcancelfrm = class(TObject)
  private
 
   phtlis,modals:tstringlist;
    CombBox1,CombBox2:tcombobox;
    listbox1:tlistbox;  
//    checklistbox1:tchecklistbox;
    edit1:tedit; 
    date1:tdatetimepicker; 
    memo1:tmemo;
    btnOK,btnCancel:tbutton;
    frmInfo:tform;
    flabel1,flabel2,flabel3,flabel4,flabel5:tlabel;   
    tmp :tcxquery; 
    CheckComBox1:tcxCheckComboBox;
    wxht,wxhtstr:string;
    number,frecordid,fmodule:string;
  procedure createdWindow(var frm:tform;text:string;left:integer;top:integer;width:integer;height:integer); 
   procedure FreeInfoWindow;
 // procedure createdGrid(var frm: TWincontrol;var grid:tcxtreelist;left,top,width,height:integer;ColunmList,ColunmWidth:tstringlist);  
  //procedure createdGrid(var frm: TWincontrol; var grid: TcxlistView; left: integer; top: integer; width: integer; height: integer; ColunmList: tstringlist; ColunmWidth: tstringlist);
  procedure createdLabel(var frm: TWincontrol;var flabel:tlabel;text:string;left:integer;top:integer);
 procedure  createdDate(var frm: TWincontrol;var fdate:tdatetimepicker;left,top,width,height:integer);
  procedure createdEdit(var frm: TWincontrol;var fedit:tedit;left:integer;top:integer;width:integer;height:integer;dauf:string);
   procedure createdmemo(var frm: TWincontrol;var fedit:tmemo;left:integer;top:integer;width:integer;height:integer;dauf:string); 
  //procedure createdComBox(var frm: TWincontrol;var combox:tcombobox;left:integer;top:integer;width:integer;height:integer;itmlst:tstringlist); 
 procedure createdButton(var frm: TWincontrol;var btn:tbutton;text:string;left:integer;top:integer;width:integer;height:integer;event: TNotifyEvent);
    
  //procedure createdStatusBar(var frm: TWincontrol;var StatusBar:tStatusBar);   
  //procedure createProgressBar(var frm: TWincontrol;var Progress:tProgressBar;left:integer;top:integer;width:integer;height:integer;max:integer);
  procedure  begined(sender:tobject); 
  procedure  getParamsByInput;
  procedure  canceled(sender:tobject);
  //procedure  cmbDataSourceChange(Sender: TObject);
 
  public
    //constructor Create;override;
   // destructor Destroy; override;
    procedure  InitionInfoWindow(capital: string);
   // procedure DoImport(Module: string; ZdzName: string = '');
  end;  
  
  procedure sendmessageData(userlist:tstringlist;messagetext,recordid,modulename:string); 
  
  
implementation       
 procedure sendmessageData(userlist:tstringlist;messagetext,recordid,modulename:string);
var i, j: integer;
str1:string;
begin
 
  with Thxcancelfrm.create do
  begin
   modals:=userlist; 
  tmp:=tcxquery.create(nil);

  if modulename<>'' then fmodule:=modulename;

 //wxht:=tmp.fieldbyname('order_id').asstring; 
  
 
 
 frecordid:=recordid; 
 
 wxhtstr:=messagetext; 
 
   
  
 InitionInfoWindow(modulename);   

 FreeInfoWindow;  
 modals.free;
 //if tmp.open then tmp.close;
 tmp.free;  
  end;   
end;  
 
  class function TControlFactory.createControlObj(AOwner:TWinControl ;ControlClass:TControlClass;left,top,width,height:integer):TControl;
var
  FControlObj:TControl;
begin
  FControlObj:=ControlClass.Create(AOwner);
  FControlObj.Parent:=AOwner;
  //FControlObj.Name:=FControlObj.ClassName;
  FControlObj.SetBounds(left,top,width,height);
  result:=FControlObj;
end;





  procedure Thxcancelfrm.createdWindow(var frm:tform;text:string;left:integer;top:integer;width:integer;height:integer);
  begin
    frm:=tform.create(application);
    frm.height:=height;
    frm.width:=width;
    frm.position:=poScreenCenter; 
    //frm.top:=top;
    //frm.left:=left;       
    frm.borderstyle:=bsDialog;
    frm.formstyle:=fsStayOnTop;
    frm.caption:=text;
  end;   
{procedure Thxcancelfrm.createdGrid(var frm: TWincontrol; var grid: TcxlistView; left: integer; top: integer; width: integer; height: integer; ColunmList: tstringlist; ColunmWidth: tstringlist);
var ind: integer;
begin
  grid := TcxlistView.Create(frm);
  grid.Parent := frm;
  grid.top := top;
  grid.left := left;
  grid.Height := height;
  grid.Width := width;

  for ind := 0 to ColunmList.Count - 1 do
  begin
    grid.Columns.Add;
    grid.Columns.Items[ind].Caption := ColunmList.Strings[ind];
    grid.Columns.Items[ind].Width := strtoint(ColunmWidth.Strings[ind]);
  end;
  grid.ViewStyle := vsReport;
  grid.RowSelect := true;
end; }

procedure Thxcancelfrm.createdLabel(var frm: TWincontrol;var flabel:tlabel;text:string;left:integer;top:integer);
  begin
     flabel:=tlabel.Create(frm);
     flabel.Parent:=frm;
     flabel.top:=top;
     flabel.left:=left;
     flabel.Font.Name:='宋体';
     flabel.Font.Size:=9;
     flabel.Caption:=text;
     //flabel.autosize;
  end; 
  procedure Thxcancelfrm.createdDate(var frm: TWincontrol;var fdate:tdatetimepicker;left,top,width,height:integer);
  begin
     fdate:=tdatetimepicker.Create(frm);
     fdate.Parent:=frm;
     fdate.top:=top;
     fdate.left:=left;
     fdate.Width:=width;
     fdate.height:=height;
     fdate.Date:=now;   
     
     //flabel.autosize;
  end;
procedure Thxcancelfrm.createdEdit(var frm: TWincontrol;var fedit:tedit;left:integer;top:integer;width:integer;height:integer;dauf:string);
  begin
     fedit:=tedit.Create(frm);
     fedit.Parent:=frm;
     fedit.top:=top;
     fedit.left:=left;
     fedit.Height:=height;
     fedit.Width:=width;
     fedit.Hint:=dauf;
     fedit.ShowHint:=true;   
     fedit.Text:=dauf;
  end; 
  procedure Thxcancelfrm.createdmemo(var frm: TWincontrol;var fedit:tmemo;left:integer;top:integer;width:integer;height:integer;dauf:string);
  begin
     fedit:=tmemo.Create(frm);
     fedit.Parent:=frm;
     fedit.top:=top;
     fedit.left:=left;
     fedit.Height:=height;
     fedit.Width:=width;
     fedit.Hint:=dauf;
     fedit.ShowHint:=true;   
     fedit.Text:=dauf;
  end;

procedure Thxcancelfrm.createdButton(var frm: TWincontrol;var btn:tbutton;text:string;left:integer;top:integer;width:integer;height:integer;event: TNotifyEvent);
  begin
     btn:=tbutton.Create(frm);
     btn.Parent:=frm;
     btn.top:=top;
     btn.left:=left;
     btn.Height:=height;
     btn.Width:=width;
     btn.Caption:=text;
     btn.OnClick := event;
  end;


 procedure Thxcancelfrm. InitionInfoWindow(capital: string); 
  begin
     // createdWindow(frmInfo,capital,380,200);   
     
      createdWindow(frmInfo,capital+'取消界面',30,180,380,200); 
       flabel1:=Tlabel(TControlFactory.createControlObj(frmInfo,Tlabel,10,20,100,10));
       
       flabel1.Caption:= '请选择取消日期:';
       
       date1:=tdatetimepicker(TControlFactory.createControlObj(frmInfo,tdatetimepicker,flabel1.left+flabel1.Width+10,flabel1.top,220,20)); 
       //showmessage('0');
       flabel2:=Tlabel(TControlFactory.createControlObj(frmInfo,Tlabel,flabel1.left,flabel1.top+flabel1.height+20,10,10));
       flabel2.Caption:='请输入取消原因:';
       CombBox1:=Tcombobox(TControlFactory.createControlObj(frmInfo,Tcombobox,flabel2.left,flabel2.top+flabel2.height+20,flabel2.width,20));
       combbox1.Items.add('11');
        combbox1.Items.add('22'); 
        combbox1.ItemIndex:=0;
        memo1:=Tmemo(TControlFactory.createControlObj(frmInfo,Tmemo,date1.left,50,date1.Width,80)); 
         createdButton(frmInfo,btnOK,'确    定',80,150,60,20,begined);  
      
      createdButton(frmInfo,btnCancel,'取    消',230,150,60,20,canceled);
     { createdLabel(frmInfo,flabel1,'请选择取消日期:',10,20); 
      
    
      createdDate(frmInfo,date1,flabel1.left+flabel1.Width+10,flabel1.top,220,20);
       
      createdLabel(frmInfo,flabel2,'请输入取消原因:',flabel1.left,flabel1.top+flabel1.height+20);  
      createdmemo(frmInfo,memo1,date1.left,flabel2.top,date1.Width,80,'');
      createdButton(frmInfo,btnOK,'确    定',80,150,60,20,begined);  
      
      createdButton(frmInfo,btnCancel,'取    消',230,150,60,20,canceled); }
     
      frmInfo.ShowModal;
  end;    
procedure  Thxcancelfrm.begined(sender:tobject);
 var AIndex:integer;
 InTimeMessage:string;
  MSGFont: TFont;
  rq:tdatetime;
  str,maintable:string; 
  tmp:tcxquery; 
  i,j,k:integer; 
  flist,subtable,subsql:tstringlist;
 begin
   //etParamsByInput;
   subtable:=tstringlist.Create;
   subsql:=tstringlist.Create;  
   flist:=tstringlist.create;
   rq:=strtodate(formatdatetime('yyyy-mm-dd',date1.Date));
   //str:=memo1.Text; 
   tmp:=tcxquery.Create(nil); 
    maintable:=IProject.ModuleByName(fmodule).TableName; 
   if (rq>strtodate('1900-01-01')) and  (memo1.Text<>'')   then
   begin 
       showmessage(datetostr(rq));
       showmessage(memo1.Text);
       { for j:=0 to  IProject.ModuleByName(fmodule).FieldGroups.count-1 do
          begin
           if  IProject.ModuleByName(fmodule).FieldGroups.Items[j].IsTable=false    then
              for i:=0 to IProject.ModuleByName(fmodule).FieldGroups.Items[j].Fields.count-1 do
                  str:=  str+IProject.ModuleByName(fmodule).FieldGroups.Items[j].Fields.Items[i].DataProperties.FieldName+','
            
            else
              begin
              if  IProject.ModuleByName(fmodule).FieldGroups.Items[j].IsTable then
                   if subtable.IndexOf(IProject.ModuleByName(fmodule).FieldGroups.Items[j].TableName)=-1 then
                   subtable.Add(IProject.ModuleByName(fmodule).FieldGroups.Items[j].TableName);
                   subsql.Add('');
                   for i:=0 to IProject.ModuleByName(fmodule).FieldGroups.Items[j].Fields.count-1 do 
                    begin
                    subsql.Strings(subsql.count-1):=subsql.Strings(subsql.count-1)+IProject.ModuleByName(fmodule).FieldGroups.Items[j].Fields.Items[i].DataProperties.FieldName+',';
                    //showmessage(subsql.strings(subsql.count-1)); 
                    end;
               end;     
                   
          end; 
          if str<>'' then
            str:=copy(str,1,length(str)-1); 
           
           // tmp:=tcxquery.Create(nil);
            //tmp.sql.text:='delete from '
           try
            IBeginTran; 
            tmp.close;
            tmp.sql.text:= 'delete from '+maintable+'_cancel where recordid='+quotedstr(frecordid);
            tmp.ExecSQL;
           
          //flist.Add( 'delete from '+maintable+'_cancel where recordid='+quotedstr(frecordid)); 
        
          str:='insert into '+maintable+'_cancel(recordid,qxrq,qxyy,'+str+') select recordid,'+quotedstr(datetostr(rq))+'[qxrq],'+quotedstr(memo1.text)+'[qxyy],'+str+' from '+maintable+' where recordid='+quotedstr(frecordid);
            tmp.close;
            tmp.sql.text:= str;
            tmp.ExecSQL;
          flist.add(str); 
           for i:=0 to subtable.count-1 do  
            begin  
              subsql.Strings[i]:= copy(subsql.Strings[i],1,length(subsql.Strings[i])-1); 
              //flist.add('delete from '+subtable.strings[i]+'_cancel where parentid='+quotedstr(frecordid));
                tmp.close;
                tmp.sql.text:= 'delete from '+subtable.strings[i]+'_cancel where parentid='+quotedstr(frecordid);
                tmp.ExecSQL;
                str:='insert into '+subtable.Strings[i]+'_cancel(parentid,recordid,'+subsql.strings[i]+') select parentid,recordid,'+subsql.strings[i]+' from '+subtable.Strings[i]+' where parentid='+quotedstr(frecordid);         
              //flist.add(str); 
               tmp.close;
               tmp.sql.text:= str;
               tmp.ExecSQL; 
               
            end;
            ICommitTran;
            //showmessage('ok');
            if _DeleteModuleRecord(fmodule,frecordid) then
               ShowMessage('原记录已删除');
                
            except
            on E: exception do
             begin
            IRollbackTran; //---出错执行事务回滚
            Showmessage(E.Message);
             end;   
           
    end; }
  
         //flist.SaveToFile('d:\insert.txt'); 
       

   end
   else 
   begin
   showmessage('取消日期和取消备注不能为空');
   exit;
   end;
    frmInfo.ModalResult := mrOK;  
 
 end;      
 
  
 
  procedure  Thxcancelfrm.getParamsByInput;
  var res:string; 
  m:integer;
  begin
     {if CheckComBox1.Text<>'' then
      begin 
         res:=CheckComBox1.Text;
         modals.Clear;
         while pos(';',res)>0 do
          begin
            modals.Add(copy(res,1,pos(';',res)-1));
            delete(res,1,pos(';',res));
          end;
         if res<>'' then modals.Add(res);
      end;}  
      modals.Clear;
       for m := 0 to CheckComBox1.Properties.Items.Count - 1 do
      if cbsChecked = CheckComBox1.States[m] then
        modals.Add(CheckComBox1.Properties.Items[m].Description);  

  end;   
  procedure Thxcancelfrm.FreeInfoWindow;
  begin
      flabel1.Free;
      flabel2.Free;
      flabel3.Free;
      flabel4.Free;
      flabel5.Free;
      CombBox1.Free;
      CombBox2.Free;
      edit1.Free;
      btnOK.Free;
      btnCancel.Free; 
      CheckComBox1.Free;    
      frmInfo.close;
      frmInfo.free;
      
  end;
  procedure  Thxcancelfrm.canceled(sender:tobject);
 begin
 frmInfo.ModalResult := mrCancel;
 end; 
 
var str:string; 
begin
    // showmessage(self.recordid);  
     //if IApplication.YesOrNo('你确认取消外销合同为'+self.recordset.fieldbyname('外销合同').asstring+'的记录吗?')=True then
    sendmessageData(nil,'','','外销合同');
end.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
[Delphi]一个功能完备的国密SM4类(TSM4)
[原]DELPHI图像显示特效
Delphi多线程编程 - 编程技巧文章 - 蓝鸟软件-19
读十六进制文本到 Btye 数组的函数
delphi7编程技巧与实例精解之图形图像(修正重绘变形)
Best way to do non-flickering, segmented graphics updates in Delphi?
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服