444 lines
11 KiB
ObjectPascal
444 lines
11 KiB
ObjectPascal
unit U_PrtDyeInfoInPut;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
|
||
cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
|
||
cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
|
||
cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
|
||
cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, StdCtrls, ExtCtrls,
|
||
cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
|
||
dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu, U_BaseInput,
|
||
U_BaseList, System.ImageList, Vcl.ImgList, ComObj;
|
||
|
||
type
|
||
TfrmPrtDyeInfoInPut = class(TfrmBaseInput)
|
||
cxGrid2: TcxGrid;
|
||
Tv1: TcxGridDBTableView;
|
||
v1Column2: TcxGridDBColumn;
|
||
v1SPName: TcxGridDBColumn;
|
||
cxGrid2Level1: TcxGridLevel;
|
||
ToolBar1: TToolBar;
|
||
TBAdd: TToolButton;
|
||
TBDel: TToolButton;
|
||
TBSave: TToolButton;
|
||
TBClose: TToolButton;
|
||
DataSource3: TDataSource;
|
||
CDS_Sub: TClientDataSet;
|
||
ADOQueryCmd: TADOQuery;
|
||
ADOQueryMain: TADOQuery;
|
||
ADOQueryTemp: TADOQuery;
|
||
cxGridPopupMenu2: TcxGridPopupMenu;
|
||
v1Column12: TcxGridDBColumn;
|
||
v1SPSpec: TcxGridDBColumn;
|
||
v1QtyUnit: TcxGridDBColumn;
|
||
v1Column1: TcxGridDBColumn;
|
||
v1Column18: TcxGridDBColumn;
|
||
v1Column10: TcxGridDBColumn;
|
||
v1Column15: TcxGridDBColumn;
|
||
v1Column3: TcxGridDBColumn;
|
||
ToolButton1: TToolButton;
|
||
Tv1Column1: TcxGridDBColumn;
|
||
Tv1Column2: TcxGridDBColumn;
|
||
Tv1Column3: TcxGridDBColumn;
|
||
ToolButton2: TToolButton;
|
||
CDS_LM: TClientDataSet;
|
||
OpenDialog1: TOpenDialog;
|
||
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
||
procedure TBAddClick(Sender: TObject);
|
||
procedure TBCloseClick(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure TBDelClick(Sender: TObject);
|
||
procedure TBSaveClick(Sender: TObject);
|
||
procedure ToolButton1Click(Sender: TObject);
|
||
procedure v1QtyUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
procedure ButtonEdit(Sender: TObject; AButtonIndex: Integer);
|
||
procedure Tv1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
procedure ToolButton2Click(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
function SaveCKData(): Boolean;
|
||
public
|
||
{ Public declarations }
|
||
FBCId, FSTKName: string;
|
||
|
||
end;
|
||
|
||
var
|
||
frmPrtDyeInfoInPut: TfrmPrtDyeInfoInPut;
|
||
|
||
implementation
|
||
|
||
uses
|
||
U_DataLink, U_RTFun, U_ZDYHelp;
|
||
|
||
{$R *.dfm}
|
||
|
||
procedure TfrmPrtDyeInfoInPut.FormClose(Sender: TObject; var Action: TCloseAction);
|
||
begin
|
||
inherited;
|
||
Action := caFree;
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.TBAddClick(Sender: TObject);
|
||
begin
|
||
if CDS_Sub.IsEmpty = False then
|
||
begin
|
||
CopyAddRowCDS(CDS_Sub);
|
||
with CDS_Sub do
|
||
begin
|
||
Edit;
|
||
FieldByName('BPIID').Value := null;
|
||
post;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
with CDS_Sub do
|
||
begin
|
||
Append;
|
||
Post;
|
||
end;
|
||
end;
|
||
|
||
end;
|
||
|
||
function TfrmPrtDyeInfoInPut.SaveCKData(): Boolean;
|
||
var
|
||
MaxNo, MBPIID: string;
|
||
begin
|
||
try
|
||
ADOQueryCmd.Connection.BeginTrans;
|
||
CDS_Sub.DisableControls;
|
||
with CDS_Sub do
|
||
begin
|
||
First;
|
||
while not eof do
|
||
begin
|
||
with ADOQueryTemp do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add('select * from BS_Product_Info where BPIID=''' + Trim(CDS_Sub.fieldbyname('BPIID').AsString) + '''');
|
||
open;
|
||
end;
|
||
MBPIID := Trim(ADOQueryTemp.fieldbyname('BPIID').AsString);
|
||
if Trim(MBPIID) = '' then
|
||
begin
|
||
if GetLSNo(ADOQueryCmd, MaxNo, 'P', 'BS_Product_Info', 4, 0) = False then
|
||
raise Exception.Create('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>');
|
||
end
|
||
else
|
||
begin
|
||
MaxNo := Trim(MBPIID);
|
||
end;
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add('select * from BS_Product_Info where BPIID=''' + Trim(MaxNo) + '''');
|
||
Open;
|
||
end;
|
||
with ADOQueryCmd do
|
||
begin
|
||
if Trim(MBPIID) = '' then
|
||
begin
|
||
Append;
|
||
FieldByName('Fillid').Value := Trim(Dcode);
|
||
FieldByName('Filler').Value := Trim(DName)
|
||
end
|
||
else
|
||
begin
|
||
Edit;
|
||
FieldByName('Editid').Value := Trim(Dcode);
|
||
FieldByName('Editer').Value := Trim(DName);
|
||
FieldByName('EditTime').Value := SGetServerDate(ADOQueryTemp);
|
||
end;
|
||
FieldByName('BPIID').Value := Trim(MaxNo);
|
||
FieldByName('STKName').Value := Trim(FSTKName);
|
||
|
||
RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Sub, 'BS_Product_Info', 2);
|
||
Post;
|
||
end;
|
||
|
||
Edit;
|
||
FieldByName('BPIID').Value := Trim(MaxNo);
|
||
Post;
|
||
Next;
|
||
end;
|
||
end;
|
||
CDS_Sub.EnableControls;
|
||
ADOQueryCmd.Connection.CommitTrans;
|
||
Result := True;
|
||
except
|
||
Result := False;
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
application.MessageBox(PChar(Exception(ExceptObject).Message), '<27><>ʾ<EFBFBD><CABE>Ϣ', 0);
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.TBCloseClick(Sender: TObject);
|
||
begin
|
||
|
||
Close;
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.FormShow(Sender: TObject);
|
||
var
|
||
fsj: string;
|
||
begin
|
||
inherited;
|
||
ReadCxGrid(trim(self.Caption), Tv1, 'Ⱦ<><C8BE><EFBFBD>ϲֿ<CFB2>');
|
||
with CDS_LM do
|
||
begin
|
||
FieldDefs.Clear;
|
||
FieldDefs.Add('LXH', ftInteger, 0);
|
||
FieldDefs.Add('lCode', ftString, 40);
|
||
FieldDefs.Add('LName', ftString, 40);
|
||
close;
|
||
CreateDataSet;
|
||
end;
|
||
with ADOQueryTemp do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add(' select A.* ');
|
||
sql.Add(' from BS_Product_Info A');
|
||
sql.Add(' where BPIID=''' + Trim(FBCId) + '''');
|
||
Open;
|
||
end;
|
||
SCreateCDS(ADOQueryTemp, CDS_Sub);
|
||
SInitCDSData(ADOQueryTemp, CDS_Sub);
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.TBDelClick(Sender: TObject);
|
||
begin
|
||
if CDS_Sub.IsEmpty then
|
||
Exit;
|
||
if Trim(CDS_Sub.fieldbyname('BPIID').AsString) <> '' then
|
||
begin
|
||
if Application.MessageBox('ȷ<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', 32 + 4) <> IDYES then
|
||
Exit;
|
||
|
||
try
|
||
ADOQueryCmd.Connection.BeginTrans;
|
||
with ADOQueryCmd do
|
||
begin
|
||
Close;
|
||
sql.Clear;
|
||
sql.Add(' delete BS_Product_Info where BPIID=''' + Trim(CDS_Sub.fieldbyname('BPIID').AsString) + '''');
|
||
ExecSQL;
|
||
end;
|
||
|
||
ADOQueryCmd.Connection.CommitTrans;
|
||
CDS_Sub.Delete;
|
||
except
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
Application.MessageBox('ɾ<><C9BE><EFBFBD>쳣!', '<27><>ʾ', 0);
|
||
end;
|
||
|
||
end
|
||
else
|
||
begin
|
||
CDS_Sub.Delete;
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.TBSaveClick(Sender: TObject);
|
||
begin
|
||
if CDS_Sub.IsEmpty then
|
||
Exit;
|
||
if CDS_Sub.Locate('P_Name', null, []) = True then
|
||
begin
|
||
Application.MessageBox('Ʒ<><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
if CDS_Sub.Locate('P_Name', null, []) = True then
|
||
begin
|
||
Application.MessageBox('Ʒ<><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
|
||
if CDS_Sub.Locate('QtyUnit', null, []) = True then
|
||
begin
|
||
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>!', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
if SaveCKData() then
|
||
begin
|
||
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!', '<27><>ʾ', 0);
|
||
ModalResult := 1;
|
||
Exit;
|
||
end;
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.ToolButton1Click(Sender: TObject);
|
||
begin
|
||
WriteCxGrid(trim(self.Caption), Tv1, 'Ⱦ<><C8BE><EFBFBD>ϲֿ<CFB2>');
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.ToolButton2Click(Sender: TObject);
|
||
var
|
||
excelApp, WorkBook: Variant;
|
||
i, j, k, LX, ExcelRowCount: integer;
|
||
maxId, FCPID, FCPName, t1, t2, t3, FFID: string;
|
||
begin
|
||
|
||
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;
|
||
|
||
CDS_LM.EmptyDataSet;
|
||
|
||
for j := 0 to Tv1.ColumnCount - 1 do
|
||
begin
|
||
with CDS_LM do
|
||
begin
|
||
Append;
|
||
FieldByName('LCode').Value := trim(Tv1.Columns[j].DataBinding.FieldName);
|
||
FieldByName('LName').Value := trim(Tv1.Columns[j].Caption);
|
||
Post;
|
||
end;
|
||
end;
|
||
|
||
try
|
||
for i := 1 to 50 do
|
||
begin
|
||
if trim(WorkBook.WorkSheets[1].Cells[1, i].value) = '' then
|
||
continue;
|
||
if CDS_LM.Locate('LName', trim(WorkBook.WorkSheets[1].Cells[1, i].value), []) then
|
||
begin
|
||
with CDS_LM do
|
||
begin
|
||
Edit;
|
||
FieldByName('LXH').Value := i;
|
||
Post;
|
||
end;
|
||
end;
|
||
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
|
||
with CDS_Sub do
|
||
begin
|
||
Append;
|
||
CDS_LM.First;
|
||
while not CDS_LM.Eof do
|
||
begin
|
||
if CDS_LM.FieldByName('LXH').AsInteger > 0 then
|
||
CDS_Sub.fieldbyname(CDS_LM.FieldByName('LCode').AsString).Value := WorkBook.WorkSheets[1].Cells[i, CDS_LM.FieldByName('LXH').AsInteger].Value;
|
||
CDS_LM.Next;
|
||
end;
|
||
Post;
|
||
end;
|
||
end;
|
||
WorkBook.Close;
|
||
excelApp.Quit;
|
||
excelApp := Unassigned;
|
||
WorkBook := Unassigned;
|
||
except
|
||
WorkBook.Close;
|
||
excelApp.Quit;
|
||
excelApp := Unassigned;
|
||
WorkBook := Unassigned;
|
||
exit;
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.Tv1Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'P_Type';
|
||
flagname := '<27><><EFBFBD><EFBFBD>';
|
||
MainType := FSTKName;
|
||
if ShowModal = 1 then
|
||
begin
|
||
with Self.CDS_Sub do
|
||
begin
|
||
Edit;
|
||
FieldByName('P_Type').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
|
||
end;
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.ButtonEdit(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'TakeUnit';
|
||
flagname := '<27><><EFBFBD>ϵ<EFBFBD>λ';
|
||
MainType := FSTKName;
|
||
if ShowModal = 1 then
|
||
begin
|
||
with Self.CDS_Sub do
|
||
begin
|
||
Edit;
|
||
FieldByName('TakeUnit').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
|
||
end;
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
|
||
end;
|
||
|
||
procedure TfrmPrtDyeInfoInPut.v1QtyUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'QtyUnit';
|
||
flagname := '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ';
|
||
MainType := FSTKName;
|
||
if ShowModal = 1 then
|
||
begin
|
||
with Self.CDS_Sub do
|
||
begin
|
||
Edit;
|
||
FieldByName('QtyUnit').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
|
||
end;
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
|
||
end;
|
||
|
||
end.
|
||
|