📄 checkdata.pas
字号:
unit CheckData;
interface
uses SysUtils;
function CheckDateNomal(sDate: String): Boolean; //檢查日期
function CheckDate(sDate: String): boolean; //檢查日期, 包括是否在作業區間
function CheckPower(ProgramID: String): String; //檢查程式使用權限
function CheckUserID(UserID: String): Boolean; //檢查使用者代號
function CheckProductTypeID(ProductTypeID: String): Boolean; //檢查商品類別代碼代碼
function CheckSalesManID(SalesManID: String): Boolean; //檢查業務員編號
function CheckRegionID(RegionID: String): Boolean; //檢查地區編號
function CheckCustomerTypeID(CustomerTypeID: String): Boolean; //檢查客戶類別編號
function CheckAddressID(CustomerID, AddressID: String): Boolean; //檢查客戶地址編號
function CheckCustomerID(CustomerID: String): Boolean; //檢查客戶編號
function CheckDepartmentID(DepartmentID: String): Boolean; //檢查部门編號
function CheckEmployeeID(EmployeeID: String): Boolean; //检查员工编号
function CheckWarehouseID(WarehouseID: String): Boolean; //檢查倉庫編號
function CheckProductID(ProductID: String): Boolean; //檢查商品編號
function CheckSupplierTypeID(SupplierTypeID: String): Boolean; //檢查供應商類別編號
function CheckBankID(BankID: String): Boolean; //檢查銀行編號
function CheckSupplierID(SupplierID: String): Boolean; //檢查供應商編號
function CheckChangeCode(ChangeCode: String): Boolean; //檢查庫存異動代碼
function CheckProgramID(ProgramID: String): Boolean; //檢查程式編號
function CheckUnitID(UnitID: String): Boolean; //檢查计量单位編號
//new
function CheckSaleCode(SaleCode: String): Boolean; //检查销售点编号
function CheckPayCode(PayCode: real;SaleCode: String): Boolean; //检查缴费编号
implementation
uses Main, DataModule, PublicFunction;
//new
function CheckSaleCode(SaleCode: String): Boolean; //检查销售点编号
begin
if Trim(SaleCode) = '' then
begin
NullWarning('销售点编号');
Result := False;
Exit;
end;
with DM.qyCheck do
begin
Close;
SQL.Clear;
SQL.Add('SELECT SaleCode ');
SQL.Add('FROM Pwpt_Sale ');
SQL.Add('WHERE SaleCode = :SaleCode and bUsed = ''1'' ');
ParamByName('SaleCode').AsString := SaleCode;
Open;
end;
if DM.qyCheck.FieldByName('SaleCode').AsString = '' then
begin
NotFoundWarning('销售点编号', SaleCode);
Result := False;
Exit;
end;
Result := True;
end;
function CheckPayCode(PayCode: real;SaleCode: String): Boolean; //检查缴费编号
begin
with DM.qyCheck do
begin
Close;
SQL.Clear;
SQL.Add('SELECT PayCode ');
SQL.Add('FROM Pwpt_Pay ');
SQL.Add('WHERE PayCode = :PayCode and SaleCode = :SaleCode and bCite = ''0'' ');
ParamByName('PayCode').AsFloat := PayCode;
ParamByName('SaleCode').AsString := SaleCode;
Open;
end;
if DM.qyCheck.FieldByName('PayCode').IsNull then
begin
NotFoundWarning('缴费编号', floattostr(PayCode));
Result := False;
Exit;
end;
Result := True;
end;
//new
//檢查日期
function CheckDateNomal(sDate: String):Boolean;
function DateCheck(sDate: String): Boolean;
begin
if not MyMask(sDate, '99-99-99') then
begin
Result := False;
Exit;
end;
if (StrToInt(SubStr(sDate, 4, 2)) < 1) or
(StrToInt(SubStr(sDate, 4, 2)) > 12) then
begin
Result := False;
Exit;
end;
if (StrToInt(SubStr(sDate, 7, 2)) < 1) or
(StrToInt(SubStr(sDate, 7, 2)) > 31) then
begin
Result := False;
Exit;
end;
if (StrToInt(SubStr(sDate, 4, 2)) in [2, 4, 6, 9, 11]) then
begin
if (StrToInt(SubStr(sDate, 7, 2)) > 30) then
begin
Result := False;
Exit;
end;
end
else
begin
if (StrToInt(SubStr(sDate, 7, 2)) > 31) then
begin
Result := False;
Exit;
end;
end;
if (StrToInt(SubStr(sDate, 4, 2)) = 2) and
(not (StrToInt(SubStr(sDate, 1, 2)) in
[00,04,08])) and
(StrToInt(SubStr(sDate, 7, 2)) > 28) then
begin
Result := False;
Exit;
end;
Result := True;
end;
begin
if sDate = '' then
begin
MyWarning('日期不可空白!');
Result := False;
Exit;
end;
//MyWarning(sDate);
if not DateCheck(sDate) then
begin
MyWarning('日期格式输入错误,请重新输入!' + #10#13 +
'(本系统的日期格式为YY-MM-DD)');
Result := False;
Exit;
end;
Result := True;
end;
{查日期(區間)}
function CheckDate(sDate: String):Boolean;
begin
if not CheckDateNomal(sDate) then
begin
Result := False;
Exit;
end;
if (sDate < sStartPeriodDate) or (sDate > sEndPeriodDate) then
begin
MyWarning('日期不在作业区内!');
Result := False;
Exit;
end; //2003yxl
Result := True;
end;
//檢查程式使用權限
function CheckPower(ProgramID: String): String;
function GetAuthority(UserID: String): String;
begin
with DM.qyGet do
begin
Close;
SQL.Clear;
SQL.Add('SELECT ProgramID, Run, Append, Edit, Del, Report, BrowseAll, EditAll ');
SQL.Add('FROM UserAuthority ');
SQL.Add('WHERE CompanyID = :CompanyID AND ProgramID = :ProgramID ');
SQL.Add('AND UserID = :UserID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('ProgramID').AsString := ProgramID;
ParamByName('UserID').AsString := UserID;
Open;
end;
if DM.qyGet.FieldByName('ProgramID').AsString = '' then
begin
with DM.qyGet do
begin
Close;
SQL.Clear;
SQL.Add('SELECT ProgramID, Run, Append, Edit, Del, Report, BrowseAll, EditAll ');
SQL.Add('FROM UserAuthority ');
SQL.Add('WHERE CompanyID = :CompanyID AND ProgramID = :ProgramID ');
SQL.Add('AND UserID = :UserID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('ProgramID').AsString := '*';
ParamByName('UserID').AsString := UserID;
Open;
end;
if DM.qyGet.FieldByName('ProgramID').AsString = '' then
Result := 'NNNNNNN'
else
Result := DM.qyGet.FieldByName('Run').AsString +
DM.qyGet.FieldByName('Append').AsString +
DM.qyGet.FieldByName('Edit').AsString +
DM.qyGet.FieldByName('Del').AsString +
DM.qyGet.FieldByName('Report').AsString +
DM.qyGet.FieldByName('BrowseAll').AsString +
DM.qyGet.FieldByName('EditAll').AsString;
end
else
Result := DM.qyGet.FieldByName('Run').AsString +
DM.qyGet.FieldByName('Append').AsString +
DM.qyGet.FieldByName('Edit').AsString +
DM.qyGet.FieldByName('Del').AsString +
DM.qyGet.FieldByName('Report').AsString +
DM.qyGet.FieldByName('BrowseAll').AsString +
DM.qyGet.FieldByName('EditAll').AsString;
end;
var
sAuthority : String;
sRun, sAppend, sEdit, sDel, sReport, sBrowseAll, sEditAll : String;
begin
Result := 'YYYYYYY';
Exit;
if sUserID = 'SUPERVISOR' then
begin
Result := 'YYYYYYY';
Exit;
end;
sRun := 'N';
sAppend := 'N';
sEdit := 'N';
sDel := 'N';
sReport := 'N';
sBrowseALL := 'N';
sEditAll := 'N';
with DM.qyTemp1 do
begin
Close;
SQL.Clear;
SQL.Add('SELECT GroupID ');
SQL.Add('FROM Users ');
SQL.Add('WHERE CompanyID = :CompanyID ');
SQL.Add('AND UserID = :UserID ');
SQL.Add('AND UserID <> GroupID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('UserID').AsString := sUserID;
Open;
end;
if DM.qyTemp1.FieldByName('GroupID').AsString <> '' then
begin
sAuthority := GetAuthority(DM.qyTemp1.FieldByName('GroupID').AsString);
sRun := SubStr(sAuthority, 1, 1);
sAppend := SubStr(sAuthority, 2, 1);
sEdit := SubStr(sAuthority, 3, 1);
sDel := SubStr(sAuthority, 4, 1);
sReport := SubStr(sAuthority, 5, 1);
sBrowseAll := SubStr(sAuthority, 6, 1);
sEditAll := SubStr(sAuthority, 7, 1);
end;
sAuthority := GetAuthority(sUserID);
if SubStr(sAuthority, 1, 1) = 'Y' then
sRun := 'Y';
if SubStr(sAuthority, 2, 1) = 'Y' then
sAppend := 'Y';
if SubStr(sAuthority, 3, 1) = 'Y' then
sEdit := 'Y';
if SubStr(sAuthority, 4, 1) = 'Y' then
sDel := 'Y';
if SubStr(sAuthority, 5, 1) = 'Y' then
sReport := 'Y';
if SubStr(sAuthority, 6, 1) = 'Y' then
sBrowseAll := 'Y';
if SubStr(sAuthority, 7, 1) = 'Y' then
sEditAll := 'Y';
Result := sRun + sAppend + sEdit + sDel + sReport + sBrowseAll + sEditAll;
end;
//檢查使用者編號
function CheckUserID(UserID: String): Boolean;
begin
if Trim(UserID) = '' then
begin
NullWarning('使用者编号');
Result := False;
Exit;
end;
with DM.qyCheck do
begin
Close;
SQL.Clear;
SQL.Add('SELECT UserID ');
SQL.Add('FROM Users ');
SQL.Add('WHERE CompanyID = :CompanyID ');
SQL.Add('AND UserID = :UserID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('UserID').AsString := UserID;
Open;
end;
if DM.qyCheck.FieldByName('UserID').AsString = '' then
begin
NotFoundWarning('使用者编号', UserID);
Result := False;
Exit;
end;
Result := True;
end;
//檢查商品類別編號
function CheckProductTypeID(ProductTypeID: String): Boolean;
begin
if Trim(ProductTypeID) = '' then
begin
NullWarning('商品类别编号');
Result := False;
Exit;
end;
with DM.qyCheck do
begin
Close;
SQL.Clear;
SQL.Add('SELECT ProductTypeID ');
SQL.Add('FROM ProductType ');
SQL.Add('WHERE CompanyID = :CompanyID ');
SQL.Add('AND ProductTypeID = :ProductTypeID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('ProductTypeID').AsString := ProductTypeID;
Open;
end;
if DM.qyCheck.FieldByName('ProductTypeID').AsString = '' then
begin
NotFoundWarning('商品类别编号', ProductTypeID);
Result := False;
Exit;
end;
Result := True;
end;
//檢查業務員編號
function CheckSalesManID(SalesManID: String): Boolean;
begin
if Trim(SalesManID) = '' then
begin
NullWarning('业务员编号');
Result := False;
Exit;
end;
with DM.qyCheck do
begin
Close;
SQL.Clear;
SQL.Add('SELECT SalesManID ');
SQL.Add('FROM SalesMan ');
SQL.Add('WHERE CompanyID = :CompanyID ');
SQL.Add('AND SalesManID = :SalesManID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('SalesManID').AsString := SalesManID;
Open;
end;
if DM.qyCheck.FieldByName('SalesManID').AsString = '' then
begin
NotFoundWarning('业务员编号', SalesManID);
Result := False;
Exit;
end;
Result := True;
end;
//檢查地區編號
function CheckRegionID(RegionID: String): Boolean;
begin
if Trim(RegionID) = '' then
begin
NullWarning('地区编号');
Result := False;
Exit;
end;
with DM.qyCheck do
begin
Close;
SQL.Clear;
SQL.Add('SELECT RegionID ');
SQL.Add('FROM Region ');
SQL.Add('WHERE CompanyID = :CompanyID ');
SQL.Add('AND RegionID = :RegionID ');
ParamByName('CompanyID').AsString := sCompanyID;
ParamByName('RegionID').AsString := RegionID;
Open;
end;
if DM.qyCheck.FieldByName('RegionID').AsString = '' then
begin
NotFoundWarning('地区编号', RegionID);
Result := False;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -