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

📄 unitgj.pas

📁 手机批发商进销存管理
💻 PAS
📖 第 1 页 / 共 2 页
字号:

    //刷新显示
    DateTimePicker1Change(Sender);
    
    ComboBox1.SetFocus;
  except
    DM1.ADOConnection1.RollbackTrans;
    DM1.ADOQuery1.Close;
    Application.MessageBox('保存失败,可能此串号的商品已经存在!', '提示', MB_OK + MB_ICONINFORMATION);
  end;
end;

procedure TGjForm.FormResize(Sender: TObject);
begin
  Panel_Db_Left.Width := (Width - 78) div 2;
  Panel_Db_Right.Width := (Width - 78) div 2;
end;

procedure TGjForm.SpeedButton1Click(Sender: TObject);
begin
  TGoodsNameTypeForm.Create(Self, 'GjForm').ShowModal;
end;

procedure TGjForm.ComboBox1Change(Sender: TObject);
var
  i: integer;
  tmpstr: string;
  ts: TStrings;
begin
  tmpstr := Trim(ComboBox1.Text);
  ComboBox2.Items.Clear;
  for i:=0 to TsGoodsNameType.Count-1 do
  begin
    ts := TStrings(TsGoodsNameType.Objects[i]);
    if (ComboBox2.Items.IndexOf(ts.Strings[1])<0)and(ts.Strings[0]=tmpstr) then
      ComboBox2.Items.Add(ts.Strings[1]);
  end;
  ComboBox2.Text := '';
end;

procedure TGjForm.ADOQuery1CalcFields(DataSet: TDataSet);
begin
  if ADOQuery1IsSale.AsInteger=0 then
    ADOQuery1Sale.Value := '未售'
  else
    ADOQuery1Sale.Value := '已售';
end;

procedure TGjForm.DateTimePicker1Change(Sender: TObject);
begin
  try
    ADOQuery1.DisableControls;
    ADOQuery1.Close;
    ADOQuery1.SQL.Text := ' select A.*,B.* from Tab_Goods A '
                         +' left join Tab_GoodsNo B on A.GoodsNo=B.GoodsNo '
                         +' where A.IsSale=0 and A.GoodsOwner=''总仓'' '
                         +' and A.InDate=''' + FormatDateTime('yyyymmdd', DateTimePicker1.DateTime) + ''' '
                         +' order by B.GoodsName, B.GoodsType ';
    ADOQuery1.Open;
    ADOQuery1.Last;
  finally
    ADOQuery1.EnableControls;
  end;
end;

procedure TGjForm.BitBtn2Click(Sender: TObject);
var
  tmpStr: string;
  s1, s2, S3: string;
begin
  if not ADOQuery1.Active then Exit;
  if ADOQuery1.IsEmpty then Exit;
  if ADOQuery1.FieldByName('IsSale').AsInteger<>0 then
  begin
    Application.MessageBox('已经销售的商品不能删除!如要删除,请先返销,然后退回总仓!','提示',MB_OK + MB_ICONWARNING);
    Exit;
  end;
  if ADOQuery1.FieldByName('GoodsOwner').AsString<>'总仓' then
  begin
    Application.MessageBox('已经调到柜台的商品不能删除!如要删除,请退回总仓!','提示',MB_OK + MB_ICONWARNING);
    Exit;
  end;
  tmpStr := '是否真的要删除串号为 ' + ADOQuery1.FieldByName('GoodsNo').AsString + ' 的商品?删除后不可恢复';
  if Application.MessageBox(PChar(tmpStr),'请确认',MB_OKCancel + MB_DEFBUTTON2 + MB_IconQuestion)<>ID_OK then Exit;

  try
    s1 := ADOQuery1.FieldByName('GoodsNo').AsString;

    DM1.ADOConnection1.BeginTrans;

    DM1.ADOQuery1.Close;
    DM1.ADOQuery1.SQL.Clear;
    DM1.ADOQuery1.SQL.Text := 'select * from Tab_GoodsNo where GoodsNo=:GoodsNo';
    DM1.ADOQuery1.Parameters.ParamByName('GoodsNo').Value := s1;
    DM1.ADOQuery1.Open;
    s2 := DM1.ADOQuery1.FieldByName('GoodsName').AsString;
    s3 := DM1.ADOQuery1.FieldByName('GoodsType').AsString;

    //删除品名机型编码表
    DM1.ADOQuery1.Close;
    DM1.ADOQuery1.SQL.Clear;
    DM1.ADOQuery1.SQL.Text := 'delete from Tab_GoodsNameType where GoodsName=:GoodsName and GoodsType=:GoodsType';
    DM1.ADOQuery1.Parameters.ParamByName('GoodsName').Value := s2;
    DM1.ADOQuery1.Parameters.ParamByName('GoodsType').Value := s3;
    DM1.ADOQuery1.ExecSQL;

    //删除商品表
    DM1.ADOQuery1.Close;
    DM1.ADOQuery1.SQL.Clear;
    DM1.ADOQuery1.SQL.Text := 'delete from Tab_Goods where GoodsNo=:GoodsNo';
    DM1.ADOQuery1.Parameters.ParamByName('GoodsNo').Value := s1;
    DM1.ADOQuery1.ExecSQL;

    //删除商品编码表
    DM1.ADOQuery1.Close;
    DM1.ADOQuery1.SQL.Clear;
    DM1.ADOQuery1.SQL.Text := 'delete from Tab_GoodsNo where GoodsNo=:GoodsNo';
    DM1.ADOQuery1.Parameters.ParamByName('GoodsNo').Value := s1;
    DM1.ADOQuery1.ExecSQL;

    DM1.ADOConnection1.CommitTrans;

    DM1.ADOQuery1.Close;

    //刷新显示
    DateTimePicker1Change(Sender);

  except
    DM1.ADOConnection1.RollbackTrans;
    DM1.ADOQuery1.Close;
  end;
end;

procedure TGjForm.SpeedButton3Click(Sender: TObject);
begin
  TSetupForm.Create(nil).ShowModal;
  ComboBox6.Items.Assign(TsGoodsOwner);
end;

procedure TGjForm.ComboBox4KeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then BitBtn6.Click;
end;

procedure TGjForm.ComboBox7KeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then BitBtn3.Click;
end;

procedure TGjForm.ComboBox6Change(Sender: TObject);
begin
  ComboBox7.ItemIndex := 0;
  Edit3.Clear;
  BitBtn3.Click;
end;

procedure TGjForm.BitBtn6Click(Sender: TObject);
var
  s1, s2: string;
  sql: string;
begin
  s1 := Trim(ComboBox4.Items.Strings[ComboBox4.ItemIndex]);
  s2 := Trim(Edit2.Text);
  ADODataSet1.Close;
  sql := ' select A.*,B.* from Tab_Goods A left join Tab_GoodsNo B on A.GoodsNo=B.GoodsNo '
        +' where A.IsSale=0 and A.GoodsOwner=''总仓'' ';
  if s1<>'' then sql := sql + ' and B.GoodsName= ''' + s1 + '''';
  if s2<>'' then sql := sql + ' and A.GoodsNo= ''' + s2 + '''';
  sql := sql +' order by A.InDate, B.GoodsName, B.GoodsType ';
  ADODataSet1.CommandText := sql;
  ADODataSet1.Open;
end;

procedure TGjForm.BitBtn3Click(Sender: TObject);
var
  s1, s2: string;
  sql: string;
begin
  s1 := Trim(ComboBox7.Items.Strings[ComboBox7.ItemIndex]);
  s2 := Trim(Edit3.Text);
  ADODataSet2.Close;
  sql := ' select A.*,B.* from Tab_Goods A left join Tab_GoodsNo B on A.GoodsNo=B.GoodsNo '
        +' where A.IsSale=0 ';
  if Trim(ComboBox6.Items.Strings[ComboBox6.ItemIndex])<>'' then
  begin
    sql := sql + ' and A.GoodsOwner=''' + Trim(ComboBox6.Items.Strings[ComboBox6.ItemIndex]) + ''' ';
    if s1<>'' then sql := sql + ' and B.GoodsName= ''' + s1 + '''';
    if s2<>'' then sql := sql + ' and A.GoodsNo= ''' + s2 + '''';
    sql := sql + ' order by A.InDate, B.GoodsName, B.GoodsType ';
    ADODataSet2.CommandText := sql;
    ADODataSet2.Open;
  end;
end;

procedure TGjForm.RzBitBtn2Click(Sender: TObject);
var
  s1, s2: string;
begin
  if not ADODataSet1.Active then Exit;
  if ADODataSet1.IsEmpty then Exit;
  s1 := ADODataSet1.FieldByName('GoodsNo').AsString;//串号
  s2 := Trim(ComboBox6.Items.Strings[ComboBox6.ItemIndex]);//柜台
  if (s1='') or (s2='') then Exit;
  
//调出总仓
  try
    DM1.ADOConnection1.BeginTrans;

    DM1.ADOQuery1.Close;
    DM1.ADOQuery1.SQL.Clear;
    DM1.ADOQuery1.SQL.Text := 'update Tab_Goods set GoodsOwner=:GoodsOwner where GoodsNo=:GoodsNo and IsSale=0 and GoodsOwner=''总仓'' ';
    DM1.ADOQuery1.Parameters.ParamByName('GoodsOwner').Value := s2;
    DM1.ADOQuery1.Parameters.ParamByName('GoodsNo').Value := s1;
    DM1.ADOQuery1.ExecSQL;

    DM1.ADOConnection1.CommitTrans;

    DM1.ADOQuery1.Close;

    //刷新显示
    BitBtn6.Click;
    BitBtn3.Click;

  except
    DM1.ADOConnection1.RollbackTrans;
    DM1.ADOQuery1.Close;
  end;
end;

procedure TGjForm.RzBitBtn3Click(Sender: TObject);
var
  s1, s2: string;
begin
  if not ADODataSet2.Active then Exit;
  if ADODataSet2.IsEmpty then Exit;
  if ADODataSet2.FieldByName('IsSale').AsInteger<>0 then
  begin
    Application.MessageBox('已经销售的商品不能退回!如要退回,请先返销!','提示',MB_OK + MB_ICONWARNING);  
    Exit;
  end;
  s1 := ADODataSet2.FieldByName('GoodsNo').AsString;//串号
  s2 := Trim(ComboBox6.Items.Strings[ComboBox6.ItemIndex]);//柜台
  if (s1='') or (s2='') then Exit;
  
//调回总仓
  try
    DM1.ADOConnection1.BeginTrans;

    DM1.ADOQuery1.Close;
    DM1.ADOQuery1.SQL.Clear;
    DM1.ADOQuery1.SQL.Text := 'update Tab_Goods set GoodsOwner=''总仓'' where GoodsNo=:GoodsNo and IsSale=0 and GoodsOwner=:GoodsOwner ';
    DM1.ADOQuery1.Parameters.ParamByName('GoodsNo').Value := s1;
    DM1.ADOQuery1.Parameters.ParamByName('GoodsOwner').Value := s2;    
    DM1.ADOQuery1.ExecSQL;

    DM1.ADOConnection1.CommitTrans;

    DM1.ADOQuery1.Close;

    //刷新显示
    BitBtn6.Click;
    BitBtn3.Click;

  except
    DM1.ADOConnection1.RollbackTrans;
    DM1.ADOQuery1.Close;
  end;
end;

procedure TGjForm.RzPageControl1Change(Sender: TObject);
begin
  FormCreate(Sender);
  if RzPageControl1.ActivePageIndex=0 then
    DateTimePicker1.SetFocus
  else
    ComboBox6.SetFocus;
end;

procedure TGjForm.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then RzBitBtn1.SetFocus;
end;

procedure TGjForm.FormActivate(Sender: TObject);
begin
  RzPageControl1.ActivePageIndex := 0;
  DateTimePicker1.SetFocus;
end;

end.

⌨️ 快捷键说明

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