📄 doapplyfrm.pas.svn-base
字号:
unit DoApplyFrm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BaseFrm, StdCtrls, jpeg, ExtCtrls, Grids, ComCtrls, DateUtils,
ActnList, TB2Item, TBX, Menus;
type
TRefreshDataThread = class(TThread)
private
procedure doRefreshData;
protected
procedure Execute; override;
end;
TTicketApply = record
Id: Integer;
AgentId: Integer;
AgentName: string;
ApplyTicketCount: Integer;
InvalidTickerCount: Integer;
AgentTotalTicketCount: Integer;
ApplyDate: TDateTime;
IdentifyCode: string;
TheResults: string;
Status: string;
end;
TFormDoApply = class(TFormBase)
pnlTop: TPanel;
pnlClient: TPanel;
btnDoApply: TButton;
cbApply: TCheckBox;
Label4: TLabel;
mmResult: TMemo;
lvApply: TListView;
ppmApply: TTBPopupMenu;
TBXItem1: TTBXItem;
aclMain: TActionList;
acDelSuperDateTicket: TAction;
procedure FormDestroy(Sender: TObject);
procedure btnDoApplyClick(Sender: TObject);
procedure lvApplyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
FRefreshDataThread: TRefreshDataThread;
procedure InsertTicketApplyDate(ATicketApply: TTicketApply);
function isAgentApplyExist(AAgentId: Integer): Boolean;
function GetCanLQTicketCount(AAgentId: integer): Integer;
function GetIdentifyCode: string;
public
{ Public declarations }
constructor Create(AOwner: TComponent;AFormDoApply: TFormDoApply); reintroduce;
class procedure DoRefreshDataList;
class procedure InitDoApplyData(AFormDoApply: TFormDoApply);
end;
implementation
uses
SystemDM, SystemPH;
{$R *.dfm}
var
FFormDoApply: TFormDoApply;
{ TFormDoApply }
procedure TFormDoApply.InsertTicketApplyDate(ATicketApply: TTicketApply);
var
oListItem: TListItem;
begin
oListItem := lvApply.Items.Add;
oListItem.Caption := IntToStr(ATicketApply.Id);
oListItem.SubItems.Add(IntToStr(ATicketApply.AgentId));
oListItem.SubItems.Add(ATicketApply.AgentName);
oListItem.SubItems.Add(DateTimeToStr(ATicketApply.ApplyDate));
oListItem.SubItems.Add(IntToStr(ATicketApply.AgentTotalTicketCount));
oListItem.SubItems.Add(IntToStr(ATicketApply.InvalidTickerCount));
oListItem.SubItems.Add(IntToStr(ATicketApply.ApplyTicketCount));
//oListItem.SubItems.Add(ATicketApply.IdentifyCode);
oListItem.SubItems.Add(ATicketApply.Status)
end;
class procedure TFormDoApply.DoRefreshDataList;
var
nAgentId: Integer;
sSqlStr: string;
oTicketApply: TTicketApply;
begin
if not Assigned(FFormDoApply) then Exit;
with FFormDoApply do
begin
sSqlStr := 'SELECT A.ID AS APPLYINDEX, A.AGENTID, A.TICKETCOUNT, A.APPLYDATE, A.IDENTIFYCODE, A.ISDOAPPLY, B.ID, B.USERNAME, B.TICKET_COUNT' +
' FROM TICKET_APPLY A INNER JOIN SITE_USER B ON A.AGENTID = B.ID WHERE A.ISDOAPPLY = 0';
if DMSystem.SQL_Querys(DMSystem.Qry_Temp, sSqlStr) then
try
with DMSystem.Qry_Temp do
begin
First;
while not Eof do
begin
nAgentId := FieldByName('AGENTID').AsInteger;
if not isAgentApplyExist(nAgentId) then
begin
oTicketApply.Id := FieldByName('APPLYINDEX').AsInteger;
oTicketApply.AgentId := nAgentId;
oTicketApply.AgentName := Trim(FieldByName('USERNAME').AsString);
oTicketApply.ApplyTicketCount := FieldByName('TICKETCOUNT').AsInteger;
oTicketApply.AgentTotalTicketCount := FieldByName('TICKET_COUNT').AsInteger;
oTicketApply.ApplyDate := FieldByName('APPLYDATE').AsDateTime;
oTicketApply.IdentifyCode := Trim(FieldByName('IDENTIFYCODE').AsString);
oTicketApply.InvalidTickerCount := oTicketApply.AgentTotalTicketCount - GetCanLQTicketCount(nAgentId);
if DaysBetween(Now, oTicketApply.ApplyDate) > systemConst_SuperDateTime then
oTicketApply.Status := '过期'
else oTicketApply.Status := '申请中';
InsertTicketApplyDate(oTicketApply);
end;
Next;
end;
end;
except
end;
end;
end;
constructor TFormDoApply.Create(AOwner: TComponent;
AFormDoApply: TFormDoApply);
begin
inherited Create(AOwner);
// FFormDoApply := AFormDoApply;
DoRefreshDataList;
FRefreshDataThread := TRefreshDataThread.Create(False);
end;
function TFormDoApply.isAgentApplyExist(AAgentId: Integer): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to lvApply.Items.Count-1 do
begin
if StrToIntDef(lvApply.Items[I].SubItems.Strings[0], 0) = AAgentId then
begin
Result := True;
Break;
end;
end;
end;
class procedure TFormDoApply.InitDoApplyData(AFormDoApply: TFormDoApply);
begin
FFormDoApply := AFormDoApply;
// DoRefreshDataList;
end;
function TFormDoApply.GetCanLQTicketCount(AAgentId: Integer): Integer;
var
sSqlStr: string;
begin
Result := 0;
sSqlStr := 'SELECT SUM(NUM - USED) AS KUSEDTICKETCOUNT FROM PRINTCODE WHERE AGENT_ID = ' + IntToStr(AAgentId);
if DMSystem.SQL_Querys(DMSystem.Qry_Info, sSqlStr) then
Result := DMSystem.Qry_Info.FieldByName('KUSEDTICKETCOUNT').AsInteger;
end;
function TFormDoApply.GetIdentifyCode: string;
const
MAX_LEN = 9;
var
i: Byte;
StrTemp, sSqlStr: string;
begin
StrTemp := 'ABCDEF0123456789';
Result := '';
for i := 0 to MAX_LEN-1 do
Result := Result + StrTemp[Random(Length(StrTemp)-1) + 1];
sSqlStr := 'SELECT IDENTIFYCODE FROM TICKET_APPLY WHERE IDENTIFYCODE = ' + #39 + Result + #39;
if DMSystem.SQL_Querys(DMSystem.Qry_Info, sSqlStr) then
Result := GetIdentifyCode;
end;
{ TRefreshDataThread }
procedure TRefreshDataThread.doRefreshData;
begin
TFormDoApply.DoRefreshDataList;
end;
procedure TRefreshDataThread.Execute;
begin
inherited;
if Terminated then Exit;
while True do
begin
Sleep(systemConst_RefreshInterval);
Synchronize(DoRefreshData);
end;
end;
procedure TFormDoApply.FormDestroy(Sender: TObject);
begin
inherited;
if not FRefreshDataThread.Terminated then FRefreshDataThread.Terminate;
end;
procedure TFormDoApply.btnDoApplyClick(Sender: TObject);
var
sSqlStr: string;
oApply: TListItem;
begin
inherited;
if lvApply.Selected = nil then Exit;
try
oApply := lvApply.Selected;
sSqlStr := 'UPDATE TICKET_APPLY SET RESULTS = ' + #39 + Trim(mmResult.Text)+ #39 + ',' +
'ISDOAPPLY = 1' + ',' +
'ISAGREE = ' + IntToStr(Integer(cbApply.Checked)) + ',' +
'DOAPPLYDATE = ' + #39 + DateTimeToStr(Now) + #39 + ',' +
'IDENTIFYCODE = ' + #39 + GetIdentifyCode + #39 +
' WHERE ID = ' + oApply.Caption;
if not DMSystem.SQL_Exec(DMSystem.Qry_Temp, sSqlStr) then
DMSystem.Qry_Temp.SQL.SaveToFile('C:\SQL.TXT');
finally
if lvApply.Selected <> nil then
begin
ShowMessage('代理[' + lvApply.Selected.SubItems[1] + ']的申请处理完毕。');
lvApply.Selected.Delete;
btnDoApply.Enabled := False;
cbApply.Caption := '同意申请';
mmResult.Clear;
end;
end;
end;
procedure TFormDoApply.lvApplyMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
oListItem: TListItem;
begin
inherited;
oListItem := lvApply.GetItemAt(X, Y);
if oListItem <> nil then
begin
btnDoApply.Enabled := True;
cbApply.Caption := '同意代理[' + oListItem.SubItems.Strings[1] + ']的申请';
end
else begin
cbApply.Caption := '同意代理';
btnDoApply.Enabled := False;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -