📄 bas_standardprice.pas
字号:
unit Bas_StandardPrice;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Outer, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
StdCtrls, ExtCtrls, ComCtrls, ToolWin, DBCtrls, jpeg;
Type
TFrm_Bas_StandardPrice = Class(TFrm_Base_Outer)
AdoQry_MainspstArtMonth: TStringField;
AdoQry_MainItemCode: TStringField;
AdoQry_MainItemName: TStringField;
AdoQry_MainUomName: TStringField;
AdoQry_MainspPrice: TFloatField;
Label1: TLabel;
DBText1: TDBText;
procedure Act_DeleteExecute(Sender: TObject);
procedure Act_NewExecute(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
procedure Act_CopyExecute(Sender: TObject);
private
Function checkMonth(CurrentMonth:string):Boolean;
Function CanModify(CurrentMonth:string):Boolean;
{ Private declarations }
public
loginMonth:string;
function SetDeleteSql: String;Override;
procedure initform(AdOConnection:TAdOConnection;ReadOnly:boolean);Override;
{ Public declarations }
end;
var
Frm_Bas_StandardPrice: TFrm_Bas_StandardPrice;
implementation
uses Sys_Global,Bas_StandardPrice_D,Bas_StandardPrice_Month;
{$R *.DFM}
procedure TFrm_Bas_StandardPrice.initform(AdOConnection:TAdOConnection;ReadOnly:boolean);
begin//SQL初始化
inherited;
PriceFields:='spPrice,';
SelectFromSQL:='Select StandardPrice.spstArtMonth,'+
'StandardPrice.ItemCode,'+
'Item.ItemName,'+
'Uom.UomName,'+
'StandardPrice.spPrice '+
'from StandardPrice '+
'left join Item on StandardPrice.ItemCode=Item.ItemCode '+
'left join Uom on Item.UomCode=Uom.UomCode ';
//当前排序字段
loginMonth:=copy(LoginDate,1,7);
OrderByFields:='spstArtMonth,ItemCode';
condition:='spstArtMonth='''+loginMonth+'''';
lbl_Order.Caption:='月份,物料代码';
lbl_Condition.Caption:=loginMonth;
GetData;
//设置弹出窗体
Frm_Sys_Detail:=TFrm_Bas_StandardPrice_D.Create(Application);
if Param1='Query' then
begin
act_Copy.enabled:=False;
act_Copy.Visible :=False;
end;
end;
function TFrm_Bas_StandardPrice.SetDeleteSql: String;
begin
Result:='Delete StandardPrice Where '+
' ItemCode='''+AdoQry_Main.fieldbyname('ItemCode').AsString+''' and '+
' spstArtMonth='''+AdoQry_Main.fieldbyname('spstArtMonth').AsString+'''';
end;
Function TFrm_Bas_StandardPrice.checkMonth(CurrentMonth:string):Boolean;
begin
Result:=True;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' select left(convert(varchAr,Invstatus),7) as InvStatus '+
' from Invstatus '+
' where InvStatusName=''clsperiod'' ');
open;
if fieldbyname('Invstatus').asstring>CurrentMonth then
Result:=False
end;
end;
Function TFrm_Bas_StandardPrice.CanModify(CurrentMonth:string):boolean;
begin
Result:=True;
if (CurrentMonth<>'') and (not CheckMonth(CurrentMonth)) then
begin
DispInfo(CurrentMonth+'已经有仓库结帐,不允许更改计划价!',1);
Result:=False;
end;
end;
procedure TFrm_Bas_StandardPrice.Act_DeleteExecute(Sender: TObject);
var
CurrentMonth:string;
begin
CurrentMonth:=AdoQry_Main.fieldbyname('spstArtMonth').asstring; // 当前行的月份
if CurrentMonth='' then abort; // CurrentMonth:= LoginMonth;
// if not Canmodify(CurrentMonth) then
// Abort;
Inherited;
ChangeInvStatus(AdoQry_tmp,'',CurrentMonth) //在Sys_Global中已经定义
end;
procedure TFrm_Bas_StandardPrice.Act_NewExecute(Sender: TObject);
var
CurrentMonth:string;
begin
{ CurrentMonth:=AdoQry_Main.fieldbyname('spstArtMonth').asstring; // 当前行的月份
if CurrentMonth='' then
begin
Frm_Bas_StandardPrice_Month:=TFrm_Bas_StandardPrice_Month.Create(Application);
Frm_Bas_StandardPrice_Month.ShowModal;
if Frm_Bas_StandardPrice_Month.ModalResult=mrok then
begin
CurrentMonth:=Frm_Bas_StandardPrice_Month.medt_DMonth.text;
end
else
begin
DispInfo('没有增加计划价月份,不能增加!',1);
abort;
end;
Frm_Bas_StandardPrice_Month.Release;
end;
if not Canmodify(CurrentMonth) then
Abort;}
CurrentMonth:=AdoQry_Main.fieldbyname('spstArtMonth').asstring; // 当前行的月份
if CurrentMonth='' then
CurrentMonth:=copy(LoginDate,1,7);
Inherited;
ChangeInvStatus(AdoQry_tmp, '', CurrentMonth) //在Sys_Global中已经定义
end;
procedure TFrm_Bas_StandardPrice.Act_ModifyExecute(Sender: TObject);
var
CurrentMonth:string;
begin
CurrentMonth:=AdoQry_Main.fieldbyname('spstArtMonth').asstring; // 当前行的月份
if CurrentMonth='' then CurrentMonth:= LoginMonth;
// if not Canmodify(CurrentMonth) then
// Abort;
Inherited;
ChangeInvStatus(AdoQry_tmp, '', CurrentMonth) //在Sys_Global中已经定义
end;
procedure TFrm_Bas_StandardPrice.Act_CopyExecute(Sender: TObject);
var
copyMonth,lastMonth:string;
begin
inherited;
Frm_Bas_StandardPrice_Month:=TFrm_Bas_StandardPrice_Month.Create(Application);
Frm_Bas_StandardPrice_Month.InitForm(AdoQry_Main.Connection);
Frm_Bas_StandardPrice_Month.ShowModal;
if Frm_Bas_StandardPrice_Month.ModalResult=mrok then
begin
CopyMonth:=Frm_Bas_StandardPrice_Month.medt_SMonth.text; // 当前行的月份
if copyMonth='' then
begin
DispInfo('没有可以复制的数据!',1);
abort;
end;
LastMonth:=Frm_Bas_StandardPrice_Month.medt_DMonth.text;
// if not CanModify(LastMonth) then
// abort;
if Frm_Bas_StandardPrice_Month.chck_recOver.checked=False then
begin
try
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.text:=
' insert into StandardPrice (SPStArtMonth,ItemCode,SPPrice) '+
' select '+LastMonth+',ItemCode,SPPrice from StandardPrice '+
' where SPStArtMonth='''+CopyMonth+''''+
' and ItemCode not in ( select ItemCode '+
' from StandardPrice '+
' where SPStArtMonth='''+LastMonth+''')';
execsql;
AdoQry_Main.Close;
AdoQry_Main.open;
end;
except
DispInfo(' 复制失败,请稍后再试!',1);
end;
end
else
begin
if DispInfo(' 即将复制'+CopyMonth+'月的计划价,'+LastMonth+'月的计划价将全部被覆盖,是否继续?',2)='y' then
begin
try
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(' delete from StandardPrice where spstArtMonth='''+LastMonth+'''');
sql.Add(' insert into StandardPrice (SPStArtMonth,ItemCode,SPPrice) ');
sql.Add(' select '+LastMonth+',ItemCode,SPPrice from StandardPrice ');
sql.Add(' where SPStArtMonth='''+CopyMonth+'''');
execsql;
AdoQry_Main.Close;
AdoQry_Main.open;
end;
except
DispInfo(' 复制失败,请稍后再试!',1);
end;
end;
end;
end;
Frm_Bas_StandardPrice_Month.Release;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -