unit U_SketchManage;

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, cxDropDownEdit,
  StrUtils, cxPC, ShellAPI, cxCalendar, Math, Menus, cxLookAndFeelPainters,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP, cxButtons,
  cxImage, cxDBEdit, cxCheckBox, cxGridBandedTableView, cxGridDBBandedTableView,
  cxLookAndFeels, dxBarBuiltInMenu, cxNavigator, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmSketchManage = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    Panel2: TPanel;
    DS_XM: TDataSource;
    CDS_XM: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    CDS_GC: TClientDataSet;
    DS_GC: TDataSource;
    CDS_SQ: TClientDataSet;
    DS_zbgs: TDataSource;
    CDS_ZBGS: TClientDataSet;
    DS_SQ: TDataSource;
    IdFTP1: TIdFTP;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    Label44: TLabel;
    Panel5: TPanel;
    ADOQuery1: TADOQuery;
    ScrollBox2: TScrollBox;
    Label7: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    F_MSMGF: TEdit;
    F_MGF: TEdit;
    F_MSXPKPF: TEdit;
    F_MGQTF: TEdit;
    F_ZFY: TEdit;
    F_XPKPF: TEdit;
    F_MSDPKPF: TEdit;
    F_DPKPF: TEdit;
    YF_MGF: TCheckBox;
    YF_XPKPF: TCheckBox;
    YF_DWZPF: TCheckBox;
    YF_DYQTF: TCheckBox;
    YF_DYF: TCheckBox;
    YF_MGQTF: TCheckBox;
    YF_DPKPF: TCheckBox;
    F_MGHJ: TEdit;
    Panel3: TPanel;
    Panel1: TPanel;
    Label4: TLabel;
    Label14: TLabel;
    Label21: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    Label28: TLabel;
    Label30: TLabel;
    Label41: TLabel;
    Label45: TLabel;
    G_FACTORYNAME: TcxButtonEdit;
    G_FACTORYHX: TEdit;
    G_ZBDATE: TDateTimePicker;
    G_ZBFACTORYNAME: TcxButtonEdit;
    G_NOTE: TMemo;
    G_ZBFACTORYCODE: TEdit;
    G_PYW: TComboBox;
    G_SGYDJ: TComboBox;
    G_YMG: TCheckBox;
    G_yyp: TCheckBox;
    G_NG: TCheckBox;
    FileName: TcxButton;
    G_FACTORYCODE: TEdit;
    cxButton1: TcxButton;
    IMG_SLT: TEdit;
    IMG_SJT: TEdit;
    cxButton3: TcxButton;
    Panel4: TPanel;
    cxGrid2: TcxGrid;
    TV3: TcxGridDBTableView;
    V2Column3: TcxGridDBColumn;
    V2Column2: TcxGridDBColumn;
    V2Column1: TcxGridDBColumn;
    V2Column4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    Label11: TLabel;
    Label5: TLabel;
    Label43: TLabel;
    lbl1: TLabel;
    Label3: TLabel;
    Label6: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label20: TLabel;
    M_HXCODE: TEdit;
    M_COLOR: TEdit;
    YWY: TcxButtonEdit;
    M_ORDERNEWS: TEdit;
    M_KHNAME: TcxButtonEdit;
    M_DBSPEC: TcxButtonEdit;
    M_TYPE: TComboBox;
    M_COLORNO: TEdit;
    M_HXTYPE: TComboBox;
    M_KHHX: TEdit;
    M_GONGYI: TComboBox;
    M_NOTE: TMemo;
    ORDERNO: TcxButtonEdit;
    frommainid: TEdit;
    FROMSUBID: TEdit;
    Panel6: TPanel;
    ToolBar3: TToolBar;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    cxGrid1: TcxGrid;
    TV4: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    cxGrid4: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    cxGridDBBandedColumn1: TcxGridDBBandedColumn;
    cxGridDBBandedColumn2: TcxGridDBBandedColumn;
    cxGridDBBandedColumn3: TcxGridDBBandedColumn;
    cxGridDBBandedColumn4: TcxGridDBBandedColumn;
    cxGridDBBandedColumn5: TcxGridDBBandedColumn;
    cxGridDBBandedColumn6: TcxGridDBBandedColumn;
    cxGridDBBandedColumn7: TcxGridDBBandedColumn;
    cxGridDBBandedColumn8: TcxGridDBBandedColumn;
    cxGridDBBandedColumn9: TcxGridDBBandedColumn;
    cxGridDBBandedColumn10: TcxGridDBBandedColumn;
    cxGridDBBandedColumn11: TcxGridDBBandedColumn;
    cxGridDBBandedColumn12: TcxGridDBBandedColumn;
    cxGridDBBandedColumn13: TcxGridDBBandedColumn;
    cxGridDBBandedColumn14: TcxGridDBBandedColumn;
    cxGridDBBandedColumn15: TcxGridDBBandedColumn;
    cxGridDBBandedColumn16: TcxGridDBBandedColumn;
    cxGridDBBandedColumn33: TcxGridDBBandedColumn;
    cxGridDBBandedColumn34: TcxGridDBBandedColumn;
    cxGridDBBandedColumn35: TcxGridDBBandedColumn;
    cxGridDBBandedColumn36: TcxGridDBBandedColumn;
    cxGridDBBandedColumn37: TcxGridDBBandedColumn;
    cxGridDBBandedColumn38: TcxGridDBBandedColumn;
    cxGridDBBandedColumn39: TcxGridDBBandedColumn;
    cxGridLevel4: TcxGridLevel;
    cxGrid3: TcxGrid;
    TV2: TcxGridDBBandedTableView;
    cxGridDBBandedColumn40: TcxGridDBBandedColumn;
    cxGridDBBandedColumn41: TcxGridDBBandedColumn;
    cxGridDBBandedColumn42: TcxGridDBBandedColumn;
    cxGridDBBandedColumn43: TcxGridDBBandedColumn;
    cxGridDBBandedColumn44: TcxGridDBBandedColumn;
    cxGridDBBandedColumn45: TcxGridDBBandedColumn;
    cxGridDBBandedColumn46: TcxGridDBBandedColumn;
    cxGridDBBandedColumn47: TcxGridDBBandedColumn;
    cxGridDBBandedColumn48: TcxGridDBBandedColumn;
    cxGridDBBandedColumn49: TcxGridDBBandedColumn;
    cxGridDBBandedColumn50: TcxGridDBBandedColumn;
    cxGridDBBandedColumn51: TcxGridDBBandedColumn;
    cxGridDBBandedColumn52: TcxGridDBBandedColumn;
    cxGridDBBandedColumn53: TcxGridDBBandedColumn;
    cxGridDBBandedColumn54: TcxGridDBBandedColumn;
    cxGridDBBandedColumn55: TcxGridDBBandedColumn;
    cxGridLevel3: TcxGridLevel;
    Label42: TLabel;
    G_ZBFACTORYZBCODE: TEdit;
    V3Column1: TcxGridDBColumn;
    ScrollBox3: TScrollBox;
    Label2: TLabel;
    F_YSTS: TEdit;
    Label29: TLabel;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    F_SOMTZBF: TEdit;
    F_SOMSPSF: TEdit;
    F_MSDPZWF: TEdit;
    F_DYQTFY: TEdit;
    Label27: TLabel;
    F_PSS: TEdit;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    Label37: TLabel;
    F_SOZBF: TEdit;
    F_PSF: TEdit;
    F_DPZWF: TEdit;
    F_DYF: TEdit;
    Label38: TLabel;
    F_NOTE: TMemo;
    Label46: TLabel;
    M_DBname: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure C_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure tbADDClick(Sender: TObject);
    procedure tbDELClick(Sender: TObject);
    procedure Tv6DblClick(Sender: TObject);
    procedure Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Tv5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure B_YWYBMKeyPress(Sender: TObject; var Key: Char);
    procedure B_FactoryNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure B_NOTEDblClick(Sender: TObject);
    procedure Picture4DblClick(Sender: TObject);
    procedure FileNameClick(Sender: TObject);
    procedure B_KHPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ORDERNOPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure M_DBSPECPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure G_FACTORYNAMEPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure G_ZBFACTORYNAMEPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton3Click(Sender: TObject);
    procedure TV4FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure cxGridDBColumn1PropertiesChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure cxGridDBColumn6PropertiesChange(Sender: TObject);
    procedure G_PYWChange(Sender: TObject);
    procedure G_YMGClick(Sender: TObject);
    procedure F_YSTSExit(Sender: TObject);
    procedure cxTabSheet1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure V2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure N1Click(Sender: TObject);
    procedure cxGridDBColumn4PropertiesEditValueChanged(Sender: TObject);
  private
    FXS, Fint: Integer;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    procedure InitImage();
    procedure HQGC();
    procedure HQZBGS();
//    procedure HQXPS();
//    procedure JSFY();
//    procedure JSFY2();

    procedure JSFYAll();
    procedure LookImage(FileName: string);
    { Private declarations }
  public
    PState, CopyInt: Integer;
    FMainId, FConNo, PType, FSubId: string;
    FDDID: string;
    ftype: string;
    fFlileFlag: string;
    canshu1: string;
    { Public declarations }
  end;

var
  frmSketchManage: TfrmSketchManage;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun, U_ZdyAttachGYS, U_CompressionFun, U_FjList_RZ,
  U_ZdyAttachment, U_ZDYHelpSel, getpic, getpic2, U_ProductOrderListSel,
  U_CPManageSel;

{$R *.dfm}

procedure TfrmSketchManage.JSFYAll();
var
  F_YSTS1, F_MSMGF1, F_MSXPKPF1, F_MSDPKPF1, F_MGQTF1: Double;
  F_MGF1, F_XPKPF1, F_DPKPF1: Double;
  F_PSS1, F_SOMTZBF1, F_DYQTFY1, F_MSDPZWF1, F_SOMSPSF1: Double;
  F_SOZBF1, F_PSF1: Double;
  J, K, L, Z: Integer;
begin
  J := 0;
  K := 0;
  L := 0;
  Z := 0;
  if not CDS_XM.IsEmpty then
  begin
    with CDS_XM do
    begin
      CDS_XM.DisableControls;
      First;
      while not Eof do
      begin
        if CDS_XM.fieldbyname('XMNAME').asstring = '小片' then
        begin
          J := J + 1;
        end;
        if (CDS_XM.fieldbyname('XMNAME').asstring = '小片') and (CDS_XM.fieldbyname('XMKP').AsBoolean = True) then
        begin
          K := K + 1;
        end;

        if (CDS_XM.fieldbyname('XMNAME').asstring = '大片') and (CDS_XM.fieldbyname('XMKP').AsBoolean = True) then
        begin
          L := L + 1;
        end;

        if (CDS_XM.fieldbyname('XMNAME').asstring = '大片') and (CDS_XM.fieldbyname('XMWCSJ').AsString <> '') then
        begin
          Z := Z + 1;
        end;
        Next;
      end;
      CDS_XM.EnableControls;
    end;
  end;

  F_PSS1 := StrToFloatDef(F_PSS.Text, 0);   //配色数
  F_SOMTZBF1 := StrToFloatDef(F_SOMTZBF.Text, 0);  //S/O每套制版费
  F_SOMSPSF1 := StrToFloatDef(F_SOMSPSF.Text, 0);  //每色配色费
  F_DYQTFY1 := StrToFloatDef(F_DYQTFY.Text, 0);  //打样其他费用
  F_MSDPZWF1 := StrToFloatDef(F_MSDPZWF.Text, 0);  //每色大片制网费

  F_SOZBF1 := StrToFloatDef(F_SOZBF.Text, 0);  //S/O制版费
  F_PSF1 := StrToFloatDef(F_PSF.Text, 0);  //配色费

  F_YSTS1 := StrToFloatDef(F_YSTS.Text, 0);   //颜色套数
  F_MSMGF1 := StrToFloatDef(F_MSMGF.Text, 0);  //每色描稿费
  F_MSXPKPF1 := StrToFloatDef(F_MSXPKPF.Text, 0);    //每色小片刻盘费
  F_MSDPKPF1 := StrToFloatDef(F_MSDPKPF.Text, 0);   //每色大片刻盘费
  F_MGQTF1 := StrToFloatDef(F_MGQTF.Text, 0);   //描稿其他费

  F_MGF1 := StrToFloatDef(F_MGF.Text, 0);   //描稿费
  //S/O制版费=S/O每套制版费  * 颜色套数
  F_SOZBF.TEXT := FloatToStr(ROUNDFLOAT((F_YSTS1 * F_SOMTZBF1), 2));   //S/O制版费
  //配色费=配色数 * 每色配色费
  F_PSF.TEXT := FloatToStr(ROUNDFLOAT((F_PSS1 * F_SOMSPSF1), 2));   //配色费
  //打样费=(S/O制版费 + 配色费 + 打样其他费用 )*K(小片数)
  F_DYF.TEXT := FloatToStr(ROUNDFLOAT((J * (StrToFloatDef(F_SOZBF.text, 0) + StrToFloatDef(F_PSF.text, 0) + strtofloatdef(F_DYQTFY.text, 0))), 2));   //打样费
  //描稿费=每色描稿费 * 颜色套数
  //已描稿打上 就说明 描稿费用不用没有了
  if G_YMG.Checked = False then
  begin
    F_MGF.TEXT := FloatToStr(ROUNDFLOAT((F_YSTS1 * F_MSMGF1), 2));   //描稿费
  end
  else
  begin
    F_MGF.TEXT := '0';
  end;
    //已有片打上 是描稿 和工厂两个里面的纸片费用制片费用都不用了
  if G_yyp.Checked = False then
  begin
  //小片刻盘费=每色小片刻盘费  * 颜色套数
    F_XPKPF.TEXT := FloatToStr(ROUNDFLOAT((K * F_YSTS1 * F_MSXPKPF1), 2));   //小片刻盘费
  //大片刻盘费=每色大片刻盘费  * 颜色套数
    F_DPKPF.TEXT := FloatToStr(ROUNDFLOAT((L * F_YSTS1 * F_MSDPKPF1), 2));   //大片刻盘费
      //大片制网费=每色大片制网费 * 颜色套数
    if Z > 0 then
    begin
      F_DPZWF.text := FloatToStr(ROUNDFLOAT((F_MSDPZWF1 * StrToFloatDef(F_YSTS.text, 0)), 2));   //大片制网费
    end
    else
    begin
      F_DPZWF.text := '0';
    end;

  end
  else
  begin
    F_XPKPF.TEXT := '0';
    F_DPKPF.TEXT := '0';

  end;

  F_XPKPF1 := StrToFloatDef(F_XPKPF.Text, 0);  //小片刻盘费
  F_DPKPF1 := StrToFloatDef(F_DPKPF.Text, 0);  //大片刻盘费
   //描稿合计=描稿费 + 小片刻盘费 + 大片刻盘费 + 描稿其他费
  F_MGHJ.Text := FloatToStr(ROUNDFLOAT((StrToFloatDef(F_MGF.Text, 0) + StrToFloatDef(F_DPKPF.Text, 0) + StrToFloatDef(F_XPKPF.Text, 0) + StrToFloatDef(F_MGQTF.Text, 0)), 2));   //描稿合计
   //总费用 = 描稿合计 + 打样费 + 大片制网费
  F_ZFY.Text := FloatToStr(ROUNDFLOAT((StrToFloatDef(F_DPZWF.text, 0) + StrToFloatDef(F_DYF.text, 0) + StrToFloatDef(F_MGHJ.text, 0)), 2));   //总费用
end;

//procedure TfrmSketchManage.JSFY();
//var
//  F_YSTS1, F_MSMGF1, F_MSXPKPF1, F_MSDPKPF1, F_MGQTF1: Double;
//  F_MGF1, F_XPKPF1, F_DPKPF1: Double;
//begin
//
//  F_YSTS1 := StrToFloatDef(F_YSTS.Text, 0);   //颜色套数
//  F_MSMGF1 := StrToFloatDef(F_MSMGF.Text, 0);  //每色描稿费
//  F_MSXPKPF1 := StrToFloatDef(F_MSXPKPF.Text, 0);    //每色小片刻盘费
//  F_MSDPKPF1 := StrToFloatDef(F_MSDPKPF.Text, 0);   //每色大片刻盘费
//  F_MGQTF1 := StrToFloatDef(F_MGQTF.Text, 0);   //描稿其他费
//
//  F_MGF1 := StrToFloatDef(F_MGF.Text, 0);   //描稿费
//
//  //描稿费=每色描稿费 * 颜色套数
//  //已描稿打上 就说明 描稿费用不用没有了
//  if G_YMG.Checked = False then
//  begin
//    F_MGF.TEXT := FloatToStr(ROUNDFLOAT((F_YSTS1 * F_MSMGF1), 2));   //描稿费
//  end;
//    //已有片打上 是描稿 和工厂两个里面的纸片费用制片费用都不用了
//  if G_yyp.Checked = False then
//  begin
//  //小片刻盘费=每色小片刻盘费  * 颜色套数
//    F_XPKPF.TEXT := FloatToStr(ROUNDFLOAT((k * F_YSTS1 * F_MSXPKPF1), 2));   //小片刻盘费
//  //大片刻盘费=每色大片刻盘费  * 颜色套数
//    F_DPKPF.TEXT := FloatToStr(ROUNDFLOAT((l * F_YSTS1 * F_MSDPKPF1), 2));   //大片刻盘费
//  end;
//
//  F_XPKPF1 := StrToFloatDef(F_XPKPF.Text, 0);  //小片刻盘费
//  F_DPKPF1 := StrToFloatDef(F_DPKPF.Text, 0);  //大片刻盘费
//
//   //描稿合计=描稿费 + 小片刻盘费 + 大片刻盘费 + 描稿其他费
//  F_MGHJ.Text := FloatToStr(ROUNDFLOAT((StrToFloatDef(F_MGF.Text, 0) + StrToFloatDef(F_DPKPF.Text, 0) + StrToFloatDef(F_XPKPF.Text, 0) + StrToFloatDef(F_MGQTF.Text, 0)), 2));   //描稿合计
//
//    //总费用 = 描稿合计 + 打样费 + 大片制网费
//  F_ZFY.Text := FloatToStr(ROUNDFLOAT((strtofloatDEF(F_DPZWF.text, 0) + strtofloatDEF(F_DYF.text, 0) + strtofloatDEF(F_MGHJ.text, 0)), 2));   //总费用
//
//
//end;

//procedure TfrmSketchManage.HQXPS();
//begin
//  J := 0;
//  K := 0;
//  L := 0;
//  with CDS_XM do
//  begin
//    First;
//    while not Eof do
//    begin
//      if CDS_XM.fieldbyname('XMNAME').asstring = '小片' then
//      begin
//        J := J + 1;
//      end;
//      if (CDS_XM.fieldbyname('XMNAME').asstring = '小片') and (CDS_XM.fieldbyname('XMKP').AsBoolean = True) then
//      begin
//        K := K + 1;
//      end;
//
//      if (CDS_XM.fieldbyname('XMNAME').asstring = '大片') and (CDS_XM.fieldbyname('XMKP').AsBoolean = True) then
//      begin
//        L := L + 1;
//      end;
//
//      Next;
//    end;
//  end;
////  ShowMessage(IntToStr(J));
//end;

//procedure TfrmSketchManage.JSFY2();
//var
//  F_PSS1, F_SOMTZBF1, F_DYQTFY1, F_MSDPZWF1, F_SOMSPSF1: Double;
//  F_SOZBF1, F_PSF1: Double;
//begin
//  F_PSS1 := StrToFloatDef(F_PSS.Text, 0);   //配色数
//  F_SOMTZBF1 := StrToFloatDef(F_SOMTZBF.Text, 0);  //S/O每套制版费
//  F_SOMSPSF1 := StrToFloatDef(F_SOMSPSF.Text, 0);  //每色配色费
//  F_DYQTFY1 := StrToFloatDef(F_DYQTFY.Text, 0);  //打样其他费用
//  F_MSDPZWF1 := StrToFloatDef(F_MSDPZWF.Text, 0);  //每色大片制网费
//
//  F_SOZBF1 := StrToFloatDef(F_SOZBF.Text, 0);  //S/O制版费
//  F_PSF1 := StrToFloatDef(F_PSF.Text, 0);  //配色费
//
//  //S/O制版费=S/O每套制版费  * 颜色套数
//  F_SOZBF.TEXT := FloatToStr(ROUNDFLOAT((F_PSS1 * F_SOMTZBF1), 2));   //S/O制版费
//  //配色费=配色数 * 每色配色费
//  F_PSF.TEXT := FloatToStr(ROUNDFLOAT((F_PSS1 * F_SOMSPSF1), 2));   //配色费
//  //打样费=S/O制版费 + 配色费 + 打样其他费用
//  F_DYF.TEXT := FloatToStr(ROUNDFLOAT((J * (StrToFloatDef(F_SOZBF.text, 0) + StrToFloatDef(F_PSF.text, 0) + strtofloatdef(F_DYQTFY.text, 0))), 2));   //打样费
//  //大片制网费=每色大片制网费 * 颜色套数
//  F_DPZWF.text := FloatToStr(ROUNDFLOAT((F_MSDPZWF1 * StrToFloatDef(F_YSTS.text, 0)), 2));   //大片制网费
//
//   //总费用 = 描稿合计 + 打样费 + 大片制网费
//  F_ZFY.Text := FloatToStr(ROUNDFLOAT((StrToFloatDef(F_DPZWF.text, 0) + StrToFloatDef(F_DYF.text, 0) + StrToFloatDef(F_MGHJ.text, 0)), 2));   //总费用
//end;

procedure TfrmSketchManage.HQGC();
begin
  if CDS_GC.IsEmpty then
    Exit;
  if CDS_GC.fieldbyname('F_XYZPF').AsString <> '' then
  begin
    F_SOMTZBF.Text := CDS_GC.fieldbyname('F_XYZPF').AsString;
  end;

  if CDS_GC.fieldbyname('F_XYPSF').AsString <> '' then
  begin
    F_SOMSPSF.Text := CDS_GC.fieldbyname('F_XYPSF').AsString;
  end;

//  F_SOMSPSF.Text := ADOQueryTemp.fieldbyname('F_DPYW').Value;
//  (F_SOMTZBF.Text, 0);
end;

procedure TfrmSketchManage.HQZBGS();
begin
  if CDS_ZBGS.IsEmpty then
    Exit;
  if G_NG.Checked = True then
  begin
    if CDS_ZBGS.fieldbyname('F_MSMGFFJ').AsString <> '' then
    begin
      F_MSMGF.Text := CDS_ZBGS.fieldbyname('F_MSMGFFJ').AsString;
    end;
  end
  else
  begin
    if CDS_ZBGS.fieldbyname('F_MSMGFJ').AsString <> '' then
    begin
      F_MSMGF.Text := CDS_ZBGS.fieldbyname('F_MSMGFJ').Value;
    end;

  end;

  if G_PYW.Text = '圆网' then
  begin
    if CDS_ZBGS.fieldbyname('F_XXGYW').AsString <> '' then
    begin
      F_MSXPKPF.Text := CDS_ZBGS.fieldbyname('F_XXGYW').Value;
    end;
    if CDS_ZBGS.fieldbyname('F_DXGYW').AsString <> '' then
    begin
      F_MSDPKPF.Text := CDS_ZBGS.fieldbyname('F_DXGYW').Value;
    end;
    if CDS_GC.fieldbyname('F_DPYW').AsString <> '' then
    begin
      F_MSDPZWF.Text := CDS_GC.fieldbyname('F_DPYW').Value;
    end;

  end
  else
  begin
    if CDS_ZBGS.fieldbyname('F_XXGPW').AsString <> '' then
    begin
      F_MSXPKPF.Text := CDS_ZBGS.fieldbyname('F_XXGPW').Value;
    end;
    if CDS_ZBGS.fieldbyname('F_DXGPW').AsString <> '' then
    begin
      F_MSDPKPF.Text := CDS_ZBGS.fieldbyname('F_DXGPW').Value;
    end;
    if CDS_GC.fieldbyname('F_DPPW').AsString <> '' then
    begin
      F_MSDPZWF.Text := CDS_GC.fieldbyname('F_DPPW').Value;
    end;

  end;

end;

procedure TfrmSketchManage.TBCloseClick(Sender: TObject);
begin
  Close;

end;

procedure TfrmSketchManage.InitData();
var
  PBNO, PBFlag, maxconno: string;
begin
  if ftype = '查看' then
  begin
    tbsave.visible := false;
  end;
 
/////////////////刷新产品信息/////////////////////////

  G_ZBDATE.Date := Now;
  G_ZBDATE.Checked := False;
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.* from Sketch_main A ');
    if PState = 1 then
    begin
      sql.Add(' where A.mgId=' + Quotedstr(Trim(FMainId)));
    end;
    if PState = 0 then
    begin
      sql.Add('  where 1<>1 ');
    end;
//    ShowMessage(sql.Text);
    Open;
  end;
  SCSHData(ADOQueryTemp, ScrollBox1, 0);
  if CopyInt <> 99 then
  begin
    SCSHData(ADOQueryTemp, PANEL1, 1);
    SCSHData(ADOQueryTemp, ScrollBox1, 2);
    SCSHDataNew(ADOQueryTemp, ScrollBox2, 3);
    SCSHDataNew(ADOQueryTemp, ScrollBox3, 3);
    if ADOQueryTemp.fieldbyname('G_ymg').value = '1' then
    begin
      G_ymg.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('G_yyp').value = '1' then
    begin
      G_yyp.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('G_ng').value = '1' then
    begin
      G_ng.Checked := True;
    end;

    if ADOQueryTemp.fieldbyname('YF_MGQTF').value = '1' then
    begin
      YF_MGQTF.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('YF_DYF').value = '1' then
    begin
      YF_DYF.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('YF_DYQTF').value = '1' then
    begin
      YF_DYQTF.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('YF_DWZPF').value = '1' then
    begin
      YF_DWZPF.Checked := True;
    end;

    if ADOQueryTemp.fieldbyname('YF_MGF').value = '1' then
    begin
      YF_MGF.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('YF_XPKPF').value = '1' then
    begin
      YF_XPKPF.Checked := True;
    end;
    if ADOQueryTemp.fieldbyname('YF_DPKPF').value = '1' then
    begin
      YF_DPKPF.Checked := True;
    end;
  end;
//  if G_ZBFACTORYCODE.Text <> '' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      SQL.Add('SELECT A.*,B.CONAME FROM Company_MGFY A INNER JOIN Company B  ON A.FromCoID=B.CoID WHERE COCODE=' + QUOTEDSTR(G_ZBFACTORYCODE.Text));
//    ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_ZBGS);
    SInitCDSData20(ADOQueryTemp, CDS_ZBGS);
  end;

//  if G_FACTORYCODE.Text <> '' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      SQL.Add('SELECT A.*,B.CONAME FROM Company_GCFY A INNER JOIN Company B  ON A.FromCoID=B.CoID WHERE COCODE=' + QUOTEDSTR(G_FACTORYCODE.Text));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_GC);
    SInitCDSData20(ADOQueryTemp, CDS_GC);
  end;

  HQGC();
  HQZBGS();
  if FDDID <> '' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,B.SUBID,PRTHXKH,PRTColorNo,PRTColor from JYOrder_Main A inner join JYOrder_Sub B on  A.MainId=B.MAINID ');
      SQL.Add('WHERE SUBID=' + QUOTEDSTR(FDDID));
//      ShowMessage(SQL.Text);
      Open;
    end;
    M_COLOR.Text := Trim(ADOQueryTemp.fieldbyname('PRTColor').AsString);
    M_COLORNO.Text := Trim(ADOQueryTemp.fieldbyname('PRTColorNo').AsString);
//        M_COLORNO.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHX').AsString);
    M_KHHX.Text := Trim(ADOQueryTemp.fieldbyname('PRTHXKH').AsString);
    orderno.Text := Trim(ADOQueryTemp.fieldbyname('orderno').AsString);
    M_KHNAME.Text := Trim(ADOQueryTemp.fieldbyname('CustomerNoName').AsString);
    frommainid.Text := Trim(ADOQueryTemp.fieldbyname('mainid').AsString);

    fromsubid.Text := Trim(ADOQueryTemp.fieldbyname('subid').AsString);
    M_DBSPEC.Text := Trim(ADOQueryTemp.fieldbyname('MPRTCODENAME').AsString);
  end;
 /////////////////刷新产品信息/////////////////////////
 ///////////刷新授权/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');

    sql.Add('from Sketch_BQSD A ');

    sql.Add(' where A.HxCode=''' + Trim(M_HXCODE.Text) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_SQ);
  if CopyInt <> 99 then
    SInitCDSData20(ADOQueryTemp, CDS_SQ);
   ///////////刷新项目安排/////////////////////////
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');

    sql.Add('from Sketch_XMAP A ');

    sql.Add(' where A.MGID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_XM);
  if CopyInt <> 99 then
    SInitCDSData20(ADOQueryTemp, CDS_XM);


 /////////////刷新原料/////////////////////////
 //**************        复制数据清除ID         ***************//
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    IMG_SLT.text := '';
    IMG_SJT.text := '';
    with CDS_SQ do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MGID').Value := null;
        FieldByName('SQID').Value := null;
        Post;
        Next;
      end;
    end;

    with CDS_XM do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MGID').Value := null;
        FieldByName('XMId').Value := null;
        Post;
        Next;
      end;
    end;
  end;
   //**************        复制数据清除ID         ***************//
end;

procedure TfrmSketchManage.ZDYHelp(FButn: TcxButtonEdit; LType: string);
begin

end;

procedure TfrmSketchManage.FormShow(Sender: TObject);
begin
  fFlileFlag := UserDataFlag + 'HX';
//  showmessage(fFlileFlag);  UserDataFlag
  InitData();

  if Trim(canshu1) = '录入' then
  begin
    ScrollBox2.Visible := False;
    cxGrid4.Visible := False;
    cxGrid3.Visible := False;
  end;
  if Trim(canshu1) = '查询' then
  begin
    Panel1.Enabled := False;
    ToolBar2.Visible := False;
    ToolBar3.Visible := False;
//    TV3.OptionsSelection.CellSelect := False;
    ScrollBox2.Visible := False;
    ScrollBox3.Visible := False;
    cxGrid4.Visible := False;
    cxGrid3.Visible := False;
  end;
  JSFYAll();
//  InitImage();
end;

function TfrmSketchManage.SaveData(): Boolean;
var
  maxno, maxsubno, maxpbno, maxpzno, maxsjno: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOQueryCmd, maxno, 'MG', 'Sketch_main', 4, 1) = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('生成流水号异常！', '提示', 0);
        exit;
      end;
    end
    else
    begin
      maxno := Trim(FMainId);
    end;

    ///保存主表
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Sketch_main where MGID=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if ADOQueryCmd.IsEmpty then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('Filltime').Value := SGetServerDateTime(ADOQueryTemp);
      end
      else
      begin
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTemp);
      end;
      FieldByName('MGID').Value := Trim(maxno);
      RTSetsavedata(ADOQueryCmd, 'Sketch_main', ScrollBox1, 0);
      SSetsaveSqlNew(ADOQueryCmd, 'Sketch_main', Panel1, 1);
      SSetsaveSqlNew(ADOQueryCmd, 'Sketch_main', ScrollBox2, 3);
      SSetsaveSqlNew(ADOQueryCmd, 'Sketch_main', ScrollBox3, 3);
      if G_YMG.Checked = True then
      begin
        FieldByName('G_YMG').Value := 1;
      end
      else
      begin
        FieldByName('G_YMG').Value := 0;
      end;
      if G_YYP.Checked = True then
      begin
        FieldByName('G_YYP').Value := 1;
      end
      else
      begin
        FieldByName('G_YYP').Value := 0;
      end;
      if G_NG.Checked = True then
      begin
        FieldByName('G_NG').Value := 1;
      end
      else
      begin
        FieldByName('G_NG').Value := 0;
      end;

      if YF_MGF.Checked = True then
      begin
        FieldByName('YF_MGF').Value := 1;
      end
      else
      begin
        FieldByName('YF_MGF').Value := 0;
      end;
      if YF_XPKPF.Checked = True then
      begin
        FieldByName('YF_XPKPF').Value := 1;
      end
      else
      begin
        FieldByName('YF_XPKPF').Value := 0;
      end;

      if YF_DPKPF.Checked = True then
      begin
        FieldByName('YF_DPKPF').Value := 1;
      end
      else
      begin
        FieldByName('YF_DPKPF').Value := 0;
      end;
      if YF_MGQTF.Checked = True then
      begin
        FieldByName('YF_MGQTF').Value := 1;
      end
      else
      begin
        FieldByName('YF_MGQTF').Value := 0;
      end;

      if YF_DYF.Checked = True then
      begin
        FieldByName('YF_DYF').Value := 1;
      end
      else
      begin
        FieldByName('YF_DYF').Value := 0;
      end;

      if YF_DYQTF.Checked = True then
      begin
        FieldByName('YF_DYQTF').Value := 1;
      end
      else
      begin
        FieldByName('YF_DYQTF').Value := 0;
      end;

      if YF_DYQTF.Checked = True then
      begin
        FieldByName('YF_DWZPF').Value := 1;
      end
      else
      begin
        FieldByName('YF_DWZPF').Value := 0;
      end;
      Post;
    end;



//保存授权客户表
    with CDS_SQ do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_SQ.fieldbyname('SQID').AsString) = '' then
        begin
          if GetLSNo(ADOQueryTemp, maxpzno, 'SQ', 'Sketch_BQSD', 3, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpzno := Trim(CDS_SQ.fieldbyname('SQID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Sketch_BQSD where ');
          sql.Add('  SQID=''' + Trim(maxpzno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_SQ.fieldbyname('SQID').AsString) = '' then
          begin
            Append;

          end
          else
          begin
            Edit;

          end;
          FieldByName('MGID').Value := Trim(maxno);

          FieldByName('SQID').Value := Trim(maxpzno);
          RTSetSaveDataCDS(ADOQueryCmd, Tv3, CDS_SQ, 'Sketch_BQSD', 0);
          Post;
        end;
        CDS_SQ.Edit;

        CDS_SQ.FieldByName('MGID').Value := Trim(maxno);
        CDS_SQ.FieldByName('SQID').Value := Trim(maxpzno);
        CDS_SQ.Post;
        Next;
      end;
    end;
    ///保存项目表
    with CDS_XM do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_XM.fieldbyname('XMID').AsString) = '' then
        begin
          if GetLSNo(ADOQueryTemp, maxpbno, 'XM', 'Sketch_XMAP', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取配比子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpbno := Trim(CDS_XM.fieldbyname('XMID').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Sketch_XMAP where ');
          sql.Add('  XMID=''' + Trim(maxpbno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_XM.fieldbyname('XMID').AsString) = '' then
          begin
            Append;

          end
          else
          begin
            Edit;

          end;
          FieldByName('MGID').Value := Trim(maxno);
          FieldByName('XMId').Value := Trim(maxpbno);
          RTSetSaveDataCDS(ADOQueryCmd, Tv4, CDS_XM, 'Sketch_XMAP', 0);
          Post;
        end;
        CDS_XM.Edit;
        CDS_XM.FieldByName('MGId').Value := Trim(maxno);
        CDS_XM.FieldByName('XMId').Value := Trim(maxpbno);
        CDS_XM.Post;
        Next;
      end;
    end;

    ADOQueryCmd.Connection.CommitTrans;

    FMainId := Trim(maxno);
    FSubId := Trim(maxsubno);
    Result := True;
  except
    Result := False;

    CDS_XM.EnableControls;
//    CDS_Paizhen.EnableControls;
    CDS_SQ.EnableControls;

    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmSketchManage.TBSaveClick(Sender: TObject);
var
  FReal: Double;
  maxConNo: string;
begin
  ToolBar1.SetFocus();
//  b_QDTime.SetFocus;
//  if Trim(C_CodeName.Text) = '' then
//  begin
//    Application.MessageBox('产品名称不能为空!', '提示', 0);
//    Exit;
//  end;

  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('SELECT ISSD=[dbo].[F_Mg_Judge_SD](' + quotedstr(M_KHNAME.Text) + ',' + quotedstr(M_HXCODE.Text));
    sql.Add(') ');

    Open;
  end;
  if ADOQueryTemp.FieldByName('ISSD').AsString = '已锁定' then
  begin
    if Application.MessageBox(pchar('设计稿' + trim(M_HXCODE.Text) + ' 版权已锁定，确定继续吗？'), '提示', 32 + 4) <> IDYES then
      exit;
  end;
  if Trim(M_KHNAME.Text) = '' then
  begin
    Application.MessageBox('客户不能为空!', '提示', 0);
    Exit;
  end;

  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
//    ModalResult := 0;
  end;
end;

procedure TfrmSketchManage.C_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
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);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if Trim(flag) = 'OrdDefStr2' then
      begin
        V1Name.Caption := '中文名称';
        V1Note.Caption := '英文名称';
        fnote := True;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);

      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmSketchManage.tbADDClick(Sender: TObject);
var
  i: Integer;
begin
  i := CDS_SQ.RecordCount;
  i := i + 1;
  with CDS_SQ do
  begin
    Append;
    FieldByName('SQNO').Value := i;
//    FieldByName('jddate').Value := Trim(FormatDateTime('yyyy-MM-dd', Now));
    Post;
  end;
end;

procedure TfrmSketchManage.tbDELClick(Sender: TObject);
begin
  if CDS_XM.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('delete Sketch_XMAP where XMID=''' + Trim(CDS_XM.fieldbyname('XMID').AsString) + '''');
    ExecSQL;
  end;
  CDS_XM.Delete;
//  HQXPS();
  JSFYAll();

end;

procedure TfrmSketchManage.Tv6DblClick(Sender: TObject);
var
  sFieldName: string;
  fileName: string;
  ff: TADOBlobStream;
  FJStream: TMemoryStream;
begin
//  if CDS_Fujian.IsEmpty then
//    exit;
//  Panel4.Caption := '正在下载文件，请稍等...';
//  Panel4.Visible := true;
//  application.ProcessMessages;
//  with ADOQueryTemp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select * from TP_File where TFID=''' + Trim(CDS_Fujian.fieldbyname('TFID').AsString) + '''');
//    Open;
//  end;
//  sFieldName := 'D:\图片查看';
//  if not DirectoryExists(pchar(sFieldName)) then
//    CreateDirectory(pchar(sFieldName), nil);
//  fileName := CDS_Fujian.fieldbyname('FileName').AsString;
//  sFieldName := sFieldName + '\' + trim(fileName);
//  try
//    ff := TADOBlobstream.Create(ADOQueryTemp.fieldByName('FilesOther') as TblobField, bmRead);
//    FJStream := TMemoryStream.Create;
//    ff.SaveToStream(FJStream);
//    UnCompressionStream(FJStream);
//    FJStream.SaveToFile(sFieldName);
//    Panel4.Visible := False;
//    ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
//  finally
//    Panel4.Visible := False;
//    FJStream.free;
//    ff.Free;
//  end;
end;

procedure TfrmSketchManage.Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint := 1;
end;

procedure TfrmSketchManage.Tv5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint := 2;
end;

procedure TfrmSketchManage.C_CodeKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    SelectNext(ActiveControl as TWinControl, True, True);
  end;
end;

procedure TfrmSketchManage.B_YWYBMKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Key := #0;
    SelectNext(ActiveControl as TWinControl, True, True);
  end;
end;

procedure TfrmSketchManage.B_FactoryNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  if fsj = '' then
  begin

  end
  else
  begin
    FWZ := Pos('/', fsj);
    try
      frmZDYHelp := TfrmZDYHelp.Create(Application);
      with frmZDYHelp do
      begin
        flag := Copy(fsj, 1, FWZ - 1);
        flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
        if Trim(flag) = 'C_CodeName' then
        begin
          fnote := True;
          V1Note.Caption := '类型';
        end;
        if ShowModal = 1 then
        begin
          TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        end;
      end;
    finally
      frmZDYHelp.Free;
    end;
  end;

end;

procedure TfrmSketchManage.B_NOTEDblClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
  i: integer;
begin
//  fsj := Trim(TMemo(Sender).Hint);
//  FWZ := Pos('/', fsj);
//  i := 0;
//  try
//    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
//    with frmZDYHelpSel do
//    begin
//      flag := Copy(fsj, 1, FWZ - 1);
//      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
//      if ShowModal = 1 then
//      begin
//        B_NOTE.Lines.Clear;
//        with ClientDataSet1 do
//        begin
//          First;
//          while not Eof do
//          begin
//            if FieldByName('SSel').AsBoolean = True then
//            begin
//              i := i + 1;
//              B_NOTE.Lines.Add(inttostr(i) + '.' + FieldByName('ZDYName').AsString)
//            end;
//            Next;
//          end;
//        end;
//      end;
//    end;
//  finally
//    frmZDYHelpSel.Free;
//  end;
end;

procedure TfrmSketchManage.Picture4DblClick(Sender: TObject);
begin
  if TcxDBImage(Sender).Picture.Height = 0 then
    exit;

  LookImage(ADOQueryImage.fieldbyname(TcxDBImage(Sender).Hint).asstring);
end;

procedure TfrmSketchManage.LookImage(FileName: string);
var
  sFieldName: string;
 //	ff: TADOBlobStream;
 // FJStream : TMemoryStream;
begin

  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);

  sFieldName := sFieldName + '\' + trim(FileName);

  try
    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    ;
  end;

  if IdFTP1.Connected then
  begin

    Panel5.Caption := '正在下载数据，请稍等...';
    Panel5.Visible := true;
    application.ProcessMessages;
    try
      IdFTP1.Get(fFlileFlag + '\' + Trim(FileName), sFieldName, true, false);
    except
      Panel5.Visible := false;
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Panel5.Visible := false;
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
  Panel5.Visible := false;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

procedure TfrmSketchManage.FileNameClick(Sender: TObject);
begin
  if trim(fmainid) = '' then
  begin
    application.MessageBox('寻样单信息未保存，请先保存寻样单信息！', '提示信息', MB_ICONERROR);
    exit;
  end;
//
//  try
//    FormGetPic2 := TFormGetPic.Create(Application);
//    with FormGetPic do
//    begin
//      fkeyNO := trim(self.fmainid);
//      pat1 := TCXbutton(Sender).Name;
//      pic1 := TCXbutton(Sender).Hint;
//      FTFType := '寻样';
//      fFlileFlag := self.fFlileFlag;
//      if ShowModal = 1 then
//      begin
//     // self.Timage(Tbutton(Sender).Hint).Picture.Assign(FormGetPic.Image2.Picture.Bitmap);
//     //   zdycode.Enabled:=false;
//      end;
//
//      Release;
//    end;
//    InitImage();
//  except
//    if FormGetPic <> nil then
//      FormGetPic.Release;
//  end;
end;

procedure TfrmSketchManage.InitImage();
begin
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID=' + quotedstr(trim(fmainid)));
    sql.Add('and TFType=' + quotedstr(trim('寻样')));
    open;
  end;
end;

procedure TfrmSketchManage.B_KHPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin
        M_KHname.Text := Trim(CDS_HZ.fieldbyname('coname').AsString);

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

procedure TfrmSketchManage.ORDERNOPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmProductOrderListSel := TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal = 1 then
      begin
        if (PState = 1) and (CopyInt <> 99) then
        begin
          with ADOQueryTemp do
          begin
            Close;
            SQL.Clear;
            SQL.Add('SELECT A.* FROM JYORDER_MAIN A INNER JOIN JYORDER_SUB B  ON A.MAINID=B.MAINID WHERE A.MAINID=' + QUOTEDSTR(Trim(frmProductOrderListSel.Order_Main.fieldbyname('mainid').AsString)));
            SQL.Add('AND PRTHX=' + QUOTEDSTR(M_HXCODE.TEXT));
            Open;
          end;
          if ADOQueryTemp.IsEmpty = True then
          begin
            application.MessageBox('该指示单不存在该花型！', '提示信息', MB_ICONERROR);
            exit;
          end;
          orderno.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('orderno').AsString);
          frommainid.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('mainid').AsString);
          fromsubid.Text := Trim(frmProductOrderListSel.Order_main.fieldbyname('subid').AsString);

        end
        else
        begin
          M_COLOR.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColor').AsString);
          M_COLORNO.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColorNo').AsString);
//        M_COLORNO.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHX').AsString);
          M_KHHX.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHXKH').AsString);
          M_HXCODE.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHx').AsString);
          orderno.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('orderno').AsString);
          M_KHNAME.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('CustomerNoName').AsString);
          frommainid.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('mainid').AsString);
          fromsubid.Text := Trim(frmProductOrderListSel.Order_main.fieldbyname('subid').AsString);
          M_DBSPEC.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCODENAME').AsString);
        end;

      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;
end;

procedure TfrmSketchManage.M_DBSPECPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
//      M_COLOR.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('CYCOLOR').AsString);
//      M_COLORNO.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('CYColorNo').AsString);
////        M_COLORNO.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHX').AsString);
//      M_KHHX.Text := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTHXKH').AsString);

      M_DBSPEC.Text := CDS_Main.fieldbyname('CYno').asstring;
      M_DBname.Text := CDS_Main.fieldbyname('CYNAME').asstring;

    end;
    free;
  end;
end;

procedure TfrmSketchManage.G_FACTORYNAMEPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  fsj: string;
  FWZ: Integer;
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      FStatus := '工厂花型';
      if ShowModal = 1 then
      begin

        G_FACTORYNAME.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        G_FACTORYCODE.Text := Trim(CDS_HZ.fieldbyname('CoCODE').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;

  if G_FACTORYCODE.Text <> '' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      SQL.Add('SELECT A.*,B.CONAME FROM Company_GCFY A INNER JOIN Company B  ON A.FromCoID=B.CoID WHERE COCODE=' + QUOTEDSTR(G_FACTORYCODE.Text));
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_GC);
    SInitCDSData20(ADOQueryTemp, CDS_GC);
  end;
  HQGC();
//  JSFY2();
  JSFYAll();
end;

procedure TfrmSketchManage.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
  if Trim(M_HXCODE.Text) = '' then
  begin
    application.MessageBox('花型编号不能为空！', '提示信息', MB_ICONERROR);
    exit;
  end;
  i := CDS_SQ.RecordCount;
  i := i + 1;
  with CDS_SQ do
  begin
    Append;
    FieldByName('SQNO').Value := i;
    FieldByName('HxCode').Value := M_HXCODE.Text;
//    FieldByName('jddate').Value := Trim(FormatDateTime('yyyy-MM-dd', Now));
    Post;
  end;
end;

procedure TfrmSketchManage.ToolButton5Click(Sender: TObject);
begin
  with CDS_XM do
  begin
    Append;

    FieldByName('XMAPSJ').Value := Trim(FormatDateTime('yyyy-MM-dd', Now));
    Post;
  end;
end;

procedure TfrmSketchManage.G_ZBFACTORYNAMEPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      FStatus := '制版公司';
      if ShowModal = 1 then
      begin

        G_ZBFACTORYNAME.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        G_ZBFACTORYCODE.Text := Trim(CDS_HZ.fieldbyname('CoCODE').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
  if G_ZBFACTORYCODE.Text <> '' then
  begin
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      SQL.Add('SELECT A.*,B.CONAME FROM Company_MGFY A INNER JOIN Company B  ON A.FromCoID=B.CoID WHERE COCODE=' + QUOTEDSTR(G_ZBFACTORYCODE.Text));
//    ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryTemp, CDS_ZBGS);
    SInitCDSData20(ADOQueryTemp, CDS_ZBGS);
  end;
  HQZBGS();
  JSFYAll();
end;

procedure TfrmSketchManage.cxButton1Click(Sender: TObject);
begin
  if Trim(FMainId) = '' then
  begin
    if GetLSNo(ADOQueryCmd, FMainId, 'MG', 'Sketch_main', 4, 1) = False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('生成流水号异常！', '提示', 0);
      exit;
    end;
  end;
  FormGetPic := TFormGetPic.create(self);
  with FormGetPic do
  begin
    fFlileFlag := self.fFlileFlag;
    FMainId := self.FMainId;
    fkeyNo := IMG_SLT.Text;
    FTFType := 'MGSLT';
    pat1 := 'FileName';
    pic1 := 'FilesOther';
    if showmodal = 1 then
    begin
      IMG_SLT.Text := trim(fkeyNo);
    end;
    free;
  end;
end;

procedure TfrmSketchManage.cxButton3Click(Sender: TObject);
begin
  if Trim(FMainId) = '' then
  begin
    if GetLSNo(ADOQueryCmd, FMainId, 'MG', 'Sketch_main', 4, 1) = False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('生成流水号异常！', '提示', 0);
      exit;
    end;
  end;
  FormGetPic := TFormGetPic.create(self);
  with FormGetPic do
  begin
    fFlileFlag := self.fFlileFlag;
    FMainId := self.FMainId;
    fkeyNo := IMG_SJT.Text;
    FTFType := 'MGSJT';
    pat1 := 'FileName';
    pic1 := 'FilesOther';
    if showmodal = 1 then
    begin
      IMG_SJT.Text := trim(fkeyNo);
    end;
    free;
  end;

//  FormGetPic2 := TFormGetPic2.create(self);
//  with FormGetPic2 do
//  begin
//    fFlileFlag := self.fFlileFlag;
//    FMainId := self.FMainId;
//    fkeyNo := IMG_SJT.Text;
//    FTFType := 'MGSJT';
//    if showmodal = 1 then
//    begin
//      IMG_SJT.Text := trim(fkeyNo);
//    end;
//    free;
//  end;
end;

procedure TfrmSketchManage.TV4FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQuery1 do
  begin

    Close;
    sql.Clear;
    sql.Add('select * from Sketch_XMAP where XMID=''' + Trim(CDS_XM.fieldbyname('XMID').AsString) + '''');
    open;

  end;

end;

procedure TfrmSketchManage.cxGridDBColumn1PropertiesChange(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditValue;
  FFieldName := Trim(Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_XM do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;

  end;
  JSFYAll();
end;

procedure TfrmSketchManage.ToolButton2Click(Sender: TObject);
begin
  if CDS_SQ.IsEmpty = True then
    Exit;

  with CDS_SQ do
  begin
    CDS_SQ.Delete;
  end;
end;

procedure TfrmSketchManage.cxGridDBColumn6PropertiesChange(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  mvalue := TcxTextEdit(Sender).EditValue;
  FFieldName := Trim(Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_XM do
  begin
    Edit;
    FieldByName(FFieldName).Value := mvalue;
    Post;

  end;
  JSFYAll();
end;

procedure TfrmSketchManage.G_PYWChange(Sender: TObject);
begin
  HQZBGS();
  JSFYAll();
end;

procedure TfrmSketchManage.G_YMGClick(Sender: TObject);
begin
  HQZBGS();
  JSFYAll();
end;

procedure TfrmSketchManage.F_YSTSExit(Sender: TObject);
begin
  JSFYAll();
end;

procedure TfrmSketchManage.cxTabSheet1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ToolBar1.SetFocus;
end;

procedure TfrmSketchManage.V2Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin

        with CDS_SQ do
        begin
          Edit;
          FieldByName('SQKHNAME').Value := Trim(CDS_HZ.fieldbyname('coname').AsString);
          FieldByName('SQGJ').Value := Trim(CDS_HZ.fieldbyname('Coarea').AsString);

          Post;
        end;

      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
  tv3.Controller.EditingController.ShowEdit();
end;

procedure TfrmSketchManage.N1Click(Sender: TObject);
var
  i: Integer;
begin
  if Trim(M_HXCODE.Text) = '' then
  begin
    application.MessageBox('花型编号不能为空！', '提示信息', MB_ICONERROR);
    exit;
  end;
  i := CDS_SQ.RecordCount;
  i := i + 1;
  with CDS_SQ do
  begin
    Append;
    FieldByName('SQNO').Value := i;
    FieldByName('HxCode').Value := M_HXCODE.Text;
//    FieldByName('jddate').Value := Trim(FormatDateTime('yyyy-MM-dd', Now));
    Post;
  end;
end;

procedure TfrmSketchManage.cxGridDBColumn4PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FFieldName: string;
begin
  if TcxTextEdit(Sender).EditValue = NULL then
  begin
    mvalue := '';
  end
  else
  begin
    mvalue := TcxTextEdit(Sender).EditValue;
  end;

  FFieldName := Trim(Tv4.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_XM do
  begin
    Edit;
    if mvalue <> '' then
    begin
      FieldByName(FFieldName).Value := mvalue;
    end
    else
    begin
      FieldByName(FFieldName).AsString := '';
    end;

    Post;

  end;

  JSFYAll();
end;

end.

