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

📄 inoutform.pas

📁 库房管理系统
💻 PAS
字号:
unit InoutForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, FR_E_HTML2, FR_E_CSV, FR_E_RTF, frexpimg, frOLEExl, FR_Class,
  FR_E_TXT, FR_DSet, FR_DBSet, DB, ADODB, StdCtrls, DBCtrls, DBCtrlsEh,
  Mask, Buttons, Grids, DBGrids;

type
  TINstockOut = class(TForm)
    grp1: TGroupBox;
    grp2: TGroupBox;
    dbgrd1: TDBGrid;
    grp3: TGroupBox;
    Label1: TLabel;
    add: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn3: TBitBtn;
    savebtn: TBitBtn;
    canbtn: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    BitBtn9: TBitBtn;
    BitBtn10: TBitBtn;
    grp4: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    DBEdit1: TDBEdit;
    DBEdit5: TDBEdit;
    dbqty: TDBEdit;
    DBEdit8: TDBEdit;
    DBEdit11: TDBEdit;
    DBEdit12: TDBEdit;
    DBEdit13: TDBEdit;
    dbdate: TDBDateTimeEditEh;
    DBEdit10: TDBEdit;
    DBEdit15: TDBEdit;
    Adoconstractoutput: TADOQuery;
    constractoutput_ds: TDataSource;
    stock_rpt: TfrReport;
    frDBDataSet1: TfrDBDataSet;
    frTextExport1: TfrTextExport;
    frOLEExcelExport1: TfrOLEExcelExport;
    frJPEGExport1: TfrJPEGExport;
    frRTFExport1: TfrRTFExport;
    frCSVExport1: TfrCSVExport;
    frHTML2Export1: TfrHTML2Export;
    comb_product: TDBComboBox;
    product_name: TDBEdit;
    dbmoney: TDBComboBox;
    ADO_Product: TADOTable;
    ADO_money: TADOTable;
    ADO_unit: TADOTable;
    dbunit: TDBComboBox;
    Label15: TLabel;
    ado_temp: TADOQuery;
    Ado_Mtr_updt: TADOQuery;
    Ado_Mtr_Updt_BOM: TADOQuery;
    Mtr_check: TADOQuery;
    ADO_ProductfParentID: TWideStringField;
    ADO_unitfUnitCode: TWideStringField;
    ADO_unitfbaseUnits: TWideStringField;
    ADO_moneyfMoneyCode: TWideStringField;
    RefUnit: TDBComboBox;
    out_put: TfrReport;
    dataset_stock: TfrDBDataSet;
    Ado_stock: TADOQuery;
    ds_stock: TDataSource;
    weightUnit: TDBEdit;
    measureunit: TDBEdit;
    stocktxt: TLabel;
    outputtxt: TLabel;
    stocktxt2: TLabel;
    outputtxt2: TLabel;
    stock_ado: TADOQuery;
    QProducts: TADOQuery;
    updtByInput: TADOQuery;
    procedure addClick(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure savebtnClick(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure canbtnClick(Sender: TObject);
    procedure BitBtn10Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure comb_productChange(Sender: TObject);
    procedure AdoconstractoutputAfterPost(DataSet: TDataSet);
    procedure AdoconstractoutputBeforePost(DataSet: TDataSet);
    procedure BitBtn9Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  INstockOut: TINstockOut;

implementation
 uses MainFm;

{$R *.dfm}

procedure TINstockOut.addClick(Sender: TObject);
begin
   Adoconstractoutput.Append;
   savebtn.Enabled:=true;
   dbdate.Value:=now();
   add.Enabled:=False;
   canbtn.Enabled:=true;
end;

procedure TINstockOut.BitBtn2Click(Sender: TObject);
begin
   if messagebox(Handle,PChar('sure to delete?'),'warning',mb_iconwarning+mb_yesno)=IDYES then
     Adoconstractoutput.Delete;
end;

procedure TINstockOut.savebtnClick(Sender: TObject);
begin                 //check the stock if not exist the product then msg can't continue
  if (trim(comb_product.Text)<>'') and (trim(product_name.text)<>'') and (trim(dbqty.text)<>'') and (trim(measureunit.text)<>'') then
     begin
     Adoconstractoutput.Post;
     savebtn.Enabled:=false;
   //  add.Enabled:=true;
     canbtn.Enabled:=true;
      end
   else
     begin
     showmessage('please check the information if intact');
     end;
end;

 //   if spGetProducts.Locate('fID',(Sender as TField).AsInteger,[]) then
//   QDetail.FieldByName('fTotalQty').AsFloat := spGetProducts.fieldbyName('rSumQty').AsFloat;
//if QProducts.Locate('fID',(Sender as TField).AsInteger,[]) then
 //  QDetail.FieldByName('fPrePrice').AsFloat := QProducts.fieldbyName('fPrePrice').AsFloat
 //  else
 //  Raise Exception.Create('无此产品!')
//   with stock_ado do
 //  stock_ado.Close;
  // stock_ado.SQL.Clear;
 //  stock_ado.sql.Text:='select fweightqty,fmeasureqty,fmeasureUnit,fweightUnit from tContractstock where fProductID like '+''''+ Adoconstractoutput.fieldbyname('fProductID').AsString+'''';
 //  stock_ado.Open;
 //  stocktxt.Caption:='库存量:'+stock_ado.fieldbyname('fmeasureqty').AsString;
 //  stocktxt2.Caption:='库重量'+ stock_ado.fieldbyname('fweightqty').AsString;
 //  outputtxt.Caption:='出库量:'+Adoconstractoutput.fieldbyname('fmeasureqty').AsString;
//   outputtxt2.Caption:='出库重'+ Adoconstractoutput.fieldbyname('fweightqty').AsString;


 //   if  stock_ado.fieldbyname('fmeasureqty').AsVariant<Adoconstractoutput.fieldbyname('fmeasureqty').AsVariant then
 //  begin
  //  showmessage('注:库存量不够!现该产品库存量只:'+stocktxt.Caption+stock_ado.fieldbyname('fmeasureUnit').AsString);
//    showmessage(stocktxt.Caption);
  // if messagebox(Handle,PChar('sure to save?'),'warning',mb_iconwarning+mb_yesno)=IDYES then
   //  begin

  //   end;
  // end
  //else
//   begin
 //  showmessage('measuer save successed!');
  //   Adoconstractoutput.Post;
 //    savebtn.Enabled:=false;
 //    add.Enabled:=true;
  // end;
  //  if  stock_ado.fieldbyname('fweightqty').AsVariant<Adoconstractoutput.fieldbyname('fweightqty').AsVariant then
 //  begin
   // showmessage('注:库存量不够!现该产品库存量只:'+stocktxt2.Caption+stock_ado.fieldbyname('fweightUnit').AsString);
//    showmessage(stocktxt.Caption);
 //  if messagebox(Handle,PChar('sure to save?'),'warning',mb_iconwarning+mb_yesno)=IDYES then
  //   begin
  //   Adoconstractoutput.Post;
  //   savebtn.Enabled:=false;
  //   add.Enabled:=true;
  //   end;
//   end
  //  else
 //    begin
 //  showmessage('weight save successed!');
  //   Adoconstractoutput.Post;
   //  savebtn.Enabled:=false;
   //  add.Enabled:=true;
 //    end;


procedure TINstockOut.BitBtn3Click(Sender: TObject);
begin
  Adoconstractoutput.Edit;
  savebtn.Enabled:=true;
  canbtn.Enabled:=true;
end;

procedure TINstockOut.canbtnClick(Sender: TObject);
begin
  Adoconstractoutput.Cancel;
end;

procedure TINstockOut.BitBtn10Click(Sender: TObject);
begin
  out_put.ShowReport;
end;

procedure TINstockOut.FormCreate(Sender: TObject);
  var i:integer;
begin
 with ado_product do
   if ado_product.RecordCount>0 then
   begin
    ado_product.first;
    for i:=0 to ado_product.RecordCount-1 do
     begin
     comb_product.Items.Add(ado_product.fieldbyname('fParentID').AsString);
     ado_product.Next;
     end;
   end;
    with ado_unit do
    if ado_unit.RecordCount>0 then
    begin
     ado_unit.First;
    for i:=0 to ado_unit.RecordCount-1 do
     begin
    dbunit.Items.Add(ado_unit.fieldbyname('fUnitCode').AsString);
    refunit.Items.Add(ado_unit.fieldbyname('fbaseUnits').AsString);
    ado_unit.Next;
     end;
    end;
     with ado_money do
    if ado_money.RecordCount>0 then
    begin
     ado_money.First;
    for i:=0 to ado_money.RecordCount-1 do
     begin
    dbmoney.Items.Add(ado_money.fieldbyname('fMoneyCode').AsString);
    ado_money.Next;
     end;
    end;
end;

procedure TINstockOut.comb_productChange(Sender: TObject);
begin
      with ado_temp do
   ado_temp.Close;
   ado_temp.SQL.Clear;       //check the product from the tcontractstock then ok
   ado_temp.SQL.Add('select fParentName,fMeasureUnit,fWeightUnit from tProductCode where fParentID like '''+'%'+comb_product.Text+'%'+'''');
   ado_temp.open;
  // edit1.Text:=ado_temp.SQL.text;
   product_name.Text:=ado_temp.fieldbyname('fParentName').AsString;
   dbunit.Items.Text:=ado_temp.fieldbyname('fMeasureUnit').AsString;
   RefUnit.Items.Text:=ado_temp.fieldbyname('fWeightUnit').AsString;
   measureunit.Text:=ado_temp.fieldbyname('fMeasureUnit').AsString;
   weightUnit.Text:=ado_temp.fieldbyname('fWeightUnit').AsString;
//end;
end;

procedure TINstockOut.AdoconstractoutputAfterPost(DataSet: TDataSet);
begin
   with ado_temp do      //the same maybe update the tProductStockStock's quanlity
     begin        //if need update the tProductStockStock's product 's quanlity for the update
      ado_temp.Close;                  //update tContractOutput record and update the tContractstock
      ado_temp.Prepared:=false;
      ado_temp.SQL.Text:='insertProductStockbyInput'+ ''''+Adoconstractoutput.fieldbyname('fProductID').AsString+'''';
      ado_temp.Prepared:=True;
      ado_temp.ExecSQL;
     end;

   with updtByInput do      //the same maybe update the tProductStockStock's quanlity
     begin        //if need update the tProductStockStock's product 's quanlity for the update
      updtByInput.Close;                  //update tContractOutput record and update the tContractstock
      updtByInput.Prepared:=false;
      updtByInput.SQL.Text:='updtProductStockbyInput'+ ''''+Adoconstractoutput.fieldbyname('fProductID').AsString+'''';
      updtByInput.Prepared:=True;
      updtByInput.ExecSQL;
     end;

  //updtMtrQtybyBOM  update the tMaterialOutput table after the tcontractoutput reference BOM
  with Mtr_check do
     begin          //p_checkbyMtr  'hp025001'
        Mtr_check.Close;                       //from the BOM (tMaterail) to check the fMtrCode
        Mtr_check.Prepared:=false;
        Mtr_check.SQL.Text:='p_checkbyMtr' + ''''+Adoconstractoutput.fieldbyname('fProductID').AsString+'''';
        Mtr_check.Prepared:=True;
        Mtr_check.Open;        
     end;

  with Ado_Mtr_Updt_BOM do             //update the tMaterialOutput table by the tContractoutput
    begin
     Ado_Mtr_Updt_BOM.Close;               //this is very important that must the tMaterialoutput and Bom out then ok
     Ado_Mtr_Updt_BOM.Prepared:=false;
     Ado_Mtr_Updt_BOM.SQL.Text:='updtMtrQtybyBOM' +''''+Mtr_check.fieldbyname('fMtrCode').AsString+'''';
     Ado_Mtr_Updt_BOM.Prepared:=True;
     Ado_Mtr_Updt_BOM.ExecSQL;
    end;

   with Ado_Mtr_updt do       //if the tMaterialstock not exists the material information then message wrong...
     begin                          //update the tMaterialStock qty from the tMaterailoutput
     Ado_Mtr_updt.Close;               //this is very important that must the tMaterialoutput and Bom out then ok
     Ado_Mtr_updt.Prepared:=false;
     Ado_Mtr_updt.SQL.Text:='updtMtrQtybyOutput' +''''+Mtr_check.fieldbyname('fMtrCode').AsString+'''';
     Ado_Mtr_updt.Prepared:=True;
     Ado_Mtr_updt.ExecSQL;
     end;

end;

procedure TINstockOut.AdoconstractoutputBeforePost(DataSet: TDataSet);
begin
//  if QProducts.Locate('fProductID',Adoconstractoutput.fieldbyname('fProductID').AsString,[]) then
 //  begin
//   QDetail.FieldByName('fPrePrice').AsFloat := QProducts.fieldbyName('fPrePrice').AsFloat
    //with ado_temp do
//   ado_temp.Close;
//   ado_temp.SQL.Clear;
//   ado_temp.sql.Text:='select fweightqty,fmeasureqty,fmeasureUnit,fweightUnit from tContractstock where fProductID like '+''''+ Adoconstractoutput.fieldbyname('fProductID').AsString+'''';
//   Ado_temp.Open;
 //  stocktxt.Caption:='库存量:'+ado_temp.fieldbyname('fmeasureqty').AsString;
 //  stocktxt2.Caption:='库重量:'+ ado_temp.fieldbyname('fweightqty').AsString;
 //  outputtxt.Caption:='出库量:'+Adoconstractoutput.fieldbyname('fmeasureqty').AsString;
 //  outputtxt2.Caption:='出库重:'+ Adoconstractoutput.fieldbyname('fweightqty').AsString;
  // if  ado_temp.fieldbyname('fmeasureqty').AsVariant<Adoconstractoutput.fieldbyname('fmeasureqty').AsVariant then
 //  begin
  //  showmessage('注:库存量不够!现该产品库存量只:'+stocktxt.Caption+ado_temp.fieldbyname('fmeasureUnit').AsString);
//    showmessage(stocktxt.Caption);
 //  end
 //  else
 //  showmessage('measuer save successed!');
 //   if  ado_temp.fieldbyname('fweightqty').AsVariant<Adoconstractoutput.fieldbyname('fweightqty').AsVariant then
  // begin
//    showmessage('注:库存量不够!现该产品库存量只:'+stocktxt2.Caption+ado_temp.fieldbyname('fweightUnit').AsString);
//    showmessage(stocktxt.Caption);
//   end
 //  else
//   showmessage('weight save successed!')
 // end
 //  else

 //   begin
   //   Raise Exception.Create('成品库存中无此产品库存,请确认资料之准确性!');
   //   comb_product.SetFocus;
  //  end;

end;
procedure TINstockOut.BitBtn9Click(Sender: TObject);
begin
  Adoconstractoutput.Close;
  Adoconstractoutput.Open;
 // Adoconstractoutput.Refresh;
end;

procedure TINstockOut.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Adoconstractoutput.State in [dsInsert,dsEdit] then
  //  if  Ado_Material.Modified  then
      begin
       if MessageBox(Handle, PChar('数据未保存,确定要退出吗?'), MsgQst, Msg2YNWARN) = IDYES then
 // if MessageBox(Handle,pchar('warning'),mB_iconQuestion,mb_YESNO)=IDyes then
   //   self.Hide;
      Action:=caHide
 //     end
      else
      Action:=caNone;
     end;
end;

end.

⌨️ 快捷键说明

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