unit U_GreyInspection;

interface

uses
  Windows, Messages, SysUtils, 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, IniFiles, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  StrUtils, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmGreyInspection = class(TForm)
    cxGridPopupMenu1: TcxGridPopupMenu;
    DataSource1: TDataSource;
    Order_MJ: TClientDataSet;
    ADOCmd: TADOQuery;
    RMDB_Main: TRMDBDataSet;
    RM2: TRMGridReport;
    DS_MJCD: TDataSource;
    CDS_MJCD: TClientDataSet;
    DS_MJID: TDataSource;
    CDS_MJID: TClientDataSet;
    ADOQueryPrint: 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;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ADOQueryMainDSC: TADOQuery;
    SpeedButton45: TSpeedButton;
    SpeedButton46: TSpeedButton;
    SpeedButton47: TSpeedButton;
    SpeedButton48: TSpeedButton;
    SpeedButton50: TSpeedButton;
    SpeedButton51: TSpeedButton;
    SpeedButton54: TSpeedButton;
    SpeedButton55: TSpeedButton;
    SpeedButton56: TSpeedButton;
    SpeedButton57: TSpeedButton;
    SpeedButton58: TSpeedButton;
    SpeedButton59: TSpeedButton;
    SpeedButton62: TSpeedButton;
    SpeedButton63: TSpeedButton;
    SpeedButton64: TSpeedButton;
    SpeedButton65: TSpeedButton;
    SpeedButton66: TSpeedButton;
    SpeedButton67: TSpeedButton;
    SpeedButton70: TSpeedButton;
    SpeedButton71: TSpeedButton;
    SpeedButton72: TSpeedButton;
    SpeedButton73: TSpeedButton;
    SpeedButton74: TSpeedButton;
    SpeedButton75: TSpeedButton;
    Panel2: TPanel;
    Label9: TLabel;
    JYLen1: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label11: TLabel;
    BTPrint: TButton;
    Button5: TButton;
    Edit3: TEdit;
    Label10: TLabel;
    Edit4: TEdit;
    Label12: 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;
    SpeedButton49: TSpeedButton;
    Label30: TLabel;
    JYTare: TEdit;
    Label31: TLabel;
    Label32: TLabel;
    JYNW: TEdit;
    Label33: TLabel;
    Panel7: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    tv2CDType: TcxGridDBColumn;
    ZZPerson: TcxGridDBColumn;
    Tv2CDReason: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    OrdNote: TRichEdit;
    SpeedButton19: TSpeedButton;
    SpeedButton20: TSpeedButton;
    SpeedButton27: TSpeedButton;
    SpeedButton28: TSpeedButton;
    SpeedButton35: TSpeedButton;
    SpeedButton36: TSpeedButton;
    Label36: TLabel;
    RM3: TRMGridReport;
    JYxh: TEdit;
    ADOTmp: TADOQuery;
    Panel5: TPanel;
    Panel6: TPanel;
    Label1: TLabel;
    Label35: TLabel;
    Label39: TLabel;
    Scan: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    TBCD: TToolButton;
    TBClose: TToolButton;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Label2: TLabel;
    Label13: TLabel;
    JYXS: TEdit;
    ToolButton2: TToolButton;
    BatchNo: TEdit;
    Label3: TLabel;
    person1: TEdit;
    person2: TEdit;
    Label14: TLabel;
    Label6: TLabel;
    Label15: TLabel;
    JYLen2: TEdit;
    ToolButton3: TToolButton;
    Label16: TLabel;
    Label19: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Label24: TLabel;
    JYLen3: TEdit;
    person3: TEdit;
    person4: TEdit;
    JYLen4: TEdit;
    Label25: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    person5: TEdit;
    JYLen5: TEdit;
    QryCheckNet: TADOQuery;
    Label29: TLabel;
    edtDel: TEdit;
    lblJYPS: TLabel;
    MovePanel1: TMovePanel;
    Label7: TLabel;
    Button1: TButton;
    Button4: TButton;
    JXiuPrice: TEdit;
    Label8: TLabel;
    ToolButton4: TToolButton;
    lblJYLen: TLabel;
    JXiuKouK: TEdit;
    Label17: TLabel;
    Label18: TLabel;
    DCheKouK: TEdit;
    Label37: TLabel;
    ToolButton5: TToolButton;
    v2Column2: TcxGridDBColumn;
    v2Column4: TcxGridDBColumn;
    SpeedButton84: TSpeedButton;
    lbl1: TLabel;
    lbl2: TLabel;
    JYGW: TEdit;
    Tv3Column1: TcxGridDBColumn;
    Label40: TLabel;
    Edit1: TEdit;
    Tv3Column2: TcxGridDBColumn;
    Label41: TLabel;
    WXPH: TEdit;
    Label20: TLabel;
    Label38: TLabel;
    Label42: TLabel;
    Label43: TLabel;
    Label44: TLabel;
    Label45: TLabel;
    DChePrice: TEdit;
    DCGKaiJ: TEdit;
    Tv2Column1: TcxGridDBColumn;
    SpeedButton43: TSpeedButton;
    Panel1: TPanel;
    Label26: TLabel;
    Label34: TLabel;
    Edit6: TEdit;
    ComboBox1: TComboBox;
    Label46: TLabel;
    kaijian: TEdit;
    CDLEN: TEdit;
    Label48: TLabel;
    Label47: TLabel;
    Tv2Column2: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBCDClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BTPrintClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure cxGridDBColumn2PropertiesChange(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure SpeedButton49Click(Sender: TObject);
    procedure ScanKeyPress(Sender: TObject; var Key: Char);
    procedure Edit3Click(Sender: TObject);
    procedure Edit4Click(Sender: TObject);
    procedure Edit6Click(Sender: TObject);
    procedure MJstr3KeyPress(Sender: TObject; var Key: Char);
    procedure JYGWChange(Sender: TObject);
    procedure ScanClick(Sender: TObject);
    procedure Edit7Click(Sender: TObject);
    procedure JYNWKeyPress(Sender: TObject; var Key: Char);
    procedure FormCreate(Sender: TObject);
    procedure Edit8Click(Sender: TObject);
    procedure JYLen1Change(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure person1Click(Sender: TObject);
    procedure person2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure person5Click(Sender: TObject);
    procedure person4Click(Sender: TObject);
    procedure person3Click(Sender: TObject);
    procedure edtDelClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure DCheKouKClick(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure JXiuKouKClick(Sender: TObject);
    procedure Label9Click(Sender: TObject);
    procedure Label6Click(Sender: TObject);
    procedure Label16Click(Sender: TObject);
    procedure Label23Click(Sender: TObject);
    procedure Label27Click(Sender: TObject);
    procedure Edit1Click(Sender: TObject);
    procedure SpeedButton43Click(Sender: TObject);
    procedure JYLen1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure JYLen2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure JYLen3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure JYLen4MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure JYLen5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    FColumn, FFFMJID, FOperationStatus: string;
    FAPID, FSPID, FMainId, FSubId, FMJCode, FMJName, FMJSpec, FMJMF, FMJKZ, FMJColor, FAPBatchNo, FCarNo, FISJSKZ: string;   // 产品信息
    FMF_Wai, FJSKZ, FKONGJIA, fkongjiawei: Double;
    FCDName: string; //疵点名称
    isCommopen, IsJsMessage: boolean;
    fxsType, fRollType: string;
    procedure InitBatchNo(); //刷新批号选项
    procedure InitDefectOptions(); //刷新疵点选项
    procedure InitCDGrid(); //刷新疵点信息
    procedure InitInspectionRecord(); //刷新检验信息

    function CheckData(CKType: string): Boolean; //校验数据
    function SaveData(): Boolean; //保存数据
    function SelfConnData(): Boolean; //检测网络链接
    procedure ScanOrder();  //扫描订单
    procedure ScanSample();  //扫描样品
    procedure ScanAnPai();   //扫描布票
    procedure ClearGlobal(MStatus: string); //清除全局ID
    procedure PrintCKMDG(MRKOrdID: string); //打印入库单
    procedure PrtData(FMJID: string);  //打印卷标签
    procedure QuantityConversion();  //数量换算
    procedure OpenCom(DllName: string);
    procedure CloseCom(DllName: string);
    procedure DelDate(FMJID: string); //删除标签
    procedure On1201(var Message: Tmessage); message 1201;
    procedure On1301(var Message: Tmessage); message 1301;
  public
    fmanage: string;
    I3: Double;
    { Public declarations }

  end;

var
  frmGreyInspection: TfrmGreyInspection;
  newh, newh1: hwnd;
  IniFile: TIniFile;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_iniParam, U_SCPerson,
  U_FinishedClothStatistical;

{$R *.dfm}

procedure TfrmGreyInspection.DelDate(FMJID: string);
var
  FJYID: string;
begin

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_Cloth_CR where APID=''' + Trim(FMJID) + '''');
    sql.Add('and CRFlag=''出库'' ');
    Open;
  end;
  if ADOTmp.RecordCount >= 1 then
  begin
    Application.MessageBox('已出库不能扫描删除!', '提示', 0);
    Exit;
  end;

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select top 1 * from CK_Cloth_CR where APID=''' + Trim(FMJID) + '''');
    Open;
  end;
  FJYID := Trim(ADOTmp.fieldbyname('JYID').AsString);

  try
    ADOCmd.Connection.BeginTrans;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('UPDATE CK_Cloth_CR Set CRTime=NULL,CRType=NULL,CRFlag=''待入库'' ,RKNo=NULL where CK_Cloth_CR.CRFlag=''入库'' and CK_Cloth_CR.JYID=''' + Trim(FJYID) + '''');
      sql.Add('UPDATE CK_Cloth_KC Set Valid=''N'' where CK_Cloth_KC.JYID=''' + Trim(FJYID) + '''');
      sql.Add('UPDATE JY_Cloth Set JYCRType=''未入库'',RKNo=null where JY_Cloth.JYID=''' + Trim(FJYID) + '''');
      sql.Add('delete JY_Cloth where JYID=''' + Trim(FJYID) + '''');
      sql.Add('delete CK_Cloth_CR where JYID=''' + Trim(FJYID) + '''');
      sql.Add('delete CK_Cloth_KC where JYID=''' + Trim(FJYID) + '''');
      sql.Add('delete JY_Cloth_CD where JYID=''' + Trim(FJYID) + '''');
      sql.Add('update PD_Plan_AnPai set jyflag=(case when isnull((select count(*) from JY_Cloth where apid=''' + trim(FMJID) + '''),0)>0 then 1 else 0 end)');
      sql.Add('where apid =''' + trim(FMJID) + ''' ');

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('作废成品检验数据')));
      sql.Add(',' + quotedstr('卷条码：' + trim(FMJID)));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      ExecSQL;
    end;
    if not CDS_MJID.IsEmpty then
    begin
      if CDS_MJID.Locate('JYID', FJYID, []) then
        CDS_MJID.Delete;
    end;
    FAPID := FMJID;
    FFFMJID := FJYID;
    InitInspectionRecord();
    InitCDGrid();

    ADOCmd.Connection.CommitTrans;
    Application.MessageBox('删除成功!', '提示', 0);
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('删除失败!', '提示', 0);
  end;
  edtDel.Text := '';
end;

function TfrmGreyInspection.SelfConnData(): Boolean;
begin
  try
    with QryCheckNet do
    begin
      Close;
      sql.Clear;
      //查询一个小表检测网络
      SQL.Add('select getdate()');
      Open;
    end;
    Result := true;
  except
//    if Application.MessageBox('是否重新连接网络！','提示',32+4)<>IDYES then  Exit;
    if not Assigned(DataLink_FabricInspection) then
      DataLink_FabricInspection := DataLink_FabricInspection.Create(Application);
    try
      with DataLink_FabricInspection.ADOLink do
      begin
        //if not Connected then
        begin
          Connected := false;
          ConnectionString := DConString;
          LoginPrompt := false;
          Connected := true;
        end;
      end;
      Result := true;
    except
      Result := false;
    end;
  end;
end;

procedure TfrmGreyInspection.InitBatchNo();
var
  fsj: string;
begin
//  fsj := 'select distinct(ZdyName) name from KH_ZDY A where A.Type=''GreyBatchNo''  ';
//  SInitComBoxBySql(ADOTmp, BatchNo, False, fsj);
end;

procedure TfrmGreyInspection.QuantityConversion();
var
  MLen, MNWet, MGWet, MPWet, MCC, XiShu, MGreyLen: Double;
begin
//  MLen := StrToFloatdef(trim(JYLen.Text), 0);
//  MNWet := StrToFloatdef(trim(JYNW.Text), 0);
//  MPWet := StrToFloatdef(trim(JYTare.Text), 0);
//  MGWet := StrToFloatdef(trim(JYGW.Text), 0);
//  MCC := StrToFloatdef(trim(JYXS.Text), 0);
//  if MCC > 0 then
//  begin
//    MGWet := StrToFloat(format('%.1f', [MLen * MCC]));
//    MNWet := MGWet - MPWet;
//    JYGW.Text := FloatToStr(MGWet);
//    JYNW.Text := FloatToStr(MNWet);
//  end;
//
//  MNWet := MGWet - MPWet;
//  JYNW.Text := FloatToStr(MNWet);

end;

function TfrmGreyInspection.CheckData(CKType: string): Boolean;
var
  mvalue, i4: Double;
begin
  try
    if Trim(FMainId) = '' then
      raise Exception.Create('此布票已检验,请扫描新布票！');

    if Trim(CKType) = '提交' then
    begin
      with ADOTmp do
      begin
        Close;
        sql.Clear;
        sql.Add(' select * from JY_Cloth where  APID=' + QuotedStr(Trim(FAPID)));
        Open;
      end;
      if ADOTmp.IsEmpty = FALSE then
      begin
        raise Exception.Create('此布票已检验,请扫描新布票！');

      end;


//      if (strtofloatdef(trim(JYLen1.Text), 0) < 0.00) or (strtofloatdef(trim(JYLen2.Text), 0) < 0.00) or (strtofloatdef(trim(JYLen3.Text), 0) < 0.00) or (strtofloatdef(trim(JYLen4.Text), 0) < 0.00) or (strtofloatdef(trim(JYLen5.Text), 0) < 0.00) then
//        raise Exception.Create('长度不能小于0!');
      if (strtofloatdef(trim(JYLen1.Text), 0) + strtofloatdef(trim(JYLen2.Text), 0) + strtofloatdef(trim(JYLen3.Text), 0) + strtofloatdef(trim(JYLen4.Text), 0) + strtofloatdef(trim(JYLen5.Text), 0)) <= 0.00 then
        raise Exception.Create('总长度不能小于等于0!');

      if (Trim(JYLen1.Text) <> '') or (Trim(JYLen2.Text) <> '') or (Trim(JYLen3.Text) <> '') or (Trim(JYLen4.Text) <> '') or (Trim(JYLen5.Text) <> '') then
      begin
        if (strtofloatdef(trim(JYLen1.Text), 0) > 400) or (strtofloatdef(trim(JYLen2.Text), 0) > 400) or (strtofloatdef(trim(JYLen3.Text), 0) > 400) or (strtofloatdef(trim(JYLen4.Text), 0) > 400) or (strtofloatdef(trim(JYLen5.Text), 0) > 400) then
          raise Exception.Create('长度不能大于400!');
      end;

      if (strtofloatdef(trim(JYLen1.Text), 0) = 0) and (strtofloatdef(trim(JYLen2.Text), 0) = 0) and (strtofloatdef(trim(JYLen3.Text), 0) = 0) and (strtofloatdef(trim(JYLen4.Text), 0) = 0) and (strtofloatdef(trim(JYLen5.Text), 0) = 0) then
        raise Exception.Create('长度不能为0!!');

      if (strtofloatdef(trim(JYGW.Text), 0) > 100) then
        raise Exception.Create('重量不能大于100!!');

      if Edit7.Text <> '' then
      begin
        i4 := RoundFloat(I3 + 0.1, 0);
        if (JYLen5.Text <> '') and (JYLen4.Text <> '') and (JYLen3.Text <> '') and (JYLen2.Text <> '') and (JYLen1.Text <> '') then
        begin
          JYLen5.Text := FloatToStr(i4 - strtofloat(jylen4.Text) - strtofloat(jylen3.Text) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text));
        end
        else if (JYLen4.Text <> '') and (JYLen3.Text <> '') and (JYLen2.Text <> '') and (JYLen1.Text <> '') then
        begin
          JYLen4.Text := FloatToStr(i4 - strtofloat(jylen3.Text) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text));
        end
        else if (JYLen3.Text <> '') and (JYLen2.Text <> '') and (JYLen1.Text <> '') then
        begin
          JYLen3.Text := FloatToStr(i4 - strtofloat(jylen2.Text) - strtofloat(jylen1.Text));
        end
        else if (JYLen2.Text <> '') and (JYLen1.Text <> '') then
        begin
          JYLen2.Text := FloatToStr(i4 - strtofloat(jylen1.Text));
        end
        else if (JYLen1.Text <> '') then
        begin
          JYLen1.Text := FloatToStr(i4);
        end;
      end;

    end;
    //ShowMessage(JYLen2.Text);
    Result := True;
  except
    Result := false;
    application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0);
  end;
end;

procedure TfrmGreyInspection.ClearGlobal(MStatus: string);
begin
  if MStatus = '扫描' then
  begin
    FAPID := '';
    FSPID := '';
    FMainId := '';
    FSubId := '';
    FFFMJID := '';
    FMJCode := '';
    FMJName := '';
    FMJSpec := '';
    FMJMF := '';
    FMJKZ := '';
    FMJColor := '';
    FAPBatchNo := '';
    FCarNo := '';
    FMF_Wai := 0;
    FJSKZ := 0;
    FISJSKZ := '';
    JYxh.Text := '';
    JYXS.Text := '';
    JYGW.Text := '';
    JYNW.Text := '';
    JYLen1.Text := '';
    JYLen2.Text := '';
    BatchNo.Text := '';
  end;

  if MStatus = '提交' then
  begin
    JYLen1.Text := '';
    JYLen2.Text := '';
    JYGW.Text := '';
    JYNW.Text := '';
    FOperationStatus := '';
    FFFMJID := '';
    //FAPID := '';
  end;

end;

procedure TfrmGreyInspection.PrintCKMDG(MRKOrdID: string);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin

  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add(' exec P_Print_RKMDGangNo ');
    SQL.Add(' @RKOrdID=''' + Trim(MRKOrdID) + '''');
    Open;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('RKOrdID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    exit;
  end;
  ExportFtErpFile('验布工仓库码单.rmf', ADOTmp);
  fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\验布工仓库码单.rmf';
  if FileExists(fPrintFile) then
  begin
    RMVariables['QRBARCODE'] := fImagePath;
    RM2.LoadFromFile(fPrintFile);
    Rm2.DefaultCopies := 1;
    RM2.ShowReport;
  end
  else
  begin
    Application.MessageBox(PChar('没有找' + fPrintFile), '提示', 0);
    Exit;
  end;
end;

procedure TfrmGreyInspection.ScanSample();
var
  MFromMJLen: Double;
begin

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CP_YDang ');
    sql.Add('where CYID=''' + Trim(Scan.Text) + '''');
    Open;
  end;

  if not ADOTmp.IsEmpty then
  begin

    FMainId := Trim(ADOTmp.fieldbyname('MainId').AsString);
    FSubId := Trim(ADOTmp.fieldbyname('SubId').AsString);
    FMJCode := Trim(ADOTmp.fieldbyname('SPCode').AsString);
    FMJName := Trim(ADOTmp.fieldbyname('SPName').AsString);
    FMJSpec := Trim(ADOTmp.fieldbyname('SPSpec').AsString);
    FMJMF := Trim(ADOTmp.fieldbyname('SPMF').AsString);
    FMJKZ := Trim(ADOTmp.fieldbyname('SPKZ').AsString);
    FMJColor := trim(ADOTmp.fieldbyname('SPColor').AsString);

    JYxh.Text := '1';

    OrdNote.Text := '编号:' + FMJCode + #13;
    OrdNote.Text := OrdNote.Text + '品名:' + FMJName + #13;
    OrdNote.Text := OrdNote.Text + '门幅:' + FMJMF + #13;
    OrdNote.Text := OrdNote.Text + '克重:' + FMJKZ + #13;
    OrdNote.Text := OrdNote.Text + '颜色:' + FMJColor + #13;

  end
  else
  begin
    ClearGlobal('扫描');
  end;

  InitInspectionRecord();
  InitCDGrid();

  Scan.Text := '';
end;

procedure TfrmGreyInspection.ScanOrder();
begin

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.* ');
    sql.Add(',maxRoll=1+isnull((select cast (max(mjxh) as int) from FinishedCloth_Inspect X where X.subid=B.subid and X.MJType =''正品'' ),0)');
    sql.Add('from Cloth_Main A ');
    sql.Add('inner join Cloth_Sub B on A.MainId=B.MainId');
    sql.Add('where A.MainID=''' + Trim(Scan.Text) + '''');
    sql.Add(' and A.OrderType=''梭织织造单''');
    //ShowMessage(SQL.Text);
    Open;
  end;

  if not ADOTmp.IsEmpty then
  begin
    FAPID := '';
//    FSPID := Trim(ADOTmp.fieldbyname('SPID').AsString);
    FMainId := Trim(ADOTmp.fieldbyname('MainId').AsString);
    FSubId := Trim(ADOTmp.fieldbyname('SubId').AsString);
    FMJCode := Trim(ADOTmp.fieldbyname('C_Code').AsString);
    FMJName := Trim(ADOTmp.fieldbyname('C_CodeName').AsString);
    FMJSpec := Trim(ADOTmp.fieldbyname('C_Spec').AsString);
    FMJMF := Trim(ADOTmp.fieldbyname('MF').AsString);
    FMJKZ := Trim(ADOTmp.fieldbyname('KZ').AsString);
    FMJColor := trim(ADOTmp.fieldbyname('C_Color').AsString);
    JYxh.Text := Trim(ADOTmp.fieldbyname('maxRoll').AsString);

    OrdNote.Text := '订单号:' + Trim(ADOTmp.fieldbyname('ConNo').AsString) + #13;
    OrdNote.Text := OrdNote.Text + '编号:' + FMJCode + #13;
    OrdNote.Text := OrdNote.Text + '品名:' + FMJName + #13;
    OrdNote.Text := OrdNote.Text + '门幅:' + FMJMF + #13;
    OrdNote.Text := OrdNote.Text + '克重:' + FMJKZ + #13;
    OrdNote.Text := OrdNote.Text + '颜色:' + FMJColor + #13;
    OrdNote.Text := OrdNote.Text + '特别提示:' + Trim(ADOTmp.fieldbyname('Note').AsString);

  end
  else
  begin
    ClearGlobal('扫描生产计划单');
  end;

  InitInspectionRecord();
  InitCDGrid();

  Scan.Text := '';

end;

procedure TfrmGreyInspection.ScanAnPai();
var
  FAPXH, FCAPXH: string;
begin

  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JY_Cloth where APID = ''' + Trim(Scan.Text) + '''');
    Open;
  end;
  if not ADOCmd.IsEmpty then
  begin
    application.MessageBox('重复扫描布票！', '提示', 0);
    Exit;
  end;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('select PCID,APXH from PD_Plan_AnPai where APID = ''' + Trim(Scan.Text) + '''');
    Open;
  end;
  if not ADOCmd.IsEmpty then
  begin
    if ADOCmd.fieldbyname('APXH').AsInteger - 1 <> 0 then
    begin
      FAPXH := IntToStr(ADOCmd.fieldbyname('APXH').AsInteger - 1);
      FCAPXH := ADOCmd.fieldbyname('APXH').AsString;
      with ADOTmp do
      begin
        Close;
        sql.Clear;
        sql.Add('select JYFlag from PD_Plan_AnPai where PCID = ''' + Trim(ADOCmd.fieldbyname('PCID').AsString) + '''');
        SQL.Add(' and APXH=' + QuotedStr(Trim(FAPXH)));
        Open;
      end;
      if Trim(ADOTmp.fieldbyname('JYFlag').AsString) <> 'True' then
      begin
        FAPXH := '当前布号: ' + FCAPXH + #13 + FAPXH + '号布还未检验，是否跳过？';
        if MessageBox(self.Handle, PChar(FAPXH), '提示', MB_OKCANCEL or MB_ICONINFORMATION) = IDOK then
        begin
          Next;
        end
        else
        begin
          Exit;
        end;
      end;
    end;

  end;

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('exec P_Get_ScanAnPai ''' + Trim(Scan.Text) + '''');
    Open;
  end;

  if not ADOTmp.IsEmpty then
  begin
    FAPID := Trim(ADOTmp.fieldbyname('APID').AsString);
//    FSPID := Trim(ADOTmp.fieldbyname('SPID').AsString);
    FMainId := Trim(ADOTmp.fieldbyname('MainId').AsString);
    FSubId := Trim(ADOTmp.fieldbyname('SubId').AsString);
    FMJCode := Trim(ADOTmp.fieldbyname('P_Code').AsString);
    FMJName := Trim(ADOTmp.fieldbyname('P_CodeName').AsString);
    FMJSpec := Trim(ADOTmp.fieldbyname('P_Spec').AsString);
    FMJMF := Trim(ADOTmp.fieldbyname('P_MF').AsString);
    FMF_Wai := ADOTmp.fieldbyname('MF_Wai').AsFloat;
    FJSKZ := ADOTmp.fieldbyname('JSKZ').AsFloat;
    FISJSKZ := Trim(ADOTmp.fieldbyname('ISJSKZ').AsString);
    FMJKZ := Trim(ADOTmp.fieldbyname('P_KZ').AsString);
    FMJColor := trim(ADOTmp.fieldbyname('P_Color').AsString);
    JYxh.Text := Trim(ADOTmp.fieldbyname('maxRoll').AsString);
    BatchNo.Text := Trim(ADOTmp.fieldbyname('APBatchNo').AsString);
    FKONGJIA := StrToFloatDEF(ADOTmp.fieldbyname('KONGJIA').AsString, 0);
    fkongjiawei := StrToFloatDEF(ADOTmp.fieldbyname('kongjiawei').AsString, 0);
    OrdNote.Text := '订单号:' + Trim(ADOTmp.fieldbyname('orderno').AsString) + #13;
    OrdNote.Text := OrdNote.Text + '编号:' + FMJCode + #13;
    OrdNote.Text := OrdNote.Text + '品名:' + FMJName + #13;
    OrdNote.Text := OrdNote.Text + '门幅:' + FMJMF + #13;
    OrdNote.Text := OrdNote.Text + '克重:' + FMJKZ + #13;
    OrdNote.Text := OrdNote.Text + '颜色:' + FMJColor + #13;
    OrdNote.Text := OrdNote.Text + '特别提示:' + Trim(ADOTmp.fieldbyname('P_Note').AsString);
  end
  else
  begin
    ClearGlobal('扫描生产计划单');
  end;

  InitInspectionRecord();
  InitCDGrid();

  Scan.Text := '';

end;

procedure TfrmGreyInspection.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 TfrmGreyInspection.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 TfrmGreyInspection.FormDestroy(Sender: TObject);
begin
  frmGreyInspection := nil;
end;

procedure TfrmGreyInspection.On1301(var Message: Tmessage);
var
  i1, i2: Double;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  I3 := strtofloat(format('%.3f', [i1 / 100000]));
  i2 := Message.LParam;
  if IsJsMessage then
  begin
    if (trim(Edit7.Text) = '√') then
    begin
      if person2.Text = '' then
      begin
        if StrToFloat(format('%.1f', [i1 / 100000])) >= 0 then
        begin
          JYLen1.Text := format('%.1f', [i1 / 100000]);
        end
        else
          JYLen1.Text := '0';

      end
      else
      begin
        if person3.Text = '' then
        begin
          if JYLen1.Text <> '' then
          begin
            if (strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen1.Text)) >= 0 then
            begin
              JYLen2.Text := FloatToStr(strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen1.Text));
            end
            else
              JYLen2.Text := '0';

          end
          else
          begin
            JYLen2.Text := format('%.1f', [i1 / 100000]);
          end;
        end
        else
        begin
          if person4.Text = '' then
          begin
            if (JYLen2.Text <> '') and (JYLen1.Text <> '') then
            begin
              if (strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text)) >= 0 then
              begin
                JYLen3.Text := FloatToStr(strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text));
              end
              else
                JYLen3.Text := '0';

            end
            else
            begin
              JYLen3.Text := format('%.1f', [i1 / 100000]);
            end;
          end
          else
          begin
            if person5.Text = '' then
            begin
              if (JYLen3.Text <> '') and (JYLen2.Text <> '') and (JYLen1.Text <> '') then
              begin
                if (strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen3.Text) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text)) >= 0 then
                begin
                  JYLen4.Text := FloatToStr(strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen3.Text) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text));
                end
                else
                  JYLen4.Text := '0';

              end
              else
              begin
                JYLen4.Text := format('%.1f', [i1 / 100000]);
              end;
            end
            else
            begin
              if (JYLen4.Text <> '') and (JYLen3.Text <> '') and (JYLen2.Text <> '') and (JYLen1.Text <> '') then
              begin
                if (strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen4.Text) - strtofloat(jylen3.Text) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text)) >= 0 then
                begin
                  JYLen5.Text := FloatToStr(strtofloat(format('%.1f', [i1 / 100000])) - strtofloat(jylen4.Text) - strtofloat(jylen3.Text) - strtofloat(jylen2.Text) - strtofloat(jylen1.Text));
                end
                else
                  JYLen5.Text := '0';

              end
              else
              begin
                JYLen5.Text := format('%.1f', [i1 / 100000]);
              end;
            end;
          end;
        end;

      end;

//      if i2 = 0 then
//      begin
//        Label9.Caption := 'M';
//        Label6.Caption := 'M';
//        Label16.Caption := 'M';
//        Label23.Caption := 'M';
//        Label27.Caption := 'M';
//      end
//      else
//      begin
//        Label9.Caption := 'Y';
//        Label6.Caption := 'Y';
//        Label16.Caption := 'Y';
//        Label23.Caption := 'Y';
//        Label27.Caption := 'Y';
//      end;
    end;
  end;

end;

procedure TfrmGreyInspection.On1201(var Message: Tmessage);
var
  i1, i2: integer;
  unitname: string;
  fdata: double;
begin
  i1 := Message.WParam;
  i2 := Message.LParam;
  if IsJsMessage then
  begin
    if trim(Edit1.Text) = '√' then
    begin
      JYGW.Text := format('%.1f', [i1 / 100000]);
    end;
  end;
end;

procedure TfrmGreyInspection.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  //DataLink_WFBProducttion.ADOLink.Connected:=False;

  if isCommopen then
  begin
    closeCom(DZCDYDllName);
    closeCom(MBDYDllName);
  end;
  Action := caFree;
end;

procedure TfrmGreyInspection.InitCDGrid();
begin

  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from JY_Cloth_CD where JYID=' + quotedstr(Trim(FFFMJID)));
    //ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOTmp, CDS_MJCD);
  SInitCDSData20(ADOTmp, CDS_MJCD);
end;

procedure TfrmGreyInspection.InitInspectionRecord();
begin

  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select JYPS=count(JYId),JYLen=isnull(sum(JYLen),0) from JY_Cloth where Filler=''' + Trim(DName) + ''' ');
    sql.Add(' and DateDiff(dd,FillTime,getdate())=0 ');
   // ShowMessage(SQL.Text);
    Open;
  end;

  lblJYPS.Caption := '日检验:' + trim(ADOTmp.fieldbyname('JYPS').AsString) + '匹';
  lblJYLen.Caption := '日检验:' + trim(ADOTmp.fieldbyname('JYLen').AsString) + '米';

  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select JYPS=count(JYId),JYLen=isnull(sum(JYLen),0) from JY_Cloth where Filler=''' + Trim(DName) + ''' ');
    sql.Add(' and datediff(month,FillTime,getdate())=0 ');
    //ShowMessage(SQL.Text);
    Open;
  end;

  lblJYPS.Caption := lblJYPS.Caption + '       月检验:' + trim(ADOTmp.fieldbyname('JYPS').AsString) + '匹';
  lblJYLen.Caption := lblJYLen.Caption + '       月检验:' + trim(ADOTmp.fieldbyname('JYLen').AsString) + '米';
  with ADOTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select A.*');
    sql.Add(',SJKZ=(CASE WHEN JYLen>0 THEN ROUND((JYnW/JYLen),0) ELSE 0 END) ');
    sql.Add('from JY_Cloth A where A.JYCRType=''已入库'' ');
    SQL.Add(' and A.APID=''' + Trim(FAPID) + ''' ');
    sql.Add(' and A.Filler=''' + Trim(DName) + '''');
    sql.Add(' and DATEDIFF(HH,Filltime,GETDATE())<5');
    //ShowMessage(SQL.Text);
    Open;
  end;
  SCreateCDS20(ADOTmp, CDS_MJID);
  SInitCDSData20(ADOTmp, CDS_MJID);

end;

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

procedure TfrmGreyInspection.TBCDClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GreyCD';
      flagname := '疵点';
      fnote := True;
      V1Note.Caption := '英文名称';
      if ShowModal = 1 then
      begin
        Self.InitDefectOptions();
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmGreyInspection.FormShow(Sender: TObject);
begin
  InitDefectOptions();
  InitCDGrid();
  InitBatchNo();

  if IsINIFile() then
    ReadINIFile()
  else
    WriteINIFile;

  if trim(Edit7.Text) = '√' then
    IsJsMessage := true;

  if trim(fmanage) <> '高权限' then
  begin
    if trim(DZCDYDllName) <> '' then
      OpenCom(DZCDYDllName);
    if trim(MBDYDllName) <> '' then
      OpenCom(MBDYDllName);
    Edit7.Visible := true;
    Label35.Visible := true;
  end;
end;

procedure TfrmGreyInspection.InitDefectOptions();
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=''GreyCD'' 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 > 54 then
  begin
    i := 54;
  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]) > 6 then
      begin
        if Length(AA[j]) < 12 then
        begin
          TSpeedButton(Controls[j]).Caption := MidStr(Trim(AA[j]), 1, 3) + #13 + MidStr(Trim(AA[j]), 4, Length(AA[j]) - 3);
        end
        else
        begin
          TSpeedButton(Controls[j]).Caption := MidStr(Trim(AA[j]), 1, 3) + #13 + MidStr(Trim(AA[j]), 4, 3) + #13 + MidStr(Trim(AA[j]), 7, Length(AA[j]) - 6);
        end;

      end
      else
      begin
        TSpeedButton(Controls[j]).Caption := AA[j];
      end;

    end;
  end;
end;

function TfrmGreyInspection.SaveData(): Boolean;
var
  maxno, FMJID, BZID, strsql: string;
  FMJLen: Double;
  FJYLEN, FJSLEN: Double;
begin

  FMJID := '';

  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JY_Cloth where JYId=''' + Trim(FMJID) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMJID) = '' then
      begin
        Append;
        if GetLSNo(ADOTmp, maxno, 'G' + Trim(SCXFlag), 'JY_Cloth', 4, 1) = False then
        begin
          ADOCmd.Connection.RollbackTrans;
          Application.MessageBox('生成流水号异常！', '提示', 0);
          BTPrint.Enabled := True;
          exit;
        end;
      end
      else
      begin
        maxno := Trim(FMJID);
        Edit;
      end;
      FieldByName('MainId').value := Trim(FMainId);
      FieldByName('SubId').value := Trim(FSubId);
      FieldByName('APId').value := Trim(FAPID);
      FieldByName('P_Code').value := Trim(FMJCode);
      FieldByName('P_CodeName').value := Trim(FMJName);
      FieldByName('P_Spec').value := Trim(FMJSpec);
      FieldByName('P_Color').value := Trim(FMJColor);
      FieldByName('P_MF').value := Trim(FMJMF);
      FieldByName('P_KZ').value := Trim(FMJKZ);
      FieldByName('BatchNo').value := Trim(BatchNo.Text);
      FieldByName('WXPH').value := Trim(WXPH.Text) + '';
      FieldByName('MachNo').value := Trim(FCarNo) + '';
      FieldByName('JYID').Value := Trim(maxno);
      FieldByName('JYCRType').Value := '未入库';
      FieldByName('Valie').Value := 'Y';
      FieldByName('kaijian').Value := StrToFloatDef(kaijian.Text, 0);
      FieldByName('JYXH').Value := strtointdef(trim(JYxh.Text), 0);

      //挡车工
      FieldByName('Person1').Value := trim(Person1.Text);
      FieldByName('Person2').Value := trim(Person2.Text);
      FieldByName('Person3').Value := trim(Person3.Text);
      FieldByName('Person4').Value := trim(Person4.Text);
      FieldByName('Person5').Value := trim(Person5.Text);
      //挡车工长度
      FieldByName('JYLen1').Value := StrToFloatdef(trim(JYLen1.Text), 0);
      FieldByName('JYLen2').Value := StrToFloatdef(trim(JYLen2.Text), 0);
      FieldByName('JYLen3').Value := StrToFloatdef(trim(JYLen3.Text), 0);
      FieldByName('JYLen4').Value := StrToFloatdef(trim(JYLen4.Text), 0);
      FieldByName('JYLen5').Value := StrToFloatdef(trim(JYLen5.Text), 0);
      //长度
      FieldByName('JYLen').Value := StrToFloatdef(trim(JYLen1.Text), 0) + StrToFloatdef(trim(JYLen2.Text), 0) + StrToFloatdef(trim(JYLen3.Text), 0) + StrToFloatdef(trim(JYLen4.Text), 0) + StrToFloatdef(trim(JYLen5.Text), 0) + FKONGJIA;
      //皮重
      FieldByName('JYTare').Value := 0;
      //StrToFloatdef(trim(JYTare.Text), 0)
     // 毛重
      FieldByName('JYGW').Value := StrToFloatdef(trim(JYGW.Text), 0) + fkongjiawei;
     // 净重
      FieldByName('JYNW').Value := StrToFloatdef(trim(JYGW.Text), 0);
      //- StrToFloatdef(trim(JYTare.Text), 0);
      //系数
      FieldByName('JYXS').Value := StrToFloatdef(trim(JYXS.Text), 0);
      FieldByName('kongjia').Value := FKONGJIA;
      FieldByName('kongjiaWEI').Value := FKONGJIAWEI;
      FieldByName('JSKZ').Value := FJSKZ;
      //计算米数

      if (FJSKZ > 0) then
      begin
        FieldByName('JSLen').Value := RoundFloat(((StrToFloatdef(trim(JYGW.Text), 0)) * 1000 / FJSKZ + FKONGJIA), 1);
      end
      else
      begin
        FieldByName('JSLen').Value := RoundFloat((StrToFloatdef(trim(JYLen1.Text), 0) + StrToFloatdef(trim(JYLen2.Text), 0) + StrToFloatdef(trim(JYLen3.Text), 0) + StrToFloatdef(trim(JYLen4.Text), 0) + StrToFloatdef(trim(JYLen5.Text), 0)), 1) + FKONGJIA;
      end;
      if Trim(Edit3.Text) <> '' then
      begin
        FieldByName('JYType').Value := '正品';
      end;
      if Trim(Edit4.Text) <> '' then
      begin
        FieldByName('JYType').Value := '次品';
      end;

      if Trim(FMJID) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);
        FieldByName('FillCode').Value := Trim(DCode);
        FieldByName('FillTime').Value := SGetServerDateTime(ADOTmp);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditCode').Value := Trim(DCode);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTmp);
      end;
      FieldByName('JTType').Value := Trim(SCXFlag);
      Post;
    end;
 
    /////////////////////////更新卷号/////////////////////////////////////

    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update JY_Cloth SET ');
      sql.Add('JYXH= (select isnull(MAX(JYXH),0)+1 from JY_Cloth X where X.JYID<>JY_Cloth.JYID and X.subid=JY_Cloth.subid and X.BatchNo=JY_Cloth.BatchNo )');
      sql.Add('where JYID=''' + Trim(maxno) + ''' ');
      execsql;
    end;

    
    //查询卷号修改界面
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select JYXH from JY_Cloth');
      sql.Add('where JYID=''' + Trim(maxno) + '''');
      open;
      if not IsEmpty then
      begin
        JYxh.Text := fieldbyname('JYxh').AsString;
      end;
    end;
    //////////////////////////更新卷号////////////////////////////////////
    FMJID := Trim(maxno);
    FFFMJID := Trim(maxno);

////////////////////////保存母卷疵点表//////////////////////////////////////
    with CDS_MJCD do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_MJCD.fieldbyname('JCID').AsString) = '' then
        begin
          if GetLSNo(ADOTmp, maxno, 'GC', 'JY_Cloth_CD', 5, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            BTPrint.Enabled := True;
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(CDS_MJCD.fieldbyname('JCID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JY_Cloth_CD  ');
          sql.Add(' where JCID=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_MJCD.fieldbyname('JCID').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('JYId').Value := Trim(FMJID);
          FieldByName('JCID').Value := Trim(maxno);
          SSetSaveDataCDSNew(ADOCmd, Tv2, CDS_MJCD, 'JY_Cloth_CD', 0);
//          FieldByName('DChePrice').Value := CDS_MJCD.fieldbyname('DChePrice').Value;
//          FieldByName('JXiuPrice').Value := CDS_MJCD.fieldbyname('JXiuPrice').Value;
          Post;
        end;
        CDS_MJCD.Edit;
        CDS_MJCD.FieldByName('JCID').Value := Trim(maxno);
        Next;
      end;
    end;

    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update JY_Cloth SET ');
      sql.Add('CDList=cast((select CDName+CAST(CDQty as varchar)+''M;'' from JY_Cloth_CD where JY_Cloth_CD.JYID=JY_Cloth.JYID for xml path('''')) as varchar(200))');
      sql.Add('where JYID=''' + Trim(FMJID) + ''' ');
      execsql;
    end;

    with ADOCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update JY_Cloth SET ');
      sql.Add('jslen=jylen');
      sql.Add('where JYID=''' + Trim(FMJID) + ''' ');
      sql.Add('and  jslen<jylen');
      execsql;
    end;
////////////////////////保存母卷疵点表//////////////////////////////////////
////////////////////////出入库及库存/////////////////////////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_CK_Cloth_CRK @JYID=''' + trim(FMJID) + '''');
      execsql;
    end;
////////////////////////出入库及库存/////////////////////////////////////
////////////////////////修改布票状态/////////////////////////////////////
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('update PD_Plan_AnPai SET jyflag=''1'' ');
      sql.Add('where APID=''' + trim(fapid) + ''' ');
      execsql;
    end;
////////////////////////修改布票状态/////////////////////////////////////

    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
    BTPrint.Enabled := True;
  end;
end;

procedure TfrmGreyInspection.BTPrintClick(Sender: TObject);
var
  fPrintFile: string;
  mvalue: Double;
  i: Integer;
begin
  BTPrint.Enabled := False;
  Scan.SetFocus;

  if SelfConnData() = False then
  begin
    Application.MessageBox('网络连接失败,请重新保存', '提示', 0);
    Exit;
  end;

  if CheckData('提交') = False then
  begin
    BTPrint.Enabled := True;
    exit;
  end;

  if SaveData() then
  begin
    if StrToFloatDef(kaijian.Text, 0) <> 0 then
    begin
      with ADOCmd do
      begin
        close;
        sql.Clear;
        sql.Add('exec P_JY_ChaiPi ');
        sql.Add(' @OrgJYID=' + quotedstr(FFFMJID));
        sql.Add(',@KJLen=' + kaijian.text);
        open;
      end;
      if ADOCmd.FieldByName('intReturn').AsInteger = -1 then
      begin
        application.MessageBox(PChar(trim(ADOCmd.FieldByName('ShowMsg').AsString)), '提示信息', 0);
        ADOCmd.Connection.RollbackTrans;
      end;
    end;
    JYxh.Text := inttostr(strTointdef(trim(JYXH.Text), 0) + 1);
    if Trim(Edit6.Text) = '√' then
    begin
      PrtData(FFFMJID);
    end;
  end
  else
  begin
    BTPrint.Enabled := True;
  end;

  InitInspectionRecord();
  InitCDGrid();
  ClearGlobal('提交');
  JYLen1.SetFocus;
  jylen1.Text := '';
  jylen2.Text := '';
  jylen3.Text := '';
  jylen4.Text := '';
  jylen5.Text := '';
  person1.Text := '';
  person2.Text := '';
  person3.Text := '';
  person4.Text := '';
  person5.Text := '';
  FMainId := '';
  BTPrint.Enabled := True;
end;

procedure TfrmGreyInspection.PrtData(FMJID: string);
var
  fPrintFile: string;
  Txt, fImagePath: string;
  Moudle: THandle;
  Makebar: TMakebar;
  Mixtext: TMixtext;
begin
  with ADOQueryPrint do
  begin
    Close;
    SQL.Clear;
    sql.Add(' EXEC P_JY_Print_Lab ');
    SQL.Add(' @JYID=''' + Trim(FMJID) + '''');
    Open;
  end;
  if ADOQueryPrint.IsEmpty then
  begin
    application.MessageBox('标签内容未找到！', '提示信息', MB_ICONERROR);
    BTPrint.Enabled := True;
    exit;
  end;
  try
    Moudle := LoadLibrary('MakeQRBarcode.dll');
    @Makebar := GetProcAddress(Moudle, 'Make');
    @Mixtext := GetProcAddress(Moudle, 'MixText');
    Txt := Trim(ADOQueryPrint.fieldbyname('JYID').AsString);
    fImagePath := ExtractFilePath(Application.ExeName) + 'image\temp.bmp';
    if not DirectoryExists(pchar(ExtractFilePath(Application.ExeName) + 'image')) then
      CreateDirectory(pchar(ExtractFilePath(Application.ExeName) + 'image'), nil);
    if FileExists(fImagePath) then
      DeleteFile(fImagePath);
    Makebar(pchar(Txt), Length(Txt), 3, 3, 0, PChar(fImagePath), 3);
  except
    application.MessageBox('条形码生成失败！', '提示信息', MB_ICONERROR);
    BTPrint.Enabled := True;
    exit;
  end;
  ExportFtErpFile(Trim(ADOQueryPrint.fieldbyname('LabName').AsString), ADOTmp);
  if Trim(ADOQueryPrint.fieldbyname('LabName').AsString) <> '' then
  begin
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\' + Trim(ADOQueryPrint.fieldbyname('LabName').AsString) + '.rmf';
  end
  else
  begin
    ExportFtErpFile('通用坯布标签.rmf', ADOTmp);
    fPrintFile := ExtractFilePath(Application.ExeName) + 'Report\通用坯布标签.rmf';
  end;

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

procedure TfrmGreyInspection.SpeedButton1Click(Sender: TObject);
var
  fsj: string;
begin
  fsj := Trim(TSpeedButton(Sender).Hint);
  if Trim(fsj) = '' 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 TfrmGreyInspection.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 TfrmGreyInspection.SpeedButton13Click(Sender: TObject);
var
  i: Integer;
begin
  if CheckData('疵点') = False then
    exit;

  FCDName := Trim(TSpeedButton(Sender).Hint);
  MovePanel1.Visible := True;
  Label7.Caption := Trim(FCDName);
  if FCDName = '开机' then
  begin
    DCGKaiJ.text := '4';
  end;
  //显示数字键盘
//  DChePrice.SetFocus;
//  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(DChePrice.Name);
//      end;
//    end;
//  end;

end;

procedure TfrmGreyInspection.cxGridDBColumn2PropertiesChange(Sender: TObject);
var
  fsj: string;
begin

  fsj := Trim(Order_MJ.fieldbyname('SubId').AsString);
  Order_MJ.DisableControls;
  with Order_MJ do
  begin
    First;
    while not Eof do
    begin
      if Trim(Order_MJ.fieldbyname('SubId').AsString) <> fsj then
      begin
        Edit;
        FieldByName('SSel').Value := False;
      end;
      Next;
    end;
  end;
  Order_MJ.EnableControls;
  Order_MJ.Locate('SubId', fsj, []);
end;

procedure TfrmGreyInspection.Button5Click(Sender: TObject);
var
  fPrintFile: string;
  i: Integer;
  mvalue: Double;
begin
  if CDS_MJID.IsEmpty then
    Exit;
  PrtData(CDS_MJID.fieldbyname('JYID').AsString);
end;

procedure TfrmGreyInspection.SpeedButton49Click(Sender: TObject);
begin
  Panel3.Visible := False;
end;

procedure TfrmGreyInspection.ScanKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
//    if Pos('CM', Trim(Scan.Text)) > 0 then
//    begin
//      FOperationStatus := '扫描生产计划单';
//      ClearGlobal('扫描');
//      ScanOrder();
//    end
//    else
//    begin
//      FOperationStatus := '扫描产品信息';
//      ClearGlobal('扫描');
//      ScanSample();
//    end;
    if edtDel.Text = '√' then
    begin
      DelDate(Trim(Scan.Text));
    end
    else
    begin
      FOperationStatus := '扫描布票';
      ClearGlobal('扫描');
      ScanAnpai();
    end;

    JYLen1.SetFocus;
    Scan.Text := '';
  end;
end;

procedure TfrmGreyInspection.Edit3Click(Sender: TObject);
begin
  if Trim(Edit3.Text) = '' then
  begin
    Edit3.Text := '√';
    Edit4.Text := '';
  end
  else
  begin
    Edit3.Text := '';
    Edit4.Text := '√';
  end;
end;

procedure TfrmGreyInspection.Edit4Click(Sender: TObject);
begin
  if Trim(Edit4.Text) = '' then
  begin
    Edit4.Text := '√';
    Edit3.Text := '';
  end
  else
  begin
    Edit4.Text := '';
    Edit3.Text := '√';
  end;
end;

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

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

procedure TfrmGreyInspection.JYGWChange(Sender: TObject);
begin
  QuantityConversion();
end;

procedure TfrmGreyInspection.ScanClick(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 TfrmGreyInspection.Edit7Click(Sender: TObject);
begin
  if Trim(Edit7.Text) = '' then
  begin
    Edit7.Text := '√';
  end
  else
  begin
    Edit7.Text := '';
  end;
end;

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

procedure TfrmGreyInspection.FormCreate(Sender: TObject);
begin
  IsCommopen := false;
  IsJsMessage := false;
end;

procedure TfrmGreyInspection.Edit8Click(Sender: TObject);
begin
  if Trim(Edit8.Text) = '' then
  begin
    Edit8.Text := '√';
    Button5.Visible := true;
  end
  else
  begin
    Edit8.Text := '';
    Button5.Visible := false;
  end;
end;

procedure TfrmGreyInspection.JYLen1Change(Sender: TObject);
var
  XiShu, FMJLen, FMJMaShu: Double;
begin
  QuantityConversion();

end;

procedure TfrmGreyInspection.Tv2CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_MJCD.IsEmpty then
    Exit;

  if Trim(CDS_MJCD.fieldbyname('MCID').AsString) = '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    CDS_MJCD.Delete;
  end;
end;

procedure TfrmGreyInspection.ToolButton1Click(Sender: TObject);
begin
  InitDefectOptions();
end;

procedure TfrmGreyInspection.ToolButton2Click(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'GreyBatchNo';
      flagname := '批号';
      if ShowModal = 1 then
      begin
        InitBatchNo();
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;

end;

procedure TfrmGreyInspection.person1Click(Sender: TObject);
var
  i: Integer;
begin

  Panel3.Visible := false;
//  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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        Person1.Text := frmSCPerson.FSDPerson;
      end;
    end;
  finally
    frmSCPerson.Free;
  end;

end;

procedure TfrmGreyInspection.person2Click(Sender: TObject);
var
  i: Integer;
begin

  Panel3.Visible := false;
//  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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        Person2.Text := frmSCPerson.FSDPerson;
      end;
    end;
  finally
    frmSCPerson.Free;
  end;
end;

procedure TfrmGreyInspection.ToolButton3Click(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'SCPerson';
      flagname := '挡车工';
      V1Note.Caption := '组别';
      fnote := True;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZDYHelp.free;
  end;
end;

procedure TfrmGreyInspection.person5Click(Sender: TObject);
var
  i: Integer;
begin

  Panel3.Visible := false;
//  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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        Person5.Text := frmSCPerson.FSDPerson;
      end;
    end;
  finally
    frmSCPerson.Free;
  end;

end;

procedure TfrmGreyInspection.person4Click(Sender: TObject);
var
  i: Integer;
begin

  Panel3.Visible := false;
//  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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        Person4.Text := frmSCPerson.FSDPerson;
      end;
    end;
  finally
    frmSCPerson.Free;
  end;
end;

procedure TfrmGreyInspection.person3Click(Sender: TObject);
var
  i: Integer;
begin

  Panel3.Visible := false;
//  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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        Person3.Text := frmSCPerson.FSDPerson;
      end;
    end;
  finally
    frmSCPerson.Free;
  end;
end;

procedure TfrmGreyInspection.edtDelClick(Sender: TObject);
begin
  if Trim(TEdit(Sender).Text) = '' then
  begin
    TEdit(Sender).Text := '√';
    Edit7.Text := '';
  end
  else
  begin
    TEdit(Sender).Text := '';
    Edit7.Text := '√';
  end;
end;

procedure TfrmGreyInspection.Button1Click(Sender: TObject);
var
  mvalue: Double;
begin
  if (DCheKouK.Text = '') or (DCheKouK.Text = null) then
  begin
    Application.MessageBox('挡车工不能为空!', '提示', 0);
    Exit;
  end;
  if Label7.Caption <> '开机' then
  begin

    if TryStrToFloat(DChePrice.Text, mvalue) = False then
    begin
      Application.MessageBox('挡车工扣款金额非法数字!', '提示', 0);
      Exit;
    end;
    if mvalue = 0 then
    begin
      Application.MessageBox('挡车工扣款金额不能为0!', '提示', 0);
      Exit;
    end;
  end
  else if Label7.Caption = '开机' then
  begin

    if TryStrToFloat(DCGKaiJ.Text, mvalue) = False then
    begin
      Application.MessageBox('挡车工开机金额非法数字!', '提示', 0);
      Exit;
    end;
    if mvalue = 0 then
    begin
      Application.MessageBox('挡车工开机金额不能为0!', '提示', 0);
      Exit;
    end;
  end;

  with CDS_MJCD do
  begin
    Append;
    FieldByName('CDName').Value := Trim(FCDName);
    FieldByName('DChePrice').Value := StrToFloatDef(DChePrice.Text, 0);
    FieldByName('JXiuPrice').Value := StrToFloatDef(JXiuPrice.Text, 0);
    FieldByName('CDLEN').Value := StrToFloatDef(CDLEN.Text, 0);
    FieldByName('DCGKaiJ').Value := StrToFloatDef(DCGKaiJ.Text, 0);
    FieldByName('DCheKouK').Value := Trim(DCheKouK.Text);
    FieldByName('JXiuKouK').Value := Trim(JXiuKouK.Text);
    Post;
  end;
  DChePrice.Text := '';
  JXiuPrice.Text := '';
  DCGKaiJ.Text := '';
  CDLEN.Text := '';
  DCheKouK.Text := '';
  JXiuKouK.Text := '';
  MovePanel1.Visible := False;
  Panel3.Visible := False;
end;

procedure TfrmGreyInspection.Button4Click(Sender: TObject);
begin

  DChePrice.Text := '';
  JXiuPrice.Text := '';
  DCGKaiJ.Text := '';
  DCheKouK.Text := '';
  JXiuKouK.Text := '';
  MovePanel1.Visible := False;
  Panel3.Visible := False;
end;

procedure TfrmGreyInspection.ToolButton4Click(Sender: TObject);
begin
  try
    frmFinishedClothStatistical := TfrmFinishedClothStatistical.Create(self);
    with frmFinishedClothStatistical do
    begin

      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmFinishedClothStatistical.Free;
  end;
end;

procedure TfrmGreyInspection.DCheKouKClick(Sender: TObject);
var
  i: Integer;
  FDCheKouK: string;
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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'SCPerson';
      if ShowModal = 1 then
      begin
        FDCheKouK := frmSCPerson.FSDPerson;
        if (Trim(FDCheKouK) = Trim(person1.text)) or (Trim(FDCheKouK) = Trim(person2.text)) or (Trim(FDCheKouK) = Trim(person3.text)) or (Trim(FDCheKouK) = Trim(person4.text)) or (Trim(FDCheKouK) = Trim(person5.text)) then
        begin
          DCheKouK.Text := FDCheKouK;
        end
        else
        begin
          raise Exception.Create('责任挡车工必须在挡车工1到挡车工5中!');
        end;

      end;
    end;
  finally
    frmSCPerson.Free;
  end;
end;

procedure TfrmGreyInspection.ToolButton5Click(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'JXiuG';
      flagname := '机修工';
      V1Note.Caption := '组别';
      fnote := True;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmZDYHelp.free;
  end;
end;

procedure TfrmGreyInspection.JXiuKouKClick(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;

  try
    frmSCPerson := TfrmSCPerson.Create(self);
    with frmSCPerson do
    begin
      FlagStr := 'JXiuG';
      if ShowModal = 1 then
      begin
        JXiuKouK.Text := frmSCPerson.FSDPerson;
      end;
    end;
  finally
    frmSCPerson.Free;
  end;
end;

procedure TfrmGreyInspection.Label9Click(Sender: TObject);
begin
  if Label9.Caption = 'Y' then
  begin
    Label9.Caption := 'M';
    Label6.Caption := 'M';
    Label16.Caption := 'M';
    Label23.Caption := 'M';
    Label27.Caption := 'M';
  end
  else
  begin
    Label9.Caption := 'Y';
    Label6.Caption := 'Y';
    Label16.Caption := 'Y';
    Label23.Caption := 'Y';
    Label27.Caption := 'Y';
  end;
end;

procedure TfrmGreyInspection.Label6Click(Sender: TObject);
begin
  if Label6.Caption = 'Y' then
  begin
    Label9.Caption := 'M';
    Label6.Caption := 'M';
    Label16.Caption := 'M';
    Label23.Caption := 'M';
    Label27.Caption := 'M';
  end
  else
  begin
    Label9.Caption := 'Y';
    Label6.Caption := 'Y';
    Label16.Caption := 'Y';
    Label23.Caption := 'Y';
    Label27.Caption := 'Y';
  end;
end;

procedure TfrmGreyInspection.Label16Click(Sender: TObject);
begin
  if Label16.Caption = 'Y' then
  begin
    Label9.Caption := 'M';
    Label6.Caption := 'M';
    Label16.Caption := 'M';
    Label23.Caption := 'M';
    Label27.Caption := 'M';
  end
  else
  begin
    Label9.Caption := 'Y';
    Label6.Caption := 'Y';
    Label16.Caption := 'Y';
    Label23.Caption := 'Y';
    Label27.Caption := 'Y';
  end;
end;

procedure TfrmGreyInspection.Label23Click(Sender: TObject);
begin
  if Label23.Caption = 'Y' then
  begin
    Label9.Caption := 'M';
    Label6.Caption := 'M';
    Label16.Caption := 'M';
    Label23.Caption := 'M';
    Label27.Caption := 'M';
  end
  else
  begin
    Label9.Caption := 'Y';
    Label6.Caption := 'Y';
    Label16.Caption := 'Y';
    Label23.Caption := 'Y';
    Label27.Caption := 'Y';
  end;
end;

procedure TfrmGreyInspection.Label27Click(Sender: TObject);
begin
  if Label27.Caption = 'Y' then
  begin
    Label9.Caption := 'M';
    Label6.Caption := 'M';
    Label16.Caption := 'M';
    Label23.Caption := 'M';
    Label27.Caption := 'M';
  end
  else
  begin
    Label9.Caption := 'Y';
    Label6.Caption := 'Y';
    Label16.Caption := 'Y';
    Label23.Caption := 'Y';
    Label27.Caption := 'Y';
  end;
end;

procedure TfrmGreyInspection.Edit1Click(Sender: TObject);
begin
  if Trim(Edit1.Text) = '' then
  begin
    Edit1.Text := '√';
  end
  else
  begin
    Edit1.Text := '';
  end;
end;

procedure TfrmGreyInspection.SpeedButton43Click(Sender: TObject);
begin
  if edtDel.Text = '√' then
  begin
    DelDate(Trim(Scan.Text));
  end
  else
  begin
    FOperationStatus := '扫描布票';
    ClearGlobal('扫描');
    ScanAnpai();
  end;

  JYLen1.SetFocus;
  Scan.Text := '';

end;

procedure TfrmGreyInspection.JYLen1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(person1.Text) = '' then
  begin
    raise Exception.Create('先输入挡车工1!');
  end;
end;

procedure TfrmGreyInspection.JYLen2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(person2.Text) = '' then
  begin
    raise Exception.Create('先输入挡车工2!');
  end;
end;

procedure TfrmGreyInspection.JYLen3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(person3.Text) = '' then
  begin
    raise Exception.Create('先输入挡车工3!');
  end;
end;

procedure TfrmGreyInspection.JYLen4MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(person4.Text) = '' then
  begin
    raise Exception.Create('先输入挡车工4!');
  end;
end;

procedure TfrmGreyInspection.JYLen5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(person5.Text) = '' then
  begin
    raise Exception.Create('先输入挡车工5!');
  end;
end;

end.

