unit U_MLOrderInPut_JGNX;

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,
  cxGroupBox, cxCheckBox, ImgList, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, Menus, ShellAPI, cxSplitter;

type
  TfrmMLOrderInPut_JGNX = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    v1ConColor: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1Qty: TcxGridDBColumn;
    Label10: TLabel;
    v1XHNo: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1ConHX: TcxGridDBColumn;
    Label3: TLabel;
    Label14: TLabel;
    OrdDate: TDateTimePicker;
    KHName: TBtnEditC;
    v1ConNote: TcxGridDBColumn;
    CDS_CON: TClientDataSet;
    DSCON: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1ConCode: TcxGridDBColumn;
    v1ConCodeName: TcxGridDBColumn;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuery2: TADOQuery;
    v1ConGY: TcxGridDBColumn;
    Label2: TLabel;
    SYRName: TBtnEditC;
    Label4: TLabel;
    Panel1: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    Panel21: TPanel;
    ScrollBox2: TScrollBox;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label11: TLabel;
    QtyBiaoZhun: TBtnEditC;
    ZLBiaoZhun: TBtnEditC;
    JHType: TBtnEditC;
    BZYaoQiu: TBtnEditC;
    Label12: TLabel;
    JSType: TBtnEditC;
    Label13: TLabel;
    HZQiXian: TBtnEditC;
    Label15: TLabel;
    WYZeRen: TBtnEditC;
    BCShuoMing: TBtnEditC;
    CheckBox1: TCheckBox;
    KPCodeName: TBtnEditC;
    CheckBox2: TCheckBox;
    Label16: TLabel;
    Label17: TLabel;
    Label18: TLabel;
    SYRAdd: TEdit;
    Label19: TLabel;
    SYRZJL: TEdit;
    Label20: TLabel;
    SYRTel: TEdit;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    SYRYWTel: TEdit;
    Label24: TLabel;
    Label25: TLabel;
    Label26: TLabel;
    SYRBankNo: TEdit;
    Label27: TLabel;
    KHAdd: TEdit;
    Label28: TLabel;
    KHZJL: TEdit;
    Label29: TLabel;
    KHTel: TEdit;
    Label30: TLabel;
    KHFDR: TEdit;
    Label31: TLabel;
    KHYWFZR: TEdit;
    Label32: TLabel;
    KHYWTel: TEdit;
    Label33: TLabel;
    KHPhone: TEdit;
    Label34: TLabel;
    KHBankName: TEdit;
    Label35: TLabel;
    KHBankNo: TEdit;
    v1ConPrice: TcxGridDBColumn;
    v1ConMoney: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    Label37: TLabel;
    v1ConType: TcxGridDBColumn;
    YWConNO: TEdit;
    v1ConColNo: TcxGridDBColumn;
    v1ConKHColNo: TcxGridDBColumn;
    IFHS: TCheckBox;
    IFBHS: TCheckBox;
    v1IFFZ: TcxGridDBColumn;
    Label52: TLabel;
    KHConNo: TEdit;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N3: TMenuItem;
    MenuItem2: TMenuItem;
    N4: TMenuItem;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    ImageList1: TImageList;
    PopupMenu1: TPopupMenu;
    MenuItem3: TMenuItem;
    MenuItem4: TMenuItem;
    SYRFDR: TBtnEditA;
    SYRYWY: TBtnEditA;
    SYRYWFZR: TBtnEditA;
    cxSplitter1: TcxSplitter;
    ListView1: TListView;
    Panel12: TPanel;
    Label48: TLabel;
    Button4: TButton;
    Panel13: TPanel;
    Image1: TImage;
    WJName: TEdit;
    Button7: TButton;
    WJPach: TEdit;
    Button8: TButton;
    Panel2: TPanel;
    Panel3: TPanel;
    Label36: TLabel;
    Label39: TLabel;
    Label40: TLabel;
    Label41: TLabel;
    Label43: TLabel;
    Label45: TLabel;
    Label46: TLabel;
    Label47: TLabel;
    Label49: TLabel;
    Label50: TLabel;
    Label53: TLabel;
    Label38: TLabel;
    ConCodeName: TEdit;
    ConHX: TEdit;
    ConColor: TEdit;
    Qty: TEdit;
    ConPrice: TEdit;
    ConMoney: TEdit;
    ConNote: TMemo;
    Button1: TButton;
    Button2: TButton;
    ConColNo: TEdit;
    ConKHColNo: TEdit;
    ConCode: TBtnEditA;
    ConGY: TBtnEditA;
    QtyUnit: TBtnEditA;
    CSID: TEdit;
    KHConCodeName: TEdit;
    KHConCode: TBtnEditA;
    Panel5: TPanel;
    PopupMenu3: TPopupMenu;
    MenuItem5: TMenuItem;
    PTID: TEdit;
    Panel4: TPanel;
    Image2: TImage;
    Button3: TButton;
    Button5: TButton;
    Button6: TButton;
    Button9: TButton;
    Button10: TButton;
    Button11: TButton;
    Button12: TButton;
    N2: TMenuItem;
    MLID: TEdit;
    ConNo: TEdit;
    Button13: TButton;
    SYRBankName: TEdit;
    SYRPhone: TEdit;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton1Click(Sender: TObject);
    procedure KHNameBtnUpClick(Sender: TObject);
    procedure KHNameBtnDnClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ConCodeKeyPress(Sender: TObject; var Key: Char);
    procedure ListView1DblClick(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Image1Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure MenuItem3Click(Sender: TObject);
    procedure MenuItem4Click(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure IFHSClick(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure SYRNameBtnUpClick(Sender: TObject);
    procedure QtyUnitBtnClick(Sender: TObject);
    procedure ConGYBtnClick(Sender: TObject);
    procedure ConCodeBtnClick(Sender: TObject);
    procedure QtyChange(Sender: TObject);
    procedure SYRFDRBtnClick(Sender: TObject);
    procedure SYRYWYBtnClick(Sender: TObject);
    procedure SYRYWFZRBtnClick(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button11Click(Sender: TObject);
    procedure Button12Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure KHConCodeBtnClick(Sender: TObject);
    procedure ConCodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure KHConCodeKeyPress(Sender: TObject; var Key: Char);
    procedure KHConCodeNameKeyPress(Sender: TObject; var Key: Char);
    procedure ConColorKeyPress(Sender: TObject; var Key: Char);
    procedure ConColNoKeyPress(Sender: TObject; var Key: Char);
    procedure ConKHColNoKeyPress(Sender: TObject; var Key: Char);
    procedure QtyKeyPress(Sender: TObject; var Key: Char);
    procedure QtyUnitKeyPress(Sender: TObject; var Key: Char);
    procedure ConPriceKeyPress(Sender: TObject; var Key: Char);
    procedure ConGYKeyPress(Sender: TObject; var Key: Char);
    procedure ConNoteKeyPress(Sender: TObject; var Key: Char);
    procedure ConCodeChange(Sender: TObject);
    procedure KHConCodeChange(Sender: TObject);
    procedure QtyUnitChange(Sender: TObject);
    procedure ConGYChange(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Button13Click(Sender: TObject);
    procedure IFBHSClick(Sender: TObject);
  private
    procedure InitData();
    function SaveData(): Boolean;
    function getOrderNo(fconNo: string): string;
    procedure CFSaveData();
    procedure Initimage();
    procedure InitColor();
    { Private declarations }
  public
    PState, CopyInt, PriceFlag: Integer;
    FMainId, FFMainId, FOrderNo: string;
    FXS: Integer;
    canshu1, canshu2: string;
    fFlileFlag: string;
    { Public declarations }
  end;

var
  frmMLOrderInPut_JGNX: TfrmMLOrderInPut_JGNX;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_Fun, U_RTFun, U_ZDYHelpSel, U_ZdyAttachment,
  U_ZdyAttachGYS, U_ZHCPList_CX, getpic, U_ZdyAttachCP_HX_sel, U_ContractList_CX,
  U_GSList_CX, U_KHList_CX, U_MLMangeRS_Sel1, U_BPZdy_LRPB, U_BPZdy_LRM,
  U_MCGRKList_XKC_CX, U_BPZdy_LRPB_M1, U_MLManage_LRRS, U_ZDYHelp_YW,
  U_MLMangeRS_Sel2;

{$R *.dfm}
procedure TfrmMLOrderInPut_JGNX.CFSaveData();
var
  fCFID: string;
begin
  with ADOQuery2 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from JYOrder_Sub_CF where subID=''' + Trim(Order_Sub.fieldbyname('subID').asstring) + '''');
    open;
  end;
  if ADOQuery2.IsEmpty then
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      SQL.Add('select A.CengJI,A.MLName,A.MLSeHao,A.MLID ');
      sql.Add(',HXNo=(select Top 1 B.HXNo from CP_YDang_JG B where B.CengJi=A.CengJi and B.CYID=A.CYID and B.IFZY=1)');
      sql.Add(',GYDM=(select Top 1 B.GYDM from CP_YDang_JG B where B.CengJi=A.CengJi and B.CYID=A.CYID and B.IFZY=1)');
      sql.Add(' from CP_YDang_ML A ');
      SQL.Add('where A.CYID=''' + trim(Order_Sub.fieldbyname('PRTCode').AsString) + '''');
      sql.Add(' and A.IFSel=1 ');
      sql.Add(' order by A.Cengji,A.MLID');
      open;
    end;
    while not ADOQuery1.Eof do
    begin
      if GetLSNo(ADOQueryCmd, fCFID, 'JC', 'JYOrder_Sub_CF', 4, 1) = False then
      begin
        Application.MessageBox('取子流水号失败！', '提示', 0);
        Exit;
      end;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from JYOrder_Sub_CF where CFID=''' + Trim(fCFID) + '''');
        Open;
        if IsEmpty then
          Append
        else
          edit;
        fieldbyname('CFID').Value := trim(fCFID);
        fieldbyname('PRTCode').Value := trim(Order_Sub.fieldbyname('PRTCode').AsString);
        fieldbyname('PrtCodeName').Value := trim(ADOQuery1.fieldbyname('MLName').AsString);
        fieldbyname('PrtSpec').Value := trim(Order_Sub.fieldbyname('PrtSpec').AsString);
        fieldbyname('SOrddefstr1').Value := trim(ADOQuery1.fieldbyname('MLSeHao').AsString);
        fieldbyname('PRTColor').Value := trim(ADOQuery1.fieldbyname('MLColor').AsString);
        fieldbyname('PRTHX').Value := trim(ADOQuery1.fieldbyname('HXName').AsString);
        fieldbyname('PRTOrderRollNum').Value := Order_Sub.fieldbyname('PRTOrderRollNum').AsFloat;
        fieldbyname('PrtOrderQty').Value := Order_Sub.fieldbyname('PRTOrderQty').AsFloat;
        fieldbyname('OrderUnit').Value := trim(Order_Sub.fieldbyname('OrderUnit').AsString);
        FieldByName('PRTType').Value := trim(ADOQuery1.fieldbyname('CengJi').AsString) + '层';
        fieldbyname('MainID').Value := trim(Order_Sub.fieldbyname('MainID').AsString);
        fieldbyname('SubID').Value := trim(Order_Sub.fieldbyname('SubID').AsString);
        post;
      end;
      ADOQuery1.Next;
    end;
  end
  else
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('update JYOrder_Sub_CF set ');
      sql.Add('PRTCode=''' + trim(Order_Sub.fieldbyname('PRTCode').AsString) + '''');
      sql.Add(',PrtSpec=''' + trim(Order_Sub.fieldbyname('PrtSpec').AsString) + '''');
      sql.Add(',OrderUnit=''' + trim(Order_Sub.fieldbyname('OrderUnit').AsString) + '''');
      sql.Add(' where Subid=''' + trim(Order_Sub.fieldbyname('Subid').AsString) + '''');
      ExecSQL;
    end;
  end;
end;

function TfrmMLOrderInPut_JGNX.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 TfrmMLOrderInPut_JGNX.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('面料购销合同11', Tv1, '加工内销管理');
end;

procedure TfrmMLOrderInPut_JGNX.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select *');
    sql.Add(',IFFZ=(select count(B.WBID) from TP_File B where B.WBID=A.CSID and B.TFType=''合同明细'')');
    SQL.Add(' from ML_ConSub A where 1=1 ');
    if PState = 1 then
    begin
      sql.Add(' and MLConID=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' and 1<>1');
    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1, Order_Sub);
  SInitCDSData20(ADOQuery1, Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from ML_ConMain where MLConID=''' + Trim(FMainId) + '''');
    Open;
  end;
  SCSHDataNew(ADOQuery1, ScrollBox1, 2);
  SCSHDataNew(ADOQuery1, ScrollBox2, 2);
  if PState = 0 then
  begin
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    SYRYWY.Text := Trim(DName);
  end
  else
  begin
  end;
  if CopyInt = 99 then
  begin
    PState := 0;
    FMainId := '';
    OrdDate.DateTime := SGetServerDateTime(ADOTemp);
    SYRYWY.Text := Trim(DName);
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MLConID').Value := '';
        FieldByName('CSID').Value := '';
        Post;
        Next;
      end;
    end;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.FormShow(Sender: TObject);
begin
  readCxGrid('面料购销合同11', Tv1, '加工内销管理');
  InitData();
end;

function TfrmMLOrderInPut_JGNX.SaveData(): Boolean;
var
  maxno, FConNO, FUserID, FNo: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'ML', 'ML_ConMain', 3, 1) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      if GetLSNo(ADOCmd, FConNO, 'HT', 'ML_ConMain', 4, 0) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      ConNO.Text := Trim(FConNO);
      with ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.Add('select UserID from SY_User ');
        sql.Add(' where UserName=''' + trim(SYRYWY.Text) + '''');
        open;
      end;
      FUserID := Trim(ADOQuery1.fieldbyname('UserID').AsString) + trim(formatdatetime('yy', OrdDate.Date)) + trim(formatdatetime('MM', OrdDate.Date));
      if GetLSNo(ADOCmd, FNo, FUserID, 'ML_ConMain', 2, 0) = False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!', '提示', 0);
        Exit;
      end;
      YWConNO.Text := Trim(FNo);
    end
    else
    begin
      maxno := Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from ML_ConMain where MLConID=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        Edit;
      end;
      FieldByName('MLConID').Value := Trim(maxno);
      FieldByName('ConType').Value := '加工内销';
      SSetsaveSqlNew(ADOCmd, 'ML_ConMain', ScrollBox1, 2);
      SSetsaveSqlNew(ADOCmd, 'ML_ConMain', ScrollBox2, 2);
      FieldByName('ChkStatus').Value := '未审核';
      Post;
    end;
    FMainId := Trim(maxno);
    ///保存子表
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('CSID').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'MS', 'ML_ConSub', 4, 1) = False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('CSID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from ML_ConSub where MLConID=''' + Trim(FMainId) + '''');
          sql.Add(' and CSID=''' + Trim(maxno) + '''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(Order_Sub.fieldbyname('CSID').AsString) = '' then
            Append
          else
            Edit;
          FieldByName('MLConID').Value := Trim(FMainId);
          FieldByName('CSID').Value := Trim(maxno);
          FieldByName('MLID').Value := Trim(Order_Sub.fieldbyname('MLID').AsString);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'ML_ConSub', 0);
          fieldbyname('Qty').Value := Order_Sub.FieldByName('Qty').AsFloat;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('CSID').Value := Trim(maxno);
        Order_Sub.FieldByName('MLConID').Value := Trim(FMainId);
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    Result := False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
  end;
end;

procedure TfrmMLOrderInPut_JGNX.TBSaveClick(Sender: TObject);
begin
  OrdDate.SetFocus;
  if SYRName.Text = '' then
  begin
    Application.MessageBox('供方不能为空', '提示');
    exit;
  end;
  if KHName.Text = '' then
  begin
    Application.MessageBox('需方不能为空', '提示');
    exit;
  end;
  if SYRYWY.Text = '' then
  begin
    Application.MessageBox('业务员不能为空', '提示');
    exit;
  end;
  if SYRYWFZR.Text = '' then
  begin
    Application.MessageBox('业务助理不能为空', '提示');
    exit;
  end;
  if JHType.Text = '' then
  begin
    Application.MessageBox('交货方式不能为空', '提示');
    exit;
  end;
  if CheckBox2.Checked = True then
  begin
    if KPCodeName.Text = '' then
    begin
      Application.MessageBox('开票品名不能为空', '提示');
      exit;
    end;
  end;
  if SYRYWFZR.Text = '' then
  begin
    Application.MessageBox('业务助理不能为空', '提示');
    exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.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('MLColor').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('MLColorNo').Value := Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ToolButton1Click(Sender: TObject);
begin
  Panel4.Visible := true;
end;

procedure TfrmMLOrderInPut_JGNX.KHNameBtnUpClick(Sender: TObject);
begin
  try
    frmKHList_CX := TfrmKHList_CX.Create(Application);
    with frmKHList_CX do
    begin
      if ShowModal = 1 then
      begin
        KHName.Text := Trim(CDS_HZ.fieldbyname('KHName').AsString);
        KHAdd.Text := Trim(CDS_HZ.fieldbyname('KHAdd').asstring);
        KHTel.Text := Trim(CDS_HZ.fieldbyname('KHTel').asstring);
        KHYWFZR.Text := Trim(CDS_HZ.fieldbyname('KHLXR').asstring);
        KHPhone.Text := Trim(CDS_HZ.fieldbyname('KHTel').asstring);
        KHBankName.Text := Trim(CDS_HZ3.fieldbyname('BankName').asstring);
        KHBankNo.Text := Trim(CDS_HZ3.fieldbyname('BankNo').asstring);
      end;
    end;
  finally
    frmKHList_CX.Free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.KHNameBtnDnClick(Sender: TObject);
begin
  TBtnEditC(Sender).Text := '';
  TBtnEditC(Sender).TxtCode := '';
end;

procedure TfrmMLOrderInPut_JGNX.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 TfrmMLOrderInPut_JGNX.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 TfrmMLOrderInPut_JGNX.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 ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConNoKeyPress(Sender: TObject; var Key: Char);
var
  ConMainId: string;
begin

end;

procedure TfrmMLOrderInPut_JGNX.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);
      //MainType:=TEdit(Sender).Name;
      if ShowModal = 1 then
      begin
        TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.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 TfrmMLOrderInPut_JGNX.v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  frmZdyAttachCP_HX_Sel := TfrmZdyAttachCP_HX_Sel.create(self);
  with frmZdyAttachCP_HX_Sel do
  begin
    if showmodal = 1 then
    begin
      Order_Sub.Edit;
      Order_Sub.FieldByName('PRTHX').Value := trim(cds_Hz.FieldByName('ZdyName').asstring);
      Order_Sub.Post;
    end;
    frmZdyAttachCP_HX_Sel.Free;
  end;
  tv1.Controller.EditingController.ShowEdit();
end;

procedure TfrmMLOrderInPut_JGNX.InitColor();
var
  fsj: string;
begin
  with adoqueryTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from RT_PTColor where PTID=''' + Trim(Self.PTID.Text) + '''');
    Open;
  end;
  fsj := Trim(adoqueryTmp.fieldbyname('ColDaiMa').AsString);
  if trim(fsj) <> '' then
    Panel5.Color := StrToInt('$' + Trim(fsj));
end;

procedure TfrmMLOrderInPut_JGNX.ConCodeKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConCodeName.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Initimage();
var
  ListItem: TListItem;
  Flag: Cardinal;
  info: SHFILEINFOA;
  Icon: TIcon;
begin
  ListView1.Items.Clear;
  with adoqueryTmp do
  begin
    close;
    sql.Clear;
    sql.Add('select fileName from TP_File ');
    sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + ''' ');
    sql.Add('and TFType=''合同明细''');
    open;
    if not IsEmpty then
    begin
      while not eof do
      begin
        with ListView1 do
        begin
          LargeImages := ImageList1;
          Icon := TIcon.Create;
          ListItem := Items.Add;
          ListItem.Caption := trim(fieldbyname('fileName').AsString);
          Flag := (SHGFI_LARGEICON or SHGFI_ICON or SHGFI_USEFILEATTRIBUTES);
          SHGetFileInfo(Pchar(trim(fieldbyname('fileName').AsString)), 0, info, Sizeof(info), Flag);
          Icon.Handle := info.hIcon;
          ImageList1.AddIcon(Icon);
          ListItem.ImageIndex := ImageList1.Count - 1;
        end;
        next;
      end;
    end;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ListView1DblClick(Sender: TObject);
var
  sFieldName: string;
  fileName: string;
begin
  if listView1.SelCount < 1 then
  begin
    listView1.Visible := false;
    exit;
  end;
  if ListView1.Items.Count < 1 then
    EXIT;
  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);

  fileName := ListView1.Selected.Caption;

  sFieldName := sFieldName + '\' + trim(fileName);

  try
    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    ;
  end;

  if IdFTP1.Connected then
  begin
    Panel2.Caption := '正在下载数据，请稍等...';
    Panel2.Visible := true;
    application.ProcessMessages;
    try
      IdFTP1.Get('FJ\' + Trim(fileName), sFieldName, true, false);
    except
      Panel2.Visible := false;
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
    Panel2.Visible := false;
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
  Panel2.Visible := false;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

procedure TfrmMLOrderInPut_JGNX.Button4Click(Sender: TObject);
var
  fFileName: string;
  fFilePath: string;
  maxNo: string;
begin
  try
    adoqueryCmd.Connection.BeginTrans;
    begin
      fFilePath := WJPach.Text;
      fFileName := WJName.Text;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select TFId from TP_File ');
        sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
        sql.Add(' and TFType=''合同明细''');
        sql.Add(' and FileName=' + quotedstr(trim(fFileName)));
        open;
      end;
      if ADOQueryCmd.IsEmpty = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        application.MessageBox('此附件名称已存在，请修改文件名，继续上传！', '提示信息', MB_ICONERROR);
        exit;
      end;
      Panel12.Visible := False;
      Panel2.Caption := '正在上传数据，请稍等...';
      Panel2.Visible := true;
      application.ProcessMessages;

      if GetLSNo(ADOQueryCmd, maxNo, 'NX', 'TP_File', 4, 1) = False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！', '提示', 0);
        Exit;
      end;

      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('delete from TP_File ');
        sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
        sql.Add(' and TFType=''合同明细''');
        sql.Add('and FileName=' + quotedstr(trim(fFileName)));
        execsql;
      end;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from TP_File ');
        sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
        sql.Add(' and TFType=''合同明细''');
        sql.Add(' and FileName=' + quotedstr(trim(fFileName)));
        open;
        append;
        fieldbyname('TFID').Value := trim(maxNo);
        fieldbyname('WBID').Value := trim(Order_Sub.fieldbyname('CSID').AsString);
        fieldbyname('TFType').Value := '合同明细';
        fieldbyname('FileName').Value := trim(fFileName);
        post;
      end;
      if fFilePath <> '' then
      begin
        try
          IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
          IdFTP1.Username := 'three';
          IdFTP1.Password := '641010';
          IdFTP1.Connect();
          IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
          IdFTP1.Quit;
        except
          IdFTP1.Quit;
          Application.MessageBox('上传文件失败，请检查文件服务器！', '提示', MB_ICONWARNING);
        end;
      end;
      IdFTP1.Quit;
      Panel2.Visible := false;
      Initimage();
    end;
    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('文件保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button8Click(Sender: TObject);
var
  fFileName: string;
begin
  fFileName := WJName.Hint;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('UPdate TP_File Set FileName=''' + Trim(WJName.Text) + '''');
    sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
    sql.Add(' and TFType=''合同明细''');
    sql.Add('and FileName=' + quotedstr(trim(fFileName)));
    execsql;
  end;
  Panel12.Visible := False;
  Initimage();
end;

procedure TfrmMLOrderInPut_JGNX.Button7Click(Sender: TObject);
var
  fFileName: string;
  fFilePath: string;
  maxNo: string;
begin
  try
    adoqueryCmd.Connection.BeginTrans;
    fFilePath := WJPach.Text;
    fFileName := WJName.Hint;
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select TFId from TP_File ');
      sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
      sql.Add(' and TFType=''合同明细''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      open;
      if not adoqueryCmd.IsEmpty then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        application.MessageBox('此附件名称已存在，请修改文件名，继续上传！', '提示信息', MB_ICONERROR);
        exit;
      end;
    end;
    Panel12.Visible := False;
    Panel2.Caption := '正在上传数据，请稍等...';
    Panel2.Visible := true;
    application.ProcessMessages;

    if GetLSNo(ADOQueryCmd, maxNo, 'FJ', 'TP_File', 4, 1) = False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;

    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from TP_File ');
      sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
      sql.Add(' and TFType=''合同明细''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      execsql;
    end;
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from TP_File ');
      sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
      sql.Add(' and TFType=''合同明细''');
      sql.Add('and FileName=' + quotedstr(trim(fFileName)));
      open;
      append;
      fieldbyname('TFID').Value := trim(maxNo);
      fieldbyname('WBID').Value := trim(Order_Sub.fieldbyname('CSID').AsString);
      fieldbyname('TFType').Value := '合同明细';
      fieldbyname('FileName').Value := trim(fFileName);
      post;
    end;
    if fFilePath <> '' then
    begin
      try
        IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
        IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
        IdFTP1.Quit;
      except
        IdFTP1.Quit;
        Application.MessageBox('上传文件失败，请检查文件服务器！', '提示', MB_ICONWARNING);
      end;
    end;
    IdFTP1.Quit;
    Panel2.Visible := false;
    Initimage();
    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('文件保存失败！', '提示信息', 0);
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Image1Click(Sender: TObject);
begin
  Panel12.Visible := false;
end;

procedure TfrmMLOrderInPut_JGNX.MenuItem1Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
begin
  OpenDiaLog := TOpenDialog.Create(Self);
  if OpenDiaLog.Execute then
  begin
    fFilePath := OpenDiaLog.FileName;
    fFileName := ExtractFileName(OpenDiaLog.FileName);
    Panel12.Visible := True;
    WJName.Text := Trim(fFileName);
    WJName.Hint := Trim(fFileName);
    WJPach.Text := fFilePath;
    Button8.Visible := False;
    Button4.Visible := True;
    Button7.Visible := True;
    Panel12.Refresh;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.N3Click(Sender: TObject);
var
  fFileName: string;
begin
  if listView1.SelCount < 1 then
    exit;
  fFileName := ListView1.Selected.Caption;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('delete  from TP_File ');
    sql.Add('where WBID=''' + trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
    sql.Add(' and TFType=''合同明细''');
    sql.Add('and FileName=' + quotedstr(trim(fFileName)));
    execsql;
  end;
  Initimage();
end;

procedure TfrmMLOrderInPut_JGNX.MenuItem2Click(Sender: TObject);
begin
  if listView1.SelCount < 1 then
    exit;
  Panel12.Visible := True;
  Button4.Visible := False;
  Button7.Visible := False;
  Button8.Visible := True;
  Panel12.Refresh;
  WJName.Text := Trim(ListView1.Selected.Caption);
  WJName.Hint := Trim(ListView1.Selected.Caption);
end;

procedure TfrmMLOrderInPut_JGNX.N4Click(Sender: TObject);
var
  SaveDialog: TSaveDialog;
  fFileName: string;
  fFilePath: string;
begin
  if listView1.SelCount < 1 then
    exit;
  try
    fFileName := ListView1.Selected.Caption;
    SaveDialog := TSaveDialog.Create(Self);
    SaveDialog.FileName := fFileName;
    if SaveDialog.Execute then
    begin
      Panel2.Caption := '正在保存数据，请稍等...';
      Panel2.Visible := true;
      application.ProcessMessages;
      fFilePath := SaveDialog.FileName;
      try
        IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', 'FTP地址', '127.0.0.1');
        ;
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
      except
        ;
      end;
      if IdFTP1.Connected then
      begin
        Panel2.Caption := '正在下载数据，请稍等...';
        Panel2.Visible := true;
        application.ProcessMessages;
        try
          IdFTP1.Get('FJ\' + Trim(fFileName), fFilePath, false, true);
        except
          Panel2.Visible := false;
          Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
          IdFTP1.Quit;
          Exit;
        end;
      end
      else
      begin
        Panel2.Visible := false;
        Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
        IdFTP1.Quit;
        Exit;
      end;
      Panel2.Visible := false;
      if IdFTP1.Connected then
        IdFTP1.Quit;
    end;
  except
    Panel2.Visible := false;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button2Click(Sender: TObject);
begin
  Panel3.Visible := false;
  SClearData(Panel3, 2);
end;

procedure TfrmMLOrderInPut_JGNX.MenuItem3Click(Sender: TObject);
begin
  Panel3.Visible := true;
  SCSHDataCDS(Order_Sub, Panel3, 2);
  Initimage();
  Button1.Visible := true;
  button1.Caption := '修改';
  cxGrid1.Enabled := false;
end;

procedure TfrmMLOrderInPut_JGNX.MenuItem4Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Trim(Order_Sub.fieldbyname('CSID').AsString) <> '' then
  begin
    if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete ML_ConSub where CSID=''' + Trim(Order_Sub.fieldbyname('CSID').AsString) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmMLOrderInPut_JGNX.Tv1DblClick(Sender: TObject);
begin
  if Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName = 'IFFZ' then
  begin
    ListView1.Visible := true;
    Initimage();
  end
  else
  begin
    Panel3.Visible := true;
    SCSHDataCDS(Order_Sub, Panel3, 2);
    MLID.Text := Trim(Order_Sub.FieldByName('MLID').AsString);
    Button1.Visible := false;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button1Click(Sender: TObject);
var
  FJQty, FKG, FM, FMoney: string;
  FReal: Double;
  FInt: Integer;
begin
  if Trim(ConCodeName.Text) = '' then
  begin
    Application.MessageBox('产品名称不能为空!', '提示', 0);
    Exit;
  end;
  if Trim(Qty.Text) = '' then
  begin
    Application.MessageBox('数量不能为空!', '提示', 0);
    Exit;
  end;
  with Order_Sub do
  begin
    if Button1.Caption = '确定' then
    begin
      Append;
      FieldByName('XHNo').Value := Order_Sub.RecordCount + 1;
    end
    else
      edit;
    RTsavedataCDS(Order_Sub, Panel3, 2);
    FieldByName('ConGY').Value := Trim(ConGY.Text);
    FieldByName('CSID').Value := Trim(CSID.Text);
    FieldByName('MLID').Value := Trim(MLID.Text);
    FieldByName('ConType').Value := '染色面料';
    if KHConCodeName.Text = '' then
    begin
      FieldByName('KHConCodeName').Value := Trim(ConCodeName.Text);
    end;
    if ConKHColNo.Text = '' then
    begin
      FieldByName('ConKHColNo').Value := Trim(ConColNo.Text);
    end;
    post;
  end;
  SClearData(Panel3, 2);
  ConPrice.Text := '';
  Button1.Caption := '确定';
  cxGrid1.Enabled := true;
  Panel3.Visible := false;
end;

procedure TfrmMLOrderInPut_JGNX.IFHSClick(Sender: TObject);
begin
  if IFHS.Checked = True then
  begin
    IFBHS.Checked := false;
  end
  else
  begin
    IFBHS.Checked := true;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.CheckBox2Click(Sender: TObject);
begin
  if checkbox2.Checked = true then
  begin
    KPCodeName.Visible := true;
  end
  else
  begin
    KPCodeName.Visible := false;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.CheckBox1Click(Sender: TObject);
begin
  if checkbox1.Checked = true then
  begin
    BCShuoMing.Visible := true;
  end
  else
  begin
    BCShuoMing.Visible := false;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.SYRNameBtnUpClick(Sender: TObject);
begin
  frmGSList_CX := TfrmGSList_CX.create(self);
  with frmGSList_CX do
  begin
    cxGrid3.Visible := false;
    if showmodal = 1 then
    begin
      SYRName.Text := Trim(CDS_HZ.fieldbyname('KHName').asstring);
      SYRAdd.Text := Trim(CDS_HZ.fieldbyname('KHAdd').asstring);
      SYRYWY.Text := Trim(CDS_HZ.fieldbyname('KHLXR').asstring);
    end;
    free;
  end;
  Button13.Click;
end;

procedure TfrmMLOrderInPut_JGNX.QtyUnitBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'QtyUnit';
    flagname := '数量单位';
    if ShowModal = 1 then
    begin
      QtyUnit.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      QtyUnit.TxtCode := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConGYBtnClick(Sender: TObject);
begin
  frmMLMangeRS_Sel2 := TfrmMLMangeRS_Sel2.create(self);
  with frmMLMangeRS_Sel2 do
  begin
    MLName.Text := Trim(ConCodeName.Text);
    Formid := '1';
    if ShowModal = 1 then
    begin
      ConGY.Text := Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      ConGY.TxtCode := Trim(CDS_Main.fieldbyname('GYLXName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConCodeBtnClick(Sender: TObject);
var
  maxno: string;
begin
  frmMLMangeRS_Sel1 := TfrmMLMangeRS_Sel1.create(self);
  with frmMLMangeRS_Sel1 do
  begin
    formid := '2';
    if ShowModal = 1 then
    begin
      Panel3.Visible := true;
      if CSID.Text = '' then
      begin
        if GetLSNo(ADOCmd, maxno, 'MS', 'ML_ConSub', 3, 1) = False then
        begin
          Application.MessageBox('取最大号失败!', '提示', 0);
          Exit;
        end;
        CSID.Text := Trim(maxno);
      end;
      Label53.Caption := TButton(Sender).Caption;
      ConCode.Text := Trim(CDS_Main.fieldbyname('MLNo').AsString);
      self.MLID.Text := Trim(CDS_Main.fieldbyname('MLID').AsString);
      ConCode.TxtCode := Trim(CDS_Main.fieldbyname('MLNo').AsString);
      ConCodeName.Text := Trim(CDS_Main.fieldbyname('MLName').AsString);
      //ConColor.Text:=Trim(CDS_Main.fieldbyname('ColNameKH').AsString);
      //ConColNo.Text:=Trim(CDS_Main.fieldbyname('ColNo').AsString);
      //ConKHColNo.Text:=Trim(CDS_Main.fieldbyname('GYSColNo').AsString);
      //ConGY.Text:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      //ConGY.TxtCode:=Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      self.Panel4.Visible := false;
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.QtyChange(Sender: TObject);
begin
  ConMoney.Text := FloatToStr(StrToFloatDef(Qty.Text, 0) * strtofloatdef(ConPrice.Text, 0))
end;

procedure TfrmMLOrderInPut_JGNX.SYRFDRBtnClick(Sender: TObject);
begin
  frmZDYHelp := TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    Flag := 'SYRFDR';
    flagname := '法定代表人';
    if ShowModal = 1 then
    begin
      SYRFDR.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.SYRYWYBtnClick(Sender: TObject);
begin
  frmZDYHelpYW := TfrmZDYHelpYW.Create(self);
  with frmZDYHelpYW do
  begin
    if ShowModal = 1 then
    begin
      SYRYWY.Text := Trim(ClientDataSet1.fieldbyname('UserName').AsString);
      with ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.Add('select Top 1 SYRYWTel,SYRPhone from ML_ConMain ');
        sql.Add('where SYRYWY=''' + trim(SYRYWY.Text) + ''' order by OrdDate desc');
        open;
      end;
      SYRYWTel.Text := Trim(ADOQuery1.fieldbyname('SYRYWTel').AsString);
      SYRPhone.Text := Trim(ADOQuery1.fieldbyname('SYRPhone').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.SYRYWFZRBtnClick(Sender: TObject);
begin
  frmZDYHelpYW := TfrmZDYHelpYW.Create(self);
  with frmZDYHelpYW do
  begin
    if ShowModal = 1 then
    begin
      SYRYWFZR.Text := Trim(ClientDataSet1.fieldbyname('UserName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button3Click(Sender: TObject);
var
  maxno: string;
begin
  frmMLMangeRS_Sel1 := TfrmMLMangeRS_Sel1.create(self);
  with frmMLMangeRS_Sel1 do
  begin
    if ShowModal = 1 then
    begin
      Panel3.Visible := true;
      if CSID.Text = '' then
      begin
        if GetLSNo(ADOCmd, maxno, 'MS', 'ML_ConSub', 3, 1) = False then
        begin
          Application.MessageBox('取最大号失败!', '提示', 0);
          Exit;
        end;
        self.CSID.Text := Trim(maxno);
      end;
      Label53.Caption := TButton(Sender).Caption;
      self.PTID.Text := Trim(CDS_Main.fieldbyname('PTID').AsString);
      self.MLID.Text := Trim(CDS_Main.fieldbyname('MLID').AsString);
      ConCode.Text := Trim(CDS_Main.fieldbyname('MLNo').AsString);
      ConCode.TxtCode := Trim(CDS_Main.fieldbyname('MLNo').AsString);
      ConCodeName.Text := Trim(CDS_Main.fieldbyname('MLName').AsString);
      ConColor.Text := Trim(CDS_Main.fieldbyname('ColNameKH').AsString);
      ConColNo.Text := Trim(CDS_Main.fieldbyname('ColNo').AsString);
      ConGY.Text := Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      ConGY.TxtCode := Trim(CDS_Main.fieldbyname('GYLXName').AsString);
      self.QtyUnit.Text := 'M';
      self.QtyUnit.TxtCode := 'M';
      self.Panel4.Visible := false;
      InitColor();
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button10Click(Sender: TObject);
var
  FBPIDSH: string;
begin
  frmBPZDY_LRPB := TfrmBPZDY_LRPB.create(self);
  with frmBPZDY_LRPB do
  begin
    Flag := 'PBName';
    flagName := '坯布';
    ViewFlag := true;
    Panel4.Align := alClient;
    ToolBar3.Visible := false;
    Button1.Visible := False;
    ToolButton1.Visible := true;
    if ShowModal = 1 then
    begin
      ConCode.Text := Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      ConCodeName.Text := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      ConPrice.Text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      if ClientDataSet1.fieldbyname('SKID').AsString = '' then
        FBPIDSH := Trim(ClientDataSet1.fieldbyname('BPCode').AsString)
      else
        FBPIDSH := Trim(ClientDataSet1.fieldbyname('SKID').AsString);
      with ADOQuery6 do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,B.* from RT_PTColor A ');
        sql.Add('inner join BP_ColZDY B on B.PTID=A.PTID ');
        sql.Add('where isnull(B.SKID,'''')=''' + trim(FBPIDSH) + ''' and isnull(B.SKID,'''')<>''''');
        sql.Add(' order by cast(B.ColNo as int)');
        Open;
      end;
      ConColor.Text := Trim(ADOQuery6.fieldbyname('ColNameKH').AsString);
      ConColNo.Text := Trim(ADOQuery6.fieldbyname('ColNo').AsString);
      ConKHColNo.Text := Trim(ADOQuery6.fieldbyname('GYSColNo').AsString);
      self.Panel4.Visible := false;
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button11Click(Sender: TObject);
begin
  frmBPZDY_LRM := TfrmBPZDY_LRM.create(self);
  with frmBPZDY_LRM do
  begin
    Flag := 'MName';
    flagName := '棉';
    ViewFlag := true;
    Panel4.Align := alClient;
    ToolBar3.Visible := false;
    Button1.Visible := False;
    ToolButton1.Visible := true;
    if ShowModal = 1 then
    begin
      ConCode.Text := Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      ConCodeName.Text := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      ConPrice.Text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      self.Panel4.Visible := false;
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button12Click(Sender: TObject);
begin
  frmMCGRKList_XKC_CX := TfrmMCGRKList_XKC_CX.create(self);
  with frmMCGRKList_XKC_CX do
  begin
    FInt := '1';
    if ShowModal = 1 then
    begin
      ConCode.Text := Trim(PB_MX.fieldbyname('MYNo').AsString);
      ConCodeName.Text := Trim(PB_MX.fieldbyname('MYName').AsString);
      ConColor.Text := Trim(PB_MX.fieldbyname('MYColor').AsString);
      ConColNo.Text := Trim(PB_MX.fieldbyname('MYColorNo').AsString);
      ConKHColNo.Text := Trim(PB_MX.fieldbyname('MYColorNo').AsString);
      ConPrice.Text := Trim(PB_MX.fieldbyname('MYMDPrice').AsString);
      QtyUnit.Text := '只';
      self.Panel4.Visible := false;
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button9Click(Sender: TObject);
begin
  frmBPZDY_LRPB_M1 := TfrmBPZDY_LRPB_M1.create(self);
  with frmBPZDY_LRPB_M1 do
  begin
    Flag := 'MName';
    flagName := '膜库';
    ViewFlag := true;
    Panel4.Align := alClient;
    Button1.Visible := False;
    ToolButton1.Visible := true;
    if ShowModal = 1 then
    begin
      ConCode.Text := Trim(ClientDataSet1.fieldbyname('BPCode').AsString);
      ConCodeName.Text := Trim(ClientDataSet1.fieldbyname('BPName').AsString);
      ConPrice.Text := Trim(ClientDataSet1.fieldbyname('BPPrice').AsString);
      self.Panel4.Visible := false;
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button5Click(Sender: TObject);
begin
  self.Panel4.Visible := false;
end;

procedure TfrmMLOrderInPut_JGNX.Button6Click(Sender: TObject);
begin
  self.Panel4.Visible := false;
end;

procedure TfrmMLOrderInPut_JGNX.Image2Click(Sender: TObject);
begin
  Panel4.Visible := false;
end;

procedure TfrmMLOrderInPut_JGNX.KHConCodeBtnClick(Sender: TObject);
begin
  frmZHCPList_CX := TfrmZHCPList_CX.create(self);
  with frmZHCPList_CX do
  begin
    if ShowModal = 1 then
    begin
      KHConCode.Text := trim(Order_Main.fieldbyname('ZIID').AsString);
      KHConCode.TxtCode := trim(Order_Main.fieldbyname('ZIID').AsString);
      //KHConCodeName.Text:=trim(Order_Main.fieldbyname('ZIName').AsString);
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConCodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    KHConCode.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.KHConCodeKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    KHConCodeName.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.KHConCodeNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConColor.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConColorKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConColNo.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConColNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConKHColNo.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConKHColNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Qty.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.QtyKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    QtyUnit.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.QtyUnitKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConPrice.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConPriceKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConGY.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConGYKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    ConNote.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConNoteKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    Button1.SetFocus;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.ConCodeChange(Sender: TObject);
begin
  ConCode.TxtCode := ConCode.Text;
end;

procedure TfrmMLOrderInPut_JGNX.KHConCodeChange(Sender: TObject);
begin
  KHConCode.TxtCode := KHConCode.Text;
end;

procedure TfrmMLOrderInPut_JGNX.QtyUnitChange(Sender: TObject);
begin
  QtyUnit.TxtCode := QtyUnit.Text;
end;

procedure TfrmMLOrderInPut_JGNX.ConGYChange(Sender: TObject);
begin
  ConGY.TxtCode := ConGY.Text;
end;

procedure TfrmMLOrderInPut_JGNX.N2Click(Sender: TObject);
begin
  try
    frmMLManage_LRRS := TfrmMLManage_LRRS.Create(Application);
    with frmMLManage_LRRS do
    begin
      FCYID := Trim(Self.MLID.Text);
      FGYName := '染色';
      viewFlag := True;
      if ShowModal = 1 then
      begin
        ConColor.Text := Trim(OrdBP_SH.fieldbyname('ColNameKH').AsString);
        ConColNo.Text := Trim(OrdBP_SH.fieldbyname('ColNo').AsString);
        if Trim(OrdBP_SH.fieldbyname('GYSColNo').AsString) <> '' then
          ConKHColNo.Text := Trim(OrdBP_SH.fieldbyname('GYSColNo').AsString)
        else
          ConKHColNo.Text := Trim(OrdBP_SH.fieldbyname('ColNo').AsString);
        self.PTID.Text := Trim(OrdBP_SH.fieldbyname('PTID').AsString);
        if Trim(PTID.Text) <> '' then
        begin
          InitColor();
        end;
      end;
    end;
  finally
    frmMLManage_LRRS.Free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.Button13Click(Sender: TObject);
begin
  frmGSList_CX := TfrmGSList_CX.create(self);
  with frmGSList_CX do
  begin
    if showmodal = 1 then
    begin
      SYRBankName.Text := Trim(CDS_HZ3.fieldbyname('BankName').asstring);
      SYRBankNo.Text := Trim(CDS_HZ3.fieldbyname('BankNo').asstring);
      if Trim(CDS_HZ3.fieldbyname('BankType').asstring) = '现金账户' then
      begin
        CheckBox2.Checked := false;
        KPCodeName.Visible := False;
      end
      else
      begin
        CheckBox2.Checked := true;
        KPCodeName.Visible := true;
      end;
    end;
    free;
  end;
end;

procedure TfrmMLOrderInPut_JGNX.IFBHSClick(Sender: TObject);
begin
  if IFBHS.Checked = True then
  begin
    IFHS.Checked := false;
  end
  else
  begin
    IFHS.Checked := true;
  end;
end;

end.

