D10DJkaimengwenshang/项目代码/wenshangkm/G01贸易生产计划/U_UptPlanDataToRoll.pas

247 lines
7.1 KiB
ObjectPascal
Raw Normal View History

2025-09-27 14:24:10 +08:00
unit U_UptPlanDataToRoll;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter, cxData,
cxDataStorage, cxEdit, cxNavigator, dxDateRanges, dxScrollbarAnnotations,
Data.DB, cxDBData, cxGridLevel, cxClasses, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
Vcl.ComCtrls, Vcl.ToolWin, Data.Win.ADODB, Datasnap.DBClient, cxContainer,
cxLabel, Vcl.ExtCtrls, cxCheckBox, cxTextEdit;
type
TfrmUptPlanDataToRoll = class(TForm)
TV1: TcxGridDBTableView;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
ToolBar1: TToolBar;
TBSave: TToolButton;
Tbcgs: TToolButton;
TBClose: TToolButton;
TV1ssel: TcxGridDBColumn;
TV1fieldCaption: TcxGridDBColumn;
ADOQueryTmp: TADOQuery;
ADOQueryCmd: TADOQuery;
CDS_1: TClientDataSet;
DS_1: TDataSource;
CDS_1fieldName: TStringField;
CDS_1fieldCaption: TStringField;
CDS_1fieldTable: TStringField;
CDS_1ssel: TBooleanField;
ADOQueryPlan: TADOQuery;
Panel1: TPanel;
cxLabel1: TcxLabel;
cxTextEdit1: TcxTextEdit;
cxLabel2: TcxLabel;
AllowEmptyValue: TcxCheckBox;
procedure FormCreate(Sender: TObject);
procedure TBSaveClick(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
private
function updteData():boolean;
public
fMainId:string;
fSubId:string;
end;
var
frmUptPlanDataToRoll: TfrmUptPlanDataToRoll;
implementation
uses
U_dataLink;
{$R *.dfm}
procedure TfrmUptPlanDataToRoll.FormCreate(Sender: TObject);
begin
CDS_1.Close;
CDS_1.CreateDataSet;
cxgrid1.Align:=alClient;
with CDS_1 do
begin
append;
fieldByName('fieldName').value :='OrderNo';
fieldByName('fieldCaption').value :='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_main';
post;
append;
fieldByName('fieldName').value :='ConNo';
fieldByName('fieldCaption').value :='<27><>ͬ<EFBFBD><CDAC>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='BuyConNo';
fieldByName('fieldCaption').value :='<27>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='c_Name';
fieldByName('fieldCaption').value :='Ʒ<><C6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='c_EName';
fieldByName('fieldCaption').value :='Ʒ<><C6B7>Ӣ<EFBFBD><D3A2>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_Color';
fieldByName('fieldCaption').value :='<27><>ɫ';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_EColor';
fieldByName('fieldCaption').value :=<><D3A2><EFBFBD><EFBFBD>ɫ';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_ColorNo';
fieldByName('fieldCaption').value :=<><C9AB>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_Pattern';
fieldByName('fieldCaption').value :='<27><><EFBFBD><EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='FtyPCId';
fieldByName('fieldCaption').value :=<><C8BE><EFBFBD>׺<EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='BatchNo';
fieldByName('fieldCaption').value :='<27><><EFBFBD><EFBFBD><EFBFBD>׺<EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_StyleNo';
fieldByName('fieldCaption').value :='<27><><EFBFBD><EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_Spec';
fieldByName('fieldCaption').value :='<27><><EFBFBD><EFBFBD>';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_Width';
fieldByName('fieldCaption').value :='<27>ŷ<EFBFBD>(cm)';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
append;
fieldByName('fieldName').value :='C_GramWeight';
fieldByName('fieldCaption').value :='<27><><EFBFBD><EFBFBD>(g/<2F>O)';
fieldByName('fieldTable').value :='Trade_Plan_sub';
post;
end;
end;
procedure TfrmUptPlanDataToRoll.TBCloseClick(Sender: TObject);
begin
close;
end;
procedure TfrmUptPlanDataToRoll.TBSaveClick(Sender: TObject);
begin
if not CDS_1.Locate('ssel',true,[]) then
begin
application.MessageBox('<27><>ѡ<EFBFBD><D1A1>Ҫ<EFBFBD><D2AA><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',0);
exit;
end;
if application.MessageBox('<27><><EFBFBD><EFBFBD><><C8B7>Ҫͬ<D2AA><CDAC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>?','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',1)=2 then exit;
if updteData() then
begin
application.MessageBox(<><CDAC><EFBFBD><EFBFBD><EFBFBD>³ɹ<C2B3>!<21><>','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',0);
modalResult:=1;
end;
end;
function TfrmUptPlanDataToRoll.updteData():boolean;
var
i:integer;
fieldName:string;
begin
try
result:=false;
with ADOQueryPlan do
begin
close;
sql.Clear;
sql.Add('select A.*,B.* from Trade_Plan_Main A left join Trade_Plan_Sub B on A.MainId=B.MainId ');
sql.Add('where mainId='+quotedstr(fMainId));
if fSubId<>'' then
sql.Add('and subId='+quotedstr(fSubId));
open;
end;
ADOQueryCmd.Connection.BeginTrans;
ADOQueryPlan.First;
while not ADOQueryPlan.eof do
begin
with ADOQueryCmd do
begin
close;
sql.clear;
sql.Add('update Trade_Cloth_Inspect set ');
////////////////////////////////
CDS_1.First;
i:=0;
while not CDS_1.eof do
begin
if not CDS_1.fieldByName('ssel').AsBoolean then
begin
CDS_1.Next;
continue;
end;
fieldName:= trim(CDS_1.fieldByName('fieldName').AsString);
//ֵ<><D6B5><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>
if (not AllowEmptyValue.Checked) and (trim(ADOQueryPlan.FieldByName(fieldName).AsString)='') then
begin
CDS_1.Next;
continue;
end;
inc(i);
if i=1 then
begin
sql.Add(fieldName+'='+quotedstr(trim(ADOQueryPlan.FieldByName(fieldName).AsString)));
end
else
begin
sql.Add(','+fieldName+'='+quotedstr(trim(ADOQueryPlan.FieldByName(fieldName).AsString)));
end;
CDS_1.Next;
end;
if i=0 then
begin
ADOQueryPlan.Next ;
continue;
end;
///////////////////////////////////
sql.Add('where MainId='+quotedstr(trim(ADOQueryPlan.FieldByName('MainId').AsString)));
sql.Add('and SubId='+quotedstr(trim(ADOQueryPlan.FieldByName('SubId').AsString)));
sql.Add('and mainId<>''''');
execSql;
end;
ADOQueryPlan.Next ;
end;
ADOQueryCmd.Connection.CommitTrans;
result:=true;
except
if ADOQueryCmd.Connection.InTransaction then
ADOQueryCmd.Connection.RollbackTrans;
application.MessageBox('<27><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD>²<EFBFBD><C2B2><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ',0);
end;
end;
end.