unit U_JHDInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, StdCtrls, BtnEdit,
  ExtCtrls, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter, 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, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic,
  dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinValentine, dxSkinVS2010,
  dxSkinWhiteprint, dxSkinXmas2008Blue;

type
  TfrmJHDInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Panel1: TPanel;
    Label13: TLabel;
    Label4: TLabel;
    A6PONO: TEdit;
    Label8: TLabel;
    SMA: TEdit;
    Label9: TLabel;
    DCNO: TBtnEditA;
    TOCOUNTRY: TBtnEditA;
    Label15: TLabel;
    Label19: TLabel;
    Label2: TLabel;
    BGTAITOU: TBtnEditA;
    Label18: TLabel;
    F2YunFee: TEdit;
    Label22: TLabel;
    KDYPF: TEdit;
    Label30: TLabel;
    HTDate: TDateTimePicker;
    Label31: TLabel;
    Label1: TLabel;
    ZhuMaiTou: TMemo;
    Label3: TLabel;
    SellNOTE: TMemo;
    NOTE: TMemo;
    Label6: TLabel;
    YWLX: TComboBox;
    Label11: TLabel;
    ZMXingZhi: TBtnEditA;
    Label12: TLabel;
    chuandate: TDateTimePicker;
    Label14: TLabel;
    DAYS: TEdit;
    Label20: TLabel;
    DLS: TBtnEditA;
    Label21: TLabel;
    YJZFFS: TComboBox;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    JSBZ: TComboBox;
    Label29: TLabel;
    B6ChuYunGang: TBtnEditA;
    Label5: TLabel;
    SMB: TEdit;
    Label16: TLabel;
    B7DaoHuoGang: TBtnEditA;
    ZUSDHLV: TEdit;
    Label28: TLabel;
    BANKNAME: TComboBox;
    Label32: TLabel;
    F3BaoFee: TEdit;
    Label33: TLabel;
    FKR: TMemo;
    Label7: TLabel;
    XYNO: TBtnEditA;
    Label10: TLabel;
    YWY: TComboBox;
    Label17: TLabel;
    ZRMBHLV: TEdit;
    Label34: TLabel;
    ZZG: TBtnEditA;
    Label35: TLabel;
    KHName: TBtnEditA;
    Label36: TLabel;
    POMMONEY: TEdit;
    OrdConPrcNote: TBtnEditA;
    SHFS: TBtnEditA;
    A4FPNO: TBtnEditA;
    Label23: TLabel;
    JHDTYPE: TComboBox;
    Label37: TLabel;
    YSDJ: TEdit;
    Panel2: TPanel;
    ToolBar2: TToolBar;
    ToolButton2: TToolButton;
    ToolButton1: TToolButton;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column13: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column20: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1YSKeZhong: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    VCC6BGPrice: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Panel3: TPanel;
    ToolBar3: TToolBar;
    ToolButton4: TToolButton;
    ToolButton6: TToolButton;
    cxGrid2: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    CDS_JJ: TClientDataSet;
    DS_JJ: TDataSource;
    ToolButton5: TToolButton;
    TV2Column1: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Panel4: TPanel;
    Label27: TLabel;
    Edit1: TEdit;
    Label38: TLabel;
    Edit2: TEdit;
    Label39: TLabel;
    Edit3: TEdit;
    Label40: TLabel;
    Edit4: TEdit;
    Label41: TLabel;
    Edit5: TEdit;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Label42: TLabel;
    BZWAYS: TEdit;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    TV2Column2: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    ToolButton7: TToolButton;
    Label43: TLabel;
    JDDATE: TBtnEditA;
    Label44: TLabel;
    CMHC: TBtnEditA;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    Tv1Column16: TcxGridDBColumn;
    ToolButton8: TToolButton;
    Button1: TButton;
    Tv1Column17: TcxGridDBColumn;
    ToolButton9: TToolButton;
    Tv1Column18: TcxGridDBColumn;
    ToolButton10: TToolButton;
    ColorBox1: TColorBox;
    ToolButton11: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column17PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v1ZZJGouPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure TCXLJClick(Sender: TObject);
    procedure TOCOUNTRYBtnClick(Sender: TObject);
    procedure YWLXDropDown(Sender: TObject);
    procedure ZORDERNOBtnClick(Sender: TObject);
    procedure DCNOBtnClick(Sender: TObject);
    procedure Tv1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1Column7PropertiesEditValueChanged(Sender: TObject);
    procedure Tv1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure KHNameBtnClick(Sender: TObject);
    procedure A4FPNOBtnClick(Sender: TObject);
    procedure TV2CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure JSJE();
    procedure cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject);
    procedure YSDJChange(Sender: TObject);
    procedure TV2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure JDDATEBtnClick(Sender: TObject);
    procedure SHFSBtnClick(Sender: TObject);
    procedure Tv1Column14PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SetXH();
    procedure ToolButton9Click(Sender: TObject);
    procedure ToolButton10Click(Sender: TObject);
    procedure Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure ToolButton11Click(Sender: TObject);
  private
    { Private declarations }
    function SaveCKData(): Boolean;
  public
    { Public declarations }
    FBCId, canshu3: string;
    CopyStr: string;
  end;

var
  frmJHDInPut: TfrmJHDInPut;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_ZdyAttachment, U_ProductOrderList_Sel,
  U_DCDList_Sel, U_ZdyAttachGYS, U_CHListsel2;

{$R *.dfm}

procedure TfrmJHDInPut.SetXH();
var
  i: Integer;
begin
  with CDS_Sub do
  begin
    First;
    i := 1;
    while not Eof do
    begin
      with CDS_Sub do
      begin
        Edit;
        FieldByName('XHNoTemp').Value := i;
        Post;
      end;
      i := i + 1;
      Next;
    end;
  end;

  with CDS_Sub do
  begin
    CDS_Sub.IndexFieldNames := '';
    First;
    i := 1;
    while not Eof do
    begin
      with CDS_Sub do
      begin
        Edit;
        FieldByName('XHNo').Value := FieldByName('XHNoTemp').AsInteger;
        Post;
      end;
      i := i + 1;
      Next;
    end;
    CDS_Sub.IndexFieldNames := 'XHNo';
  end;
end;

procedure TfrmJHDInPut.JSJE();
var
  FCPMoney, FDJ, fjm, fjs, fcyfee: double;
begin
  //总金额=产品金额-定金-减免总金额+加收总金额 +船样费
  if TV1.DataController.Summary.FooterSummaryValues[1] <> NULL then
    FCPMoney := TV1.DataController.Summary.FooterSummaryValues[1]
  else
    FCPMoney := 0;

  if TV1.DataController.Summary.FooterSummaryValues[7] <> NULL then
    fcyfee := TV1.DataController.Summary.FooterSummaryValues[7]
  else
    fcyfee := 0;

  FDJ := StrToFloatDEF(YSDJ.Text, 0);

  fjm := 0;
  fjs := 0;
  if CDS_JJ.IsEmpty = False then
  begin
    with CDS_JJ do
    begin
      First;
      while not Eof do
      begin
        if CDS_JJ.fieldbyname('BILI').ASSTRING <> '' then
        begin
          with CDS_JJ do
          begin
            Edit;
            FieldByName('FYMONEY').Value := StrToFloatDef((CDS_JJ.fieldbyname('BILI').ASSTRING), 0) * FCPMoney / 100;
            Post;
          end;
        end;
        if CDS_JJ.fieldbyname('FYTYPE').ASSTRING = '减免' then
        begin
          fjm := fjm + STRTOFLOATDEF(CDS_JJ.fieldbyname('FYMONEY').ASSTRING, 0);
        end
        else
        begin
          fjs := fjs + STRTOFLOATDEF(CDS_JJ.fieldbyname('FYMONEY').ASSTRING, 0);
        end;

        Next;
      end;
    end;
  end;

  EDIT2.TEXT := FLOATTOSTR(FDJ);
  EDIT1.TEXT := FLOATTOSTR(FCPMoney);
  EDIT4.TEXT := FLOATTOSTR(fjm);
  EDIT3.TEXT := FLOATTOSTR(fjs);
  Edit5.Text := FLOATTOSTR(FCPMoney - FDJ - fjm + fjs + fcyfee);
end;

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

function TfrmJHDInPut.SaveCKData(): Boolean;
var
  FJMID, Maxno, MaxSubNo, MAXJJID, FSCID, FJJID: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JHD_Main where JHID=''' + Trim(FBCId) + '''');
      Open;
    end;
    FBCId := Trim(ADOQueryTemp.fieldbyname('JHID').AsString);
    if Trim(FBCId) = '' then
    begin
      if GetLSNo(ADOQueryCmd, Maxno, 'JH', 'JHD_Main', 3, 1) = False then
      begin
        Result := False;
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取主编号失败!', '提示', 0);
        Exit;
      end;
    end
    else
    begin
      Maxno := Trim(FBCId);
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JHD_Main where JHID=''' + Trim(Maxno) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FBCId) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('FillerCode').Value := Trim(DCode);
//        FieldByName('status').Value := Trim(DCode);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditerCode').Value := Trim(DCode);
        FieldByName('EditTime').Value := SGetServerDate(ADOQueryTemp);
      end;
      FieldByName('JHID').Value := Trim(Maxno);

      FieldByName('JMMONEY').Value := Edit4.Text;
      FieldByName('JSMONEY').Value := Edit3.Text;
      FieldByName('ZMONEY').Value := Edit5.Text;

      RTSetsavedata(ADOQueryCmd, 'JHD_Main', Panel1, 1);
      RTSetsavedata(ADOQueryCmd, 'JHD_Main', Panel1, 2);

      FieldByName('FKR').Value := UpperCase(FKR.Text);

      if chuandate.Checked = true then
      begin
        FieldByName('chuandate').Value := chuandate.DateTime;
      end
      else
      begin
        FieldByName('chuandate').Value := NULL;
      end;
      Post;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JHD_Main where A4FPNO=''' + Trim(A4FPNO.Text) + ''' and Valid=''Y'' ');
      Open;
    end;
    if ADOQueryTemp.RecordCount > 1 then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('此发票号已经被使用，不能保存!', '提示', 0);
      Exit;
    end;
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not eof do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JHD_SUB where JHSID=''' + Trim(CDS_Sub.fieldbyname('JHSID').AsString) + '''');
          Open;
        end;
        FSCID := Trim(ADOQueryTemp.fieldbyname('JHSID').AsString);
        if Trim(FSCID) = '' then
        begin
          if GetLSNo(ADOQueryCmd, MaxSubNo, 'JHS', 'JHD_SUB', 3, 1) = False then
          begin
            Result := False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取子编号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          MaxSubNo := Trim(FSCID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JHD_SUB where JHSID=''' + Trim(MaxSubNo) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FSCID) = '' then
          begin
            Append;
            FieldByName('SFiller').Value := Trim(DName);
          end
          else
          begin
            Edit;
            FieldByName('SEditer').Value := Trim(DName);
            FieldByName('SEditTime').Value := SGetServerDate(ADOQueryTemp);
          end;
          FieldByName('JHID').Value := Trim(Maxno);
          FieldByName('JHSID').Value := Trim(MaxSubNo);

          FieldByName('FROMYFSID').Value := CDS_Sub.fieldbyname('FROMYFSID').ASSTRING;
          FieldByName('FROMYFPZNO').Value := CDS_Sub.fieldbyname('FROMYFPZNO').ASSTRING;
          FieldByName('JHSID').Value := Trim(MaxSubNo);

          RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Sub, 'JHD_SUB', 2);

          Post;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('UPDATE YF_MONEY_CR_SUB SET PRICE=' + (Trim(CDS_Sub.fieldbyname('C6BGPrice').Value)));
          sql.Add(',mxmoney=qty*' + (Trim(CDS_Sub.fieldbyname('C6BGPrice').Value)));
          sql.Add('where CHARINDEX(ltrim(rtrim(yfsid)),' + QuotedStr(Trim(CDS_Sub.fieldbyname('FROMYFSID').ASSTRING)));
          sql.Add(')>0');

          sql.Add('UPDATE YF_MONEY_CR SET money=(select sum(mxmoney) from  yf_money_cr_sub b where b.yfid=YF_MONEY_CR.yfid)');
          sql.Add('where yfid=(select yfid from YF_MONEY_CR_sub where CHARINDEX(yfsid,' + QuotedStr(Trim(CDS_Sub.fieldbyname('FROMYFSID').ASSTRING)));
          sql.Add(')>0)');
          ExecSQL;
        end;
        Edit;
        FieldByName('JHSID').Value := Trim(MaxSubNo);
        FieldByName('JHID').Value := Trim(Maxno);
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
      //保存右下加减表
    CDS_JJ.DisableControls;
    with CDS_JJ do
    begin
      First;
      while not eof do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JHD_JJ where JJID=''' + Trim(CDS_JJ.fieldbyname('JJID').AsString) + '''');
          Open;
        end;
        FJJID := Trim(ADOQueryTemp.fieldbyname('JJID').AsString);
        if Trim(FJJID) = '' then
        begin
          if GetLSNo(ADOQueryCmd, MAXJJID, 'JJ', 'JHD_JJ', 3, 1) = False then
          begin
            Result := False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取子编号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          MAXJJID := Trim(FJJID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JHD_JJ where JJID=''' + Trim(MAXJJID) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FJJID) = '' then
          begin
            Append;
            FieldByName('SFiller').Value := Trim(DName);
          end
          else
          begin
            Edit;
            FieldByName('SEditer').Value := Trim(DName);
            FieldByName('SEditTime').Value := SGetServerDate(ADOQueryTemp);
          end;
          FieldByName('JHID').Value := Trim(Maxno);
          FieldByName('JJID').Value := Trim(MAXJJID);
          RTSetSaveDataCDS(ADOQueryCmd, Tv2, CDS_JJ, 'JHD_JJ', 2);
          Post;
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('EXEC P_Do_JJYSK @JJID=''' + Trim(MAXJJID) + '''');
          ExecSQL;

        end;
        Edit;
        FieldByName('JJID').Value := Trim(MAXJJID);
        FieldByName('JHID').Value := Trim(Maxno);
        Post;
        Next;
      end;
    end;
    CDS_JJ.EnableControls;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JHD_MAIN Set ');
      sql.Add(' C7BGMoneyHZ=(select Sum(C7BGMoney+ISNULL(CYFEE,0)) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E1BZQtyHZ=(select Sum(E1BZQty) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E2ChiMaQtyHZ=(select Sum(E2ChiMaQty) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');

      sql.Add(',E3MaoZHZ=(select Sum(E3MaoZ) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E4JingZHZ=(select Sum(E4JingZ) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(' where JHID=''' + Trim(Maxno) + '''');
      ExecSQL;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    FBCId := Trim(Maxno);
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!', '提示', 0);
  end;

end;

procedure TfrmJHDInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('报关资料录入YD', Tv1, '报关管理12');
  Close;
end;

procedure TfrmJHDInPut.FormShow(Sender: TObject);
begin
  ReadCxGrid(Self.Caption, Tv1, '报关管理12');
  if canshu3 = '业务员' then
  begin
    VCC6BGPrice.Visible := False;
    VCC6BGPrice.Hidden := True;
  end
  else
  begin
    VCC6BGPrice.Visible := True;
    VCC6BGPrice.Hidden := False;
  end;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from JHD_MAIN A');
    sql.Add(' where JHID=''' + Trim(FBCId) + '''');
    Open;
  end;
  SCSHDataNew(ADOQueryTemp, Panel1, 1);
  SCSHDataNew(ADOQueryTemp, Panel1, 2);
  if ADOQueryTemp.FieldByName('CHUANDATE').ASSTRING = '' then
  begin
    chuandate.Date := SGetServerDate(ADOQueryTemp);
    chuandate.Checked := False;
  end
  else
  begin
    chuandate.Date := ADOQueryTemp.FieldByName('CHUANDATE').AsDateTime;
  end;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.*,XHNoTemp=XHNO ');
    sql.Add(' from JHD_SUB A');
    sql.Add(' where JHID=''' + Trim(FBCId) + '''');
    sql.Add(' and SValid=''Y'' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sub);
  SInitCDSData20(ADOQueryTemp, CDS_Sub);

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from JHD_JJ A');
    sql.Add(' where JHID=''' + Trim(FBCId) + '''');

    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_JJ);
  SInitCDSData20(ADOQueryTemp, CDS_JJ);
  if CopyStr = '99' then
  begin
    FBCId := '';
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('JHID').Value := Null;
        FieldByName('JHSID').Value := Null;
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;

    CDS_JJ.DisableControls;
    with CDS_JJ do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('JHID').Value := Null;
        FieldByName('JJID').Value := Null;
        Post;
        Next;
      end;
    end;
    CDS_JJ.EnableControls;
  end;
  if Trim(FBCId) = '' then
  begin
    YWY.Text := Trim(DName);
    HTDate.Date := SGetServerDate(ADOQueryTemp);
    chuandate.Date := SGetServerDate(ADOQueryTemp);
    chuandate.Checked := False;
  end;
  JSJE();
  setxh();

end;

procedure TfrmJHDInPut.TBSaveClick(Sender: TObject);
var
  FReal: Double;
  i: Integer;
begin

  if TryStrToFloat(F2YunFee.Text, FReal) = False then
  begin
    Application.MessageBox('运费非法数字!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(F3BaoFee.Text, FReal) = False then
  begin
    Application.MessageBox('保费非法数字!', '提示', 0);
    Exit;
  end;
  if Trim(days.Text) = '' then
  begin
    Application.MessageBox('付款期限不能为空!', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(days.Text, FReal) = False then
  begin
    Application.MessageBox('付款期限非法数字!', '提示', 0);
    Exit;
  end;
  if CDS_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('C3BGName', Null, []) then
  begin
    Application.MessageBox('品名不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(DCNO.Text) = '' then
  begin
    Application.MessageBox('订舱单不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(jhdtype.Text) = '' then
  begin
    Application.MessageBox('类型不能为空!', '提示', 0);
    Exit;
  end;

  if Trim(KHName.Text) = '' then
  begin
    Application.MessageBox('客户不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('C4BGQty', Null, []) then
  begin
    Application.MessageBox('数量不能为空!', '提示', 0);
    Exit;
  end;

  ToolBar1.SetFocus;
  if SaveCKData() then
  begin
    Application.MessageBox('保存成功!', '提示', 0);
    //ModalResult:=1;
    Exit;
  end;
end;

procedure TfrmJHDInPut.ToolButton2Click(Sender: TObject);
var
  i: Integer;
begin
  //CopyAddRowCDS(CDS_Sub);
  {with CDS_Sub do
  begin
    Edit;
    FieldByName('BGID').Value:=Null;
    FieldByName('BSID').Value:=Null;
    Post;
  end; }


  frmProductOrderList_Sel := TfrmProductOrderList_Sel.Create(self);
  with frmProductOrderList_Sel do
  begin
    if showmodal = 1 then
    begin
      while frmProductOrderList_Sel.Order_Main.Locate('SSel', True, []) do
      begin
        Self.CDS_Sub.Append;
        i := CDS_Sub.RecordCount;
        Self.CDS_Sub.FieldByName('XHInt').Value := i + 1;
        Self.CDS_Sub.FieldByName('XHNO').Value := i + 1;
        Self.CDS_Sub.FieldbyName('C6BGPrice').Value := 0;
//        Self.CDS_Sub.FieldbyName('Money').Value := 0;
        Self.CDS_Sub.fieldbyname('orderno').Value := Order_Main.fieldbyname('Orderno').asstring;
        Self.CDS_Sub.fieldbyname('FromMainId').Value := Order_Main.fieldbyname('MainId').asstring;
        Self.CDS_Sub.fieldbyname('C3BGNameEng').Value := Order_Main.fieldbyname('YWNAME').asstring;
        Self.CDS_Sub.fieldbyname('C3BGName').Value := Order_Main.fieldbyname('MPRTCODENAME').asstring;
        Self.CDS_Sub.fieldbyname('YSFuKuan').Value := Order_Main.fieldbyname('MPRTMF').asstring;
        Self.CDS_Sub.fieldbyname('YSKeZhong').Value := Order_Main.fieldbyname('MPRTKZ').asstring;
        Self.CDS_Sub.fieldbyname('YSChenFen').Value := Order_Main.fieldbyname('MPRTCF').asstring;
        Self.CDS_Sub.fieldbyname('C4BGQty').Value := Order_Main.fieldbyname('PRTORDERQTY').ASFLOAT;

        Self.CDS_Sub.fieldbyname('C5BGUnit').Value := Order_Main.fieldbyname('orderunit').asstring;

        Self.CDS_Sub.fieldbyname('ZZFF').Value := Order_Main.fieldbyname('BPBigType').asstring;
        Self.CDS_Sub.fieldbyname('ZDDATE').Value := Order_Main.fieldbyname('filltime').AsDateTime;
        Self.CDS_Sub.fieldbyname('GYLX').Value := Order_Main.fieldbyname('JGType').asstring;

        Self.CDS_Sub.fieldbyname('KuanNo').Value := Order_Main.fieldbyname('SCSKX').asstring;
        Self.CDS_Sub.fieldbyname('HXCODE').Value := Order_Main.fieldbyname('SCSHX').asstring;
        Self.CDS_Sub.fieldbyname('JSUNIT').Value := '件';
        Self.CDS_Sub.fieldbyname('WL').Value := '平纹';
        Self.CDS_Sub.fieldbyname('sj').Value := '是';

        Self.CDS_Sub.fieldbyname('CYQTY').Value := 0;
        Self.CDS_Sub.fieldbyname('CYFEE').Value := 0;

        Self.CDS_Sub.Post;
        frmProductOrderList_Sel.Order_Main.Delete;
      end;
    end;
    free;
  end;
  SetXH();
end;

procedure TfrmJHDInPut.ToolButton3Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if Trim(CDS_Sub.fieldbyname('JHSID').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update JHD_SUB Set SValid=''N'',SEditer=''' + Trim(DName) + ''',SEditTime=getdate() ');
      sql.Add(' where JHSID=''' + Trim(CDS_Sub.fieldbyname('JHSID').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPdate JHD_MAIN Set ');
      sql.Add(' C7BGMoneyHZ=(select Sum(C7BGMoney) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E1BZQtyHZ=(select Sum(E1BZQty) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E2ChiMaQtyHZ=(select Sum(E2ChiMaQty) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E3MaoZHZ=(select Sum(E3MaoZ) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(',E4JingZHZ=(select Sum(E4JingZ) from JHD_SUB A where A.JHID=JHD_MAIN.JHID and A.SValid=''Y'' )');
      sql.Add(' where JHID=''' + Trim(CDS_Sub.fieldbyname('JHID').AsString) + '''');
      ExecSQL;
    end;
  end;
  CDS_Sub.Delete;
  JSJE();
end;

procedure TfrmJHDInPut.v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := '';
      flagname := '';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('C3BGName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select Top 1 * from JYOrder_BaoGuan_Sub where C3BGName=''' + Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
          sql.add(' and isnull(C2HSNO,'''')<>'''' ');
          sql.Add(' order by SFillTime desc');
          Open;
        end;
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('C2HSNO').Value := Trim(ADOQueryTemp.fieldbyname('C2HSNO').asstring);
          FieldByName('C3BGNameEng').Value := Trim(ADOQueryTemp.fieldbyname('C3BGNameEng').asstring);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'YSChenFen';
      flagname := '成分含量';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YSChenFen').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.v1Column16PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'YSPinPai';
      flagname := '品牌';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YSPinPai').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.v1Column17PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'YSShengChanShang';
      flagname := '生产商';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('YSShengChanShang').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.v1Column3PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FName, FPrice, FQty, FBaoGangFee, FCYQTY: string;
begin
  FName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName(FName).Value := mvalue;
    Post;
  end;
  FPrice := Trim(CDS_Sub.fieldbyname('C6BGPrice').AsString);
  FQty := Trim(CDS_Sub.fieldbyname('C4BGQty').AsString);
  FCYQTY := Trim(CDS_Sub.fieldbyname('CYQTY').AsString);
  if Trim(FPrice) = '' then
  begin
    FPrice := '0';
  end;
  if Trim(FQty) = '' then
  begin
    FQty := '0';
  end;
  if Trim(FCYQTY) = '' then
  begin
    FCYQTY := '0';
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('C7BGMoney').Value := RoundFloat(StrToFloat(FPrice) * StrToFloat(FQty), 2);
    FieldByName('CYFEE').Value := RoundFloat(StrToFloat(FPrice) * StrToFloat(FCYQTY), 2);
    Post;
  end;
  JSJE();
end;

procedure TfrmJHDInPut.ToolButton1Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  OneKeyPost(Tv1, CDS_Sub);
end;

procedure TfrmJHDInPut.ToolButton4Click(Sender: TObject);
var
  fsj: string;
begin
  with CDS_JJ do
  begin
    Append;
    FieldByName('FYTYPE').Value := '减免';
    FieldByName('FYMONEY').Value := 0;
    post;
  end;
end;

procedure TfrmJHDInPut.v1ZZJGouPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'ZZJGou';
      flagname := '组织结构';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ZZJGou').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'E5MaiTou';
      flagname := '唛头';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('E5MaiTou').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.TCXLJClick(Sender: TObject);
begin
  if not Assigned(DataLink_DDMD) then
    DataLink_DDMD := TDataLink_DDMD.Create(Application);
  try
    with DataLink_DDMD.ADOLink do
    begin
      //if not Connected then
      begin
        Connected := false;
        ConnectionString := DConString;
        LoginPrompt := false;
        Connected := true;
      end;
    end;
  except
    application.MessageBox('数据库连接失败！', '错误', mb_Ok + MB_ICONERROR);
  end;
end;

procedure TfrmJHDInPut.TOCOUNTRYBtnClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin

      flag := Copy(fsj, 1, FWZ - 1);
//         ShowMessage(flag);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if flag = 'TOCOUNTRY' then
      begin
        fnote := True;
        V1Note.Caption := '中文名称';
        V1Name.Caption := '英文名称';
      end
      else if (flag = 'LCTOPlace') or (flag = 'LCFromPlace') or (flag = 'YSFS') then
      begin
        fnote := True;
        V1Note.Caption := '备注';
        V1Name.Caption := '名称';
//        V1Name.Caption := '英文名称';
      end
      else if (flag = 'SHFS') then
      begin
        fnote := True;
        V1Note.Caption := '天数';
        V1Name.Caption := '收汇方式';
//        V1Name.Caption := '英文名称';
      end
      else
      begin
        fnote := false;
      end;
//      if (flag = 'B6ChuYunGang') or (flag = 'B7DaoHuoGang') or (flag = 'ZMXingZhi')  then
//      begin
//        fnote := True;
//        V1Note.Caption := '备注';
////        V1Name.Caption := '英文名称';
//      end
//      else
//      begin
//        fnote := false;
//      end;

      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if (flag = 'SHFS') then
        begin
          days.Text := Trim(ClientDataSet1.fieldbyname('note').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmJHDInPut.YWLXDropDown(Sender: TObject);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM SY_User WHERE Udept LIKE ''%客服%'' ');

    Open;
  end;
  YWY.Items.Clear;
  while not ADOQueryTemp.eof do
  begin
    YWY.Items.Add(Trim(ADOQueryTemp.fieldbyname('username').AsString));
    ADOQueryTemp.next;
  end;
end;

procedure TfrmJHDInPut.ZORDERNOBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin
//        self.khcode.Text := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
        self.KHName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmJHDInPut.DCNOBtnClick(Sender: TObject);
begin
  try
    frmDCDList_Sel := TfrmDCDList_Sel.Create(Application);
    with frmDCDList_Sel do
    begin

      if ShowModal = 1 then
      begin
//        self.TOCOUNTRY.Text := Trim(Order_Main.fieldbyname('TOCOUNTRY').AsString);
        self.DCNO.Text := Trim(Order_Main.fieldbyname('DCNO').AsString);
        Self.ZhuMaiTou.Text := Trim(Order_Main.fieldbyname('ZhuMaiTou').AsString);
      end;
    end;
  finally
    frmDCDList_Sel.Free;
  end;
end;

procedure TfrmJHDInPut.Tv1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := tfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin

      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          Edit;
          fieldbyname('gcdm').Value := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          fieldbyname('gcname').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
          fieldbyname('gcaddress').Value := Trim(CDS_HZ.fieldbyname('Coaddress').AsString);
        end;

      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmJHDInPut.Tv1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'zzff';
      flagname := '织造方法';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('zzff').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.Tv1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GRADE';
      flagname := '等级';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('GRADE').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmJHDInPut.Tv1Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GYLX';
      flagname := '工艺类型';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('gylx').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.Tv1Column9PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'JSUNIT';
      flagname := '件数单位';
      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          edit;
          fieldbyname('JSUNIT').AsString := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.Tv1Column7PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FName, FPrice, FQty, FBaoGangFee: string;
begin
  FName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
  mvalue := TcxTextEdit(Sender).EditingText;
  if Trim(mvalue) = '' then
  begin
    mvalue := '0';
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName(FName).Value := mvalue;
    Post;
  end;
  JSJE();
end;

procedure TfrmJHDInPut.Tv1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := tfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin

      if ShowModal = 1 then
      begin
        with CDS_Sub do
        begin
          Edit;
          fieldbyname('gcdm').Value := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
          fieldbyname('gcname').Value := Trim(CDS_HZ.fieldbyname('CoName').AsString);
          fieldbyname('gcaddress').Value := Trim(CDS_HZ.fieldbyname('Coaddress').AsString);
        end;

      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmJHDInPut.KHNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin

        self.KHName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmJHDInPut.A4FPNOBtnClick(Sender: TObject);
var
  i: Integer;
begin
  try
    frmCHListsel2 := tfrmCHListsel2.Create(Application);
    with frmCHListsel2 do
    begin
      if ShowModal = 1 then
      begin

        Self.A4FPNO.Text := Trim(CDS_Main.fieldbyname('A4FPNO').AsString);
        Self.DCNO.Text := Trim(CDS_Main.fieldbyname('DCNO').AsString);
        Self.OrdConPrcNote.Text := Trim(CDS_Main.fieldbyname('OrdConPrcNote').AsString);
        Self.B6ChuYunGang.Text := Trim(CDS_Main.fieldbyname('B6ChuYunGang').AsString);
        Self.DAYS.Text := Trim(CDS_Main.fieldbyname('SHdays').AsString);
        Self.ZhuMaiTou.Text := Trim(CDS_Main.fieldbyname('maitou').AsString);

//        Self.FKR.Text := Trim(CDS_Main.fieldbyname('TDShouHuoPerson').AsString);
        Self.FKR.Text := Trim(CDS_Main.fieldbyname('TDShouHuoPerson').AsString);
//        Self.FKR.Text := Self.FKR.Text + #13 + Trim(CDS_Main.fieldbyname('COADDRESS').AsString);

        Self.SHFS.Text := Trim(CDS_Main.fieldbyname('SHFS').AsString);
        Self.F3BaoFee.Text := Trim(CDS_Main.fieldbyname('F3BaoFee').AsString);
        Self.F2YunFee.Text := Trim(CDS_Main.fieldbyname('F2YunFee').AsString);
        Self.B7DaoHuoGang.Text := Trim(CDS_Main.fieldbyname('B7DaoHuoGang').AsString);
        Self.BGTAITOU.Text := Trim(CDS_Main.fieldbyname('BGTAITOU').AsString);
        Self.ZMXingZhi.Text := Trim(CDS_Main.fieldbyname('ZMXingZhi').AsString);
        Self.KHName.Text := Trim(CDS_Main.fieldbyname('KHName').AsString);

//        Self.chuandate.DateTime := CDS_Main.fieldbyname('chuandate').AsDateTime;
        Self.YWY.Text := Trim(CDS_Main.fieldbyname('YWY').AsString);

        Self.SellNOTE.Text := Trim(CDS_Main.fieldbyname('SellNOTE').AsString);

        Self.TOCOUNTRY.Text := Trim(CDS_Main.fieldbyname('TOCOUNTRY').AsString);
        Self.A6PONO.Text := Trim(CDS_Main.fieldbyname('A6PONO').AsString);

        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;

//          SQL.Add('with c1 as(select sum(qty)qty,price,SUM(D.MXMONEY)MXMONEY,isnull(MXOrderNo,'''')MXOrderNo,');
//          SQL.Add('isnull(CPCODE,'''')CPCODE,isnull(dcno,'''')dcno');
//          SQL.Add(',STUFF(( SELECT  '','' +convert(VARCHAR, ltrim(rtrim(YFsID))) FROM YF_MONEY_CR_SUB t inner join ');
//          SQL.Add('YF_MONEY_CR r on t.YFID=r.YFID   ');
//          SQL.Add(' where isnull(t.MXOrderNo,'''')=isnull(d.MXOrderNo,'''')  and isnull(r.dcno,'''')=isnull(c.dcno,'''') ');
//          SQL.Add('and isnull(t.CPCODE,'''')=isnull(d.CPCODE,'''') ');
//          SQL.Add(' FOR XML PATH('''')), 1, 1, '''') AS YFSID');
//          SQL.Add(',STUFF(( SELECT  '','' +convert(VARCHAR, ltrim(rtrim(yfpzno))) FROM YF_MONEY_CR_SUB t inner join ');
//          SQL.Add('YF_MONEY_CR r on t.YFID=r.YFID   ');
//          SQL.Add(' where isnull(t.MXOrderNo,'''')=isnull(d.MXOrderNo,'''')  and isnull(r.dcno,'''')=isnull(c.dcno,'''') ');
//          SQL.Add('and isnull(t.CPCODE,'''')=isnull(d.CPCODE,'''') ');
//          SQL.Add(' FOR XML PATH('''')), 1, 1, '''') AS yfpzno');
//          SQL.Add(' from YF_MONEY_CR_SUB d  inner join YF_MONEY_CR c on c.YFID=d.YFID  ');
//          SQL.Add(' where CRtype=''应收款登记''  group by price,isnull(MXOrderNo,''''),isnull(CPCODE,'''') ,isnull(dcno,'''') )');
//          SQL.Add(' select A.*,e.*  FROM JYOrder_BaoGuan_SUB A INNER  JOIN JYOrder_BaoGuan_MAIN B ON A.BGID=B.BGID');
//          SQL.Add(' INNER JOIN c1 e ON e.DCNO=B.DCNO  AND e.MXORDERNO=A.ORDERNO AND e.CPCODE=A.C3BGNameEng');
//          SQL.Add('WHERE A.BGID=' + QuotedStr(CDS_Main.fieldbyname('BGID').AsString));
//          SQL.Add('select sum(qty)qty,price,SUM(D.MXMONEY)MXMONEY,isnull(MXOrderNo,'''')MXOrderNo,');
//          SQL.Add('isnull(CPCODE,'''')CPCODE,isnull(dcno,'''')dcno');
//          SQL.Add(',STUFF(( SELECT  '','' +convert(VARCHAR, ltrim(rtrim(YFsID))) FROM YF_MONEY_CR_SUB t inner join ');
//          SQL.Add('YF_MONEY_CR r on t.YFID=r.YFID   ');
//          SQL.Add(' where isnull(t.MXOrderNo,'''')=isnull(d.MXOrderNo,'''')  and isnull(r.dcno,'''')=isnull(c.dcno,'''') ');
//          SQL.Add('and isnull(t.CPCODE,'''')=isnull(d.CPCODE,'''') ');
//          SQL.Add(' FOR XML PATH('''')), 1, 1, '''') AS YFSID');
//          SQL.Add(',STUFF(( SELECT  '','' +convert(VARCHAR, ltrim(rtrim(yfpzno))) FROM YF_MONEY_CR_SUB t inner join ');
//          SQL.Add('YF_MONEY_CR r on t.YFID=r.YFID   ');
//          SQL.Add(' where isnull(t.MXOrderNo,'''')=isnull(d.MXOrderNo,'''')  and isnull(r.dcno,'''')=isnull(c.dcno,'''') ');
//          SQL.Add('and isnull(t.CPCODE,'''')=isnull(d.CPCODE,'''') ');
//          SQL.Add(' FOR XML PATH('''')), 1, 1, '''') AS yfpzno');
//          SQL.Add(' from YF_MONEY_CR_SUB d  inner join YF_MONEY_CR c on c.YFID=d.YFID  ');
//          SQL.Add(' where CRtype=''应收款登记''    AND DCNO=' + QuotedStr(CDS_Main.fieldbyname('DCNO').AsString));
//
//          SQL.Add('group by price,isnull(MXOrderNo,''''),isnull(CPCODE,'''') ,isnull(dcno,'''') ');
//         ShowMessage(sql.Text);

          SQL.Add('EXEC P_Do_CHQDCWHZ @DCNO=' + QuotedStr(CDS_Main.fieldbyname('DCNO').AsString));
          Open;
        end;
        with ADOQueryTemp do
        begin
          First;
          while not Eof do
          begin
            with CDS_Sub do
            begin
              Append;
              i := CDS_Sub.RecordCount;
              Self.CDS_Sub.FieldByName('XHInt').Value := i + 1;
              Self.CDS_Sub.FieldByName('XHNO').Value := i + 1;
//              CDS_Sub.fieldbyname('FROMYFSID').AsString := ADOQueryTemp.fieldbyname('YFSID').AsString;
//              CDS_Sub.fieldbyname('FROMYFPZNO').AsString := ADOQueryTemp.fieldbyname('YFPZNO').AsString;
//
//              CDS_Sub.fieldbyname('orderno').AsString := ADOQueryTemp.fieldbyname('MXORDERNO').AsString;
//              CDS_Sub.fieldbyname('C3BGName').AsString := ADOQueryTemp.fieldbyname('C3BGName').AsString;
//              CDS_Sub.fieldbyname('C3BGNameEng').AsString := ADOQueryTemp.fieldbyname('C3BGNameEng').AsString;
//              CDS_Sub.fieldbyname('YSChenFen').AsString := ADOQueryTemp.fieldbyname('YSChenFen').AsString;
//              CDS_Sub.fieldbyname('YSKeZhong').AsString := ADOQueryTemp.fieldbyname('YSKeZhong').AsString;
//              CDS_Sub.fieldbyname('YSFuKuan').AsString := ADOQueryTemp.fieldbyname('YSFuKuan').AsString;
//              CDS_Sub.fieldbyname('C4BGQty').AsString := ADOQueryTemp.fieldbyname('QTY').AsString;
//              CDS_Sub.fieldbyname('C6BGPrice').AsString := ADOQueryTemp.fieldbyname('Price').AsString;
//              CDS_Sub.fieldbyname('C7BGMoney').AsString := ADOQueryTemp.fieldbyname('MXMONEY').AsString;
//              CDS_Sub.fieldbyname('E3MaoZ').AsString := ADOQueryTemp.fieldbyname('E3MaoZ').AsString;
//              CDS_Sub.fieldbyname('E4JingZ').AsString := ADOQueryTemp.fieldbyname('E4JingZ').AsString;
//              CDS_Sub.fieldbyname('BGTJ').AsString := ADOQueryTemp.fieldbyname('BGTJ').AsString;


              CDS_Sub.fieldbyname('FROMYFSID').AsString := ADOQueryTemp.fieldbyname('YFSID').AsString;
              CDS_Sub.fieldbyname('FROMYFPZNO').AsString := ADOQueryTemp.fieldbyname('YFPZNO').AsString;

              CDS_Sub.fieldbyname('orderno').AsString := ADOQueryTemp.fieldbyname('MXORDERNO').AsString;
              CDS_Sub.fieldbyname('C3BGName').AsString := ADOQueryTemp.fieldbyname('CPCODE').AsString;
              CDS_Sub.fieldbyname('C3BGNameEng').AsString := ADOQueryTemp.fieldbyname('SCSEName').AsString;
              CDS_Sub.fieldbyname('YSChenFen').AsString := ADOQueryTemp.fieldbyname('SCSCF').AsString;
              CDS_Sub.fieldbyname('YSKeZhong').AsString := ADOQueryTemp.fieldbyname('SCSKZ').AsString;
              CDS_Sub.fieldbyname('YSFuKuan').AsString := ADOQueryTemp.fieldbyname('SCSMF').AsString;
              CDS_Sub.fieldbyname('C4BGQty').AsString := ADOQueryTemp.fieldbyname('QTY').AsString;
              CDS_Sub.fieldbyname('C6BGPrice').AsString := ADOQueryTemp.fieldbyname('Price').AsString;
              CDS_Sub.fieldbyname('C7BGMoney').AsString := ADOQueryTemp.fieldbyname('MXMONEY').AsString;
              CDS_Sub.fieldbyname('E3MaoZ').AsString := ADOQueryTemp.fieldbyname('FHKgQty').AsString;
              CDS_Sub.fieldbyname('E4JingZ').AsString := ADOQueryTemp.fieldbyname('FHKgnetQty').AsString;
              CDS_Sub.fieldbyname('bgcolor').AsString := ADOQueryTemp.fieldbyname('CPCOLOR').AsString;
              CDS_Sub.fieldbyname('bgecolor').AsString := ADOQueryTemp.fieldbyname('SCSECOLOR').AsString;
              CDS_Sub.fieldbyname('E1BZUNIT').AsString := ADOQueryTemp.fieldbyname('SCSCurrency').AsString;
              CDS_Sub.fieldbyname('C5BGUnit').AsString := ADOQueryTemp.fieldbyname('SCSUnit').AsString;
              CDS_Sub.fieldbyname('PS').AsString := ADOQueryTemp.fieldbyname('PS').AsString;
              CDS_Sub.fieldbyname('bs').AsString := ADOQueryTemp.fieldbyname('bs').AsString;

              CDS_Sub.fieldbyname('KuanNo').AsString := ADOQueryTemp.fieldbyname('SCSKX').AsString;
              CDS_Sub.fieldbyname('HXCODE').AsString := ADOQueryTemp.fieldbyname('SCSHX').AsString;

              CDS_Sub.fieldbyname('hscode').AsString := ADOQueryTemp.fieldbyname('hscode').AsString;

//              CDS_Sub.fieldbyname('BGTJ').AsString := ADOQueryTemp.fieldbyname('BGTJ').AsString;

              Post;

            end;
            Next;
          end;
        end;

      end;
    end;
  finally
    frmCHListsel2.Free;
  end;
  JSJE();
  SetXH();

end;

procedure TfrmJHDInPut.TV2CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmJHDInPut.ToolButton6Click(Sender: TObject);
begin
  if CDS_JJ.IsEmpty then
    Exit;
  if Trim(CDS_JJ.fieldbyname('JJID').AsString) <> '' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT * FROM YF_MONEY_CR  ');
      sql.Add(' where YFID=''J''+ ''' + Trim(CDS_JJ.fieldbyname('JJID').AsString) + '''');
      SQL.Add('AND STATUS=''1''');
      OPEN;
    end;
    if ADOQueryTemp.IsEmpty = False then
    begin
      Application.MessageBox('财务已审核，禁止删除!', '提示', 0);
      Exit;
    end;

    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('DELETE JHD_JJ ');
      sql.Add(' where JJID=''' + Trim(CDS_JJ.fieldbyname('JJID').AsString) + '''');

      sql.Add('DELETE YF_MONEY_CR  ');
      sql.Add(' where YFID=''J'' +''' + Trim(CDS_JJ.fieldbyname('JJID').AsString) + '''');
      sql.Add('DELETE YF_MONEY_CR_SUB  ');
      sql.Add(' where YFID=''J'' +''' + Trim(CDS_JJ.fieldbyname('JJID').AsString) + '''');
      ExecSQL;
    end;

  end;
  CDS_JJ.Delete;
  JSJE();
end;

procedure TfrmJHDInPut.ToolButton5Click(Sender: TObject);
begin
  with CDS_JJ do
  begin
    Append;
    FieldByName('FYTYPE').Value := '加收';
    FieldByName('FYMONEY').Value := 0;
    post;
  end;
end;

procedure TfrmJHDInPut.cxGridDBColumn3PropertiesEditValueChanged(Sender: TObject);
begin
  JSJE();
end;

procedure TfrmJHDInPut.YSDJChange(Sender: TObject);
begin
  JSJE();
end;

procedure TfrmJHDInPut.TV2Column2PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FName, FBILI, FQTY, FMONEY: string;
begin
//  FName := Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
//  mvalue := TcxTextEdit(Sender).EditingText;
//  if Trim(mvalue) = '' then
//  begin
//    mvalue := '0';
//  end;
//  with CDS_JJ do
//  begin
//    Edit;
//    FieldByName(FName).Value := mvalue;
//    Post;
//  end;
//
//  if TV1.DataController.Summary.FooterSummaryValues[1] <> NULL then
//    FQTY := TV1.DataController.Summary.FooterSummaryValues[1]
//  else
//    FQTY := '0';
//  FBILI := Trim(CDS_JJ.fieldbyname('BILI').AsString);
//
//  if Trim(FBILI) = '' then
//  begin
//    FBILI := '0';
//  end;
//  if Trim(FQTY) = '' then
//  begin
//    FQTY := '0';
//  end;
//
//  with CDS_JJ do
//  begin
//    Edit;
//    FieldByName('FYMONEY').Value := StrToFloat(FBILI) * StrToFloat(FQTY) / 100;
//
//    Post;
//  end;
  JSJE();
end;

procedure TfrmJHDInPut.ToolButton7Click(Sender: TObject);
begin
  if Panel3.Visible = true then
  begin
    Panel3.Visible := false;
  end
  else
  begin
    Panel3.Visible := True;
  end;

end;

procedure TfrmJHDInPut.JDDATEBtnClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin

      flag := Copy(fsj, 1, FWZ - 1);
//         ShowMessage(flag);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      TBAdd.Visible := False;
      TBDel.Visible := False;
      TBEdit.Visible := False;
      TBSave.Visible := False;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.SHFSBtnClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin

      flag := Copy(fsj, 1, FWZ - 1);
//         ShowMessage(flag);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      TBAdd.Visible := False;
      TBDel.Visible := False;
      TBEdit.Visible := False;
      TBSave.Visible := False;
      if flag = 'TOCOUNTRY' then
      begin
        fnote := True;
        V1Note.Caption := '中文名称';
        V1Name.Caption := '英文名称';
      end
      else if (flag = 'LCTOPlace') or (flag = 'LCFromPlace') or (flag = 'YSFS') then
      begin
        fnote := True;
        V1Note.Caption := '备注';
        V1Name.Caption := '名称';
//        V1Name.Caption := '英文名称';
      end
      else if (flag = 'SHFS') then
      begin
        fnote := True;
        V1Note.Caption := '天数';
        V1Name.Caption := '收汇方式';
//        V1Name.Caption := '英文名称';
      end
      else
      begin
        fnote := false;
      end;
//      if (flag = 'B6ChuYunGang') or (flag = 'B7DaoHuoGang') or (flag = 'ZMXingZhi')  then
//      begin
//        fnote := True;
//        V1Note.Caption := '备注';
////        V1Name.Caption := '英文名称';
//      end
//      else
//      begin
//        fnote := false;
//      end;

      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if (flag = 'SHFS') then
        begin
          days.Text := Trim(ClientDataSet1.fieldbyname('note').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.Tv1Column14PropertiesEditValueChanged(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GRADE';
      flagname := '等级';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('GRADE').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJHDInPut.ToolButton8Click(Sender: TObject);
var
  i: Integer;
begin
  if CDS_Sub.IsEmpty = False then
  begin
    CopyAddRowCDS(CDS_Sub);
    with CDS_Sub do
    begin
      Edit;
      i := CDS_Sub.RecordCount;
//      Self.CDS_Sub.FieldByName('XHInt').Value := i + 1;
      Self.CDS_Sub.FieldByName('XHNO').Value := Self.CDS_Sub.FieldByName('XHNO').AsFloat + 0.5;
      FieldByName('JHSID').Value := null;
      post;
    end;
  end
  else
  begin
    Exit;
  end;
  SetXH();
end;

procedure TfrmJHDInPut.Button1Click(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal = 1 then
      begin
//        self.FKR.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);

        self.FKR.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString) + #$d#$a + Trim(CDS_HZ.fieldbyname('COADDRESS').AsString);

//        self.FKR.Text := '1' + #13 + '2';
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmJHDInPut.ToolButton9Click(Sender: TObject);
var
  i: Integer;
begin
  if CDS_Sub.IsEmpty = False then
  begin
    CopyAddRowCDS(CDS_Sub);
    with CDS_Sub do
    begin
      Edit;
      i := CDS_Sub.RecordCount;
//      Self.CDS_Sub.FieldByName('XHInt').Value := i + 1;
      Self.CDS_Sub.FieldByName('XHNO').Value := Self.CDS_Sub.FieldByName('XHNO').AsFloat - 0.5;
      FieldByName('JHSID').Value := null;
      post;
    end;
  end
  else
  begin
    Exit;
  end;
  SetXH();
end;

procedure TfrmJHDInPut.ToolButton10Click(Sender: TObject);
begin

  if CDS_Sub.IsEmpty then
    exit;
  if CDS_Sub.fieldbyname('JHsID').AsString <> '' then
  begin
    try
      ADOQueryCmd.Connection.BeginTrans;
      with CDS_Sub do
      begin

        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          sql.Add('update JHD_SUB SET COLOR= ' + quotedstr(Trim(ColorToString(ColorBox1.Selected))));
          sql.Add('where JHSID =' + quotedstr(trim(CDS_SUB.fieldbyname('JHSID').AsString)));
          execsql;
        end;

        EnableControls;
      end;
      ADOQueryCmd.Connection.CommitTrans;

    except
      ADOQueryCmd.Connection.RollbackTrans;
      application.MessageBox('操作失败！', '提示信息', 0);
    end;
  end;

  with CDS_Sub do
  begin
    Edit;
    FieldByName('color').AsString := ColorToString(ColorBox1.selected);
    Post;
  end;
end;

procedure TfrmJHDInPut.Tv1CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  if AViewInfo.GridRecord.Values[Tv1Column18.Index] <> null then
  begin
    ACanvas.Brush.Color := StringToColor(AViewInfo.GridRecord.Values[Tv1Column18.Index]);
  end;
end;

procedure TfrmJHDInPut.ToolButton11Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    exit;
  if CDS_Sub.fieldbyname('JHsID').AsString <> '' then
  begin
    try
      ADOQueryCmd.Connection.BeginTrans;
      with CDS_Sub do
      begin
        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          sql.Add('update JHD_SUB SET COLOR=NULL');
          sql.Add('where JHSID =' + quotedstr(trim(CDS_SUB.fieldbyname('JHSID').AsString)));
          execsql;
        end;
        EnableControls;
      end;
      ADOQueryCmd.Connection.CommitTrans;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      application.MessageBox('操作失败！', '提示信息', 0);
    end;
  end;

  with CDS_Sub do
  begin
    Edit;
    FieldByName('color').VALUE := NULL;
    Post;
  end;
end;

end.

