📄 saledepot_unit.pas
字号:
unit SaleDepot_Unit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls, Grids, DBGrids, Buttons,
DB, ADODB, RpRender, RpRenderCanvas, RpRenderPreview, RpRave, RpDefine,
RpCon, RpConDS, RpBase, RpSystem;
type
TfrmSaleDepot = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
lblAuditing: TLabel;
lblSaleID: TLabel;
cmbxType: TComboBox;
SaleDatetime: TDateTimePicker;
edtRemark: TMemo;
DBGrid1: TDBGrid;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
cmbxMeicineID: TComboBox;
edtRetailPrice: TEdit;
edtAmount: TEdit;
ValidityDatetime: TDateTimePicker;
btnFind: TBitBtn;
btnAdd: TBitBtn;
btnDel: TBitBtn;
btnSave: TBitBtn;
btnPrint: TBitBtn;
btnAuditing: TBitBtn;
dsrSaleHeader: TDataSource;
qrySaleHeader: TADOQuery;
qryMedicine: TADOQuery;
qrySaleBody: TADOQuery;
dsrSaleBody: TDataSource;
qryPrint: TADOQuery;
RvDataSetConnection1: TRvDataSetConnection;
RvProject1: TRvProject;
RvSystem1: TRvSystem;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure btnAddClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cmbxMeicineIDExit(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
frmSaleDepot: TfrmSaleDepot;
implementation
uses Common_Unit, LeechdomMain_Unit;
{$R *.dfm}
procedure TfrmSaleDepot.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
frmSaleDepot := nil;
end;
procedure TfrmSaleDepot.btnAddClick(Sender: TObject);
var
InsertHeaderStr, MaxID: string;
begin
qrySaleBody.Close;
edtRemark.Text := '';
lblAuditing.Caption := '未审核';
cmbxMeicineID.Text := '';
edtRetailPrice.Text := '';
edtAmount.Text := '';
MaxID := 'Exec proc_Sale @Flag=''SelectMaxID''' ;
OpenDataSQL(frmLeechdomMain.qryMaxID, MaxID);
if frmLeechdomMain.qryMaxID.FieldByName('MaxID').AsString = '' then
lblSaleID.Caption := 'SH' + FormatDatetime('yyyymm',Date) + '0001'
else
lblSaleID.Caption := 'SH' + frmLeechdomMain.qryMaxID.FieldByName('MaxID').AsString;
end;
procedure TfrmSaleDepot.FormShow(Sender: TObject);
var
SelectStrMed, sID, sName: string;
begin
SelectStrMed := 'Select * From Medicine';
cmbxMeicineID.Items.Clear;
OpenDataSQL(qryMedicine, SelectStrMed);
with qryMedicine do
begin
while not Eof do
begin
sID := FieldByName('MedicineID').AsString;
sName := FieldByName('MedName').AsString;
cmbxMeicineID.Items.Add(sID + '.' + sName);
Next;
end;
end;
end;
procedure TfrmSaleDepot.cmbxMeicineIDExit(Sender: TObject);
begin
cmbxMeicineID.Text := Copy(cmbxMeicineID.Text,1,Pos('.',cmbxMeicineID.Text)-1);
end;
procedure TfrmSaleDepot.btnFindClick(Sender: TObject);
var
SelectAll, FindID: string;
FindBool: Boolean;
begin
try
FindID := lblSaleID.Caption;
FindBool := InputQuery('查询', '输入查询的编号', FindID);
if FindBool then
begin
SelectAll := 'Exec proc_Sale @Flag=''SelectSale'''
+',@SaleID=' + Quotedstr(FindID);
OpenDataSQL(qrySaleHeader, SelectAll);
OpenDataSQL(qrySaleBody, SelectAll);
lblSaleID.Caption := qrySaleHeader.FieldByName('SaleID').AsString;
cmbxType.Text := qrySaleHeader.FieldByName('SaleType').AsString;
edtRemark.Text := qrySaleHeader.FieldByName('Remark').AsString;
SaleDatetime.Date := StrToDate(qrySaleHeader.FieldByName('SaleDatetime').AsString);
lblAuditing.Caption := qrySaleHeader.FieldByName('Auditing').AsString;
end;
except
Application.MessageBox('查询错误,请核实后重新查询!','错误',16);
lblSaleID.Caption := '自动生成';
end;
end;
procedure TfrmSaleDepot.DBGrid1CellClick(Column: TColumn);
begin
if DBGrid1.DataSource.DataSet.IsEmpty then
Exit;
if qrySaleBody.Active then
begin
cmbxMeicineID.Text := DBGrid1.DataSource.DataSet.FieldByName('MedicineID').AsString;
edtRetailPrice.Text := DBGrid1.DataSource.DataSet.FieldByName('RetailPrice').AsString;
edtAmount.Text := DBGrid1.DataSource.DataSet.FieldByName('Amount').AsString;
ValidityDatetime.Date := DBGrid1.DataSource.DataSet.FieldByName('ValidityDatetime').AsDateTime;
end;
end;
procedure TfrmSaleDepot.btnDelClick(Sender: TObject);
var
DelBodyStr,DelHeadStr,SelectAll, SelectBody: 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_Sale @Flag=''DelSale'''
+ ',@SaleID=' + Quotedstr(lblSaleID.Caption)
+ ',@MedicineID=' + Quotedstr(cmbxMeicineID.Text)
+ ',@ValidityDatetime=' + Quotedstr(DateToStr(ValidityDatetime.Date));
DelHeadStr := 'Exec proc_Sale @Flag=''DelHeader'''
+ ',@SaleID=' + Quotedstr(lblSaleID.Caption);
ExecSQL(qrySaleBody,DelBodyStr);
if FindSQL('Select * From SaleBody where SaleID=' + QuotedStr(lblSaleID.Caption)) = False then
ExecSQL(qrySaleHeader,DelHeadStr);
SelectAll := 'Exec proc_Sale @Flag=''SelectSale'''
+',@SaleID=' + Quotedstr(lblSaleID.Caption);
OpenDataSQL(qrySaleBody, SelectAll);
Application.MessageBox('明细删除成功!','提示',64);
end;
end;
procedure TfrmSaleDepot.btnSaveClick(Sender: TObject);
var
InsertHeader, InsertBody, SelectBody: string;
begin
try
if lblAuditing.Caption = '已审核' then
begin
Application.MessageBox('已审核不能再保存数据!','提示',16);
Exit;
end;
if (cmbxMeicineID.Text = '') or (edtRetailPrice.Text = '') or (edtAmount.Text = '') then
begin
Application.MessageBox('明细数据不能为空!','错误',16);
cmbxMeicineID.SetFocus;
Exit;
end;
if lblSaleID.Caption = '自动生成' then
begin
Application.MessageBox('主项数据没有单号,请添加!','错误',16);
Exit;
end;
InsertHeader := 'Exec proc_Sale @Flag=''InsertHeader'''
+ ',@SaleID=' + Quotedstr(lblSaleID.Caption)
+ ',@SaleType=' + Quotedstr(cmbxType.Text)
+ ',@SaleDatetime=' + Quotedstr(DateToStr(SaleDatetime.Date))
+ ',@SaleMan=' + Quotedstr(LoginID)
+ ',@Remark=' + Quotedstr(edtRemark.Text);
InsertBody := 'Exec proc_Sale @Flag=''InsertBody'''
+ ',@SaleID=' + Quotedstr(lblSaleID.Caption)
+ ',@ValidityDatetime=' + Quotedstr(DateToStr(ValidityDatetime.Date))
+ ',@MedicineID=' + Quotedstr(cmbxMeicineID.Text)
+ ',@RetailPrice=' + edtRetailPrice.Text
+ ',@Amount=' + edtAmount.Text;
SelectBody := 'Exec proc_Sale @Flag=''SelectSale'''
+',@SaleID=' + QUotedstr(lblSaleID.Caption);
ExecSQL(qrySaleHeader,InsertHeader);
ExecSQL(qrySaleBody,InsertBody);
OpenDataSQL(qrySaleBody, SelectBody);
except
Application.MessageBox('保存数据错误,请查实!','错误',16);
end;
end;
procedure TfrmSaleDepot.btnAuditingClick(Sender: TObject);
var
Auditing, Update: 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_Sale @Flag=''UpdateSale'''
+',@SaleID=' + Quotedstr(lblSaleID.Caption);
ExecSQL(qrySaleHeader,Auditing);
Update := 'Exec proc_Storage @Flag=''OutUpdateStorage'''
+ ',@SaleID=' + Quotedstr(lblSaleID.Caption);
ExecSQL(qrySaleHeader,Update);
Application.MessageBox('审核成功!','提示',64);
lblAuditing.Caption := '已审核';
end;
procedure TfrmSaleDepot.btnPrintClick(Sender: TObject);
var
PrintSQL: string;
begin
PrintSQL := 'Select A.*,B.*,C.MedName From SaleHeader A'
+' Left Join SaleBody B on A.SaleID=B.SaleID'
+' Left join Medicine C On B.MedicineID=C.MedicineID'
+ ' where A.SaleID =' + QuotedStr(lblSaleID.Caption);
if lblSaleID.Caption = '自动生成' then Exit;
OpenDataSQL(qryPrint, PrintSQL);
RvProject1.ProjectFile :='.\SaleReport.rav';
RvProject1.Execute;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -