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

📄 stock_unit.pas

📁 药品进销管理程序,内有SQL附加的数据库.....详情看里面的,运行就OK
💻 PAS
字号:
unit Stock_Unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls, Grids, DBGrids, Buttons,
  DB, DBCtrls, RpCon, RpConDS, RpBase, RpSystem, RpDefine, RpRave, ADODB,
  RpRender, RpRenderCanvas, RpRenderPreview;

type
  TfrmStock = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    lblStockID: TLabel;
    cmbxProviderID: TComboBox;
    dtpStockDatetime: TDateTimePicker;
    edtRemark: TMemo;
    DBGrid1: TDBGrid;
    Label4: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    cmbxMedicineID: TComboBox;
    edtByPrice: TEdit;
    edtJobPrice: TEdit;
    edtRetailPrice: TEdit;
    edtAmount: TEdit;
    btnAdd: TBitBtn;
    btnPrint: TBitBtn;
    btnDel: TBitBtn;
    btnSave: TBitBtn;
    btnAuditing: TBitBtn;
    btnFind: TBitBtn;
    lblAuditing: TLabel;
    dsrStock: TDataSource;
    DBNavigator1: TDBNavigator;
    RvProject1: TRvProject;
    RvDataSetConnection1: TRvDataSetConnection;
    qryStockHeader: TADOQuery;
    qryProvider: TADOQuery;
    qryMedicine: TADOQuery;
    qryStockBody: TADOQuery;
    qryAudtiting: TADOQuery;
    qryPrint: TADOQuery;
    RvSystem1: TRvSystem;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cmbxProviderIDExit(Sender: TObject);
    procedure cmbxMedicineIDExit(Sender: TObject);
    procedure btnFindClick(Sender: TObject);
    procedure DBGrid1CellClick(Column: TColumn);
    procedure btnDelClick(Sender: TObject);
    procedure btnSaveClick(Sender: TObject);
    procedure btnAuditingClick(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmStock: TfrmStock;

implementation

uses Common_Unit, LeechdomMain_Unit;

{$R *.dfm}


procedure TfrmStock.FormShow(Sender: TObject);
var
  SelectStrPro,SelectStrMed, sID, sName: string;
begin
  dtpStockDatetime.Date := Date;
  SelectStrPro := 'Select * From Provider';
  cmbxProviderID.Items.Clear;
  OpenDataSQL(qryProvider, SelectStrPro);
  with qryProvider do
  begin
    while not Eof do
    begin
      sID := FieldByName('ProviderID').AsString;
      sName := FieldByName('ProName').AsString;
      cmbxProviderID.Items.Add(sID + '.' + sName);
      Next;
    end;
  end;
  
  SelectStrMed := 'Select * From Medicine';
  cmbxMedicineID.Items.Clear;
  OpenDataSQL(qryMedicine, SelectStrMed);
  with qryMedicine do
  begin
    while not Eof do
    begin
      sID := FieldByName('MedicineID').AsString;
      sName := FieldByName('MedName').AsString;
      cmbxMedicineID.Items.Add(sID + '.' + sName);
      Next;
    end;
  end;
end;

procedure TfrmStock.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
  frmStock := nil;
end;

procedure TfrmStock.btnAddClick(Sender: TObject);
var
  InsertHeaderStr, MaxID: string;
begin
  qryStockBody.Close;
  cmbxProviderID.Text := '';
  cmbxMedicineID.Text := '';
  edtByPrice.Text := '';
  edtJobPrice.Text := '';
  edtRetailPrice.Text := '';
  edtAmount.Text := '';
  lblAuditing.Caption := '未审核';
  MaxID := 'Exec proc_StockTask @Flag=''SelectMaxID''' ;
  OpenDataSQL(frmLeechdomMain.qryMaxID, MaxID);
  if frmLeechdomMain.qryMaxID.FieldByName('MaxID').AsString = '' then
    lblStockID.Caption := 'PR' + FormatDatetime('yyyymm',Date) + '0001'
  else
    lblStockID.Caption := 'PR' + frmLeechdomMain.qryMaxID.FieldByName('MaxID').AsString;
end;

procedure TfrmStock.cmbxProviderIDExit(Sender: TObject);
begin
  cmbxProviderID.Text := Copy(cmbxProviderID.Text,1,Pos('.',cmbxProviderID.Text)-1);
end;

procedure TfrmStock.cmbxMedicineIDExit(Sender: TObject);
begin
  cmbxMedicineID.Text := Copy(cmbxMedicineID.Text,1,Pos('.',cmbxMedicineID.Text)-1);
end;

procedure TfrmStock.btnFindClick(Sender: TObject);
var
  SelectAll, FindID: string;
  FindBool: Boolean;
begin
  try
    FindID := lblStockID.Caption;
    FindBool := InputQuery('查询', '输入查询的编号', FindID);
    if FindBool then
    begin
      if lblStockID.Caption = '自动生成' then Exit;
      SelectAll := 'Exec proc_StockTask @Flag=''SelectStock'''
                  +',@StockID=' + Quotedstr(FindID);
      OpenDataSQL(qryStockBody, SelectAll);
      OpenDataSQL(qryStockHeader, SelectAll);
      lblStockID.Caption := qryStockHeader.FieldByName('StockID').AsString;
      cmbxProviderID.Text := qryStockHeader.FieldByName('ProviderID').AsString;
      dtpStockDatetime.Date := StrToDate(qryStockHeader.FieldByName('StockDatetime').AsString);
      lblAuditing.Caption := qryStockHeader.FieldByName('Auditing').AsString;
      edtRemark.Text := qryStockHeader.FieldByName('Remark').AsString;
    end;
  except
    Application.MessageBox('查询错误,请核实后重新查询!','错误',16);
    lblStockID.Caption := '自动生成';
  end;
end;

procedure TfrmStock.DBGrid1CellClick(Column: TColumn);
begin    { TODO : 数据为空的时候报错 }
  if DBGrid1.DataSource.DataSet.IsEmpty then
    Exit;
  if qryStockBody.Active then
  begin
    cmbxMedicineID.Text := DBGrid1.DataSource.DataSet.FieldByName('MedicineID').AsString;
    edtByPrice.Text := DBGrid1.DataSource.DataSet.FieldByName('ByPrice').AsString;
    edtJobPrice.Text := DBGrid1.DataSource.DataSet.FieldByName('JobPrice').AsString;
    edtRetailPrice.Text := DBGrid1.DataSource.DataSet.FieldByName('RetailPrice').AsString;
    edtAmount.Text := DBGrid1.DataSource.DataSet.FieldByName('Amount').AsString;
  end;
end;

procedure TfrmStock.btnDelClick(Sender: TObject);
var
  DelBodyStr,DelHeadStr, SelectBody, SelectAll: string;
begin
  if lblAuditing.Caption = '已审核' then
  begin
    Application.MessageBox('已审核不能修改!','提示',16);
    Exit;
  end;
  if DBGrid1.DataSource.DataSet.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除此条信息吗?','提示',68) = IDYes then
  begin
    DelBodyStr := 'Exec proc_StockTask @Flag=''DelStock'''
            + ',@StockID=' + Quotedstr(lblStockID.Caption)
            + ',@MedID=' + Quotedstr(cmbxMedicineID.Text);
    DelHeadStr := 'Exec proc_StockTask @Flag=''DelHeader'''
                + ',@StockID = ' + QuotedStr(lblStockID.Caption);
    ExecSQL(qryStockBody,DelBodyStr);
    if FindSQL('Select * From StockBody where StockID=' + QuotedStr(lblStockID.Caption)) = False then
      ExecSQL(qryStockHeader,DelHeadStr);
    SelectAll := 'Exec proc_StockTask @Flag=''SelectStock'''
                +',@StockID=' + Quotedstr(lblStockID.Caption);
    OpenDataSQL(qryStockBody, SelectAll);
    Application.MessageBox('明细删除成功!','提示',64);
  end;
end;

procedure TfrmStock.btnSaveClick(Sender: TObject);
var
  InsertHeader, InsertBody, SelectBody: string;
begin
  try
    if lblAuditing.Caption = '已审核' then
    begin
      Application.MessageBox('已审核不能再保存数据!','提示',16);
      Exit;
    end;
    if (cmbxMedicineID.Text = '') or (edtByPrice.Text = '') or (edtJobPrice.Text = '') or (edtRetailPrice.Text = '') then
    begin
      Application.MessageBox('明细数据不能为空!','错误',16);
      cmbxMedicineID.SetFocus;
      Exit;
    end;
    if lblStockID.Caption = '自动生成' then
    begin
      Application.MessageBox('主项数据没有单号,请添加!','错误',16);
      Exit;
    end;
    InsertHeader := 'Exec proc_StockTask @Flag=''InsertHeader'''
                 + ',@StockID=' + Quotedstr(lblStockID.Caption)
                 + ',@ProviderID=' + Quotedstr(cmbxProviderID.Text)
                 + ',@StockDatetime=' + Quotedstr(DateToStr(Date))
                 + ',@TabMan=' + Quotedstr(LoginID)       
                 + ',@Remark=' + Quotedstr(edtRemark.Text);

    InsertBody := 'Exec proc_StockTask @Flag=''InsertBody'''
                + ',@StockID=' + Quotedstr(lblStockID.Caption)
                + ',@MedID=' + Quotedstr(cmbxMedicineID.Text)
                + ',@ByPrice=' + edtByPrice.Text
                + ',@JobPrice=' + edtJobPrice.Text
                + ',@RetailPrice=' + edtRetailPrice.Text
                + ',@Amount=' + edtAmount.Text;

    SelectBody := 'Exec proc_StockTask @Flag=''SelectStock'''
                 +',@StockID='  + QUotedstr(lblStockID.Caption);
    ExecSQL(qryStockHeader,InsertHeader);
    ExecSQL(qryStockBody,InsertBody);
    OpenDataSQL(qryStockBody, SelectBody)
  except
    Application.MessageBox('保存数据错误,请查实!','错误',16); 
  end;
end;

procedure TfrmStock.btnAuditingClick(Sender: TObject);
var
  Auditing: string;
begin
  if lblAuditing.Caption = '已审核' then
  begin
    Application.MessageBox('不能重复审核!','提示',16);
    Exit;
  end;
  if DBGrid1.DataSource.DataSet.IsEmpty then
    Exit;
  if Application.MessageBox('确定要审核此单吗?','提示',68) = IDNo then
    Exit;
  Auditing := 'Exec proc_StockTask @Flag=''Auditing'''
             +',@StockID=' + Quotedstr(lblStockID.Caption);
  ExecSQL(qryAudtiting,Auditing);
  Application.MessageBox('审核成功!','提示',64);
  lblAuditing.Caption := '已审核';
end;

procedure TfrmStock.btnPrintClick(Sender: TObject);
var
  PrintSQL: string;
begin
  PrintSQL := 'Select A.*,B.*,C.ProName,D.MedName From'
            + ' StockHeader A left join'
            + ' StockBody B on A.StockID=B.StockID'
            + ' Left Join Provider C on A.ProviderID=C.ProviderID'
            + ' Left Join Medicine D on B.MedicineID=D.MedicineID'
            + ' where A.StockID =' + QuotedStr(lblStockID.Caption);
  if lblStockID.Caption = '自动生成' then Exit;
  OpenDataSQL(qryPrint, PrintSQL);
  RvProject1.ProjectFile :='.\StockReport.rav';
  RvProject1.Execute;
end;

end.

⌨️ 快捷键说明

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