unit U_Con_DDXQ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, cxMemo,
  cxRichEdit, ComCtrls, cxContainer, cxTextEdit, cxMaskEdit, cxButtonEdit,
  StdCtrls, ToolWin, DBClient, ADODB, ExtCtrls, BtnEdit, cxCalendar, StrUtils,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxCurrencyEdit, cxGridBandedTableView,
  cxGridDBBandedTableView, cxDropDownEdit, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, cxSplitter, Buttons, commctrl, DateUtils, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

type
  TfrmCon_DDXQ = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ScrollBox1: TScrollBox;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    ADOQueryMain: TADOQuery;
    Label1: TLabel;
    OrderNO: TEdit;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    CustomerNoName: TEdit;
    Label6: TLabel;
    Leader: TEdit;
    Label7: TLabel;
    FILLER: TEdit;
    Label8: TLabel;
    GDY: TEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    GroupBox3: TGroupBox;
    Label9: TLabel;
    JGMoney: TEdit;
    Label10: TLabel;
    SJGFactory: TEdit;
    Label11: TLabel;
    cqts: TEdit;
    Label12: TLabel;
    Label13: TLabel;
    Cqyy: TEdit;
    Label14: TLabel;
    Label15: TLabel;
    Edit5: TEdit;
    Label16: TLabel;
    tpqty: TEdit;
    Label18: TLabel;
    CPS: TEdit;
    Label19: TLabel;
    Zdgs: TEdit;
    Label20: TLabel;
    JCS: TEdit;
    Label22: TLabel;
    cpyy: TEdit;
    Label17: TLabel;
    Ycqr: TEdit;
    Label21: TLabel;
    Edit11: TEdit;
    GroupBox4: TGroupBox;
    Label23: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Edit13: TEdit;
    FPHZ: TEdit;
    SSMONEY: TEdit;
    spl: TEdit;
    FPMONEY: TEdit;
    spk: TEdit;
    GroupBox5: TGroupBox;
    Label29: TLabel;
    Label30: TLabel;
    Label31: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Edit19: TEdit;
    chdate: TEdit;
    ysdate: TEdit;
    SHFS: TEdit;
    SSdate: TEdit;
    GroupBox6: TGroupBox;
    Label35: TLabel;
    Edit25: TEdit;
    Label36: TLabel;
    Edit26: TEdit;
    DLYDATE: TEdit;
    CDS_FP: TClientDataSet;
    DS_FP: TDataSource;
    CDS_CK: TClientDataSet;
    DS_CK: TDataSource;
    Panel1: TPanel;
    cxGrid2: TcxGrid;
    TV3: TcxGridDBTableView;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    TV3Column1: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Label32: TLabel;
    TV3Column2: TcxGridDBColumn;
    Panel2: TPanel;
    Label37: TLabel;
    cxGrid1: TcxGrid;
    TV2: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    CDS_SS: TClientDataSet;
    DS_SS: TDataSource;
    Panel3: TPanel;
    Label38: TLabel;
    cxGrid4: TcxGrid;
    TV4: TcxGridDBTableView;
    V4Column3: TcxGridDBColumn;
    V4Column1: TcxGridDBColumn;
    TV4Column1: TcxGridDBColumn;
    V4Column5: TcxGridDBColumn;
    TV4Column2: TcxGridDBColumn;
    V4Column4: TcxGridDBColumn;
    cxGrid4Level1: TcxGridLevel;
    Panel4: TPanel;
    Label39: TLabel;
    cxGrid3: TcxGrid;
    TV5: TcxGridDBTableView;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridDBColumn13: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    TV5Column1: TcxGridDBColumn;
    CDS_CP: TClientDataSet;
    DS_CP: TDataSource;
    TV5Column2: TcxGridDBColumn;
    TV5Column3: TcxGridDBColumn;
    Image2: TImage;
    Image1: TImage;
    Image3: TImage;
    Image4: TImage;
    TV4Column4: TcxGridDBColumn;
    TV4Column5: TcxGridDBColumn;
    TV4Column6: TcxGridDBColumn;
    TV4Column7: TcxGridDBColumn;
    TV4Column3: TcxGridDBColumn;
    TV3Column3: TcxGridDBColumn;
    TV3Column4: TcxGridDBColumn;
    GroupBox7: TGroupBox;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RadioButton3: TRadioButton;
    SCNOTE: TMemo;
    Label40: TLabel;
    GroupBox8: TGroupBox;
    Label41: TLabel;
    RadioButton4: TRadioButton;
    RadioButton5: TRadioButton;
    RadioButton6: TRadioButton;
    ywnote: TMemo;
    Button1: TButton;
    IdHTTP1: TIdHTTP;
    Button2: TButton;
    ZHJCTIME: TEdit;
    Label42: TLabel;
    GDYNAME: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FPMONEYClick(Sender: TObject);
    procedure TV4DblClick(Sender: TObject);
    procedure SSMONEYClick(Sender: TObject);
    procedure JCSClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TV3DblClick(Sender: TObject);
    procedure TV2DblClick(Sender: TObject);
    procedure CPSClick(Sender: TObject);
    procedure TV5DblClick(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure Image3Click(Sender: TObject);
    procedure Image4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    procedure ControlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ControlMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure ControlMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure InitData();
    procedure InitFP();
    procedure InitSS();
    procedure InitCK();
    procedure InitCP();
    procedure gridkz();
    function SaveData(): Boolean;
    procedure HJ();
    procedure QiPaoShowMessage(h: HWND; text, cap: string; IconType: integer = 1; t: integer = 1000; left: Integer = 0; top: Integer = 0);
    { Private declarations }
  public
    PState, CopyInt: Integer;
    FMainId, FSubid, FFMainId: string;
    FXS: Integer;
    inReposition: boolean;
    oldPos: TPoint;
    canshu1: string;
    { Public declarations }
  end;

var
  frmCon_DDXQ: TfrmCon_DDXQ;
  newh: hwnd;
  FMAINID, Forderno: string;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_UserSel;

{$R *.dfm}

procedure TfrmCon_DDXQ.ControlMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if (Sender is TWinControl) then
  begin
    inReposition := True;
    SetCapture(TWinControl(Sender).Handle);
    GetCursorPos(oldPos);
  end;
end; (*ControlMouseDown*)

procedure TfrmCon_DDXQ.ControlMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
  minWidth = 20;
  minHeight = 20;
var
  newPos: TPoint;
  frmPoint: TPoint;
begin
  if inReposition then
  begin
    with TWinControl(Sender) do
    begin
      GetCursorPos(newPos);
      if ssShift in Shift then
      begin //resize
        Screen.Cursor := crSizeNWSE;
        frmPoint := ScreenToClient(Mouse.CursorPos);
        if frmPoint.X > minWidth then
          Width := frmPoint.X;
        if frmPoint.Y > minHeight then
          Height := frmPoint.Y;
      end
      else //move
      begin
        Screen.Cursor := crSize;
        Left := Left - oldPos.X + newPos.X;
        Top := Top - oldPos.Y + newPos.Y;
        oldPos := newPos;
      end;
    end;
  end;
end; (*ControlMouseMove*)

procedure TfrmCon_DDXQ.ControlMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if inReposition then
  begin
    Screen.Cursor := crDefault;
    ReleaseCapture;
    inReposition := False;
  end;
end; (*ControlMouseUp*)

procedure TfrmCon_DDXQ.HJ();
begin

end;

procedure TfrmCon_DDXQ.gridkz();
var
  i: Integer;
begin
//  with ScrollBox1 do
//  begin
//    for i := 0 to 10 do
//    begin
//      cxGrid[i].visible := False;
//    end;
//  end;
end;

procedure TfrmCon_DDXQ.TBCloseClick(Sender: TObject);
begin
  ModalResult := 1;
  Close;
end;

procedure TfrmCon_DDXQ.InitData();
var
  T1, T2: TDateTime;
  D, H, M, S: Integer;
  Value: Int64;
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;

    sql.Add(' exec P_View_DDQKYLB @mainid=' + quotedstr(trim(FMainId)));
    sql.Add(' ,@orderno=' + quotedstr(trim(Forderno)));

//    ShowMessage(sql.Text);
    Open;
  end;
  SCSHDataNew(ADOTemp, ScrollBox1, 1);
//  DLYDate.Text := ADOTemp.FieldByName('DLYDate').AsString;
//  ZHJCTIME.Text := ADOTemp.FieldByName('ZHJCTIME').AsString;
//  cqts.Text := ADOTemp.FieldByName('cqts').AsString;
//  JCS.Text := ADOTemp.FieldByName('JCS').AsString;
  SCSHDataNew(ADOTemp, GroupBox1, 1);
  SCSHDataNew(ADOTemp, GroupBox2, 1);
  SCSHDataNew(ADOTemp, GroupBox4, 1);
  SCSHDataNew(ADOTemp, GroupBox5, 1);
  if CPS.Text <> '0' then
  begin
    Edit5.Text := FloatToStr(RoundFloat(strtofloatdef(CPS.Text, 0) / strtofloatdef(jcs.Text, 1) * 100, 2));
  end
  else
  begin
    Edit5.Text := '0';
  end;

  if (ysdate.Text <> '') and (SSdate.Text <> '') then
  begin
    T1 := StrToDateTime(ysdate.Text);
    T2 := StrToDateTime(SSdate.Text);

    Value := SecondsBetween(T2, T1);
//    ShowMessage(IntToStr(Value));
    if T1 < T2 then
    begin
      D := Value div SecsPerDay;

      Edit19.Text := IntToStr(D);
    end
    else
    begin
      Edit19.Text := '0';
    end;

  end;

  if trim(ADOTemp.FieldByName('SCKHSTATUS').AsString) = '计入考核' then
  begin
    RadioButton1.Checked := True;
  end
  else if trim(ADOTemp.FieldByName('SCKHSTATUS').AsString) = '待定' then
  begin
    RadioButton2.Checked := True;
  end
  else if trim(ADOTemp.FieldByName('SCKHSTATUS').AsString) = '不计入考核' then
  begin
    RadioButton3.Checked := True;
  end;

  if trim(ADOTemp.FieldByName('ywKHSTATUS').AsString) = '计入考核' then
  begin
    RadioButton4.Checked := True;
  end
  else if trim(ADOTemp.FieldByName('ywKHSTATUS').AsString) = '待定' then
  begin
    RadioButton5.Checked := True;
  end
  else if trim(ADOTemp.FieldByName('ywKHSTATUS').AsString) = '不计入考核' then
  begin
    RadioButton6.Checked := True;
  end;
  SCNOTE.Text := ADOTemp.FieldByName('SCNOTE').AsString;
  Ycqr.Text := ADOTemp.FieldByName('Ycqr').AsString;
  ywNOTE.Text := ADOTemp.FieldByName('ywNOTE').AsString;
  Edit26.Text := ADOTemp.FieldByName('SSMONEY').AsString;
//  FPHZ.Text := ADOTemp.FieldByName('FPHZ').AsString;
//  FPMONEY.Text := ADOTemp.FieldByName('FPMONEY').AsString;
//  SSMONEY.Text := ADOTemp.FieldByName('SSMONEY').AsString;
//  tpqty.Text := ADOTemp.FieldByName('tpqty').AsString;
end;

procedure TfrmCon_DDXQ.InitFP();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;
//    SQL.Add('SELECT *,yqts=(case when YSDATE>=SSDATE then 0 else DATEDIFF(day,YSDATE,SSDATE) end )  FROM (');
//    sql.Add('SELECT A4FPNO,SUM(C4BGQty)C4BGQty,C5BGUnit,C6BGPrice,e1bzunit,SUM(C7BGMoney+ISNULL(CYFEE,0))C7BGMoney   ');
//
//    sql.Add(',SSDATE=(SELECT MAX (CRTIME)  FROM YF_Money_CR D inner join YF_Money_CR_Sub b on D.yfid=b.YFID where  ');
//    SQL.Add('SKtype=''水单'' and MXOrderNo= ' + QuotedStr(Trim(Forderno)));
//    SQL.Add('AND B.SUBWXFPNO=A.A4FPNO)');
//    sql.Add(',CHUANDATE=(SELECT  MAX(CHUANDATE)  FROM JYOrder_BaoGuan_Main D WHERE D.A4FPNO=A.A4FPNO)  ');
//
//    sql.Add(',YSDATE=DATEADD(day,cast (days as int),(SELECT  MAX(CHUANDATE)  FROM JYOrder_BaoGuan_Main D WHERE D.A4FPNO=A.A4FPNO))  ');
//
//    sql.Add(',DZMONEY=(SELECT SUM(ZDZJE)  FROM YF_Money_CR D inner join YF_Money_CR_Sub b on D.yfid=b.YFID where  ');
//    SQL.Add('SKtype=''水单'' and MXOrderNo= ' + QuotedStr(Trim(Forderno)));
//    SQL.Add('AND B.SUBWXFPNO=A.A4FPNO)');
//    SQL.Add('FROM JHD_Main A INNER JOIN JHD_SUB B ON A.JHID=B.JHID  ');
//    SQL.Add('WHERE  orderno=' + QuotedStr(Trim(Forderno)));
//
//    SQL.Add('GROUP BY A4FPNO,C5BGUnit,C6BGPrice,e1bzunit,DAYS');
//    SQL.Add(')AA');

    sql.Add(' exec P_VIEW_DDQKYLB_MX_FP  ');
    sql.Add(' @orderno=' + quotedstr(trim(Forderno)));

//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_FP);
  SInitCDSData20(ADOTemp, CDS_FP);
end;

procedure TfrmCon_DDXQ.InitCP();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;

    sql.Add('SELECT *,CPKGQTY=(SELECT SUM(MJMAOZ) FROM WFB_MJJY B WHERE B.APID=A.SPID )  ');
    SQL.Add(',CPQTY=(SELECT SUM(MJLEN) FROM WFB_MJJY B WHERE B.APID=A.SPID )');
    SQL.Add(',CPyQTY=(SELECT SUM(MJyLEN) FROM WFB_MJJY B WHERE B.APID=A.SPID )');
    sql.Add(' FROM CK_SXPB_CR  A WHERE  ORDMainIdCK=' + QuotedStr(Trim(FMainId)));
    SQL.Add('AND CKNAME=''待检布'' and crflag=''出库''');
    SQL.Add('AND ISNULL(CPYY,'''')<>''''');
    SQL.Add('ORDER BY CRTIME');
//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_CP);
  SInitCDSData20(ADOTemp, CDS_CP);
end;

procedure TfrmCon_DDXQ.InitCK();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;

//    sql.Add('SELECT A.*,CWPRICE=(SELECT PRICE FROM YF_Money_CR_Sub B WHERE B.YFPZNO=A.SPID)    ');
//    SQL.Add(',MXMONEY=(SELECT MXMONEY FROM YF_Money_CR_Sub B WHERE B.YFPZNO=A.SPID) ');
//    sql.Add('FROM CK_SXPB_CR A WHERE  ORDMainIdRK=' + QuotedStr(Trim(FMainId)));
//
//    SQL.Add('AND CKNAME=''待检布'' and crflag=''入库''');
//    SQL.Add('ORDER BY CRTIME');

    SQL.ADD('SELECT *,B.QTYUNIT AS QTYUNIT2,CRType2=(SELECT CRTYPE FROM CK_SXPB_CR c where c.spid=b.YFPZNO)');

    sql.Add('  from YF_Money_CR A INNER JOIN YF_Money_CR_Sub B ON A.YFID=B.YFID');
    SQL.ADD(' WHERE   CRFlag=''应付付'' AND MXOrderNo=' + QuotedStr(Trim(Forderno)));
    sql.Add(' and CHARINDEX(''DH'', YFPZNO)<=0');
//    sql.Add(' ,@orderno=' + quotedstr(trim(Forderno)));
//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_CK);
  SInitCDSData20(ADOTemp, CDS_CK);
end;

procedure TfrmCon_DDXQ.InitSS();
begin
  with ADOTemp do
  begin
    Close;
    sql.Clear;

    sql.Add('SELECT * FROM YF_Money_CR A inner join YF_Money_CR_Sub b on a.yfid=b.YFID where  ');
    SQL.Add('SKtype=''水单'' and MXOrderNo= ' + QuotedStr(Trim(Forderno)));

    Open;
  end;
  SCreateCDS20(ADOTemp, CDS_SS);
  SInitCDSData20(ADOTemp, CDS_SS);
end;

procedure TfrmCon_DDXQ.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmCon_DDXQ.SaveData(): Boolean;
begin

end;

procedure TfrmCon_DDXQ.QiPaoShowMessage(h: HWND; text, cap: string; IconType: integer = 1; t: integer = 1000; left: Integer = 0; top: Integer = 0);
var
  r: TRect;                       //是一个记录（Record），保存了矩形的（左上角右下角两个点）4个坐标或2个点的值。
  hTooltip: Cardinal;    //Cardinal是无符号32位整数 ，取值0到4294967295范围。
  ti: TToolInfo;
 ///////////////////////----------参数说明---------------------//////////////////////

//h:窗体中控件的句柄（用在某个控件上提示消息）（要调用的控件句柄）

//text:要提示的文本

//cap:提示框上的标题

//IconType:提示框上显示的图标（共三个值。1、2、3分别为提示、警告、错误s）

//t:消息停留的时间(以毫秒计算)

//left: 消息框偏离控件的左距离，设为0则表示没有

//top: 消息框偏离控件的顶距离，设为0则表示没有
begin
  hTooltip := CreateWindow('Tooltips_Class32', nil, $40, 0, 0, 0, 0, 0, 0, hInstance, nil);
  if hTooltip <> 0 then
  begin
    SetWindowPos(hTooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE);  //让气泡在最前面
    ti.cbSize := SizeOf(TToolInfo);
    ti.uFlags := TTF_IDISHWND or TTF_TRACK;
    ti.hInst := hInstance;
    ti.lpszText := pchar(text);
    SendMessage(hTooltip, TTM_ADDTOOL, 0, Integer(@ti));
    if (IconType > 3) or (IconType < 0) then
      IconType := 0;
    SendMessage(hTooltip, WM_USER + 32, IconType, Integer(pchar(cap)));
    GetWindowRect(h, r);             //获取指定控件的坐标,R.Right 、R.Left、R.Bottom、R.Top
    r.Left := r.Left - left;
    r.Top := r.Top - top;

 // 定义气泡位置
    SendMessage(hTooltip, TTM_TRACKPOSITION, 0, MAKELONG((r.Right - r.Left) div 2 + r.Left, (r.Bottom - r.Top) div 2 + r.Top));
    SendMessage(hTooltip, TTM_TRACKACTIVATE, Integer(True), Integer(@ti));
    Sleep(t);
    DestroyWindow(hTooltip);
  end;
end;

procedure TfrmCon_DDXQ.FPMONEYClick(Sender: TObject);
begin
  if panel3.Visible = FALSE then
  begin
    panel3.Visible := True;
//    cxGrid1.Visible := False;
//    gridkz();
//    cxGrid4.Visible := True;
//    cxGrid1.Visible := False;

    panel3.BringToFront();

    InitFP();
  end
  else
  begin
//    control.SetToBack();
    panel3.SendToBack();
    panel3.Visible := FALSE
  end;

end;

procedure TfrmCon_DDXQ.TV4DblClick(Sender: TObject);
begin
  Panel3.Visible := False;
end;

procedure TfrmCon_DDXQ.SSMONEYClick(Sender: TObject);
begin
//  if PANEL2.Visible = FALSE then
//  begin
//    PANEL2.Visible := True;
//    PANEL2.BringToFront();
//    InitSS();
//  end
//  else
//  begin
//    PANEL2.SendToBack();
//    PANEL2.Visible := FALSE
//  end;
end;

procedure TfrmCon_DDXQ.JCSClick(Sender: TObject);
begin
  if (canshu1 = '业务') or (canshu1 = '组长') or (Trim(DName) = '蔡列娜') then
    Exit;
  if PANEL1.Visible = FALSE then
  begin
//    cxGrid4.Visible := True;
//    cxGrid1.Visible := False;
//    gridkz();
    PANEL1.Visible := True;
    PANEL1.BringToFront();
    InitCK();
  end
  else
  begin
    PANEL1.SendToBack();
    PANEL1.Visible := FALSE
  end;
end;

procedure TfrmCon_DDXQ.FormCreate(Sender: TObject);
begin
//  OrderNO.OnMouseDown := ControlMouseDown;
//  OrderNO.OnMouseMove := ControlMouseMove;
//  OrderNO.OnMouseUp := ControlMouseUp;

  PANEL1.OnMouseDown := ControlMouseDown;
  PANEL1.OnMouseMove := ControlMouseMove;
  PANEL1.OnMouseUp := ControlMouseUp;

  PANEL2.OnMouseDown := ControlMouseDown;
  PANEL2.OnMouseMove := ControlMouseMove;
  PANEL2.OnMouseUp := ControlMouseUp;

  PANEL3.OnMouseDown := ControlMouseDown;
  PANEL3.OnMouseMove := ControlMouseMove;
  PANEL3.OnMouseUp := ControlMouseUp;

  PANEL4.OnMouseDown := ControlMouseDown;
  PANEL4.OnMouseMove := ControlMouseMove;
  PANEL4.OnMouseUp := ControlMouseUp;

//  ToolBar2.OnMouseDown := ControlMouseDown;
//  ToolBar2.OnMouseMove := ControlMouseMove;
//  ToolBar2.OnMouseUp := ControlMouseUp;

end;

procedure TfrmCon_DDXQ.TV3DblClick(Sender: TObject);
begin
  Panel1.Visible := False;
end;

procedure TfrmCon_DDXQ.TV2DblClick(Sender: TObject);
begin
  Panel2.Visible := False;
end;

procedure TfrmCon_DDXQ.CPSClick(Sender: TObject);
begin
  if PANEL4.Visible = FALSE then
  begin
//    cxGrid4.Visible := True;
//    cxGrid1.Visible := False;
//    gridkz();
    PANEL4.Visible := True;

    panel4.BringToFront();

    InitCP();
  end
  else
  begin
//    control.SetToBack();
    panel4.SendToBack();
    PANEL4.Visible := FALSE
  end;
end;

procedure TfrmCon_DDXQ.TV5DblClick(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmCon_DDXQ.Image2Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmCon_DDXQ.Image1Click(Sender: TObject);
begin
  Panel1.Visible := False;
end;

procedure TfrmCon_DDXQ.Image3Click(Sender: TObject);
begin
  panel3.Visible := False;
end;

procedure TfrmCon_DDXQ.Image4Click(Sender: TObject);
begin
  Panel2.Visible := False;
end;

procedure TfrmCon_DDXQ.Button1Click(Sender: TObject);
var
  FBJNO: string;
  fgdy: string;
begin
//  if CDS_Main.IsEmpty then
//    exit;
//  if CDS_Main.Locate('ssel', true, []) = false then
//  begin
//    Application.MessageBox('没有选择数据!', '提示', 0);
//    Exit;
//  end;
  if (RadioButton1.Checked = False) and (RadioButton2.Checked = False) and (RadioButton3.Checked = False) then
  begin
    Application.MessageBox('请先选择考核情况!', '提示', 0);
    Exit;
  end;

  fgdy := '';
  try
    frmUserSel := TfrmUserSel.Create(Application);
    with frmUserSel do
    begin
      fgdy := Trim(GDY.Text);
      FGDYNAME := TRIM(GDYNAME.Text);
      if ShowModal = 1 then
      begin
        if RadioButton1.Checked = True then
        begin
          with ADOTemp do
          begin
            close;
            sql.Clear;

            sql.Add('update JYOrder_Main set SCKHSTATUS=' + QuotedStr(RadioButton1.Caption));
            SQL.Add(',SCNOTE=' + QuotedStr(SCNOTE.TEXT));
            SQL.Add('where mainid=' + QuotedStr(Trim(FMainId)));
            ExecSQL;
          end;
        end;
        if RadioButton2.Checked = True then
        begin
          with ADOTemp do
          begin
            close;
            sql.Clear;

            sql.Add('update JYOrder_Main set SCKHSTATUS=' + QuotedStr(RadioButton2.Caption));
            SQL.Add(',SCNOTE=' + QuotedStr(SCNOTE.TEXT));
            SQL.Add('where mainid=' + QuotedStr(Trim(FMainId)));
            ExecSQL;
          end;
        end;
        if RadioButton3.Checked = True then
        begin
          with ADOTemp do
          begin
            close;
            sql.Clear;

            sql.Add('update JYOrder_Main set SCKHSTATUS=' + QuotedStr(RadioButton3.Caption));
            SQL.Add(',SCNOTE=' + QuotedStr(SCNOTE.TEXT));
            SQL.Add('where mainid=' + QuotedStr(Trim(FMainId)));
            ExecSQL;
          end;
        end;
        while frmUserSel.CDS_User.Locate('SSel', True, []) do
        begin
          if Trim(CDS_User.fieldbyname('wxid').AsString) <> '' then
          begin
            with ADOQueryCmd do
            begin
              close;
              sql.Clear;

              sql.Add('exec P_INSERT_DD ');
              sql.Add('@CODE=' + quotedstr(Trim(CDS_User.fieldbyname('wxid').AsString)));
              sql.Add(',@MAINID=' + quotedstr(Trim(FMAINID)));
              sql.Add(',@ORDERNO=' + quotedstr(Trim(OrderNO.Text)));
              sql.Add(',@days=' + quotedstr(Trim(cqts.Text)));
              sql.Add(',@CPYY=' + quotedstr(Trim(cpyy.Text)));
              sql.Add(',@CLYJ=' + quotedstr(Trim(SCNOTE.Text)));
//              ShowMessage(sql.Text);
              execsql;
            end;
            GetHTTP(IdHTTP1, 'http://zhengyong.rightsoft.top/api/message/send/Feedback');
            fgdy := '1';
          end;

          frmUserSel.CDS_User.Delete;
        end;
        with ADOTemp 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('指示单号：' + trim(OrderNO.Text) + ';反馈意见:' + Trim(SCNOTE.Text))));
          sql.Add(',' + quotedstr(trim('成功')));
          sql.Add(')');
          execsql;
        end;
      end;
    end;
  finally
    frmUserSel.Free;
    if fgdy = '1' then
    begin
      application.MessageBox('推送成功！', '提示信息');
    end;

  end;

end;

procedure TfrmCon_DDXQ.Button2Click(Sender: TObject);
var
  FBJNO: string;
  fgdy: string;
begin
//  if CDS_Main.IsEmpty then
//    exit;
//  if CDS_Main.Locate('ssel', true, []) = false then
//  begin
//    Application.MessageBox('没有选择数据!', '提示', 0);
//    Exit;
//  end;

  if (RadioButton4.Checked = False) and (RadioButton5.Checked = False) and (RadioButton6.Checked = False) then
  begin
    Application.MessageBox('请先选择考核情况!', '提示', 0);
    Exit;
  end;
  fgdy := '';
  try
    frmUserSel := TfrmUserSel.Create(Application);
    with frmUserSel do
    begin
      FLeader := Trim(Leader.Text);
      FFILLER := Trim(FILLER.Text);
      if ShowModal = 1 then
      begin
        while frmUserSel.CDS_User.Locate('SSel', True, []) do
        begin
          if Trim(CDS_User.fieldbyname('wxid').AsString) <> '' then
          begin
            if RadioButton4.Checked = True then
            begin
              with ADOTemp do
              begin
                close;
                sql.Clear;

                sql.Add('update JYOrder_Main set YWKHSTATUS=' + QuotedStr(RadioButton4.Caption));
                SQL.Add(',ywnote=' + QuotedStr(ywnote.TEXT));
                SQL.Add('where mainid=' + QuotedStr(Trim(FMainId)));
                ExecSQL;
              end;
            end;
            if RadioButton5.Checked = True then
            begin
              with ADOTemp do
              begin
                close;
                sql.Clear;

                sql.Add('update JYOrder_Main set YWKHSTATUS=' + QuotedStr(RadioButton5.Caption));
                SQL.Add(',ywnote=' + QuotedStr(ywnote.TEXT));
                SQL.Add('where mainid=' + QuotedStr(Trim(FMainId)));
                ExecSQL;
              end;
            end;
            if RadioButton6.Checked = True then
            begin
              with ADOTemp do
              begin
                close;
                sql.Clear;

                sql.Add('update JYOrder_Main set YWKHSTATUS=' + QuotedStr(RadioButton6.Caption));
                SQL.Add(',ywnote=' + QuotedStr(ywnote.TEXT));
                SQL.Add('where mainid=' + QuotedStr(Trim(FMainId)));
                ExecSQL;
              end;
            end;
            with ADOQueryCmd do
            begin
              close;
              sql.Clear;

              sql.Add('exec P_INSERT_DD_yw ');
              sql.Add('@CODE=' + quotedstr(Trim(CDS_User.fieldbyname('wxid').AsString)));
              sql.Add(',@MAINID=' + quotedstr(Trim(FMAINID)));
              sql.Add(',@ORDERNO=' + quotedstr(Trim(OrderNO.Text)));
              sql.Add(',@days=' + quotedstr(Trim(Edit19.Text)));
              sql.Add(',@CPYY=' + quotedstr(Trim(cpyy.Text)));
              sql.Add(',@CLYJ=' + quotedstr(Trim(ywnote.Text)));
              sql.Add(',@spk=' + quotedstr(Trim(spk.Text)));
//             ShowMessage(sql.Text);
              execsql;
            end;
            GetHTTP(IdHTTP1, 'http://zhengyong.rightsoft.top/api/message/send/Feedback');
            fgdy := '1';
          end;

          frmUserSel.CDS_User.Delete;
        end;
        with ADOTemp 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('指示单号：' + trim(OrderNO.Text) + ';反馈意见:' + Trim(ywNOTE.Text))));
          sql.Add(',' + quotedstr(trim('成功')));
          sql.Add(')');
          execsql;
        end;
      end;
    end;
  finally
    frmUserSel.Free;
    if fgdy = '1' then
    begin
      application.MessageBox('推送成功！', '提示信息');
    end;

  end;

end;

end.

