unit U_OrderInPutPrice;

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, cxPC, cxGridCustomPopupMenu,
  cxGridPopupMenu, cxDropDownEdit,jpeg,IdGlobal, RM_Common, RM_Class,
  RM_e_Xls, RM_System, RM_GridReport, RM_Dataset;

type
  TfrmOrderInPutPrice = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    cxPageControl1: TcxPageControl;
    cxTabSheet1: TcxTabSheet;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1SOrddefstr1: TcxGridDBColumn;
    v1PRTColor: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1PRTOrderQty: TcxGridDBColumn;
    v1OrderUnit: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxTabSheet3: TcxTabSheet;
    Panel1: TPanel;
    Label1: TLabel;
    Label10: TLabel;
    Label3: TLabel;
    Label14: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label2: TLabel;
    Label6: TLabel;
    Label25: TLabel;
    Label43: TLabel;
    OrderNo: TEdit;
    ConNo: TEdit;
    OrdDate: TDateTimePicker;
    DLYDate: TDateTimePicker;
    YWY: TBtnEditC;
    Label4: TLabel;
    Note: TMemo;
    Label5: TLabel;
    CDS_JGLC: TClientDataSet;
    DataSource2: TDataSource;
    CDS_JGC: TClientDataSet;
    DataSource3: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxGridPopupMenu2: TcxGridPopupMenu;
    cxGridPopupMenu3: TcxGridPopupMenu;
    MPRTCodeName: TEdit;
    MPRTSpec: TEdit;
    Label7: TLabel;
    MPRTCF: TEdit;
    MPRTMF: TEdit;
    MPRTKZ: TEdit;
    CustomerNoName: TBtnEditA;
    MPRTCode: TBtnEditA;
    Label8: TLabel;
    Label9: TLabel;
    MPRTGYHZ: TEdit;
    SYRName: TBtnEditA;
    Label18: TLabel;
    LiDanPerson: TBtnEditA;
    ToolBar4: TToolBar;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    ScrollBox3: TScrollBox;
    ToolBar3: TToolBar;
    ToolButton8: TToolButton;
    ToolButton10: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton11: TToolButton;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    V3GYS: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    Tv3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column6: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    ToolButton13: TToolButton;
    Panel4: TPanel;
    CheckBox1: TCheckBox;
    ToolButton18: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel6: TPanel;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridDBColumn5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    cxGridDBColumn6: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Label44: TLabel;
    SCYaoSu: TMemo;
    v1Column20: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v3Column10: TcxGridDBColumn;
    Panel3: TPanel;
    Label30: TLabel;
    Label29: TLabel;
    Label31: TLabel;
    ClothOneQty: TEdit;
    OneQtyUnit: TComboBox;
    MPRTOneQty: TEdit;
    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 RanFactoryBtnUpClick(Sender: TObject);
    procedure CustomerNoNameBtnDnClick(Sender: TObject);
    procedure NoteDblClick(Sender: TObject);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1PriceUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure OrdDefStr2BtnUpClick(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure YCLFactoryBtnUpClick(Sender: TObject);
    procedure MPRTSCTeBieNoteBtnUpClick(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton8Click(Sender: TObject);
    procedure cxGridDBColumn6PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure CustomerNoNameBtnClick(Sender: TObject);
    procedure MPRTCodeBtnClick(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure Tv2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton10Click(Sender: TObject);
    procedure ToolButton11Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure v2Column2PropertiesEditValueChanged(Sender: TObject);
    procedure Tv5CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure Tv6CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure SYRNameBtnClick(Sender: TObject);
    procedure LiDanPersonBtnClick(Sender: TObject);
    procedure v3Column1PropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure ToolButton13Click(Sender: TObject);
    procedure v3Column2PropertiesEditValueChanged(Sender: TObject);
    procedure ToolButton18Click(Sender: TObject);
    procedure V3GYSPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
  private
    CanShu1,CanShu2,ConPrice:String;
    FJSFlag:Boolean;
    procedure InitData();
    procedure ZDYHelp(FButn:TcxButtonEdit;LType:string);
    function  SaveData():Boolean;

    { Private declarations }
  public
    PState,CopyInt,PriceFlag,DRInt,JYInt:Integer;
    FMainId,FFMainId,FOrderNo,ConSubId,DataType:String;
    FXS:Integer;
    { Public declarations }
  end;

var
  frmOrderInPutPrice: TfrmOrderInPutPrice;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun,U_ZDYHelpSel,U_CPManageTPCX,U_ZdyAttachment
  ,U_GYSList,U_OrderSubSel, U_ModuleNote;

{$R *.dfm}

procedure TfrmOrderInPutPrice.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('指示单录入11222',Tv1,'生产指示单管理');
  WriteCxGrid('流程录入22',Tv2,'生产指示单管理');
  WriteCxGrid('加工商录入',Tv3,'生产指示单管理');
end;

procedure TfrmOrderInPutPrice.InitData();
var
  fsj:string;
begin
  if Trim(CanShu1)<>'高权限' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CK_SXPB_CR where isnull(ORDMainIdRK,'''')='''+Trim(FMainId)+'''');
      sql.Add(' or isnull(ORDMainIdCK,'''')='''+Trim(FMainId)+'''');
      Open;
    end;
    if ADOTemp.IsEmpty=false then
    begin
      OrderNo.ReadOnly:=True;
    end else
    begin
      OrderNo.ReadOnly:=False;
    end;
  end;

  ReadCxGrid('指示单录入11222',Tv1,'生产指示单管理');
  ReadCxGrid('流程录入22',Tv2,'生产指示单管理');
  ReadCxGrid('加工商录入',Tv3,'生产指示单管理');
  cxPageControl1.ActivePageIndex:=0;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.*  ');
    sql.Add(',YAPPS=(select sum(PFTPPS) from JYOrder_PCS_Sub B where B.SubId=A.SubId)');
    sql.Add(',YAPKgQty=(select sum(PFTPQty) from JYOrder_PCS_Sub B where B.SubId=A.SubId and B.PFTPUnit=''Kg'')');
    sql.Add(',YAPMQty=(select sum(PFTPQty) from JYOrder_PCS_Sub B where B.SubId=A.SubId and B.PFTPUnit=''M'')');
    sql.Add(' from JYOrder_Sub A 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(ADOQuery1,Order_Sub);
  SInitCDSData20(ADOQuery1,Order_Sub);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main where MainId='''+Trim(FMainId)+'''');
    Open;
  end;
  SCSHDataNew(ADOQuery1,Panel1,2);
  SCSHDataNew(ADOQuery1,Panel3,2);
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    if CopyInt<>99 then
      sql.Add('select * from JYOrder_Process where MainId='''+Trim(FMainId)+'''')
    else
      sql.Add('select * from JYOrder_Process where 1<>1');
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_JGLC);
  SInitCDSData20(ADOQuery1,CDS_JGLC);

  if PState=0 then
  begin
    OrdDate.DateTime:=SGetServerDateTime(ADOTemp);
    DlyDate.DateTime:=OrdDate.DateTime;
    LiDanPerson.Text:=Trim(DName);
    //YWY.Text:=Trim(DName);
  end else
  begin
  end;
  if CopyInt=99 then
  begin
    DLYDate.DateTime:=Now;
    DLYDate.Checked:=False;
    OrdDate.DateTime:=Now;
    PState:=0;
    FMainId:='';
    //OrdPerson1.Text:=Trim(DName);
    OrderNo.Text:='';
    OrderNo.ReadOnly:=False;
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value:='';
        FieldByName('SubId').Value:='';
        Post;
        Next;
      end;
    end;
  end;
end;

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

procedure TfrmOrderInPutPrice.FormShow(Sender: TObject);
begin
  InitData();
end;

function TfrmOrderInPutPrice.SaveData():Boolean;
var
  maxno,maxsubno,maxJDNo,JDMainId,maxjfno,maxjcno: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;
    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);
      if Trim(ConSubId)<>'' then
      begin
        FieldByName('ConSubId').Value:=Trim(ConSubId);
      end;
      RTSetsavedata(ADOCmd,'JYOrder_Main',Panel1,2);

      RTSetsavedata(ADOCmd,'JYOrder_Main',Panel3,2);
     
      FieldByName('CustomerNo').Value:=Trim(CustomerNoName.TxtCode);
      if Trim(FMainId)='' then
      begin
        FieldByName('Filler').Value:=Trim(DName);
        FieldByName('FillerCode').Value:=Trim(DCode);
      end else
      begin
        FieldByName('Editer').Value:=Trim(DName);
        FieldByName('EditTime').Value:=SGetServerDateTime(ADOTemp);
      end;
      FieldByName('Note').Value:=Trim(Note.Text);
      Post;
    end;

    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main where orderno='''+Trim(OrderNo.Text)+'''');
      Open;
    end;
    if ADOTemp.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,maxsubno,'JS','JYOrder_Sub',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxsubno:=Trim(Order_Sub.fieldbyname('SubId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Sub where SubId='''+Trim(maxsubno)+'''');
          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(maxsubno);
          RTSetSaveDataCDS(ADOCmd,Tv1,Order_Sub,'JYOrder_Sub',0);
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SubId').Value:=Trim(maxsubno);
        //Order_Sub.Post;
        Next;
      end;
    end;

    ///保存流程表
    with CDS_JGLC do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_JGLC.fieldbyname('PSId').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxsubno,'PS','JYOrder_Process',4,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取流程流水号失败！','提示',0);
            Exit;
          end;
        end else
        begin
          maxsubno:=Trim(CDS_JGLC.fieldbyname('PSId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from JYOrder_Process where PSId='''+Trim(maxsubno)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_JGLC.fieldbyname('PSId').AsString)='' then
            Append
          else
            Edit;
          FieldByName('MainId').Value:=Trim(maxno);
          FieldByName('PSId').Value:=Trim(maxsubno);
          RTSetSaveDataCDS(ADOCmd,Tv2,CDS_JGLC,'JYOrder_Process',0);
          Post;
        end;
        CDS_JGLC.Edit;
        CDS_JGLC.FieldByName('PSId').Value:=Trim(maxsubno);
        CDS_JGLC.FieldByName('MainId').Value:=Trim(maxno);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ADOCmd.Connection.CommitTrans;
    Result:=True;
    FMainId:=Trim(maxno);
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;




procedure TfrmOrderInPutPrice.TBSaveClick(Sender: TObject);
var
  FReal:Double;
begin
  ToolBar1.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(YWY.Text)='' then
  begin
    Application.MessageBox('业务员不能为空！','提示',0);
    Exit;
  end;
  if Trim(LiDanPerson.Text)='' then
  begin
    Application.MessageBox('理单员不能为空！','提示',0);
    Exit;
  end;  }
 
  if DLYDate.Checked=False then
  begin
    Application.MessageBox('交货日期不能为空!','提示',0);
    exit;
  end;
  if OrdDate.Checked=False then
  begin
    Application.MessageBox('制单日期不能为空!','提示',0);
    exit;
  end;
  if CDS_JGLC.IsEmpty=False then
  begin
    if CDS_JGLC.Locate('MFQty',Null,[])=True then
    begin
      Application.MessageBox('生产流程中的门幅不能为空!','提示',0);
      exit;
    end;
    if CDS_JGLC.Locate('KZQty',Null,[])=True then
    begin
      Application.MessageBox('生产流程中的克重不能为空!','提示',0);
      exit;
    end;
  end;
  if Trim(ClothOneQty.Text)<>'' then
  begin
    if TryStrToFloat(ClothOneQty.Text,FReal)=False then
    begin
      Application.MessageBox('每匹白坯数量非法数字!','提示',0);
      Exit;
    end;
  end;
  if Trim(MPRTOneQty.Text)<>'' then
  begin
    if TryStrToFloat(MPRTOneQty.Text,FReal)=False then
    begin
      Application.MessageBox('每匹成品数量非法数字!','提示',0);
      Exit;
    end;
  end; 

  if Order_Sub.Locate('PRTOrderQty',Null,[])=True then
  begin
    Application.MessageBox('数量不能为空!','提示',0);
    Exit;
  end;
  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空!','提示',0);
    Exit;
  end;
  {if CDS_JGLC.IsEmpty=False then
  begin
    if CDS_JGLC.Locate('KgZM',null,[])=True then
    begin
      Application.MessageBox('每公斤/米不能为空!','提示',0);
      Exit;
    end;
  end; }

  if cxPageControl1.ActivePageIndex=2 then
  begin
    if CDS_JGC.IsEmpty=False then
    begin
      if CDS_JGC.Locate('PFID',null,[])=True then
      begin
        Application.MessageBox('安排信息未确定!','提示',0);
        Exit;
      end;
    end;

  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
  end;
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.PRTHX,B.PRTColor,B.PRTOrderQty,B.OrderUnit from JYOrder_PCS_Sub A ');
      sql.Add(' left join JYOrder_Sub B on A.SubId=B.SubId');
      sql.Add('where A.PSID='''+Trim(CDS_JGLC.fieldbyname('PSID').AsString)+'''');
      SQL.Add(' and isnull(A.CKName,'''')<>''调节仓库'' ');
      Open;
    end;
    SCreateCDS20(ADOQuery1,CDS_JGC);
    SInitCDSData20(ADOQuery1,CDS_JGC);
  end;

end;

procedure TfrmOrderInPutPrice.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      MainType:=Trim(DName);
      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('PRTColorEng').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton1Click(Sender: TObject);
var
  FReal:Double;
  i,j,z:Integer;
  jstr:string;
begin
  ToolBar1.SetFocus;
  if Trim(OrderNo.Text)='' then
  begin
    Application.MessageBox('订单号不能为空!','提示',0);
    Exit;
  end;
  if CheckBox1.Checked then
  begin
    if Order_Sub.IsEmpty then
    begin
      j:=1;
    end else
    begin
      z:=Pos('#',Trim(Order_Sub.fieldbyname('Sorddefstr1').AsString));
      jstr:=Copy(Trim(Order_Sub.fieldbyname('Sorddefstr1').AsString),2,z-2);
      if Trim(jstr)<>'' then
      begin
        if TryStrToFloat(jstr,FReal)=True then
        begin
          j:=StrToInt(jstr)+1;
        end;
      end else
      begin
        j:=1;
      end;
    end;
  end;
  CopyAddRow(Tv1,Order_Sub);
  with Order_Sub do
  begin
    Edit;
    FieldByName('SubId').Value:='';
    if CheckBox1.Checked then
    begin
      FieldByName('Sorddefstr1').Value:='C'+Trim(IntToStr(j))+'#';
    end;
    Post;
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
 { with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Contract_Cloth_LLMX where OrdSubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty=False then
  begin
    Application.MessageBox('已领料不能删除数据!','提示',0);
    Exit;
  end;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Sub_AnPai 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
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from JYOrder_Main_MD where ORDSubId='''+Trim(Order_Sub.fieldbyname('SubId').AsString)+'''');
      Open;
    end;
    if ADOTemp.IsEmpty=false then
    begin
      Application.MessageBox('已经录入码单不能删除数据!','提示',0);
      Exit;
    end;
    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;
 { if Order_Sub.IsEmpty then
  begin
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Main where MainId='''+Trim(FMainId)+'''');
      ExecSQL;
    end;
  end;  }
end;

procedure TfrmOrderInPutPrice.RanFactoryBtnUpClick(Sender: TObject);
begin
  {try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='RKPlace';
      flagname:='染厂名称';    
      if ShowModal=1 then
      begin
        JGFactoryName.Text:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        JGFactoryName.TxtCode:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end; }
end;

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

procedure TfrmOrderInPutPrice.NoteDblClick(Sender: TObject);
begin
  {try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='OrdNote';
      flagname:='备注及要求';
      if ShowModal=1 then
      begin
        Note.Text:=Note.Text+frmZDYHelpSel.ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;}
end;

procedure TfrmOrderInPutPrice.v1OrderUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  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('OrderUnit').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPutPrice.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 TfrmOrderInPutPrice.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
        //flag:='OrdDefStr2';
        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').Value;
          MPRTMF.Text:=ADOTemp.fieldbyname('MPRTMF').Value;
          MPRTKZ.Text:=ADOTemp.fieldbyname('MPRTKZ').Value;
          MPRTSpec.Text:=ADOTemp.fieldbyname('MPRTSpec').Value;
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton3Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then Exit;
  ToolBar1.SetFocus;
  OneKeyPost(Tv1,Order_Sub);
end;

procedure TfrmOrderInPutPrice.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 TfrmOrderInPutPrice.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 TfrmOrderInPutPrice.ToolButton6Click(Sender: TObject);
var
  Fint:Integer;
  FReal,FMF,FKZ:Double;
begin
  {if Trim(FMainId)='' then
  begin
    Application.MessageBox('基本信息未保存!','提示',0);
    Exit;
  end;  }
  Fint:=CDS_JGLC.RecordCount;
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='JGGX';
      flagname:='加工工序';
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean=True then
            begin
              with CDS_JGLC do
              begin
                Append;
                FieldByName('PSXH').Value:=Fint+1;
                FieldByName('PSName').Value:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
                if Trim(MPRTMF.Text)<>'' then
                begin
                  if TryStrToFloat(MPRTMF.Text,FReal)=True then
                  begin
                    FieldByName('MFQty').Value:=MPRTMF.Text;
                    FMF:=StrToFloat(MPRTMF.Text);
                  end else
                  begin
                    FMF:=0;
                  end;
                end else
                begin
                  FMF:=0;
                end;
                if Trim(MPRTKZ.Text)<>'' then
                begin
                  if TryStrToFloat(MPRTKZ.Text,FReal)=True then
                  begin
                    FieldByName('KZQty').Value:=MPRTKZ.Text;
                    FKZ:=StrToFloat(MPRTKZ.Text);
                  end else
                  begin
                    FKZ:=0;
                  end;
                end else
                begin
                  FKZ:=0;
                end;
                if FMF*FKZ<>0 then
                begin
                  FieldByName('KgZM').Value:=100000*1.0000/(FMF*FKZ);
                end else
                begin
                  FieldByName('KgZM').Value:=0;
                end;
                Fint:=Fint+1;
                Post;
              end;
            end;
            Next;
          end;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton4Click(Sender: TObject);
begin
  if CDS_JGLC.IsEmpty then
  begin
    Application.MessageBox('加工流程不能为空!','提示',0);
    Exit;
  end;
  if Trim(CDS_JGLC.fieldbyname('PSID').AsString)='' then
  begin
    Application.MessageBox('信息未保存!','提示',0);
    Exit;
  end;
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        with CDS_JGC do
        begin
          Append;
          FieldByName('FactoryNo').Value:=Trim(frmGYSList.CDS_HZ.fieldbyname('ATID').AsString) ;
          FieldByName('FactoryName').Value:=Trim(frmGYSList.CDS_HZ.fieldbyname('ZdyNameZ').AsString);
          FieldByName('PFTPUnit').Value:=Trim(OneQtyUnit.Text);
          Post;
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;

end;

procedure TfrmOrderInPutPrice.ToolButton8Click(Sender: TObject);
var
  maxno:string;
begin
  {if Trim(CDS_JGLC.fieldbyname('PSID').AsString)='' then
  begin
    Application.MessageBox('信息未保存!','提示',0);
    Exit;
  end;}
  if CDS_JGC.IsEmpty then Exit;
  ToolBar1.SetFocus;
  try
    ADOCmd.Connection.BeginTrans;
    CDS_JGC.DisableControls;
    with CDS_JGC do
    begin
      First;
      while not Eof do
      begin
        if Trim(CDS_JGC.fieldbyname('PFID').AsString)='' then
        begin
          if GetLSNo(ADOCmd,maxno,'PF','JYOrder_PCS_Sub',3,1)=False then
          begin
            ADOCmd.Connection.RollbackTrans;
            CDS_JGC.EnableControls;
            Application.MessageBox('取流程加工厂流水号失败!','提示',0);
            Exit;
          end;
        end else
        begin
          maxno:=Trim(CDS_JGC.fieldbyname('PFID').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          sql.Clear;
          sql.Add('select * from JYOrder_PCS_Sub where PFID='''+Trim(CDS_JGC.fieldbyname('PFID').AsString)+'''');
          Open;
        end;
        with ADOCmd do
        begin
          if Trim(CDS_JGC.fieldbyname('PFID').AsString)='' then
          begin
            Append;
          end else
          begin
            Edit;
          end;
          FieldByName('MainID').Value:=Trim(FMainId);
          FieldByName('PSID').Value:=Trim(CDS_JGLC.fieldbyname('PSID').AsString);
          FieldByName('SubID').Value:=Trim(CDS_JGC.fieldbyname('SubID').AsString);
          FieldByName('PFID').Value:=Trim(maxno);
          FieldByName('FactoryNo').Value:=Trim(CDS_JGC.fieldbyname('FactoryNo').AsString);
          FieldByName('FactoryName').Value:=Trim(CDS_JGC.fieldbyname('FactoryName').AsString);
          FieldByName('PFDlyDate').Value:=CDS_JGC.fieldbyname('PFDlyDate').Value;
          RTSetSaveDataCDS(ADOCmd,Tv3,CDS_JGC,'JYOrder_PCS_Sub',0);
          Post;
        end;
        if Trim(CDS_JGC.fieldbyname('PFTPUnit').AsString)<>'M' then
        begin
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update JYOrder_PCS_Sub Set PFTPMQty=PFTPQty*');
            sql.Add('(select KgZM from JYOrder_Process A where A.PSID=JYOrder_PCS_Sub.PSID)');
            sql.Add(' where PFID='''+Trim(maxno)+'''');
            ExecSQL;
          end;
        end else
        begin
          with ADOCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('Update JYOrder_PCS_Sub Set PFTPMQty=PFTPQty');
            sql.Add(' where PFID='''+Trim(maxno)+'''');
            ExecSQL;
          end;
        end;
        Next;
      end;
    end;

    ADOCmd.Connection.CommitTrans;
    CDS_JGC.EnableControls;
    Application.MessageBox('操作成功!','提示',0);
    Exit;
  except
    ADOCmd.Connection.RollbackTrans;
    CDS_JGC.EnableControls;
    Application.MessageBox('操作异常!','提示',0);
    Exit;
  end;
end;

procedure TfrmOrderInPutPrice.cxGridDBColumn6PropertiesButtonClick(
  Sender: TObject; AButtonIndex: Integer);
var
  fsj:string;
begin
  fsj:=Trim(CDS_JGLC.fieldbyname('PSNote').AsString);
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='PSNote';
      flagname:='生产流程说明';
      MainType:=Trim(CDS_JGLC.fieldbyname('PSName').AsString);
      if ShowModal=1 then
      begin
        with ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            if ClientDataSet1.FieldByName('SSel').AsBoolean=True then
            begin
              fsj:=fsj+Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
            end;
            Next;
          end;
        end;
        with CDS_JGLC do
        begin
          Edit;
          FieldByName('PSNote').Value:=Trim(fsj);
          //Post;
        end;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
end;

procedure TfrmOrderInPutPrice.CustomerNoNameBtnClick(Sender: TObject);
begin
  try
    frmZdyAttachment:=TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal=1 then
      begin
        CustomerNoName.Text:=Trim(frmZdyAttachment.CDS_HZ.fieldbyname('zdyNameZ').AsString);
        CustomerNoName.TxtCode:=Trim(frmZdyAttachment.CDS_HZ.fieldbyname('ATID').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmOrderInPutPrice.MPRTCodeBtnClick(Sender: TObject);
var
  fsj:string;
begin
  try
    frmCPManageTPCX:=TfrmCPManageTPCX.Create(Application);
    with frmCPManageTPCX do
    begin
      if ShowModal=1 then
      begin
        MPRTCode.Text:=Trim(frmCPManageTPCX.CDS_Main.fieldbyname('CYNO').AsString);
        MPRTCodeName.Text:=Trim(frmCPManageTPCX.CDS_Main.fieldbyname('CYName').AsString);
        MPRTSpec.Text:=Trim(frmCPManageTPCX.CDS_Main.fieldbyname('CYSpec').AsString);
        MPRTCF.Text:=Trim(frmCPManageTPCX.CDS_Main.fieldbyname('CYCF').AsString);
        MPRTMF.Text:=Trim(frmCPManageTPCX.CDS_Main.fieldbyname('CYMF').AsString);
        MPRTKZ.Text:=Trim(frmCPManageTPCX.CDS_Main.fieldbyname('CYKZ').AsString);
      end;
    end;
  finally
    frmCPManageTPCX.Free;
  end;
  if Trim(MPRTMF.Text)<>'' then
  begin
    MPRTMF.Text:=Copy(Trim(MPRTMF.Text),1,Pos('c',Trim(MPRTMF.Text))-1);
  end;
  if Trim(MPRTKZ.Text)<>'' then
  begin
    MPRTKZ.Text:=Copy(Trim(MPRTKZ.Text),1,Pos('g',Trim(MPRTKZ.Text))-1);
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton7Click(Sender: TObject);
begin
  if CDS_JGC.IsEmpty=False then
  begin
    Application.MessageBox('已安排不能删除数据!','提示',0);
    Exit;
  end;
  with ADOTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from JYOrder_Main_MD where PSID='''+Trim(CDS_JGLC.fieldbyname('PSID').AsString)+'''');
    Open;
  end;
  if ADOTemp.IsEmpty=False then
  begin
    Application.MessageBox('已录入码单，不能删除数据!','提示',0);
    Exit;
  end;
  if Trim(CDS_JGLC.fieldbyname('PSId').AsString)<>'' then
  begin
    if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete JYOrder_Process where PSId='''+Trim(CDS_JGLC.fieldbyname('PSId').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_JGLC.Delete;
end;

procedure TfrmOrderInPutPrice.Tv2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.*,B.PRTHX,PRTColor ');
    sql.Add(',B.PRTOrderQty,B.OrderUnit from JYOrder_PCS_Sub A');
    sql.Add(' left join JYOrder_Sub B on A.SubId=B.SubId');
    sql.Add('where A.PSID='''+Trim(CDS_JGLC.fieldbyname('PSID').AsString)+'''');
    SQL.Add(' and isnull(A.CKName,'''')<>''调节仓库'' ');
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_JGC);
  SInitCDSData20(ADOQuery1,CDS_JGC);
end;

procedure TfrmOrderInPutPrice.ToolButton10Click(Sender: TObject);
var
  i:Integer;
  FName:String;
begin
  if CDS_JGLC.IsEmpty then
  begin
    Application.MessageBox('加工流程不能为空!','提示',0);
    Exit;
  end;
  if Trim(CDS_JGLC.fieldbyname('PSID').AsString)='' then
  begin
    Application.MessageBox('信息未保存!','提示',0);
    Exit;
  end;
  if CDS_JGC.IsEmpty then
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,B.PRTHX,PRTColor ');
      sql.Add(',B.PRTOrderQty,B.OrderUnit from JYOrder_PCS_Sub A');
      sql.Add(' left join JYOrder_Sub B on A.SubId=B.SubId');
      sql.Add('where A.PSID='''+Trim(CDS_JGLC.fieldbyname('PSID').AsString)+'''');
      SQL.Add(' and isnull(A.CKName,'''')<>''调节仓库'' ');
      Open;
    end;
    SCreateCDS20(ADOQuery1,CDS_JGC);
    SInitCDSData20(ADOQuery1,CDS_JGC);
  end;
  try
    frmOrderSubSel:=TfrmOrderSubSel.Create(Application);
    with frmOrderSubSel do
    begin
      FFFMainId:=Trim(Self.FMainId);
      if ShowModal=1 then
      begin
        ClientDataSet1.DisableControls;
        with frmOrderSubSel.ClientDataSet1 do
        begin
          First;
          while not Eof do
          begin
            Self.CDS_JGC.Append;
            Self.CDS_JGC.FieldByName('SubId').Value:=frmOrderSubSel.ClientDataSet1.FieldByName('SubId').Value;
            for i:=0 to frmOrderSubSel.Tv3.ColumnCount-1 do
            begin
              FName:=frmOrderSubSel.Tv3.Columns[i].DataBinding.FilterFieldName;
              if Trim(FName)<>'' then
              begin

                Self.CDS_JGC.FieldByName(FName).Value:=frmOrderSubSel.ClientDataSet1.FieldByName(FName).Value;
              end;


            end;
            Self.CDS_JGC.FieldByName('FactoryNo').Value:=frmOrderSubSel.ClientDataSet1.FieldByName('FactoryNo').Value;
            Self.CDS_JGC.Post;
            Next;
          end;
        end;
        ClientDataSet1.EnableControls;
      end;
    end;
  finally
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton11Click(Sender: TObject);
begin
  if CDS_JGC.IsEmpty then Exit;
  ToolBar1.SetFocus;
  OneKeyPost(Tv3,CDS_JGC);
end;

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

procedure TfrmOrderInPutPrice.v2Column2PropertiesEditValueChanged(
  Sender: TObject);
var
  mvalue,FName,FMF,FKZ:string;
begin
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  FName:=Trim(Tv2.Controller.FocusedColumn.DataBinding.FilterFieldName);
  with CDS_JGLC do
  begin
    Edit;
    FieldByName(FName).Value:=Trim(mvalue);
    Post;
  end;
  FMF:=Trim(CDS_JGLC.fieldbyname('MFQty').AsString);
  FKZ:=Trim(CDS_JGLC.fieldbyname('KZQty').AsString);
  if Trim(FMF)='' then Exit;
  if Trim(FKZ)='' then Exit;
  if StrToFloat(FMF)=0 then Exit;
  if StrToFloat(FKZ)=0 then Exit;
  with CDS_JGLC do
  begin
    Edit;
    FieldByName('KgZM').Value:=100000*1.0000/(StrToFloat(FMF)*StrToFloat(FKZ));
    Post;
  end;
end;

procedure TfrmOrderInPutPrice.Tv5CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var
  PFID,FPFID,Fsj:String;
begin
  {if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(ClientDataSet5.fieldbyname('PFID').AsString)<>'' then
    begin
      Tv5.OptionsSelection.CellSelect:=False;
    end else
    begin
      Tv5.OptionsSelection.CellSelect:=True;
    end;
  end; }



end;

procedure TfrmOrderInPutPrice.FormCreate(Sender: TObject);
begin
  CanShu1:=Trim(DParameters1);
  CanShu2:=Trim(DParameters2);
  if Trim(CanShu2)='仓库' then
  begin
    TBSave.Visible:=false;
    //ToolBar2.Visible:=False;
    ToolButton1.Visible:=False;
    ToolButton2.Visible:=False;
    ToolButton3.Visible:=False;
    Panel4.Visible:=False;
    ToolBar3.Visible:=False;
    ToolBar4.Visible:=False;
  end;
end;

procedure TfrmOrderInPutPrice.Tv6CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  {if Trim(CanShu1)<>'高权限' then
  begin
    if Trim(ClientDataSet6.fieldbyname('CKID').AsString)<>'' then
    begin
      Tv6.OptionsSelection.CellSelect:=False;
    end;
  end; }
end;

procedure TfrmOrderInPutPrice.SYRNameBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='GSTTHT';
      flagname:='公司抬头';
      V1ZdyStr1.Visible:=True;
      V1ZdyStr2.Visible:=True;
      V1ZdyStr3.Visible:=True;
      V1ZdyStr4.Visible:=True;
      V1ZdyStr1.Caption:='简称';
      V1ZdyStr2.Caption:='电话';
      V1ZdyStr3.Caption:='传真';
      V1ZdyStr4.Caption:='地址';
      frmZDYHelp.Align:=alClient;
      if ShowModal=1 then
      begin
        SYRName.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPutPrice.LiDanPersonBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='LiDanPerson';
      flagname:='理单员';
      fnote:=True;
      V1Note.Caption:='电话';
      if ShowModal=1 then
      begin
        LiDanPerson.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPutPrice.v3Column1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='PFGenDanPerson';
      flagname:='跟单员';
      fnote:=True;
      V1Note.Caption:='电话';
      if ShowModal=1 then
      begin
        with CDS_JGC do
        begin
          Edit;
          FieldByName('PFGenDanPerson').Value:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
        end;
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton13Click(Sender: TObject);
begin
  try
    frmModuleNote:=TfrmModuleNote.Create(Application);
    with frmModuleNote do
    begin
      flag:='生产指示单';
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmModuleNote.Free;
  end;
end;

procedure TfrmOrderInPutPrice.v3Column2PropertiesEditValueChanged(
  Sender: TObject);
var
  FReal:Double;
  mvalue:string;
begin
  if Trim(ClothOneQty.Text)<>'' then
  begin
    if TryStrToFloat(Trim(ClothOneQty.Text),FReal)=False then
    begin
      Application.MessageBox('白坯每匹数量非法数字!','提示',0);
      Exit;
    end;
  end;
  mvalue:=TcxTextEdit(Sender).EditingText;
  if Trim(mvalue)='' then
  begin
    mvalue:='0';
  end;
  with CDS_JGC do
  begin
    Edit;
    FieldByName('PFTPPS').Value:=mvalue;
    FieldByName('PFTPQty').Value:=StrToFloat(mvalue)*StrToFloat(ClothOneQty.Text);
    Post;
  end;
end;

procedure TfrmOrderInPutPrice.ToolButton18Click(Sender: TObject);
begin
  if Application.MessageBox('确定要重新连接吗？','提示',32+4)<>IDYES then Exit;
  if not Assigned(DataLink_OrderAndGD) then
     DataLink_OrderAndGD:=TDataLink_OrderAndGD.Create(Application);
  Try
    with DataLink_OrderAndGD.ADOLink do
    begin
      //if not Connected then
      begin
        Connected:=false;
        ConnectionString:=DConString;
        LoginPrompt:=false;
        Connected:=true;
      end;
    end;
  Except
    application.MessageBox('数据库连接失败！','错误',mb_Ok+ MB_ICONERROR);
  end;
  with ADOCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate  SY_MaxBH Set BHNo=BHNo+1 where BHType=''JYOrder_Sub'' ');
    sql.Add('UPdate  SY_MaxBH Set BHNo=BHNo+1 where BHType=''JYOrder_Main'' ');
    ExecSQL;
  end;
end;

procedure TfrmOrderInPutPrice.V3GYSPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmGYSList:=TfrmGYSList.Create(Application);
    with frmGYSList do
    begin
      if ShowModal=1 then
      begin
        with CDS_JGC do
        begin
          edit;
          FieldByName('FactoryNo').Value:=Trim(frmGYSList.CDS_HZ.fieldbyname('ATID').AsString) ;
          FieldByName('FactoryName').Value:=Trim(frmGYSList.CDS_HZ.fieldbyname('ZdyNameZ').AsString);
          //Post;
        end;
      end;
    end;
  finally
    frmGYSList.Free;
  end;
end;

end.
