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

📄 main_depotgoods.pas

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

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_depotgoods = 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;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_main_depotgoods: TFrm_main_depotgoods;

implementation

{$R *.dfm}

procedure TFrm_main_depotgoods.FormCreate(Sender: TObject);
begin
  inherited;
   self.Caption :='商场(仓库)期初数据录入';
   impsg_data.ColWidths[6]:=-1;
   impsg_data.ColWidths[8]:=-1;
end;

procedure TFrm_main_depotgoods.FormShow(Sender: TObject);
begin
  inherited;
  if cb_depot.Enabled then
  begin
   cb_depot.Style:=csDropDownList;
   with query_data do
   begin
      close;
      sql.Clear ;
      sql.Text :='select name from depot where setid<>999 and type<>"暂停"';
      Open;
      while not eof do
      begin
         CB_depot.Items.add(fieldbyname('name').asstring);
         next;
      end;
      close;
   end;
  end;
end;

procedure TFrm_main_depotgoods.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_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_depotgoods.OKBtnClick(Sender: TObject);
var
   T_temp:TModalResult;
begin
  T_temp:=messagedlg(Askmsg0002+' - 【'+cb_depot.text+'】的期初数据',mtConfirmation,mbOKCancel,0);
  if T_temp=mrOk then
  begin
   if not user_save then
   begin
      messagedlg('【'+cb_depot.text+'】的期初'+Infmsg0004,mtError,[mbok],0);
   end
   else
   begin
      messagedlg(Infmsg0001,mtInformation,[mbok],0);
      okbtn.Enabled :=false;
      self.close;
   end;
  end;
end;

function TFrm_main_depotgoods.User_save():boolean;
var
   I_errordb,I_temp,I_count:integer;
   S_nameid:string;
begin
   I_errordb:=0;
   I_count:=0;
   S_nameid:='';
   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;
   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]='') 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]);
            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_nameid:=fieldbyname('id').AsString ;
         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:='delete from kccount where depotID="'+S_nameid+'" and GOODSID='''
                        + IMPSG_DATA.Cells[1,I_temp] +'''';
               execsql;
               I_errordb:=2;
               close;
               sql.clear;
               sql.text:='insert into kccount (depotid,goodsid,number,price,id,memo)'
                      +' values ("'+S_nameid+'","'
                      +IMPSG_DATA.Cells[1,I_temp]+'",'+IMPSG_DATA.cells[4,I_temp]+','
                      +IMPSG_DATA.cells[5,I_temp]+',"'+Nowindex+'-'+inttostr(I_temp)+'","'
                      + IMPSG_DATA.cells[9,i_temp]+'")';
               execsql;
               I_errordb:=3;
               close;
               sql.clear;
               sql.text:='insert into startrecord (depotid,goodsid,number,price,mydate,id,memo)'
                      +' values ("'+S_nameid+'","'
                      +IMPSG_DATA.Cells[1,I_temp]+'",'+IMPSG_DATA.cells[4,I_temp]+','
                      +IMPSG_DATA.cells[5,I_temp]+',"'+formatdatetime('yyyy-mm-dd',DTP_date.DateTime)
                      +'","'+Nowindex+'-'+inttostr(I_temp)+'","'
                      + IMPSG_DATA.cells[9,i_temp]+'")';
               execsql;
               I_errordb:=4;
               //设置已初始化标志
               close;
               sql.Clear ;
               sql.text:='update depot set setid=999 where name='''+cb_depot.text+'''';
               execsql;
               I_errordb:=5;
               close;
               sql.Clear ;
               sql.Text :='update goodsmessage set price='+IMPSG_DATA.cells[5,I_temp]+' where id='''+IMPSG_DATA.Cells[1,I_temp]+'''';
               execsql;
               close;
            end;
         end;
         except
            result:=false;
            if I_errordb=1 then
               messagedlg(Errormsg0005+'0016',mtwarning,[mbok],0)
            else if I_errordb=2 then
               messagedlg(Errormsg0004+'0016',mtwarning,[mbok],0)
            else if I_errordb=3 then
               messagedlg(Errormsg0004+'0017',mtwarning,[mbok],0)
            else if I_errordb=4 then
               messagedlg(Errormsg0004+'0011',mtwarning,[mbok],0)
            else if I_errordb=5 then
               messagedlg(Errormsg0004+'0013',mtwarning,[mbok],0)
            else
               messagedlg(Errormsg0001+'0000',mtwarning,[mbok],0);
            close;
            exit;
         end;
         close;
      end;
   end;
end;


procedure TFrm_main_depotgoods.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
   frm_main.User_depotgoodsMenu;
end;

end.

⌨️ 快捷键说明

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