524 lines
13 KiB
ObjectPascal
524 lines
13 KiB
ObjectPascal
unit U_Factory;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
|
||
cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
|
||
cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
|
||
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
|
||
cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
|
||
cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
|
||
RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
|
||
IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
|
||
cxTextEdit, cxDBLookupComboBox, ComObj, cxLookAndFeels, cxLookAndFeelPainters,
|
||
cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
|
||
dxBarBuiltInMenu, U_BaseList, cxPC, cxContainer;
|
||
|
||
type
|
||
TfrmFactory = class(TFrmBaseList)
|
||
ToolBar1: TToolBar;
|
||
TBRafresh: TToolButton;
|
||
TBDel: TToolButton;
|
||
TBClose: TToolButton;
|
||
ADOQueryTemp: TADOQuery;
|
||
ADOQueryCmd: TADOQuery;
|
||
Panel1: TPanel;
|
||
ADOQueryMain: TADOQuery;
|
||
Label3: TLabel;
|
||
cxGrid1: TcxGrid;
|
||
Tv1: TcxGridDBTableView;
|
||
cxGridLevel1: TcxGridLevel;
|
||
DS_1: TDataSource;
|
||
CDS_1: TClientDataSet;
|
||
btnAdd: TToolButton;
|
||
v2Column6: TcxGridDBColumn;
|
||
v2Column1: TcxGridDBColumn;
|
||
v2Column2: TcxGridDBColumn;
|
||
Label1: TLabel;
|
||
btnEdit: TToolButton;
|
||
v2Column12: TcxGridDBColumn;
|
||
v2Column15: TcxGridDBColumn;
|
||
CDS_2: TClientDataSet;
|
||
DS_2: TDataSource;
|
||
v2Column3: TcxGridDBColumn;
|
||
v2Column4: TcxGridDBColumn;
|
||
btnFollower: TToolButton;
|
||
Panel2: TPanel;
|
||
GPM_1: TcxGridPopupMenu;
|
||
cxGrid2: TcxGrid;
|
||
Tv2: TcxGridDBTableView;
|
||
v3Column3: TcxGridDBColumn;
|
||
cxGridDBColumn1: TcxGridDBColumn;
|
||
Tv2Column1: TcxGridDBColumn;
|
||
cxGridLevel2: TcxGridLevel;
|
||
GPM_2: TcxGridPopupMenu;
|
||
Tv2Column2: TcxGridDBColumn;
|
||
Tv2Column3: TcxGridDBColumn;
|
||
btnChk: TToolButton;
|
||
btnReChk: TToolButton;
|
||
cxTabControl1: TcxTabControl;
|
||
ToolButton1: TToolButton;
|
||
ToolButton8: TToolButton;
|
||
Tv1Column1: TcxGridDBColumn;
|
||
CoName: TcxTextEdit;
|
||
CoCode: TcxTextEdit;
|
||
procedure FormDestroy(Sender: TObject);
|
||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||
procedure TBCloseClick(Sender: TObject);
|
||
procedure TBDelClick(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure TBRafreshClick(Sender: TObject);
|
||
procedure btnEditClick(Sender: TObject);
|
||
procedure btnAddClick(Sender: TObject);
|
||
procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
|
||
procedure btnFollowerClick(Sender: TObject);
|
||
procedure FactTypeChange(Sender: TObject);
|
||
procedure Tv2Column2PropertiesEditValueChanged(Sender: TObject);
|
||
procedure Tv2Column3PropertiesEditValueChanged(Sender: TObject);
|
||
procedure CoCodeKeyPress(Sender: TObject; var Key: Char);
|
||
procedure btnChkClick(Sender: TObject);
|
||
procedure btnReChkClick(Sender: TObject);
|
||
procedure cxTabControl1Change(Sender: TObject);
|
||
procedure ToolButton1Click(Sender: TObject);
|
||
procedure ToolButton8Click(Sender: TObject);
|
||
procedure CoCodeChange(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
procedure InitGrid();
|
||
procedure SetStatus();
|
||
public
|
||
FAuthority: string;
|
||
end;
|
||
|
||
var
|
||
frmFactory: TfrmFactory;
|
||
|
||
implementation
|
||
|
||
uses
|
||
U_DataLink, U_RTFun, U_ZDYHelp, U_FactoryInput, U_UserSel, U_AttachmentUpload;
|
||
|
||
{$R *.dfm}
|
||
|
||
procedure TfrmFactory.SetStatus();
|
||
begin
|
||
btnFollower.Visible := false; //ָ<><D6B8>
|
||
btnChk.Visible := false; //<2F><><EFBFBD><EFBFBD>
|
||
btnReChk.Visible := false; //<2F><><EFBFBD><EFBFBD>
|
||
|
||
btnAdd.Visible := false; //<2F><><EFBFBD><EFBFBD>
|
||
btnEdit.Visible := false; //<2F><EFBFBD>
|
||
TBDel.Visible := false; //ɾ<><C9BE>
|
||
|
||
if Trim(FAuthority) = '<27><><EFBFBD><EFBFBD>' then
|
||
begin
|
||
btnFollower.Visible := true;
|
||
btnAdd.Visible := true;
|
||
case cxTabControl1.TabIndex of
|
||
0:
|
||
begin
|
||
btnEdit.Visible := true;
|
||
TBDel.Visible := true;
|
||
btnChk.Visible := true;
|
||
end;
|
||
1:
|
||
begin
|
||
btnReChk.Visible := true;
|
||
end;
|
||
2:
|
||
begin
|
||
|
||
end;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
btnAdd.Visible := true;
|
||
case cxTabControl1.TabIndex of
|
||
0:
|
||
begin
|
||
btnEdit.Visible := true;
|
||
TBDel.Visible := true;
|
||
end;
|
||
1:
|
||
begin
|
||
|
||
end;
|
||
2:
|
||
begin
|
||
|
||
end;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.InitGrid();
|
||
var
|
||
SqlStr, FilterStr: string;
|
||
begin
|
||
FilterStr := SGetFilters(Panel1, 1, 2);
|
||
SqlStr := ' select * from BS_Company where CoType=''<27><>Ӧ<EFBFBD><D3A6>'' and Valid=''Y'' ';
|
||
case cxTabControl1.TabIndex of
|
||
0:
|
||
begin
|
||
SqlStr := SqlStr + ' and status=''0'''; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
|
||
end;
|
||
1:
|
||
begin
|
||
SqlStr := SqlStr + ' and status=''1''';
|
||
end;
|
||
end;
|
||
SqlStr := SqlStr + ' ORDER BY CoCode ';
|
||
InitCDSData(ADOQueryMain, CDS_1, Tv1, SqlStr, FilterStr, 'CoCode');
|
||
end;
|
||
|
||
procedure TfrmFactory.FormDestroy(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
frmFactory := nil;
|
||
end;
|
||
|
||
procedure TfrmFactory.FactTypeChange(Sender: TObject);
|
||
begin
|
||
InitGrid();
|
||
end;
|
||
|
||
procedure TfrmFactory.FormClose(Sender: TObject; var Action: TCloseAction);
|
||
begin
|
||
inherited;
|
||
Action := caFree;
|
||
end;
|
||
|
||
procedure TfrmFactory.TBCloseClick(Sender: TObject);
|
||
begin
|
||
|
||
Close;
|
||
end;
|
||
|
||
procedure TfrmFactory.TBDelClick(Sender: TObject);
|
||
var
|
||
RTValues: TArray<string>;
|
||
begin
|
||
if CDS_1.IsEmpty then
|
||
exit;
|
||
RTValues := SelTVKey(Tv1, ['COID']);
|
||
if RTValues[0] = '' then
|
||
begin
|
||
Application.MessageBox('<27><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add('exec P_BS_Com_Del @COID=' + quotedstr(RTValues[0]));
|
||
sql.Add(',@DCode=' + quotedstr(trim(DCode)));
|
||
sql.Add(',@DName=' + quotedstr(trim(DName)));
|
||
ExecSQL;
|
||
end;
|
||
InitGrid();
|
||
end;
|
||
|
||
procedure TfrmFactory.FormShow(Sender: TObject);
|
||
begin
|
||
inherited;
|
||
FAuthority := self.fParameters1;
|
||
ReadCxGrid(trim(self.Caption) + 'TV1', Tv1, '<27><>Ӧ<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>');
|
||
ReadCxGrid(trim(self.Caption) + 'TV2', Tv2, '<27><>Ӧ<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>');
|
||
SetStatus();
|
||
|
||
InitGrid();
|
||
|
||
end;
|
||
|
||
procedure TfrmFactory.TBRafreshClick(Sender: TObject);
|
||
begin
|
||
InitGrid();
|
||
end;
|
||
|
||
procedure TfrmFactory.ToolButton1Click(Sender: TObject);
|
||
begin
|
||
|
||
WriteCxGrid(trim(self.Caption) + 'TV1', Tv1, '<27><>Ӧ<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>');
|
||
WriteCxGrid(trim(self.Caption) + 'TV2', Tv2, '<27><>Ӧ<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>');
|
||
|
||
end;
|
||
|
||
procedure TfrmFactory.CoCodeChange(Sender: TObject);
|
||
begin
|
||
if ADOQueryMain.Active then
|
||
begin
|
||
SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
|
||
SCreateCDS(ADOQueryMain, CDS_1);
|
||
SInitCDSData(ADOQueryMain, CDS_1);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.CoCodeKeyPress(Sender: TObject; var Key: Char);
|
||
begin
|
||
if Key = #13 then
|
||
begin
|
||
InitGrid();
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.cxTabControl1Change(Sender: TObject);
|
||
begin
|
||
SetStatus();
|
||
TBRafresh.Click;
|
||
end;
|
||
|
||
procedure TfrmFactory.btnEditClick(Sender: TObject);
|
||
begin
|
||
if CDS_1.IsEmpty then
|
||
exit;
|
||
try
|
||
frmFactoryInput := TfrmFactoryInput.Create(Application);
|
||
with frmFactoryInput do
|
||
begin
|
||
FCOID := Trim(Self.CDS_1.fieldbyname('COID').AsString);
|
||
// CoCode.ReadOnly:=True;
|
||
if ShowModal = 1 then
|
||
begin
|
||
TBRafresh.Click;
|
||
end;
|
||
end;
|
||
finally
|
||
frmFactoryInput.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.btnAddClick(Sender: TObject);
|
||
begin
|
||
try
|
||
frmFactoryInput := TfrmFactoryInput.Create(Application);
|
||
with frmFactoryInput do
|
||
begin
|
||
FCOID := '';
|
||
if ShowModal = 1 then
|
||
begin
|
||
InitGrid();
|
||
end;
|
||
end;
|
||
finally
|
||
frmFactoryInput.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.Tv2Column2PropertiesEditValueChanged(Sender: TObject);
|
||
var
|
||
mvalue, FFieldName: string;
|
||
begin
|
||
mvalue := TcxTextEdit(Sender).EditingText;
|
||
FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
|
||
if Trim(mvalue) = '' then
|
||
begin
|
||
mvalue := '0';
|
||
end;
|
||
|
||
with CDS_1 do
|
||
begin
|
||
Edit;
|
||
FieldByName(FFieldName).Value := mvalue;
|
||
Post;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add('update BS_Company set ' + FFieldName + '=' + quotedstr(Trim(mvalue)));
|
||
sql.Add('where CoID=' + quotedstr(Trim(CDS_1.fieldbyname('CoID').AsString)));
|
||
ExecSQL;
|
||
end;
|
||
tv2.Controller.EditingController.ShowEdit();
|
||
end;
|
||
|
||
procedure TfrmFactory.Tv2Column3PropertiesEditValueChanged(Sender: TObject);
|
||
var
|
||
mvalue, FFieldName: string;
|
||
begin
|
||
mvalue := TcxTextEdit(Sender).EditingText;
|
||
FFieldName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
|
||
if Trim(mvalue) = '' then
|
||
begin
|
||
mvalue := '0';
|
||
end;
|
||
|
||
with CDS_1 do
|
||
begin
|
||
Edit;
|
||
FieldByName(FFieldName).Value := mvalue;
|
||
Post;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add('update BS_Company set ' + FFieldName + '=' + quotedstr(Trim(mvalue)));
|
||
sql.Add('where CoID=' + quotedstr(Trim(CDS_1.fieldbyname('CoID').AsString)));
|
||
ExecSQL;
|
||
end;
|
||
tv2.Controller.EditingController.ShowEdit();
|
||
end;
|
||
|
||
procedure TfrmFactory.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
|
||
begin
|
||
with ADOQueryTemp do
|
||
begin
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add(' select * from BS_Company_contact where COID=' + quotedstr(Trim(CDS_1.FieldByName('COID').AsString)));
|
||
Open;
|
||
end;
|
||
SCreateCDS(ADOQueryTemp, CDS_2);
|
||
SInitCDSData(ADOQueryTemp, CDS_2);
|
||
|
||
end;
|
||
|
||
procedure TfrmFactory.btnFollowerClick(Sender: TObject);
|
||
var
|
||
MFollower, MFollowId: string;
|
||
var
|
||
RTValues: TArray<string>;
|
||
begin
|
||
if CDS_1.IsEmpty then
|
||
exit;
|
||
RTValues := SelTVKey(Tv1, ['COID']);
|
||
if RTValues[0] = '' then
|
||
begin
|
||
Application.MessageBox('<27><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
|
||
MFollower := '';
|
||
MFollowId := '';
|
||
|
||
try
|
||
frmUserSel := TfrmUserSel.Create(Application);
|
||
with frmUserSel do
|
||
begin
|
||
FMultiple := True;
|
||
if ShowModal = 1 then
|
||
begin
|
||
while frmUserSel.CDS_1.Locate('SSel', True, []) do
|
||
begin
|
||
if MFollowId = '' then
|
||
begin
|
||
MFollowId := Trim(CDS_1.FieldByName('UserID').AsString);
|
||
MFollower := Trim(CDS_1.FieldByName('UserName').AsString);
|
||
end
|
||
else
|
||
begin
|
||
MFollowId := MFollowId + ',' + Trim(CDS_1.FieldByName('UserID').AsString);
|
||
MFollower := MFollower + ',' + Trim(CDS_1.FieldByName('UserName').AsString);
|
||
end;
|
||
frmUserSel.CDS_1.Delete;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add('update BS_Company set FollowId=' + quotedstr(trim(MFollowId)));
|
||
sql.Add(' ,Follower=' + quotedstr(trim(MFollower)));
|
||
sql.Add('where EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + QuotedStr(RTValues[0]) + ','','') X where BS_Company.CoID=X.RTValue ) ');
|
||
|
||
ExecSQL;
|
||
end;
|
||
|
||
Self.InitGrid();
|
||
end;
|
||
end;
|
||
finally
|
||
frmUserSel.Free;
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmFactory.btnChkClick(Sender: TObject);
|
||
var
|
||
RTValues: TArray<string>;
|
||
begin
|
||
if CDS_1.IsEmpty then
|
||
exit;
|
||
RTValues := SelTVKey(Tv1, ['COID']);
|
||
if RTValues[0] = '' then
|
||
begin
|
||
Application.MessageBox('<27><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
try
|
||
with ADOQueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('update BS_Company SET status=''1'',Chktime=getdate(),Chker=' + quotedstr(trim(DName)));
|
||
sql.Add('where EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + QuotedStr(RTValues[0]) + ','','') X where BS_Company.CoID=X.RTValue ) ');
|
||
execsql;
|
||
end;
|
||
application.MessageBox('<27><><EFBFBD>˳ɹ<CBB3><C9B9><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
|
||
TBRafresh.Click;
|
||
except
|
||
application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.btnReChkClick(Sender: TObject);
|
||
var
|
||
RTValues: TArray<string>;
|
||
begin
|
||
if CDS_1.IsEmpty then
|
||
exit;
|
||
RTValues := SelTVKey(Tv1, ['COID']);
|
||
if RTValues[0] = '' then
|
||
begin
|
||
Application.MessageBox('<27><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
try
|
||
with ADOQueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('update BS_Company SET status=''0'',Chktime=null,Chker=null ');
|
||
sql.Add('where EXISTS(select X.RTValue from [dbo].[F_Tool_SplitString](' + QuotedStr(RTValues[0]) + ','','') X where BS_Company.CoID=X.RTValue ) ');
|
||
execsql;
|
||
end;
|
||
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳ɹ<CBB3><C9B9><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ');
|
||
TBRafresh.Click;
|
||
except
|
||
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactory.ToolButton8Click(Sender: TObject);
|
||
begin
|
||
if CDS_1.IsEmpty then
|
||
Exit;
|
||
try
|
||
frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
|
||
with frmAttachmentUpload do
|
||
begin
|
||
if (Trim(FAuthority) = '¼<><C2BC>') or (Trim(FAuthority) = '<27><><EFBFBD><EFBFBD>') then
|
||
FEditAuthority := True;
|
||
fkeyNO := Trim(Self.CDS_1.fieldbyname('Coid').AsString);
|
||
fType := '<27>ͻ<EFBFBD>';
|
||
if ShowModal = 1 then
|
||
begin
|
||
|
||
end;
|
||
end;
|
||
finally
|
||
frmAttachmentUpload.Free;
|
||
end;
|
||
|
||
end;
|
||
|
||
end.
|
||
|