unit U_ShuttleClothSCList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, StrUtils, RM_e_Graphic, RM_e_Jpeg,
  dxBarBuiltInMenu, cxPC;

type
  TfrmShuttleClothSCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label1: TLabel;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    ConNo: TEdit;
    Label5: TLabel;
    P_CodeName: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    CDS_PM: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column6: TcxGridDBColumn;
    RMDB_Main: TRMDBDataSet;
    TBCopy: TToolButton;
    TBView: TToolButton;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    P_Code: TEdit;
    v1Column20: TcxGridDBColumn;
    Label6: TLabel;
    BatchNo: TEdit;
    v1Column31: TcxGridDBColumn;
    v1Column30: TcxGridDBColumn;
    KHNAME: TEdit;
    Label7: TLabel;
    v1Column1: TcxGridDBColumn;
    RMDB_JS: TRMDBDataSet;
    CDS_PJS: TClientDataSet;
    RMDB_WS: TRMDBDataSet;
    CDS_PWS: TClientDataSet;
    ComboBox1: TComboBox;
    v1Column7: TcxGridDBColumn;
    Label35: TLabel;
    ConNoType: TComboBox;
    Label4: TLabel;
    Label8: TLabel;
    JSWSNote: TEdit;
    v1Column8: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    cxGridDBTableView1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn12: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridDBColumn15: TcxGridDBColumn;
    cxGridDBColumn16: TcxGridDBColumn;
    cxGridDBColumn17: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    RMDB_CZ: TRMDBDataSet;
    CDS_CZ: TClientDataSet;
    cxGrid3: TcxGrid;
    cxGridDBTableView2: TcxGridDBTableView;
    cxGridDBColumn18: TcxGridDBColumn;
    cxGridDBColumn19: TcxGridDBColumn;
    cxGridDBColumn20: TcxGridDBColumn;
    cxGridDBColumn21: TcxGridDBColumn;
    cxGridDBColumn22: TcxGridDBColumn;
    cxGridDBColumn23: TcxGridDBColumn;
    cxGridDBColumn24: TcxGridDBColumn;
    cxGridDBColumn25: TcxGridDBColumn;
    cxGridDBColumn26: TcxGridDBColumn;
    cxGridDBColumn27: TcxGridDBColumn;
    cxGridDBColumn28: TcxGridDBColumn;
    cxGridDBColumn29: TcxGridDBColumn;
    cxGridDBColumn30: TcxGridDBColumn;
    cxGridDBColumn31: TcxGridDBColumn;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn33: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn35: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridDBColumn37: TcxGridDBColumn;
    cxGridDBColumn38: TcxGridDBColumn;
    cxGridDBColumn39: TcxGridDBColumn;
    cxGridDBColumn40: TcxGridDBColumn;
    cxGridDBColumn41: TcxGridDBColumn;
    cxGridDBColumn42: TcxGridDBColumn;
    cxGridDBColumn43: TcxGridDBColumn;
    cxGridDBColumn44: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGridDBColumn46: TcxGridDBColumn;
    cxGridDBColumn47: TcxGridDBColumn;
    cxGridDBColumn48: TcxGridDBColumn;
    cxGridDBColumn49: TcxGridDBColumn;
    cxGridDBColumn50: TcxGridDBColumn;
    cxGridDBColumn51: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    RMDB_QZ: TRMDBDataSet;
    CDS_QZ: TClientDataSet;
    Tv3Column1: TcxGridDBColumn;
    Label9: TLabel;
    ConNoStatu: TComboBox;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    CDS_QZ2: TClientDataSet;
    RMDB_QZ2: TRMDBDataSet;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Tv3Column6: TcxGridDBColumn;
    Tv3Column7: TcxGridDBColumn;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    Tv3Column8: TcxGridDBColumn;
    Tv3Column9: TcxGridDBColumn;
    Tv3Column10: TcxGridDBColumn;
    ToolButton3: TToolButton;
    Tv3Column11: TcxGridDBColumn;
    ToolButton4: TToolButton;
    RMJPEGExport1: TRMJPEGExport;
    cxTabControl1: TcxTabControl;
    Tv3Column12: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure conPress(Sender: TObject; var Key: Char);
    procedure TBViewClick(Sender: TObject);
    procedure TBCopyClick(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure cxGridDBColumn46PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure Tv3CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitButton();
    procedure UPGYD(MMainId: string);
    procedure SCGYD(MMainId: string);
    { Private declarations }
  public
    canshu1, FCheJian: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ShuttleClothSCInPut, U_LabelList,
  U_CompressionFun;

{$R *.dfm}
procedure TfrmShuttleClothSCList.UPGYD(MMainId: string);
var
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
  maxNo: string;
  FJStream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin

  try
    adoqueryCmd.Connection.BeginTrans;
    fFilePath := ExtractFilePath(Application.ExeName) + 'image\label0001.jpg';
    fFileName := 'label.jpg';
    application.ProcessMessages;
    if GetLSNo(ADOQueryTemp, maxNo, 'FJ', 'TP_File', 4, 1) = False then
    begin
      adoqueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;
      //获取文件信息
    GetFileInfo(fFilePath, mfileSize, mCreationTime, mWriteTime);
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from TP_File ');
      sql.Add('where TFType=''织造工艺单'' and  WBID=' + quotedstr(Trim(MMainId)));
      execsql;
    end;

    try
      FJStream := TMemoryStream.Create;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from TP_File ');
        sql.Add('where TFID=' + quotedstr(trim(maxNo)));
        open;
        append;
        fieldbyname('TFID').Value := trim(maxNo);
        fieldbyname('WBID').Value := Trim(MMainId);
        fieldbyname('TFType').Value := trim('织造工艺单');
        fieldbyname('Filler').Value := trim(DName);
        fieldbyname('FileName').Value := trim(fFileName);
        fieldbyname('TFDate').Value := mWriteTime;
        FJStream.LoadFromFile(fFilePath);
        CompressionStream(FJStream);
        tblobfield(FieldByName('Filesother')).LoadFromStream(FJStream);
        post;
      end;
    finally
      FJStream.Free;
    end;

    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('附件保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmShuttleClothSCList.SCGYD(MMainId: string);
var
  fPrintFile, fImagePath2: string;
  i, j, k: integer;
begin

  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ComboBox1.Text) + '.rmf';
  ExportFtErpFile(Trim(ComboBox1.Text) + '.rmf', ADOQueryTemp);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId where A.MainId=' + Quotedstr(Trim(MMainId)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PM);
  SInitCDSData20(ADOQueryTemp, CDS_PM);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from PD_Plan_Yarn where PYType=''经丝'' and MainId=' + Quotedstr(Trim(MMainId)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PJS);
  SInitCDSData20(ADOQueryTemp, CDS_PJS);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from PD_Plan_Yarn where PYType=''纬丝'' and MainId=' + Quotedstr(Trim(MMainId)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PWS);
  SInitCDSData20(ADOQueryTemp, CDS_PWS);

  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);

    fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\label0001.jpg';
    if FileExists(fImagePath2) then
      DeleteFile(fImagePath2);
    fImagePath2 := ExtractFilePath(Application.ExeName) + 'image\label.jpg';
    RM1.PrepareReport;
    RM1.ExportTo(RMJPEGExport1, fImagePath2);
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
  end;

end;

procedure TfrmShuttleClothSCList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmShuttleClothSCList.InitButton();
begin

  if Trim(canshu1) = '查询' then
  begin
    TBAdd.Visible := False;
    TBCopy.Visible := False;
    TBEdit.Visible := False;
    TBDel.Visible := False;
  end;

end;

procedure TfrmShuttleClothSCList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(self.Caption), Tv1, '坯布生产管理');
  Close;
end;

procedure TfrmShuttleClothSCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
     // Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*  ');
      SQL.Add(',JSWSNote=CAST((SELECT C.PYXH +''.''+C.Y_Name+'';'' FROM PD_Plan_Yarn C WHERE C.MainId=A.MainId FOR xml path(''''))as VARCHAR(3000))');
      sql.Add(' from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId');
      sql.Add(' where A.FillTIme>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + '''');
      sql.Add(' and A.FillTIme<''' + Trim(FormatDateTime('yyyy-MM-dd', EndDate.DateTime + 1)) + '''');
      case cxTabControl1.TabIndex of
        0:
          begin
            SQL.Add('AND A.VALID=''Y''');
          end;
        1:
          begin
            SQL.Add('AND A.VALID=''N''');
          end;
      end;
      if Trim(canshu1) = '录入' then
        sql.Add(' and A.Filler=' + quotedstr(DName));
        //ShowMessage(SQL.Text);
      Open;
    end;

    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmShuttleClothSCList.InitForm();
begin
  InitButton();
  ReadCxGrid(Trim(self.Caption), Tv1, '坯布生产管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 90;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);
  InitGrid();
end;

procedure TfrmShuttleClothSCList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmShuttleClothSCList.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Order_Main.FieldByName('ISSD').AsString = '已锁定' then
  begin
    Application.MessageBox('已锁定数据不能删除!', '提示', 0);
    Exit;
  end;
  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
        Self.Order_Main.Locate('MainId', frmClothSCInPut.FMainId, []);
      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*');
    sql.Add('from PD_Plan_Card_MS A');
    sql.Add(' where A.SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('已产生安排数据不能删除!', '提示', 0);
    Exit;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select TOP 1 A.*');
    sql.Add('from CK_Cloth_CR A');
    sql.Add(' where A.SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('已产生检验数据不能删除!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmShuttleClothSCList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE  PD_Plan_Main SET VALID=''N'' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
//      sql.Add('delete PD_Plan_Main where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
//      sql.Add('delete PD_Plan_Sub where SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
//      sql.Add('delete PD_Plan_Yarn where SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmShuttleClothSCList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布生产单', cxGrid1);
end;

procedure TfrmShuttleClothSCList.TBPrintClick(Sender: TObject);
var
  fPrintFile, fPrintFileQZ, fPrintFileYWB: string;
  i, j, k: integer;
begin
  if Order_Main.IsEmpty then
    Exit;
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + trim(ComboBox1.Text) + '.rmf';
  ExportFtErpFile(trim(ComboBox1.Text) + '.rmf', ADOQueryTemp);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId where A.MainId=' + Quotedstr(Trim(Order_Main.fieldbyname('MainId').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PM);
  SInitCDSData20(ADOQueryTemp, CDS_PM);

  if Trim(ADOQueryTemp.fieldbyname('YWBian').AsString) <> '' then
  begin
    fPrintFileYWB := ExtractFilePath(Application.ExeName) + 'Report\英文边.rmf';
    ExportFtErpFile('英文边.rmf', ADOQueryTemp);
  end;

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add(' EXEC P_PRINT_QZ_CS @MAINID=' + Quotedstr(Trim(Order_Main.fieldbyname('MainId').AsString)));
//    ShowMessage(sql.Text);
    open;
  end;
  SCreateCDS20(ADOQuery1, CDS_QZ);
  SInitCDSData20(ADOQuery1, CDS_QZ);
  if ADOQuery1.IsEmpty = false then
  begin
    fPrintFileQZ := ExtractFilePath(Application.ExeName) + 'Report\起综工艺单.rmf';
    ExportFtErpFile('起综工艺单.rmf', ADOQuery1);
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from PD_Plan_Yarn where PYType=''经丝'' and MainId=' + Quotedstr(Trim(Order_Main.fieldbyname('MainId').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PJS);
  SInitCDSData20(ADOQueryTemp, CDS_PJS);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from PD_Plan_Yarn where PYType=''纬丝'' and MainId=' + Quotedstr(Trim(Order_Main.fieldbyname('MainId').AsString)));
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_PWS);
  SInitCDSData20(ADOQueryTemp, CDS_PWS);

  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.ShowReport;
    if FileExists(fPrintFileQZ) then
    begin
      RM1.LoadFromFile(fPrintFileQZ);
      RM1.ShowReport;
    end;

    if FileExists(fPrintFileYWB) then
    begin
      RM1.LoadFromFile(fPrintFileYWB);
      RM1.ShowReport;
    end;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
  end;

end;

procedure TfrmShuttleClothSCList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmShuttleClothSCList.TBAddClick(Sender: TObject);
begin

  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 0;
      FMainId := '';
      FSubId := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmShuttleClothSCList.FormShow(Sender: TObject);
begin
  InitForm();
  cxGridDBColumn46.Properties.ReadOnly := True;

  if canshu1 = '查询' then
  begin
    cxGridDBColumn46.Properties.ReadOnly := False;
  end;
end;

procedure TfrmShuttleClothSCList.conPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(Trim(ConNo.Text)) < 4 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        //sql.Add('exec Cloth_QryList :MainId,:WSql');
       // Parameters.ParamByName('WSql').Value:=' and OM.conNo like '''+'%'+Trim(ConNoM.Text)+'%'+''''
                                             // +' and ConType=''生产'' ';
        sql.Add('select * from PD_Plan_Main A inner join PD_Plan_Sub B on A.Mainid=B.MainId');
        sql.Add(' where A.ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');

        Open;
      end;
      SCreateCDS20(ADOQueryMain, Order_Main);
      SInitCDSData20(ADOQueryMain, Order_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmShuttleClothSCList.TBViewClick(Sender: TObject);
begin
  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.Order_Main.fieldbyname('SubId').AsString);
      FConNo := Trim(Self.Order_Main.fieldbyname('ConNo').AsString);
      TBSave.Visible := False;

      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.TBCopyClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmClothSCInPut := TfrmClothSCInPut.Create(Application);
    with frmClothSCInPut do
    begin
      PState := 1;
      FCopyInt := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      FConNo := Trim(Self.Order_Main.fieldbyname('ConNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClothSCInPut.Free;
  end;
end;

procedure TfrmShuttleClothSCList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  FDDZT: string;
begin

  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('ConNoStatu').Index] = '已取消' then
  begin
    ACanvas.Brush.Color := $0000FF;
    ACanvas.Font.Color := $F0FBFF;
  end;
  

//
//  FDDZT := AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('DDZT').Index];
//
//  if FDDZT = '已开始' then
//    ACanvas.Font.Color := $FF0000;
//  if FDDZT = '已结束' then
//    ACanvas.Font.Color := $0000FF;

end;

procedure TfrmShuttleClothSCList.cxGridDBColumn46PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditingText;
  FFieldName := Trim(Tv3.Controller.FocusedColumn.DataBinding.FilterFieldName);
  try
    ADOQueryCmd.Connection.BeginTrans;
    with Order_Main do
    begin
      Edit;
      FieldByName(FFieldName).Value := Trim(mvalue);
      Post;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate PD_Plan_Sub ');
      sql.Add(' Set ' + FFieldName + '=''' + Trim(mvalue) + '''');
      sql.Add(' where SubId=' + quotedstr(Order_Main.fieldbyname('SubId').AsString));
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    tv3.Controller.EditingController.ShowEdit();

  except
    tv3.Controller.EditingController.ShowEdit();
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end
end;

procedure TfrmShuttleClothSCList.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;

  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  PD_Plan_Main SET sdren=''' + Trim(DName) + ''',sdtime=getdate(),issd=''已锁定'' ');
      sql.Add('where mainid=' + quotedstr(trim(Order_Main.fieldbyname('mainid').AsString)));
      execsql;
    end;

    InitGrid();
    application.MessageBox('锁定成功！', '提示信息');
  except
    application.MessageBox('锁定失败！', '提示信息', 0);
  end;
end;

procedure TfrmShuttleClothSCList.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;

  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  PD_Plan_Main SET sdren=NULL,sdtime=NULL,issd=NULL ');
      sql.Add('where mainid=' + quotedstr(trim(Order_Main.fieldbyname('mainid').AsString)));
      execsql;
    end;

    InitGrid();
    application.MessageBox('解除锁定成功！', '提示信息');
  except
    application.MessageBox('解除锁定失败！', '提示信息', 0);
  end;
end;

procedure TfrmShuttleClothSCList.ToolButton3Click(Sender: TObject);
var
  MLBName: string;
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmLabelList := TfrmLabelList.Create(Application);
    with frmLabelList do
    begin
      if ShowModal = 1 then
      begin
//        MLBName := leftStr(Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString), );
        MLBName := Trim(Copy(Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString), 1, Length(Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString)) - 4));
//        ShowMessage(MLBName);
      end;
    end;
  finally
    frmLabelList.Free;
  end;
  if MLBName <> '' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update PD_Plan_Main Set LaBName=''' + MLBName + '''');
      sql.Add(' where Mainid=''' + Trim(self.Order_Main.fieldbyname('Mainid').AsString) + '''');
      ExecSQL;
    end;
    with Order_Main do
    begin
      Edit;
      FieldByName('SSel').Value := False;
      FieldByName('LaBName').Value := MLBName;
      Post;
    end;

    tv1.Controller.EditingController.ShowEdit();
  end;

end;

procedure TfrmShuttleClothSCList.ToolButton4Click(Sender: TObject);
begin
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      SCGYD(Trim(Order_Main.fieldbyname('MainId').AsString));
      Sleep(150);
      UPGYD(Trim(Order_Main.fieldbyname('MainId').AsString));
      Next;
    end;
  end;
end;

procedure TfrmShuttleClothSCList.cxTabControl1Change(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmShuttleClothSCList.Tv3CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('exec P_Del_CF2 @mainid=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');

    ExecSQL;
  end;
end;

end.

