unit U_TatMachInsp;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxCalendar, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, RM_Common, RM_Class, RM_GridReport,
  RM_System, RM_Dataset, ADODB, DBClient, cxGridCustomPopupMenu, cxGridPopupMenu,
  ExtCtrls, ComCtrls, ToolWin, cxTextEdit, Buttons, cxSplitter, cxCheckBox,
  MovePanel, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, Menus,
  U_BaseList, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
  dxBarBuiltInMenu, cxContainer, cxImage, cxDBEdit, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, ShellAPI, IdFTP,
  FireDAC.Stan.StorageXML, cxPC, XMLDoc, XMLIntf, DateUtils, cxMaskEdit,
  cxButtonEdit, BtnEdit, dxScrollbarAnnotations;

type
  TfrmTatMachInsp = class(TfrmBaseList)
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    GPM_1: TcxGridPopupMenu;
    ADOQueryMain: TADOQuery;
    ADOCmd: TADOQuery;
    RMDB_1: TRMDBDataSet;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    ADOQueryPrint: TADOQuery;
    GPM_2: TcxGridPopupMenu;
    ADOQueryMainDSC: TADOQuery;
    RM1: TRMGridReport;
    ADOTmp: TADOQuery;
    ScrollBox1: TScrollBox;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton21: TSpeedButton;
    SpeedButton22: TSpeedButton;
    SpeedButton23: TSpeedButton;
    SpeedButton24: TSpeedButton;
    SpeedButton25: TSpeedButton;
    SpeedButton26: TSpeedButton;
    SpeedButton29: TSpeedButton;
    SpeedButton30: TSpeedButton;
    SpeedButton31: TSpeedButton;
    SpeedButton32: TSpeedButton;
    SpeedButton33: TSpeedButton;
    SpeedButton34: TSpeedButton;
    SpeedButton37: TSpeedButton;
    SpeedButton38: TSpeedButton;
    SpeedButton39: TSpeedButton;
    SpeedButton40: TSpeedButton;
    SpeedButton41: TSpeedButton;
    SpeedButton42: TSpeedButton;
    SpeedButton45: TSpeedButton;
    SpeedButton46: TSpeedButton;
    SpeedButton47: TSpeedButton;
    SpeedButton48: TSpeedButton;
    SpeedButton50: TSpeedButton;
    SpeedButton51: TSpeedButton;
    SpeedButton54: TSpeedButton;
    SpeedButton55: TSpeedButton;
    CDS_3: TClientDataSet;
    DS_3: TDataSource;
    ADOQueryImage: TADOQuery;
    DataSource2: TDataSource;
    IdFTP1: TIdFTP;
    Panel4: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Tv3Column1: TcxGridDBColumn;
    MovePanel1: TMovePanel;
    Label17: TLabel;
    Label18: TLabel;
    lblLenUnit1: TLabel;
    CIFBeg: TEdit;
    Button1: TButton;
    Button4: TButton;
    CIFEnd: TEdit;
    CIFQty: TEdit;
    RadioGroup1: TRadioGroup;
    Button2: TButton;
    Tv3Column4: TcxGridDBColumn;
    cxStyle4: TcxStyle;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    查看: TcxTabSheet;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    tv2CDType: TcxGridDBColumn;
    tv2CDWZ: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    Tv2CDQty: TcxGridDBColumn;
    Tv2CDReason: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    cxGridDBColumn8: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    lblCIFName: TLabel;
    Label2: TLabel;
    Label8: TLabel;
    CIFNumber: TEdit;
    Panel9: TPanel;
    Panel2: TPanel;
    lblLenUnit: TLabel;
    Label5: TLabel;
    InputLen: TEdit;
    BTPrint: TButton;
    ToolBar2: TToolBar;
    ToolButton3: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    GPM_3: TcxGridPopupMenu;
    Panel6: TPanel;
    Label35: TLabel;
    Label16: TLabel;
    Label26: TLabel;
    edtChen: TEdit;
    edtMaBiao: TEdit;
    ComboBox1: TComboBox;
    Edit6: TEdit;
    Label6: TLabel;
    Panel10: TPanel;
    Label14: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    Label1: TLabel;
    Loom: TEdit;
    Repairer: TEdit;
    CodeName: TEdit;
    edtScan: TEdit;
    Button3: TButton;
    ToolButton4: TToolButton;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    Label7: TLabel;
    edtMBDW: TEdit;
    Label9: TLabel;
    MinLen: TEdit;
    Label15: TLabel;
    MinWeight: TEdit;
    MaxLen: TEdit;
    MaxWeight: TEdit;
    Label19: TLabel;
    MPlace: TEdit;
    Label20: TLabel;
    Label21: TLabel;
    YPlace: TEdit;
    Label27: TLabel;
    KgPlace: TEdit;
    Label28: TLabel;
    Label33: TLabel;
    Label13: TLabel;
    Label22: TLabel;
    Label4: TLabel;
    Label11: TLabel;
    InputWeight: TEdit;
    Tare: TEdit;
    Label3: TLabel;
    lblRuleConversion: TLabel;
    Coefficient: TEdit;
    Label29: TLabel;
    Label30: TLabel;
    SPEC: TEdit;
    MF: TEdit;
    Label32: TLabel;
    KZ: TEdit;
    Label31: TLabel;
    code: TEdit;
    Label50: TLabel;
    Panel3: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton92: TSpeedButton;
    SpeedButton102: TSpeedButton;
    Button7: TButton;
    Panel1: TPanel;
    Label44: TLabel;
    Label45: TLabel;
    SpeedButton113: TSpeedButton;
    Button9: TButton;
    carno: TEdit;
    Label10: TLabel;
    Edit7: TEdit;
    Label25: TLabel;
    Button6: TButton;
    Button8: TButton;
    cxPageControl2: TcxPageControl;
    cxTabSheet2: TcxTabSheet;
    cxTabSheet3: TcxTabSheet;
    cxTabSheet4: TcxTabSheet;
    cxTabSheet5: TcxTabSheet;
    PNL1: TPanel;
    PNL1_6: TPanel;
    Label12: TLabel;
    SEL1: TEdit;
    SEL2: TEdit;
    SEL3: TEdit;
    SEL4: TEdit;
    SEL5: TEdit;
    PNL1_4: TPanel;
    Label34: TLabel;
    METER1: TEdit;
    METER2: TEdit;
    METER3: TEdit;
    METER4: TEdit;
    METER5: TEdit;
    PNL1_3: TPanel;
    Label36: TLabel;
    PNL1_2: TPanel;
    Label37: TLabel;
    CODE1: TEdit;
    CODE2: TEdit;
    CODE3: TEdit;
    CODE4: TEdit;
    CODE5: TEdit;
    PNL1_1: TPanel;
    Label38: TLabel;
    MF1: TEdit;
    MF2: TEdit;
    MF3: TEdit;
    MF4: TEdit;
    MF5: TEdit;
    PNL1_5: TPanel;
    Label39: TLabel;
    KG1: TEdit;
    KG2: TEdit;
    KG3: TEdit;
    KG4: TEdit;
    KG5: TEdit;
    PNL2: TPanel;
    PNL2_6: TPanel;
    Label40: TLabel;
    SEL6: TEdit;
    SEL7: TEdit;
    SEL8: TEdit;
    SEL9: TEdit;
    SEL10: TEdit;
    PNL2_4: TPanel;
    Label41: TLabel;
    METER6: TEdit;
    METER7: TEdit;
    METER8: TEdit;
    METER9: TEdit;
    METER10: TEdit;
    PNL2_2: TPanel;
    Label43: TLabel;
    CODE6: TEdit;
    CODE7: TEdit;
    CODE8: TEdit;
    CODE9: TEdit;
    CODE10: TEdit;
    PNL2_1: TPanel;
    Label46: TLabel;
    MF6: TEdit;
    MF7: TEdit;
    MF8: TEdit;
    MF9: TEdit;
    MF10: TEdit;
    PNL2_5: TPanel;
    Label47: TLabel;
    KG6: TEdit;
    KG7: TEdit;
    KG8: TEdit;
    KG9: TEdit;
    KG10: TEdit;
    PNL3: TPanel;
    PNL3_6: TPanel;
    Label48: TLabel;
    SEL11: TEdit;
    SEL12: TEdit;
    SEL13: TEdit;
    SEL14: TEdit;
    SEL15: TEdit;
    PNL3_4: TPanel;
    Label49: TLabel;
    METER11: TEdit;
    METER12: TEdit;
    METER13: TEdit;
    METER14: TEdit;
    METER15: TEdit;
    PNL3_2: TPanel;
    Label52: TLabel;
    CODE11: TEdit;
    CODE12: TEdit;
    CODE13: TEdit;
    CODE14: TEdit;
    CODE15: TEdit;
    PNL3_1: TPanel;
    Label53: TLabel;
    MF11: TEdit;
    MF12: TEdit;
    MF13: TEdit;
    MF14: TEdit;
    MF15: TEdit;
    PNL3_5: TPanel;
    Label54: TLabel;
    KG11: TEdit;
    KG12: TEdit;
    KG13: TEdit;
    KG14: TEdit;
    KG15: TEdit;
    PNL4: TPanel;
    PNL4_6: TPanel;
    Label55: TLabel;
    SEL16: TEdit;
    SEL17: TEdit;
    SEL18: TEdit;
    SEL19: TEdit;
    SEL20: TEdit;
    PNL4_4: TPanel;
    Label56: TLabel;
    METER16: TEdit;
    METER17: TEdit;
    METER18: TEdit;
    METER19: TEdit;
    METER20: TEdit;
    PNL4_2: TPanel;
    Label58: TLabel;
    CODE16: TEdit;
    CODE17: TEdit;
    CODE18: TEdit;
    CODE19: TEdit;
    CODE20: TEdit;
    PNL4_1: TPanel;
    Label59: TLabel;
    MF16: TEdit;
    MF17: TEdit;
    MF18: TEdit;
    MF19: TEdit;
    MF20: TEdit;
    PNL4_5: TPanel;
    Label60: TLabel;
    KG16: TEdit;
    KG17: TEdit;
    KG18: TEdit;
    KG19: TEdit;
    KG20: TEdit;
    Grade1: TComboBox;
    Label61: TLabel;
    Label62: TLabel;
    yg1: TEdit;
    Button10: TButton;
    Label63: TLabel;
    yg2: TEdit;
    Button11: TButton;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    JK1: TComboBox;
    JK2: TComboBox;
    JK3: TComboBox;
    JK4: TComboBox;
    JK5: TComboBox;
    PNL2_3: TPanel;
    Label42: TLabel;
    JK6: TComboBox;
    JK7: TComboBox;
    JK8: TComboBox;
    JK9: TComboBox;
    JK10: TComboBox;
    PNL3_3: TPanel;
    Label51: TLabel;
    JK11: TComboBox;
    JK12: TComboBox;
    JK13: TComboBox;
    JK14: TComboBox;
    JK15: TComboBox;
    PNL4_3: TPanel;
    Label57: TLabel;
    JK16: TComboBox;
    JK17: TComboBox;
    JK18: TComboBox;
    JK19: TComboBox;
    JK20: TComboBox;
    Label64: TLabel;
    fbmeter: TEdit;
    Label65: TLabel;
    xjmeter: TEdit;
    Label66: TLabel;
    CBGS: TEdit;
    ADOQuery1: TADOQuery;
    Tv2Column1: TcxGridDBColumn;
    SpeedButton19: TSpeedButton;
    Label67: TLabel;
    Label68: TLabel;
    Label69: TLabel;
    tube: TEdit;
    Packaging: TEdit;
    Seal: TEdit;
    Button5: TButton;
    Label70: TLabel;
    Label71: TLabel;
    batchno: TEdit;
    PCID: TEdit;
    SpeedButton20: TSpeedButton;
    PNL1_7: TPanel;
    Label72: TLabel;
    SH1: TEdit;
    SH2: TEdit;
    SH3: TEdit;
    SH4: TEdit;
    SH5: TEdit;
    Pnl2_7: TPanel;
    Label73: TLabel;
    SH6: TEdit;
    SH7: TEdit;
    SH8: TEdit;
    SH9: TEdit;
    SH10: TEdit;
    pnl3_7: TPanel;
    Label74: TLabel;
    SH11: TEdit;
    SH12: TEdit;
    SH13: TEdit;
    SH14: TEdit;
    SH15: TEdit;
    PnL4_7: TPanel;
    Label75: TLabel;
    sh16: TEdit;
    sh17: TEdit;
    sh18: TEdit;
    sh19: TEdit;
    sh20: TEdit;
    Tv3Column3: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv3Column6: TcxGridDBColumn;
    ToolBar1: TToolBar;
    ToolButton9: TToolButton;
    grade: TcxButtonEdit;
    Timer1: TTimer;
    Label77: TLabel;
    koumi: TEdit;
    Label76: TLabel;
    DXMETER: TEdit;
    Button12: TButton;
    Label78: TLabel;
    Edit1: TEdit;
    Label79: TLabel;
    issp: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure BTPrintClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure edtScanKeyPress(Sender: TObject; var Key: Char);
    procedure CIFBegClick(Sender: TObject);
    procedure CIFEndChange(Sender: TObject);
    procedure Edit6Click(Sender: TObject);
    procedure MJstr3KeyPress(Sender: TObject; var Key: Char);
    procedure Button2Click(Sender: TObject);
    procedure edtScanClick(Sender: TObject);
    procedure NetWeightKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure edtChenClick(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure edtYJClick(Sender: TObject);
    procedure Pic_Image1DblClick(Sender: TObject);
    procedure Tv3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
    procedure lblLenUnitClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure MinLenExit(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure carnoBtnClick(Sender: TObject);
//    procedure OutPutQty1Change(Sender: TObject);

    procedure carnoClick(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure SpeedButton113Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure SEL1Click(Sender: TObject);
    procedure METER1Change(Sender: TObject);
    procedure METER2Change(Sender: TObject);
    procedure METER3Change(Sender: TObject);
    procedure METER4Change(Sender: TObject);
    procedure METER5Change(Sender: TObject);
    procedure METER6Change(Sender: TObject);
    procedure METER7Change(Sender: TObject);
    procedure METER8Change(Sender: TObject);
    procedure METER9Change(Sender: TObject);
    procedure METER10Change(Sender: TObject);
    procedure METER11Change(Sender: TObject);
    procedure METER12Change(Sender: TObject);
    procedure METER13Change(Sender: TObject);
    procedure METER14Change(Sender: TObject);
    procedure METER15Change(Sender: TObject);
    procedure METER16Change(Sender: TObject);
    procedure METER17Change(Sender: TObject);
    procedure METER18Change(Sender: TObject);
    procedure METER19Change(Sender: TObject);
    procedure METER20Change(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure SpeedButton19Click(Sender: TObject);
    procedure METER1KeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton9Click(Sender: TObject);
    procedure gradeClick(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure SealClick(Sender: TObject);
    procedure PackagingClick(Sender: TObject);
    procedure tubeClick(Sender: TObject);
    procedure Edit1Click(Sender: TObject);
  private
    { Private declarations }
    FCIID, FOperationStatus, FCIFName, FWorkshop: string;
    FOrderNo, FMainId, FSubId, FPCId, FConNo, FConMId, FConSId: string;
    FLoom, FBatchNO, FLenUnit, FC_Code, FC_Name, FC_Spec, FC_Width, FC_GramWeight: string;
    FC_Color, FC_ColorNo, FC_StyleNo, FC_Pattern, FC_CustPattern, FC_ColorDepth: string;
    FFtyPCId, FGangNo, FBCIOID, fmxid: string;
    FMFFlag: string;
    FPieceNo, FXJCount: Integer;
    IsCommopen: boolean;
    FNAME, FCODE, FMF, FMETER, FKG, fsunhao, FSHREASON, FYMETER, FYWIDTH, fyciid: string;
    FXS: DOUBLE;
    FXSTYPE: string;
    procedure SetINIFile();  //设置配置文件
    procedure GetINIFile(); //设置长度单位
    procedure SetUnit(MUnit: string); //设置长度单位
    procedure SetDdetails(); //刷新详细信息
    procedure InitCDPanel(); //刷新疵点选项
    procedure InitCDGrid(MCIID: string); //刷新疵点登记信息
    procedure InitCDGridCX(MCIID: string); //刷新疵点查询信息
    procedure InitJYGrid(); //刷新检验信息
    function CheckData(CKType: string): Boolean; //校验数据
    function SaveData(FINT: Integer): Boolean; //保存数据

    procedure SetKGVisibility(F1: Integer);
    function SaveData2(meter: double; grossweight: double): Boolean; //保存数据
    procedure InitLCK(MPCId: string);  //扫描流程卡
    procedure InitJTM(MCIID: string);  //扫描卷条码
    procedure Initedit();  //取框值
    procedure ClearGlobal(); //清除全局ID
    procedure PrtData(MCIID: string);  //打印卷标签
    procedure QuantityConversion();  //数量换算
    procedure InitImage(YFTPName: string);
    procedure InitImageHX(HXSID: string);   //图片
    procedure Initclearsel();
    procedure Settrue();
    procedure LookImage(FileName: string);
    procedure VisbleControl(Panel55: TWinControl; XS: Boolean; SXCount: Integer);
    procedure OpenCom(DllName: string);     //打开串口
    procedure CloseCom(DllName: string);    //关闭串口
    procedure On1201(var Message: Tmessage); message 1201;   //电子称
    procedure On1301(var Message: Tmessage); message 1301;   //码表
    procedure On1302(var Message: Tmessage); message 1302;   //码表
    procedure On1303(var Message: Tmessage); message 1303;   //码表
    procedure On1304(var Message: Tmessage); message 1304;   //码表
  public
    fmanage: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmTatMachInsp: TfrmTatMachInsp;
  newh, newh1: hwnd;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_iniParam, U_EmployeeSel, U_TatClothInfoSel,
  U_SCPersonColor, U_SCPersonColor2, U_SCPersonColor3, U_SCPersonColor4;

{$R *.dfm}
procedure TfrmTatMachInsp.On1201(var Message: Tmessage);
var
  i1, i2: integer;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  i2 := Message.LParam;

  if trim(edtChen.Text) = '√' then
  begin
    InputWeight.Text := format('%.2f', [i1 / 100000]);
  end;

end;

procedure TfrmTatMachInsp.Settrue();
begin
        //1-5
  VisbleControl(pnl1_1, true, pnl1_1.ControlCount);
  VisbleControl(pnl1_2, true, pnl1_2.ControlCount);
  VisbleControl(pnl1_3, true, pnl1_3.ControlCount);
  VisbleControl(pnl1_4, true, pnl1_4.ControlCount);
  VisbleControl(pnl1_5, true, pnl1_5.ControlCount);
  VisbleControl(pnl1_6, true, pnl1_6.ControlCount);
  VisbleControl(pnl1_7, true, pnl1_7.ControlCount);
          //6-10
  VisbleControl(pnl2_1, true, pnl2_1.ControlCount);
  VisbleControl(pnl2_2, true, pnl2_2.ControlCount);
  VisbleControl(pnl2_3, true, pnl2_3.ControlCount);
  VisbleControl(pnl2_4, true, pnl2_4.ControlCount);
  VisbleControl(pnl2_5, true, pnl2_5.ControlCount);
  VisbleControl(pnl2_6, true, pnl2_6.ControlCount);
  VisbleControl(pnl2_7, true, pnl2_7.ControlCount);
            //11-15
  VisbleControl(pnl3_1, true, pnl3_1.ControlCount);
  VisbleControl(pnl3_2, true, pnl3_2.ControlCount);
  VisbleControl(pnl3_3, true, pnl3_3.ControlCount);
  VisbleControl(pnl3_4, true, pnl3_4.ControlCount);
  VisbleControl(pnl3_5, true, pnl3_5.ControlCount);
  VisbleControl(pnl3_6, true, pnl3_6.ControlCount);
  VisbleControl(pnl3_7, true, pnl3_7.ControlCount);
              //16-20
  VisbleControl(pnl4_1, true, pnl4_1.ControlCount);
  VisbleControl(pnl4_2, true, pnl4_2.ControlCount);
  VisbleControl(pnl4_3, true, pnl4_3.ControlCount);
  VisbleControl(pnl4_4, true, pnl4_4.ControlCount);
  VisbleControl(pnl4_5, true, pnl4_5.ControlCount);
  VisbleControl(pnl4_6, true, pnl4_6.ControlCount);
  VisbleControl(pnl4_7, true, pnl4_7.ControlCount);
end;

procedure TfrmTatMachInsp.Initclearsel();
var
  I: Integer;
begin
  with PNL1_6 do
  begin
    for I := 0 to ControlCount - 1 do
    begin
      if Controls[I] is TEdit then
      begin

        TcxTextEdit(Controls[I]).Text := '';
      end;
    end;
  end;
  with PNL2_6 do
  begin
    for I := 0 to ControlCount - 1 do
    begin
      if Controls[I] is TEdit then
      begin

        TcxTextEdit(Controls[I]).Text := '';
      end;
    end;
  end;
  with PNL3_6 do
  begin
    for I := 0 to ControlCount - 1 do
    begin
      if Controls[I] is TEdit then
      begin

        TcxTextEdit(Controls[I]).Text := '';
      end;
    end;
  end;
  with PNL4_6 do
  begin
    for I := 0 to ControlCount - 1 do
    begin

      if Controls[I] is TEdit then
      begin

        TcxTextEdit(Controls[I]).Text := '';
      end;
    end;
  end;
end;

procedure TfrmTatMachInsp.InitEdit();
var
  i: integer;
begin
  i := 1;
  with ADOTMP do
  begin
    close;
    sql.Clear;
    sql.Add('select * from BS_CLOTH_IO_MX where bcioid=''' + Trim(FBCIOID) + ''' ');
    open;
  end;
  if not ADOTMP.IsEmpty then
  begin
    while not ADOTMP.Eof do
    begin
//      TEdit(FindComponent('MF' + Trim(IntToStr(i)))).Text := '';
//      TEdit(FindComponent('CODE' + Trim(IntToStr(i)))).Text := '';
//      TEdit(FindComponent('NAME' + Trim(IntToStr(i)))).Text := ADOTMP.fieldbyName('C_MXNAME').AsString;
      i := i + 1;
      ADOTMP.next;
    end;
  end;
  for i := 1 to 20 do
  begin

    TEdit(FindComponent('MF' + Trim(IntToStr(i)))).Text := '';

    TEdit(FindComponent('CODE' + Trim(IntToStr(i)))).Text := '';
  end;
end;

procedure TfrmTatMachInsp.VisbleControl(Panel55: TWinControl; XS: Boolean; SXCount: Integer);
var
  i: Integer;
begin
  with Panel55 do
  begin
    for i := 0 to SXCount - 1 do
    begin
      if Controls[i] is TEdit then
      begin
        TEdit(Controls[i]).Visible := XS;
      end;
      if Controls[i] is TLabel then
      begin
        TEdit(Controls[i]).Visible := true;
      end;
      if Controls[i] is TComboBox then
      begin
        TEdit(Controls[i]).Visible := XS;
      end;
    end;
  end;
end;

procedure TfrmTatMachInsp.SetKGVisibility(F1: Integer);
var
  i: Integer;
  kgEdit: TEdit;
  controlName: string;
begin
  ClearControl(pnl1_1, 0);
  ClearControl(pnl1_2, 0);
  ClearControl(pnl1_3, 0);
  ClearControl(pnl1_4, 0);
  ClearControl(pnl1_5, 0);

    //6-10
  ClearControl(pnl2_1, 0);
  ClearControl(pnl2_2, 0);
  ClearControl(pnl2_3, 0);
  ClearControl(pnl2_4, 0);
  ClearControl(pnl2_5, 0);

      //11-15
  ClearControl(pnl3_1, 0);
  ClearControl(pnl3_2, 0);
  ClearControl(pnl3_3, 0);
  ClearControl(pnl3_4, 0);
  ClearControl(pnl3_5, 0);

        //16-20
  ClearControl(pnl4_1, 0);
  ClearControl(pnl4_2, 0);
  ClearControl(pnl4_3, 0);
  ClearControl(pnl4_4, 0);
  ClearControl(pnl4_5, 0);

          //1-5
  VisbleControl(pnl1_1, False, pnl1_1.ControlCount);
  VisbleControl(pnl1_2, False, pnl1_2.ControlCount);
  VisbleControl(pnl1_3, False, pnl1_3.ControlCount);
  VisbleControl(pnl1_4, False, pnl1_4.ControlCount);
  VisbleControl(pnl1_5, False, pnl1_5.ControlCount);
  VisbleControl(pnl1_6, False, pnl1_6.ControlCount);
          //6-10
  VisbleControl(pnl2_1, False, pnl2_1.ControlCount);
  VisbleControl(pnl2_2, False, pnl2_2.ControlCount);
  VisbleControl(pnl2_3, False, pnl2_3.ControlCount);
  VisbleControl(pnl2_4, False, pnl2_4.ControlCount);
  VisbleControl(pnl2_5, False, pnl2_5.ControlCount);
  VisbleControl(pnl2_6, False, pnl2_6.ControlCount);

            //11-15
  VisbleControl(pnl3_1, False, pnl3_1.ControlCount);
  VisbleControl(pnl3_2, False, pnl3_2.ControlCount);
  VisbleControl(pnl3_3, False, pnl3_3.ControlCount);
  VisbleControl(pnl3_4, False, pnl3_4.ControlCount);
  VisbleControl(pnl3_5, False, pnl3_5.ControlCount);
  VisbleControl(pnl3_6, False, pnl3_6.ControlCount);

              //16-20
  VisbleControl(pnl4_1, False, pnl4_1.ControlCount);
  VisbleControl(pnl4_2, False, pnl4_2.ControlCount);
  VisbleControl(pnl4_3, False, pnl4_3.ControlCount);
  VisbleControl(pnl4_4, False, pnl4_4.ControlCount);
  VisbleControl(pnl4_5, False, pnl4_5.ControlCount);
  VisbleControl(pnl4_6, False, pnl4_6.ControlCount);

  if F1 < 6 then
  begin
          //1-5
    VisbleControl(pnl1_1, true, F1 + 1);
    VisbleControl(pnl1_2, true, F1 + 1);
    VisbleControl(pnl1_3, true, F1 + 1);
    VisbleControl(pnl1_4, true, F1 + 1);
    VisbleControl(pnl1_5, true, F1 + 1);
    VisbleControl(pnl1_6, true, F1 + 1);
         // ClearControl(Panel1,Trim(Cds_Main.fieldbyname('SPMF').AsString),Panel1.ControlCount);
  end
  else if F1 < 11 then
  begin
          //1-10
    VisbleControl(pnl1_1, true, 6);
    VisbleControl(pnl1_2, true, 6);
    VisbleControl(pnl1_3, true, 6);
    VisbleControl(pnl1_4, true, 6);
    VisbleControl(pnl1_5, true, 6);
    VisbleControl(pnl1_6, true, 6);
          //11-20
    VisbleControl(pnl2_1, true, F1 - 4);
    VisbleControl(pnl2_2, true, F1 - 4);
    VisbleControl(pnl2_3, true, F1 - 4);
    VisbleControl(pnl2_4, true, F1 - 4);
    VisbleControl(pnl2_5, true, F1 - 4);
    VisbleControl(pnl2_6, true, F1 - 4);
  end
  else if F1 < 16 then
  begin
    VisbleControl(pnl1_1, true, 6);
    VisbleControl(pnl1_2, true, 6);
    VisbleControl(pnl1_3, true, 6);
    VisbleControl(pnl1_4, true, 6);
    VisbleControl(pnl1_5, true, 6);
    VisbleControl(pnl1_6, true, 6);
    VisbleControl(pnl2_1, true, 6);
    VisbleControl(pnl2_2, true, 6);
    VisbleControl(pnl2_3, true, 6);
    VisbleControl(pnl2_4, true, 6);
    VisbleControl(pnl2_5, true, 6);
    VisbleControl(pnl2_6, true, 6);

    VisbleControl(pnl3_1, true, F1 - 9);
    VisbleControl(pnl3_2, true, F1 - 9);
    VisbleControl(pnl3_3, true, F1 - 9);
    VisbleControl(pnl3_4, true, F1 - 9);
    VisbleControl(pnl3_5, true, F1 - 9);
    VisbleControl(pnl3_6, true, F1 - 9);
  end
  else
  begin
    VisbleControl(pnl1_1, true, 6);
    VisbleControl(pnl1_2, true, 6);
    VisbleControl(pnl1_3, true, 6);
    VisbleControl(pnl1_4, true, 6);
    VisbleControl(pnl1_5, true, 6);
    VisbleControl(pnl1_6, true, 6);
    VisbleControl(pnl2_1, true, 6);
    VisbleControl(pnl2_2, true, 6);
    VisbleControl(pnl2_3, true, 6);
    VisbleControl(pnl2_4, true, 6);
    VisbleControl(pnl2_5, true, 6);
    VisbleControl(pnl2_6, true, 6);
    VisbleControl(pnl3_1, true, 6);
    VisbleControl(pnl3_2, true, 6);
    VisbleControl(pnl3_3, true, 6);
    VisbleControl(pnl3_4, true, 6);
    VisbleControl(pnl3_5, true, 6);
    VisbleControl(pnl3_6, true, 6);

    VisbleControl(pnl4_1, true, F1 - 14);
    VisbleControl(pnl4_2, true, F1 - 14);
    VisbleControl(pnl4_3, true, F1 - 14);
    VisbleControl(pnl4_4, true, F1 - 14);
    VisbleControl(pnl4_5, true, F1 - 14);
    VisbleControl(pnl4_6, true, F1 - 14);
  end;

end;

function TfrmTatMachInsp.SaveData2(meter: double; grossweight: double): Boolean;
var
  maxno, MCIID, strsql: string;
  MInputLen, MMeter, MYardage: Double;
  MInputWeight, MGrossWeight, MNetWeight, MTare: Double;
begin
  fmainid := '';
  fsubid := '';
  if FOperationStatus = '卷条码' then
  begin
    MCIID := FCIID;
  end
  else
  begin
    MCIID := '';
  end;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Tat_Cloth_Inspect where CIID=''' + Trim(MCIID) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(MCIID) = '' then
      begin
        if not GetLSNo(ADOTmp, maxno, 'T' + Trim(SCXFlag), 'Tat_Cloth_Inspect', 4, 1) then
          raise Exception.Create('获取条码失败！');
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('CIID').Value := Trim(maxno);
      end
      else
      begin
        maxno := Trim(MCIID);
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTmp);
      end;

     /////////////////////////           保存重量         /////////////////////////

      MTare := StrToFloatdef(trim(Tare.Text), 0);
      MInputWeight := RoundFloat(StrToFloatdef(trim(InputWeight.Text), 0), StrTointdef(KgPlace.Text, 0));
      MGrossWeight := MInputWeight + MTare; //毛重
      MNetWeight := MInputWeight;  //净重
      FieldByName('InputWeight').Value := grossweight;
      FieldByName('GrossWeight').Value := grossweight;
      FieldByName('NetWeight').Value := grossweight;
      FieldByName('Tare').Value := MTare;
      /////////////////////////           保存重量         /////////////////////////
      ///
      /////////////////////////           保存长度         /////////////////////////
      MInputLen := RoundFloat(StrToFloatdef(trim(InputLen.Text), 0), 1);
      if lblLenUnit.Caption = 'M' then
      begin
        MMeter := RoundFloat(meter, StrTointdef(MPlace.Text, 0));
        MYardage := RoundFloat(meter / 0.9144, StrTointdef(YPlace.Text, 0));
      end
      else
      begin
        MYardage := RoundFloat(meter, StrTointdef(YPlace.Text, 0));
        MMeter := RoundFloat(meter * 0.9144, StrTointdef(MPlace.Text, 0));
      end;

      FieldByName('InputLen').Value := RoundFloat(StrToFloatdef(trim(InputLen.Text), 0), 1);
      FieldByName('Meter').Value := MMeter;
      FieldByName('Yardage').Value := MYardage;
      FieldByName('LenUnit').Value := TRIM(lblLenUnit.Caption);
      /////////////////////////           保存长度         /////////////////////////
      FieldByName('Coefficient').Value := StrToFloatdef(Coefficient.text, 0);

      FieldByName('Grade').Value := Grade.text;

      FieldByName('PieceNo').Value := 0;
      FieldByName('BCIOID').Value := FBCIOID;
      FieldByName('OrderNo').value := Trim(FOrderNo);
      if fmainid = '' then
      begin
        FieldByName('MainId').value := '无订单';
      end
      else
      begin
        FieldByName('MainId').value := Trim(FMainId);
      end;
      if FSubId = '' then
      begin
        FieldByName('SubId').value := '无订单';
      end
      else
      begin
        FieldByName('SubId').value := Trim(FSubId);
      end;

      FieldByName('Workshop').value := Trim(FWorkshop);
      FieldByName('CIIOFlag').Value := '未入库';
      FieldByName('PCId').value := FPCId;
      FieldByName('C_Code').value := trim(code.Text);
      FieldByName('C_Name').value := trim(codename.Text);

      FieldByName('C_Spec').value := trim(Spec.Text);
      FieldByName('C_Color').value := FC_Color;
      FieldByName('C_ColorNo').value := FC_ColorNo;
      FieldByName('C_StyleNo').value := FC_StyleNo;
      FieldByName('C_Width').value := trim(mf.Text);
      FieldByName('C_GramWeight').value := trim(kz.Text);
      FieldByName('C_Pattern').value := FC_Pattern;
      FieldByName('C_CustPattern').value := FC_CustPattern;

      FieldByName('CIMachNo').Value := Trim(SCXFlag);

      FieldByName('CARNO').Value := Trim(CARNO.Text);

      Post;
    end;

    MCIID := Trim(maxno);   //卷条码
    FCIID := Trim(maxno);

    //保存挡车工信息
//////////////////       保存疵点信息       //////////////////
    with CDS_2 do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_2.fieldbyname('CIFID').AsString) = '' then
        begin
          if not GetLSNo(ADOTmp, maxno, 'JC', 'Tat_Cloth_Inspect_Flaw', 5, 1) then
            raise Exception.Create('获取疵点失败！');
        end
        else
        begin
          maxno := Trim(CDS_2.fieldbyname('CIFID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Tat_Cloth_Inspect_Flaw  ');
          sql.Add(' where CIFID=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_2.fieldbyname('CIFID').AsString) = '' then
            Append
          else
            Edit;
          RTSetSaveDataCDS(ADOCmd, Tv2, CDS_2, 'Tat_Cloth_Inspect_Flaw', 0);
          FieldByName('CIID').Value := Trim(MCIID);
          FieldByName('CIFID').Value := Trim(maxno);
          Post;
        end;
        CDS_2.Edit;
        CDS_2.FieldByName('CIID').Value := Trim(MCIID);
        CDS_2.FieldByName('CIFID').Value := Trim(maxno);
        Next;
      end;
    end;
//////////////////       保存疵点信息       //////////////////
///
//////////////////       更新卷号疵点信息       //////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Tat_Insp_Up @CIID=''' + trim(MCIID) + '''');
      if FOperationStatus = '布票' then
        sql.Add(',@InspType=' + QuotedStr('布票'))
      else
        sql.Add(',@InspType=' + QuotedStr('单卷修改'));
      execsql;
    end;
//////////////////       更新卷号疵点信息       //////////////////
//////////////////       更新进度       //////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into Tat_Need_Up(UType,UDataId) values(''机台检验'',' + quotedstr(maxno) + ')  ');
      execsql;
    end;
//////////////////       更新进度       //////////////////
///
    ADOCmd.Connection.CommitTrans;

//////////////////       出入库及库存       //////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Tat_Insp_In_Stk @CIID=''' + trim(MCIID) + '''');
      Open;
    end;
    if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      application.MessageBox(PChar(trim(ADOCmd.FieldByName('ShowMsg').AsString)), '提示信息', 0);
      Result := False;
    end
    else
    begin
      Result := True;
    end;
//////////////////       出入库及库存       //////////////////
    Result := True;
  except
    ADOCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    Result := False;
  end;
end;

procedure TfrmTatMachInsp.SealClick(Sender: TObject);
begin
  try
    frmSCPersonColor2 := TfrmSCPersonColor2.Create(self);
    with frmSCPersonColor2 do
    begin
      FType := '腰封';
      if ShowModal = 1 then
      begin

        Self.Seal.Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor2.close;
  end;
end;

procedure TfrmTatMachInsp.SEL1Click(Sender: TObject);
var
  mMFID: string;
  mIDNum: Integer;
begin
  initclearsel();

  TcxTextEdit(Sender).Text := '√';

  mIDNum := StrToInt(TEdit(Sender).Hint);
//  mIDNum := StrToIntDef(TEdit(Sender).Hint, 0);
  mMFID := TEdit(FindComponent('CODE' + Trim(IntToStr(mIDNum)))).Text;
  if FMFFlag = '分切' then
  begin
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('select DISTINCT max(B.tube) as tube,max(B.Packaging) as Packaging,max(B.Seal) as Seal from BS_CLOTH_MF A    ');
      SQL.Add('  FULL JOIN BS_CLOTH_IO_MX B on A.C_CODE = B.C_MXCODE ');
      SQL.Add(' WHERE A.MFID =' + QuotedStr(Trim(mMFID)));
      SQL.Add('  Group By A.C_CODE,A.C_MXMF ');

//      SQL.Add(' select * from BS_CLOTH_MF where MFID = ' + QuotedStr(Trim(mMFID)));
      Open;
    end;
  end
  else if FMFFlag = '不分切' then
  begin
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      SQL.Add(' select * from BS_CLOTH_IO_MX where MXID = ' + QuotedStr(Trim(mMFID)));
      Open;
    end;
  end;

  tube.Text := ADOQueryMain.FieldByName('tube').AsString;         // 纸管
  Packaging.Text := ADOQueryMain.FieldByName('Packaging').AsString;    //包装袋
  Seal.Text := ADOQueryMain.FieldByName('Seal').AsString;    //腰封

end;

procedure TfrmTatMachInsp.SetINIFile();
begin
  if edtChen.Text = '√' then
    IsDZCDYDll := '1'
  else
    IsDZCDYDll := '0';

  if edtMaBiao.Text = '√' then
    IsMBDYDll := '1'
  else
    IsMBDYDll := '0';

  if edtMBDW.Text = '√' then
    IsMBDYDllUnit := '1'
  else
    IsMBDYDllUnit := '0';

  LabQty := ComboBox1.Text;
  FMinLen := MinLen.Text;
  FMaxLen := MaxLen.Text;
  FMinWeight := MinWeight.Text;
  FMaxWeight := MaxWeight.Text;

  FMPlace := MPlace.Text;
  FYPlace := YPlace.Text;
  FKgPlace := KgPlace.Text;
  FKOUMI := koumi.Text;
  WriteINIFile();

end;

procedure TfrmTatMachInsp.GetINIFile();
begin
  if IsDZCDYDll = '1' then
    edtChen.Text := '√'
  else
    edtChen.Text := '';

  if IsMBDYDll = '1' then
    edtMaBiao.Text := '√'
  else
    edtMaBiao.Text := '';

  if IsMBDYDllUnit = '1' then
    edtMBDW.Text := '√'
  else
    edtMBDW.Text := '';

  ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(trim(LabQty));

  MinLen.Text := FMinLen;
  MaxLen.Text := FMaxLen;
  MinWeight.Text := FMinWeight;
  MaxWeight.Text := FMaxWeight;

  MPlace.Text := FMPlace;
  YPlace.Text := FYPlace;
  KgPlace.Text := FKgPlace;
  KOUMI.TEXT := FKOUMI;
end;

procedure TfrmTatMachInsp.gradeClick(Sender: TObject);
begin
  try
    frmSCPersonColor4 := TfrmSCPersonColor4.Create(self);
    with frmSCPersonColor4 do
    begin
      if ShowModal = 1 then
      begin

        Self.grade.Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor4.close;
  end;
end;

procedure TfrmTatMachInsp.SetDdetails();
begin
//  AOrdDefNote1.Text := '';
//  AOrdDefNote1.Text := AOrdDefNote1.Text + '卡号:' + FPCId + #13;
//  AOrdDefNote1.Text := AOrdDefNote1.Text + '品名:' + FC_Name + #13;
//  AOrdDefNote1.Text := AOrdDefNote1.Text + '颜色:' + FC_Color + #13;
//  AOrdDefNote1.Text := AOrdDefNote1.Text + '色号:' + FC_ColorNo + #13;

end;

procedure TfrmTatMachInsp.SetUnit(MUnit: string);
begin
  lblLenUnit.Caption := MUnit;
  lblLenUnit1.Caption := MUnit;
end;

procedure TfrmTatMachInsp.InitImage(YFTPName: string);
begin
//  with ADOQueryImage do
//  begin
//    close;
//    sql.Clear;
//    sql.Add('select * from TC_File A');
//    sql.Add('where isnull(WBID,'''')<>'''' and WBID=' + quotedstr(YFTPName));
////    showmessage(sql.text);
//    open;
//  end;
end;

procedure TfrmTatMachInsp.InitImageHX(HXSID: string);
begin
//  with Qry_ImgHX do
//  begin
//    close;
//    sql.Clear;
//    sql.Add('select * from TC_File A');
//    sql.Add('where isnull(WBID,'''')<>'''' and WBID=' + quotedstr(HXSID));
////    ShowMessage(SQL.Text);
//    open;
//  end;
end;

procedure TfrmTatMachInsp.QuantityConversion();
begin
  if lblRuleConversion.Caption = '米转公斤' then
  begin
    InputWeight.Text := floattostr(StrToFloatdef(trim(InputLen.Text), 0) * StrToFloatdef(trim(Coefficient.Text), 0));
  end;
  if lblRuleConversion.Caption = '公斤转米' then
  begin
    InputLen.Text := floattostr(StrToFloatdef(trim(InputWeight.Text), 0) * StrToFloatdef(trim(Coefficient.Text), 0));
  end;
end;

function TfrmTatMachInsp.CheckData(CKType: string): Boolean;
var
  mvalue: Double;
begin
  try
//    if Trim(FPCId) = '' then
//      raise Exception.Create('请扫描流程卡！');

    if Trim(CKType) = '提交' then
    begin
//      if trim(CodeName.text) = '' then
//        raise Exception.Create('品名不能为空!');
//      if trim(carno.text) = '' then
//        raise Exception.Create('机台号不能为空!');
//
//      if trim(lblLenUnit.Caption) = '' then
//        raise Exception.Create('长度单位不能为空!');

      if Trim(InputWeight.Text) <> '' then
      begin
        if TryStrToFloat(InputWeight.Text, mvalue) = False then
          raise Exception.Create('重量录入错误!');
        if strtofloatdef(trim(InputWeight.Text), 0) < Strtofloatdef(MinWeight.Text, 0) then
          raise Exception.Create('重量不能小于' + MinWeight.Text + '!');
        if strtofloatdef(trim(InputWeight.Text), 0) > Strtofloatdef(MaxWeight.Text, 0) then
          raise Exception.Create('重量不能大于' + MaxWeight.Text + '!');
      end;

      if Trim(InputLen.Text) <> '' then
      begin
        if TryStrToFloat(InputLen.Text, mvalue) = False then
          raise Exception.Create('长度录入错误!');
        if strtofloatdef(trim(InputLen.Text), 0) < Strtofloatdef(MinLen.Text, 0) then
          raise Exception.Create('长度不能小于' + MinLen.Text + '米!');
        if strtofloatdef(trim(InputLen.Text), 0) > Strtofloatdef(MaxLen.Text, 0) then
          raise Exception.Create('长度不能大于' + MaxLen.Text + '米!');
      end;

      if (strtofloatdef(trim(InputLen.Text), 0) = 0) and (strtofloatdef(trim(InputWeight.Text), 0) = 0) then
        raise Exception.Create('长度和重量不能都为0!!');
    end;
    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmTatMachInsp.ClearGlobal();
begin
  FOrderNo := '';
  FConNo := '';
  FConMId := '';
  FConSId := '';
  FMainId := '';
  FSubId := '';
//  FPCId := '';
  FC_CustPattern := '';
  FC_ColorDepth := '';
  FFtyPCId := '';
  FGangNo := '';
  FC_Code := '';
  FC_Name := '';
  FBatchNO := '';
  FC_Spec := '';
  FC_Color := '';
  FC_ColorNo := '';
  FC_StyleNo := '';
  FC_Width := '';
  FC_GramWeight := '';
  FC_Pattern := '';
  FCIID := '';
  FWorkshop := '';
  InputLen.Text := '';
  Coefficient.Text := '';
//  AOrdDefNote1.Text := '';
  Tare.Text := '';
  InputWeight.Text := '';
  FLenUnit := '';
  FLoom := '';
end;

procedure TfrmTatMachInsp.LookImage(FileName: string);
var
  sFieldName: string;
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
    try
      IdFTP1.Get(fFlileFlag + '\' + Trim(FileName), sFieldName, true, false);
    except
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

procedure TfrmTatMachInsp.PackagingClick(Sender: TObject);
begin
  try
    frmSCPersonColor2 := TfrmSCPersonColor2.Create(self);
    with frmSCPersonColor2 do
    begin
      FType := '包装袋';
      if ShowModal = 1 then
      begin

        Self.Packaging.Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor2.close;
  end;
end;

procedure TfrmTatMachInsp.Pic_Image1DblClick(Sender: TObject);
begin
  if TcxDBImage(Sender).Picture.Height = 0 then
    exit;
  LookImage(ADOQueryImage.fieldbyname(TcxDBImage(Sender).Hint).asstring);
end;

procedure TfrmTatMachInsp.InitLCK(MPCId: string);
begin
  with ADOTmp do
  begin
    Close;
    sql.Clear;
//    sql.Add('EXEC P_Tat_Insp_Get_PlanCard @PCID=''' + Trim(MPCId) + '''');
    sql.Add('EXEC P_Tat_Insp_Get_ORDERNO @MAINID=''' + Trim(MPCId) + '''');
    Open;
  end;

  if ADOTmp.IsEmpty = False then
  begin
//    if Trim(ADOTmp.fieldbyname('Status').AsString) <> '9' then
//    begin
//      application.MessageBox('流程卡不在已审核状态！', '提示信息', MB_ICONERROR);
//      ClearGlobal();
//    end
//    else
    begin
        //    InitImage(Trim(ADOTmp.fieldbyname('YFTPName').AsString));
//    InitImageHX(Trim(ADOTmp.fieldbyname('HXSID').AsString));
//      FLenUnit := Trim(ADOTmp.fieldbyname('LenUnit').AsString);
//      SetUnit(FLenUnit);

      FBCIOID := Trim(ADOTmp.fieldbyname('BCIOID').AsString);
      FC_Code := Trim(ADOTmp.fieldbyname('C_Code').AsString);
      FC_Name := Trim(ADOTmp.fieldbyname('C_Name').AsString);
      FC_Spec := Trim(ADOTmp.fieldbyname('C_Spec').AsString);
      FC_Color := Trim(ADOTmp.fieldbyname('C_Color').AsString);
      FC_ColorNo := Trim(ADOTmp.fieldbyname('C_ColorNo').AsString);
      FC_Width := Trim(ADOTmp.fieldbyname('C_Width').AsString);
      FC_GramWeight := Trim(ADOTmp.fieldbyname('C_GramWeight').AsString);
      FC_Pattern := Trim(ADOTmp.fieldbyname('C_Pattern').AsString);
//      FLoom := Trim(ADOTmp.fieldbyname('Loom').AsString);
//      FBatchNO := Trim(ADOTmp.fieldbyname('BatchNO').AsString);
      FPCId := Trim(ADOTmp.fieldbyname('PCId').AsString);
//    PieceNo.Text := Trim(ADOTmp.fieldbyname('maxRoll').AsString);
      Coefficient.Text := '0';
      fbmeter.text := Trim(ADOTmp.fieldbyname('fbmeter').AsString);
      xjmeter.text := Trim(ADOTmp.fieldbyname('xjmeter').AsString);
      CBGS.text := Trim(ADOTmp.fieldbyname('CBGS').AsString);

      PCID.text := Trim(ADOTmp.fieldbyname('PCID').AsString);
      BATCHNO.text := Trim(ADOTmp.fieldbyname('BATCHNO').AsString);
      if Trim(ADOTmp.fieldbyname('PCID').AsString) <> '' then
      begin
        PCID.Enabled := FALSE;

      end
      else
      begin
        PCID.Enabled := TRUE;
      end;
      if Trim(ADOTmp.fieldbyname('BATCHNO').AsString) <> '' then
      begin
        BATCHNO.Enabled := FALSE;

      end
      else
      begin
        BATCHNO.Enabled := TRUE;
      end;

      FXS := ADOTmp.fieldbyname('XS').ASFLOAT;
      FXSTYPE := ADOTmp.fieldbyname('XSTYPE').AsString;
      CodeName.Text := FC_Name;
//      BatchNO.Text := FBatchNO;
      spec.Text := FC_Spec;
      Code.Text := FC_Code;
      mf.Text := FC_Width;
      KZ.Text := FC_GramWeight;
      Edit7.Text := Trim(fbcioid);


//      Repairer.Text := Trim(ADOTmp.fieldbyname('Repairer').AsString);
      SetDdetails();
//      InputLen.SetFocus;
      CIFBegClick(InputLen);
      FXJCount := ADOTmp.fieldbyname('MXNO').AsInteger;
      Settrue();
//      SetKGVisibility(ADOTmp.fieldbyname('MXNO').AsInteger);
      InitEdit()
    end;

  end
  else
  begin
    application.MessageBox('计划单不存在！', '提示信息', MB_ICONERROR);
    ClearGlobal();
  end;

  InitJYGrid();
  InitCDGrid(FCIID);
  edtScan.Text := '';

end;

procedure TfrmTatMachInsp.InitJTM(MCIID: string);
begin

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_Cloth_IO where StkId=''' + Trim(MCIID) + ''' and IOFlag=''出库''');
    Open;
  end;
  if not ADOTmp.IsEmpty then
  begin
    Application.MessageBox('已产生出库数据不能操作!', '提示', 0);
    Exit;
  end;
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_Cloth_IO where StkId=''' + Trim(MCIID) + ''' and IOFlag=''入库''');
    Open;
  end;
  if ADOTmp.IsEmpty then
  begin
    Application.MessageBox('未入库不能操作!', '提示', 0);
    Exit;
  end;
  ////////状态为待出库才能操作
  try
    ADOCMD.Connection.BeginTrans;

    with ADOCMD do
    begin
      Close;
      Sql.Clear;
      sql.Add('insert into Finance_Need_Up(UType,UDataId,UOperation,UOperator,UModule) ');
      sql.Add('values(''梭织成品出库''    ');
      sql.Add(',' + quotedstr(MCIID));
      sql.Add(',''出库'' ');
      sql.Add(',' + quotedstr(dname));
      sql.Add(',' + quotedstr(self.Caption));
      sql.Add(')  ');

//      sql.Add('update  Tat_Cloth_Stock SET StkExists=0     ');
////        sql.Add('where iono=' + quotedstr(trim(Order_Main.fieldbyname('DRMID').AsString)));
//      sql.add('where IsStocking=''1''');
//      sql.Add('and  ciid=' + quotedstr(MCIID));
//
//      sql.Add('update  Tat_Cloth_Inspect SET CIIOFlag=''已出库''     ');
////        sql.Add('where iono=' + quotedstr(trim(Order_Main.fieldbyname('DRMID').AsString)));
//      sql.add('where  ');
//      sql.Add('  ciid=' + quotedstr(MCIID));
//
//      sql.Add('update  Tat_Cloth_IO SET ioflag=''出库'',iotime=getdate(),iotype=''分切出库''    ');
//      sql.Add(' where stkid=' + quotedstr(MCIID));
//      sql.add('and ioflag=''待出库''');

      Sql.Add('exec P_Tat_Cloth_Out ');
      Sql.Add(' @StkIds=' + quotedstr(trim(MCIID)));
      Sql.Add(',@IOTime=' + Quotedstr(FormatDateTime('yyyy-MM-dd', SGetServerDate(ADOTmp))));
      Sql.Add(',@IOType=' + Quotedstr('分切出库'));
      Sql.Add(',@IONO=' + Quotedstr(MCIID));
      Sql.Add(',@FillId=' + Quotedstr(DCode));
      Sql.Add(',@Filler=' + Quotedstr(DName));

      execsql;

    end;

    ADOCMD.Connection.CommitTrans;

  except
    ADOCMD.Connection.RollbackTrans;
    raise Exception.Create(PChar(Exception(ExceptObject).Message));
  end;
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select *,MXNO=(SELECT COUNT(*) FROM Bs_Cloth_IO_MX e WHERE E.BCIOID=A.BCIOID )     ');
    sql.Add(',XS=(select xs from bs_cloth_io e where e.bcioid=a.bcioid)');
    sql.Add(',XStype=(select XStype from bs_cloth_io e where e.bcioid=a.bcioid)');

    sql.Add(',fbmeter=(select top 1 fbmeter from Bs_Cloth_Info F WHERE F.C_NAME=A.C_Name)');
    sql.Add(',XJmeter=(select top 1 XJmeter from Bs_Cloth_Info F WHERE F.C_NAME=A.C_Name)');
    sql.Add(',CBGS=(select top 1 CBGS from Bs_Cloth_Info F WHERE F.C_NAME=A.C_Name)');
    sql.Add('from Tat_Cloth_Inspect a  where CIID=''' + Trim(MCIID) + '''');

    Open;
  end;
  if not ADOTmp.IsEmpty then
  begin
    FOperationStatus := '卷条码';
    fyciid := Trim(MCIID);
    FBCIOID := Trim(ADOTmp.fieldbyname('BCIOID').AsString);
//    FBCIOID := '';
    FC_Code := Trim(ADOTmp.fieldbyname('C_Code').AsString);
    FC_Name := Trim(ADOTmp.fieldbyname('C_Name').AsString);
    FC_Spec := Trim(ADOTmp.fieldbyname('C_Spec').AsString);
    FC_Color := Trim(ADOTmp.fieldbyname('C_Color').AsString);
    FC_ColorNo := Trim(ADOTmp.fieldbyname('C_ColorNo').AsString);
    FC_Width := Trim(ADOTmp.fieldbyname('C_Width').AsString);
    FC_GramWeight := Trim(ADOTmp.fieldbyname('C_GramWeight').AsString);
    FC_Pattern := Trim(ADOTmp.fieldbyname('C_Pattern').AsString);
//      FLoom := Trim(ADOTmp.fieldbyname('Loom').AsString);
//      FBatchNO := Trim(ADOTmp.fieldbyname('BatchNO').AsString);
    FPCId := Trim(ADOTmp.fieldbyname('PCId').AsString);
//    PieceNo.Text := Trim(ADOTmp.fieldbyname('maxRoll').AsString);
    Coefficient.Text := '0';
    fbmeter.text := Trim(ADOTmp.fieldbyname('fbmeter').AsString);
    xjmeter.text := Trim(ADOTmp.fieldbyname('xjmeter').AsString);
    CBGS.text := Trim(ADOTmp.fieldbyname('CBGS').AsString);
    DXMETER.text := Trim(ADOTmp.fieldbyname('DXMETER').AsString);

    PCID.text := Trim(ADOTmp.fieldbyname('PCID').AsString);
    BATCHNO.text := Trim(ADOTmp.fieldbyname('BATCHNO').AsString);
    if Trim(ADOTmp.fieldbyname('PCID').AsString) <> '' then
    begin
      PCID.Enabled := FALSE;

    end
    else
    begin
      PCID.Enabled := TRUE;
    end;
    if Trim(ADOTmp.fieldbyname('BATCHNO').AsString) <> '' then
    begin
      BATCHNO.Enabled := FALSE;

    end
    else
    begin
      BATCHNO.Enabled := TRUE;
    end;

    FXS := ADOTmp.fieldbyname('XS').ASFLOAT;
    FXSTYPE := ADOTmp.fieldbyname('XSTYPE').AsString;
    CodeName.Text := FC_Name;
//      BatchNO.Text := FBatchNO;
    spec.Text := FC_Spec;
    Code.Text := FC_Code;
    mf.Text := FC_Width;
    KZ.Text := FC_GramWeight;
    Edit7.Text := Trim(fbcioid);

    FYMETER := ADOTmp.fieldbyname('METER').AsString;
    FYWIDTH := ADOTmp.fieldbyname('C_WIDTH').AsString;
//      Repairer.Text := Trim(ADOTmp.fieldbyname('Repairer').AsString);
    SetDdetails();
//      InputLen.SetFocus;
    CIFBegClick(InputLen);
    FXJCount := ADOTmp.fieldbyname('MXNO').AsInteger;
    Settrue();
//      SetKGVisibility(ADOTmp.fieldbyname('MXNO').AsInteger);
    InitEdit();
    PNL1_1.Enabled := true;
    PNL2_1.Enabled := true;
    PNL3_1.Enabled := true;
    PNL4_1.Enabled := true;

    InitJYGrid();
    InitCDGrid(FCIID);
    edtScan.Text := '';

  end;

end;

procedure TfrmTatMachInsp.CloseCom(DllName: string);
type
  TMyFunc = function(sCommName: PAnsiChar): HWND; stdcall;
var
  Tf1: TMyFunc;
  Tp1: TFarProc;
  Th1: Thandle;
begin
  Th1 := LoadLibrary(Pchar(trim(DllName)));
  if Th1 > 0 then
  begin
    try
      Tp1 := GetProcAddress(Th1, 'CommClose');
      if Tp1 <> nil then
      begin
        Tf1 := TMyFunc(Tp1);
        newh1 := Tf1('Comm1');
      end
      else
      begin

      end;
    finally
    // FreeLibrary(Th1);
    end;
  end
  else
  begin
    application.MessageBox(Pchar('找不到 ' + trim(DllName) + ' 文件！'), '提示');
  end;
end;

procedure TfrmTatMachInsp.ComboBox1Change(Sender: TObject);
begin
  SetINIFile();
end;

procedure TfrmTatMachInsp.OpenCom(DllName: string);
type
  TMyFunc = function(fhandle: hwnd; sCommName: PAnsiChar; IntTime: integer; IsMessage: integer): HWND; stdcall;
var
  Tf: TMyFunc;
  Tp: TFarProc;
  Th: Thandle;
begin
 //  closeCom(FComFile);
  Th := LoadLibrary(Pchar(trim(DllName)));
  if Th > 0 then
  begin
    try
      Tp := GetProcAddress(Th, 'CommOpen');
      if Tp <> nil then
      begin
        Tf := TMyFunc(Tp);
        newh := Tf(self.Handle, 'Comm1', 500, 1);
        if newh < 1 then
        begin
          application.MessageBox(Pchar('打开串口失败！'), '提示');
        end
        else
          IsCommOpen := true;
      end
      else
      begin
        IsCommOpen := false;
      end;
    finally
    // FreeLibrary(Th);
    end;
  end
  else
  begin
    IsCommOpen := false;
    application.MessageBox(Pchar('找不到 ' + trim(DllName) + ' 文件！'), '提示');
  end;
end;

procedure TfrmTatMachInsp.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTatMachInsp := nil;
end;

procedure TfrmTatMachInsp.On1301(var Message: Tmessage);
var
  i1, i2, I: integer;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  i2 := Message.LParam;

//  if (trim(edtMaBiao.Text) = '√') then
//  begin
//    InputLen.Text := format('%.1f', [i1 / 100000]);
//  end;

  if JK1.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter1.Text := '0';
    end
    else
    begin
      meter1.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK2.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter2.Text := '0';
    end
    else
    begin
      meter2.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK3.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter3.Text := '0';
    end
    else
    begin
      meter3.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK4.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter4.Text := '0';
    end
    else
    begin
      meter4.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK5.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter5.Text := '0';
    end
    else
    begin
      meter5.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);

      //format('%.0f', [i1 / 100000]);

    end;
  end;
  if JK6.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter6.Text := '0';
    end
    else
    begin
      meter6.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK7.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter7.Text := '0';
    end
    else
    begin
      meter7.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK8.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter8.Text := '0';
    end
    else
    begin
      meter8.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK9.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter9.Text := '0';
    end
    else
    begin
      meter9.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK10.Text = '1' then
  begin
    if i1 = 0 then
    begin
      meter10.Text := '0';
    end
    else
    begin
      meter10.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK11.Text = '1' then
  begin
    meter11.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK12.Text = '1' then
  begin
    meter12.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK13.Text = '1' then
  begin
    meter13.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK14.Text = '1' then
  begin
    meter14.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK15.Text = '1' then
  begin
    meter15.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK16.Text = '1' then
  begin
    meter16.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK17.Text = '1' then
  begin
    meter17.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK18.Text = '1' then
  begin
    meter18.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK19.Text = '1' then
  begin
    meter19.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK20.Text = '1' then
  begin
    meter20.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;


//  with PNL1_3 do
//  begin
//    for I := 0 to 5 do
//    begin
//
//      if (Controls[I].Visible = True) and (Controls[I] is TComboBox) then
//      begin
//
//        if TComboBox(Controls[I]).Text = '1' then
//        begin
//          TEdit(FindComponent('meter' + Trim(TEdit(Controls[I]).Hint))).Text := format('%.1f', [i1 / 100000]);
//
//        end;
//      end;
//    end;
//  end;
//  with PNL2_3 do
//  begin
//    for I := 0 to 5 do
//    begin
//      if (Controls[I].Visible = True) and (Controls[I] is TComboBox) then
//      begin
//
//        if TComboBox(Controls[I]).Text = '1' then
//        begin
//          TEdit(FindComponent('meter' + Trim(TEdit(Controls[I]).Hint))).Text := format('%.1f', [i1 / 100000]);
//
//        end;
//      end;
//    end;
//  end;
//  with PNL3_3 do
//  begin
//    for I := 0 to 5 do
//    begin
//      if (Controls[I].Visible = True) and (Controls[I] is TComboBox) then
//      begin
//
//        if TComboBox(Controls[I]).Text = '1' then
//        begin
//          TEdit(FindComponent('meter' + Trim(TEdit(Controls[I]).Hint))).Text := format('%.1f', [i1 / 100000]);
//
//        end;
//      end;
//    end;
//  end;
//  with PNL4_3 do
//  begin
//    for I := 0 to 5 do
//    begin
//      if (Controls[I].Visible = True) and (Controls[I] is TComboBox) then
//      begin
//
//        if TComboBox(Controls[I]).Text = '1' then
//        begin
//          TEdit(FindComponent('meter' + Trim(TEdit(Controls[I]).Hint))).Text := format('%.1f', [i1 / 100000]);
//
//        end;
//      end;
//    end;
//  end;
end;

procedure TfrmTatMachInsp.On1302(var Message: Tmessage);
var
  i1, i2, I: integer;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  i2 := Message.LParam;

  if JK1.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter1.Text := '0';
    end
    else
    begin
      meter1.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK2.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter2.Text := '0';
    end
    else
    begin
      meter2.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK3.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter3.Text := '0';
    end
    else
    begin
      meter3.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK4.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter4.Text := '0';
    end
    else
    begin
      meter4.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK5.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter5.Text := '0';
    end
    else
    begin
      meter5.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK6.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter6.Text := '0';
    end
    else
    begin
      meter6.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK7.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter7.Text := '0';
    end
    else
    begin
      meter7.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK8.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter8.Text := '0';
    end
    else
    begin
      meter8.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK9.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter9.Text := '0';
    end
    else
    begin
      meter9.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK10.Text = '2' then
  begin
    if i1 = 0 then
    begin
      meter10.Text := '0';
    end
    else
    begin
      meter10.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK11.Text = '2' then
  begin
    meter11.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK12.Text = '2' then
  begin
    meter12.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK13.Text = '2' then
  begin
    meter13.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK14.Text = '2' then
  begin
    meter14.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK15.Text = '2' then
  begin
    meter15.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK16.Text = '2' then
  begin
    meter16.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK17.Text = '2' then
  begin
    meter17.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK18.Text = '2' then
  begin
    meter18.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK19.Text = '2' then
  begin
    meter19.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK20.Text = '2' then
  begin
    meter20.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
end;

procedure TfrmTatMachInsp.On1303(var Message: Tmessage);
var
  i1, i2, I: integer;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  i2 := Message.LParam;

  if JK1.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter1.Text := '0';
    end
    else
    begin
      meter1.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK2.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter2.Text := '0';
    end
    else
    begin
      meter2.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK3.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter3.Text := '0';
    end
    else
    begin
      meter3.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK4.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter4.Text := '0';
    end
    else
    begin
      meter4.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK5.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter5.Text := '0';
    end
    else
    begin
      meter5.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK6.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter6.Text := '0';
    end
    else
    begin
      meter6.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK7.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter7.Text := '0';
    end
    else
    begin
      meter7.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK8.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter8.Text := '0';
    end
    else
    begin
      meter8.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK9.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter9.Text := '0';
    end
    else
    begin
      meter9.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK10.Text = '3' then
  begin
    if i1 = 0 then
    begin
      meter10.Text := '0';
    end
    else
    begin
      meter10.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK11.Text = '3' then
  begin
    meter11.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK12.Text = '3' then
  begin
    meter12.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK13.Text = '3' then
  begin
    meter13.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK14.Text = '3' then
  begin
    meter14.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK15.Text = '3' then
  begin
    meter15.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK16.Text = '3' then
  begin
    meter16.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK17.Text = '3' then
  begin
    meter17.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK18.Text = '3' then
  begin
    meter18.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK19.Text = '3' then
  begin
    meter19.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK20.Text = '3' then
  begin
    meter20.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
end;

procedure TfrmTatMachInsp.On1304(var Message: Tmessage);
var
  i1, i2, I: integer;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  i2 := Message.LParam;

  if JK1.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter1.Text := '0';
    end
    else
    begin
      meter1.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK2.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter2.Text := '0';
    end
    else
    begin
      meter2.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;

  end;
  if JK3.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter3.Text := '0';
    end
    else
    begin
      meter3.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK4.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter4.Text := '0';
    end
    else
    begin
      meter4.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK5.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter5.Text := '0';
    end
    else
    begin
      meter5.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK6.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter6.Text := '0';
    end
    else
    begin
      meter6.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK7.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter7.Text := '0';
    end
    else
    begin
      meter7.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK8.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter8.Text := '0';
    end
    else
    begin
      meter8.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK9.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter9.Text := '0';
    end
    else
    begin
      meter9.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK10.Text = '4' then
  begin
    if i1 = 0 then
    begin
      meter10.Text := '0';
    end
    else
    begin
      meter10.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
    end;
  end;
  if JK11.Text = '4' then
  begin
    meter11.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK12.Text = '4' then
  begin
    meter12.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK13.Text = '4' then
  begin
    meter13.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK14.Text = '4' then
  begin
    meter14.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK15.Text = '4' then
  begin
    meter15.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK16.Text = '4' then
  begin
    meter16.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK17.Text = '4' then
  begin
    meter17.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;
  if JK18.Text = '4' then
  begin
    meter18.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK19.Text = '4' then
  begin
    meter19.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

  if JK20.Text = '4' then
  begin
    meter20.Text := format('%.0f', [i1 / 100000 - StrToIntDef(koumi.Text, 2)]);
  end;

end;

procedure TfrmTatMachInsp.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  if isCommopen then
  begin
    closeCom(DZCDYDllName);
    closeCom(MBDYDllName);
  end;
  Action := caFree;
end;

procedure TfrmTatMachInsp.InitCDGrid(MCIID: string);
begin
  cxPageControl1.ActivePageIndex := 0;
  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from Tat_Cloth_Inspect_Flaw where CIID=' + quotedstr(Trim(MCIID)));
    Open;
  end;
  SCreateCDS(ADOTmp, CDS_2);
  SInitCDSData(ADOTmp, CDS_2);
end;

procedure TfrmTatMachInsp.InitCDGridCX(MCIID: string);
begin
  cxPageControl1.ActivePageIndex := 1;
  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from Tat_Cloth_Inspect_Flaw where CIID=' + quotedstr(Trim(MCIID)));
    Open;
  end;
  SCreateCDS(ADOTmp, CDS_1);
  SInitCDSData(ADOTmp, CDS_1);
end;

procedure TfrmTatMachInsp.InitJYGrid();
var
  MNetWeight, MJYLen: double;
begin
  with ADOQueryMain do
  begin
    Close;
    SQL.Clear;
    if FMainId <> '' then
    begin
      sql.Add('select A.*');
      sql.Add('from Tat_Cloth_Inspect A '); //where PCId=''' + Trim(FPCId) + '''');

      sql.Add('where  mainid=' + quotedstr(fmainid));
      sql.Add('and filler=' + quotedstr(dname));
      sql.Add('order by ciid');
    end
    else
    begin
      sql.Add('select A.*');
      sql.Add('from Tat_Cloth_Inspect A '); //where PCId=''' + Trim(FPCId) + '''');
      sql.Add('where  convert(varchar(10),filltime,120)=convert(varchar(10),getdate(),120)');
      sql.Add('and filler=' + quotedstr(dname));
      sql.Add('and BCIOID=' + quotedstr(FBCIOID));
      sql.Add('order by ciid');
    end;


//    ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS(ADOQueryMain, CDS_3);
  SInitCDSData(ADOQueryMain, CDS_3);

  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select COUNT(*)JS,SUM(METER)METER,sum(SHMETER)SHMETER,fbps=sum(case when grade=''废布'' then 1 else 0 end )');
    sql.Add('from Tat_Cloth_Inspect A '); //where PCId=''' + Trim(FPCId) + '''');
    sql.Add('where  convert(varchar(10),filltime,120)=convert(varchar(10),getdate(),120)');
    sql.Add('and filler=' + quotedstr(dname));
    sql.Add('and mainid=''无订单''');
    Open;
  end;
  if ADOTmp.IsEmpty = FALSE then
  begin
    LABEL45.Caption := '今日已打匹数:' + ADOTmp.FieldByName('JS').AsString + ';  废布匹数：' + ADOTmp.FieldByName('fbps').AsString;
    LABEL44.Caption := '今日已打长度:' + ADOTmp.FieldByName('METER').AsString + ';  损耗米数：' + ADOTmp.FieldByName('SHMETER').AsString;
  end;

end;

procedure TfrmTatMachInsp.FormShow(Sender: TObject);
begin
//  inherited;
  ReadCxGrid(trim(Self.Caption) + 'Tv1', Tv1, '贸易检验管理');
  ReadCxGrid(trim(Self.Caption) + 'Tv2', Tv2, '贸易检验管理');
  ReadCxGrid(trim(Self.Caption) + 'Tv3', Tv3, '贸易检验管理');
  fFlileFlag := UserDataFlag + 'HX';
  InitCDPanel();
  InitCDGrid(FCIID);
  InitJYGrid();
  if IsINIFile() then
    ReadINIFile()
  else
    WriteINIFile;
  GetINIFile();
  if trim(fmanage) <> '高权限' then
  begin
    if trim(DZCDYDllName) <> '' then
      OpenCom(DZCDYDllName);
    if trim(MBDYDllName) <> '' then
      OpenCom(MBDYDllName);

//    edtScan.SetFocus;

  end;
  CARNO.Text := TRIM(SCXFlag);
end;

procedure TfrmTatMachInsp.InitCDPanel();
var
  AA: array[0..100] of string;
  i, j: Integer;
begin
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select ZDYName from KH_Zdy where Type=''WFBCD''and MainType=''梭织'' order by ZDYNO ');
    Open;
  end;
  if ADOTmp.IsEmpty then
  begin
    Application.MessageBox('没有定义疵点！', '提示', 0);
    Exit;
  end;
  with ADOTmp do
  begin
    First;
    i := 0;
    while not Eof do
    begin
      AA[i] := Trim(fieldbyname('ZDYName').AsString);
      i := i + 1;
      Next;
    end;
  end;
  i := i - 1;
  if i > 27 then
  begin
    i := 27;
  end;
  for j := 0 to i do
  begin
    with ScrollBox1 do
    begin
      TSpeedButton(Controls[j]).Visible := True;
      TSpeedButton(Controls[j]).Hint := AA[j];
      if Length(AA[j]) > 4 then
      begin
        TSpeedButton(Controls[j]).Caption := Copy(Trim(AA[j]), 1, 4) + #13 + Copy(Trim(AA[j]), 5, Length(AA[j]) - 4);
      end
      else
        TSpeedButton(Controls[j]).Caption := AA[j];
    end;
  end;
end;

procedure TfrmTatMachInsp.Tv3CustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
begin
  if AViewInfo.GridRecord.Values[TcxGridDBTableView(Sender).GetColumnByFieldName('Grade').Index] = '次品' then
    ACanvas.Brush.Color := clRed;
end;

procedure TfrmTatMachInsp.Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if CDS_3.isEmpty then
    exit;

  InitCDGridCX(CDS_3.FieldByName('CIID').AsString);
end;

function TfrmTatMachInsp.SaveData(FINT: Integer): Boolean;
var
  maxno, MCIID, strsql, T1: string;
  MInputLen, MMeter, MYardage: Double;
  MInputWeight, MGrossWeight, MNetWeight, MTare: Double;
  Year, Month, Day: Word;
  YearCode: Char;
begin
  fmainid := '';
  fsubid := '';
//  if FOperationStatus = '卷条码' then
//  begin
//    MCIID := FCIID;
//  end
//  else
//  begin
//    MCIID := '';
//  end;
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from Tat_Cloth_Inspect where CIID=''' + Trim(MCIID) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(MCIID) = '' then
      begin
        DecodeDate(Now, Year, Month, Day);

        YearCode := Chr(Ord('A') + (Year - 2025));

        T1 := YearCode + Format('%.2d', [Month]);
        if not GetLSNo(ADOTmp, maxno, T1 + Trim(SCXFlag), 'Tat_Cloth_Inspect', 7, 0) then
          raise Exception.Create('获取条码失败！');
        Append;
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('CIID').Value := Trim(maxno);
      end
      else
      begin
        maxno := Trim(MCIID);
        Edit;
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTmp);
      end;

     /////////////////////////           保存重量         /////////////////////////

      MTare := StrToFloatdef(trim(Tare.Text), 0);
      MInputWeight := RoundFloat(StrToFloatdef(trim(fkg), 0), StrTointdef(KgPlace.Text, 0));
      MGrossWeight := MInputWeight + MTare; //毛重
      MNetWeight := MInputWeight;  //净重
      FieldByName('InputWeight').Value := MInputWeight;
      FieldByName('GrossWeight').Value := MGrossWeight;
      FieldByName('NetWeight').Value := MNetWeight;
      FieldByName('Tare').Value := MTare;
      /////////////////////////           保存重量         /////////////////////////
      ///
      /////////////////////////           保存长度         /////////////////////////
      MInputLen := RoundFloat(StrToFloatdef(trim(FMETER), 0), 1);
      if lblLenUnit.Caption = 'M' then
      begin
        MMeter := RoundFloat(StrToFloatdef(trim(FMETER), 0) - StrToFloatdef(trim(fsunhao), 0), StrTointdef(MPlace.Text, 0));
        MYardage := RoundFloat(MMeter / 0.9144, StrTointdef(YPlace.Text, 0));
      end
      else
      begin
        MYardage := RoundFloat(StrToFloatdef(trim(FMETER), 0) - StrToFloatdef(trim(fsunhao), 0), StrTointdef(YPlace.Text, 0));
        MMeter := RoundFloat(MYardage * 0.9144, StrTointdef(MPlace.Text, 0));
      end;

      FieldByName('InputLen').Value := RoundFloat(StrToFloatdef(trim(InputLen.Text), 0), 1);
      FieldByName('Meter').Value := MMeter;
      FieldByName('SHMETER').Value := StrToFloatdef(fsunhao, 0);
      FieldByName('Yardage').Value := MYardage;
      FieldByName('LenUnit').Value := TRIM(lblLenUnit.Caption);
      if FOperationStatus = '卷条码' then
      begin
        FieldByName('BEFOREMETER').Value := StrToFloatDEF(FYMETER, 0);
        FieldByName('BEFOREC_WIDTH').Value := FYWIDTH;
        FieldByName('BEFORECIID').Value := fyciid;

      end;



      /////////////////////////           保存长度         /////////////////////////
      FieldByName('Coefficient').Value := StrToFloatdef(Coefficient.text, 0);

      FieldByName('Grade').Value := Grade.text;

      FieldByName('PieceNo').Value := 0;

      FieldByName('OrderNo').value := Trim(FOrderNo);
      if fmainid = '' then
      begin
        FieldByName('MainId').value := '无订单';
      end
      else
      begin
        FieldByName('MainId').value := Trim(FMainId);
      end;
      if FSubId = '' then
      begin
        FieldByName('SubId').value := '无订单';
      end
      else
      begin
        FieldByName('SubId').value := Trim(FSubId);
      end;
      FieldByName('mxid').value := Trim(fcode);
      FieldByName('BCIOID').value := Trim(FBCIOID);

      FieldByName('SHREASON').value := Trim(FSHREASON);

      FieldByName('Workshop').value := Trim(FWorkshop);
      FieldByName('CIIOFlag').Value := '未入库';
      FieldByName('PCId').value := FPCId;
      FieldByName('YG1').value := trim(YG1.Text);
      FieldByName('YG2').value := trim(YG2.Text);

      FieldByName('C_Code').value := trim(code.Text); //fcode;
      FieldByName('C_Name').value := trim(codename.Text); // fname;//trim(codename.Text);

      FieldByName('C_Spec').value := trim(Spec.Text);
      FieldByName('C_Color').value := FC_Color;
      FieldByName('C_ColorNo').value := FC_ColorNo;
      FieldByName('C_StyleNo').value := FC_StyleNo;
      FieldByName('C_Width').value := FMF; //trim(mf.Text);
      FieldByName('C_GramWeight').value := trim(kz.Text);
      FieldByName('C_Pattern').value := FC_Pattern;
      FieldByName('C_CustPattern').value := FC_CustPattern;

      FieldByName('CIMachNo').Value := Trim(SCXFlag);

      FieldByName('CARNO').Value := Trim(CARNO.Text);
      FieldByName('DXMETER').Value := Trim(DXMETER.Text);

      FieldByName('BATCHNO').Value := Trim(BATCHNO.Text);
      FieldByName('PCID').Value := Trim(PCID.Text);
      Post;
    end;

    MCIID := Trim(maxno);   //卷条码
    FCIID := Trim(maxno);
//    if fcode <> '' then
    if FMFFlag = '不分切' then
    begin
      with ADOCmd do
      begin
        Close;
        SQL.Clear;
//        sql.Add('update Tat_Cloth_Inspect  set tube=a.tube,Packaging=a.Packaging,Seal=a.Seal,ISSP=A.ISSP from Bs_Cloth_IO_mx a');
//        sql.Add(' where  Tat_Cloth_Inspect.mxid=a.mxid and Tat_Cloth_Inspect.ciid =''' + Trim(maxno) + '''');
        sql.Add('update Tat_Cloth_Inspect  set tube=   ' + QuotedStr(tube.Text));
        sql.Add(',Packaging=   ' + QuotedStr(Packaging.Text));
        sql.Add(',Seal=   ' + QuotedStr(Seal.Text));
        sql.Add(' ,ISSP=A.ISSP from Bs_Cloth_IO_mx a');
        sql.Add(' where  Tat_Cloth_Inspect.mxid=a.mxid and Tat_Cloth_Inspect.ciid =''' + Trim(maxno) + '''');
//        ShowMessage(sql.Text);
        execsql;
      end;

      if grade.Text = '循环布' then
      begin
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('update Tat_Cloth_Inspect set c_width=(select c_width from bs_cloth_io e where e.bcioid=Tat_Cloth_Inspect.bcioid)  ');

          sql.Add('where  ciid =''' + Trim(maxno) + '''');
          execsql;
        end;
      end;
    end
    else
    begin
      with ADOCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('update Tat_Cloth_Inspect set tube=   ' + QuotedStr(tube.Text));
        sql.Add(',Packaging=   ' + QuotedStr(Packaging.Text));
        sql.Add(',Seal=   ' + QuotedStr(Seal.Text));
        sql.Add(',issp=   ' + QuotedStr(issp.Text));
        sql.Add('where  ciid =''' + Trim(maxno) + '''');
        execsql;
      end;

    end;



    //保存挡车工信息
//////////////////       保存疵点信息       //////////////////
    with CDS_2 do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_2.fieldbyname('FQXH').AsString) = IntToStr(FINT) then
        begin
          if Trim(CDS_2.fieldbyname('CIFID').AsString) = '' then
          begin
            if not GetLSNo(ADOTmp, maxno, 'JC', 'Tat_Cloth_Inspect_Flaw', 5, 1) then
              raise Exception.Create('获取疵点失败！');
          end
          else
          begin
            maxno := Trim(CDS_2.fieldbyname('CIFID').AsString);
          end;
          with ADOCmd do
          begin
            Close;
            SQL.Clear;
            sql.Add('select * from Tat_Cloth_Inspect_Flaw  ');
            sql.Add(' where CIFID=''' + Trim(maxno) + '''');
            Open;
          end;
          with ADOCmd do
          begin
            if Trim(CDS_2.fieldbyname('CIFID').AsString) = '' then
              Append
            else
              Edit;
            RTSetSaveDataCDS(ADOCmd, Tv2, CDS_2, 'Tat_Cloth_Inspect_Flaw', 0);
            FieldByName('CIID').Value := Trim(MCIID);
            FieldByName('CIFID').Value := Trim(maxno);
            Post;
          end;
          CDS_2.Edit;
          CDS_2.FieldByName('CIID').Value := Trim(MCIID);
          CDS_2.FieldByName('CIFID').Value := Trim(maxno);
          CDS_2.Delete;
        end
        else
        begin
          CDS_2.next;
        end;

      end;
    end;
//////////////////       保存疵点信息       //////////////////
///
///
//////////////////       更新卷号疵点信息       //////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Tat_Insp_Up @CIID=''' + trim(MCIID) + '''');
      if FOperationStatus = '布票' then
        sql.Add(',@InspType=' + QuotedStr('布票'))
      else
        sql.Add(',@InspType=' + QuotedStr('单卷修改'));
      execsql;
    end;
//////////////////       更新卷号疵点信息       //////////////////
//////////////////       更新进度       //////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into Tat_Need_Up(UType,UDataId) values(''机台检验'',' + quotedstr(maxno) + ')  ');
      execsql;
    end;
//////////////////       更新进度       //////////////////
///
    ADOCmd.Connection.CommitTrans;

    if grade.Text = '自动' then
    begin
      with ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        sql.Add('select tt=count(*) from Tat_Cloth_Inspect_Flaw  ');
        sql.Add(' where ciid=''' + Trim(MCIID) + '''');

        Open;
      end;
      if (ADOQuery1.FieldByName('tt').AsInteger >= StrToIntDef(CBGS.Text, 0)) then
      begin
        if MMeter >= StrToFloatDef(fbmeter.Text, 0) then
        begin
          with ADOTmp do
          begin
            Close;
            SQL.Clear;
            sql.Add('update  Tat_Cloth_Inspect set grade=''二等品''');
            sql.Add(' where ciid=''' + Trim(MCIID) + '''');
            execsql;
          end;
        end
        else
        begin
          with ADOTmp do
          begin
            Close;
            SQL.Clear;
            sql.Add('update  Tat_Cloth_Inspect set grade=''废布''');
            sql.Add(' where ciid=''' + Trim(MCIID) + '''');
            execsql;
          end;
        end;

      end
      else
      begin
        if MMeter >= StrToFloatDef(xjmeter.Text, 0) then
        begin
          with ADOTmp do
          begin
            Close;
            SQL.Clear;
            sql.Add('update  Tat_Cloth_Inspect set grade=''优等品''');
            sql.Add(' where ciid=''' + Trim(MCIID) + '''');
            execsql;
          end;
        end
        else if MMeter >= StrToFloatDef(fbmeter.Text, 0) then
        begin
          with ADOTmp do
          begin
            Close;
            SQL.Clear;
            sql.Add('update  Tat_Cloth_Inspect set grade=''小卷''');
            sql.Add(' where ciid=''' + Trim(MCIID) + '''');
            execsql;
          end;
        end
        else
        begin
          with ADOTmp do
          begin
            Close;
            SQL.Clear;
            sql.Add('update  Tat_Cloth_Inspect set grade=''废布''');
            sql.Add(' where ciid=''' + Trim(MCIID) + '''');
            execsql;
          end;
        end;
      end;

    end;

//////////////////       出入库及库存       //////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Tat_Insp_In_Stk @CIID=''' + trim(MCIID) + '''');
      Open;
    end;
    if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      application.MessageBox(PChar(trim(ADOCmd.FieldByName('ShowMsg').AsString)), '提示信息', 0);
      Result := False;
    end
    else
    begin
      Result := True;
    end;
//////////////////       出入库及库存       //////////////////
    Result := True;
  except
    ADOCmd.Connection.RollbackTrans;
    BTPrint.Enabled := TRUE;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
    Result := False;
  end;
end;

procedure TfrmTatMachInsp.BTPrintClick(Sender: TObject);
var
  fPrintFile: string;
  mvalue: Double;
  i, J, FXJINT: Integer;
  tempValue: Double; ///验证定型米数为数字
begin
  CodeName.SetFocus;

  if batchno.Text = '' then
  begin
    Application.MessageBox('请输入批号！', '提示信息', MB_OK);
    Exit;
  end;
  if PCID.Text = '' then
  begin
    Application.MessageBox('请输入流转卡号！', '提示信息', MB_OK);
    Exit;
  end;
  if DXMETER.Text = '' then
  begin
    Application.MessageBox('请输入定型米数！', '提示信息', MB_OK);
    Exit;
  end;
  if not TryStrToFloat(DXMETER.Text, tempValue) then
  begin
    Application.MessageBox('定型米数必须是数字！', '提示信息', MB_OK);
    Exit;
  end;

  J := 0;
  BTPrint.Enabled := FALSE;
  with PNL1_6 do
  begin
    for i := 0 to 5 do
    begin

      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin

        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL2_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL3_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL4_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;

  if J = 0 then
  begin
    Application.MessageBox('没有选择小卷！', '提示', 0);
    BTPrint.Enabled := TRUE;
    Exit;
  end;
  if Trim(TEdit(FindComponent('meter' + Trim(IntToStr(FXJINT)))).Text) = '' then
  begin
    Application.MessageBox('长度不能为空！', '提示', 0);
    BTPrint.Enabled := TRUE;
    Exit;
  end
  else
  begin
    fmeter := Trim(TEdit(FindComponent('meter' + Trim(IntToStr(FXJINT)))).Text);
  end;
  fsunhao := Trim(TEdit(FindComponent('sh' + Trim(IntToStr(FXJINT)))).Text);
  fkg := Trim(TEdit(FindComponent('kg' + Trim(IntToStr(FXJINT)))).Text);
  fmf := Trim(TEdit(FindComponent('mf' + Trim(IntToStr(FXJINT)))).Text);
  fcode := Trim(TEdit(FindComponent('code' + Trim(IntToStr(FXJINT)))).Text);
  fname := Trim(TEdit(FindComponent('name' + Trim(IntToStr(FXJINT)))).Text);

  if StrToFloatDef(fmf, 0) = 0 then
  begin
    Application.MessageBox('门幅格式错误！', '提示', 0);
    BTPrint.Enabled := TRUE;
    Exit;
  end;
  if PNL1_1.Enabled = false then
  begin
    if fcode = '' then
    begin
      Application.MessageBox('没有选择明细！', '提示', 0);
      BTPrint.Enabled := TRUE;
      Exit;
    end;
  end;

  if StrToFloatDef(fmeter, 0) = 0 then
  begin
    Application.MessageBox('长度格式错误！', '提示', 0);
    BTPrint.Enabled := TRUE;
    Exit;
  end;

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('SELECT * FROM (     SELECT *, ROW_NUMBER() OVER (ORDER BY mxid) as row_num    FROM Bs_Cloth_IO_mx   ');
    sql.Add('where bcioid=' + QuotedStr(fbcioid));
    sql.Add(') AS temp where row_num=' + IntToStr(FXJINT));

    Open;
  end;
  if ADOTmp.IsEmpty then
  begin
//    Application.MessageBox('没有录入明细！', '提示', 0);
//    Exit;
  end
  else
  begin
    fmxid := ADOTmp.FieldByName('mxid').AsString;
  end;

  if fsunhao <> '' then
  begin
    try
      frmSCPersonColor3 := TfrmSCPersonColor3.Create(self);
      with frmSCPersonColor3 do
      begin
        if ShowModal = 1 then
        begin

          FSHREASON := Trim(cpyy.Text);

        end;
      end;
    finally
      frmSCPersonColor3.close;
    end;
    if FSHREASON = '' then
    begin
      Application.MessageBox('请选择损耗原因！', '提示', 0);
      BTPrint.Enabled := TRUE;
      Exit;
    end;
  end;
//  if CheckData('提交') = False then
//    exit;
  if SaveData(FXJINT) then
  begin

    if Trim(Edit6.Text) = '√' then
    begin
      PrtData(FCIID);
    end;
    TEdit(FindComponent('sh' + Trim(IntToStr(FXJINT)))).Text := '';
  end;
  FSHREASON := '';
  InputLen.Text := '';
  InputWeight.Text := '';
  FYMETER := '';
  FYWIDTH := '';
  fyciid := '';

  grade.text := '自动';
//  InputLen.SetFocus;
//  CIFBegClick(InputLen);
  FOperationStatus := '布票';
  InitJYGrid();
//  InitCDGrid('');
  FCIID := '';

//  OutPutQty1.Text := '';
//  OutPutQty2.Text := '';
//  OutPutQty3.Text := '';
//  OutPutQty4.Text := '';
//  OutPutQty5.Text := '';
//  BTPrint.Enabled := false;
  Timer1.Enabled := true;
end;

procedure TfrmTatMachInsp.PrtData(MCIID: string);
var
  fPrintFile, FLBName: string;
begin
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add(' EXEC P_Tat_Insp_Prt_Lab ');
    SQL.Add(' @CIID=''' + Trim(MCIID) + '''');
    Open;
  end;
  if ADOQueryPrint.IsEmpty then
  begin
    application.MessageBox('标签内容未找到！', '提示信息', MB_ICONERROR);
    exit;
  end;

  FLBName := Trim(ADOQueryPrint.fieldbyname('LBName').AsString);

  ExportFtErpFile(FLBName + '.rmf', ADOTmp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + FLBName + '.rmf';

  if FileExists(fPrintFile) then
  begin
    RM1.LoadFromFile(fPrintFile);
    RM1.DefaultCopies := strtointdef(trim(ComboBox1.Text), 1);
    RM1.PrintReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
  end;
end;

procedure TfrmTatMachInsp.SpeedButton1Click(Sender: TObject);
var
  fsj: string;
begin
  fsj := Trim(TSpeedButton(Sender).Hint);
  if Trim(fsj) = '' then
    Exit;
  if TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Name = 'KuangHao' then
    Exit;
  fsj := Trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text := fsj + Trim(TSpeedButton(Sender).Caption);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).SelectAll;
end;

procedure TfrmTatMachInsp.SpeedButton113Click(Sender: TObject);
begin
  inherited;
  panel3.Visible := False;
end;

procedure TfrmTatMachInsp.SpeedButton12Click(Sender: TObject);
var
  fsj: string;
begin
  fsj := Trim(TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text);
  if Trim(fsj) = '' then
    Exit;
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text := Copy(fsj, 1, Length(fsj) - 1);
  TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).SelectAll;
end;

procedure TfrmTatMachInsp.SpeedButton13Click(Sender: TObject);
var
  i, j, FXJINT: Integer;
begin
  if CheckData('疵点') = False then
    exit;

  FCIFName := Trim(TSpeedButton(Sender).Hint);
  MovePanel1.Visible := True;
  lblCIFName.Caption := Trim(FCIFName);

  j := 0;

  with PNL1_6 do
  begin
    for i := 0 to 5 do
    begin

      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin

        if TEdit(Controls[i]).Text = '√' then
        begin
          if j = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            j := 100
          end;
        end;
      end;
    end;
  end;
  with PNL2_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if j = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            j := 100
          end;
        end;
      end;
    end;
  end;
  with PNL3_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if j = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            j := 100
          end;
        end;
      end;
    end;
  end;
  with PNL4_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if j = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            j := 100
          end;
        end;
      end;
    end;
  end;

  if j = 0 then
  begin
    Application.MessageBox('没有选择小卷！', '提示', 0);
    Exit;
  end;
  //显示数字键盘
  CIFBeg.Text := Trim(TEdit(FindComponent('meter' + Trim(IntToStr(FXJINT)))).Text);
//  fmeter := Trim(TEdit(FindComponent('meter' + Trim(IntToStr(FXJINT)))).Text);
  with Panel3 do
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint := Trim(CIFBeg.Name);
      end;
    end;
  end;

end;

procedure TfrmTatMachInsp.SpeedButton19Click(Sender: TObject);
var
  FXJINT, I, J: Integer;
  mIDNum: Integer;
  FFMF, FFMXID: string;
  mMFID: string;
begin
  J := 0;

  with PNL1_6 do
  begin
    for I := 0 to 5 do
    begin

      if (Controls[I].Visible = True) and (Controls[I] is TEdit) then
      begin

        if TEdit(Controls[I]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[I]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL2_6 do
  begin
    for I := 0 to 5 do
    begin
      if (Controls[I].Visible = True) and (Controls[I] is TEdit) then
      begin
        if TEdit(Controls[I]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[I]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL3_6 do
  begin
    for I := 0 to 5 do
    begin
      if (Controls[I].Visible = True) and (Controls[I] is TEdit) then
      begin
        if TEdit(Controls[I]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[I]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL4_6 do
  begin
    for I := 0 to 5 do
    begin
      if (Controls[I].Visible = True) and (Controls[I] is TEdit) then
      begin
        if TEdit(Controls[I]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[I]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  if J = 0 then
  begin
    Application.MessageBox('没有选择小卷！', '提示', 0);
    Exit;
  end;

  try
    frmSCPersonColor := TfrmSCPersonColor.Create(self);
    with frmSCPersonColor do
    begin
      FBCIOID := SELF.FBCIOID;
      FC_Code := Self.FC_Code;
      FMFFlag := Self.FMFFlag;
      if ShowModal = 1 then
      begin
        FFMF := Trim(FName);
        FFMXID := Trim(FHINT);
//          TEdit(FindComponent('MF' + Trim(IntToStr(FXJINT)))).Text := Trim(FName);
//          TEdit(FindComponent('CODE' + Trim(IntToStr(FXJINT)))).Text := Trim(FHINT);
//          TEdit(FindComponent(Trim(TSpeedButton(Sender).Hint))).Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor.close;
  end;

  if FFMF = '' then
    EXIT;
  TEdit(FindComponent('CODE' + Trim(IntToStr(FXJINT)))).Text := Trim(FFMXID);

//  if FBCIOID = '' then
  if FMFFlag = '分切' then
  begin
    with ADOTmp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT A.* FROM Bs_Cloth_MF A where  A.MFID=''' + Trim(FFMXID) + '''');
      Open;
    end;
    TEdit(FindComponent('MF' + Trim(IntToStr(FXJINT)))).Text := ADOTmp.FieldByName('C_MXMF').AsString;
  end
  else
  begin
    with ADOTmp do
    begin
      Close;
      sql.Clear;
      sql.Add('SELECT A.* FROM Bs_Cloth_IO_MX A where  A.MXID=''' + Trim(FFMXID) + '''');
      Open;
    end;
    TEdit(FindComponent('MF' + Trim(IntToStr(FXJINT)))).Text := ADOTmp.FieldByName('C_MXWIDTH').AsString;
  end;

  mIDNum := FXJINT;
//  mIDNum := StrToIntDef(TEdit(Sender).Hint, 0);
  mMFID := TEdit(FindComponent('CODE' + Trim(IntToStr(mIDNum)))).Text;
  if FMFFlag = '分切' then
  begin
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      sql.Add('select DISTINCT max(B.tube) as tube,max(B.Packaging) as Packaging,max(B.Seal) as Seal from BS_CLOTH_MF A    ');
      SQL.Add('  FULL JOIN BS_CLOTH_IO_MX B on A.C_CODE = B.C_MXCODE ');
      SQL.Add(' WHERE A.MFID =' + QuotedStr(Trim(mMFID)));
      SQL.Add('  Group By A.C_CODE,A.C_MXMF ');

//      SQL.Add(' select * from BS_CLOTH_MF where MFID = ' + QuotedStr(Trim(mMFID)));
      Open;
    end;
  end
  else if FMFFlag = '不分切' then
  begin
    with ADOQueryMain do
    begin
      close;
      sql.Clear;
      SQL.Add(' select * from BS_CLOTH_IO_MX where MXID = ' + QuotedStr(Trim(mMFID)));
      Open;
    end;
  end;

  tube.Text := ADOQueryMain.FieldByName('tube').AsString;         // 纸管
  Packaging.Text := ADOQueryMain.FieldByName('Packaging').AsString;    //包装袋
  Seal.Text := ADOQueryMain.FieldByName('Seal').AsString;    //腰封


end;

procedure TfrmTatMachInsp.Button10Click(Sender: TObject);
begin
  try
    frmSCPersonColor2 := TfrmSCPersonColor2.Create(self);
    with frmSCPersonColor2 do
    begin
      FType := '员工';
      if ShowModal = 1 then
      begin

        Self.YG1.Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor2.close;
  end;

end;

procedure TfrmTatMachInsp.Button11Click(Sender: TObject);
var
  i: Integer;
begin
  try
    frmSCPersonColor2 := TfrmSCPersonColor2.Create(self);
    with frmSCPersonColor2 do
    begin
      FType := '员工';
      if ShowModal = 1 then
      begin

        Self.YG2.Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor2.close;
  end;
end;

procedure TfrmTatMachInsp.Button12Click(Sender: TObject);
begin

  if trim(DZCDYDllName) <> '' then
  begin
    closeCom(DZCDYDllName);
    OpenCom(DZCDYDllName);
  end;

  if trim(MBDYDllName) <> '' then
  begin
    closeCom(MBDYDllName);
    OpenCom(MBDYDllName);
  end;

end;

procedure TfrmTatMachInsp.Button1Click(Sender: TObject);
var
  mvalue: Double;
  i, J, FXJINT: Integer;
begin

  if Trim(CIFBeg.Text) <> '' then
  begin
    if Trim(CIFEnd.Text) <> '' then
    begin
      if StrToFloat(CIFEnd.Text) < StrToFloat(CIFBeg.Text) then
      begin
        Application.MessageBox('疵点位置录入错误!', '提示', 0);
        Exit;
      end;
    end;
  end;
  if CIFQty.Text <> '' then
  begin
    if TryStrToFloat(CIFQty.Text, mvalue) = False then
    begin
      Application.MessageBox('非法数字!', '提示', 0);
      Exit;
    end;
  end;

  J := 0;

  with PNL1_6 do
  begin
    for i := 0 to 5 do
    begin

      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin

        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL2_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL3_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;
  with PNL4_6 do
  begin
    for i := 0 to 5 do
    begin
      if (Controls[i].Visible = True) and (Controls[i] is TEdit) then
      begin
        if TEdit(Controls[i]).Text = '√' then
        begin
          if J = 0 then
          begin
            FXJINT := StrToInt(TEdit(Controls[i]).Hint);
            J := 100
          end;
        end;
      end;
    end;
  end;

  if J = 0 then
  begin
    Application.MessageBox('没有选择小卷！', '提示', 0);
    Exit;
  end;
  with CDS_2 do
  begin
    Append;
    if RadioGroup1.ItemIndex = 5 then
      FieldByName('CIFName').Value := '连续性' + Trim(FCIFName)
    else if RadioGroup1.ItemIndex = 4 then
      FieldByName('CIFName').Value := '整匹' + Trim(FCIFName)
    else
      FieldByName('CIFName').Value := Trim(FCIFName);
    FieldByName('CIFbeg').Value := Trim(CIFBeg.Text);
    FieldByName('CIFEnd').Value := Trim(CIFEnd.Text);
    FieldByName('CIFPoints').Value := 0;
    FieldByName('FQXH').Value := FXJINT;
    if RadioGroup1.ItemIndex > -1 then
    begin
      if RadioGroup1.ItemIndex < 3 then
      begin
        FieldByName('CIFPoints').Value := RadioGroup1.ItemIndex + 1;
      end
      else
      begin
        FieldByName('CIFPoints').Value := 4;
      end;
    end;
    FieldByName('CIFQty').Value := StrToFloatdef(trim(CIFQty.Text), 0);

    Post;
  end;
  CIFBeg.Text := '';
  CIFEnd.Text := '';
  CIFQty.Text := '';
  MovePanel1.Visible := False;
  cxPageControl1.ActivePageIndex := 0;
end;

procedure TfrmTatMachInsp.edtScanKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if trim(edtScan.Text) = '' then
      exit;
//    if trim(edtScan.Text) = FPCId then
//      exit;
    with ADOTmp do
    begin
      close;
      sql.Clear;
      sql.Add(' select * from Tat_Cloth_Inspect where CIID=''' + Trim(edtScan.Text) + ''' ');

//      ShowMessage(sql.Text);
      open;
    end;

    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from BS_Cloth_IO where BCIOID=''' + Trim(edtScan.Text) + ''' ');
      sql.Add(' AND CAST(fillTime AS DATE) >= CAST(GETDATE() - 2 AS DATE)');
//      ShowMessage(sql.Text);
      open;
    end;
    if ADOCmd.IsEmpty and ADOTmp.IsEmpty then
    begin
      ShowMessage('请选择最近三天的切割工单');
      exit;
    end;

    if ADOTmp.IsEmpty = FALSE then
    begin
      batchno.Text := ADOTmp.FieldByName('batchno').AsString;
      PCID.Text := ADOTmp.FieldByName('PCID').AsString;
      DXMETER.Text := ADOTmp.FieldByName('DXMETER').AsString;
      issp.Text := ADOTmp.FieldByName('issp').AsString;
      if Application.MessageBox('是否分切出库？', '提示', 32 + 4) <> IDYES then
      begin
        edtScan.Text := '';
        Exit;
      end
      else
      begin
        FMFFlag := '分切'; //为了选择门幅时做判断，为空选择产品门幅
        InitJTM(edtScan.Text);
      end;

    end
    else
    begin
      ClearGlobal();
      FMFFlag := '不分切'; //为了选择门幅时做判断，为空选择产品门幅
      FOperationStatus := '布票';
      InitLCK(edtScan.Text);
      InitJYGrid();
      PNL1_1.Enabled := false;
      PNL2_1.Enabled := false;
      PNL3_1.Enabled := false;
      PNL4_1.Enabled := false;
    end;


//    InputLen.SetFocus;
  end;
end;

procedure TfrmTatMachInsp.CIFBegClick(Sender: TObject);
var
  i: Integer;
begin
  panel3.Visible := true;
  with Panel3 do
  begin

    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint := Trim(TEdit(Sender).Name);
      end;
    end;
  end;
end;

procedure TfrmTatMachInsp.CIFEndChange(Sender: TObject);
var
  mvalue: Double;
begin
  if Trim(CIFBeg.Text) <> '' then
  begin
    if TryStrToFloat(CIFBeg.Text, mvalue) = False then
    begin
      Application.MessageBox('非法数字!', '提示', 0);
      Exit;
    end;
  end
  else
  begin
    Exit;
  end;
  if Trim(CIFEnd.Text) <> '' then
  begin
    if TryStrToFloat(CIFEnd.Text, mvalue) = False then
    begin
      Application.MessageBox('非法数字!', '提示', 0);
      Exit;
    end;
  end
  else
  begin
    Exit;
  end;
  CIFQty.Text := FloatToStr(StrToFloat(CIFEnd.Text) - StrToFloat(CIFBeg.Text));
end;

procedure TfrmTatMachInsp.Edit1Click(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text) = '' then
  begin
    TEdit(Sender).Text := '√';
    if trim(DZCDYDllName) <> '' then
    begin

      OpenCom(DZCDYDllName);
    end;

    if trim(MBDYDllName) <> '' then
    begin

      OpenCom(MBDYDllName);
    end;
  end
  else
  begin
    TEdit(Sender).Text := '';

    if trim(DZCDYDllName) <> '' then
    begin
      closeCom(DZCDYDllName);

    end;

    if trim(MBDYDllName) <> '' then
    begin
      closeCom(MBDYDllName);

    end;
  end;
end;

procedure TfrmTatMachInsp.Edit6Click(Sender: TObject);
begin
  if Trim(Edit6.Text) = '' then
  begin
    Edit6.Text := '√';
  end
  else
  begin
    Edit6.Text := '';
  end;
end;

procedure TfrmTatMachInsp.METER10Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter10.Text, 0) - strtofloatdef(sh10.Text, 0)) * strtofloatdef(MF10.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg10.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg10.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER11Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL11.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg11.text := FloatToStr(roundfloat(strtofloatdef(meter11.Text, 0) * strtofloatdef(MF11.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER12Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL12.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg12.text := FloatToStr(roundfloat(strtofloatdef(meter12.Text, 0) * strtofloatdef(MF12.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER13Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL13.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg13.text := FloatToStr(roundfloat(strtofloatdef(meter13.Text, 0) * strtofloatdef(MF13.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER14Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL14.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg14.text := FloatToStr(roundfloat(strtofloatdef(meter14.Text, 0) * strtofloatdef(MF14.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER15Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL15.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg15.text := FloatToStr(roundfloat(strtofloatdef(meter15.Text, 0) * strtofloatdef(MF15.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER16Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL16.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg16.text := FloatToStr(roundfloat(strtofloatdef(meter16.Text, 0) * strtofloatdef(MF16.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER17Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL17.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg17.text := FloatToStr(roundfloat(strtofloatdef(meter17.Text, 0) * strtofloatdef(MF17.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER18Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL18.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg18.text := FloatToStr(roundfloat(strtofloatdef(meter18.Text, 0) * strtofloatdef(MF18.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER19Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL19.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg19.text := FloatToStr(roundfloat(strtofloatdef(meter19.Text, 0) * strtofloatdef(MF19.Text, 0) * strtofloatdef(KZ.Text, 0) / 10000, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER1Change(Sender: TObject);
var
  F1: DOUBLE;
begin
//  Initclearsel();
//  SEL1.text := '√';
//  if FXSTYPE = '米转净重' then
//  begin

  F1 := (strtofloatdef(meter1.Text, 0) - strtofloatdef(sh1.Text, 0)) * strtofloatdef(MF1.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if F1 > 1 then
  begin
    kg1.text := FloatToStr(RoundFloat(F1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg1.text := '0';
  end;
  //  kg1.text := FloatToStr(roundfloat((strtofloatdef(meter1.Text, 0) - strtofloatdef(sh1.Text, 0)) * strtofloatdef(MF1.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000, StrTointdef(KgPlace.Text, 0)));


end;

procedure TfrmTatMachInsp.METER1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    BTPrint.Click();
  end;
end;

procedure TfrmTatMachInsp.METER20Change(Sender: TObject);
begin
//  Initclearsel();
//  SEL20.text := '√';
  if FXSTYPE = '米转净重' then
  begin
    kg20.text := FloatToStr(roundfloat(strtofloatdef(meter20.Text, 0) * fxs, StrTointdef(KgPlace.Text, 0)));
  end;
end;

procedure TfrmTatMachInsp.METER2Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter2.Text, 0) - strtofloatdef(sh2.Text, 0)) * strtofloatdef(MF2.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg2.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg2.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER3Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter3.Text, 0) - strtofloatdef(sh3.Text, 0)) * strtofloatdef(MF3.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg3.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg3.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER4Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter4.Text, 0) - strtofloatdef(sh4.Text, 0)) * strtofloatdef(MF4.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg4.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg4.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER5Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter5.Text, 0) - strtofloatdef(sh5.Text, 0)) * strtofloatdef(MF5.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg5.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg5.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER6Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter6.Text, 0) - strtofloatdef(sh6.Text, 0)) * strtofloatdef(MF6.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg6.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg6.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER7Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter7.Text, 0) - strtofloatdef(sh7.Text, 0)) * strtofloatdef(MF7.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg7.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg7.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER8Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter8.Text, 0) - strtofloatdef(sh8.Text, 0)) * strtofloatdef(MF8.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg8.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg8.text := '0';
  end;
end;

procedure TfrmTatMachInsp.METER9Change(Sender: TObject);
var
  f1: Double;
begin

  f1 := (strtofloatdef(meter9.Text, 0) - strtofloatdef(sh9.Text, 0)) * strtofloatdef(MF9.Text, 0) * strtofloatdef(KZ.Text, 0) / 100000;
  if f1 > 1 then
  begin
    kg9.text := FloatToStr(RoundFloat(f1, StrTointdef(KgPlace.Text, 0)));

  end
  else
  begin
    kg9.text := '0';
  end;
end;

procedure TfrmTatMachInsp.MinLenExit(Sender: TObject);
begin
  SetINIFile();
end;

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

procedure TfrmTatMachInsp.Button2Click(Sender: TObject);
begin
  RadioGroup1.ItemIndex := -1;
end;

procedure TfrmTatMachInsp.Button3Click(Sender: TObject);
begin
  if Panel6.Visible then
    Panel6.Visible := False
  else
    Panel6.Visible := True;
end;

procedure TfrmTatMachInsp.edtScanClick(Sender: TObject);
var
  i: Integer;
begin
  Panel3.Visible := True;
  with Panel3 do
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i] is TSpeedButton then
      begin
        TSpeedButton(Controls[i]).Hint := Trim(TEdit(Sender).Name);
      end;
    end;
  end;
end;

procedure TfrmTatMachInsp.NetWeightKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    BTPrint.Click;
  end;
end;

procedure TfrmTatMachInsp.FormCreate(Sender: TObject);
begin
  inherited;
  IsCommopen := false;
end;

procedure TfrmTatMachInsp.lblLenUnitClick(Sender: TObject);
begin
//  if Trim(lblLenUnit.Caption) = 'M' then
//    SetUnit('Y')
//  else
//    SetUnit('M');
end;

procedure TfrmTatMachInsp.Button4Click(Sender: TObject);
begin
  MovePanel1.Visible := false;
end;

procedure TfrmTatMachInsp.Button5Click(Sender: TObject);
var
  i: integer;
begin
  inherited;
  try
    frmTatClothInfoSel := TfrmTatClothInfoSel.Create(Application);
    with frmTatClothInfoSel do
    begin
      if ShowModal = 1 then
      begin
        Self.Code.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_Code').AsString;
        Self.CodeName.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_Name').AsString;
//        Self.MF.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_Width').AsString;
        Self.KZ.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_GramWeight').AsString;

        Self.SPEC.Text := frmTatClothInfoSel.CDS_1.fieldbyname('C_SPEC').AsString;

        Self.fbmeter.Text := frmTatClothInfoSel.CDS_1.fieldbyname('fbmeter').AsString;
        Self.xjmeter.Text := frmTatClothInfoSel.CDS_1.fieldbyname('xjmeter').AsString;
        Self.CBGS.Text := frmTatClothInfoSel.CDS_1.fieldbyname('CBGS').AsString;
        Settrue();

        InitEdit();
        batchno.text := '';
        PCID.text := '';
        batchno.ReadOnly := false;
        PCID.ReadOnly := false;
        PNL1_1.Enabled := true;
        PNL2_1.Enabled := true;
        PNL3_1.Enabled := true;
        PNL4_1.Enabled := true;

      end;
    end;
  finally
    frmTatClothInfoSel.Free;
  end;


//  try
//    frmSCPersonColor := TfrmSCPersonColor.Create(self);
//    with frmSCPersonColor do
//    begin
//      if ShowModal = 1 then
//      begin
//        with ADOTmp do
//        begin
//          Close;
//          sql.Clear;
//          sql.Add('SELECT A.* FROM Bs_Cloth_Info A where  A.C_name=''' + Trim(FName) + '''');
//          Open;
//        end;
//        Self.Code.Text := ADOTmp.fieldbyname('C_Code').AsString;
//        Self.CodeName.Text := ADOTmp.fieldbyname('C_Name').AsString;
//        Self.MF.Text := ADOTmp.fieldbyname('C_Width').AsString;
//        Self.KZ.Text := ADOTmp.fieldbyname('C_GramWeight').AsString;
//
//        Self.SPEC.Text := ADOTmp.fieldbyname('C_SPEC').AsString;
//
//      end;
//    end;
//  finally
//    frmSCPersonColor.close;
//  end;
//  fmainid := '';
//  fsubid := '';
//  Label14.Caption := '订单号';
end;

procedure TfrmTatMachInsp.Timer1Timer(Sender: TObject);
begin
  BTPrint.Enabled := true;
  Timer1.Enabled := False;
end;

procedure TfrmTatMachInsp.ToolButton1Click(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      MainType := '梭织';
      flag := 'SUNHAO';
      flagname := '损耗管理';

      if ShowModal = 1 then
      begin
//        Self.InitCDPanel();
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmTatMachInsp.ToolButton3Click(Sender: TObject);
begin
  if CDS_3.IsEmpty then
    Exit;
  PrtData(CDS_3.fieldbyname('CIID').AsString);

end;

procedure TfrmTatMachInsp.ToolButton4Click(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      MainType := '梭织';
      flag := 'WFBCD';
      flagname := '疵点';
      fnote := True;
      fnote1 := True;
      V1Note.Caption := '英文名称';
      V1Note1.Caption := '疵点等级';
      if ShowModal = 1 then
      begin
        Self.InitCDPanel();
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmTatMachInsp.ToolButton5Click(Sender: TObject);
begin
  if CDS_3.IsEmpty then
    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  ADOCmd.Connection.BeginTrans;
  try

    with ADOCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Cloth_ReIn ');
      Sql.Add('@StkIds=' + quotedstr(Trim(CDS_3.fieldbyname('CIID').AsString)));
      Sql.Add(',@IOIDS=' + quotedstr(trim('')));
      Sql.Add(',@FillId=' + Quotedstr(DCode));
      Sql.Add(',@Filler=' + Quotedstr(DName));
//      ShowMessage(sql.Text);
      Open;
    end;

    if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOCmd.FieldByName('ShowMsg').AsString)));
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into Tat_Need_Up(UType,UDataId) values(''检验删除'',' + quotedstr(Trim(CDS_3.fieldbyname('CIID').AsString)) + ')  ');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      Sql.Clear;
      Sql.Add('exec P_Tat_Insp_Del ');
      Sql.Add('@CIIDS=' + quotedstr(Trim(CDS_3.fieldbyname('CIID').AsString)));
      Sql.Add(',@DCode=' + Quotedstr(DCode));
      Sql.Add(',@DName=' + Quotedstr(DName));
      Open;
    end;
    if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
    begin
      raise Exception.Create(pchar(trim(ADOCmd.FieldByName('ShowMsg').AsString)));
    end;
    ADOCmd.Connection.CommitTrans;
    CDS_3.Delete;
    application.MessageBox('删除成功！', '提示信息');
  except
    ADOCmd.Connection.RollbackTrans;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
  InitJYGrid();
end;

procedure TfrmTatMachInsp.ToolButton6Click(Sender: TObject);
begin
  if CDS_3.IsEmpty then
    Exit;
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_Cloth_IO where StkId=''' + Trim(CDS_3.fieldbyname('CIID').AsString) + ''' and IOFlag=''入库''');
    Open;
  end;
  if not ADOTmp.IsEmpty then
  begin
    Application.MessageBox('已产生入库数据不能删除!', '提示', 0);
    Exit;
  end;
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Tat_Cloth_IO where StkId=''' + Trim(CDS_3.fieldbyname('CIID').AsString) + ''' and IOFlag=''出库''');
    Open;
  end;
  if not ADOTmp.IsEmpty then
  begin
    Application.MessageBox('已产生出库数据不能删除!', '提示', 0);
    Exit;
  end;
  InitJTM(CDS_3.fieldbyname('CIID').AsString);
end;

procedure TfrmTatMachInsp.ToolButton7Click(Sender: TObject);
begin
  WriteCxGrid(trim(Self.Caption) + 'Tv1', Tv1, '贸易检验管理');
  WriteCxGrid(trim(Self.Caption) + 'Tv2', Tv2, '贸易检验管理');
  WriteCxGrid(trim(Self.Caption) + 'Tv3', Tv3, '贸易检验管理');

end;

procedure TfrmTatMachInsp.ToolButton8Click(Sender: TObject);
begin
  Close;
end;

procedure TfrmTatMachInsp.ToolButton9Click(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    Exit;
//  if FOperationStatus = '缸条码' then
//    Exit;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if Trim(CDS_2.fieldbyname('CIFID').AsString) = '' then
  begin
    CDS_2.Delete;
  end
  else
  begin
    with ADOCmd do
    begin
      Close;
      SQL.Clear;
//      sql.Add('insert ZDel_Coat_Cloth_Inspect_Flaw into select * from  Coat_Cloth_Inspect_Flaw where CIFID=''' + Trim(CDS_2.fieldbyname('CIFID').AsString) + '''');
      sql.Add('delete Coat_Cloth_Inspect_Flaw where CIFID=''' + Trim(CDS_2.fieldbyname('CIFID').AsString) + '''');
      ExecSQL;
    end;
    //更新疵点信息
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_Coat_Insp_Up @CIID=''' + Trim(CDS_2.fieldbyname('CIID').AsString) + '''');
      sql.Add(',@InspType=' + QuotedStr('单卷修改'));
      execsql;
    end;
    CDS_2.Delete;
  end;
end;

procedure TfrmTatMachInsp.tubeClick(Sender: TObject);
begin
  try
    frmSCPersonColor2 := TfrmSCPersonColor2.Create(self);
    with frmSCPersonColor2 do
    begin
      FType := '纸管';
      if ShowModal = 1 then
      begin

        Self.tube.Text := Trim(FName);

      end;
    end;
  finally
    frmSCPersonColor2.close;
  end;
end;

procedure TfrmTatMachInsp.edtChenClick(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text) = '' then
  begin
    TEdit(Sender).Text := '√';
  end
  else
  begin
    TEdit(Sender).Text := '';
  end;
  SetINIFile();
end;

procedure TfrmTatMachInsp.edtYJClick(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text) = '' then
  begin
    TEdit(Sender).Text := '√';
  end
  else
  begin
    TEdit(Sender).Text := '';
  end;
end;

procedure TfrmTatMachInsp.Button6Click(Sender: TObject);
begin
  if ScrollBox1.Visible then
    ScrollBox1.Visible := False
  else
    ScrollBox1.Visible := True;
end;

procedure TfrmTatMachInsp.Button7Click(Sender: TObject);
begin
  inherited;
//  if OutPutQty1.Text = '' then
//  begin
//    OutPutQty1.Text := InputLen.Text;
//
//  end
//  else if OutPutQty2.Text = '' then
//  begin
//    if JBSCPerson.Text <> '' then
//    begin
//      OutPutQty2.Text := FLOATTOSTR(STRTOFLOATDEF(InputLen.Text, 0) - STRTOFLOATDEF(OutPutQty1.Text, 0));
//    end
//    else
//    begin
//      Application.MessageBox('请先选择挡车工2!', '提示', 0);
//      Exit;
//    end;
//
//  end
//  else if OutPutQty3.Text = '' then
//  begin
//    if JBSCPerson3.Text <> '' then
//    begin
//      OutPutQty3.Text := FLOATTOSTR(STRTOFLOATDEF(InputLen.Text, 0) - STRTOFLOATDEF(OutPutQty1.Text, 0) - STRTOFLOATDEF(OutPutQty2.Text, 0));
//    end
//    else
//    begin
//      Application.MessageBox('请先选择挡车工3!', '提示', 0);
//      Exit;
//    end;
//
//  end
//  else if OutPutQty4.Text = '' then
//  begin
//    if JBSCPerson4.Text <> '' then
//    begin
//      OutPutQty4.Text := FLOATTOSTR(STRTOFLOATDEF(InputLen.Text, 0) - STRTOFLOATDEF(OutPutQty1.Text, 0) - STRTOFLOATDEF(OutPutQty2.Text, 0) - STRTOFLOATDEF(OutPutQty3.Text, 0));
//    end
//    else
//    begin
//      Application.MessageBox('请先选择挡车工4!', '提示', 0);
//      Exit;
//    end;
//
//  end
//  else if OutPutQty5.Text = '' then
//  begin
//    if JBSCPerson5.Text <> '' then
//    begin
//      OutPutQty5.Text := FLOATTOSTR(STRTOFLOATDEF(InputLen.Text, 0) - STRTOFLOATDEF(OutPutQty1.Text, 0) - STRTOFLOATDEF(OutPutQty2.Text, 0) - STRTOFLOATDEF(OutPutQty3.Text, 0) - STRTOFLOATDEF(OutPutQty4.Text, 0));
//    end
//    else
//    begin
//      Application.MessageBox('请先选择挡车工5!', '提示', 0);
//      Exit;
//    end;
//
//  end
//  else if OutPutQty6.Text = '' then
//  begin
//    if JBSCPerson6.Text <> '' then
//    begin
//      OutPutQty6.Text := FLOATTOSTR(STRTOFLOATDEF(InputLen.Text, 0) - STRTOFLOATDEF(OutPutQty1.Text, 0) - STRTOFLOATDEF(OutPutQty2.Text, 0) - STRTOFLOATDEF(OutPutQty3.Text, 0) - STRTOFLOATDEF(OutPutQty4.Text, 0) - STRTOFLOATDEF(OutPutQty5.Text, 0));
//    end
//    else
//    begin
//      Application.MessageBox('请先选择挡车工6!', '提示', 0);
//      Exit;
//    end;
//
//  end
//  else if OutPutQty7.Text = '' then
//  begin
//    if JBSCPerson7.Text <> '' then
//    begin
//      OutPutQty7.Text := FLOATTOSTR(STRTOFLOATDEF(InputLen.Text, 0) - STRTOFLOATDEF(OutPutQty1.Text, 0) - STRTOFLOATDEF(OutPutQty2.Text, 0) - STRTOFLOATDEF(OutPutQty3.Text, 0) - STRTOFLOATDEF(OutPutQty4.Text, 0) - STRTOFLOATDEF(OutPutQty5.Text, 0) - STRTOFLOATDEF(OutPutQty6.Text, 0));
//    end
//    else
//    begin
//      Application.MessageBox('请先选择挡车工7!', '提示', 0);
//      Exit;
//    end;
//
//  end;

end;

procedure TfrmTatMachInsp.Button8Click(Sender: TObject);
begin
//  if Panel7.Visible then
//    Panel7.Visible := False
//  else
//    Panel7.Visible := True;
end;

procedure TfrmTatMachInsp.Button9Click(Sender: TObject);
begin

  try
    frmSCPersonColor := TfrmSCPersonColor.Create(self);
    with frmSCPersonColor do
    begin
      FType := '机台号';
      if ShowModal = 1 then
      begin
        carno.text := trim(fname);

      end;
    end;
  finally
    frmSCPersonColor.close;
  end;
end;

procedure TfrmTatMachInsp.carnoBtnClick(Sender: TObject);
begin
  inherited;
  try
    frmSCPersonColor := TfrmSCPersonColor.Create(self);
    with frmSCPersonColor do
    begin
      FType := '机台号';
      if ShowModal = 1 then
      begin
        carno.text := trim(fname);

      end;
    end;
  finally
    frmSCPersonColor.close;
  end;
end;

procedure TfrmTatMachInsp.carnoClick(Sender: TObject);
begin
  inherited;
  try
    frmSCPersonColor := TfrmSCPersonColor.Create(self);
    with frmSCPersonColor do
    begin
      FType := '机台号';
      if ShowModal = 1 then
      begin
        carno.text := trim(fname);

      end;
    end;
  finally
    frmSCPersonColor.close;
  end;
end;

end.

