📄 bas_item_all.pas
字号:
unit Bas_Item_All;
//物料主文件所有属性维护主单元
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Outer, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
StdCtrls, ExtCtrls, ComCtrls, ToolWin, jpeg;
Type
TFrm_Bas_Item_All = Class(TFrm_Base_Outer)
Label1: TLabel;
edt_locate: TEdit;
cbx_ShowAll: TCheckBox;
tmp_grid: TDBGridEh;
Button1: TButton;
chk_max: TCheckBox;
Label2: TLabel;
Label3: TLabel;
AdoQry_MainItemCode: TStringField;
AdoQry_MainItemName: TStringField;
AdoQry_MainMaterial: TStringField;
AdoQry_MainItemshortName: TStringField;
AdoQry_MainUomCode: TStringField;
AdoQry_MainUomName: TStringField;
AdoQry_MainClassCode: TStringField;
AdoQry_MainClassName: TStringField;
AdoQry_MainProductClass: TStringField;
AdoQry_MainQcClass: TStringField;
AdoQry_MainUomCodeName: TStringField;
AdoQry_MainCaiGouyuan: TStringField;
AdoQry_MainwhCodeName: TStringField;
AdoQry_MainJiHuayuan: TStringField;
AdoQry_MainEmployeeCode: TStringField;
AdoQry_MainCaiGou: TStringField;
AdoQry_MainwhCode: TStringField;
AdoQry_MainwhName: TStringField;
AdoQry_MainPla_EmployeeCode: TStringField;
AdoQry_MainJiHua: TStringField;
AdoQry_Mainwh_EmployeeCode: TStringField;
AdoQry_Mainwh_EmployeeName: TStringField;
AdoQry_MainItemType: TIntegerField;
AdoQry_Maindesignno: TStringField;
AdoQry_MainItemUsable: TIntegerField;
AdoQry_Mainmaxqty: TFloatField;
AdoQry_Mainminqty: TFloatField;
AdoQry_Mainlimitout: TIntegerField;
AdoQry_MainLongPurchLT: TIntegerField;
AdoQry_MainiScheck: TIntegerField;
AdoQry_Maingreateout: TIntegerField;
AdoQry_Mainpurchldtime: TFloatField;
AdoQry_Mainmnldtime: TFloatField;
AdoQry_MainPrepareLT: TIntegerField;
AdoQry_MainrunLT: TIntegerField;
AdoQry_MainQcLT: TIntegerField;
AdoQry_MainPmCode: TIntegerField;
AdoQry_MainPmBatch: TIntegerField;
AdoQry_Mainonlydefaultwh: TIntegerField;
AdoQry_MainBarCode: TStringField;
AdoQry_MainItemCode2: TStringField;
AdoQry_MaincanSale: TIntegerField;
AdoQry_MainItemcreatetime: TDateTimeField;
AdoQry_MainItemmodifytime: TDateTimeField;
AdoQry_MainItemdisabletime: TDateTimeField;
AdoQry_MainCurrentOnHandInv: TFloatField;
AdoQry_MainCurrentOnCheckInv: TFloatField;
AdoQry_MainCurrentFreezeInv: TFloatField;
AdoQry_MainCurrentOnShipInv: TFloatField;
AdoQry_MainCurrentWasterInv: TFloatField;
AdoQry_MainremArk: TStringField;
AdoQry_MainDeptCode: TStringField;
AdoQry_MainDeptName: TStringField;
AdoQry_MainBatchstrat: TIntegerField;
AdoQry_MainBatchCtrl: TIntegerField;
AdoQry_MainCapacityhours: TFloatField;
AdoQry_MainItemClass1: TStringField;
AdoQry_MainItemClass2: TStringField;
AdoQry_MainItemClass3: TStringField;
AdoQry_MainItemClass4: TStringField;
AdoQry_MainItemClass5: TStringField;
AdoQry_MainopInv: TFloatField;
AdoQry_MainAssetKmCode: TStringField;
AdoQry_MainKmName: TStringField;
AdoQry_MainInSpecTEmployeeCode: TStringField;
AdoQry_MainInSpecTEmployeeName: TStringField;
AdoQry_MainScrApType: TIntegerField;
AdoQry_MainISStockItem: TIntegerField;
procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
procedure FormCreate(Sender: TObject);
procedure Action3Execute(Sender: TObject);
procedure edt_locateChange(Sender: TObject);
procedure cbx_ShowAllClick(Sender: TObject);
procedure Act_FilterExecute(Sender: TObject);
procedure Act_LocateExecute(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Act_NewExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
private
sqltext,sqltext1:string;
procedure initdbgrdehcolumn;
{ Private declarations }
public
function SetDeleteSql:String;Override;
procedure initform(AdOConnection:TAdOConnection;ReadOnly:boolean);
procedure col_Adjust;
{ Public declarations }
end;
var
Frm_Bas_Item_All: TFrm_Bas_Item_All;
implementation
uses Bas_Item_D0,Sys_Global,Bas_Item_Copy;
{$R *.DFM}
procedure TFrm_Bas_Item_All.initform(AdOConnection:TAdOConnection;ReadOnly:boolean);
var
i,j:integer;
begin//SQL初始化
Application.ProcessMessages;
CreatePanel(1,dbgrideh);
inherited;
sqltext:='Select * From Vw_Base_Item';
selectfromsql:='select * from Vw_Base_Item';
//当前排序字段
OrderByFields:='ItemCode';
lbl_Order.Caption:='物料代码';
ExecuteSql(AdoQry_Main,SelectFromSql+' where 1=2 ',0);
Act_FilterExecute(Application);
//GetData;
//列的宽度调整
// Executesql(AdoQry_tmp,sqltext,1);
col_Adjust;
j:=0;
for i:=0 to dbgrideh.Columns.Count-1 do
begin
if dbgrideh.Columns[i].Visible then
begin
tmp_grid.Columns.Add;
tmp_grid.Columns[j].Assign(dbgrideh.columns[i]);
j:=j+1;
end;
end;
// initdbgrdehcolumn;
//设置弹出窗体
Frm_Sys_Detail:=TFrm_Bas_Item_D0.Create(Application);
If Assigned(ShowAnimate) then ShowAnimate.free;
If Assigned(ShowPanel) then ShowPanel.free;
end;
function TFrm_Bas_Item_All.SetDeleteSql:String;
begin
Result:='Delete Item Where ItemCode='''+AdoQry_Main.fieldbyname('ItemCode').AsString+'''';
end;
procedure TFrm_Bas_Item_All.initdbgrdehcolumn;
var
recCount,fieldCounts,i,j:Integer;
ItemClass:string;
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select SysParamValueC from SysParam where left(SysParamCode,9)=''ItemClass'' ');
open;
recCount:=0;
while not eof do
begin
if fieldbyname('SysParamValueC').asstring<>'' then
inc(recCount)
else
//防止中间有一个为空的,如果有,则后面的都不理会
break;
next;
end;
First;
//记录dbgrid有多少个Column
fieldCounts:=dbgrideh.Columns.Count;
for i:=1 to recCount do
begin
ItemClass:='ItemClass'+inttostr(i);
//遍历所有字段,而不是指定字段的序号
for j:=0 to fieldCounts-1 do
begin
if lowercase(dbgrideh.columns[j].fieldName)=ItemClass then
begin
dbgrideh.columns[j].Title.Caption:=fieldbyname('SysParamValueC').asstring;
next;
break;
end;
end;
end;
//删除不用的字段
for i:=i to 5 do
begin
ItemClass:='ItemClass'+inttostr(i);
for j:=0 to fieldCounts-1 do
begin
if lowercase(dbgrideh.columns[j].fieldName)=ItemClass then
begin
dbgrideh.columns.delete(j);
break;
end;
end;
end;
end;
end;
procedure TFrm_Bas_Item_All.DBGridEhGetCellParams(Sender: TObject;
Column: TColumnEh; AFont: TFont; var Background: TColor;
State: TGridDrawState);
begin
inherited;
//DBGRID的颜色设置
if AdoQry_Main.fieldbyname('ItemUsable').AsString='0' Then
AFont.Color:=ClRed;
if (gdselected in state) then
begin
Background:=clnavy;
afont.color:=clwindow;
end;
end;
procedure TFrm_Bas_Item_All.FormCreate(Sender: TObject);
begin
inherited;
// toolbutton6.Action:=action3;
end;
procedure TFrm_Bas_Item_All.Action3Execute(Sender: TObject);
begin
inherited;
if AdoQry_Main.fieldbyname('ItemUsable').asstring='1' then
begin
if DispInfo('确认该物料无效吗?',2)='y' then
begin
try
AdoQry_Main.edit;
AdoQry_Main.fieldbyname('ItemUsable').asstring:='0';
AdoQry_Main.post;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('update Item '+
' set '+
' ItemUsable=0,'+
' Itemdisabletime='''+formatdatetime('yyyy.mm.dd hh:mm:ss',now)+''''+
' where ItemCode='''+AdoQry_Main.fieldbyname('ItemCode').asstring+'''');
execsql;
end
except
begin
DispInfo('更改失败,请重试!',1);
abort;
end;
end;
end;
end
else
begin
if DispInfo('确认该物料有效吗?',2)='y' then
begin
try
AdoQry_Main.edit;
AdoQry_Main.fieldbyname('ItemUsable').asstring:='1';
AdoQry_Main.post;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('update Item set ItemUsable=1,Itemdisabletime=null where ItemCode='''+AdoQry_Main.fieldbyname('ItemCode').asstring+'''');
execsql;
end
except
begin
DispInfo('更改失败,请重试!',1);
abort;
end;
end;
end;
end;
end;
procedure TFrm_Bas_Item_All.edt_locateChange(Sender: TObject);
var sqltext:string;
tmpItemCode:string;
begin
inherited;
tmpItemCode:='';
tmpItemCode:=Trim(edt_locate.text);
if chk_max.Checked then
begin
sqltext:='select ItemCode from Item where ItemCode like '+quotedstr(Trim(edt_locate.text)+'%')+' Order by ItemCode DESC ';
Executesql(AdoQry_tmp,sqltext,0) ;
if AdoQry_tmp.RecordCount>0 then
tmpItemCode:=AdoQry_tmp.fieldbyname('ItemCode').asstring;
end;
if edt_locate.text<>'' then
begin
AdoQry_Main.First;
AdoQry_Main.Locate('ItemCode',tmpItemCode,[loPArtialKey]);
end;
end;
procedure TFrm_Bas_Item_All.cbx_ShowAllClick(Sender: TObject);
var
tmp_ItemCode:string;
i:integer;
cur_Cursor:tcursor;
begin
inherited;
with AdoQry_tmp do
begin
Close;
sql.Text:='Drop Table '+ '#'+self.Name+','+'#'+self.Name+'Chb';
try
execsql;
except
end;
end;
//处理两种情况:是否显示所有属性
cur_Cursor:=Screen.Cursor ;
Screen.Cursor:=crHourGlass;
Executesql(AdoQry_tmp,'drop table #tmpItemBase',1);
Executesql(AdoQry_tmp,sqltext,1);
if cbx_Showall.Checked then
begin
tmp_ItemCode:=AdoQry_Main.fieldbyname('ItemCode').asstring;
AdoQry_Main.DisableControls ;
for i:=0 to dbgrideh.Columns.Count-1 do
begin
dbgrideh.Columns[i].Visible:=True
end;
// AdoQry_Main.Close;
// selectfromsql:='select * from #tmpItemBase';
// AdoQry_Main.SQL.Text:='select * from #tmpItemBase Order by ItemCode';
// AdoQry_Main.Open ;
Getdata;
col_Adjust;
initdbgrdehcolumn;
AdoQry_Main.Locate('ItemCode',tmp_ItemCode,[]);
AdoQry_Main.EnableControls ;
end
else
begin
tmp_ItemCode:=AdoQry_Main.fieldbyname('ItemCode').asstring;
AdoQry_Main.DisableControls ;
for i:=0 to dbgrideh.Columns.Count-1 do
begin
if (dbgrideh.Columns[i].FieldName='ItemCode')
or(dbgrideh.Columns[i].FieldName='ItemName')
or(dbgrideh.Columns[i].FieldName='UomName')
or(dbgrideh.Columns[i].FieldName='ItemType')
or(dbgrideh.Columns[i].FieldName='ItemUsable')then
dbgrideh.Columns[i].Visible:=True
else
dbgrideh.Columns[i].Visible:=False;
end;
// AdoQry_Main.Close;
// selectfromsql:='select * from #tmpItemBase ';
// Orderbyfields:='ItemCode,';
// AdoQry_Main.SQL.Text:=selectfromsql;
// AdoQry_Main.Open ;
Getdata;
col_Adjust;
AdoQry_Main.Locate('ItemCode',tmp_ItemCode,[]);
AdoQry_Main.EnableControls ;
end;
Screen.Cursor :=cur_Cursor;
end;
procedure TFrm_Bas_Item_All.Act_FilterExecute(Sender: TObject);
var
i:integer;
begin
//动态监控查询条件设置
inherited;
end;
procedure TFrm_Bas_Item_All.col_Adjust ;
var
i:integer;
begin
if not cbx_Showall.Checked then
begin
for i:=0 to dbgrideh.Columns.Count-1 do
begin
if dbgrideh.Columns[i].FieldName='ItemCode' then
dbgrideh.Columns[i].Width:=125;
if dbgrideh.Columns[i].FieldName='ItemName' then
dbgrideh.Columns[i].Width:=250;
if dbgrideh.Columns[i].FieldName='UomName' then
dbgrideh.Columns[i].Width:=80;
if dbgrideh.Columns[i].FieldName='ItemType' then
dbgrideh.Columns[i].Width:=80;
if dbgrideh.Columns[i].FieldName='ItemUsable' then
dbgrideh.Columns[i].Width:=80;
end;
end
else
begin
for i:=0 to dbgrideh.Columns.Count-1 do
begin
if dbgrideh.Columns[i].FieldName='ItemCode' then
dbgrideh.Columns[i].Width:=125;
if dbgrideh.Columns[i].FieldName='ItemName' then
dbgrideh.Columns[i].Width:=250;
if dbgrideh.Columns[i].FieldName='UomName' then
dbgrideh.Columns[i].Width:=36;
if dbgrideh.Columns[i].FieldName='ItemType' then
dbgrideh.Columns[i].Width:=64;
if dbgrideh.Columns[i].FieldName='ItemUsable' then
dbgrideh.Columns[i].Width:=33;
end;
end;
end;
procedure TFrm_Bas_Item_All.Act_LocateExecute(Sender: TObject);
begin
if cbx_Showall.Checked then
Frm_Sys_QuickLocate.SetSrcGrid(dbgrideh)
else
Frm_Sys_QuickLocate.SetSrcGrid(tmp_grid);
Frm_Sys_QuickLocate.ShowModal;
if Frm_Sys_QuickLocate.ModalResult=mrok then
begin
AdoQry_Main.Locate(Frm_Sys_QuickLocate.LocateFieldName,Frm_Sys_QuickLocate.LocateFieldValue,[loPArtialKey]);
end;
end;
procedure TFrm_Bas_Item_All.Button1Click(Sender: TObject);
var
ItemCode:String;
begin
inherited;
Application.CreateForm(TFrm_Bas_Item_Copy,Frm_Bas_Item_Copy);
Frm_Bas_Item_Copy.AdoQry_Tmp.Connection :=AdoQry_Main.Connection ;
Frm_Bas_Item_Copy.ShowModal ;
end;
procedure TFrm_Bas_Item_All.Act_NewExecute(Sender: TObject);
var
aaa:string;
begin
with AdoQry_tmp do
begin
Close;
sql.text:='select isnull(Param3,'''') as Param3 from SysLOGINParam ';
open;
if not eof then
begin
aaa:=fieldbyname('Param3').asstring;
if aaa='1' then
begin
Close;
sql.text:='select Count(*) as maxItemqty from Item ';
open;
if fieldbyname('maxItemqty').Value>=200 then
begin
DispInfo('您用的系统是测试版,物料数量已经达到最大限制,请用正式版!'+
chr(13)+chr(10)+'联系电话:0755-12345678',1);
Abort;
end;
end;
end;
end;
inherited;
end;
procedure TFrm_Bas_Item_All.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
try
Executesql(AdoQry_tmp,'drop table #tmpItemBase',1);
except
end;
end;
procedure TFrm_Bas_Item_All.FormDestroy(Sender: TObject);
begin
inherited;
Frm_Bas_Item_All:=nil;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -