D7gmYushang/客户供应商管理2(Company.dll)/U_Customer.pas

479 lines
13 KiB
ObjectPascal
Raw Normal View History

2025-09-24 13:13:14 +08:00
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, cxLookAndFeels, cxLookAndFeelPainters,
cxNavigator;
type
TfrmCustomer = class(TForm)
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;
ToolButton1: TToolButton;
v2Column3: TcxGridDBColumn;
v2Column4: TcxGridDBColumn;
Tv2Column1: TcxGridDBColumn;
Tv2Column2: TcxGridDBColumn;
Panel2: TPanel;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v3Column3: TcxGridDBColumn;
cxGridDBColumn1: TcxGridDBColumn;
cxGridDBColumn2: TcxGridDBColumn;
cxGridDBColumn3: TcxGridDBColumn;
cxGridDBColumn4: TcxGridDBColumn;
cxGridDBColumn5: TcxGridDBColumn;
Tv1Column1: TcxGridDBColumn;
v3Column2: TcxGridDBColumn;
cxGridLevel2: TcxGridLevel;
cxGrid3: TcxGrid;
tv3: TcxGridDBTableView;
cxGridDBColumn13: TcxGridDBColumn;
cxGridLevel3: TcxGridLevel;
CDS_DZ: TClientDataSet;
DSDZ: TDataSource;
Tv1Column2: TcxGridDBColumn;
ToolButton5: TToolButton;
Tv2Column3: TcxGridDBColumn;
BegDate: TDateTimePicker;
EndDate: TDateTimePicker;
Tv2Column4: TcxGridDBColumn;
CheckBox1: TCheckBox;
Tv2Column5: TcxGridDBColumn;
Label5: TLabel;
FILLER: TEdit;
ToolButton6: TToolButton;
Tv2Column6: TcxGridDBColumn;
ToolButton7: TToolButton;
Tv2Column7: 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 ToolButton5Click(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure Tv2CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
procedure ToolButton7Click(Sender: TObject);
private
{ Private declarations }
procedure InitGrid();
procedure SetStatus();
public
canshu1: string;
end;
//var
// frmCustomer: TfrmCustomer;
implementation
uses
U_DataLink, U_Fun, U_ZDYHelp, U_CustomerInput, U_YWYSel, U_FjList_RZ;
{$R *.dfm}
procedure TfrmCustomer.SetStatus();
begin
ToolButton1.Visible := false;
if Trim(canshu1) = '<27><><EFBFBD><EFBFBD>Ա' then
begin
ToolButton1.Visible := true;
ToolButton6.Visible := true;
ToolButton7.Visible := 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 * ');
sql.Add(',ISSC=cast((case when isnull((select count(*) from TP_File X where X.WBID=A.coid ),0)>0 then 1 else 0 end) as bit)');
sql.Add('from Company a where CoType=''<27>ͻ<EFBFBD>'' and Valid=''Y'' ');
if CheckBox1.Checked = True then
begin
sql.Add(' and FILLTIME>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.Date)) + '''');
sql.Add(' and FILLTIME<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1)) + '''');
end;
if Trim(canshu1) = <><D2B5>Ա' then
sql.Add('and ( Salesman=' + Quotedstr(Trim(DName)) + ' or XSZL=' + Quotedstr(Trim(DName)) + ') ');
// sql.Add(' and Salesman=' + quotedstr(trim(DName)));
if Trim(canshu1) = '<27>鳤' then
sql.Add(' and SalesClass in (select Udept from SY_User where UType=''<27>鳤'' and UserID=' + quotedstr(trim(DCode)) + ' )');
// ShowMessage(SQL.Text);
Open;
end;
SCreateCDS20(ADOQueryMain, CDS_HZ);
SInitCDSData20(ADOQueryMain, CDS_HZ);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmCustomer.FormDestroy(Sender: TObject);
begin
// frmCustomer:=nil;
end;
procedure TfrmCustomer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
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
ReadCxGrid(trim(self.Caption), Tv2, '<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>');
SetStatus();
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add(' select * from SY_User where uDEPT=''<27><><EFBFBD><EFBFBD>'' and username=' + QuotedStr(Trim(DName)));
Open;
end;
if ADOQueryTemp.IsEmpty = True then
begin
TBDel.Visible := False;
end;
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));
SCreateCDS20(ADOQueryMain, CDS_HZ);
SInitCDSData20(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
FCOID := Trim(Self.CDS_HZ.fieldbyname('COID').AsString);
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add(' select * from YF_Money_CR where FactoryName=' + QuotedStr(Trim(CDS_HZ.fieldbyname('CoName').AsString)));
Open;
end;
if ADOQueryTemp.IsEmpty = false then
begin
with ADOQueryTemp do
begin
Close;
SQL.Clear;
sql.Add(' select * from SY_User where uDEPT=''<27><><EFBFBD><EFBFBD>'' and username=' + QuotedStr(Trim(DName)));
Open;
end;
if ADOQueryTemp.IsEmpty = True then
begin
CoName.Enabled := False;
end;
end;
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 := '';
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;
SCreateCDS20(ADOQueryTemp, CDS_LXR);
SInitCDSData20(ADOQueryTemp, CDS_LXR);
// with ADOQueryTemp do
// begin
// Filtered := False;
// Close;
// SQL.Clear;
// sql.Add(' select * from Company_DZ where COID=' + quotedstr(Trim(CDS_HZ.FieldByName('COID').AsString)));
// Open;
// end;
// SCreateCDS20(ADOQueryTemp, CDS_DZ);
// SInitCDSData20(ADOQueryTemp, CDS_DZ);
end;
procedure TfrmCustomer.ToolButton1Click(Sender: TObject);
var
MSalesman: string;
begin
if CDS_HZ.IsEmpty then
Exit;
if CDS_HZ.Locate('SSel', True, []) = False then
begin
Application.MessageBox(ѡ<CEB4><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
Exit;
end;
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;
try
ADOQueryCmd.Connection.BeginTrans;
while CDS_HZ.Locate('SSel', True, []) do
begin
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('update Company set Salesman=' + quotedstr(trim(MSalesman)) + ' where COID=''' + Trim(CDS_HZ.fieldbyname('COID').AsString) + '''');
sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
sql.Add(' ' + quotedstr(trim(DName)));
sql.Add(',getdate() ');
sql.Add(',' + quotedstr(trim(self.Caption)));
sql.Add(',' + quotedstr(trim('<27>޸<EFBFBD>ҵ<EFBFBD><D2B5>Ա')));
sql.Add(',' + quotedstr(trim('<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>' + trim(CDS_HZ.FieldByName('CoName').AsString))));
sql.Add(',' + quotedstr(trim('<27>ɹ<EFBFBD>')));
sql.Add(')');
ExecSQL;
end;
CDS_HZ.Delete;
end;
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27>޸<EFBFBD><DEB8>쳣!', '<27><>ʾ', 0);
end;
initgrid();
end;
procedure TfrmCustomer.ToolButton5Click(Sender: TObject);
begin
if CDS_HZ.IsEmpty then
Exit;
try
frmFjList_RZ := TfrmFjList_RZ.Create(Application);
with frmFjList_RZ do
begin
fkeyNO := Trim(Self.CDS_HZ.fieldbyname('coid').AsString);
fType := '<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>';
if canshu1 <> '<27><><EFBFBD><EFBFBD>Ա' then
begin
cxButton1.Visible := False;
end;
if ShowModal = 1 then
begin
end;
end;
finally
frmFjList_RZ.Free;
end;
end;
procedure TfrmCustomer.CheckBox1Click(Sender: TObject);
begin
InitGrid();
end;
procedure TfrmCustomer.FormCreate(Sender: TObject);
begin
EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
BegDate.DateTime := EndDate.DateTime - 90;
end;
procedure TfrmCustomer.ToolButton6Click(Sender: TObject);
var
FCOID: string;
begin
FCOID := Trim(CDS_HZ.fieldbyname('COID').AsString);
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('update Company set ISBD=''<27>Ѱ<EFBFBD><D1B0><EFBFBD>'' where COID=''' + Trim(CDS_HZ.fieldbyname('COID').AsString) + '''');
ExecSQL;
end;
initgrid();
CDS_HZ.locate('COID', FCOID, []);
end;
procedure TfrmCustomer.Tv2CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
if (AViewInfo.GridRecord.Values[Tv2Column6.Index] = '<27>Ѱ<EFBFBD><D1B0><EFBFBD>') then
begin
ACanvas.FONT.Color := clRed;
end;
end;
procedure TfrmCustomer.ToolButton7Click(Sender: TObject);
var
FCOID: string;
begin
FCOID := Trim(CDS_HZ.fieldbyname('COID').AsString);
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('update Company set ISBD='<><CEB4><EFBFBD><EFBFBD>'' where COID=''' + Trim(CDS_HZ.fieldbyname('COID').AsString) + '''');
ExecSQL;
end;
initgrid();
CDS_HZ.locate('COID', FCOID, []);
end;
end.