unit U_DyePCDetailsList; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient, cxDropDownEdit, MovePanel, cxButtonEdit, cxCalendar, RM_System, RM_Common, RM_Class, RM_GridReport, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges, dxBarBuiltInMenu, U_BaseList, dxScrollbarAnnotations, cxContainer, cxTextEdit, cxMaskEdit, Vcl.Menus, cxButtons; type TfrmDyePCDetailsList = class(TfrmBaseList) ToolBar1: TToolBar; TBRafresh: TToolButton; TBFind: TToolButton; TBExport: TToolButton; TBPrint: TToolButton; TBClose: TToolButton; Panel1: TPanel; ADOQueryCmd: TADOQuery; ADOQueryMain: TADOQuery; ADOQueryTemp: TADOQuery; DS_1: TDataSource; GPM1: TcxGridPopupMenu; Label3: TLabel; pcid: TEdit; CDS_1: TClientDataSet; MovePanel2: TMovePanel; RMGridReport1: TRMGridReport; customerNoName: TEdit; Label13: TLabel; ywy: TEdit; Label17: TLabel; lbHx: TEdit; Label7: TLabel; ToolButton1: TToolButton; ToolButton2: TToolButton; BegDate: TDateTimePicker; EndDate: TDateTimePicker; Label1: TLabel; Label2: TLabel; BegTime: TDateTimePicker; EndTime: TDateTimePicker; cxStyleRepository1: TcxStyleRepository; cxStyle1: TcxStyle; TbUpdateTime: TToolButton; Panel2: TPanel; Tv1: TcxGridDBTableView; cxGrid1Level1: TcxGridLevel; cxGrid1: TcxGrid; Tv1PCID: TcxGridDBColumn; Tv1OrderNo: TcxGridDBColumn; Tv1C_Name: TcxGridDBColumn; Tv1PSName: TcxGridDBColumn; Tv1CALL_temperature6: TcxGridDBColumn; Tv1PCQty: TcxGridDBColumn; Tv1time: TcxGridDBColumn; Tv1BegTime: TcxGridDBColumn; Tv1EndTime: TcxGridDBColumn; cxGrid2: TcxGrid; Tv2: TcxGridDBTableView; cxGridDBColumn1: TcxGridDBColumn; cxGridDBColumn2: TcxGridDBColumn; cxGridDBColumn3: TcxGridDBColumn; cxGridDBColumn4: TcxGridDBColumn; cxGridDBColumn5: TcxGridDBColumn; cxGridDBColumn6: TcxGridDBColumn; cxGridDBColumn7: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; DS_2: TDataSource; CDS_2: TClientDataSet; GPM2: TcxGridPopupMenu; Tv2PC_FLAG: TcxGridDBColumn; Tv2isComplete: TcxGridDBColumn; MCNO: TcxButtonEdit; MCName: TEdit; Label4: TLabel; cxButton1: TcxButton; cxButton2: TcxButton; TbMoveUp: TcxButton; TbMoveDown: TcxButton; Tv1GlideID: TcxGridDBColumn; Tv2GlideID: TcxGridDBColumn; procedure FormDestroy(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure TBRafreshClick(Sender: TObject); procedure ConNoMChange(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBExportClick(Sender: TObject); procedure TBFindClick(Sender: TObject); procedure pcidChange(Sender: TObject); procedure PRTColorChange(Sender: TObject); procedure TBdelClick(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); procedure tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); procedure TbUpdateTimeClick(Sender: TObject); procedure MCNOPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure Tv2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure Tv1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure cxButton1Click(Sender: TObject); procedure Tv2CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); procedure cxButton2Click(Sender: TObject); procedure Tv1BegTimePropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure TbMoveUpClick(Sender: TObject); procedure TbMoveDownClick(Sender: TObject); private FLeft, FTop: Integer; procedure InitGrid1(); procedure InitGrid2(); function SaveData(): boolean; function GetLastLine(const AText: string): string; function SaveMove(const Flag: string): Boolean; { Private declarations } public fsyrName, canshu1: string; { Public declarations } end; var frmDyePCDetailsList: TfrmDyePCDetailsList; implementation uses U_DataLink, U_RTFun, U_ZDYHelp, U_MachTaskList, U_BS_MachineSel; {$R *.dfm} procedure TfrmDyePCDetailsList.FormDestroy(Sender: TObject); begin inherited; frmDyePCDetailsList := nil; end; procedure TfrmDyePCDetailsList.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin case Key of VK_ESCAPE: begin Key := 0; // 清除按键,防止继续传递 Close; end; end; end; function TfrmDyePCDetailsList.SaveData(): boolean; var mLoopNum: Integer; mMCName, mNewValue, mStartTime: string; mEndTime, mBegTime: string; begin result := false; ADOQueryCmd.Connection.BeginTrans; try mLoopNum := StrToInt(CDS_1.FieldByName('Time').AsString) div 10; if (MCNO.Text <> '') and (CDS_1.FieldByName('BegTime').AsString <> '') then begin with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add(' update Dye_Plan_Glide set PC_FLAG = 1 , EndTime = DATEADD(MINUTE, ' + CDS_1.FieldByName('time').AsString + ', ' + QuotedStr(trim(CDS_1.FieldByName('BegTime').AsString)) + ')'); SQL.Add(' , begTime = ' + QuotedStr(Trim(CDS_1.FieldByName('BegTime').AsString))); SQL.Add(' , MCNO = ' + QuotedStr(Trim(MCNO.Text))); SQL.Add(' , MCName = ' + QuotedStr(MCName.Text)); SQL.Add(' where GlideID = ' + QuotedStr(Trim(CDS_1.FieldByName('GlideID').asString))); // ShowMessage(sql.Text); ExecSQL; end; mMCName := MCName.Text; mStartTime := CDS_1.FieldByName('BegTime').AsString; // mNewValue := '计划单:' + CDS_1.FieldByName('OrderNo').AsString + #13; mNewValue := mNewValue + CDS_1.FieldByName('C_Name').AsString + #13; mNewValue := mNewValue + '成品门幅:' + CDS_1.FieldByName('C_Width').AsString + #13; mNewValue := mNewValue + '工序 刮胶次数:' + CDS_1.FieldByName('GlideName').AsString; if CDS_1.FieldByName('PSType').AsString = '长车清洗' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '干定型' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '下水定型' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '刮胶' then begin mNewValue := mNewValue + '' + CDS_1.FieldByName('gj_number').AsString + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '发泡' then begin mNewValue := mNewValue + ' ' + CDS_1.FieldByName('fp_gjNumber').AsString + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '轧毛' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '机缸清洗' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '卷染缸清洗' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else begin mNewValue := mNewValue + '' + #13; end; //////////////////////显示助剂 mNewValue := mNewValue + '助剂:' + CDS_1.FieldByName('All_zhuji').AsString + #13; mNewValue := mNewValue + CDS_1.FieldByName('PCID').AsString + #13; mNewValue := mNewValue + CDS_1.FieldByName('GlideID').AsString; with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add('EXEC P_PC_UpdatePCAboutTime ' + '@MCName = :MCName, ' + '@NewValue = :NewValue, ' + '@StartTime = :StartTime, ' + '@LoopNum = :LoopNum'); Parameters.ParamByName('MCName').Value := mMCName; Parameters.ParamByName('NewValue').Value := mNewValue; Parameters.ParamByName('StartTime').Value := mStartTime; Parameters.ParamByName('LoopNum').Value := mLoopNum; ExecSQL; end; with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add('select * from PCAboutTime '); SQL.Add(' where time >= ' + quotedStr(Trim(mStartTime))); Open; end; ADOQueryCmd.First; mNewValue := ADOQueryCmd.FieldByName(mMCName).AsString; mBegTime := ADOQueryCmd.FieldByName('time').AsString; mEndTime := ADOQueryCmd.FieldByName('time').AsString; while not ADOQueryCmd.Eof do begin if (ADOQueryCmd.FieldByName(mMCName).AsString = null) or (ADOQueryCmd.FieldByName(mMCName).AsString = '') then begin mEndTime := ADOQueryCmd.FieldByName('time').AsString; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('update Dye_Plan_Glide set BegTime = ' + QuotedStr(Trim(mBegTime))); sql.Add(' , EndTime = ' + QuotedStr(Trim(mEndTime))); SQL.Add(' where GlideID = ' + QuotedStr(Trim(GetLastLine(mNewValue)))); ExecSQL; end; ADOQueryCmd.Connection.CommitTrans; result := true; Exit; end; if mNewValue <> ADOQueryCmd.FieldByName(mMCName).AsString then begin mEndTime := ADOQueryCmd.FieldByName('time').AsString; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('update Dye_Plan_Glide set BegTime = ' + QuotedStr(Trim(mBegTime))); sql.Add(' , EndTime = ' + QuotedStr(Trim(mEndTime))); SQL.Add(' where GlideID = ' + QuotedStr(Trim(GetLastLine(mNewValue)))); ExecSQL; end; mBegTime := ADOQueryCmd.FieldByName('time').AsString; mNewValue := ADOQueryCmd.FieldByName(mMCName).AsString; end; ADOQueryCmd.Next; end; end; ADOQueryCmd.Connection.CommitTrans; result := true; except ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); result := false; end; end; function TfrmDyePCDetailsList.SaveMove(const Flag: string): Boolean; var mLoopNum: Integer; mMCName, mNewValue, mStartTime: string; mEndTime, mBegTime: string; begin Result := False; // 默认返回失败 ADOQueryCmd.Connection.BeginTrans; try if Flag = '上移' then begin CDS_1.Prior; mStartTime := CDS_1.FieldByName('BegTime').AsString; CDS_1.Next; end else if Flag = '下移' then begin mStartTime := CDS_1.FieldByName('BegTime').AsString; CDS_1.Next; end; mLoopNum := StrToInt(CDS_1.FieldByName('Time').AsString) div 10; if (MCNO.Text <> '') and (CDS_1.FieldByName('BegTime').AsString <> '') then begin with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add(' update Dye_Plan_Glide set PC_FLAG = 1 , EndTime = DATEADD(MINUTE, ' + CDS_1.FieldByName('time').AsString + ', ' + QuotedStr(trim(mStartTime)) + ')'); SQL.Add(' , begTime = ' + QuotedStr(Trim(mStartTime))); SQL.Add(' , MCNO = ' + QuotedStr(Trim(MCNO.Text))); SQL.Add(' , MCName = ' + QuotedStr(MCName.Text)); SQL.Add(' where GlideID = ' + QuotedStr(Trim(CDS_1.FieldByName('GlideID').asString))); ExecSQL; end; mMCName := MCName.Text; mNewValue := mNewValue + CDS_1.FieldByName('C_Name').AsString + #13; mNewValue := mNewValue + '成品门幅:' + CDS_1.FieldByName('C_Width').AsString + #13; mNewValue := mNewValue + '工序 刮胶次数:' + CDS_1.FieldByName('GlideName').AsString; if CDS_1.FieldByName('PSType').AsString = '长车清洗' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '干定型' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '下水定型' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '刮胶' then begin mNewValue := mNewValue + '' + CDS_1.FieldByName('gj_number').AsString + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '发泡' then begin mNewValue := mNewValue + ' ' + CDS_1.FieldByName('fp_gjNumber').AsString + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '轧毛' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '机缸清洗' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else if CDS_1.FieldByName('PSType').AsString = '卷染缸清洗' then begin mNewValue := mNewValue + '' + #13; mNewValue := mNewValue + '车速:' + CDS_1.FieldByName('All_Speed').AsString + #13; mNewValue := mNewValue + '温度6#:' + CDS_1.FieldByName('ALL_temperature6').AsString + #13; end else begin mNewValue := mNewValue + '' + #13; end; // 显示助剂 mNewValue := mNewValue + '助剂:' + CDS_1.FieldByName('All_zhuji').AsString + #13; mNewValue := mNewValue + CDS_1.FieldByName('PCID').AsString + #13; mNewValue := mNewValue + CDS_1.FieldByName('GlideID').AsString; with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add('UPDATE PCAboutTime SET '); SQL.Add(mMCName + ' = null WHERE '); SQL.Add(mMCName + ' = ' + QuotedStr(Trim(mNewValue))); ExecSQL; end; with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add('EXEC P_PC_UpdatePCAboutTime ' + '@MCName = :MCName, ' + '@NewValue = :NewValue, ' + '@StartTime = :StartTime, ' + '@LoopNum = :LoopNum'); Parameters.ParamByName('MCName').Value := mMCName; Parameters.ParamByName('NewValue').Value := mNewValue; Parameters.ParamByName('StartTime').Value := mStartTime; Parameters.ParamByName('LoopNum').Value := mLoopNum; ExecSQL; end; with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add('select * from PCAboutTime '); SQL.Add(' where time >= ' + quotedStr(Trim(mStartTime))); Open; end; ADOQueryCmd.First; mNewValue := ADOQueryCmd.FieldByName(mMCName).AsString; mBegTime := ADOQueryCmd.FieldByName('time').AsString; mEndTime := ADOQueryCmd.FieldByName('time').AsString; while not ADOQueryCmd.Eof do begin if (ADOQueryCmd.FieldByName(mMCName).AsString = null) or (ADOQueryCmd.FieldByName(mMCName).AsString = '') then begin mEndTime := ADOQueryCmd.FieldByName('time').AsString; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('update Dye_Plan_Glide set BegTime = ' + QuotedStr(Trim(mBegTime))); sql.Add(' , EndTime = ' + QuotedStr(Trim(mEndTime))); SQL.Add(' where GlideID = ' + QuotedStr(Trim(GetLastLine(mNewValue)))); ExecSQL; end; ADOQueryCmd.Connection.CommitTrans; Result := True; // 操作成功 Exit; end; if mNewValue <> ADOQueryCmd.FieldByName(mMCName).AsString then begin mEndTime := ADOQueryCmd.FieldByName('time').AsString; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('update Dye_Plan_Glide set BegTime = ' + QuotedStr(Trim(mBegTime))); sql.Add(' , EndTime = ' + QuotedStr(Trim(mEndTime))); SQL.Add(' where GlideID = ' + QuotedStr(Trim(GetLastLine(mNewValue)))); ExecSQL; end; mBegTime := ADOQueryCmd.FieldByName('time').AsString; mNewValue := ADOQueryCmd.FieldByName(mMCName).AsString; end; ADOQueryCmd.Next; end; end; ADOQueryCmd.Connection.CommitTrans; Result := True; // 操作成功 except ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); Result := False; // 操作失败 end; end; function TfrmDyePCDetailsList.GetLastLine(const AText: string): string; var StringList: TStringList; begin Result := ''; StringList := TStringList.Create; try StringList.Text := AText; // 自动按回车分割 if StringList.Count > 0 then Result := StringList[StringList.Count - 1]; // 获取最后一行 finally StringList.Free; end; end; procedure TfrmDyePCDetailsList.cxButton1Click(Sender: TObject); begin if CDS_2.FieldByName('PC_FLAG').AsString = '1' then begin Application.MessageBox('工序已排产!', '提示信息', MB_OK); exit; end else if CDS_2.FieldByName('isComplete').AsString <> '' then begin Application.MessageBox('工序已报工!', '提示信息', MB_OK); exit; end; try ADOQueryCmd.Connection.BeginTrans; with ADOQueryMain do begin close; filtered := false; sql.Clear; SQL.Add('select Max(EndTime) as MaxTime from V_Dye_Cloth_PaiGang where (BegTime between :StartTime and :EndTime) and PC_FLAG = 1 and MCNO = :MCNO '); Parameters.ParamByName('StartTime').Value := Trunc(BegDate.Date) + Frac(BegTime.Time); Parameters.ParamByName('EndTime').Value := Trunc(EndDate.Date) + Frac(EndTime.Time); Parameters.ParamByName('MCNO').Value := MCNO.Text; Open; end; with CDS_1 do begin append; FieldByName('PCID').value := CDS_2.FieldByName('PCID').AsString; FieldByName('OrderNo').value := CDS_2.FieldByName('OrderNo').AsString; FieldByName('GlideName').value := CDS_2.FieldByName('GlideName').AsString; FieldByName('C_name').value := CDS_2.FieldByName('C_name').AsString; FieldByName('ALL_temperature6').value := CDS_2.FieldByName('ALL_temperature6').AsString; FieldByName('time').value := CDS_2.FieldByName('time').AsString; FieldByName('GlideID').value := CDS_2.FieldByName('GlideID').AsString; FieldByName('PSType').value := CDS_2.FieldByName('PSType').AsString; FieldByName('C_Width').value := CDS_2.FieldByName('C_Width').AsString; FieldByName('All_Speed').value := CDS_2.FieldByName('All_Speed').AsString; FieldByName('All_zhuji').value := CDS_2.FieldByName('All_zhuji').AsString; FieldByName('gj_number').AsString := CDS_2.FieldByName('gj_number').AsString; FieldByName('fp_gjNumber').AsString := CDS_2.FieldByName('fp_gjNumber').AsString; FieldByName('PCQty').AsString := CDS_2.FieldByName('PCQty').AsString; FieldByName('begTime').value := ADOQueryMain.FieldByName('MaxTime').AsString; Post; end; ADOQueryCmd.Connection.CommitTrans; except if ADOQueryCmd.Connection.InTransaction then ADOQueryCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); // showMessage('插入任务数据时发生错误!'); end; if SaveData() then begin Application.MessageBox('排产成功', '提示信息!', MB_OK); end; initGrid1(); end; procedure TfrmDyePCDetailsList.cxButton2Click(Sender: TObject); begin if MessageDlg('确定取消?此操作无法撤销!', mtWarning, [mbOK, mbCancel], 0) = mrOK then begin // 开始事务 ADOQueryCmd.Connection.BeginTrans; try // 第一个更新操作 with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add('UPDATE PCAboutTime SET '); SQL.Add(MCName.Text + ' = null WHERE '); SQL.Add(' time >= ' + QuotedStr(CDS_1.FieldByName('BegTime').AsString)); SQL.Add(' and time < ' + QuotedStr(CDS_1.FieldByName('EndTime').AsString)); showMessage(sql.Text); ExecSQL; end; // 第二个更新操作 with ADOQueryCmd do begin Close; SQL.Clear; SQL.Add(' update Dye_Plan_Glide set PC_FLAG = 0,endTime = null,begTime = null where GlideID = ' + QuotedStr(Trim(CDS_1.FieldByName('GlideID').asString))); ExecSQL; end; // 两个操作都成功,提交事务 ADOQueryCmd.Connection.CommitTrans; Application.MessageBox('取消成功!', '提示', 0); InitGrid1(); except on E: Exception do begin // 发生异常,回滚事务 ADOQueryCmd.Connection.RollbackTrans; ShowMessage('操作失败:' + E.Message); end; end; end; end; procedure TfrmDyePCDetailsList.FormClose(Sender: TObject; var Action: TCloseAction); begin inherited; Action := caFree; end; procedure TfrmDyePCDetailsList.FormCreate(Sender: TObject); begin inherited; // EndDate.DateTime := SGetServerDateTime(ADOQueryTemp); // BegDate.DateTime := EndDate.DateTime; fsyrName := trim(DdataBase); canshu1 := trim(DParameters1); // SInitComBoxBySql(ADOQueryTemp, GlideName, false, 'select PSName as Name from Dye_Process'); end; procedure TfrmDyePCDetailsList.InitGrid1(); var mBegDate, mendDate: string; mAction: string; rs: _Recordset; r: integer; begin // 任务时间 try tv1.BeginUpdate; ADOQueryMain.DisableControls; with ADOQueryMain do begin close; filtered := false; sql.Clear; SQL.Add('select * from V_Dye_Cloth_PaiGang where (BegTime between :StartTime and :EndTime) and PC_FLAG = 1 and MCNO = :MCNO order By BegTime '); Parameters.ParamByName('StartTime').Value := Trunc(BegDate.Date) + Frac(BegTime.Time); Parameters.ParamByName('EndTime').Value := Trunc(EndDate.Date) + Frac(EndTime.Time); Parameters.ParamByName('MCNO').Value := MCNO.Text; Open; end; SCreateCDS(ADOQueryMain, CDS_1); SInitCDSData(ADOQueryMain, CDS_1); finally ADOQueryMain.EnableControls; tv1.EndUpdate; // tv1.ApplyBestFit(); end; end; procedure TfrmDyePCDetailsList.InitGrid2(); var mBegDate, mendDate: string; mAction: string; rs: _Recordset; r: integer; begin // 任务时间 try tv1.BeginUpdate; ADOQueryMain.DisableControls; with ADOQueryMain do begin close; filtered := false; sql.Clear; SQL.Add('select * from V_Dye_Cloth_PaiGang'); Open; end; SCreateCDS(ADOQueryMain, CDS_2); SInitCDSData(ADOQueryMain, CDS_2); finally ADOQueryMain.EnableControls; tv1.EndUpdate; // tv1.ApplyBestFit(); end; end; procedure TfrmDyePCDetailsList.MCNOPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmBS_MachineSel := TfrmBS_MachineSel.Create(Application); with frmBS_MachineSel do begin if ShowModal = 1 then begin MCNO.Text := frmBS_MachineSel.Order_Main.FieldByName('MCNO').Value; MCName.Text := frmBS_MachineSel.Order_Main.FieldByName('MCName').Value; Self.InitGrid1(); end; end; finally frmBS_MachineSel.Free; end; end; procedure TfrmDyePCDetailsList.TBRafreshClick(Sender: TObject); begin MovePanel2.Visible := True; MovePanel2.Refresh; InitGrid1(); InitGrid2(); MovePanel2.Visible := False; end; procedure TfrmDyePCDetailsList.TbUpdateTimeClick(Sender: TObject); var DeletedCount, InsertedCount: Integer; Status, StartDate, EndDate: string; begin with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('exec P_InsertDelTimeToPC @MinuteInterval = 10'); Open; if not IsEmpty then begin Status := FieldByName('状态').AsString; DeletedCount := FieldByName('删除记录数').AsInteger; InsertedCount := FieldByName('插入记录数').AsInteger; StartDate := FieldByName('保留开始时间').AsString; EndDate := FieldByName('保留结束时间').AsString; ShowMessage(Format('时间数据更新成功!' + #13#10 + '删除记录:%d 条' + #13#10 + '插入记录:%d 条' + #13#10 + '时间范围:%s 至 %s', [DeletedCount, InsertedCount, StartDate, EndDate])); end else begin ShowMessage('时间数据更新完成!'); end; Close; end; end; procedure TfrmDyePCDetailsList.ToolButton1Click(Sender: TObject); begin WriteCxGrid(self.Caption + tv1.Name, Tv1, '排产信息'); end; procedure TfrmDyePCDetailsList.ToolButton2Click(Sender: TObject); begin // if ADOQuerymain.IsEmpty then // exit; frmMachTaskList := TfrmMachTaskList.create(self); with frmMachTaskList do begin // fcurMachId := trim(self.adoquerymain.FieldByName('mcid').AsString); // machName.text := trim(self.adoquerymain.FieldByName('mcName').AsString); showModal; free; end; initgrid1(); end; procedure TfrmDyePCDetailsList.Tv1BegTimePropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); var Begtime: TDateTime; Hour, Min, Sec, MSec: Word; begin try // 使用 DisplayValue 而不是 Sender.AsString if VarIsNull(DisplayValue) or (DisplayValue = '') then Exit; Begtime := VarToDateTime(DisplayValue); DecodeTime(Begtime, Hour, Min, Sec, MSec); if Sec <> 0 then begin ErrorText := '开始时间秒数必须为 0!'; Error := True; // 设置错误标志 end else if (Min mod 10) <> 0 then // 添加分钟验证 begin ErrorText := '开始时间分钟必须为 10 的倍数!当前分钟为:' + IntToStr(Min); Error := True; end else begin Error := False; // 清除错误标志 end; except on E: Exception do begin ErrorText := '时间格式错误:' + E.Message; Error := True; end; end; end; procedure TfrmDyePCDetailsList.tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean); begin // if ADOQuerymain.IsEmpty then // exit; frmMachTaskList := TfrmMachTaskList.create(self); with frmMachTaskList do begin fBegTime := Self.CDS_1.FieldByName('time').AsString; fMCName := Self.Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; fText := self.CDS_1.FieldByName(fMCName).AsString; showModal; free; end; initgrid1(); end; procedure TfrmDyePCDetailsList.tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); begin inherited; ACanvas.Font.Size := 7; end; procedure TfrmDyePCDetailsList.Tv1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin case Key of VK_LEFT: begin // 左方向键被按下 ShowMessage('左方向键'); // 执行向左移动的代码 end; VK_RIGHT: begin // 右方向键被按下 ShowMessage('右方向键'); // 执行向右移动的代码 end; VK_UP: begin // 上方向键被按下 ShowMessage('上方向键'); // 执行向上移动的代码 end; VK_DOWN: begin // 下方向键被按下 ShowMessage('下方向键'); // 执行向下移动的代码 end; end; end; procedure TfrmDyePCDetailsList.Tv2CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); var PC_FLAG, isComplete: Variant; begin // 获取字段值 PC_FLAG := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('PC_FLAG').Index]; isComplete := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('isComplete').Index]; // 设置不同状态的颜色和字体 if VarIsNull(PC_FLAG) or (PC_FLAG = 0) then // 未排入计划单 begin ACanvas.Brush.Color := $00CCCCFF; // 浅红色背景 ACanvas.Font.Color := clRed; ACanvas.Font.Style := [fsBold]; end else if (PC_FLAG = 1) and VarIsNull(isComplete) then // 排入未报工 begin ACanvas.Brush.Color := clWindow; // 默认窗口背景色 ACanvas.Font.Color := clWindowText; // 默认窗口文本色 ACanvas.Font.Style := []; end else if (not VarIsNull(isComplete)) and (isComplete = 0) then // 生产一部分 begin ACanvas.Brush.Color := $00E0E0E0; // 浅灰色背景 ACanvas.Font.Color := clGray; ACanvas.Font.Style := [fsBold]; // end else if (not VarIsNull(isComplete)) and (isComplete = 1) then // 成品入库 begin ACanvas.Brush.Color := $00E0FFE0; // 浅绿色背景 ACanvas.Font.Color := $00008000; ACanvas.Font.Style := [fsBold]; end else // 默认情况 begin ACanvas.Brush.Color := clWindow; ACanvas.Font.Color := clWindowText; ACanvas.Font.Style := []; end; // 如果需要自定义绘制完成,取消下面的注释 // ADone := True; end; procedure TfrmDyePCDetailsList.Tv2KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin case Key of VK_LEFT: begin // 左方向键被按下 ShowMessage('左方向键'); // 执行向左移动的代码 end; VK_RIGHT: begin // 右方向键被按下 ShowMessage('右方向键'); // 执行向右移动的代码 end; VK_UP: begin // 上方向键被按下 ShowMessage('上方向键'); // 执行向上移动的代码 end; VK_DOWN: begin // 下方向键被按下 ShowMessage('下方向键'); // 执行向下移动的代码 end; end; end; procedure TfrmDyePCDetailsList.ConNoMChange(Sender: TObject); begin if ADOQueryMain.Active then begin SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2)); end; end; procedure TfrmDyePCDetailsList.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmDyePCDetailsList.FormShow(Sender: TObject); begin inherited; ReadCxGrid(self.Caption + tv1.Name, Tv1, '排产信息明细'); ReadCxGrid(self.Caption + tv2.Name, Tv2, '排产信息明细'); canshu1 := self.fParameters1; // BegDate.DateTime := strToDateTime(FormatDateTime('yyyy-MM-dd 00:00:00', SGetServerDate(ADOQueryTemp))) - 1; // EndDate.DateTime := strToDateTime(FormatDateTime('yyyy-MM-dd 00:00:00', SGetServerDate(ADOQueryTemp))) + 1; var ServerDate: TDateTime := SGetServerDate(ADOQueryTemp); BegDate.Date := Trunc(ServerDate) - 1; // 前一天 EndDate.Date := Trunc(ServerDate) + 1; // 后一天 Begtime.Time := EncodeTime(0, 0, 0, 0); // 早上8点 endTime.Time := EncodeTime(0, 0, 0, 0); // 晚上6点 initgrid1(); initgrid2(); KeyPreview := True; end; procedure TfrmDyePCDetailsList.TBExportClick(Sender: TObject); begin if ADOQueryMain.IsEmpty then exit; TcxGridToExcel(self.Caption, cxGrid1); end; procedure TfrmDyePCDetailsList.TBFindClick(Sender: TObject); begin if ADOQueryMain.Active then begin SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2)); SCreateCDS(ADOQueryMain, CDS_1); SInitCDSData(ADOQueryMain, CDS_1); end; end; procedure TfrmDyePCDetailsList.TbMoveDownClick(Sender: TObject); begin if SaveMove('下移') then ShowMessage('下移成功!') else ShowMessage('下移失败!'); end; procedure TfrmDyePCDetailsList.TbMoveUpClick(Sender: TObject); begin if SaveMove('上移') then ShowMessage('上移成功!') else ShowMessage('上移失败!'); end; procedure TfrmDyePCDetailsList.pcidChange(Sender: TObject); begin TBFind.Click; end; procedure TfrmDyePCDetailsList.PRTColorChange(Sender: TObject); begin TBFind.Click; end; procedure TfrmDyePCDetailsList.TBdelClick(Sender: TObject); begin if CDS_1.IsEmpty then Exit; if Application.MessageBox('确定要删除数据吗?', '提示', 32 + 4) <> IDYES then Exit; try with ADOQueryCmd do begin Close; sql.Clear; sql.Add('insert into Dye_Need_Up(UType,UDataId) values(''机台刷卡'',' + quotedstr(Trim(CDS_1.fieldbyname('GOID').AsString)) + ') '); sql.Add('delete Dye_Plan_Glide_OutPut where GOID=''' + Trim(CDS_1.fieldbyname('GOID').AsString) + ''''); ExecSQL; end; ////////////////// 更新进度 ////////////////// with ADOQueryCmd do begin Close; sql.Clear; sql.Add('exec P_Dye_Card_upCL @PCID=' + QuotedStr(CDS_1.fieldbyname('pcid').AsString)); execsql; end; ////////////////// 更新进度 ////////////////// CDS_1.Delete; except application.MessageBox('删除失败!', '提示信息', 0); end; end; end.