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

📄 bassmessage_depotgoods.pas

📁 pos商场、超市管理系统
💻 PAS
字号:
unit BASSMESSAGE_DEPOTGOODS;

interface

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

type
  TFrm_main_depotgoods = class(TFrm_bass)
    Table_DATA: TTable;
    Query_data: TQuery;
    L_warning: TLabel;
    IMPSG_DATA: TImpStringgrid;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    cb_depot: TComboBox;
    DTP_date: TDateTimePicker;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure IMPSG_DATADblClick(Sender: TObject);
    procedure IMPSG_DATAElippsisclicked(Sender: TObject; Col,
      Row: Integer);
    procedure cb_depotChange(Sender: TObject);
    procedure IMPSG_DATASetEditText(Sender: TObject; ACol, ARow: Integer;
      const Value: String);
    procedure IMPSG_DATASelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    function User_save():boolean;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure IMPSG_DATAKeyPress(Sender: TObject; var Key: Char);
  private
   I_lastcol,I_lastrow:integer;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_main_depotgoods: TFrm_main_depotgoods;

implementation

uses SELECT_GOODS, FRMmain;

{$R *.dfm}

procedure TFrm_main_depotgoods.FormCreate(Sender: TObject);
var
   i_temp:integer;
begin
  inherited;
   self.Caption :=self.Caption +'商场期初数据录入';
   I_lastcol:=1;
   I_lastrow:=1;
   Query_data.DatabaseName :=HWSHOPDATA;
   Table_DATA.DatabaseName :=HWSHOPDATA;
   with IMPSG_DATA do
   begin
      ColCount :=6;
      ColWidths[0]:=26;
      ColWidths[1]:=80;
      ColWidths[2]:=180;
      ColWidths[3]:=180;
      ColWidths[4]:=60;
      ColWidths[5]:=160;
      Columns.Items[0].Title.caption:='◎';
      Columns.Items[1].Title.caption:='商品编号';
      Columns.Items[2].Title.caption:='商品名称';
      Columns.Items[3].Title.caption:='商品型号';
      Columns.Items[4].Title.caption:='数量';
      Columns.Items[5].Title.caption:='备注';
      columns.Items[3].ButtonStyle := cbsPicklist;

      for i_temp:=1 to 500 do
         Cells [0,i_temp]:=inttostr(i_temp);
   end;
end;

procedure TFrm_main_depotgoods.FormShow(Sender: TObject);
var
   list:Tstringlist;
   b_find:boolean;
   I_temp:integer;
begin
  inherited;
   //增加下拉列表
    DTP_date.DateTime :=now;
    with table_data do
    begin
      Close;
      TableName:='depot.db';
      active :=true;
      first;
      while not eof do
      begin
         if fieldbyname('setid').AsInteger <>999 then
            CB_depot.Items.Append(fieldbyname('name').asstring);
         next;
      end;
      Close;
      TableName:='goodsmessage.db';
      active :=true;
      first;
      with impsg_data do
      begin
         //增加产品名称
         columns.Items[2].ButtonStyle := cbsPicklist;
         list := tstringlist.create;
      end;
      while not eof do
      begin
         B_find:=false;
         for I_temp:=0 to list.Count-1 do
         begin
           if list.Strings[I_temp]=fieldbyname('name').asstring then
             B_find:=true;          //找到相同名称
         end;
         if not B_find then        //没有找到时增加
           list.add(fieldbyname('name').asstring);
         next;
      end;
      impsg_data.columns.Items[2].Picklist := list;
      impsg_data.columns.Items[2].DropDownRows :=20;
    end;
    impsg_data.columns.Items[1].ButtonStyle := cbsEllipsis;
end;

procedure TFrm_main_depotgoods.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.Col :=4;
   end;
   frm_select_goods.free;
  end;
end;

procedure TFrm_main_depotgoods.IMPSG_DATAElippsisclicked(Sender: TObject; Col,
  Row: Integer);
begin
  inherited;
  IMPSG_DATAdblclick(IMPSG_DATA);
end;

procedure TFrm_main_depotgoods.cb_depotChange(Sender: TObject);
begin
  inherited;
   OKBtn.Enabled :=true;
   L_warning.Caption :='商场名称:'+cb_depot.Text ;
   l_warning.Font.Color :=clblue;
end;

procedure TFrm_main_depotgoods.IMPSG_DATASetEditText(Sender: TObject; ACol,
  ARow: Integer; const Value: String);
begin
  inherited;
   if acol=3 then
   begin
      with query_data do
      begin
         sql.Text :='select * from goodsmessage where name='''+
            IMPSG_DATA.Cells[2,arow]+''''+ ' and type='''+IMPSG_DATA.Cells[3,arow]+'''';
         execsql;
         open;
         first;
         if not eof then
         begin
            IMPSG_DATA.Cells[1,arow]:=fieldbyname('id').asstring;
            if IMPSG_DATA.Cells[4,impsg_data.Row]='' then IMPSG_DATA.Cells[4,impsg_data.Row]:='1';
         end
         else
            impsg_data.Cells[acol,arow]:='';
      end;
   end;
   if acol=2 then
   begin
      impsg_data.Cells[3,arow]:='';
   end;
end;

procedure TFrm_main_depotgoods.IMPSG_DATASelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
   list:Tstringlist;
   b_find:boolean;
   I_temp:integer;
begin
  inherited;
      If i_lastcol=1 then
      begin
            with query_data do
            begin
               sql.Text :='select * from goodsmessage where id='''+
                  IMPSG_DATA.Cells[i_lastcol,i_lastrow]+'''';
               execsql;
               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';
               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]:='';
               end;
            end;
      end;
      I_lastcol:=acol;
      I_lastrow:=arow;
   if acol=3 then
   begin
      with query_data do
      begin
         sql.Text :='select * from goodsmessage where name='''+
            IMPSG_DATA.Cells[2,arow]+'''';
         execsql;
         open;
         first;
         list := tstringlist.create;
         while not eof do
         begin
            B_find:=false;
            for I_temp:=0 to list.Count-1 do
            begin
            if list.Strings[I_temp]=fieldbyname('type').asstring then
               B_find:=true;          //找到相同型号
            end;
            if not B_find then        //没有找到时增加
              list.add(fieldbyname('type').asstring);
            next;
         end;
         impsg_data.columns.Items[3].Picklist := list;
         impsg_data.columns.Items[3].DropDownRows :=20;
      end;
   end;
end;

function TFrm_main_depotgoods.User_save():boolean;
var
   I_temp,I_count:integer;
begin
   I_count:=0;
   if CB_depot.Text ='' then
   begin
      messagedlg('商场名称不能为空,请检查后重新输入。',mtwarning,[mbok],0);
      result:=false;
   end
   else
      result:=true;
   if result then
   begin
      for I_temp:=1 to 499 do              //逐行检测进货记录是否有效
      begin
         if IMPSG_DATA.Cells[1,I_temp]<>'' then           //有效记录
         begin
            inc(I_count);
            if (IMPSG_DATA.cells[4,I_temp]='') then
            begin
               messagedlg('第'+inttostr(I_temp)+
                  '行记录的数量未输入,请检查后重新输入。',mtwarning,[mbok],0);
               IMPSG_DATA.Row :=I_temp;
               IMPSG_DATA.Col :=4;
               IMPSG_DATA.SetFocus ;
               result:=false;
               exit;
            end;
            try
               strtofloat(IMPSG_DATA.Cells[4,I_temp]);
            except
               messagedlg('第'+inttostr(I_temp)+
                  '行记录的商品数量有错误,请检查后重新输入。',mtwarning,[mbok],0);
               IMPSG_DATA.Row :=I_temp;
               IMPSG_DATA.Col :=4;
               IMPSG_DATA.SetFocus ;
               result:=false;
               exit;
            end;
         end;
      end;
      if I_count<1 then
      begin
         result:=false;
         messagedlg('没有输入期初数据记录,请检查后重新输入。',mtwarning,[mbok],0);
      end;
   end;
   if result then
   begin
      with query_data do
      begin
         try
         for I_temp:=1 to 499 do
         begin
            if IMPSG_DATA.Cells[1,I_temp]<>'' then           //有效记录
            begin
               close;
               sql.clear;
               sql.text:='delete from kccount where depot='''+cb_depot.Text+''' and GOODSID='''
                        + IMPSG_DATA.Cells[1,I_temp] +'''';
               execsql;
               close;
               sql.clear;
               sql.text:='insert into kccount (depot,goodsid,num,mydate,id,memo)'+
                      'values ('''+cb_depot.text+''','''+IMPSG_DATA.Cells[1,I_temp]+''','
                      +IMPSG_DATA.cells[4,I_temp]+','''+formatdatetime('yyyy-mm-dd',DTP_date.DateTime)
                      +''','''+formatdatetime('yyyymmdd',date)
                      +'-'+formatdatetime('hhmmss',time)+'-'+inttostr(I_temp)+''','''
                      + IMPSG_DATA.cells[5,i_temp]+''')';
               execsql;
               close;
               sql.clear;
               sql.text:='insert into startrecord (depot,goodsid,num,mydate,id,memo)'+
                      'values ('''+cb_depot.text+''','''+IMPSG_DATA.Cells[1,I_temp]+''','
                      +IMPSG_DATA.cells[4,I_temp]+','''+formatdatetime('yyyy-mm-dd',DTP_date.DateTime)
                      +''','''+formatdatetime('yyyymmdd',date)
                      +'-'+formatdatetime('hhmmss',time)+'-'+inttostr(I_temp)+''','''
                      + IMPSG_DATA.cells[5,i_temp]+''')';
               execsql;
               //设置标志
               sql.text:='update depot set setid=999 where name='''+cb_depot.text+'''';
               execsql;
            end;
         end;
         except
            result:=false;
            messagedlg('数据保存时发生意外错误,停止保存数据。',mtwarning,[mbok],0);
            close;
            exit;
         end;
         close;
      end;
   end;
end;

procedure TFrm_main_depotgoods.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
var
   T_temp:TModalResult;
begin
  inherited;
  if cb_depot.text='' then exit;
  T_temp:=messagedlg('是否要保存【'+cb_depot.text+'】的期初数据?',mtConfirmation,mbYesnoCancel,0);
  if T_temp=mrYes then
  begin
   if not user_save then
   begin
      messagedlg('【'+cb_depot.text+'】的期初数据保存失败,请检查后重新保存。',mtError,[mbok],0);
      canclose:=false;
   end
   else
      canclose:=true;
  end
  else if T_temp=mrNo then
     canclose:=true
  else
     canclose:=false;

end;

procedure TFrm_main_depotgoods.IMPSG_DATAKeyPress(Sender: TObject;
  var Key: Char);
begin
  inherited;
   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)<47) or (word(key)>57) then key:=chr(0);
   end;
end;

end.

⌨️ 快捷键说明

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