unit U_ClaimsList;

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, dxSkinsCore,
  dxSkinsDefaultPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu,
  U_BaseList, RM_e_Graphic, RM_e_Jpeg, RM_E_llPDF, Vcl.Clipbrd,
  dxScrollbarAnnotations, dxSkinBasic, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkroom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray,
  dxSkinOffice2013White, dxSkinOffice2016Colorful, dxSkinOffice2016Dark,
  dxSkinOffice2019Black, dxSkinOffice2019Colorful, dxSkinOffice2019DarkGray,
  dxSkinOffice2019White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringtime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinTheBezier, dxSkinValentine,
  dxSkinVisualStudio2013Blue, dxSkinVisualStudio2013Dark,
  dxSkinVisualStudio2013Light, dxSkinVS2010, dxSkinWhiteprint, dxSkinWXI,
  dxSkinXmas2008Blue;

type
  TfrmClaimsList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    v1OrdDate: TcxGridDBColumn;
    v1ConNo: TcxGridDBColumn;
    CDS_2: TClientDataSet;
    v1CustomerNoName: TcxGridDBColumn;
    ToolButton1: TToolButton;
    v1Column1: TcxGridDBColumn;
    ToolButton2: TToolButton;
    v1Column4: TcxGridDBColumn;
    pm2: TPopupMenu;
    Panel1: TPanel;
    Label4: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    OurCoName: TEdit;
    MPRTCodeName: TEdit;
    ClaNo: TEdit;
    MPRTKZ: TEdit;
    MPRTMF: TEdit;
    cxTabControl1: TcxTabControl;
    tchk: TToolButton;
    Tnochk: TToolButton;
    cxSplitter1: TcxSplitter;
    DS_2: TDataSource;
    Label2: TLabel;
    v1Column10: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    GPM_2: TcxGridPopupMenu;
    CDS_1: TClientDataSet;
    btnTijiao: TToolButton;
    btnCXTijiao: TToolButton;
    v1Column13: TcxGridDBColumn;
    Label3: TLabel;
    OppCoName: TEdit;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    pm1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQueryImage: TADOQuery;
    IsJYTime: TCheckBox;
    ToolButton7: TToolButton;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    v1Column32: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    v1Column23: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column27: TcxGridDBColumn;
    v1Column28: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column40: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    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 Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    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 Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    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 ClaNoKeyPress(Sender: TObject; var Key: Char);
    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 ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
  private
    fFlileFlag: string;
    procedure InitGrid();
    procedure SetStatus();
    procedure InitSub();
    procedure InitImage();
    function DelData(): Boolean;

    { 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,
  U_ClaimsPut, U_CLNoteEdit;

{$R *.dfm}

procedure TfrmClaimsList.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 TfrmClaimsList.InitSub();
begin
  if CDS_1.IsEmpty then
    exit;
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from Claims_Sub A  ');
    sql.Add('where ClaMId =' + quotedstr((CDS_1.fieldbyname('ClaMId').AsString)));
    open;
  end;
  SCreateCDS(ADOQueryTemp, CDS_2);
  SInitCDSData(ADOQueryTemp, CDS_2);
  TV2.DataController.Filter.Clear;
end;

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

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

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

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

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

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

end;

procedure TfrmClaimsList.SetStatus();
begin
  TBAdd.Enabled := false;        //增加
  tbedit.Enabled := false;       //修改
  btnTijiao.Enabled := false;    //复核
  btnCXTijiao.Enabled := false;  //复核
  ToolButton2.Enabled := false;  //撤销复制
  ToolButton4.Enabled := false;  //删除
  tchk.Enabled := false;         //审核
  tnochk.Enabled := false;       //撤销审核
  ToolButton3.Enabled := false;  //处理结果补录
  TBPrint.Enabled := False;      //打印
  if trim(DParameters1) = '申请' then
  begin
    TBAdd.Enabled := True;
    tbedit.Enabled := True;
    ToolButton2.Enabled := True;
    TBPrint.Enabled := True;
    ToolButton3.Enabled := True;
    ToolButton4.Enabled := True;
    case cxTabControl1.TabIndex of
      0:
        begin
        end;
      1:
        begin

        end;
      2:
        begin
        end;
    end;
  end;
  if trim(DParameters1) = '审核' then
  begin
    TBAdd.Enabled := True;
    tbedit.Enabled := True;
    ToolButton2.Enabled := True;
    TBPrint.Enabled := True;
    ToolButton3.Enabled := True;
    ToolButton4.Enabled := True;
    case cxTabControl1.TabIndex of
      0:
        begin
          tchk.Enabled := true;
        end;
      1:
        begin
          tnochk.Enabled := true;
        end;
      2:
        begin
        end;
    end;
  end;
  if trim(DParameters1) = '复核' then
  begin
    TBAdd.Enabled := True;
    tbedit.Enabled := True;
    ToolButton2.Enabled := True;
    TBPrint.Enabled := True;
    ToolButton3.Enabled := True;
    ToolButton4.Enabled := True;
    case cxTabControl1.TabIndex of
      0:
        begin
        end;
      1:
        begin
          btnTijiao.Enabled := true;
        end;
      2:
        begin
          btnCXTijiao.Enabled := true;
        end;
    end;
  end;
end;

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

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

procedure TfrmClaimsList.FormCreate(Sender: TObject);
begin
  inherited;
  EndDate.DateTime := SGetServerDate(ADOQueryTemp);
  BegDate.DateTime := EndDate.DateTime - 90;

end;

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

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

  if IsJYTime.Checked then
  begin
    WSql := WSql + ' and ClaDate>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    WSql := WSql + ' and ClaDate<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end
  else
  begin
    if trim(WSql) <> '' then
      WSql := ' and 1=1' + trim(WSql)
    else
      WSql := WSql + ' and 1=2 ';
  end;
  if trim(WSql) = 'and 1=2' then
    Application.MessageBox('勾选制单日期或填入搜索条件', '提示', 0);

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

      sql.Add('select AA.* from (select A.*');
      sql.Add(' from Claims_Main A ) AA  ');
      sql.Add('where 1=1 ' + (WSql));

      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add(' and  isnull(AA.status,''0'')=''0''');
          end;
        1:
          begin
            sql.Add(' and  isnull(AA.status,''0'')=''9''');
          end;
        2:
          begin
            sql.Add(' and  isnull(AA.status,''0'')=''10''');
          end;

      end;
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
    TV1.DataController.Filter.Clear;

  end;
end;

procedure TfrmClaimsList.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 TfrmClaimsList.TBPrintClick(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'ClaPrint';
      FFiltration1 := QuotedStr(Trim(Self.CDS_1.fieldbyname('ClaMId').AsString));
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmClaimsList.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
    frmClaimsPut := TfrmClaimsPut.Create(Application);
    with frmClaimsPut do
    begin
      PState := '修改';
      FClaMId := Trim(Self.CDS_1.fieldbyname('ClaMId').AsString);
      FAuthority := self.FAuthority;
      FGSTT := self.FGSTT;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClaimsPut.Free;
  end;
end;

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

procedure TfrmClaimsList.TBAddClick(Sender: TObject);
var
  maxno: string;
begin
  try
    frmClaimsPut := TfrmClaimsPut.Create(Application);
    with frmClaimsPut do
    begin
      PState := '新增';
      FClaMId := '';
      FAuthority := self.FAuthority;
      FGSTT := self.FGSTT;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClaimsPut.Free;
  end;
end;

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

  SetStatus();
  InitGrid();
end;

procedure TfrmClaimsList.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if ToolButton1.Visible = False then
    Exit;
  ToolButton1.Click;
end;

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

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

procedure TfrmClaimsList.ClaNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    InitGrid();
  end;
end;

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

      end;
    end;
  finally
    frmClaimsPut.Free;
  end;
end;

procedure TfrmClaimsList.ToolButton2Click(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmClaimsPut := TfrmClaimsPut.Create(Application);
    with frmClaimsPut do
    begin
      PState := '复制';
      FClaMId := Trim(Self.CDS_1.fieldbyname('ClaMId').AsString);
      FAuthority := self.FAuthority;
      fFlileFlag := self.fFlileFlag;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmClaimsPut.Free;
  end;
end;

procedure TfrmClaimsList.ToolButton3Click(Sender: TObject);
begin
  try
    frmCLNoteEdit := TfrmCLNoteEdit.Create(Application);
    with frmCLNoteEdit do
    begin
      FFFIDS := Trim(Self.CDS_1.fieldbyname('ClaMId').AsString);
      with ADOQueryTemp do
      begin
        Close;
        SQL.Clear;
        SQL.Add('SELECT CLNote FROM Claims_Main');
        SQL.Add('WHERE ClaMid = :ID');
        Parameters.ParamByName('ID').Value := FFFIDS;
        Open;
        if not Eof then
          CLNote.Text := FieldByName('CLNote').AsString;
      end;
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmCLNoteEdit.Free;
  end;
end;

procedure TfrmClaimsList.ToolButton4Click(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;

  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;



  while CDS_1.Locate('SSel', true, []) do
  begin
    if Trim(CDS_1.fieldbyname('ClaMid').AsString) <> '' then
    begin
      DelData()
    end;
    CDS_1.Delete;
  end;

end;

function TfrmClaimsList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Claims_Main where ClaMid=''' + Trim(CDS_1.fieldbyname('ClaMid').AsString) + '''');
      sql.Add('delete Claims_Sub where ClaMid=''' + Trim(CDS_1.fieldbyname('ClaMid').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(CDS_1.FieldByName('ClaNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      ExecSQL;
    end;

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

procedure TfrmClaimsList.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 TfrmClaimsList.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 TfrmClaimsList.tchkClick(Sender: TObject);
var
  MClaMIdS: 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;
    MClaMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MClaMIdS := MClaMIdS + trim(fieldbyname('ClaMId').AsString) + ',';
      end;
      next;
    end;
    MClaMIdS := copy(MClaMIdS, 1, Length(MClaMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Claims_SetStatus ');
      sql.Add(' @ClaMIdS=' + QuotedStr(MClaMIdS));
      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(MClaMIdS))));
      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 TfrmClaimsList.TnochkClick(Sender: TObject);
var
  MClaMIdS: 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;
    MClaMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MClaMIdS := MClaMIdS + trim(fieldbyname('ClaMId').AsString) + ',';
      end;
      next;
    end;
    MClaMIdS := copy(MClaMIdS, 1, Length(MClaMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Claims_SetStatus ');
      sql.Add(' @ClaMIdS=' + QuotedStr(MClaMIdS));
      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(MClaMIdS))));
      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 TfrmClaimsList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  TBRafresh.Click;
end;

procedure TfrmClaimsList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitSub();
end;

procedure TfrmClaimsList.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 TfrmClaimsList.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 TfrmClaimsList.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 TfrmClaimsList.ToolButton7Click(Sender: TObject);
begin
  writeCxGrid(trim(Self.Caption) + 'tv1', Tv1, '销售合同管理');
  writeCxGrid(trim(Self.Caption) + 'tv2', Tv2, '销售合同管理');
end;

procedure TfrmClaimsList.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 TfrmClaimsList.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 TfrmClaimsList.btnTijiaoClick(Sender: TObject);
var
  MClaMIdS: 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;
    MClaMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MClaMIdS := MClaMIdS + trim(fieldbyname('ClaMId').AsString) + ',';
      end;
      next;
    end;
    MClaMIdS := copy(MClaMIdS, 1, Length(MClaMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Claims_SetStatus ');
      sql.Add(' @CLaMIdS=' + QuotedStr(MClaMIdS));
      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(MClaMIdS))));
      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 TfrmClaimsList.btnCXTijiaoClick(Sender: TObject);
var
  MClaMIdS: 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;
    MClaMIdS := '';
    while not eof do
    begin
      if fieldbyname('SSel').AsBoolean then
      begin
        MClaMIdS := MClaMIdS + trim(fieldbyname('ClaMId').AsString) + ',';
      end;
      next;
    end;
    MClaMIdS := copy(MClaMIdS, 1, Length(MClaMIdS) - 1);
    EnableControls;
  end;

  try
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Claims_SetStatus ');
      sql.Add(' @ClaMIdS=' + QuotedStr(MClaMIdS));
      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(MClaMIdS))));
      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.

