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

📄 maininputtyunit.pas

📁 安装完成后
💻 PAS
字号:
unit MainInputTYUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, ComCtrls, StdCtrls, ExtCtrls, DB, DBTables;

type
  TMainInputTYfrm = class(TForm)
    P_back: TPanel;
    P_main: TPanel;
    Panel_down: TPanel;
    Bevel_bass: TBevel;
    L_count: TLabel;
    Panel_button: TPanel;
    PageScroller_input: TPageScroller;
    Panel1: TPanel;
    Label1: TLabel;
    Label3: TLabel;
    Label2: TLabel;
    DTP_date: TDateTimePicker;
    IMPSG_DATA: TStringGrid;
    L_title: TLabel;
    Query_data: TQuery;
    OKBtn: TButton;
    CancelBtn: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CancelBtnClick(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure IMPSG_DATADblClick(Sender: TObject);
    procedure IMPSG_DATAKeyPress(Sender: TObject; var Key: Char);
    procedure IMPSG_DATASelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure IMPSG_DATASetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: string);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    I_lastcol, I_lastrow: integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainInputTYfrm: TMainInputTYfrm;

implementation

uses MainUnit, GoodsSelectUnit;

{$R *.dfm}



procedure TMainInputTYfrm.FormCreate(Sender: TObject);
var
  I_windows: integer;
  i_temp: integer;
begin
  with MainForm do
  begin
    for I_windows := 0 to Panel_main.DockClientCount - 1 do
    begin
      Panel_main.DockClients[I_windows].Hide;
    end;
  end;
  I_lastcol := 1; //上一次编辑单元格位置指针
  I_lastrow := 1;
  dtp_date.DateTime := now;
  Query_data.DatabaseName := 'CPXSGL';
  //初始化显示表格IMPSG_DATA
  with IMPSG_DATA do
  begin
    ColCount := 10;
    ColWidths[0] := 16;
    ColWidths[1] := 80;
    ColWidths[2] := 180;
    ColWidths[3] := 180;
    ColWidths[4] := 50;
    ColWidths[5] := 50;
    ColWidths[6] := 50;
    ColWidths[7] := 80;
    ColWidths[8] := 80;
    ColWidths[9] := 200;

    Cols[0].text := '◎';
    Cols[1].text := '商品编号';
    Cols[2].text := '商品名称';
    Cols[3].text := '商品型号';
    Cols[4].text := '数量';
    Cols[5].text := '单价';
    Cols[6].text := '提成';
    Cols[7].text := '合计金额';
    Cols[8].text := '提成金额';
    Cols[9].text := '备注';
    for i_temp := 1 to 99 do
      Cells[0, i_temp] := inttostr(i_temp);
  end;
end;

procedure TMainInputTYfrm.FormShow(Sender: TObject);
begin
  self.Resize;
  l_count.Caption := '合计金额: ¥0.00';
end;

procedure TMainInputTYfrm.CancelBtnClick(Sender: TObject);
begin
  self.Close;
end;

procedure TMainInputTYfrm.FormResize(Sender: TObject);
var
  I_temp, I_colcount: integer;
begin
  L_title.Caption := application.Title + ' - ' + self.Caption;
  L_title.left := 0;
  L_title.top := 1;
  L_title.Width := self.Width;

  I_colcount := 0;
  for I_temp := 1 to impsg_data.ColCount - 1 do
  begin
    if impsg_data.ColWidths[I_temp] > 0 then
      inc(I_colcount);
  end;
  for I_temp := 1 to impsg_data.ColCount - 1 do
  begin
    if impsg_data.ColWidths[I_temp] > 0 then
      impsg_data.ColWidths[I_temp] := impsg_data.Width div I_colcount - 5;
  end;
end;

procedure TMainInputTYfrm.IMPSG_DATADblClick(Sender: TObject);
begin
  if IMPSG_DATA.Col < 4 then
  begin
    application.CreateForm(TGoodsSelectForm, GoodsSelectForm);
    //如果选择商品窗体返回为确定信息,则将选择的商品记录读入
    if GoodsSelectForm.showmodal = mrOK then
    begin
      IMPSG_DATA.Cells[1, impsg_data.Row] := GoodsSelectForm.SG_data.Cells[1, GoodsSelectForm.SG_data.Row];
      IMPSG_DATA.Cells[2, impsg_data.Row] := GoodsSelectForm.SG_data.Cells[2, GoodsSelectForm.SG_data.Row];
      IMPSG_DATA.Cells[3, impsg_data.Row] := GoodsSelectForm.SG_data.Cells[3, GoodsSelectForm.SG_data.Row];
      if IMPSG_DATA.Cells[4, impsg_data.Row] = '' then IMPSG_DATA.Cells[4, impsg_data.Row] := '1';
      IMPSG_DATA.Cells[5, impsg_data.Row] := GoodsSelectForm.SG_data.Cells[4, GoodsSelectForm.SG_data.Row];
      IMPSG_DATA.Cells[6, impsg_data.Row] := GoodsSelectForm.SG_data.Cells[5, GoodsSelectForm.SG_data.Row];
      IMPSG_DATASetEditText(IMPSG_DATA, 5, impsg_data.Row, '');
      IMPSG_DATA.Col := 4;
    end;
    GoodsSelectForm.free;
  end;
end;

procedure TMainInputTYfrm.IMPSG_DATAKeyPress(Sender: TObject;
  var Key: Char);
begin
  if impsg_data.Col = 1 then
    if (word(key) >= 97) and (word(key) <= 122) then
      key := chr(word(key) - 32);
  if (IMPSG_DATA.Col = 4) then
  begin
    if word(key) = 46 then
    begin
      key := chr(0);
    end
    else if (word(key) <> 8) and (word(key) < 45) or (word(key) > 57) then key := chr(0);
  end;
  if (IMPSG_DATA.col = 5) or (IMPSG_DATA.col = 6) then
  begin
    if word(key) = 46 then
    begin
      if strpos(pchar(IMPSG_DATA.Cells[IMPSG_DATA.col, IMPSG_DATA.row]), chr(46)) <> nil then key := chr(0);
    end
    else if (word(key) <> 8) and (word(key) < 48) or (word(key) > 57) then key := chr(0);
  end;
end;

procedure TMainInputTYfrm.IMPSG_DATASelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  if (acol = 7) or (acol = 8) then //设定第7、8列不可选
    canselect := false
  else
  begin
    //如果上一次编辑的是第一列,也就是商品编号列,则根据商品编号查询显示商品别的信息
    if i_lastcol = 1 then
    begin
      with query_data do
      begin
        close;
        sql.Clear;
        sql.Text := 'select * from goods where id=''' +
          IMPSG_DATA.Cells[1, i_lastrow] + '''';
        open;
        first;
        if not eof then
        begin
          IMPSG_DATA.Cells[2, i_lastrow] := fieldbyname('name').asstring;
          IMPSG_DATA.Cells[3, i_lastrow] := fieldbyname('type').asstring;
          if IMPSG_DATA.Cells[4, impsg_data.Row] = '' then IMPSG_DATA.Cells[4, impsg_data.Row] := '1';
          if IMPSG_DATA.Cells[5, impsg_data.Row] = '' then IMPSG_DATA.Cells[5, impsg_data.Row] := fieldbyname('price').AsString;
          if IMPSG_DATA.Cells[6, impsg_data.Row] = '' then IMPSG_DATA.Cells[6, impsg_data.Row] := fieldbyname('sellprice').AsString;
        end
        //如果输入商品编号不正确,清空整条交易记录
        else
        begin
          IMPSG_DATA.Cells[1, i_lastrow] := '';
          IMPSG_DATA.Cells[2, i_lastrow] := '';
          IMPSG_DATA.Cells[3, i_lastrow] := '';
          IMPSG_DATA.Cells[4, i_lastrow] := '';
          IMPSG_DATA.Cells[5, i_lastrow] := '';
          IMPSG_DATA.Cells[6, i_lastrow] := '';
        end;
        close;
      end;
    end;
  end;
  if impsg_data.Cells[1, I_lastrow] <> '' then
    IMPSG_DATASetEditText(IMPSG_DATA, 5, I_LASTRow, '');
    //指针指向当前单元格
  I_lastcol := acol;
  I_lastrow := arow;
end;

procedure TMainInputTYfrm.IMPSG_DATASetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: string);
var
  I_temp: integer;
  F_tempmoney: real;
  I_price, I_sellprice, I_num: real;
begin
  //编辑商品价格,数量及提成时,重新统计金额
  if (acol >= 4) and (acol <= 6) then
  begin
    try
      I_num := strtoint(IMPSG_DATA.Cells[4, aRow]);
    except
      I_num := 0;
    end;
    try
      I_price := strtofloat(IMPSG_DATA.Cells[5, aRow]);
    except
      I_price := 0;
    end;
    try
      I_sellprice := strtofloat(IMPSG_DATA.Cells[6, aRow]);
    except
      I_sellprice := 0;
    end;
    IMPSG_DATA.Cells[7, aRow] := formatfloat('.00', I_num * I_price);
    IMPSG_DATA.Cells[8, aRow] := formatfloat('.00', I_num * I_sellprice);

    try
      F_tempmoney := 0;
      //统计金额
      for I_temp := 1 to 99 do
      begin
        if trim(IMPSG_DATA.Cells[7, I_temp]) <> '' then
          F_tempmoney := F_tempmoney + strtofloat(IMPSG_DATA.Cells[7, I_temp]);
      end;
      L_count.caption := '合计金额:' + ' ¥' + formatfloat(',.00', f_tempmoney);
    except
      l_count.Caption := '合计金额: ¥0.00';
    end;
  end;
  //如果交易商品编号没有输入,保存对话框不可选
  for I_temp := 1 to 99 do
  begin
    if trim(IMPSG_DATA.Cells[1, I_temp]) <> '' then
    begin
      OKBTN.Enabled := TRUE;
      break;
    end
    else
      OKBTN.Enabled := false;
  end;
end;

procedure TMainInputTYfrm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  try
    self.Release;
  except
    messagedlg('系统在关闭〖' + self.Caption + '〗窗口时发生非致命的保护性错误'
      + #13 + #13 + '系统将停止运行,请立即与程序供应商联系。', mtError, [mbok], 0);
    application.Terminate;
  end;
  query_data.Free;

end;

end.

⌨️ 快捷键说明

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