unit U_DJBKKInPut;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxCalendar, cxDropDownEdit, ComCtrls, ToolWin,
  cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxClasses, cxControls, cxGridCustomView, cxGrid, cxGridCustomPopupMenu,
  cxGridPopupMenu, ADODB, DBClient, cxButtonEdit, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmDJBKKInPut = class(TForm)
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column2: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    ToolBar1: TToolBar;
    TBAdd: TToolButton;
    TBDel: TToolButton;
    TBSave: TToolButton;
    TBClose: TToolButton;
    v1Column4: TcxGridDBColumn;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    cxGridPopupMenu2: TcxGridPopupMenu;
    v1Column12: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column17: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxgrdWSTaiTou: TcxGridDBColumn;
    cxgrdSPType: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBAddClick(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column16PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column18PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure v1Column12PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure v1Column3PropertiesEditValueChanged(Sender: TObject);
    procedure Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
  private
    { Private declarations }

    function SaveCKData(): Boolean;
  public
    { Public declarations }
    XGQX: string;
    FBCId: string;                             
    canshu1: string;
  end;

var
  frmDJBKKInPut: TfrmDJBKKInPut;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_ZdyAttachGYS, U_ProductOrderListSel;

{$R *.dfm}

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

procedure TfrmDJBKKInPut.TBAddClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty = False then
  begin
    CopyAddRowCDS(CDS_Sub);
    with CDS_Sub do
    begin
      Edit;
      FieldByName('SPID').Value := null;
      //FieldByName('WSTaiTou').Value := '伊夫';
      FieldByName('SPType').Value := '正品';
      post;
    end;
  end
  else
  begin
    with CDS_Sub do
    begin
      Append;
      FieldByName('CRTime').Value := Trim(FormatDateTime('yyyy-MM-dd', Now));
      FieldByName('WSTaiTou').Value := '伊夫';
      FieldByName('SPType').Value := '正品';
      Post;
    end;
  end;
end;

function TfrmDJBKKInPut.SaveCKData(): Boolean;
var
  FCRID, Maxno, FFSPID: string;
  FDate: TDateTime;
begin
  FDate := SGetServerDateTime(ADOQueryTemp);
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Sub.DisableControls;
    with CDS_Sub do
    begin
      First;
      while not eof do
      begin
        with ADOQueryTemp do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID=''' + Trim(CDS_Sub.fieldbyname('SPID').AsString) + '''');
          open;
        end;
        FFSPID := Trim(ADOQueryTemp.fieldbyname('SPID').AsString);
        if Trim(FFSPID) = '' then
        begin
          if CDS_Sub.FieldByName('CRTime').AsDateTime > FDate then
          begin
            CDS_Sub.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('开卡时间大于当前日期不能保存!', '提示', 0);
            Exit;
          end;
          if (FDate - CDS_Sub.FieldByName('CRTime').AsDateTime) > 90 then
          begin
            CDS_Sub.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('开卡时间比当前日期小90天，不能操作!', '提示', 0);
            Exit;
          end;
          if GetLSNo(ADOQueryCmd, Maxno, 'KK', 'CK_SXPB_CR', 3, 1) = False then
          begin
            Result := False;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取开卡编号失败!', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          Maxno := Trim(FFSPID);
        end;
        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from CK_SXPB_CR where SPID=''' + Trim(Maxno) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(FFSPID) = '' then
          begin
            Append;
          end
          else
          begin
            Edit;
          end;
          FieldByName('SPID').Value := Trim(Maxno);
          FieldByName('FZSPID').Value := Trim(Maxno);
          FieldByName('CKName').Value := '待检布';
          FieldByName('FactoryNo').Value := Trim(CDS_Sub.fieldbyname('FactoryNo').AsString);
          FieldByName('FromFactoryNo').Value := Trim(CDS_Sub.fieldbyname('FromFactoryNo').AsString);
          FieldByName('ToFactoryNo').Value := Trim(CDS_Sub.fieldbyname('ToFactoryNo').AsString);
          FieldByName('ORDMainIdRK').Value := Trim(CDS_Sub.fieldbyname('ORDMainIdRK').AsString);
          FieldByName('ORDSubIdRK').Value := Trim(CDS_Sub.fieldbyname('ORDSubIdRK').AsString);
          FieldByName('CRFlag').Value := '入库';
          FieldByName('CRQtyFlag').Value := 1;
          RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Sub, 'CK_SXPB_CR', 2);
          if Trim(FFSPID) = '' then
            FieldByName('Filler').Value := Trim(DName)
          else
          begin
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDate(ADOQueryTemp);
          end;
          if Trim(CDS_Sub.fieldbyname('OrderNo').AsString) <> '' then
          begin
            FieldByName('QCOrderNo').Value := Trim(CDS_Sub.fieldbyname('OrderNo').AsString);
          end;

          if Trim(CDS_Sub.fieldbyname('XiaoPi').AsString) <> '' then
          begin
            FieldByName('XiaoPiType').Value := '有小匹';
          end
          else
          begin
            FieldByName('XiaoPiType').Value := '无小匹';
          end;
          FieldByName('XiaoPiStr').Value := Trim(CDS_Sub.fieldbyname('XiaoPi').AsString);

          if Trim(CDS_Sub.fieldbyname('DaPi').AsString) <> '' then
          begin
            FieldByName('DaPiType').Value := '有大匹';
          end
          else
          begin
            FieldByName('DaPiType').Value := '无大匹';
          end;
          FieldByName('DaPiStr').Value := Trim(CDS_Sub.fieldbyname('DaPi').AsString);

          FieldByName('PiQty').Value := CDS_Sub.fieldbyname('PiQty').AsFloat;
          FieldByName('Qty').Value := CDS_Sub.fieldbyname('Qty').AsFloat;
          Post;
        end;
        if Trim(FFSPID)='' then
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('select *from CK_SXPB_CR where SPID=''' + Trim(Maxno) + '''');
            Open;
          end;
          if (FDate - ADOQueryCmd.FieldByName('CRTime').AsDateTime) > 90 then
          begin
            CDS_Sub.EnableControls;
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('开卡时间错误，不能保存，请再次核查!', '提示', 0);
            Exit;
          end;
        end;

        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('UPDATE WFB_MJJY set MainId=ORDMainIdRK,SubId=ORDSubIdRK  from CK_SXPB_CR ');
          sql.Add('where WFB_MJJY.APID =CK_SXPB_CR.SPID and WFB_MJJY.APID=' + quotedstr(Trim(Maxno)));
          ExecSQL;
        end;

        with ADOQueryCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('exec P_Update_XiaoPi :SubId');
          Parameters.ParamByName('SubId').Value := Trim(CDS_Sub.fieldbyname('ORDSubIdRK').AsString);
          ExecSQL;
        end;
        Edit;
        FieldByName('SPID').Value := Trim(Maxno);
        Post;
        Next;
      end;
    end;
    CDS_Sub.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存异常!', '提示', 0);
  end;

end;

procedure TfrmDJBKKInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption), Tv1, '开卡管理');
  Close;
end;

procedure TfrmDJBKKInPut.FormShow(Sender: TObject);
var
  fsj: string;
begin
  ReadCxGrid(trim(self.Caption), Tv1, '开卡管理');
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add(' select A.* ');
    sql.Add(' from CK_SXPB_CR A');
    sql.Add(' where SPID=''' + Trim(FBCId) + '''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_Sub);
  SInitCDSData20(ADOQueryTemp, CDS_Sub);
  if CDS_Sub.IsEmpty then
    Exit;

  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CK_SXPB_CR where FZSPID=''' + Trim(CDS_Sub.fieldbyname('SPID').AsString) + '''');
    sql.Add(' and CRQtyFlag=-1');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    v1Column4.Options.Focusing := False;
    v1Column13.Options.Focusing := False;
    v1Column14.Options.Focusing := False;
    v2Column1.Options.Focusing := False;
    v1Column8.Options.Focusing := False;
    v1Column7.Options.Focusing := False;
    v1Column1.Options.Focusing := False;
    v1Column10.Options.Focusing := False;
    v1Column11.Options.Focusing := False;
    Exit;
  end
  else
  begin
    v1Column4.Options.Focusing := True;
    v1Column13.Options.Focusing := True;
    v1Column14.Options.Focusing := True;
    v2Column1.Options.Focusing := True;
    v1Column8.Options.Focusing := True;
    v1Column7.Options.Focusing := True;
    v1Column1.Options.Focusing := True;
    v1Column10.Options.Focusing := True;
    v1Column11.Options.Focusing := True;
  end;

end;

procedure TfrmDJBKKInPut.TBDelClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if Trim(CDS_Sub.fieldbyname('SPID').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where FZSPID=''' + Trim(CDS_Sub.fieldbyname('SPID').AsString) + '''');
      sql.Add(' and CRQtyFlag=-1');
      Open;
    end;
    if ADOQueryTemp.IsEmpty = False then
    begin
      Application.MessageBox('已有出库记录，不能删除!', '提示', 0);
      Exit;
    end;
    try
      ADOQueryCmd.Connection.BeginTrans;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add(' delete CK_SXPB_CR where SPID=''' + Trim(CDS_Sub.fieldbyname('SPID').AsString) + '''');
        ExecSQL;
      end;
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('exec P_Update_XiaoPi :SubId');
        Parameters.ParamByName('SubId').Value := Trim(CDS_Sub.fieldbyname('ORDSubIdRK').AsString);
        ExecSQL;
      end;
      ADOQueryCmd.Connection.CommitTrans;
      CDS_Sub.Delete;
    except
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('删除异常!', '提示', 0);
    end;

  end
  else
  begin
    CDS_Sub.Delete;
  end;

end;

procedure TfrmDJBKKInPut.TBSaveClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then
    Exit;
  if CDS_Sub.Locate('CRTime', null, []) = True then
  begin
    Application.MessageBox('开卡时间不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('CRType', null, []) = True then
  begin
    Application.MessageBox('开卡类型不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('SPName', null, []) = True then
  begin
    Application.MessageBox('品名不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('OrderNo', null, []) = True then
  begin
    Application.MessageBox('订单号不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('FactoryName', null, []) = True then
  begin
    Application.MessageBox('加工厂不能为空!', '提示', 0);
    Exit;
  end;

  if CDS_Sub.Locate('PiQty', null, []) = True then
  begin
    Application.MessageBox('匹数不能为空!', '提示', 0);
    Exit;
  end;
  if CDS_Sub.Locate('Qty', null, []) = True then
  begin
    Application.MessageBox('数量不能为空!', '提示', 0);
    Exit;
  end;
  if CDS_Sub.Locate('QtyUnit', null, []) = True then
  begin
    Application.MessageBox('数量单位不能为空!', '提示', 0);
    Exit;
  end;
  if canshu1 <> '高权限' then
  begin
    with CDS_Sub do
    begin
      First;
      while not Eof do
      begin
        if CDS_Sub.FieldByName('CRTime').AsDateTime < Now() - 7 then
        begin
          Application.MessageBox('开卡时间不能选择7天前!', '提示', 0);
          Exit;
        end;
        Next;
      end;
    end;
  end;

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

procedure TfrmDJBKKInPut.v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin                              
      flag := 'SXKuWei';
      flagname := '库位';                         
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('KuWei').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDJBKKInPut.v1Column14PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      CheckBox2.Checked := False;
      CheckBox1.Checked := True;
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          edit;
          FieldByName('FactoryNo').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('COCode').AsString);
          FieldByName('FactoryName').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('COName').AsString);

        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;

end;

procedure TfrmDJBKKInPut.v2Column1PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'WJGName';
      flagname := '外加工名称';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('SPName').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDJBKKInPut.v1Column5PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'KuWei';
      flagname := '库位';
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('KuWei').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmDJBKKInPut.v1Column11PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          edit;
          FieldByName('PBFactoryName').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('CoName').AsString);
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmDJBKKInPut.v1Column16PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          edit;
          FieldByName('FromFactoryNo').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyCode').AsString);
          FieldByName('FromFactoryName').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('ZdyName').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmDJBKKInPut.v1Column13PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmProductOrderListSel := TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal = 1 then
      begin
        with Self.CDS_Sub do
        begin
          Edit;
          FieldByName('ORDMainIdRK').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MainId').AsString);
          FieldByName('ORDSubIdRK').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('SubId').AsString);
          FieldByName('OrderNo').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('OrderNo').AsString);
          FieldByName('conno').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('conno').AsString);
          FieldByName('SPColor').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('PRTColor').AsString);
          FieldByName('SPCode').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCode').AsString);
          FieldByName('SPName').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCodeName').AsString);
          FieldByName('SPSpec').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTSpec').AsString);
          FieldByName('SPCF').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTCF').AsString);
          FieldByName('SPMF').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTMF').AsString);
          FieldByName('SPKZ').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('MPRTKZ').AsString);
          FieldByName('QtyUnit').Value := Trim(frmProductOrderListSel.Order_Main.fieldbyname('SXQtyUnit').AsString);

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

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

procedure TfrmDJBKKInPut.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  i: integer;
begin
  if XGQX = '特殊修改' then
  begin
    for i := 0 to tv1.ColumnCount - 1 do
    begin
      if uppercase(tv1.Columns[i].DataBinding.FieldName) <> 'SSEL' then
        tv1.Columns[i].Options.Editing := false;
    end;
    v1Column14.Options.Editing := True;
    v1Column4.Options.Editing := True;
    cxgrdWSTaiTou.Options.Editing := True;
    cxgrdSPType.Options.Editing := True;
    v1Column9.Options.Editing := True;
    v2Column6.Options.Editing := True;
    v1Column11.Options.Editing := True;
    v1Column3.Options.Editing := True;
  end;
end;

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

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

procedure TfrmDJBKKInPut.v1Column3PropertiesEditValueChanged(Sender: TObject);
var
  mvalue, FQtyUnit, FSPName: string;
begin
  mvalue := TcxComboBox(Sender).EditingText;
  if Trim(mvalue) = '' then
    mvalue := '';
  FSPName := Trim(CDS_Sub.FieldByName('SPName').AsString);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select Top 1 * from CP_Info where DataType=''CP'' and SPName=''' + Trim(FSPName) + ''' ');
    open;
  end;
  FQtyUnit := Trim(ADOQueryTemp.FieldByName('QtyUnit').AsString);
  if Trim(FQtyUnit) <> '' then
  begin
    if mvalue <> FQtyUnit then
    begin
      if Application.MessageBox('数量单位与首选单位不一致，确定要采用当前的数量单位吗？', '提示', 32 + 4) <> IDYES then
      begin
        with CDS_Sub do
        begin
          Edit;
          FieldByName('QtyUnit').Value := Null;
        end;
        Exit;
      end;
    end;
  end;
  with CDS_Sub do
  begin
    Edit;
    FieldByName('QtyUnit').Value := mvalue;
  end;
end;

procedure TfrmDJBKKInPut.Tv1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  begin
    try
      frmZDYHelp := TfrmZDYHelp.Create(Application);
      with frmZDYHelp do
      begin
        flag := 'cangku';
        flagname := '仓库';
        if ShowModal = 1 then
        begin
          with Self.CDS_Sub do
          begin
            Edit;
//            FieldByName('WSTaiTou').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
             FieldByName('cangku').Value := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
          end;
        end;
      end;
    finally
      frmZDYHelp.Free;
    end;
  end;
end;

end.

