unit U_JYSQINPUT;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls,
  Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGridLevel, cxClasses, cxControls, cxGridCustomView,
  cxGrid, StdCtrls, ComCtrls, ExtCtrls, ToolWin, cxButtonEdit, cxDropDownEdit,
  DBClient, ADODB, cxGridCustomPopupMenu, cxGridPopupMenu, BtnEdit, cxTextEdit,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, cxContainer, dxCore,
  cxDateUtils, cxMaskEdit, cxCalendar;

type
  TfrmJYSQinput = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    CRType: TComboBox;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1P_CodeName: TcxGridDBColumn;
    v1P_SPEC: TcxGridDBColumn;
    v1P_MF: TcxGridDBColumn;
    v1P_KZ: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Note: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    DataSource1: TDataSource;
    CDS_Main: TClientDataSet;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    ToCustName: TBtnEditA;
    v1P_Color: TcxGridDBColumn;
    v1P_Code: TcxGridDBColumn;
    Label8: TLabel;
    CRNo: TEdit;
    Label9: TLabel;
    custName: TBtnEditA;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    edtScan: TEdit;
    Tv1Column5: TcxGridDBColumn;
    Label4: TLabel;
    ZNOTE: TEdit;
    Label5: TLabel;
    YPQX: TEdit;
    Tv1Column1: TcxGridDBColumn;
    CRTIME: TcxDateEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1P_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToCustNameBtnClick(Sender: TObject);
    procedure orderNOBtnClick(Sender: TObject);
    procedure v1QtyPropertiesEditValueChanged(Sender: TObject);
    procedure edtScanKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure custNameBtnClick(Sender: TObject);
    procedure v1P_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Tv1KeyPress(Sender: TObject; var Key: Char);
  private
    procedure InitGrid();
    function savedate(): Boolean;
    procedure SetComboBox();
    function YSData(fYFName: string): Boolean;
    { Private declarations }
  public
    CopyInt: integer;
    fkeyNO: string;
    FType: integer;
    fCKName: string;
    { Public declarations }
  end;

var
  frmJYSQinput: TfrmJYSQinput;

implementation

uses
  U_DataLink, U_Fun10, U_ZDYHelp, U_ZdyAttachment, U_CPManageSel, U_CPManageSel2;
{$R *.dfm}

function TfrmJYSQinput.YSData(fYFName: string): Boolean;
var
  CRID, YFID, Price, PriceUnit, OrderUnit, FComTaiTou, cust: string;
begin
  Result := False;
  with ADOQueryTmp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from YF_Money_KC where FactoryName=''' + Trim(custName.Text) + ''' ');
    Open;
  end;

  if not ADOQueryTmp.IsEmpty then
  begin
    CRID := ADOQueryTmp.fieldbyname('CRID').AsString;
  end
  else
  begin
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update YF_Money_CRID set CRID=CRID+1');
      sql.Add('select * from YF_Money_CRID ');
      Open;
    end;
    CRID := ADOQueryCmd.fieldbyname('CRID').AsString;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from YF_Money_KC where 1<>1');
      Open;
    end;
    with ADOQueryCmd do
    begin
      Append;
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('FactoryName').Value := Trim(custName.Text);
      FieldByName('ZdyStr1').Value := '应收收';
      Post;
    end;
  end;

  with ADOQueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from YF_Money_CR ');
    sql.Add(' where MainID=''' + Trim(CDS_Main.fieldbyname('CRNO').AsString) + '''');
    sql.Add(' and subID=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + '''');
    sql.Add(' and YFName=''' + trim(fYFName) + ''' ');
    Open;
  end;

  if ADOQueryTmp.IsEmpty then
  begin
    if GetLSNo(ADOQueryTmp, YFID, 'CS', 'YF_Money_CR', 3, 1) = False then
    begin
      Application.MessageBox('取应收最大号失败!', '提示', 0);
      Exit;
    end;

    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from YF_Money_CR where 1<>1');
      Open;
    end;

    with ADOQueryCmd do
    begin
      Append;
      FieldByName('YFID').Value := Trim(YFID);
      FieldByName('YFTypeId').Value := Trim(CDS_Main.fieldbyname('CRNO').AsString);
      FieldByName('CRID').Value := StrToInt(CRID);
      FieldByName('Filler').Value := Trim(DName);
      FieldByName('CRType').Value := '应收款登记';
      FieldByName('CRFlag').Value := '应收收';
      FieldByName('QtyFlag').Value := 1;
      FieldByName('FactoryName').Value := Trim(custName.Text);
      FieldByName('CRTime').Value := CRTime.Text;
     // Trim(FormatDateTime('yyyy-MM-dd', CRTime.DateTime));
      FieldByName('YFType').Value := '自动生成';
      FieldByName('ps').Value := CDS_Main.fieldbyname('RollNum').AsFloat;
      FieldByName('Qty').Value := CDS_Main.fieldbyname('Qty').AsFloat;
      FieldByName('Price').Value := CDS_Main.fieldbyname('Price').AsFloat;
      FieldByName('Money').Value := CDS_Main.fieldbyname('Money').AsFloat;
      FieldByName('BBMoney').Value := CDS_Main.fieldbyname('Money').AsFloat;
      FieldByName('HuiLv').Value := 1;
      FieldByName('BZType').Value := 'RMB';
      FieldByName('QtyUnit').Value := Trim(CDS_Main.fieldbyname('QtyUnit').AsString);
      FieldByName('ComTaiTou').Value := Trim(custName.Text);
      FieldByName('YFName').Value := fYFName;
      FieldByName('MainId').Value := Trim(CDS_Main.fieldbyname('CRNO').AsString);
      FieldByName('subID').Value := Trim(CDS_Main.fieldbyname('CRID').AsString);
      FieldByName('orderNo').Value := Trim(CDS_Main.fieldbyname('P_Code').AsString);
      FieldByName('P_CodeName').Value := Trim(CDS_Main.fieldbyname('P_CodeName').AsString);
      FieldByName('P_Spec').Value := Trim(CDS_Main.fieldbyname('P_Spec').AsString);
      FieldByName('P_Color').Value := Trim(CDS_Main.fieldbyname('P_Color').AsString);
      FieldByName('status').Value := '0';
      Post;
    end;
  end
  else
  begin
    YFID := Trim(ADOQueryTmp.fieldbyname('YFID').AsString);
  end;

  Result := True;
end;

procedure TfrmJYSQinput.SetComboBox();
begin
//  ckName.Items.Clear;
//  with adoQueryTmp do
//  begin
//    close;
//    sql.Clear;
//    sql.Add('select * from KH_ZDY where Type=''YPCK'' ');
//    if trim(fCKName) <> '' then
//      sql.Add('and zdyName=' + quotedstr(trim(fCKName)));
//    open;
//    while not eof do
//    begin
//      ckName.Items.Add(trim(fieldbyname('zdyName').AsString));
//      next;
//    end;
//  end;
//  if ckName.Items.Count > 0 then
//    ckName.ItemIndex := 0;
//
//  CRType.Items.Clear;
//  with adoQueryTmp do
//  begin
//    close;
//    sql.Clear;
//    sql.Add('select * from KH_ZDY where Type=''YPCKTYPE''');
//    if trim(fCKName) <> '' then
//      sql.Add('and note=' + quotedstr(trim(fCKName)));
//    open;
//    while not eof do
//    begin
//      CRType.Items.Add(trim(fieldbyname('zdyName').AsString));
//      next;
//    end;
//  end;
//  if CRType.Items.Count > 0 then
//    CRType.ItemIndex := 0;
end;

function TfrmJYSQinput.savedate(): Boolean;
var
  fkcID: integer;
  Filler: string;
  FillTime: TdateTime;
  maxno: string;
begin
  result := false;

  if FType = 0 then
  begin
    Filler := DName;
    FillTime := SGetServerDateTime(adoqueryTmp);
  end
  else
  begin
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select * from YP_InOut2');
      sql.Add('where CRNO=' + quotedstr(trim(fkeyNO)));
      open;
      Filler := adoqueryTmp.fieldbyname('Filler').AsString;
      FillTime := adoqueryTmp.fieldbyname('FillTime').AsDateTime;
    end;
  end;

  try
    ADOQueryCmd.Connection.BeginTrans;

    CDS_Main.DisableControls;
    CDS_Main.First;
    with CDS_Main do
    begin
      while not eof do
      begin
        if Trim(CDS_Main.fieldbyname('CRID').AsString) = '' then
        begin
          if GetLSNo(ADOQueryCmd, maxno, 'YC', 'YP_InOut2', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(CDS_Main.fieldbyname('CRID').AsString);
        end;
        with ADOQueryCmd do
        begin
          close;
          sql.Clear;
          sql.Add('select * from YP_INout2');
          sql.Add('where CRID= ' + quotedstr(Trim(maxno)));
          open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(CDS_Main.fieldbyname('CRID').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := trim(Filler);
            FieldByName('FillTime').Value := dateTimetostr(FillTime);
          end
          else
          begin
            Edit;
            FieldByName('editer').Value := trim(dName);
            FieldByName('editTime').Value := SGetServerDateTime(adoqueryTmp);
          end;
          FieldByName('CKNAME').Value := '申请单';
          RTSetSaveDataCDS(ADOQueryCmd, Tv1, CDS_Main, 'YP_InOut2', 0);
          SSetsaveSqlNew(ADOQueryCmd, 'YP_InOut2', Panel1, 0);
          FieldByName('CRNO').Value := trim(fkeyNO);
          FieldByName('CRID').Value := Trim(maxno);
          FieldByName('CRTIME').Value := CRTIME.Text;
//          FieldByName('PRICE').Value := Trim(CDS_Main.fieldbyname('CKPRICE').VALUE);
          FieldByName('CRQtyFlag').Value := -1;
          FieldByName('CRFlag').Value := '出库';
          FieldByName('frommainID').Value := trim(CDS_Main.fieldbyname('frommainID').AsString);
          FieldByName('fromsubID').Value := trim(CDS_Main.fieldbyname('fromsubID').AsString);
          FieldByName('factoryName').Value := trim(CDS_Main.fieldbyname('factoryName').AsString);
          FieldByName('YWY').Value := trim(CDS_Main.fieldbyname('YWY').AsString);
          Post;
        end;

        CDS_Main.edit;
        CDS_Main.FieldByName('CRNO').Value := trim(fkeyNO);
        CDS_Main.FieldByName('CRID').Value := maxno;

        next;
      end;
    end;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('exec P_YP_Judge_KC ');
      Open;
    end;
    if Trim(ADOQueryCmd.FieldByName('msg').AsString) = '异常' then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      CDS_Main.EnableControls;
      Application.MessageBox('产生负数库存操作异常！', '提示', 0);
      exit;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    result := true;
  except
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
  end;
end;

procedure TfrmJYSQinput.InitGrid();
begin
  try

    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('EXEC P_YP_UP_SSKC2  @CRNO=' + quotedstr(trim(fkeyNO)));
//      ShowMessage(SQL.Text);
      ExecSQL;
    end;

    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('select A.*  from YP_InOut2 A');
      sql.Add('where A.CRNO=' + quotedstr(trim(fkeyNO)));
      open;
    end;
    SCreateCDS20(adoqueryTmp, CDS_Main);
    SInitCDSData20(adoqueryTmp, CDS_Main);
    if not CDS_Main.IsEmpty then
    begin
      CRTime.Date := CDS_Main.fieldbyname('CRTime').AsDateTime;
      CRType.ItemIndex := CRType.Items.IndexOf(trim(CDS_Main.fieldbyname('CRType').AsString));

      CRNO.Text := trim(CDS_Main.fieldbyname('CRNO').AsString);
      ypqx.Text := trim(CDS_Main.fieldbyname('ypqx').AsString);
      znote.Text := trim(CDS_Main.fieldbyname('znote').AsString);
      custName.TxtCode := trim(CDS_Main.fieldbyname('custNo').AsString);
      custName.Text := trim(CDS_Main.fieldbyname('custName').AsString);

      TocustName.TxtCode := trim(CDS_Main.fieldbyname('TocustNo').AsString);
      TocustName.Text := trim(CDS_Main.fieldbyname('TocustName').AsString);

    end;
  finally
  end;

end;

procedure TfrmJYSQinput.FormDestroy(Sender: TObject);
begin
  frmJYSQinput := nil;
end;

procedure TfrmJYSQinput.FormCreate(Sender: TObject);
begin
  CRTime.Date := Now;
  cxGrid1.Align := alclient;
end;

procedure TfrmJYSQinput.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  writeCxGrid(self.Caption, Tv1, '成品仓库2');
  Action := cahide;
end;

procedure TfrmJYSQinput.FormShow(Sender: TObject);
var
  fsj: string;
begin
  readCxGrid(self.Caption, Tv1, '成品仓库2');

  ToolBar1.SetFocus;
//  SetComboBox();
  InitGrid();
  if fType = 0 then
  begin
    if GetLSNo(ADOQueryCmd, fkeyNo, 'YC', 'YP_InOut2', 3, 1) = False then
    begin
      //  ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败!', '提示', 0);
      Exit;
    end;
    CRNO.Text := fkeyNo;
  end;
  if CopyInt = 99 then
  begin
    with CDS_Main do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('CRID').Value := '';
        Post;
        Next;
      end;
    end;
  end;
end;

procedure TfrmJYSQinput.TBSaveClick(Sender: TObject);
begin
  if cds_main.IsEmpty then
    exit;
  ToolBar1.SetFocus;
  if trim(CRType.Text) = '' then
  begin
    application.MessageBox('出库类型不能为空！', '提示信息', 0);
    exit;
  end;

  if (trim(CRType.Text) = '船样销售') and (trim(custName.Text) = '') then
  begin
    application.MessageBox('客户信息不能为空！', '提示信息', 0);
    exit;
  end;
  if cds_main.Locate('Qty', 0, []) then
  begin
    application.MessageBox('数量不能为0！', '提示信息', 0);
    exit;
  end;
  if cds_main.Locate('Qty', NULL, []) then
  begin
    application.MessageBox('数量不能为空！', '提示信息', 0);
    exit;
  end;
  if cds_main.Locate('QtyUnit', '', []) then
  begin
    application.MessageBox('数量单位不能为空！', '提示信息', 0);
    exit;
  end;
  if cds_main.Locate('QtyUnit', NULL, []) then
  begin
    application.MessageBox('数量单位不能为空！', '提示信息', 0);
    exit;
  end;

  if savedate() then
  begin
    application.MessageBox('数据保存成功！', '提示信息');
    ModalResult := 1;
  end
  else
  begin
    application.MessageBox('数据保存失败！', '提示信息', MB_ICONERROR);
  end;
end;

procedure TfrmJYSQinput.v1P_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Cloth';
      flagname := '坯布名称';
      if ShowModal = 1 then
      begin
        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('P_CodeName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.CDS_Main.FieldByName('P_Code').Value := Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJYSQinput.ToolButton1Click(Sender: TObject);
begin
  CopyAddRow(Tv1, CDS_Main);
  with CDS_Main do
  begin
    EDIT;
    fieldbyname('RollNum').Value := 0;
    fieldbyname('Qty').Value := 0;
    fieldbyname('ckprice').Value := 0;
    fieldbyname('money').Value := 0;
    fieldbyname('QtyUnit').Value := 'M';
    Post;
  end;

end;

procedure TfrmJYSQinput.ToolButton2Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then
    exit;

  if CDS_Main.IsEmpty then
    Exit;

  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;

    sql.Add('update  YP_InOut2 SET valid=''N'' ');
    sql.Add(',editer=' + quotedstr(trim(DName)));
    sql.Add(',edittime=getdate()');
    SQL.Add('where  CRid=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + ''' ');
//
//      sql.Add('delete from YF_money_CR  ');
//      SQL.Add('where mainID=''' + Trim(CDS_Main.fieldbyname('CRNO').AsString) + ''' ');
//      SQL.Add('and subID=''' + Trim(CDS_Main.fieldbyname('CRID').AsString) + ''' ');

    execsql;
  end;
  CDS_Main.Delete;
end;

procedure TfrmJYSQinput.TBCloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmJYSQinput.ToCustNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'CustomerNoName';
      flagname := '客户名称';
      if ShowModal = 1 then
      begin
        ToCustName.Text := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYName').AsString);
        ToCustName.TxtCode := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmJYSQinput.orderNOBtnClick(Sender: TObject);
begin
 {  frmProductOrderNewList:=TfrmProductOrderNewList.Create(Application);
   with  frmProductOrderNewList do
   begin
     DParameters1:='高权限';
     if showmodal=1 then
     begin
       self.fmainID:=trim(Order_Main.fieldbyname('MainID').AsString);
       self.fsubID:=trim(Order_Main.fieldbyname('subID').AsString);
       self.orderNo.Text:=trim(Order_Main.fieldbyname('orderNo').AsString);
       self.PRTCodeName.Text:=trim(Order_Main.fieldbyname('PRTCodeName').AsString);
       self.PRTColor.Text:=trim(Order_Main.fieldbyname('PRTColor').AsString);
     end;
     free;
   end;  }
end;

procedure TfrmJYSQinput.v1QtyPropertiesEditValueChanged(Sender: TObject);
var
  fieldname: string;
begin
  fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  with CDS_Main do
  begin
    Edit;
    FieldByName(Trim(fieldname)).Value := TcxTextEdit(Sender).EditingText;
    FieldByName('Money').Value := strtofloat(format('%0.2f', [FieldByName('Qty').AsFloat * FieldByName('ckprice').AsFloat]));
    Post;
  end;
  Tv1.Controller.EditingController.ShowEdit();

end;

procedure TfrmJYSQinput.edtScanKeyPress(Sender: TObject; var Key: Char);
var
  PWhere: string;
begin
  if Key = #13 then
  begin
    with adoqueryTmp do
    begin
      close;
      sql.Clear;
      sql.Add('exec P_YP_CK_SCAN  @SCAN  =' + Quotedstr(Trim(edtScan.Text)));
//      ShowMessage(sql.Text);
      open;
    end;
    if not adoqueryTmp.IsEmpty then
    begin

      self.cds_main.Append;
      self.cds_main.FieldByName('FROMOrderno').Value := trim(adoqueryTmp.fieldbyname('FROMOrderno').AsString);
      self.cds_main.FieldByName('frommainid').Value := trim(adoqueryTmp.fieldbyname('frommainid').AsString);
      self.cds_main.FieldByName('fromsubid').Value := trim(adoqueryTmp.fieldbyname('fromsubid').AsString);
      self.cds_main.FieldByName('factoryName').Value := trim(adoqueryTmp.fieldbyname('factoryName').AsString);
      self.cds_main.FieldByName('YWY').Value := trim(adoqueryTmp.fieldbyname('YWY').AsString);
      self.cds_main.FieldByName('P_Code').Value := trim(adoqueryTmp.fieldbyname('P_Code').AsString);
      self.cds_main.FieldByName('P_CodeName').Value := trim(adoqueryTmp.fieldbyname('P_CodeName').AsString);
      self.cds_main.FieldByName('P_cf').Value := trim(adoqueryTmp.fieldbyname('P_cf').AsString);
      self.cds_main.FieldByName('P_spec').Value := trim(adoqueryTmp.fieldbyname('P_spec').AsString);
      self.cds_main.FieldByName('shazhi').Value := trim(adoqueryTmp.fieldbyname('shazhi').AsString);
      self.cds_main.FieldByName('P_Color').Value := trim(adoqueryTmp.fieldbyname('P_Color').AsString);
      self.cds_main.FieldByName('P_HX').Value := trim(adoqueryTmp.fieldbyname('P_HX').AsString);
      self.cds_main.FieldByName('P_SMF').Value := trim(adoqueryTmp.fieldbyname('P_SMF').AsString);
      self.cds_main.FieldByName('P_SKZ').Value := trim(adoqueryTmp.fieldbyname('P_SKZ').AsString);
      self.cds_main.FieldByName('RollNum').Value := adoqueryTmp.fieldbyname('kcRollNum').AsFloat;
      self.cds_main.FieldByName('ckprice').Value := adoqueryTmp.fieldbyname('price').AsFloat;
      self.cds_main.FieldByName('price').Value := 0;
      self.cds_main.FieldByName('money').Value := 0;
      self.cds_main.FieldByName('Qty').Value := 1;
      self.cds_main.FieldByName('SSKC').Value := adoqueryTmp.fieldbyname('kcQty').AsFloat;
      self.cds_main.FieldByName('QtyUnit').Value := trim(adoqueryTmp.fieldbyname('QtyUnit').AsString);
      self.cds_main.FieldByName('kuwei').Value := trim(adoqueryTmp.fieldbyname('kuwei').AsString);
      self.cds_main.FieldByName('YPType').Value := trim(adoqueryTmp.fieldbyname('YPType').AsString);
      self.cds_main.FieldByName('JuanHao').Value := trim(adoqueryTmp.fieldbyname('JuanHao').AsString);
      self.cds_main.FieldByName('ISCGPZ').Value := trim(adoqueryTmp.fieldbyname('ISCGPZ').AsString);
      self.cds_main.FieldByName('YPCFD').Value := trim(adoqueryTmp.fieldbyname('YPCFD').AsString);
      self.cds_main.Post;

    end;
    edtScan.Text := '';
  end;
end;

procedure TfrmJYSQinput.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmJYSQinput.custNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin
        CustName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        CustName.TxtCode := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmJYSQinput.v1P_CodePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
//    Fstatus := 3;
    if showmodal = 1 then
    begin

      Self.CDS_Main.Edit;
      Self.CDS_Main.FieldByName('P_Code').Value := Trim(CDS_Main.fieldbyname('CYNo').AsString);
      Self.CDS_Main.FieldByName('P_CodeName').Value := Trim(CDS_Main.fieldbyname('CYName').AsString);
      Self.CDS_Main.FieldByName('P_CF').Value := Trim(CDS_Main.fieldbyname('CYCF').AsString);

      Self.CDS_Main.FieldByName('P_SMF').Value := Trim(CDS_Main.fieldbyname('CYMF').AsString);
      Self.CDS_Main.FieldByName('P_SKZ').Value := Trim(CDS_Main.fieldbyname('CYKZ').AsString);
      Self.CDS_Main.FieldByName('P_Color').Value := '任意色';
//      Trim(CDS_Main.fieldbyname('CYColor').AsString);
//      self.cds_main.FieldByName('P_HX').Value := trim(cds_main.fieldbyname('defnote4').AsString);
      self.cds_main.FieldByName('RollNum').Value := 0;
    end;
    free;
  end;

  self.tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmJYSQinput.Tv1KeyPress(Sender: TObject; var Key: Char);
begin
  if CDS_Main.IsEmpty = True then
    Exit;
  if Key = #13 then
  begin
    frmCPManageSel2 := TfrmCPManageSel2.Create(self);
    with frmCPManageSel2 do
    begin
//    Fstatus := 3;
      CYNO.Text := Self.CDS_Main.FieldByName('P_Code').AsString;

      if showmodal = 1 then
      begin

        Self.CDS_Main.Edit;
        Self.CDS_Main.FieldByName('P_Code').Value := Trim(CDS_Main.fieldbyname('CYNo').AsString);
        Self.CDS_Main.FieldByName('P_CodeName').Value := Trim(CDS_Main.fieldbyname('CYName').AsString);
        Self.CDS_Main.FieldByName('P_CF').Value := Trim(CDS_Main.fieldbyname('CYCF').AsString);
        Self.CDS_Main.FieldByName('P_SMF').Value := Trim(CDS_Main.fieldbyname('CYMF').AsString);
        Self.CDS_Main.FieldByName('P_SKZ').Value := Trim(CDS_Main.fieldbyname('CYKZ').AsString);
        Self.CDS_Main.FieldByName('P_Color').Value := Trim(CDS_Main.fieldbyname('CYColor').AsString);
//      self.cds_main.FieldByName('P_HX').Value := trim(cds_main.fieldbyname('defnote4').AsString);
        self.cds_main.FieldByName('RollNum').Value := 0;
      end;
      free;
    end;

    self.tv1.Controller.EditingController.ShowEdit();
  end;
end;

end.

