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.