⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewticketsfrm.~pas

📁 这个是个简单的关于出票申请的处理
💻 ~PAS
字号:
unit ViewTicketsFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, BaseFrm, StdCtrls, jpeg, ExtCtrls, Grids, TBXDkPanels, ComCtrls, DateUtils;

type
  TGridMode = (gmInitApply, gmInitLQ, gmInitStore, gmAddApply, gmAddLQ, gmADDStore);
  TFormViewTicket = class(TFormBase)
    PnlTop: TPanel;
    pnlClient: TPanel;
    Label1: TLabel;
    cbApply: TComboBox;
    rbApply: TRadioButton;
    rbLQ: TRadioButton;
    rbStore: TRadioButton;
    cbLQ: TComboBox;
    cbStore: TComboBox;
    sgResult: TStringGrid;
    pnllogic: TPanel;
    procedure RBButtonClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cbApplyChange(Sender: TObject);
    procedure sgResultDrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure cbLQChange(Sender: TObject);
    procedure cbStoreChange(Sender: TObject);
  private
    { Private declarations }
    procedure UpdateResultGrid(AGridMode: TGridMode; const ArrData: array of string);
  public
    { Public declarations }
  end;

var
  FormViewTicket: TFormViewTicket;

implementation
uses
  DatetimeSelectedFrm, systemPH, SystemDM, CommonFuncLib, logicSelectedFrm;
{$R *.dfm}

{ TFormViewTicket }

{ TFormViewTicket }

procedure TFormViewTicket.RBButtonClick(Sender: TObject);
const
  crbApply = 1001;
  crbLQ = 1002;
  crbStore = 1003;
begin
  if not (Sender is TRadioButton) then Exit;
  case TRadioButton(Sender).Tag of
    crbApply:
      begin
        cbApply.ItemIndex := -1;
        cbApply.Enabled := True;
        cbApply.Color := clWhite;
        cbLQ.Enabled := False;
        cbLQ.Color := clBtnFace;
        cbLQ.ItemIndex := -1;
        cbStore.Enabled := False;
        cbStore.Color := clBtnFace;
        cbStore.ItemIndex := -1;
      end;
    crbLQ:
      begin
        cbApply.ItemIndex := -1;
        cbApply.Enabled := False;
        cbApply.Color := clBtnFace;
        cbLQ.Enabled := True;
        cbLQ.Color := clWhite;
        cbLQ.ItemIndex := -1;
        cbStore.Enabled := False;
        cbStore.Color := clBtnFace;
        cbStore.ItemIndex := -1;
      end;
    crbStore:
      begin
        cbApply.ItemIndex := -1;
        cbApply.Enabled := False;
        cbApply.Color := clBtnFace;
        cbLQ.Enabled := False;
        cbLQ.Color := clBtnFace;
        cbLQ.ItemIndex := -1;
        cbStore.Enabled := True;
        cbStore.Color := clWhite;
        cbStore.ItemIndex := -1;
      end;
  end;
end;

procedure TFormViewTicket.FormCreate(Sender: TObject);
begin
  inherited;
  RBButtonClick(rbApply);
end;

procedure TFormViewTicket.cbApplyChange(Sender: TObject);
const
  cAllRecord = 0;
  cDate = 1;
  cDoApply = 2;
  cUnDoApply = 3;
  cSuperTime = 4;
var
  sSqlStr: string;
  StartDateTime, EndDateTime, ApplyDateTime: TDateTime;
  ArrData: array of string;
  nPos: Integer;
begin
  inherited;
  nPos := 0;
  UpdateResultGrid(gmInitApply, ArrData);

  case cbApply.ItemIndex of
    cAllRecord:
      sSqlStr := 'SELECT * FROM TICKET_APPLY';
    cDate:
      begin
        if TFormDatetimeSelected.ShowDateTimeForm(StartDateTime, EndDateTime) then
          sSqlStr := 'SELECT * FROM TICKET_APPLY WHERE APPLYDATE >=' + #39 + DateTimeToStr(StartDateTime) + #39 +
                     ' AND APPLYDATE <=' + #39 + DateTimeToStr(EndDateTime) + #39
        else begin
          cbApply.ItemIndex := -1;
          Exit;
        end;
      end;
    cDoApply:
      sSqlStr := 'SELECT * FROM TICKET_APPLY WHERE ISDOAPPLY = 1';
    cUnDoApply:
      sSqlStr := 'SELECT * FROM TICKET_APPLY WHERE ISDOAPPLY = 0';
    cSuperTime:
      begin
        ApplyDateTime := IncDay(Now, -systemConst_SuperDateTime);
        sSqlStr := 'SELECT * FROM TICKET_APPLY WHERE ISDOAPPLY = 0 AND APPLYDATE <=' + #39 + DateTimeToStr(ApplyDateTime)+ #39;
      end;
  end;

  SetLength(ArrData, 6);
  if DMSystem.SQL_Querys(DMSystem.Qry_Temp, sSqlStr) then
  with DMSystem.Qry_Temp do
  try
    First;
    SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_START_UPDATE, RecordCount);
    while not Eof do
    begin
      Inc(nPos);
      ArrData[0] := Trim(FieldByname('AgentId').AsString);
      ArrData[1] := FieldByname('TicketCount').AsString;
      ArrData[2] := FieldByname('ApplyDate').AsString;
      ArrData[3] := Trim(FieldByname('IdentifyCode').AsString);
      ArrData[4] := Trim(FieldByname('isDoApply').AsString);
      ArrData[5] := Trim(FieldByname('Results').AsString);
      UpdateResultGrid(gmAddApply, ArrData);
      SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_PLAYING_UPDATE, nPos);
      Sleep(100);
      Next;
      Application.ProcessMessages;
    end;
  finally
    SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_RECORDCOUNT, RecordCount);
  end;
end;

procedure TFormViewTicket.UpdateResultGrid(AGridMode: TGridMode;
  const ArrData: array of string);
var
  sDoApply, sUsed: string;
begin
  with sgResult do
  begin
    case AGridMode of
      gmInitApply:
        begin
          ColCount := 7;
          RowCount := 2;
          Cells[0, 0] := '序号';
          Cells[1, 0] := '代理帐号';
          Cells[2, 0] := '申请票数';
          Cells[3, 0] := '申请日期';
          Cells[4, 0] := '识别码';
          Cells[5, 0] := '是否处理';
          Cells[6, 0] := '处理结果';
          Cells[0, 1] := '';
          Cells[1, 1] := '';
          Cells[2, 1] := '';
          Cells[3, 1] := '';
          Cells[4, 1] := '';
          Cells[5, 1] := '';
          DefaultColWidth := 80;
          ColWidths[0] := 40;
          ColWidths[1] := 100;
          ColWidths[2] := 70;
          ColWidths[3] := 115;
          ColWidths[6] := 200;
        end;
      gmInitLQ:
        begin
          ColCount := 5;
          RowCount := 2;
          Cells[0, 0] := '序号';
          Cells[1, 0] := '代理人帐号';
          Cells[2, 0] := '起始票号';
          Cells[3, 0] := '领取票数';
          Cells[4, 0] := '领取日期';
          Cells[0, 1] := '';
          Cells[1, 1] := '';
          Cells[2, 1] := '';
          Cells[3, 1] := '';
          Cells[4, 1] := '';
          DefaultColWidth := 80;
          ColWidths[0] := 40;
          ColWidths[1] := 100;
          ColWidths[2] := 100;
          ColWidths[3] := 120;
        end;
      gmInitStore:
        begin
          ColCount := 4;
          RowCount := 2;
          Cells[0, 0] := '序号';
          Cells[1, 0] := '票号';
          Cells[2, 0] := '状态';
          Cells[3, 0] := '入库日期';
          Cells[0, 1] := '';
          Cells[1, 1] := '';
          Cells[2, 1] := '';
          Cells[3, 1] := '';
          DefaultColWidth := 80;
          ColWidths[0] := 40;
          ColWidths[1] := 110;
          ColWidths[3] := 120;
        end;
      gmAddApply:
        begin
          if Cells[1, 1] <> '' then RowCount := RowCount + 1;
          if Length(ArrData) < 6 then Exit;
          Cells[0, RowCount-1] := IntToStr(RowCount-1);
          Cells[1, RowCount-1] := ArrData[0];
          Cells[2, RowCount-1] := ArrData[1];
          Cells[3, RowCount-1] := ArrData[2];
          Cells[4, RowCount-1] := ArrData[3];
          if UpperCase(ArrData[4]) = 'TRUE' then  sDoApply := '已处理'
          else sDoApply := '未处理';
          Cells[5, RowCount-1] := sDoApply;
          Cells[6, RowCount-1] := ArrData[5];
          Row := RowCount - 1;
        end;
      gmAddLQ:
        begin
          if Cells[1, 1] <> '' then RowCount := RowCount + 1;
          if Length(ArrData) < 4 then Exit;
          Cells[0, RowCount-1] := IntToStr(RowCount-1);
          Cells[1, RowCount-1] := ArrData[0];
          Cells[2, RowCount-1] := ArrData[1];
          Cells[3, RowCount-1] := ArrData[2];
          Cells[4, RowCount-1] := ArrData[3];
          Row := RowCount - 1;
        end;
      gmADDStore:
        begin
          if Cells[1, 1] <> '' then RowCount := RowCount + 1;
          if Length(ArrData) < 3 then Exit;
          Cells[0, RowCount-1] := IntToStr(RowCount-1);
          Cells[1, RowCount-1] := ArrData[0];
          if UpperCase(ArrData[1]) = 'TRUE' then sUsed := '已使用'
          else sUsed  := '未使用';
          Cells[2, RowCount-1] := sUsed;
          Cells[3, RowCount-1] := ArrData[2];
          Row := RowCount - 1;
        end;
    end;
  end;
end;

procedure TFormViewTicket.sgResultDrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
var
  sCellText:   String;
begin
  with (Sender as TStringGrid) do
  begin
    Canvas.FillRect(Rect);
    sCellText := Cells[ACol,ARow];
    DrawText(Canvas.Handle, PChar(sCellText), Length(sCellText), Rect, DT_CENTER or DT_SINGLELINE or DT_VCENTER);//文字居中
  end;
end;
procedure TFormViewTicket.cbLQChange(Sender: TObject);
const
  cAllRecord = 0;
  cDate = 1;
  cTicketCount = 2;
  cAgentId = 3;
var
  sSqlStr, sAgentId, sLogic: string;
  StartDateTime, EndDateTime, LQDateTime: TDateTime;
  ArrData: array of string;
  nPos: Integer;
begin
  inherited;
  nPos := 0;
  UpdateResultGrid(gmInitLQ, ArrData);

  case cbLQ.ItemIndex of
    cAllRecord:
      sSqlStr := 'SELECT * FROM TICKET_NUMBER_HISTORY WHERE AGENTID <>' + IntToStr(COMPANYAGENTID);
    cDate:
      begin
        if TFormDatetimeSelected.ShowDateTimeForm(StartDateTime, EndDateTime) then
          sSqlStr := 'SELECT * FROM TICKET_NUMBER_HISTORY WHERE OPERATEDATE >=' + #39 + DateTimeToStr(StartDateTime) + #39 +
                     ' AND OPERATEDATE <=' + #39 + DateTimeToStr(EndDateTime) + #39 + ' AND AGENTID <> ' + IntToStr(COMPANYAGENTID)
        else begin
          cbLQ.ItemIndex := -1;
          Exit;
        end;
      end;
    cTicketCount:
      begin
        if not TFormSelectLogic.ShowSelectLogic(sLogic) then Exit;
        sSqlStr := 'SELECT * FROM TICKET_NUMBER_HISTORY WHERE TICKETCOUNT ' + sLogic;
      end;
    cAgentId:
      begin
        sAgentId := GoldenInputBox('提示', '请输入代理人帐号:', '');
        if not IsInteger(sAgentId) then
        begin
          cbLQ.ItemIndex := -1;
          Exit;
        end;
        sSqlStr := 'SELECT * FROM TICKET_NUMBER_HISTORY WHERE AGENTID = ' + sAgentId;
      end;
  end;

  SetLength(ArrData, 4);
  if DMSystem.SQL_Querys(DMSystem.Qry_Temp, sSqlStr) then
  with DMSystem.Qry_Temp do
  try
    First;
    SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_START_UPDATE, RecordCount);
    while not Eof do
    begin
      Inc(nPos);
      ArrData[0] := Trim(FieldByname('AgentId').AsString);
      ArrData[1] := Trim(FieldByname('StartPrintCode').AsString);
      ArrData[2] := FieldByname('TicketCount').AsString;
      ArrData[3] := FieldByname('OperateDate').AsString;
      UpdateResultGrid(gmAddLQ, ArrData);
      SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_PLAYING_UPDATE, nPos);
      Next;
      Application.ProcessMessages;
    end;
  finally
    SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_RECORDCOUNT, RecordCount);
  end;
end;

procedure TFormViewTicket.cbStoreChange(Sender: TObject);
const
  cAllRecord = 0;
  cTicketNum = 1;
  cUsed = 2;
  cNoUsed = 3;
  cDate = 4;
var
  sSqlStr, sTicketNum: string;
  StartDateTime, EndDateTime: TDateTime;
  ArrData: array of string;
  nPos: Integer;
begin
  inherited;
  nPos := 0;
  UpdateResultGrid(gmInitStore, ArrData);

  case cbStore.ItemIndex of
    cAllRecord:
      sSqlStr := 'SELECT * FROM TICKET_NUMBER';
    cTicketNum:
      begin
        sTicketNum := Trim(GoldenInputBox('提示', '请输入票号:', '0'));
        if not IsNumeric(sTicketNum) or (sTicketNum = '0') then
        begin
          cbStore.ItemIndex := -1;
          Exit;
        end;
        sSqlStr := 'SELECT * FROM TICKET_NUMBER WHERE PRINTCODE = ' + sTicketNum;
      end;
    cUsed:
      sSqlStr := 'SELECT * FROM TICKET_NUMBER WHERE ISUSED = 1';
    cNoUsed:
      sSqlStr := 'SELECT * FROM TICKET_NUMBER WHERE ISUSED = 0';
    cDate:
      begin
        if TFormDatetimeSelected.ShowDateTimeForm(StartDateTime, EndDateTime) then
          sSqlStr := 'SELECT * FROM TICKET_NUMBER WHERE STOREDATE >=' + #39 + DateTimeToStr(StartDateTime) + #39 +
                     ' AND STOREDATE <=' + #39 + DateTimeToStr(EndDateTime) + #39
        else begin
          cbStore.ItemIndex := -1;
          Exit;
        end;
      end;
  end;

  SetLength(ArrData, 3);
  if DMSystem.SQL_Querys(DMSystem.Qry_Temp, sSqlStr) then
  with DMSystem.Qry_Temp do
  try
    First;
    SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_START_UPDATE, RecordCount);
    Sleep(1000);
    while not Eof do
    begin
      Inc(nPos);
      ArrData[0] := Trim(FieldByname('PRINTCODE').AsString);
      ArrData[1] := Trim(FieldByname('ISUSED').AsString);
      ArrData[2] := FieldByname('STOREDATE').AsString;
      UpdateResultGrid(gmADDStore, ArrData);
      SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_PLAYING_UPDATE, nPos);
      Next;
      Application.ProcessMessages;
    end;
  finally
    SendMessage(Application.MainForm.Handle, WM_STATUS_MSG, DEF_RECORDCOUNT, RecordCount);
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -