unit U_OrderInPut;

interface

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

type
  TfrmOrderInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    OrderNo: TEdit;
    Label7: TLabel;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1PRTColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    v1PRTOrderQty: TcxGridDBColumn;
    Label10: TLabel;
    JGFactoryName: TBtnEditC;
    v1OrderUnit: TcxGridDBColumn;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    OrdDate: TDateTimePicker;
    CustomerNoName: TBtnEditC;
    Label2: TLabel;
    Label6: TLabel;
    Label19: TLabel;
    Label25: TLabel;
    DLYDate: TDateTimePicker;
    Label26: TLabel;
    MPRTCode: TBtnEditC;
    Label41: TLabel;
    GDY: TBtnEditC;
    Label42: TLabel;
    MPRTBZNote: TMemo;
    MPRTChuanY: TMemo;
    v1Column1: TcxGridDBColumn;
    Note: TMemo;
    Label23: TLabel;
    JGType: TBtnEditC;
    Label53: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1Column2: TcxGridDBColumn;
    Label60: TLabel;
    MPRTCodeName: TEdit;
    MPRTCF: TEdit;
    MPRTMF: TEdit;
    MPRTSpec: TEdit;
    MPRTKZ: TEdit;
    Label4: TLabel;
    KHConNo: TEdit;
    v1Column3: TcxGridDBColumn;
    RMPreview1: TRMPreview;
    Label5: TLabel;
    LBName: TEdit;
    ToolButton3: TToolButton;
    ADOQueryLabel: TADOQuery;
    RMGridReport1: TRMGridReport;
    Label8: TLabel;
    lidan: TBtnEditC;
    Label9: TLabel;
    PBFactoryName: TBtnEditC;
    Label11: TLabel;
    DJType: TComboBox;
    ZongPS: TEdit;
    ZongQty: TEdit;
    Label17: TLabel;
    YWY: TBtnEditC;
    Label18: TLabel;
    YXJL: TComboBox;
    Label20: TLabel;
    LLXS: TEdit;
    Label21: TLabel;
    JHGZ: TComboBox;
    ToolButton4: TToolButton;
    Label22: TLabel;
    Label24: TLabel;
    Feel: TEdit;
    Label27: TLabel;
    RSYQ: TEdit;
    Label28: TLabel;
    Label29: TLabel;
    SCYQ: TEdit;
    Label30: TLabel;
    XGF: TEdit;
    Label31: TLabel;
    ZBF: TEdit;
    Label32: TLabel;
    KHYQ: TMemo;
    CPNum: TEdit;
    Label34: TLabel;
    YTPNum: TEdit;
    Label15: TLabel;
    Label16: TLabel;
    Label33: TLabel;
    Label35: TLabel;
    SSL: TEdit;
    jhwcDate: TDateTimePicker;
    v1Column4: TcxGridDBColumn;
    CONNO: TEdit;
    v1Column5: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label36: TLabel;
    JLUNIT: TComboBox;
    v1Column10: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    SLDYQ: TBtnEditC;
    Label38: TLabel;
    DSGY: TBtnEditC;
    Label39: TLabel;
    qtyKZ: TBtnEditC;
    Label40: TLabel;
    HBYQ: TBtnEditC;
    Label43: TLabel;
    PHZ: TBtnEditC;
    Label47: TLabel;
    MMCD: TBtnEditC;
    Label48: TLabel;
    DZQK: TBtnEditC;
    Label44: TLabel;
    SYDATE: TDateTimePicker;
    Label45: TLabel;
    DHDATE: TDateTimePicker;
    Label46: TLabel;
    CYDATE: TDateTimePicker;
    Label37: TLabel;
    KJD: TComboBox;
    Tv1Column2: TcxGridDBColumn;
    Label49: TLabel;
    Label50: TLabel;
    MSNAME: TBtnEditC;
    MSCODE: TBtnEditC;
    Label51: TLabel;
    DHPRICE: TEdit;
    Label52: TLabel;
    MSPRICE: TEdit;
    Tv1Column3: TcxGridDBColumn;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure JGFactoryNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure MPRTCodeNameBtnUpClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure MPRTBZNoteDblClick(Sender: TObject);
    procedure MPRTChuanYDblClick(Sender: TObject);
    procedure MPRTCodeBtnUpClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure PBFactoryNameBtnUpClick(Sender: TObject);
    procedure ConNoBtnUpClick(Sender: TObject);
  private
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    function getOrderNo(fconNo: string): string;
    procedure OpenLabel();
    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo: string;
    FXS: Integer;
    canshu1: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmOrderInPut: TfrmOrderInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_ZDYHelpSel, U_ZdyAttachment, U_ZdyAttachGYS,
  U_CPManageSel, getpic, U_LabelList, U_ContractListSel;

{$R *.dfm}
procedure TfrmOrderInPut.OpenLabel();
begin
  with ADOQueryLabel do
  begin
    close;
    sql.Clear;
    sql.Add('select * from P_Label');
    sql.Add('where valid=''Y''');
    sql.Add('and labelCaption=' + quotedstr(trim(LBName.Text)));
    Open;
  end;
  if ADOQueryLabel.IsEmpty then
    exit;
  with RMGridReport1 do
  begin
    LoadFromBlobField(tblobfield(ADOQueryLabel.fieldbyname('labelFile')));
    //Preview :=RMPreview1;
    ShowReport;
  end;
end;

function TfrmOrderInPut.getOrderNo(fconNo: string): string;
var
  str1: string;
  i: integer;
begin
  str1 := trim(fconNo) + '01';
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select MainID from JYOrder_Main where orderNo=' + quotedstr(trim(str1)));
    open;
  end;
  if not ADOTemp.IsEmpty then
  begin
    for i := 1 to 99 do
    begin
      str1 := trim(fconNo) + rightstr(inttostr(100 + i), 2);
      with ADOCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select MainID from JYOrder_Main where orderNo=' + quotedstr(trim(str1)));
        open;
      end;
      if ADOCmd.IsEmpty then
        break;
    end;
  end;
  result := str1;
end;

procedure TfrmOrderInPut.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('指示单录入AA', Tv1, '生产指示单管理');
  Close;

end;

procedure TfrmOrderInPut.InitData();
begin
  OrdDate.DateTime := SGetServerDateTime(ADOTemp);
  DlyDate.DateTime := OrdDate.DateTime;
  jhwcdate.DateTime := OrdDate.DateTime;
  with ADOTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from JYOrder_Sub where 1=1 ');

    if PState = 1 then
    begin
      sql.Add(' and MainId=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' and 1<>1');
    end;

    Open;
  end;
  SCreateCDS20(ADOTemp, Order_Sub);
  SInitCDSData20(ADOTemp, Order_Sub);
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where MainId=''' + Trim(FMainId) + '''');
    Open;
  end;

  SCSHDataNew(ADOTemp, ScrollBox1, 2);

  if PState = 0 then
  begin
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    DlyDate.DateTime := OrdDate.DateTime;
    SYDATE.DateTime := OrdDate.DateTime;
    DHDATE.DateTime := OrdDate.DateTime;
    CYDATE.DateTime := OrdDate.DateTime;
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    OrderNo.Text := '';
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
        FieldByName('SubId').Value := '';
        FieldByName('hxFile').Value := '';
        Post;
        Next;
      end;
    end;
  end;

  OpenLabel();
end;

procedure TfrmOrderInPut.ZDYHelp(FButn: TcxButtonEdit; LType: string);
var
  FType, ZDYName, FText: string;
begin
end;

procedure TfrmOrderInPut.FormShow(Sender: TObject);
begin
  readCxGrid('指示单录入AA', Tv1, '生产指示单管理');
  {if PriceFlag=99 then
  begin
    v1PRTPrice.Visible:=False;
    v1PRTPrice.Hidden:=True;
  end;}

  OrderNo.Text := '';
  if PState = 1 then
  begin
//    Label46.Visible:=true;
//    orddefnote1.Visible:=true;
//    Label49.Visible:=true;
//    EditCnt.Visible:=true;
  end;
  fFlileFlag := UserDataFlag + 'HX';
  InitData();
end;

function TfrmOrderInPut.SaveData(): Boolean;
var
  maxno, Smaxno, maxorderno: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'JM', 'JYOrder_Main', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      if GetLSNo(ADOCmd, maxorderno, 'RT', 'JYOrder_Main', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      OrderNo.Text := TRIM(maxorderno);
//      OrderNo.Text:=getOrderNo(trim(conNo.Text));
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from JYOrder_Main where MainId=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
      end
      else
      begin
        Edit;
      end;
      FieldByName('MainId').Value := Trim(maxno);
      SSetsaveSqlNew(ADOCmd, 'JYOrder_Main', ScrollBox1, 2);
      if Trim(FMainId) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);

      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
      end;
      Post;
    end;

    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where orderno=''' + Trim(OrderNo.Text) + '''');
      Open;
    end;
    if ADOCmd.RecordCount > 1 then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('订单号重复!', '提示', 0);
      Exit;
    end;
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, Smaxno, 'JS', 'JYOrder_Sub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          Smaxno := Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where MainId=''' + Trim(maxno) + '''');
          sql.Add(' and SubId=''' + Trim(Smaxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('SubId').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('MainId').Value := Trim(maxno);
          FieldByName('SubId').Value := Trim(Smaxno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'JYOrder_Sub', 0);
//          FieldByName('ConSubId').Value := Trim(Order_Sub.fieldbyname('ConSubId').AsString);
          Post;
        end;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmOrderInPut.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
//  if Trim(OrderNo.Text)='' then
//  begin
//    Application.MessageBox('订单号不能为空！','提示',0);
//    Exit;
//  end;
  if Trim(conNo.Text) = '' then
  begin
    Application.MessageBox('订单号不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(JGFactoryName.Text) = '' then
  begin
    Application.MessageBox('加工厂不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(GDY.Text) = '' then
  begin
    Application.MessageBox('跟单员不能为空！', '提示', 0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!', '提示', 0);
    Exit;
  end;

  if Order_Sub.Locate('PRTOrderQty', null, []) then
  begin
    Application.MessageBox('数量不能为空!', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmOrderInPut.v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrdColor';
      flagname := '颜色';
      V1Name.Caption := '中文名称';
      V1Note.Caption := '英文名称';
      fnote := True;
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PRTColor').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('PRTColorNo').Value := Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.ToolButton1Click(Sender: TObject);
var
  i: Integer;
begin
//  if Trim(OrderNo.Text)='' then
//  begin
//    Application.MessageBox('订单号不能为空!','提示',0);
//    Exit;
//  end;
  CopyAddRow(Tv1, Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('PRTColor').Value := '';
    FieldByName('PRTOrderQty').Value := null;
    FieldByName('PRTColorNo').Value := null;
    FieldByName('hxFile').Value := '';
    FieldByName('PRTOrderQty').Value := 0;
    FieldByName('PRTPs').Value := 0;
    FieldByName('OrderUnit').Value := 'Kg';
    Post;
  end;
end;

procedure TfrmOrderInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;

  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from WFB_MJJY where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
    Open;
  end;
  if ADOTemp.IsEmpty = False then
  begin
    Application.MessageBox('已检验不能删除数据!', '提示', 0);
    Exit;
  end;
  if Trim(Order_Sub.fieldbyname('SubId').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Sub where SubId=''' + Trim(Order_Sub.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmOrderInPut.JGFactoryNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
//      frmZdyAttachGYS.FactType.ItemIndex:=FactType.Items.IndexOf('加工厂');

      if ShowModal = 1 then
      begin
        JGFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmOrderInPut.CustomerNoNameBtnUpClick(Sender: TObject);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
 
//      IF self.canshu1<>'高权限' then canshu1:='业务员';
      if ShowModal = 1 then
      begin
        CustomerNoName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        CustomerNoName.TxtCode := Trim(CDS_HZ.fieldbyname('CoCode').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmOrderInPut.CustomerNoNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmOrderInPut.MPRTCodeNameBtnUpClick(Sender: TObject);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
      MPRTCode.Text := CDS_Main.fieldbyname('CYNo').asstring;
      MPRTCodeName.Text := CDS_Main.fieldbyname('CYName').asstring;
      MPRTSpec.Text := CDS_Main.fieldbyname('CYSpec').asstring;
      MPRTMF.Text := CDS_Main.fieldbyname('CYmf').asstring;
      MPRTKZ.Text := CDS_Main.fieldbyname('CYkz').asstring;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
var
  mvalues: string;
begin
  mvalues := tv1.Columns[tv1.Controller.FocusedColumn.index].DataBinding.FieldName;
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'OrderUnit';
      flagname := '数量单位';
      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName(mvalues).Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'PriceUnit';
      flagname := '价格单位';
      if Trim(DParameters1) <> '高权限' then
      begin
        TBAdd.Visible := False;
        TBEdit.Visible := False;
        TBDel.Visible := False;
      end;

      if ShowModal = 1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.OrdDefStr2BtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if Trim(flag) = 'OrdDefStr2' then
      begin
        V1Name.Caption := '中文名称';
        V1Note.Caption := '英文名称';
        fnote := True;
      end;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        if Trim(flag) = 'MPRTCode' then
        begin
          with ADOTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select Top 1 * from JYOrder_Main where MPRTCode=''' + Trim(ClientDataSet1.fieldbyname('ZDYName').AsString) + '''');
            sql.Add(' order by FillTime desc');
            Open;
          end;
          MPRTCodeName.Text := ADOTemp.fieldbyname('MPRTCodeName').AsString;
          MPRTMF.Text := ADOTemp.fieldbyname('MPRTMF').AsString;
          MPRTKZ.Text := ADOTemp.fieldbyname('MPRTKZ').AsString;
          MPRTSpec.Text := ADOTemp.fieldbyname('MPRTSpec').AsString;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.YCLFactoryBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPut.MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
var
  fsj: string;
  FWZ: Integer;
begin
  fsj := Trim(TEdit(Sender).Hint);
  FWZ := Pos('/', fsj);
  try
    frmZDYHelpSel := TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag := Copy(fsj, 1, FWZ - 1);
      flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ);
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

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

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

procedure TfrmOrderInPut.MPRTCodeBtnUpClick(Sender: TObject);
begin
  frmCPManageSel := TfrmCPManageSel.Create(self);
  with frmCPManageSel do
  begin
    if showmodal = 1 then
    begin
      MPRTCode.Text := CDS_Main.fieldbyname('CYNo').asstring;
      MPRTCodeName.Text := CDS_Main.fieldbyname('CYName').asstring;
      MPRTSpec.Text := CDS_Main.fieldbyname('CYSpec').asstring;
      MPRTCF.Text := CDS_Main.fieldbyname('CYCF').asstring;
      MPRTMF.Text := CDS_Main.fieldbyname('CYmf').asstring;
      MPRTKZ.Text := CDS_Main.fieldbyname('CYkz').asstring;
    end;
    free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmOrderInPut.ToolButton3Click(Sender: TObject);
var
  maxno: string;
begin
  try
    frmLabelList := TfrmLabelList.Create(Application);
    with frmLabelList do
    begin
      if ShowModal = 1 then
      begin
        self.LBName.text := Trim(ADOQueryLabel.fieldbyname('labelCaption').AsString);
      end;
    end;
  finally
    frmLabelList.Free;
  end;
  OpenLabel();
end;

procedure TfrmOrderInPut.PBFactoryNameBtnUpClick(Sender: TObject);
begin
  //查询是否有坯布厂录入权限
//  with ADOTEMP do
//  begin
//    Close;
//    SQL.Clear;
//    sql.Add(' SELECT * FROM SY_PurView WHERE ModuleID=01 AND ModuleSubID=04 ');
//    SQL.ADD('and userid=''' + trim(DCODE) + '''');
//
//    Open;
//  end;
//  if ADOTEMP.isempty = true then
//  begin
//    Application.MessageBox('无该权限！', '提示', 0);
//    exit;
//  end;
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
//      frmZdyAttachGYS.FactType.ItemIndex := FactType.Items.IndexOf('坯布厂');
      if ShowModal = 1 then
      begin
        PBFactoryName.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmOrderInPut.ConNoBtnUpClick(Sender: TObject);
var
  FConMainId, FMPRTCode: string;
begin
  try
    frmContractListSel := TfrmContractListSel.Create(Application);
    with frmContractListSel do
    begin
      fconNo := trim(self.ConNo.Text);
      if ShowModal = 1 then
      begin
        Order_Main.locate('SSel', true, []);
        FConMainId := Trim(frmContractListSel.Order_Main.fieldbyname('MainId').AsString);
        YWY.Text := Trim(frmContractListSel.Order_Main.fieldbyname('Salesman').AsString);
        FMPRTCode := Trim(frmContractListSel.Order_Main.fieldbyname('SCSCode').AsString);
        self.ConNo.Text := Trim(frmContractListSel.Order_Main.fieldbyname('ConNo').AsString);
        self.KHConNo.Text := Trim(frmContractListSel.Order_Main.fieldbyname('BuyConNo').AsString);
        self.CustomerNoName.Text := Trim(frmContractListSel.Order_Main.fieldbyname('BuyName').AsString);
        self.CustomerNoName.TxtCode := Trim(frmContractListSel.Order_Main.fieldbyname('BuyNo').AsString);
        self.YWY.Text := Trim(frmContractListSel.Order_Main.fieldbyname('SellName').AsString);
        self.MPRTCode.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSCode').AsString);
        self.MPRTCodeName.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSName').AsString);
        self.MPRTSpec.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSSpec').AsString);
        self.MPRTCF.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSCF').AsString);
        self.MPRTMF.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSMF').AsString);
        self.MPRTKZ.Text := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKZ').AsString);
        while Order_Main.locate('SSel', true, []) do
        begin
          if FConMainId <> trim(frmContractListSel.Order_Main.Fieldbyname('MainId').AsString) then
          begin
            Application.MessageBox('不能选择多个合同！', '提示', 0);
            break;
          end;
          if self.MPRTCode.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSCode').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.MPRTMF.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSMF').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.MPRTKZ.Text <> trim(frmContractListSel.Order_Main.Fieldbyname('SCSKZ').AsString) then
          begin
            Application.MessageBox('不能选择多个产品！', '提示', 0);
            break;
          end;
          if self.Order_Sub.locate('ConSubId', trim(Order_Main.Fieldbyname('SubId').AsString), []) then
          begin
            Order_Main.Edit;
            Order_Main.fieldbyname('SSel').value := false;
            continue;
          end;
          with self.Order_Sub do
          begin
            append;

//            Fieldbyname('PrtKuanNO').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSKX').AsString);
            Fieldbyname('PrtColorNo').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSColorNo').AsString);
            Fieldbyname('PrtColor').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSColor').AsString);
            Fieldbyname('PRTHX').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSHX').AsString);
            Fieldbyname('PRTOrderQty').value := frmContractListSel.Order_Main.Fieldbyname('SCSQty').AsFloat;
            Fieldbyname('OrderUnit').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSUnit').AsString);
            Fieldbyname('SubNote').value := trim(frmContractListSel.Order_Main.Fieldbyname('SCSNote').AsString);
            Fieldbyname('ConSubId').value := trim(frmContractListSel.Order_Main.Fieldbyname('SubId').AsString);
          end;
          Order_Main.Edit;
          Order_Main.fieldbyname('SSel').value := false;
        end;

      end;
    end;
  finally
    frmContractListSel.Free;
  end;
end;

end.

