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

📄 main_datainput.pas

📁 商场管理系统源码 一套值得初学者学习的源码包含全部源码,控件
💻 PAS
字号:
unit MAIN_DATAINPUT;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FRMBASS, Grids, ComCtrls, StdCtrls,myself,
  DsFancyButton, ExtCtrls,  DB, DBTables,frmmain,
  TFlatComboBoxUnit, TFlatCheckListBoxUnit;

type
  TFrm_main_input = class(TFrm_bass)
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    DTP_date: TDateTimePicker;
    Query_data: TQuery;
    L_count: TLabel;
    Label3: TLabel;
    CB_ywy: TFlatComboBox;
    CB_depot: TFlatComboBox;
    PageScroller_input: TPageScroller;
    IMPSG_DATA: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure IMPSG_DATADblClick(Sender: TObject);
    procedure IMPSG_DATASelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    procedure IMPSG_DATASetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure IMPSG_DATAKeyPress(Sender: TObject; var Key: Char);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
   I_lastcol,I_lastrow:integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_main_input: TFrm_main_input;

implementation

uses SELECT_GOODS;

{$R *.dfm}

procedure TFrm_main_input.FormCreate(Sender: TObject);
var
   i_temp:integer;
begin
  inherited;
   I_lastcol:=1;
   I_lastrow:=1;
   Query_data.DatabaseName :=HWSHOPDATA;
   dtp_date.DateTime :=now;
   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 TFrm_main_input.FormShow(Sender: TObject);
begin
  inherited;
  l_count.Caption :='合计金额:零元  ¥0.00';
end;

procedure TFrm_main_input.FormResize(Sender: TObject);
var
   I_temp,I_colcount:integer;

begin
  inherited;
   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 TFrm_main_input.IMPSG_DATADblClick(Sender: TObject);
begin
  inherited;
  if IMPSG_DATA.Col <4 then
  begin
   application.CreateForm(tfrm_select_goods,frm_select_goods);
   if frm_select_goods.showmodal=mrOK then
   begin
      IMPSG_DATA.Cells[1,impsg_data.Row]:=frm_select_goods.SG_data.Cells[1,frm_select_goods.SG_data.Row];
      IMPSG_DATA.Cells[2,impsg_data.Row]:=frm_select_goods.SG_data.Cells[2,frm_select_goods.SG_data.Row];
      IMPSG_DATA.Cells[3,impsg_data.Row]:=frm_select_goods.SG_data.Cells[3,frm_select_goods.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]:=frm_select_goods.SG_data.Cells[4,frm_select_goods.SG_data.Row];
      IMPSG_DATA.Cells[6,impsg_data.Row]:=frm_select_goods.SG_data.Cells[5,frm_select_goods.SG_data.Row];
      IMPSG_DATASetEditText(IMPSG_DATA,5,impsg_data.Row, '');
      IMPSG_DATA.Col :=4;
   end;
   frm_select_goods.free;
  end;
end;

procedure TFrm_main_input.IMPSG_DATASelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  inherited;
   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 goodsmessage 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 TFrm_main_input.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
  inherited;
   if acol=3 then
   begin
      with query_data do
      begin
         close;
         sql.Clear ;
         sql.Text :='select * from goodsmessage where name='''+
            IMPSG_DATA.Cells[2,arow]+''''+ ' and type='''+IMPSG_DATA.Cells[3,arow]+'''';
         open;
         first;
         if not eof then
         begin
            IMPSG_DATA.Cells[1,arow]:=fieldbyname('id').asstring;
            IMPSG_DATA.Cells[4,arow]:='1';
            IMPSG_DATA.Cells[5,arow]:=fieldbyname('price').asstring;
            IMPSG_DATA.Cells[6,arow]:=fieldbyname('sellprice').asstring;
         end
         else
            impsg_data.Cells[acol,arow]:='';
         close;
      end;
   end;
   if acol=2 then
   begin
      impsg_data.Cells[3,arow]:='';
   end;
   if (acol>=4) and (acol<=6) then
   begin
      try
         I_num:=strtofloat(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:='合计金额:'+rmb(strtofloat(formatfloat('.00',f_tempmoney)))
               + '  ¥'+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 TFrm_main_input.IMPSG_DATAKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
  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 TFrm_main_input.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
   query_data.Free ;
end;

end.

⌨️ 快捷键说明

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