unit U_ClothSCListSEL;

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, dxBarBuiltInMenu, cxPC;

type
  TfrmClothSCListsel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: 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;
    C_CodeName: TEdit;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    RMDBPRT: TRMDBDataSet;
    v1Column19: TcxGridDBColumn;
    RMDBPZ: TRMDBDataSet;
    CDS_PZ: TClientDataSet;
    CDS_SJ: TClientDataSet;
    RMDBSJ: TRMDBDataSet;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    C_Code: TEdit;
    v1Column22: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    RMDBDataSet1: TRMDBDataSet;
    ClientDataSet1: TClientDataSet;
    v1Column14: TcxGridDBColumn;
    CDS_WJG: TClientDataSet;
    RMDBWJG: TRMDBDataSet;
    v1Column18: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column31: TcxGridDBColumn;
    v1Column34: TcxGridDBColumn;
    KHNAME: TEdit;
    Label7: TLabel;
    lbl1: TLabel;
    orderflag: TComboBox;
    cxTabControl1: TcxTabControl;
    ToolButton1: TToolButton;
    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 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 btn1Click(Sender: TObject);
    procedure orderflagChange(Sender: TObject);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure BatchNoHZKeyPress(Sender: TObject; var Key: Char);
    procedure KHNAMEKeyPress(Sender: TObject; var Key: Char);
    procedure C_CodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitButton();
    { Private declarations }
  public
    canshu1, FCheJian: string;
    { Public declarations }
  end;

var
  frmClothSCListsel: TfrmClothSCListsel;

implementation

uses
  U_DataLink, U_ClothSCInPut, U_Fun, U_ZDYHelp, U_SCPerson, U_ClothSCInPutSC;

{$R *.dfm}

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

procedure TfrmClothSCListsel.InitButton();
begin

end;

procedure TfrmClothSCListsel.TBCloseClick(Sender: TObject);
begin

  WriteCxGrid('坯布生产计划单', Tv1, '坯布生产管理');
  Close;
end;

procedure TfrmClothSCListsel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,CustomerNoName=(select TOP 1 CustomerNoName  from JYOrderCon_Main_PB X where X.MainId=A.ConMainId)  ');
      sql.Add(' ,HTSYRName=(select TOP 1 SYRName  from JYOrderCon_Main_PB X where X.MainId=A.ConMainId)');
      sql.Add(' ,ConPayment=(select TOP 1 Payment  from JYOrderCon_Main_PB X where X.MainId=A.ConMainId)');
      sql.Add(' ,ConPRTPrice=(select TOP 1 PRTPrice  from JYOrderCon_Sub_PB X where X.SubId=A.ConSubId) ');
      sql.Add(' ,ConDYMoney=(select TOP 1 DYMoney  from JYOrderCon_Sub_PB X where X.SubId=A.ConSubId) ');
      sql.Add(' ,ZdyNameZ=(select  TOP 1 X.ZdyNameZ from KH_Zdy_Attachment X inner join JYOrderCon_Main_PB Y on X.Type=''KHName'' and X.ZdyCode=Y.CustomerNo where Y.MainId=A.ConMainId) ');
//      sql.Add(' ,DDZT=(case when BegFlag=0 then ''待开始'' else (case when EndFlag=0 then ''已开始'' else ''已结束'' end ) end) ');
      sql.Add(' from Cloth_Main A inner join CLoth_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)) + '''');
      sql.Add('and A.ORDERFLAG=''' + Trim(orderflag.Text) + '''');
      if cxTabControl1.TabIndex = 0 then
      begin
        sql.Add('  and EndFlag=0 ');
      end
      else if cxTabControl1.TabIndex = 1 then
      begin
        sql.Add('  and EndFlag=1');
      end;

      sql.add('order by A.FILLTIME DESC');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmClothSCListsel.InitForm();
begin
  InitButton();
  ReadCxGrid('坯布生产计划单', Tv1, '坯布生产管理');
//  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 30;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);

  InitGrid();
end;

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

procedure TfrmClothSCListsel.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  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 TfrmClothSCListsel.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*');
    sql.Add('from JYCon_Sub_AnPai 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
    //TBRafresh.Click;
    //TBFind.Click;
    Order_Main.Delete;
  end;
end;

function TfrmClothSCListsel.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_Sub where SubId=''' + Trim(Order_Main.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_Main where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('计划单删除')));
      sql.Add(',' + quotedstr(trim('订单号:' + trim(Order_Main.FieldByName('ConNo').AsString) + 'mainid:' + trim(Order_Main.FieldByName('MainId').AsString) + '   subid:' + trim(Order_Main.FieldByName('subid').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');

      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_PaiZhen where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      ExecSQL;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete ZDEL_Cloth_YCL_PB where mainid=''' + Trim(Order_Main.fieldbyname('mainid').AsString) + '''');
      SQL.Add('insert into ZDEL_Cloth_YCL_PB ');
      sql.Add('select * from Cloth_YCL_PB where mainid=''' + Trim(Order_Main.fieldbyname('mainid').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update ZDEL_Cloth_YCL_PB Set DELNOTE=''删除人:''+''' + Trim(DName) + '''');
      sql.Add('+'' ''+Convert(Varchar(20),getdate(),120)');
      sql.Add(' where mainid=''' + Trim(Order_Main.fieldbyname('mainid').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_YCL_PB where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

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

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

procedure TfrmClothSCListsel.TBAddClick(Sender: TObject);
begin

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

procedure TfrmClothSCListsel.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 TfrmClothSCListsel.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmClothSCListsel.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 Cloth_Main A inner join CLoth_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 TfrmClothSCListsel.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;
      ToolBar3.Visible := False;
      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

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

procedure TfrmClothSCListsel.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 TfrmClothSCListsel.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  FDDZT: string;
begin

  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('DDZT').Index] = null then
    Exit;

  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 TfrmClothSCListsel.btn1Click(Sender: TObject);
begin

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

procedure TfrmClothSCListsel.orderflagChange(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmClothSCListsel.C_CodeKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmClothSCListsel.BatchNoHZKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmClothSCListsel.KHNAMEKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmClothSCListsel.C_CodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmClothSCListsel.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmClothSCListsel.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if Application.MessageBox('确定要执行结束操作吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate Cloth_Main Set Endtime=getdate(),EndPerson=''' + Trim(DName) + ''',EndFlag=1');
        sql.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
        sql.Add('UPdate  Cloth_JiTai SET StopFlag=1,DOTime=getdate(),DOPerson=''' + Trim(DName) + '''');
        sql.Add(',TYTime=getdate(),TYPerson=''' + Trim(DName) + '''');
        sql.Add(' where MainId=' + quotedstr(trim(Order_Main.fieldbyname('MainId').AsString)));
        sql.Add(' and StopFlag=0');
        ExecSQL;
      end;
//      UpdateJTInfo(Trim(Order_Main.fieldbyname('MainId').AsString));

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('Update Cloth_Sub Set RTAPJTQty=(select Count(*) from Cloth_JiTai A where A.MainId=Cloth_Sub.MainId )');
        sql.Add(',RTAPJTInfo=dbo.F_Get_Order_SubStr_PB(Cloth_Sub.MainId,''RTAPJTInfo'')');
        sql.Add(',RTQYJTQty=(select Count(*) from Cloth_JiTai A where A.MainId=Cloth_Sub.MainId and StopFlag=0 )');
        sql.Add(',RTQYJTInfo=dbo.F_Get_Order_SubStr_PB(Cloth_Sub.MainId,''RTQYJTInfo'')');
        sql.Add(',RTTYJTQty=(select Count(*) from Cloth_JiTai A where A.MainId=Cloth_Sub.MainId and StopFlag=1 )');
        sql.Add(',RTTYJTInfo=dbo.F_Get_Order_SubStr_PB(Cloth_Sub.MainId,''RTTYJTInfo'')');
        sql.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
    //Parameters.ParamByName('MainId').Value:=Trim(RTMainId);
        ExecSQL;
      end;
      Order_Main.Delete;

    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmClothSCListsel.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate Cloth_Main Set Endtime=NULL,EndPerson=NULL,EndFlag=0');
        sql.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
        ExecSQL;
      end;
      Order_Main.Delete;

    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmClothSCListsel.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate Cloth_Main Set Begtime=getdate(),BegPerson=''' + Trim(DName) + ''',BegFlag=1');
        sql.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');

        ExecSQL;
      end;

      Order_Main.Delete;

    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmClothSCListsel.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    Order_Main.DisableControls;
    with Order_Main do
    begin

      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('UPdate Cloth_Main Set Begtime=getdate(),BegPerson=''' + Trim(DName) + ''',BegFlag=0');
        sql.Add(' where MainId=''' + Trim(Order_Main.fieldbyname('MainId').AsString) + '''');
        ExecSQL;
      end;

      Order_Main.Delete;

    end;
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
  except
    Order_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('操作异常!', '提示', 0);
  end;
end;

procedure TfrmClothSCListsel.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  ModalResult := 1;
end;

end.

