D10myYicheng/客户供应商管理(Company.dll)/U_CustomerInput.pas

719 lines
18 KiB
ObjectPascal
Raw Permalink Normal View History

2025-05-27 14:08:09 +08:00
unit U_CustomerInput;
interface
uses
Windows, Messages, StrUtils, 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, cxContainer, dxCore, cxDateUtils, cxImage,
cxDBEdit, IdExplicitTLSClientServerBase;
type
TfrmCustomerInput = class(TForm)
ToolBar1: TToolBar;
TBClose: TToolButton;
ADOQueryTemp: TADOQuery;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
cxGridPopupMenu2: TcxGridPopupMenu;
ToolButton3: TToolButton;
CDS_LXR: TClientDataSet;
DSLXR: TDataSource;
ScrollBox1: TScrollBox;
Label2: TLabel;
Label6: TLabel;
Label12: TLabel;
Label39: TLabel;
Label7: TLabel;
Label19: TLabel;
CoName: TEdit;
Note: TMemo;
Label1: TLabel;
CoHRName: TEdit;
CoCode: TEdit;
Label3: TLabel;
Label4: TLabel;
Coarea: TBtnEditC;
CoAddress: TMemo;
Label5: TLabel;
Label8: TLabel;
CType: TComboBox;
ChuanYangD: TMemo;
Label9: TLabel;
Panel1: TPanel;
Panel2: TPanel;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v3Column3: TcxGridDBColumn;
cxGridDBColumn1: TcxGridDBColumn;
cxGridDBColumn2: TcxGridDBColumn;
cxGridDBColumn3: TcxGridDBColumn;
cxGridDBColumn4: TcxGridDBColumn;
cxGridDBColumn5: TcxGridDBColumn;
Tv1Column1: TcxGridDBColumn;
Tv1Column2: TcxGridDBColumn;
v3Column2: TcxGridDBColumn;
cxGridLevel1: TcxGridLevel;
ToolBar2: TToolBar;
ToolButton1: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
Panel4: TPanel;
cxGrid2: TcxGrid;
TV2: TcxGridDBTableView;
cxGridDBColumn6: TcxGridDBColumn;
cxGridDBColumn7: TcxGridDBColumn;
cxGridLevel2: TcxGridLevel;
ToolBar3: TToolBar;
ToolButton2: TToolButton;
ToolButton6: TToolButton;
Picture4: TcxDBImage;
DataSource1: TDataSource;
ADOQueryImage: TADOQuery;
DS_YF: TDataSource;
CDS_YF: TClientDataSet;
ToolButton7: TToolButton;
MDQDate: TEdit;
country: TBtnEditC;
Salesman: TBtnEditC;
cxgrdpmn1: TcxGridPopupMenu;
cxGridPopupMenu1: TcxGridPopupMenu;
IdFTP1: TIdFTP;
TV2Column1: TcxGridDBColumn;
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);
procedure CoareaBtnDnClick(Sender: TObject);
procedure CoareaBtnUpClick(Sender: TObject);
procedure TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ToolButton7Click(Sender: TObject);
procedure cxGridDBColumn7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
procedure Picture4DblClick(Sender: TObject);
private
{ Private declarations }
procedure InitGrid();
procedure InitImage();
function SaveData(): Boolean;
procedure LookImage(FileName: string);
public
fFlileFlag: string;
fkhType: string;
{ Public declarations }
FCOID: string;
end;
var
frmCustomerInput: TfrmCustomerInput;
implementation
uses
U_DataLink, U_RTFun, U_ZDYHelp, getpic, U_YWYSel;
{$R *.dfm}
procedure TfrmCustomerInput.InitImage();
begin
with ADOQueryImage do
begin
close;
sql.Clear;
sql.Add('select * from TP_File A');
sql.Add('where WBID=' + quotedstr(Trim(CDS_YF.fieldbyname('CFid').AsString)));
// ShowMessage(SQL.Text);
open;
end;
end;
procedure TfrmCustomerInput.Picture4DblClick(Sender: TObject);
begin
if TcxDBImage(Sender).Picture.Height = 0 then
exit;
LookImage(ADOQueryImage.fieldbyname(TcxDBImage(Sender).Hint).asstring);
end;
procedure TfrmCustomerInput.LookImage(FileName: string);
var
sFieldName: string;
// ff: TADOBlobStream;
// FJStream : TMemoryStream;
begin
sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\ͼƬ<CDBC>鿴';
if not DirectoryExists(pchar(sFieldName)) then
CreateDirectory(pchar(sFieldName), nil);
sFieldName := sFieldName + '\' + trim(FileName);
try
IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ', '127.0.0.1');
IdFTP1.Username := 'three';
IdFTP1.Password := '641010';
IdFTP1.Connect();
except
;
end;
if IdFTP1.Connected then
begin
// Panel2.Caption:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD>Ե<EFBFBD>...';
// Panel2.Visible:=true;
// application.ProcessMessages;
try
IdFTP1.Get(fFlileFlag + '\' + Trim(FileName), sFieldName, true, false);
except
// Panel2.Visible:=false;
Application.MessageBox('<27>ͻ<EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
IdFTP1.Quit;
Exit;
end;
end
else
begin
// Panel2.Visible:=false;
Application.MessageBox('<27>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', MB_ICONWARNING);
IdFTP1.Quit;
Exit;
end;
// Panel2.Visible:=false;
if IdFTP1.Connected then
IdFTP1.Quit;
ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;
procedure TfrmCustomerInput.InitGrid();
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Filtered := False;
Close;
SQL.Clear;
sql.Add(' select * from Company where CoType=''<27>ͻ<EFBFBD>'' 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);
with ADOQueryMain do
begin
Filtered := False;
Close;
SQL.Clear;
sql.Add(' select * from Company_YF where COID=' + quotedstr(Trim(FCOID)));
Open;
end;
SCreateCDS(ADOQueryMain, CDS_YF);
SInitCDSData(ADOQueryMain, CDS_YF);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmCustomerInput.FormDestroy(Sender: TObject);
begin
frmCustomerInput := nil;
end;
procedure TfrmCustomerInput.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfrmCustomerInput.TBCloseClick(Sender: TObject);
begin
WriteCxGrid(trim(self.Caption), Tv1, '<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>');
ModalResult := 1;
end;
procedure TfrmCustomerInput.FormShow(Sender: TObject);
begin
ReadCxGrid(trim(self.Caption), Tv1, '<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>');
InitGrid();
if CoCode.Text <> '' then
exit;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add(' exec P_Com_Get_No @Str=''KH'' ');
Open;
end;
CoCode.Text := trim(ADOQueryTemp.FieldByName('NewCoCode').asstring);
end;
procedure TfrmCustomerInput.TBRafreshClick(Sender: TObject);
begin
InitGrid();
end;
function TfrmCustomerInput.SaveData(): Boolean;
var
MaxId, MaxSubId, FCoCode, FCCID, MaxCFID: 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=''KH'' ');
Open;
end;
CoCode.Text := trim(ADOQueryTemp.FieldByName('NewCoCode').asstring);
end;
// CoCode.Text := trim(FCoCode);
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>';
Post;
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>'' and Valid=''Y'' ');
Open;
end;
if ADOQueryCmd.RecordCount > 1 then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>!', '<27><>ʾ', 0);
Exit;
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>'' and Valid=''Y'' ');
Open;
end;
if ADOQueryCmd.RecordCount > 1 then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>!', '<27><>ʾ', 0);
Exit;
end;
//////////////// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5> ////////////////////////
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;
//////////////// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5> ////////////////////////
//////////////// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ////////////////////////
if not CDS_YF.IsEmpty then
begin
with CDS_YF do
begin
CDS_YF.First;
while not Eof do
begin
MaxCFID := Trim(CDS_YF.fieldbyname('CFID').AsString);
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select * from Company_YF where CFID=' + quotedstr(Trim(MaxCFID)));
Open;
end;
with ADOQueryCmd do
begin
if ADOQueryCmd.IsEmpty then
begin
Append;
end
else
begin
Edit;
end;
FieldByName('CFID').Value := Trim(MaxCFID);
FieldByName('COID').Value := Trim(MaxId);
RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_YF, 'Company_YF', 0);
Post;
end;
with CDS_YF do
begin
Edit;
FieldByName('CFID').Value := Trim(MaxCFID);
Post;
end;
CDS_YF.Next;
end;
end;
end;
//////////////// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ////////////////////////
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 TfrmCustomerInput.ToolButton3Click(Sender: TObject);
begin
if Trim(CoName.Text) = '' then
begin
Application.MessageBox('<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
Exit;
end;
// if Trim(CoCode.Text)='' then
// begin
// Application.MessageBox('<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD><CEAA>!','<27><>ʾ',0);
// Exit;
// end;
if SaveData() then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!', '<27><>ʾ', 0);
end;
end;
procedure TfrmCustomerInput.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 TfrmCustomerInput.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 TfrmCustomerInput.ToolButton6Click(Sender: TObject);
begin
if Trim(CDS_YF.fieldbyname('CFID').AsString) <> '' then
begin
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('delete Company_YF where CFID=''' + Trim(CDS_YF.fieldbyname('CFID').AsString) + '''');
ExecSQL;
end;
end;
CDS_YF.Delete;
if CDS_YF.IsEmpty = false then
begin
if CDS_YF.Locate('IsDefault', true, []) = false then
begin
CDS_YF.first;
CDS_YF.edit;
CDS_YF.FieldByName('IsDefault').value := true;
end;
end;
end;
procedure TfrmCustomerInput.ToolButton7Click(Sender: TObject);
var
DwFlag: string;
begin
DwFlag := trim(CDS_YF.FieldByName('CFID').AsString);
if CDS_YF.Locate('IsDefault', true, []) then
begin
CDS_YF.edit;
CDS_YF.FieldByName('IsDefault').value := false;
end;
if CDS_YF.Locate('CFID', DwFlag, []) then
begin
CDS_YF.edit;
CDS_YF.FieldByName('IsDefault').value := true;
end;
end;
procedure TfrmCustomerInput.TV2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
InitImage();
end;
procedure TfrmCustomerInput.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;
procedure TfrmCustomerInput.ToolButton2Click(Sender: TObject);
var
MaxCFID: string;
begin
if GetLSNo(ADOQueryCmd, MaxCFID, 'CCS', 'Company_YF', 4, 1) = False then
begin
Application.MessageBox(<><C8A1><EFBFBD><EFBFBD>IDʧ<44><CAA7>!', '<27><>ʾ', 0);
Exit;
end;
if CDS_YF.IsEmpty then
begin
with CDS_YF do
begin
Append;
fieldbyname('CFID').Value := trim(MaxCFID);
fieldbyname('IsDefault').Value := true;
Post;
end;
end
else
begin
with CDS_YF do
begin
Append;
fieldbyname('CFID').Value := trim(MaxCFID);
fieldbyname('IsDefault').Value := false;
Post;
end;
end;
end;
procedure TfrmCustomerInput.CoareaBtnDnClick(Sender: TObject);
begin
TBtnEditC(Sender).Text := '';
TBtnEditC(Sender).TxtCode := '';
end;
procedure TfrmCustomerInput.CoareaBtnUpClick(Sender: TObject);
var
fsj: string;
FWZ: Integer;
begin
fsj := Trim(TEdit(Sender).Hint);
FWZ := Pos('/', fsj);
try
frmZDYHelp := TfrmZDYHelp.Create(Application);
with frmZDYHelp do
begin
flag := Copy(fsj, 1, FWZ - 1);
flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
if ShowModal = 1 then
begin
TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
end;
end;
finally
frmZDYHelp.Free;
end;
end;
procedure TfrmCustomerInput.cxGridDBColumn7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
FormGetPic := TFormGetPic.create(self);
with FormGetPic do
begin
fFlileFlag := self.fFlileFlag;
FMainId := trim(CDS_YF.FieldByName('CFid').AsString);
fkeyNO := trim(CDS_YF.FieldByName('YFTPName').AsString);
pat1 := 'FileName';
pic1 := 'FilesOther';
FTFType := 'HX';
if showmodal = 1 then
begin
with Self.CDS_YF do
begin
Edit;
FieldByName('YFTPName').Value := FormGetPic.fkeyNO;
Post;
end;
end;
free;
end;
Initimage();
end;
end.