D10sxYilanbuyi/F01染色坯布仓库/U_DyePBImport.pas
2025-09-30 17:22:54 +08:00

283 lines
7.6 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit U_DyePBImport;
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, cxPC, U_BaseHelp, cxLookAndFeels,
cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu, ComObj,
U_BaseList, System.ImageList, Vcl.ImgList, dxScrollbarAnnotations,
dxSkinsDefaultPainters, dxSkinsCore;
type
TfrmDyePBImport = class(TfrmBaseHelp)
ToolBar1: TToolBar;
TBRafresh: TToolButton;
TBClose: TToolButton;
ADOQueryTemp: TADOQuery;
ADOQueryCmd: TADOQuery;
ADOQueryMain: TADOQuery;
GPM_1: TcxGridPopupMenu;
DS_1: TDataSource;
CDS_1: TClientDataSet;
cxStyleRepository1: TcxStyleRepository;
cxStyle1: TcxStyle;
OpenDialog1: TOpenDialog;
TbSelFile: TToolButton;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
CDS_LM: TClientDataSet;
ToolButton3: TToolButton;
cxGrid1: TcxGrid;
Tv1: TcxGridDBTableView;
v2Column6: TcxGridDBColumn;
v2Column15: TcxGridDBColumn;
v2Column3: TcxGridDBColumn;
v2Column1: TcxGridDBColumn;
cxGridLevel1: TcxGridLevel;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBCloseClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TBRafreshClick(Sender: TObject);
procedure TbSelFileClick(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure ToolButton3Click(Sender: TObject);
private
{ Private declarations }
procedure InitGrid();
public
{ Public declarations }
FCTID: string;
end;
var
frmDyePBImport: TfrmDyePBImport;
implementation
uses
U_DataLink, U_RTFun, U_DyeGreyClothInEdit;
{$R *.dfm}
procedure TfrmDyePBImport.InitGrid();
begin
try
ADOQueryMain.DisableControls;
with ADOQueryMain do
begin
Close;
SQL.Clear;
sql.Add(' select * from BS_Cloth_IO where 2= 1 ');
Open;
end;
SCreateCDS(ADOQueryMain, CDS_1);
SInitCDSData(ADOQueryMain, CDS_1);
finally
ADOQueryMain.EnableControls;
end;
end;
procedure TfrmDyePBImport.FormDestroy(Sender: TObject);
begin
inherited;
frmDyePBImport := nil;
end;
procedure TfrmDyePBImport.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := cafree;
end;
procedure TfrmDyePBImport.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmDyePBImport.FormShow(Sender: TObject);
begin
inherited;
ReadCxGrid(self.Caption, Tv1, 'BS_Cloth_IO');
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;
InitGrid();
end;
procedure TfrmDyePBImport.TBRafreshClick(Sender: TObject);
begin
InitGrid();
end;
procedure TfrmDyePBImport.ToolButton1Click(Sender: TObject);
begin
WriteCxGrid(self.Caption, Tv1, '<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>');
end;
procedure TfrmDyePBImport.ToolButton2Click(Sender: TObject);
begin
try
ADOQueryCmd.Connection.BeginTrans;
CDS_1.DisableControls;
with CDS_1 do
begin
First;
while not eof do
begin
with frmDyeGreyClothInEdit.CDS_Sub do
begin
Append;
FieldByName('OrderNo').Value := Trim(CDS_1.fieldbyname('OrderNo').AsString);
FieldByName('Qty').Value := Trim(CDS_1.fieldbyname('Qty').AsString);
FieldByName('Piece').Value := Trim(CDS_1.fieldbyname('Piece').AsString);
FieldByName('Note').Value := Trim(CDS_1.fieldbyname('Note').AsString);
FieldByName('Note').Value := '<27>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD>';
Post;
end;
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('select A.* from Dye_Plan_Main A ');
sql.add(' where MainId = ' + quotedStr(Trim(CDS_1.fieldbyname('OrderNo').AsString)));
open;
end;
frmDyeGreyClothInEdit.CDS_Sub.edit;
frmDyeGreyClothInEdit.CDS_Sub.FieldByName('OrderNo').Value := ADOQueryCmd.fieldbyname('OrderNo').asstring;
frmDyeGreyClothInEdit.CDS_Sub.FieldByName('C_Name').Value := ADOQueryCmd.fieldbyname('C_Name').asstring;
frmDyeGreyClothInEdit.CDS_Sub.FieldByName('C_Code').Value := ADOQueryCmd.fieldbyname('C_Code').asstring;
frmDyeGreyClothInEdit.CDS_Sub.FieldByName('F_Name').Value := ADOQueryCmd.fieldbyname('F_Name').asstring;
frmDyeGreyClothInEdit.CDS_Sub.FieldByName('finishDescription').Value := ADOQueryCmd.fieldbyname('finishDescription').asstring;
frmDyeGreyClothInEdit.CDS_Sub.Post;
Next;
end;
end;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>', '<27><>ʾ<EFBFBD><CABE>Ϣ', MB_OK);
ADOQueryCmd.Connection.CommitTrans;
CDS_1.EnableControls;
close;
except
CDS_1.EnableControls;
ADOQueryCmd.Connection.RollbackTrans;
end;
end;
procedure TfrmDyePBImport.ToolButton3Click(Sender: TObject);
begin
CDS_1.Delete;
end;
procedure TfrmDyePBImport.TbSelFileClick(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_1 do
begin
Append;
CDS_LM.First;
while not CDS_LM.Eof do
begin
if CDS_LM.FieldByName('LXH').AsInteger > 0 then
CDS_1.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;
application.MessageBox(<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϣ<D0B6>', '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ', MB_ICONERROR);
exit;
end;
end;
end.