unit U_YarnPurchasePlanDetailList;

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, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxPC, cxButtonEdit,
  cxTextEdit, cxDropDownEdit, cxLookAndFeels, cxLookAndFeelPainters, 
   cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, RM_e_Graphic, RM_e_Jpeg, RM_E_llPDF, Vcl.Clipbrd, 
  dxScrollbarAnnotations, FrameDateSel, cxContainer,
   cxProgressBar, dxSkinsCore, dxSkinsDefaultPainters;

type
  TfrmYarnPurchasePlanDetailList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    CDS_1: TClientDataSet;
    Panel1: TPanel;
    Label4: TLabel;
    Label9: TLabel;
    BuyName: TcxTextEdit;
    PurNo: TcxTextEdit;
    cxTabControl1: TcxTabControl;
    DS_1: TDataSource;
    GPM_1: TcxGridPopupMenu;
    Label3: TLabel;
    SellName: TcxTextEdit;
    pm1: TPopupMenu;
    ToolButton7: TToolButton;
    N3: TMenuItem;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    VC_SCSCode: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    v1PRTPrice: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    N5: TMenuItem;
    N6: TMenuItem;
    TV1Column1: TcxGridDBColumn;
    frmFrameDateSel1: TfrmFrameDateSel;
    TV1Column2: TcxGridDBColumn;
    TV1Column5: TcxGridDBColumn;
    Label1: TLabel;
    Y_Name: TcxTextEdit;
    ADOQueryImage: TADOQuery;
    TV1Column7: TcxGridDBColumn;
    TV1Column8: TcxGridDBColumn;
    TV1Column9: TcxGridDBColumn;
    TV1Column10: TcxGridDBColumn;
    TV1Column11: TcxGridDBColumn;
    TV1Column12: TcxGridDBColumn;
    TV1Column13: TcxGridDBColumn;
    TV1Column14: TcxGridDBColumn;
    TV1Column15: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure BuyNameChange(Sender: TObject);
    procedure tchkClick(Sender: TObject);
    procedure TnochkClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TqxClick(Sender: TObject);
    procedure TnoqxClick(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure btnTijiaoClick(Sender: TObject);
    procedure btnCXTijiaoClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure btnWCClick(Sender: TObject);
    procedure btnWCCXClick(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure PurNoPropertiesChange(Sender: TObject);
  private
    fFlileFlag: string;
    procedure InitGrid();
    procedure SetStatus();
    procedure InitImage();

    { Private declarations }
  public
    FFInt, FCloth: Integer;
    FAuthority, FGSTT, FSubIdS: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_YarnPurchasePlanPut, U_RTFun, U_AttachmentUpload, U_LabelPrint;

{$R *.dfm}

procedure TfrmYarnPurchasePlanDetailList.InitImage();
begin

  ADOQueryImage.Close;
  if CDS_1.IsEmpty then
    exit;
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID=' + quotedstr(trim(CDS_1.fieldbyname('SubId').AsString)));
    sql.Add('and TFType=' + quotedstr(trim('HX')));
    open;
  end;
end;

procedure TfrmYarnPurchasePlanDetailList.N1Click(Sender: TObject);
begin
  SelOKNoFiler(Tv1, True); //全选
end;

procedure TfrmYarnPurchasePlanDetailList.N2Click(Sender: TObject);
begin
  SelOKNoFiler(Tv1, False); //全弃
end;

procedure TfrmYarnPurchasePlanDetailList.N3Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmYarnPurchasePlanDetailList.N4Click(Sender: TObject);
begin
  Clipboard.SetTextBuf(PChar(Trim(CDS_1.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmYarnPurchasePlanDetailList.N5Click(Sender: TObject);
begin
  SelOKNo(CDS_1, True);
end;

procedure TfrmYarnPurchasePlanDetailList.N6Click(Sender: TObject);
begin
  SelOKNo(CDS_1, False);

end;

procedure TfrmYarnPurchasePlanDetailList.PurNoPropertiesChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmYarnPurchasePlanDetailList.SetStatus();
begin

end;

procedure TfrmYarnPurchasePlanDetailList.FormDestroy(Sender: TObject);
begin
  inherited;
//  frmContractListNX:=nil;
end;

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

procedure TfrmYarnPurchasePlanDetailList.FormCreate(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.EndDate.Date := SGetServerDate(ADOQueryTemp);
  frmFrameDateSel1.BegDate.Date := frmFrameDateSel1.EndDate.Date - 90;

end;

procedure TfrmYarnPurchasePlanDetailList.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmYarnPurchasePlanDetailList.InitGrid();
var
  WSql: string;
begin
  WSql := SGetFilters(Panel1, 1, 2);
  if trim(WSql) <> '' then
  begin
    WSql := ' and ' + trim(WSql);
  end;

  WSql := WSql + ' and PurDate>' + quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.BegDate.Date));
  WSql := WSql + ' and PurDate<=' + quotedstr(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.enddate.Date + 1));

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;

      sql.Add('select A.*,B.*    ');
      sql.Add(' ,YDHQty=(select sum(Qty) from BS_Yarn_IO X where X.IOFlag=''入库''  and X.FromPurSId=B.PurSId)  ');
      sql.Add(' from Pur_YarnPlan_Main A inner join Pur_YarnPlan_sub B on A.PurMId=B.PurMId ');
      sql.Add('where isnull(LX,'''') <> ''织造单''  and 1=1 ' + (WSql));

      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''0''');
          end;
        1:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''1''');
          end;
        2:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''9''');
          end;
        3:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''10''');
          end;
        4:
          begin
            sql.Add(' and  isnull(A.status,''0'')=''-1''');
          end;
      end;
//      ShowMessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
    TV1.DataController.Filter.Clear;

  end;
end;

procedure TfrmYarnPurchasePlanDetailList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmYarnPurchasePlanDetailList.TBPrintClick(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'YarnPurPrint';
      FFiltration1 := Trim(Self.CDS_1.fieldbyname('PurMId').AsString);
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.TBEditClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  if Trim(CDS_1.fieldbyname('Filler').AsString) <> Trim(DName) then
  begin
    Application.MessageBox('不能操作他人的数据!', '提示', 0);
    Exit;
  end;
  try
    frmYarnPurchasePlanPut := TfrmYarnPurchasePlanPut.Create(Application);
    with frmYarnPurchasePlanPut do
    begin
      PState := '修改';
      FPurMId := Trim(Self.CDS_1.fieldbyname('PurMId').AsString);
      FAuthority := self.FAuthority;
      FGSTT := self.FGSTT;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmYarnPurchasePlanPut.Free;
  end;
end;

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

procedure TfrmYarnPurchasePlanDetailList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmYarnPurchasePlanPut := TfrmYarnPurchasePlanPut.Create(Application);
    with frmYarnPurchasePlanPut do
    begin
      PState := '新增';
      FPurMId := '';
      FAuthority := self.FAuthority;
      FGSTT := self.FGSTT;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmYarnPurchasePlanPut.Free;
  end;
end;

procedure TfrmYarnPurchasePlanDetailList.FormShow(Sender: TObject);
begin
  inherited;
  fFlileFlag := UserDataFlag + 'HX';
  FAuthority := self.fParameters1;
  readCxGrid(trim(Self.Caption) + 'tv1', Tv1, '销售合同管理');

  SetStatus();
  InitGrid();
end;

procedure TfrmYarnPurchasePlanDetailList.CheckBox1Click(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmYarnPurchasePlanDetailList.CheckBox2Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmYarnPurchasePlanDetailList.ToolButton1Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmYarnPurchasePlanPut := TfrmYarnPurchasePlanPut.Create(Application);
    with frmYarnPurchasePlanPut do
    begin
      PState := '查看';
      FPurMId := Trim(Self.CDS_1.fieldbyname('PurMId').AsString);
      FGSTT := self.FGSTT;
      ToolBar2.Visible := False;
      TBSave.Visible := False;
//      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmYarnPurchasePlanPut.Free;
  end;
end;

procedure TfrmYarnPurchasePlanDetailList.ToolButton2Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmYarnPurchasePlanPut := TfrmYarnPurchasePlanPut.Create(Application);
    with frmYarnPurchasePlanPut do
    begin
      PState := '复制';
      FPurMId := Trim(Self.CDS_1.fieldbyname('PurMId').AsString);
      FAuthority := self.FAuthority;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmYarnPurchasePlanPut.Free;
  end;
end;

procedure TfrmYarnPurchasePlanDetailList.btnWCClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''完成'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('完成成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.BuyNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmYarnPurchasePlanDetailList.tchkClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''审核'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('审核成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.TnochkClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''撤销审核'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;

    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('审核成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  TBRafresh.Click;
end;

procedure TfrmYarnPurchasePlanDetailList.TqxClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''取消'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('取消成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.TnoqxClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');

      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''撤销取消'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));
      ShowMessage(sql.Text);
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销取消成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.ToolButton5Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmAttachmentUpload := TfrmAttachmentUpload.Create(Application);
    with frmAttachmentUpload do
    begin
      fkeyNO := Trim(Self.CDS_1.fieldbyname('PurMId').AsString);
      fType := '合同';
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmAttachmentUpload.Free;
  end;
end;

procedure TfrmYarnPurchasePlanDetailList.ToolButton7Click(Sender: TObject);
begin
  writeCxGrid(trim(Self.Caption) + 'tv1', Tv1, '销售合同管理');
end;

procedure TfrmYarnPurchasePlanDetailList.btnWCCXClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''撤销完成'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销完成成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  if AViewInfo.GridRecord.Values[tv1.GetColumnByFieldName('status').Index] = '2' then
    ACanvas.Brush.Color := clLime;
end;

procedure TfrmYarnPurchasePlanDetailList.btnTijiaoClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''提交'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('提交成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

procedure TfrmYarnPurchasePlanDetailList.btnCXTijiaoClick(Sender: TObject);
var
  MPurMIdS: string;
begin
  if CDS_1.IsEmpty then
    exit;
  if not CDS_1.Locate('SSel', True, []) then
  begin
    application.MessageBox('请选择数据', '提示');
    Exit;
  end;
  with CDS_1 do
  begin
    DisableControls;
    First;
    MPurMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MPurMIdS := MPurMIdS + trim(fieldbyname('PurMId').AsString) + ',';
      end;
      next;
    end;
    MPurMIdS := copy(MPurMIdS, 1, Length(MPurMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Pur_YarnPlan_SetStatus ');
      sql.Add(' @PurMIdS=' + QuotedStr(MPurMIdS));
      sql.Add(',@Operation=''撤销提交'' ');
      Sql.Add(',@DCode=' + quotedstr(Trim(DCode)));
      Sql.Add(',@DName=' + quotedstr(Trim(DName)));

      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('采购计划ID：' + trim(MPurMIdS))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      open;
    end;
    if ADOQueryCmd.FieldByName('intReturn').AsInteger = -1 then
      raise Exception.Create(pchar(trim(ADOQueryCmd.FieldByName('ShowMsg').AsString)));
    application.MessageBox('撤销提交成功', '提示');
    InitGrid();
  except
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    InitGrid();
  end;

end;

end.

