414 lines
10 KiB
ObjectPascal
414 lines
10 KiB
ObjectPascal
unit U_FactoryInput;
|
||
|
||
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, cxDropDownEdit, BtnEdit, cxLookAndFeels, cxLookAndFeelPainters,
|
||
cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
|
||
dxBarBuiltInMenu, U_BaseList;
|
||
|
||
type
|
||
TfrmFactoryInput = class(TForm)
|
||
ToolBar1: TToolBar;
|
||
TBClose: TToolButton;
|
||
ADOQueryTemp: TADOQuery;
|
||
ADOQueryCmd: TADOQuery;
|
||
ADOQueryMain: TADOQuery;
|
||
cxGridPopupMenu2: TcxGridPopupMenu;
|
||
ToolButton3: TToolButton;
|
||
ToolBar2: TToolBar;
|
||
ToolButton4: TToolButton;
|
||
ToolButton5: TToolButton;
|
||
CDS_LXR: TClientDataSet;
|
||
DSLXR: TDataSource;
|
||
cxGrid1: TcxGrid;
|
||
Tv1: TcxGridDBTableView;
|
||
cxGridDBColumn1: TcxGridDBColumn;
|
||
cxGridDBColumn2: TcxGridDBColumn;
|
||
cxGridDBColumn3: TcxGridDBColumn;
|
||
cxGridDBColumn4: TcxGridDBColumn;
|
||
cxGridDBColumn5: TcxGridDBColumn;
|
||
Tv1Column1: TcxGridDBColumn;
|
||
v3Column2: TcxGridDBColumn;
|
||
cxGridLevel1: TcxGridLevel;
|
||
v3Column3: TcxGridDBColumn;
|
||
ToolButton1: TToolButton;
|
||
ScrollBox1: TScrollBox;
|
||
Label2: TLabel;
|
||
Label6: TLabel;
|
||
Label12: TLabel;
|
||
Label39: TLabel;
|
||
Label7: TLabel;
|
||
Label19: TLabel;
|
||
CoName: TEdit;
|
||
CoAddress: TEdit;
|
||
Note: TMemo;
|
||
Label1: TLabel;
|
||
CoHRName: TEdit;
|
||
CoCode: TEdit;
|
||
Coarea: TEdit;
|
||
FactType: TComboBox;
|
||
Label3: TLabel;
|
||
COGdy: TEdit;
|
||
procedure FormDestroy(Sender: TObject);
|
||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||
procedure TBCloseClick(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure TBRafreshClick(Sender: TObject);
|
||
procedure ToolButton3Click(Sender: TObject);
|
||
procedure ToolButton4Click(Sender: TObject);
|
||
procedure ToolButton5Click(Sender: TObject);
|
||
procedure ToolButton1Click(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
procedure InitGrid();
|
||
function SaveData(): Boolean;
|
||
public
|
||
fkhType: string;
|
||
{ Public declarations }
|
||
FCOID: string;
|
||
end;
|
||
|
||
var
|
||
frmFactoryInput: TfrmFactoryInput;
|
||
|
||
implementation
|
||
|
||
uses
|
||
U_DataLink, U_RTFun, U_ZDYHelp;
|
||
|
||
{$R *.dfm}
|
||
|
||
procedure TfrmFactoryInput.InitGrid();
|
||
begin
|
||
try
|
||
|
||
ADOQueryMain.DisableControls;
|
||
with ADOQueryMain do
|
||
begin
|
||
Filtered := False;
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add(' select * from Company where CoType=''<27><>Ӧ<EFBFBD><D3A6>'' and COID=''' + Trim(FCOID) + '''');
|
||
Open;
|
||
end;
|
||
SCSHData(ADOQueryMain, ScrollBox1, 2);
|
||
with ADOQueryMain do
|
||
begin
|
||
Filtered := False;
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add(' select * from Company_contact where COID=' + quotedstr(Trim(FCOID)));
|
||
Open;
|
||
end;
|
||
SCreateCDS(ADOQueryMain, CDS_LXR);
|
||
SInitCDSData(ADOQueryMain, CDS_LXR);
|
||
finally
|
||
ADOQueryMain.EnableControls;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.FormDestroy(Sender: TObject);
|
||
begin
|
||
|
||
frmFactoryInput := nil;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.FormClose(Sender: TObject; var Action: TCloseAction);
|
||
begin
|
||
|
||
Action := caFree;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.TBCloseClick(Sender: TObject);
|
||
begin
|
||
WriteCxGrid(trim(self.Caption), Tv1, '<27><>Ӧ<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>');
|
||
// ModalResult := 1;
|
||
close;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.FormShow(Sender: TObject);
|
||
begin
|
||
|
||
ReadCxGrid(trim(self.Caption), Tv1, '<27><>Ӧ<EFBFBD>̹<EFBFBD><CCB9><EFBFBD>');
|
||
InitGrid();
|
||
if trim(FCOID) = '' then
|
||
begin
|
||
with ADOQueryTemp do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add(' exec P_Com_Get_No @Str=''G'' ');
|
||
Open;
|
||
end;
|
||
CoCode.Text := trim(ADOQueryTemp.FieldByName('NewCoCode').asstring);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.TBRafreshClick(Sender: TObject);
|
||
begin
|
||
InitGrid();
|
||
end;
|
||
|
||
function TfrmFactoryInput.SaveData(): Boolean;
|
||
var
|
||
MaxId, MaxSubId, FCoCode, FCCID: string;
|
||
begin
|
||
try
|
||
ADOQueryCmd.Connection.BeginTrans;
|
||
if Trim(FCOID) = '' then
|
||
begin
|
||
if GetLSNo(ADOQueryCmd, MaxId, 'CO', 'Company', 4, 1) = False then
|
||
begin
|
||
Result := False;
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
|
||
if trim(CoCode.Text) = '' then
|
||
begin
|
||
with ADOQueryTemp do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add(' exec P_Com_Get_No @Str=''G'' ');
|
||
Open;
|
||
end;
|
||
CoCode.Text := trim(ADOQueryTemp.FieldByName('NewCoCode').asstring);
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
MaxId := Trim(FCOID);
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
SQL.Clear;
|
||
sql.Add('select * from Company where COID=''' + Trim(FCOID) + '''');
|
||
Open;
|
||
end;
|
||
with ADOQueryCmd do
|
||
begin
|
||
if Trim(FCOID) = '' then
|
||
begin
|
||
Append;
|
||
FieldByName('Filler').Value := Trim(DName);
|
||
end
|
||
else
|
||
begin
|
||
Edit;
|
||
FieldByName('Editer').Value := Trim(DName);
|
||
FieldByName('Edittime').Value := SGetServerDateTime(ADOQueryTemp);
|
||
end;
|
||
FieldByName('COID').Value := Trim(MaxId);
|
||
RTSetsavedata(ADOQueryCmd, 'Company', ScrollBox1, 2);
|
||
FieldByName('CoType').Value := '<27><>Ӧ<EFBFBD><D3A6>';
|
||
Post;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add('select * from Company where CoCode=' + quotedstr(trim(CoCode.Text)));
|
||
sql.Add(' and CoType=''<27><>Ӧ<EFBFBD><D3A6>'' and Valid=''Y'' ');
|
||
Open;
|
||
end;
|
||
if ADOQueryCmd.RecordCount > 1 then
|
||
begin
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
Application.MessageBox('<27><>Ӧ<EFBFBD>̱<EFBFBD><CCB1><EFBFBD><EFBFBD>ظ<EFBFBD>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add('select * from Company where CoName=' + quotedstr(trim(CoName.Text)));
|
||
sql.Add(' and CoType=''<27><>Ӧ<EFBFBD><D3A6>'' and Valid=''Y'' ');
|
||
Open;
|
||
end;
|
||
if ADOQueryCmd.RecordCount > 1 then
|
||
begin
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
Application.MessageBox('<27><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
|
||
if not CDS_LXR.IsEmpty then
|
||
begin
|
||
with CDS_LXR do
|
||
begin
|
||
CDS_LXR.First;
|
||
while not Eof do
|
||
begin
|
||
FCCID := Trim(CDS_LXR.fieldbyname('CCID').AsString);
|
||
if Trim(FCCID) = '' then
|
||
begin
|
||
if GetLSNo(ADOQueryCmd, MaxSubId, 'CCS', 'Company_contact', 4, 1) = False then
|
||
begin
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
Application.MessageBox('ȡϵ<C8A1><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IDʧ<44><CAA7>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
MaxSubId := trim(FCCID);
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add('select * from Company_contact where CCID=' + quotedstr(Trim(MaxSubId)));
|
||
Open;
|
||
end;
|
||
with ADOQueryCmd do
|
||
begin
|
||
if Trim(FCCID) = '' then
|
||
begin
|
||
Append;
|
||
end
|
||
else
|
||
begin
|
||
Edit;
|
||
end;
|
||
FieldByName('CCID').Value := Trim(MaxSubId);
|
||
FieldByName('COID').Value := Trim(MaxId);
|
||
RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_LXR, 'Company_contact', 0);
|
||
Post;
|
||
end;
|
||
with CDS_LXR do
|
||
begin
|
||
Edit;
|
||
FieldByName('CCID').Value := Trim(MaxSubId);
|
||
Post;
|
||
end;
|
||
CDS_LXR.Next;
|
||
end;
|
||
end;
|
||
end;
|
||
ADOQueryCmd.Connection.CommitTrans;
|
||
FCCID := Trim(MaxSubId);
|
||
Result := True;
|
||
except
|
||
Result := false;
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>쳣!', '<27><>ʾ', 0);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.ToolButton3Click(Sender: TObject);
|
||
begin
|
||
|
||
// if Trim(CoCode.Text)='' then
|
||
// begin
|
||
// Application.MessageBox('<27><>Ӧ<EFBFBD>̱<EFBFBD><CCB1>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD><CEAA>!','<27><>ʾ',0);
|
||
// Exit;
|
||
// end;
|
||
if Trim(CoName.Text) = '' then
|
||
begin
|
||
Application.MessageBox('<27><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
if SaveData() then
|
||
begin
|
||
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!', '<27><>ʾ', 0);
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.ToolButton4Click(Sender: TObject);
|
||
var
|
||
maxno: string;
|
||
begin
|
||
if GetLSNo(ADOQueryCmd, maxno, 'CC', 'Company_contact', 4, 1) = False then
|
||
begin
|
||
Application.MessageBox('ȡϵ<C8A1><CFB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IDʧ<44><CAA7>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
if CDS_LXR.IsEmpty then
|
||
begin
|
||
with CDS_LXR do
|
||
begin
|
||
Append;
|
||
fieldbyname('CCID').Value := trim(maxno);
|
||
fieldbyname('IsDefault').Value := true;
|
||
Post;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
with CDS_LXR do
|
||
begin
|
||
Append;
|
||
fieldbyname('CCID').Value := trim(maxno);
|
||
fieldbyname('IsDefault').Value := false;
|
||
Post;
|
||
end;
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.ToolButton5Click(Sender: TObject);
|
||
begin
|
||
if CDS_LXR.IsEmpty then
|
||
Exit;
|
||
if Trim(CDS_LXR.fieldbyname('CCID').AsString) <> '' then
|
||
begin
|
||
if Application.MessageBox('ȷ<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', 32 + 4) <> IDYES then
|
||
Exit;
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add('delete from Company_contact where CCID=''' + Trim(CDS_LXR.fieldbyname('CCID').AsString) + '''');
|
||
ExecSQL;
|
||
end;
|
||
end;
|
||
CDS_LXR.Delete;
|
||
if CDS_LXR.IsEmpty = false then
|
||
begin
|
||
if CDS_LXR.Locate('IsDefault', true, []) = false then
|
||
begin
|
||
CDS_LXR.first;
|
||
CDS_LXR.edit;
|
||
CDS_LXR.FieldByName('IsDefault').value := true;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmFactoryInput.ToolButton1Click(Sender: TObject);
|
||
var
|
||
DwFlag: string;
|
||
begin
|
||
DwFlag := trim(CDS_LXR.FieldByName('CCID').AsString);
|
||
if CDS_LXR.Locate('IsDefault', true, []) then
|
||
begin
|
||
CDS_LXR.edit;
|
||
CDS_LXR.FieldByName('IsDefault').value := false;
|
||
end;
|
||
if CDS_LXR.Locate('CCID', DwFlag, []) then
|
||
begin
|
||
CDS_LXR.edit;
|
||
CDS_LXR.FieldByName('IsDefault').value := true;
|
||
end;
|
||
|
||
end;
|
||
|
||
end.
|
||
|