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

📄 modifyspc.~pas

📁 根据箱号
💻 ~PAS
字号:
unit modifyspC;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Cmodel, Menus, StdCtrls, ExtCtrls, DBCtrls, Buttons, ADODB, DB;

type
  Tmodifysp = class(Tmodel)
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    Panel3: TPanel;
    StaticText1: TStaticText;
    Label6: TLabel;
    Label3: TLabel;
    spdm: TEdit;
    Label4: TLabel;
    spmc: TEdit;
    Label5: TLabel;
    Edit3: TEdit;
    Panel1: TPanel;
    Label8: TLabel;
    sjspmx: TComboBox;
    ejspmx: TCheckBox;
    Panel2: TPanel;
    Label7: TLabel;
    hssl: TCheckBox;
    sskjkm: TCheckBox;
    Panel4: TPanel;
    Label1: TLabel;
    kjkm: TDBComboBox;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    ADOCommand1: TADOCommand;
    jldw: TComboBox;
    ADOQuery3: TADOQuery;
    procedure BitBtn3Click(Sender: TObject);
    procedure spmcKeyPress(Sender: TObject; var Key: Char);
    procedure ejspmxClick(Sender: TObject);
    procedure hsslClick(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  modifysp: Tmodifysp;

implementation

{$R *.dfm}

procedure Tmodifysp.BitBtn3Click(Sender: TObject);
begin
  inherited;
   modalresult:=mrok;
end;

procedure Tmodifysp.spmcKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if key=#13 then
     edit3.SetFocus;
end;

procedure Tmodifysp.ejspmxClick(Sender: TObject);
begin
  inherited;
  if ejspmx.Checked=true then
     begin
       panel1.Enabled:=true;
     end
  else
     panel1.Enabled:=false;
end;

procedure Tmodifysp.hsslClick(Sender: TObject);
begin
  inherited;
  if hssl.Checked=true then
     begin
       panel2.Enabled:=true;
     end
  else
     panel2.Enabled:=false;
end;

procedure Tmodifysp.BitBtn2Click(Sender: TObject);
var
  spdm1,spdm2:string;
begin
  inherited;
  if spmc.Text='' then
     begin
       messagedlg('商品名称不能为空!',mtinformation,[mbyes],0);
       spmc.SetFocus;
     end
  else
  if ejspmx.Checked=false then
     begin
       messagedlg('请选择所属上级商品!',mtinformation,[mbyes],0);
     end
  else
  begin
    spdm1:=copy(sjspmx.Text,0,3);
    adoquery3.Close;
    adoquery3.SQL.Clear;
    adoquery3.SQL.add('select 商品代码 from 商品信息B where 父项编号='''+spdm1+'''');
    adoquery3.Open;
    if adoquery3.RecordCount=0 then
       begin
        spdm.Text:=''+spdm1+''+'001';
        spdm2:=spdm1;
       end
    else
    begin
      adoquery3.Close;
      adoquery3.SQL.Clear;
      adoquery3.SQL.add('select max(商品代码) as 最大代码 from 商品信息B where 父项编号='''+spdm1+'''');
      adoquery3.Open;
      spdm2:=adoquery3.fieldbyname('最大代码').AsString;
      spdm2:=inttostr(strtoint(spdm2)+1);
      if length(spdm2)=4 then
         spdm.Text:='00'+spdm2;
      if length(spdm2)=5 then
         spdm.Text:='0'+spdm2;
      if length(spdm2)=6 then
         spdm.Text:=spdm2;   
    end;
    try
      if application.MessageBox(pchar('是否新增商品代码为【'+spdm.Text+'】;'+#13+'商品名称为【'+spmc.Text+'】产品?'),'温馨提示',mb_yesno)=id_yes then
         begin
           adocommand1.CommandText:='insert into 商品信息A ([商品代码],[商品名称],[低层码],[级别]) values('''+trim(spdm.text)+''','''+trim(spmc.text)+''',''2'',''二级'')';
           adocommand1.Execute;
           adocommand1.CommandText:='insert into 商品信息B ([父项编号],[商品代码],[低层码]) values('''+spdm1+''','''+trim(spdm.text)+''',''2'')';
           adocommand1.Execute;
           modalresult:=mrok;
         end;
    except
      messagedlg('添加商品种类失败!',mterror,[mbyes],0);
    end;
  end;       
end;

procedure Tmodifysp.FormShow(Sender: TObject);
begin
  inherited;
  adoquery1.Close;
  adoquery1.SQL.Clear;
  adoquery1.SQL.add('select 商品代码,商品名称 from 商品信息A where 低层码=''0'' and 商品代码<>''000''');
  adoquery1.Open;
    while not adoquery1.Eof do
      begin
        sjspmx.Items.Add(adoquery1.fieldbyname('商品代码').AsString+' '+adoquery1.fieldbyname('商品名称').AsString);
        adoquery1.Next;
      end;
  sjspmx.ItemIndex:=0;
  adoquery2.Close;
  adoquery2.SQL.Clear;
  adoquery2.SQL.add('select 编号,单位 from 计量单位');
  adoquery2.Open;
    while not adoquery2.Eof do
      begin
        jldw.Items.Add(adoquery2.fieldbyname('编号').AsString+' '+adoquery2.fieldbyname('单位').AsString);
        adoquery2.Next;
      end;
  jldw.ItemIndex:=0;
end;

procedure Tmodifysp.BitBtn1Click(Sender: TObject);
var
  spdm1,spdm2:string;
begin
  inherited;
  if spmc.Text='' then
     begin
       messagedlg('商品名称不能为空!',mtinformation,[mbyes],0);
       spmc.SetFocus;
     end
  else
  if ejspmx.Checked=false then
     begin
       messagedlg('请选择所属上级商品!',mtinformation,[mbyes],0);
     end
  else
  begin
    spdm1:=copy(sjspmx.Text,0,3);
    adoquery3.Close;
    adoquery3.SQL.Clear;
    adoquery3.SQL.add('select 商品代码 from 商品信息B where 父项编号='''+spdm1+'''');
    adoquery3.Open;
    if adoquery3.RecordCount=0 then
       begin
        spdm.Text:=''+spdm1+''+'001';
        spdm2:=spdm1;
       end
    else
    begin
      adoquery3.Close;
      adoquery3.SQL.Clear;
      adoquery3.SQL.add('select max(商品代码) as 最大代码 from 商品信息B where 父项编号='''+spdm1+'''');
      adoquery3.Open;
      spdm2:=adoquery3.fieldbyname('最大代码').AsString;
      spdm2:=inttostr(strtoint(spdm2)+1);
      if length(spdm2)=4 then
         spdm.Text:='00'+spdm2;
      if length(spdm2)=5 then
         spdm.Text:='0'+spdm2;
      if length(spdm2)=6 then
         spdm.Text:=spdm2;   
    end;
    try
      if application.MessageBox(pchar('是否新增商品代码为【'+spdm.Text+'】;'+#13+'商品名称为【'+spmc.Text+'】产品?'),'温馨提示',mb_yesno)=id_yes then
         begin
           adocommand1.CommandText:='insert into 商品信息A ([商品代码],[商品名称],[低层码],[级别]) values('''+trim(spdm.text)+''','''+trim(spmc.text)+''',''2'',''二级'')';
           adocommand1.Execute;
           adocommand1.CommandText:='insert into 商品信息B ([父项编号],[商品代码],[低层码]) values('''+spdm1+''','''+trim(spdm.text)+''',''2'')';
           adocommand1.Execute;
           spdm.Clear;
           spmc.Clear;
           spmc.SetFocus;
         end;
    except
      messagedlg('添加商品种类失败!',mterror,[mbyes],0);
    end;
  end;      
end;

end.

⌨️ 快捷键说明

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