unit U_CPFHSQInPut;

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,
  cxDropDownEdit, cxGridCustomPopupMenu, cxGridPopupMenu, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmPBFHSQInPut = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    ToolBar2: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxgrdSQPS: TcxGridDBColumn;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    v1Column14: TcxGridDBColumn;
    cxGridPopupMenu2: TcxGridPopupMenu;
    Label1: TLabel;
    Note: TEdit;
    Label12: TLabel;
    Label11: TLabel;
    SHDanWei: TBtnEditC;
    Label13: TLabel;
    FHTaiTou: TBtnEditC;
    Label17: TLabel;
    TruckId: TEdit;
    v1Column6: TcxGridDBColumn;
    Label2: TLabel;
    SQDate: TDateTimePicker;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    Label3: TLabel;
    Note1: TEdit;
    Label4: TLabel;
    DBtype: TComboBox;
    ToolButton3: TToolButton;
    YWY: TBtnEditC;
    v1Column3: TcxGridDBColumn;
    Note3: TMemo;
    Label5: TLabel;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    Label6: TLabel;
    ZGDate: TDateTimePicker;
    v1Column9: TcxGridDBColumn;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    Label7: TLabel;
    SQXS: TEdit;
    Label8: TLabel;
    FHYWY: TBtnEditA;
    CRType: TBtnEditA;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure SHDanWeiBtnUpClick(Sender: TObject);
    procedure SHDanWeiBtnDnClick(Sender: TObject);
    procedure FHTaiTouBtnDnClick(Sender: TObject);
    procedure FHTaiTouBtnUpClick(Sender: TObject);
    procedure ShouKuanKeyPress(Sender: TObject; var Key: Char);
    procedure v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure SalesmanBtnDnClick(Sender: TObject);
    procedure OrderNoBtnUpClick(Sender: TObject);
    procedure Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure YWYBtnUpClick(Sender: TObject);
    procedure v1Column7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure v1Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton5Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure FHYWYBtnClick(Sender: TObject);
    procedure CRTypeBtnClick(Sender: TObject);
  private
    fuserName: string;
    procedure InitData();
    procedure ZDYHelp(FButn: TcxButtonEdit; LType: string);
    function SaveData(): Boolean;
    procedure GetKCSel(MKCStatus: string);
    { Private declarations }
  public
    PState, CopyInt: Integer;
    FMainId, FFMainId, ChkStr, ConPriceStr: string;
    FXS: Integer;
    FClothType: string; 
    { Public declarations }
  end;

var
  frmPBFHSQInPut: TfrmPBFHSQInPut;
  newh: hwnd;

implementation

uses
  U_DataLink, U_ZDYHelp, U_RTFun, U_SQKCHZSelList, U_ZdyAttachGYS,
  U_ZdyAttachment, U_SQKCHZMXSel, U_ProductOrderListSel, U_DJBKKListSel;

{$R *.dfm}
procedure TfrmPBFHSQInPut.GetKCSel(MKCStatus: string);
var
  FSelType, FConNo, FMPRTCodeName, FPRTColor, FgangNo, FMJID: string;
  FEFalg, FPiQty, FMJXH: Integer;
begin

  try
    frmSQKCHZSelList := TfrmSQKCHZSelList.Create(Application);
    with frmSQKCHZSelList do
    begin
      FKCStatus := MKCStatus;
      FYWY := YWY.Text;
      if ShowModal = 1 then
      begin
        while frmSQKCHZSelList.CDS_Main.Locate('SSel', true, []) do
        begin
          FEFalg := 0;
          FSelType := Trim(frmSQKCHZSelList.CDS_Main.fieldbyname('SelType').AsString);
          FConNo := Trim(frmSQKCHZSelList.CDS_Main.fieldbyname('ConNo').AsString);
          FMPRTCodeName := Trim(frmSQKCHZSelList.CDS_Main.fieldbyname('MPRTCodeName').AsString);
          FPRTColor := Trim(frmSQKCHZSelList.CDS_Main.fieldbyname('PRTColor').AsString);
          FgangNo := Trim(frmSQKCHZSelList.CDS_Main.fieldbyname('gangNo').AsString);
          FPiQty := frmSQKCHZSelList.CDS_Main.fieldbyname('PiQty').AsInteger;
          FMJID := Trim(frmSQKCHZSelList.CDS_Main.fieldbyname('MJID').AsString);
          FMJXH := frmSQKCHZSelList.CDS_Main.fieldbyname('MJXH').AsInteger;
          if FSelType = '品名' then
          begin
            if Self.Order_Sub.Locate('PRTCodeName', FMPRTCodeName, []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '订单' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName', VarArrayOf([FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '颜色' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName;PRTColor', VarArrayOf([FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '缸号' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor', VarArrayOf(['颜色', FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName;PRTColor;ganghao', VarArrayOf([FConNo, FMPRTCodeName, FPRTColor, FgangNo]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '明细' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor', VarArrayOf(['颜色', FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor;ganghao', VarArrayOf(['缸号', FConNo, FMPRTCodeName, FPRTColor, FgangNo]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;MJID', VarArrayOf(['明细', FMJID]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FEFalg = 0 then
          begin
            with Self.Order_Sub do
            begin
              Append;
              FieldByName('SelType').Value := FSelType;
              FieldByName('SCConNo').Value := FConNo;
              FieldByName('PrtCodeName').Value := FMPRTCodeName;
              FieldByName('PRTColor').Value := FPRTColor;
              FieldByName('ganghao').Value := FgangNo;
              FieldByName('SQPS').Value := FPiQty;
              FieldByName('MJXH').Value := FMJXH;
              FieldByName('MJID').Value := FMJID;
              FieldByName('SSYWY').Value := self.YWY.Text;
              Post;
            end;
          end;

          frmSQKCHZSelList.CDS_Main.Delete;
        end;
      end;
    end;
  finally
    frmSQKCHZSelList.Free;
  end;
end;

procedure TfrmPBFHSQInPut.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('发货申请录入', Tv1, '发货管理');
end;

procedure TfrmPBFHSQInPut.InitData();
var
  fsj: string;
begin
//  fsj := 'select Name=ZdyName from KH_Zdy where Type=''ClothType'' ';
//  SInitComBoxBySql(ADOTemp, ClothType, False, fsj);
  if PState = 0 then
  begin
//    Salesman.Text := dname;
    SQDate.DateTime := SGetServerDate10(ADOTemp);
    ZGDate.DateTime := SQDate.DateTime;
  end;
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select A.*  ');
    sql.Add(' from FHSQ_Sub_CP A');
    if PState = 1 then
    begin
      sql.Add('where FSId=''' + Trim(FMainId) + '''');
    end;
    if PState = 0 then
    begin
      sql.Add(' where 1<>1');

    end;
    Open;
  end;
  SCreateCDS20(ADOQuery1, Order_Sub);
  SInitCDSData20(ADOQuery1, Order_Sub);

  with ADOQuery1 do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* ');
    sql.Add(' from FHSQ_Main_CP A');
    sql.Add(' where FSId=''' + Trim(FMainId) + ''' ');
    Open;
  end;
  SCSHDataNew(ADOQuery1, ScrollBox1, 1);
end;

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

procedure TfrmPBFHSQInPut.FormShow(Sender: TObject);
begin
  readCxGrid('发货申请录入', Tv1, '发货管理');
  InitData();
end;

function TfrmPBFHSQInPut.SaveData(): Boolean;
var
  maxno, maxmnno, FSSId: string;
  fconNO, fmxType: string;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId) = '' then
    begin
      if GetLSNo(ADOCmd, maxno, 'FC', 'FHSQ_Main_CP', 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 FHSQ_Main_CP where FSID=''' + Trim(FMainId) + '''');
      Open;
    end;
    with ADOCmd do
    begin
      if Trim(FMainId) = '' then
      begin
        Append;
      end
      else
      begin
        Edit;
      end;
      FieldByName('SQType').Value := '成品布';
      FieldByName('FSID').Value := Trim(maxno);
      RTSetsavedata(ADOCmd, 'FHSQ_Main_CP', ScrollBox1, 1);

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

    FMainId := Trim(maxno);
    ///保存子表
    Order_Sub.DisableControls;
    with Order_Sub do
    begin
      First;
      while not Eof do
      begin
        if Trim(Order_Sub.fieldbyname('SSId').AsString) = '' then
        begin
          if GetLSNo(ADOCmd, maxno, 'SS', 'FHSQ_Sub_CP', 4, 1) = False then
          begin
            Order_Sub.EnableControls;
            ADOCmd.Connection.RollbackTrans;
            Application.MessageBox('取子流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxno := Trim(Order_Sub.fieldbyname('SSId').AsString);
        end;
        with ADOCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from FHSQ_Sub_CP ');
          sql.Add(' where SSId=''' + Trim(maxno) + '''');
          Open;
        end;
        if ADOCmd.IsEmpty then
        begin
          FSSId := '';
        end
        else
        begin
          FSSId := Trim(maxno);
        end;
        with ADOCmd do
        begin
          if Trim(FSSId) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp);
          end;
          FieldByName('FSID').Value := Trim(FMainId);
          FieldByName('SSID').Value := Trim(maxno);
          RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'FHSQ_Sub_CP', 0);
          FieldByName('MainId').Value := Order_Sub.fieldbyname('MainId').Value;
          FieldByName('SubId').Value := Order_Sub.fieldbyname('SubId').Value;
          FieldByName('SSConMainId').Value := Order_Sub.fieldbyname('SSConMainId').Value;
          FieldByName('SSConSubId').Value := Order_Sub.fieldbyname('SSConSubId').Value;
          Post;
        end;
        Order_Sub.Edit;
        Order_Sub.FieldByName('SSID').Value := Trim(maxno);
        Next;
      end;
    end;
    Order_Sub.EnableControls;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update FHSQ_Main_CP Set ');
      sql.Add('SQPSHZ=(select Sum(SQPS) from FHSQ_Sub_CP A where A.FSID=FHSQ_Main_CP.FSID)');
      sql.Add('where FSID=''' + Trim(FMainId) + '''');
      ExecSQL;
    end;
    ADOCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！', '提示', 0);
    Result := False;
  end;
end;

procedure TfrmPBFHSQInPut.TBSaveClick(Sender: TObject);
var
  Freal: Double;
begin
  ToolBar1.SetFocus;

  if Trim(DBtype.Text) = '' then
  begin
    Application.MessageBox('打包类型不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(CRType.Text) = '' then
  begin
    Application.MessageBox('出库类型不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(SHDanWei.Text) = '' then
  begin
    Application.MessageBox('收获单位不能为空！', '提示', 0);
    Exit;
  end;
  if Trim(FHYWY.Text) = '' then
  begin
    Application.MessageBox('业务员不能为空！', '提示', 0);
    Exit;
  end;

  if Order_Sub.IsEmpty then
  begin
    Application.MessageBox('明细不能为空！', '提示', 0);
    Exit;
  end;
//  if Order_Sub.Locate('SCConNo', null, []) = True then
//  begin
//    Application.MessageBox('白坯单号不能为空！', '提示', 0);
//    Exit;
//  end;
  if Order_Sub.Locate('SQPS', null, []) = True then
  begin
    Application.MessageBox('申请匹数不能为空！', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
  end;
end;

procedure TfrmPBFHSQInPut.ToolButton1Click(Sender: TObject);
begin
  GetKCSel('已开卡');
end;

procedure TfrmPBFHSQInPut.ToolButton2Click(Sender: TObject);
begin
  if Order_Sub.IsEmpty then
    Exit;
  if Trim(Order_Sub.fieldbyname('SSId').AsString) <> '' then
  begin
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from FHSQ_Sub_CP where SSId=''' + Trim(Order_Sub.fieldbyname('SSId').AsString) + '''');
      sql.add(' and isnull(FHPS,0)>0');
      Open;
    end;
    if ADOTemp.IsEmpty = False then
    begin
      Application.MessageBox('已发货不能删除数据!', '提示', 0);
      exit;
    end;
    with ADOTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from FHSQ_Sub_CP where SSId=''' + Trim(Order_Sub.fieldbyname('SSId').AsString) + '''');
      sql.add(' and isnull(DBPS,0)>0');
//      ShowMessage(SQL.Text);
      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 FHSQ_Sub_CP where SSId=''' + Trim(Order_Sub.fieldbyname('SSId').AsString) + '''');
      ExecSQL;
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('Update FHSQ_Main_CP Set ');
      sql.Add('SQPSHZ=(select Sum(SQPS) from FHSQ_Sub_CP A where A.FSID=FHSQ_Main_CP.FSID)');
      sql.Add('where FSID=''' + Trim(FMainId) + '''');
      ExecSQL;
    end;
  end;
  Order_Sub.Delete;
end;

procedure TfrmPBFHSQInPut.SHDanWeiBtnUpClick(Sender: TObject);
begin
//  try
//    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
//    with frmZdyAttachGYS do
//    begin
//
//      if ShowModal = 1 then
//      begin
//        SHDanWei.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
//      end;
//    end;
//  finally
//    frmZdyAttachGYS.Free;
//  end;
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin

      if ShowModal = 1 then
      begin
        Self.SHDanWei.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);
        Self.YWY.Text := Trim(CDS_HZ.fieldbyname('Salesman').AsString);
        Self.FHYWY.Text:= Trim(CDS_HZ.fieldbyname('Salesman').AsString);
      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;

end;

procedure TfrmPBFHSQInPut.SHDanWeiBtnDnClick(Sender: TObject);
begin
  SHDanWei.Text := '';
end;

procedure TfrmPBFHSQInPut.FHTaiTouBtnDnClick(Sender: TObject);
begin
  FHTaiTou.Text := '';
end;

procedure TfrmPBFHSQInPut.FHTaiTouBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'FHTaiTou';
      flagname := '发货抬头';
      if ShowModal = 1 then
      begin
        Self.FHTaiTou.Text := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmPBFHSQInPut.ShouKuanKeyPress(Sender: TObject; var Key: Char);
begin
  if not (((Key >= '0') and (Key <= '9')) or (Key = '.') or (Key = #8)) then
  begin
    Key := #0;
  end
  else if (pos('.', TEdit(Sender).text) <> 0) then
  begin
    if Key = '.' then
    begin
      Key := #0;
    end;
  end;
end;

procedure TfrmPBFHSQInPut.v1Column3PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
//  try
//    frmCPManageFMSel:=TfrmCPManageFMSel.Create(Application);
//    with frmCPManageFMSel do
//    begin
//      if ShowModal=1 then
//      begin
//        Self.PrtCodeName.Text:=Trim(frmCPManageFMSel.CDS_Main.fieldbyname('CYName').AsString);
//        Self.PrtCode.Text:=Trim(frmCPManageFMSel.CDS_Main.fieldbyname('CYNo').AsString);
////        Self.C_Spec.Text:=Trim(frmCPManageFMSel.CDS_Main.fieldbyname('CYSpec').AsString);
//      end;
//    end;
//  finally
//    frmCPManageFMSel.Free;
//  end;
end;

procedure TfrmPBFHSQInPut.SalesmanBtnDnClick(Sender: TObject);
begin
  YWY.Text := '';
end;

procedure TfrmPBFHSQInPut.OrderNoBtnUpClick(Sender: TObject);
begin
//  try
//    frmClothSCListSel := TfrmClothSCListSel.Create(Application);
//    with frmClothSCListSel do
//    begin
//      if ShowModal = 1 then
//      begin
//        self.OrderNo.Text := trim(Order_Main.FieldByName('OrderNo').AsString);
//        self.SHDanWei.Text := trim(Order_Main.FieldByName('JGFactoryName').AsString);
//        self.Salesman.Text := trim(Order_Main.FieldByName('YWY').AsString);
//      end;
//    end;
//  finally
//    frmClothSCListSel.Free;
//  end;
end;

procedure TfrmPBFHSQInPut.Tv1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Trim(Order_Sub.FieldByName('SelType').AsString) = '卷' then
    cxgrdSQPS.Options.Editing := false
  else
    cxgrdSQPS.Options.Editing := true;
end;

procedure TfrmPBFHSQInPut.ToolButton3Click(Sender: TObject);
begin

  GetKCSel('已打卷');

end;

procedure TfrmPBFHSQInPut.YWYBtnUpClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'Salesman';
      flagname := '业务员';
      if ShowModal = 1 then
      begin
        Self.YWY.Text := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

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

procedure TfrmPBFHSQInPut.v1Column8PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        with Self.Order_Sub do
        begin
          edit;
//          FieldByName('FactoryNo').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('COCode').AsString);
          FieldByName('RSFactoryName').Value := Trim(frmZdyAttachGYS.CDS_HZ.fieldbyname('COName').AsString);

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

procedure TfrmPBFHSQInPut.ToolButton5Click(Sender: TObject);
var
  FSelType, FConNo, FMPRTCodeName, FPRTColor, FgangNo, FMJID, FYWY: string;
  FEFalg, FPiQty, FMJXH: Integer;
begin

  try
    frmProductOrderListSel := TfrmProductOrderListSel.Create(Application);
    with frmProductOrderListSel do
    begin
      if ShowModal = 1 then
      begin
        while frmProductOrderListSel.CDS_Main.Locate('SSel', true, []) do
        begin
          FEFalg := 0;
          FSelType := '订单';
          FConNo := Trim(frmProductOrderListSel.CDS_Main.fieldbyname('ConNo').AsString);
          FMPRTCodeName := Trim(frmProductOrderListSel.CDS_Main.fieldbyname('MPRTCodeName').AsString);
          FPRTColor := '';
          FYWY := Trim(frmProductOrderListSel.CDS_Main.fieldbyname('YWY').AsString);
          FgangNo := '';
          FPiQty := 0;
          FMJID := '';
          FMJXH := 0;
          if FSelType = '品名' then
          begin
            if Self.Order_Sub.Locate('PRTCodeName', FMPRTCodeName, []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '订单' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName', VarArrayOf([FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '颜色' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName;PRTColor', VarArrayOf([FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '缸号' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor', VarArrayOf(['颜色', FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName;PRTColor;ganghao', VarArrayOf([FConNo, FMPRTCodeName, FPRTColor, FgangNo]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '明细' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor', VarArrayOf(['颜色', FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor;ganghao', VarArrayOf(['缸号', FConNo, FMPRTCodeName, FPRTColor, FgangNo]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;MJID', VarArrayOf(['明细', FMJID]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FEFalg = 0 then
          begin
            with Self.Order_Sub do
            begin
              Append;
              FieldByName('SelType').Value := FSelType;
              FieldByName('SCConNo').Value := FConNo;
              FieldByName('PrtCodeName').Value := FMPRTCodeName;
              FieldByName('PRTColor').Value := FPRTColor;
              FieldByName('ganghao').Value := FgangNo;
              FieldByName('SQPS').Value := FPiQty;
              FieldByName('MJXH').Value := FMJXH;
              FieldByName('MJID').Value := FMJID;
              FieldByName('SSYWY').Value := FYWY;
              Post;
            end;
          end;

          frmProductOrderListSel.CDS_Main.Delete;
        end;
      end;
    end;
  finally
    frmProductOrderListSel.Free;
  end;

end;

procedure TfrmPBFHSQInPut.ToolButton6Click(Sender: TObject);
var
  FSelType, FConNo, FMPRTCodeName, FPRTColor, FgangNo, FMJID, FYWY: string;
  FEFalg, FPiQty, FMJXH: Integer;
begin

  try
    frmDJBKKListSel := TfrmDJBKKListSel.Create(Application);
    with frmDJBKKListSel do
    begin
      YWY.Text := DName;
      if ShowModal = 1 then
      begin
        while frmDJBKKListSel.CDS_Main.Locate('SSel', true, []) do
        begin
          FEFalg := 0;
          FSelType := '颜色';
          FYWY := Trim(frmDJBKKListSel.CDS_Main.fieldbyname('YWY').AsString);
          FConNo := Trim(frmDJBKKListSel.CDS_Main.fieldbyname('ConNo').AsString);
          FMPRTCodeName := Trim(frmDJBKKListSel.CDS_Main.fieldbyname('SPName').AsString);
          FPRTColor := Trim(frmDJBKKListSel.CDS_Main.fieldbyname('SPColor').AsString);
          FgangNo := '';
          FPiQty := 0;
          FMJID := '';
          FMJXH := 0;
          if FSelType = '品名' then
          begin
            if Self.Order_Sub.Locate('PRTCodeName', FMPRTCodeName, []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '订单' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName', VarArrayOf([FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '颜色' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName;PRTColor', VarArrayOf([FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '缸号' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor', VarArrayOf(['颜色', FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SCConNo;PRTCodeName;PRTColor;ganghao', VarArrayOf([FConNo, FMPRTCodeName, FPRTColor, FgangNo]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FSelType = '明细' then
          begin
            if Self.Order_Sub.Locate('SelType;PRTCodeName', VarArrayOf(['品名', FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName', VarArrayOf(['订单', FConNo, FMPRTCodeName]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor', VarArrayOf(['颜色', FConNo, FMPRTCodeName, FPRTColor]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;SCConNo;PRTCodeName;PRTColor;ganghao', VarArrayOf(['缸号', FConNo, FMPRTCodeName, FPRTColor, FgangNo]), []) then
              FEFalg := FEFalg - 1;

            if Self.Order_Sub.Locate('SelType;MJID', VarArrayOf(['明细', FMJID]), []) then
              FEFalg := FEFalg - 1;
          end;
          if FEFalg = 0 then
          begin
            with Self.Order_Sub do
            begin
              Append;
              FieldByName('SelType').Value := FSelType;
              FieldByName('SCConNo').Value := FConNo;
              FieldByName('PrtCodeName').Value := FMPRTCodeName;
              FieldByName('PRTColor').Value := FPRTColor;
              FieldByName('ganghao').Value := FgangNo;
              FieldByName('SQPS').Value := FPiQty;
              FieldByName('MJXH').Value := FMJXH;
              FieldByName('MJID').Value := FMJID;
              FieldByName('SSYWY').Value := FYWY;
              Post;
            end;
          end;

          frmDJBKKListSel.CDS_Main.Delete;
        end;
      end;
    end;
  finally
    frmDJBKKListSel.Free;
  end;

end;

procedure TfrmPBFHSQInPut.FHYWYBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      ViewFlag:=True;
      flag:='YWY';
      flagname:='业务员';
      if ShowModal=1 then
      begin
        FHYWY.Text:=Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmPBFHSQInPut.CRTypeBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='CPCRType';
      flagname:='出库类型';
      if ShowModal=1 then
      begin
        Self.CRType.Text:=Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

end.

