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

📄 main_daysell.pas

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

interface

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

type
  TFrm_main_daysell = class(TFrm_main_input)
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure OKBtnClick(Sender: TObject);
    function User_save():boolean;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_main_daysell: TFrm_main_daysell;

implementation

{$R *.dfm}

procedure TFrm_main_daysell.FormCreate(Sender: TObject);
begin
  inherited;
   self.Caption :='商场日销售数据录入';
end;

procedure TFrm_main_daysell.FormShow(Sender: TObject);
begin
  inherited;
   with query_data do
   begin
      close;
      sql.Clear ;
      sql.Text :='select name from depot where setid=999 and type="外部"';
      open;
      cb_depot.Items.Clear ;
      cb_depot.Style:=csDropDownList;
      while not eof do
      begin
         CB_depot.Items.add(fieldbyname('name').asstring);
         next;
      end;
      close;
      sql.Clear ;
      sql.Text :='select name from people where usertype="在职"';
      open;
      cb_ywy.Items.Clear ;
      cb_ywy.Style :=csDropDownList;
      while not eof do
      begin
         CB_ywy.Items.add(fieldbyname('name').asstring);
         next;
      end;
      close;
      cb_depot.SetFocus ;
   end;
end;

procedure TFrm_main_daysell.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
var
   T_temp:TModalResult;
begin
  inherited;
   if OKBtn.Enabled then
   begin
      T_temp:=messagedlg(Askmsg0001,mtConfirmation,mbYesnoCancel,0);
      if T_temp=mrYes then
      begin
         if not user_save then
         begin
            messagedlg('【'+cb_ywy.text+'】在〖'+cb_depot.Text+'〗的当日销售'+Infmsg0004,mtError,[mbok],0);
            canclose:=false;
         end
         else
         begin
            messagedlg(Infmsg0001,mtInformation,[mbok],0);
            canclose:=true;
         end;
      end
      else if T_temp=mrNo then
         canclose:=true
      else
         canclose:=false;
   end
   else
      canclose:=true;
end;

procedure TFrm_main_daysell.OKBtnClick(Sender: TObject);
var
   T_temp:TModalResult;
   I_row,I_col:integer;
begin
   T_temp:=messagedlg(Askmsg0002+' - 【'+cb_ywy.text+'】在〖'+cb_depot.Text
        +'〗的当日销售',mtConfirmation,mbOKCancel,0);
   if T_temp=mrOk then
   begin
      if not user_save then
      begin
         messagedlg('【'+cb_ywy.text+'】在〖'+cb_depot.Text+'〗的当日销售'+Infmsg0004,mtError,[mbok],0);
      end
      else
      begin
         T_temp:=messagedlg(Infmsg0001+'  '+Askmsg0003,mtConfirmation,mbOKCancel,0);
         if T_temp=mrok then       //继续输入数据
         begin
            for I_row:=1 to 99 do
            begin
               for I_col:=1 to 9 do
               begin
                  IMPSG_DATA.Cells[I_col,I_row]:='';
               end;
            end;
            FormShow(self) ;
         end
         else
         begin
            okbtn.Enabled :=false;
            self.close;
         end;
      end;
   end;
end;

function TFrm_main_daysell.User_save():boolean;
var
   I_errordb,I_temp,I_count,I_number:integer;
   S_depotid,S_peopleid,S_id:string;
begin
   I_errordb:=0;
   I_count:=0;
   S_depotid:='';
   S_peopleid:='';
   S_id:='';
   if not Checkrights(USERRIGHTS,'增加') then
   begin
      messagedlg(Errormsg0006+'0007',mterror,[mbok],0);
      result:=false;
      exit;
   end;
   if CB_depot.Text ='' then
   begin
      messagedlg(Errormsg0002+'0002',mtwarning,[mbok],0);
      cb_depot.SetFocus ;
      result:=false;
      exit;
   end;
   if CB_ywy.Text ='' then
   begin
      messagedlg(Errormsg0002+'0002',mtwarning,[mbok],0);
      cb_ywy.SetFocus ;
      result:=false;
      exit;
   end
   else
      result:=true;
   if result then
   begin
      for I_temp:=1 to 99 do              //逐行检测进货记录是否有效
      begin
         if IMPSG_DATA.Cells[1,I_temp]<>'' then           //有效记录
         begin
            inc(I_count);
            if (IMPSG_DATA.cells[4,I_temp]='') or (IMPSG_DATA.cells[5,I_temp]='')
               or (IMPSG_DATA.cells[6,I_temp]='') then
            begin
               messagedlg('第'+inttostr(I_temp)+
                  '行记录的'+Errormsg0002+'0015',mtError,[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]);
               strtofloat(IMPSG_DATA.Cells[5,I_temp]);
               strtofloat(IMPSG_DATA.Cells[6,I_temp]);
            except
               messagedlg('第'+inttostr(I_temp)+
                  '行记录的'+Errormsg0002+'0015',mtError,[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(Errormsg0008,mtwarning,[mbok],0);
      end;
   end;
   if result then
   begin
      with query_data do
      begin
         try
            close;
            sql.Clear ;
            sql.Text :='select id from depot where name="'+ cb_depot.Text+'"';
            open;
            S_depotid:=fieldbyname('id').AsString ;
            close;
            sql.Clear ;
            sql.Text :='select id from people where name="'+ cb_ywy.Text+'"';
            open;
            S_peopleid:=fieldbyname('id').AsString ;
            close;
            //检查是否有库存,即销售数量是否合法
            for I_temp:=1 to 99 do
            begin
               if IMPSG_DATA.Cells[1,I_temp]<>'' then           //有效记录
               begin
                  I_errordb:=2;
                  close;
                  sql.Clear ;
                  sql.text:='select id,number from kccount where depotid="'+
                           S_depotid+'" and goodsid="'+ IMPSG_DATA.Cells[1,I_temp]+'"';
                  open;
                  S_id:=fieldbyname('id').asstring;
                  I_number:=fieldbyname('number').AsInteger-strtoint(IMPSG_DATA.cells[4,I_temp]);
                  if (recordcount<= 0) or (s_id='') then   //本行商品没有库存记录
                  begin
                     messagedlg('在【'+cb_depot.Text+'】'+Errormsg0009,mtwarning,[mbok],0);
                     impsg_data.Row :=I_temp;
                     impsg_data.Col :=1;
                     result:=false;
                     close;
                     exit;
                  end
                  else if I_number<0 then    //库存数量小于销售数量
                  begin
                     messagedlg('在【'+cb_depot.Text+'】'+Errormsg0010,mtwarning,[mbok],0);
                     impsg_data.Row :=I_temp;
                     impsg_data.Col :=4;
                     result:=false;
                     close;
                     exit;
                  end;
               end;
            end;

            for I_temp:=1 to 99 do
            begin
               if IMPSG_DATA.Cells[1,I_temp]<>'' then           //有效记录
               begin
                  I_errordb:=1;
                  close;
                  sql.clear;
                  sql.text:='insert into SELLRECORD (id,depotid,peopleid,mydate,goodsid,number,'
                           +'price,sellprice,memo) values ("'+Nowindex+'-'+inttostr(I_temp)+'","'
                           +S_depotid+'","'+S_peopleid+'","'+formatdatetime('yyyy-mm-dd',DTP_date.DateTime)+'","'
                           +IMPSG_DATA.Cells[1,I_temp]+'",'+IMPSG_DATA.Cells[4,I_temp]+','+IMPSG_DATA.Cells[5,I_temp]+','
                           +IMPSG_DATA.Cells[6,I_temp]+',"'+IMPSG_DATA.Cells[9,I_temp]+'")';
                  execsql;
                  I_errordb:=2;
                  close;
                  sql.Clear ;
                  sql.text:='select id,number from kccount where depotid="'+
                           S_depotid+'" and goodsid="'+ IMPSG_DATA.Cells[1,I_temp]+'"';
                  open;
                  S_id:=fieldbyname('id').asstring;
                  I_number:=fieldbyname('number').AsInteger-strtoint(IMPSG_DATA.cells[4,I_temp]);
                  I_errordb:=3;
                  close;
                  sql.Clear ;
                  sql.text:='update kccount set number='+inttostr(i_number)+' where id='''+s_id+'''';
                  execsql;
                  close;
               end;
            end;
         except
            result:=false;
            if I_errordb=1 then
               messagedlg(Errormsg0004+'0018',mtwarning,[mbok],0)
            else if I_errordb=2 then
               messagedlg(Errormsg0001+'0019',mtwarning,[mbok],0)
            else if I_errordb=3 then
               messagedlg(Errormsg0004+'0016',mtwarning,[mbok],0)
            else
               messagedlg(Errormsg0001+'0000',mtwarning,[mbok],0);
            close;
            exit;
         end;
      end;
   end;
end;

end.

⌨️ 快捷键说明

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