419 lines
10 KiB
ObjectPascal
419 lines
10 KiB
ObjectPascal
![]() |
unit U_Customer;
|
|||
|
|
|||
|
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, U_BaseList, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
|
|||
|
dxBarBuiltInMenu;
|
|||
|
|
|||
|
type
|
|||
|
FdDy = record
|
|||
|
inc: integer; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><D7BD>־<EFBFBD><D6BE><EFBFBD>
|
|||
|
FDdys: string[32]; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
|||
|
FdDysName: string[32]; //<2F>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><D7BD><EFBFBD>
|
|||
|
end;
|
|||
|
|
|||
|
TfrmCustomer = class(TFrmBaseList)
|
|||
|
ToolBar1: TToolBar;
|
|||
|
TBRafresh: TToolButton;
|
|||
|
TBDel: TToolButton;
|
|||
|
TBClose: TToolButton;
|
|||
|
ADOQueryTemp: TADOQuery;
|
|||
|
ADOQueryCmd: TADOQuery;
|
|||
|
Panel1: TPanel;
|
|||
|
ToolButton2: TToolButton;
|
|||
|
ADOQueryMain: TADOQuery;
|
|||
|
RM1: TRMGridReport;
|
|||
|
RMDB_Main: TRMDBDataSet;
|
|||
|
Label3: TLabel;
|
|||
|
CoName: TEdit;
|
|||
|
cxGrid2: TcxGrid;
|
|||
|
Tv2: TcxGridDBTableView;
|
|||
|
cxGridLevel1: TcxGridLevel;
|
|||
|
cxGridPopupMenu2: TcxGridPopupMenu;
|
|||
|
DS_HZ: TDataSource;
|
|||
|
CDS_HZ: TClientDataSet;
|
|||
|
ToolButton3: TToolButton;
|
|||
|
v2Column6: TcxGridDBColumn;
|
|||
|
v2Column1: TcxGridDBColumn;
|
|||
|
v2Column2: TcxGridDBColumn;
|
|||
|
v2Column7: TcxGridDBColumn;
|
|||
|
Label1: TLabel;
|
|||
|
CoCode: TEdit;
|
|||
|
v2Column10: TcxGridDBColumn;
|
|||
|
ToolButton4: TToolButton;
|
|||
|
Label2: TLabel;
|
|||
|
Salesman: TEdit;
|
|||
|
v2DEFStr7: TcxGridDBColumn;
|
|||
|
Coarea: TEdit;
|
|||
|
Label4: TLabel;
|
|||
|
v2Column15: TcxGridDBColumn;
|
|||
|
CDS_LXR: TClientDataSet;
|
|||
|
DSLXR: TDataSource;
|
|||
|
cxGrid1: TcxGrid;
|
|||
|
Tv1: TcxGridDBTableView;
|
|||
|
v3Column3: TcxGridDBColumn;
|
|||
|
cxGridDBColumn1: TcxGridDBColumn;
|
|||
|
cxGridDBColumn2: TcxGridDBColumn;
|
|||
|
cxGridDBColumn3: TcxGridDBColumn;
|
|||
|
cxGridDBColumn4: TcxGridDBColumn;
|
|||
|
cxGridDBColumn5: TcxGridDBColumn;
|
|||
|
Tv1Column1: TcxGridDBColumn;
|
|||
|
v3Column2: TcxGridDBColumn;
|
|||
|
cxGridLevel2: TcxGridLevel;
|
|||
|
ToolButton1: TToolButton;
|
|||
|
v2Column3: TcxGridDBColumn;
|
|||
|
v2Column4: TcxGridDBColumn;
|
|||
|
ToolButton5: TToolButton;
|
|||
|
OpenDialog1: TOpenDialog;
|
|||
|
Tv1Column2: TcxGridDBColumn;
|
|||
|
Tv2Column1: TcxGridDBColumn;
|
|||
|
Tv2Column2: TcxGridDBColumn;
|
|||
|
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 ToolButton2Click(Sender: TObject);
|
|||
|
procedure CoNameChange(Sender: TObject);
|
|||
|
procedure ToolButton4Click(Sender: TObject);
|
|||
|
procedure ToolButton3Click(Sender: TObject);
|
|||
|
procedure TBuserClick(Sender: TObject);
|
|||
|
procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
|
|||
|
procedure ToolButton1Click(Sender: TObject);
|
|||
|
procedure FormCreate(Sender: TObject);
|
|||
|
procedure ToolButton5Click(Sender: TObject);
|
|||
|
private
|
|||
|
fFlileFlag: string;
|
|||
|
dFdDy: array[0..30] of FdDy;
|
|||
|
{ Private declarations }
|
|||
|
procedure InitGrid();
|
|||
|
procedure SetStatus();
|
|||
|
public
|
|||
|
canshu1: string;
|
|||
|
end;
|
|||
|
|
|||
|
//var
|
|||
|
// frmCustomer: TfrmCustomer;
|
|||
|
|
|||
|
implementation
|
|||
|
|
|||
|
uses
|
|||
|
U_DataLink, U_RTFun, U_ZDYHelp, U_CustomerInput, U_YWYSel;
|
|||
|
|
|||
|
{$R *.dfm}
|
|||
|
procedure TfrmCustomer.SetStatus();
|
|||
|
begin
|
|||
|
ToolButton1.Visible := false;
|
|||
|
if Trim(canshu1) = '<27><><EFBFBD><EFBFBD>Ա' then
|
|||
|
begin
|
|||
|
ToolButton1.Enabled := true;
|
|||
|
end
|
|||
|
else
|
|||
|
begin
|
|||
|
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.InitGrid();
|
|||
|
begin
|
|||
|
try
|
|||
|
ADOQueryMain.DisableControls;
|
|||
|
with ADOQueryMain do
|
|||
|
begin
|
|||
|
Filtered := False;
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add(' select * from Company where CoType=''<27>ͻ<EFBFBD>'' and Valid=''Y'' ');
|
|||
|
if Trim(canshu1) = 'ҵ<><D2B5>Ա' then
|
|||
|
sql.Add(' and Salesman=' + quotedstr(trim(DName)));
|
|||
|
Open;
|
|||
|
end;
|
|||
|
SCreateCDS(ADOQueryMain, CDS_HZ);
|
|||
|
SInitCDSData(ADOQueryMain, CDS_HZ);
|
|||
|
finally
|
|||
|
ADOQueryMain.EnableControls;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.FormDestroy(Sender: TObject);
|
|||
|
begin
|
|||
|
inherited;
|
|||
|
// frmCustomer:=nil;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
begin
|
|||
|
inherited;
|
|||
|
Action := caFree;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.TBCloseClick(Sender: TObject);
|
|||
|
begin
|
|||
|
WriteCxGrid(trim(self.caption), Tv2, '<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>');
|
|||
|
Close;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.TBDelClick(Sender: TObject);
|
|||
|
begin
|
|||
|
if CDS_HZ.IsEmpty then
|
|||
|
Exit;
|
|||
|
if Application.MessageBox('ȷ<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', 32 + 4) <> IDYES then
|
|||
|
Exit;
|
|||
|
|
|||
|
if Trim(CDS_HZ.fieldbyname('COID').AsString) <> '' then
|
|||
|
begin
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add('update Company set Valid=''N'' where COID=''' + Trim(CDS_HZ.fieldbyname('COID').AsString) + '''');
|
|||
|
ExecSQL;
|
|||
|
end;
|
|||
|
end;
|
|||
|
CDS_HZ.Delete;
|
|||
|
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.FormShow(Sender: TObject);
|
|||
|
begin
|
|||
|
inherited;
|
|||
|
fFlileFlag := UserDataFlag + 'HX';
|
|||
|
canshu1 := self.fParameters1;
|
|||
|
ReadCxGrid(trim(self.Caption), Tv2, '<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>');
|
|||
|
SetStatus();
|
|||
|
InitGrid();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.TBRafreshClick(Sender: TObject);
|
|||
|
begin
|
|||
|
InitGrid();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.ToolButton2Click(Sender: TObject);
|
|||
|
begin
|
|||
|
if ADOQueryMain.Active then
|
|||
|
begin
|
|||
|
SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
|
|||
|
SCreateCDS(ADOQueryMain, CDS_HZ);
|
|||
|
SInitCDSData(ADOQueryMain, CDS_HZ);
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.CoNameChange(Sender: TObject);
|
|||
|
begin
|
|||
|
ToolButton2.Click;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.ToolButton4Click(Sender: TObject);
|
|||
|
begin
|
|||
|
if CDS_HZ.IsEmpty then
|
|||
|
exit;
|
|||
|
try
|
|||
|
frmCustomerInput := TfrmCustomerInput.Create(Application);
|
|||
|
with frmCustomerInput do
|
|||
|
begin
|
|||
|
fFlileFlag := self.fFlileFlag;
|
|||
|
FCOID := Trim(Self.CDS_HZ.fieldbyname('COID').AsString);
|
|||
|
if ShowModal = 1 then
|
|||
|
begin
|
|||
|
TBRafresh.Click;
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmCustomerInput.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.ToolButton3Click(Sender: TObject);
|
|||
|
begin
|
|||
|
try
|
|||
|
frmCustomerInput := TfrmCustomerInput.Create(Application);
|
|||
|
with frmCustomerInput do
|
|||
|
begin
|
|||
|
Salesman.Text := trim(Dname);
|
|||
|
FCOID := '';
|
|||
|
fFlileFlag := self.fFlileFlag;
|
|||
|
if ShowModal = 1 then
|
|||
|
begin
|
|||
|
InitGrid();
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmCustomerInput.Free;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.TBuserClick(Sender: TObject);
|
|||
|
var
|
|||
|
FuserName: string;
|
|||
|
begin
|
|||
|
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
|
|||
|
begin
|
|||
|
with ADOQueryTemp do
|
|||
|
begin
|
|||
|
Filtered := False;
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add(' select * from Company_contact where COID=' + quotedstr(Trim(CDS_HZ.FieldByName('COID').AsString)));
|
|||
|
Open;
|
|||
|
end;
|
|||
|
SCreateCDS(ADOQueryTemp, CDS_LXR);
|
|||
|
SInitCDSData(ADOQueryTemp, CDS_LXR);
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.ToolButton1Click(Sender: TObject);
|
|||
|
var
|
|||
|
MSalesman: string;
|
|||
|
begin
|
|||
|
try
|
|||
|
frmYWYSel := TfrmYWYSel.Create(Application);
|
|||
|
with frmYWYSel do
|
|||
|
begin
|
|||
|
if ShowModal = 1 then
|
|||
|
begin
|
|||
|
MSalesman := Trim(ClientDataSet1.fieldbyname('UserName').AsString);
|
|||
|
end;
|
|||
|
end;
|
|||
|
finally
|
|||
|
frmYWYSel.Free;
|
|||
|
end;
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add('update Company set Salesman=' + quotedstr(trim(MSalesman)) + ' where COID=''' + Trim(CDS_HZ.fieldbyname('COID').AsString) + '''');
|
|||
|
ExecSQL;
|
|||
|
end;
|
|||
|
initgrid();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.FormCreate(Sender: TObject);
|
|||
|
begin
|
|||
|
inherited;
|
|||
|
canshu1 := trim(DParameters1);
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmCustomer.ToolButton5Click(Sender: TObject);
|
|||
|
var
|
|||
|
excelApp, WorkBook: Variant;
|
|||
|
i, j, k, ExcelRowCount: integer;
|
|||
|
FCoCode, maxno: string;
|
|||
|
begin
|
|||
|
if GetLSNo(ADOQueryCmd, maxno, 'CO', 'Company', 4, 1) = False then
|
|||
|
begin
|
|||
|
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>!', '<27><>ʾ', 0);
|
|||
|
Exit;
|
|||
|
end;
|
|||
|
|
|||
|
|
|||
|
// if GetLSNo(ADOQueryCmd, FCoCode, 'K', 'KH_Zdy_Attachment', 4, 0) = False then
|
|||
|
// begin
|
|||
|
// Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', 0);
|
|||
|
// Exit;
|
|||
|
// end;
|
|||
|
|
|||
|
try
|
|||
|
excelApp := CreateOleObject('Excel.Application');
|
|||
|
openDialog1.Filter := '*.CSV;*.xls';
|
|||
|
if opendialog1.Execute then
|
|||
|
begin
|
|||
|
WorkBook := excelApp.WorkBooks.Open(OpenDialog1.FileName);
|
|||
|
end
|
|||
|
else
|
|||
|
exit;
|
|||
|
|
|||
|
excelApp.Visible := false;
|
|||
|
ExcelRowCount := WorkBook.WorkSheets[1].UsedRange.Rows.Count;
|
|||
|
except
|
|||
|
application.MessageBox('<27><><EFBFBD><EFBFBD>EXCEL<45><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ', MB_ICONERROR);
|
|||
|
exit;
|
|||
|
end;
|
|||
|
|
|||
|
try
|
|||
|
k := 0;
|
|||
|
for i := 1 to 30 do
|
|||
|
begin
|
|||
|
if trim(excelApp.Cells[1, i].value) = '' then
|
|||
|
break;
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3B6A8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ֶκ<D6B6><CEBA><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for j := 0 to Tv2.ColumnCount - 1 do
|
|||
|
begin
|
|||
|
if trim(excelApp.Cells[1, i].value) = trim(Tv2.Columns[j].Caption) then
|
|||
|
begin
|
|||
|
dFdDy[k].inc := i;
|
|||
|
dFdDy[k].FDdys := trim(Tv2.Columns[j].DataBinding.FieldName);
|
|||
|
dFdDy[k].FdDysName := trim(Tv2.Columns[j].Caption);
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
k := k + 1;
|
|||
|
end;
|
|||
|
except
|
|||
|
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ', MB_ICONERROR);
|
|||
|
exit;
|
|||
|
end;
|
|||
|
|
|||
|
try
|
|||
|
for i := 2 to ExcelRowCount do
|
|||
|
begin
|
|||
|
ADOQueryCmd.Connection.BeginTrans;
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
close;
|
|||
|
sql.Clear;
|
|||
|
sql.Add('select * from Company where 1=2');
|
|||
|
open;
|
|||
|
end;
|
|||
|
|
|||
|
ADOQueryCmd.Append;
|
|||
|
//<2F><><EFBFBD>ӵ<EFBFBD>i<EFBFBD><69><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
for j := 1 to k - 1 do
|
|||
|
begin
|
|||
|
if trim(dFdDy[j].FDdys) <> '' then
|
|||
|
ADOQueryCmd.fieldbyname(dFdDy[j].FDdys).Value := excelApp.Cells[i, dFdDy[j].inc].Value;
|
|||
|
end;
|
|||
|
|
|||
|
ADOQueryCmd.FieldByName('COID').Value := Trim(maxno) + inttostr(i);
|
|||
|
ADOQueryCmd.FieldByName('Filler').Value := Trim(DName);
|
|||
|
ADOQueryCmd.FieldByName('CoType').Value := '<27>ͻ<EFBFBD>';
|
|||
|
|
|||
|
ADOQueryCmd.Post;
|
|||
|
|
|||
|
ADOQueryCmd.Connection.CommitTrans;
|
|||
|
end;
|
|||
|
WorkBook.Close;
|
|||
|
excelApp.Quit;
|
|||
|
excelApp := Unassigned;
|
|||
|
WorkBook := Unassigned;
|
|||
|
|
|||
|
InitGrid();
|
|||
|
except
|
|||
|
WorkBook.Close;
|
|||
|
excelApp.Quit;
|
|||
|
excelApp := Unassigned;
|
|||
|
WorkBook := Unassigned;
|
|||
|
ADOQueryCmd.Connection.RollbackTrans;
|
|||
|
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ', MB_ICONERROR);
|
|||
|
exit;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
end.
|
|||
|
|