unit U_PBOuGLtListMX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, RM_Common, RM_Class, RM_e_Xls, RM_Dataset, RM_System,
  RM_GridReport, cxCheckBox, Menus, MovePanel, BtnEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, cxContainer, cxTextEdit, cxMaskEdit,
  cxButtonEdit, dxSkinsCore, dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmPBOuGLtListMX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label1: TLabel;
    Label2: TLabel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    CDS_Main: TClientDataSet;
    Label7: TLabel;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    RMDBMain: TRMDBDataSet;
    RMXLSExport1: TRMXLSExport;
    Label10: TLabel;
    CkOrdNo: TEdit;
    RMDBHZ: TRMDBDataSet;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    MovePanel2: TMovePanel;
    CDS_CX: TClientDataSet;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Sel: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    C_CodeName: TEdit;
    C_Color: TEdit;
    ConNo: TEdit;
    MJID: TEdit;
    Label8: TLabel;
    CRType: TComboBox;
    CDS_DH: TClientDataSet;
    ADOQueryDH: TADOQuery;
    ADOQueryPrint: TADOQuery;
    Label11: TLabel;
    newcarno: TEdit;
    CPType: TEdit;
    v1Column4: TcxGridDBColumn;
    Label12: TLabel;
    C_Code: TEdit;
    v1Column14: TcxGridDBColumn;
    Label14: TLabel;
    KHName1: TEdit;
    CDS_Juan: TClientDataSet;
    CDS_JuanPRT: TClientDataSet;
    RMDBMX: TRMDBDataSet;
    v1Column7: TcxGridDBColumn;
    Label15: TLabel;
    CheJian: TComboBox;
    v1Column10: TcxGridDBColumn;
    cxgrdbclmnv1Column12: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    Label9: TLabel;
    CarNo: TEdit;
    v1Column15: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    ToolButton1: TToolButton;
    Panel2: TPanel;
    Label16: TLabel;
    Button2: TButton;
    Button3: TButton;
    Label13: TLabel;
    Edit2: TEdit;
    Button4: TButton;
    Label17: TLabel;
    Edit3: TEdit;
    Button5: TButton;
    Label18: TLabel;
    Button6: TButton;
    Label19: TLabel;
    Button7: TButton;
    Label20: TLabel;
    Edit6: TEdit;
    Button8: TButton;
    Label21: TLabel;
    Button9: TButton;
    ComboBox1: TComboBox;
    KHPM: TBtnEditA;
    KHNAME: TcxButtonEdit;
    cpname: TcxButtonEdit;
    Tv1Column9: TcxGridDBColumn;
    Label22: TLabel;
    Button1: TButton;
    Edit1: TEdit;
    Tv1Column10: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Label23: TLabel;
    Edit4: TEdit;
    Button10: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MPRTCodeNameChange(Sender: TObject);
    procedure orderNoChange(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBCKCXClick(Sender: TObject);
    procedure C_CodeNameChange(Sender: TObject);
    procedure ConNoKeyPress(Sender: TObject; var Key: Char);
    procedure CheJianChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure KHPMBtnClick(Sender: TObject);
    procedure KHNAMEPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure cpnamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure Button2Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);

  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmPBOuGLtListMX: TfrmPBOuGLtListMX;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_ZdyAttachment, U_CPManageFMSel;

{$R *.dfm}

procedure TfrmPBOuGLtListMX.FormDestroy(Sender: TObject);
begin
  frmPBOuGLtListMX := nil;
end;

procedure TfrmPBOuGLtListMX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmPBOuGLtListMX.FormCreate(Sender: TObject);
begin
  //cxGrid1.Align:=alClient;
  BegDate.DateTime := SGetServerDateTime(ADOQueryTemp) - 30;
  EndDate.DateTime := SGetServerDateTime(ADOQueryTemp)
end;

procedure TfrmPBOuGLtListMX.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('select A.*, pici,D.carno,D.cpprice,newbatchno,fhkongjia,newname,khpm,newcarno,B.KHNAME AS KHNAME1,B.ConNo,B.khconno,C.C_CodeName,C.C_Code,C.C_Color,C.gongyi,D.APXH,D.CheJian,C.BatchNoHZ,D.APBatchNo ');
      SQL.Add('	,KHName2=(case when  isnull(a.KHName,'''')='''' then e.CustomerNoName else a.khname end )');
      SQL.Add(',shouhuotaitou2=(case when  isnull(E.shouhuotaitou,'''')='''' then D.KHTAITOU else E.shouhuotaitou end )  ');
      SQL.Add(',JYTIME=D.FILLTIME,JYPERSON=D.FILLER');
      SQL.Add(',JHCHEJIAN');
      //sql.add(',KHName1=(select Y.CustomerNoName from FHSQ_Main X inner join JYOrderCon_Main_PB Y on X.ConMainId=Y.MainId where X.FSId=A.CKORDNO ) ');
      sql.add('from CK_PBCP_CR A ');
      Sql.add(' inner join Cloth_Main B on A.MainId=B.MainId');
      Sql.add(' inner join Cloth_Sub C on A.MainId=C.MainId');
      Sql.add(' inner join WFB_MJJY_PB D on A.MJId=D.MJId');
      SQL.ADD(' LEFT join FHSQ_Main E on A.CKOrdNo=E.FSId');
      sql.add('where A.CRTime>=''' + Trim(FormatDateTime('yyyy-MM-dd', BegDate.DateTime)) + ''' ');
      sql.Add(' and A.CRTime<''' + Trim(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1)) + '''');
      SQL.Add(' and CRFlag in (''出库'') ');
      if CkOrdNo.Text <> '' then
      begin
        sql.Add('and CkOrdNo like ' + QuotedStr(Trim('%' + CkOrdNo.Text + '%')));
      end;
      SQL.Add('ORDER BY newname,newcarno');
//      ShowMessage(SQL.Text);
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmPBOuGLtListMX.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;
  InitGrid();
end;

procedure TfrmPBOuGLtListMX.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmPBOuGLtListMX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Self.Caption + '1', Tv1, '坯布仓库');
  Close;
end;

procedure TfrmPBOuGLtListMX.FormShow(Sender: TObject);
var
  fsj: string;
begin
  fsj := 'select distinct Code=Null,Name=MCCJ from Machine order by MCCJ ';
  SInitComBoxBySql(ADOQueryTemp, CheJian, False, fsj);
  ReadCxGrid(Self.Caption, Tv1, '坯布仓库');
  ReadCxGrid(Self.Caption + '1', Tv1, '坯布仓库');
  InitGrid();
end;

procedure TfrmPBOuGLtListMX.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    exit;
  SelExportData(Tv1, ADOQueryMain, '');
end;

procedure TfrmPBOuGLtListMX.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  end;
end;

procedure TfrmPBOuGLtListMX.MPRTCodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmPBOuGLtListMX.orderNoChange(Sender: TObject);
begin
  if Length(ConNo.Text) < 4 then
    Exit;
  TBFind.Click;
end;

procedure TfrmPBOuGLtListMX.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmPBOuGLtListMX.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmPBOuGLtListMX.TBCKCXClick(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if CDS_Main.FieldByName('SSel').AsBoolean = True then
      begin
        if FCKOrderNo = '' then
        begin
          FCKOrderNo := Trim(CDS_Main.fieldbyname('CKOrdNo').AsString);
          with ADOQueryTemp do
          begin
            Close;
            sql.Clear;
            sql.Add('select * from YF_Money_CR_Sub where yfpzno=''' + Trim(CDS_Main.fieldbyname('CKOrdNo').AsString) + '''');
            Open;
          end;
          if ADOQueryTemp.IsEmpty = False then
          begin
            CDS_Main.EnableControls;
            Application.MessageBox('已生成应收款，不能撤销出库!', '提示', 0);
            Exit;
          end;
        end;
      end;
      Next;
    end;
  end;
  CDS_Main.EnableControls;
  if Application.MessageBox('确定要撤销数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('exec P_Do_PBCK @CRFlag=''未出库'', @CKOrdNo='''', @MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));

            sql.Add('UPDATE WFB_MJJY_PB SET NEWNAME=NULL');
            SQL.Add(',NEWBATCHNO=NULL');
            SQL.Add(',NEWCARNO=NULL');
            SQL.Add(',FHKONGJIA=NULL');
            SQL.Add(',ckno=NULL');
            SQL.Add(',CPPRICE=NULL');
            SQL.Add(',pici=NULL');
            SQL.Add(',KHPM=NULL');
            SQL.Add(',KHTAITOU=NULL');
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('成品出库撤销')));
            sql.Add(',' + quotedstr(trim('出库单号：' + trim(CDS_Main.FieldByName('CKOrdNo').AsString) + ' 条码：' + trim(CDS_Main.FieldByName('MJID').AsString))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;
            sql.Add('exec P_Do_FHSQ ''' + Trim(CDS_Main.fieldbyname('CKOrdNo').AsString) + '''');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;
    MovePanel2.Visible := False;
    Exit;
  except
    MovePanel2.Visible := False;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;

end;

procedure TfrmPBOuGLtListMX.C_CodeNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmPBOuGLtListMX.ConNoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(Trim(ConNo.Text)) < 4 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        SQL.Add('select A.*,B.ConNo,C.C_CodeName,C.C_Code,C.C_Color,D.APXH ');
        sql.add('from CK_PBCP_CR A ');
        Sql.add(' inner join Cloth_Main B on A.MainId=B.MainId');
        Sql.add(' inner join Cloth_Sub C on A.MainId=C.MainId');
        Sql.add(' inner join WFB_MJJY_PB D on A.MJId=D.MJId');
        sql.add('where B.ConNo like :ConNo');
        SQL.Add(' and CRFlag=''出库'' ');
        Parameters.ParamByName('ConNo').Value := '%' + Trim(ConNo.Text) + '%';
        Open;
        //ShowMessage(SQL.Text);
      end;
      SCreateCDS20(ADOQueryMain, CDS_Main);
      SInitCDSData20(ADOQueryMain, CDS_Main);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmPBOuGLtListMX.CheJianChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmPBOuGLtListMX.ToolButton1Click(Sender: TObject);
begin
  Panel2.Visible := True;
end;

procedure TfrmPBOuGLtListMX.Button1Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if edit1.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改收货抬头吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET khTAITOU=' + QuotedStr(edit1.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改收货抬头')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原收货抬头' + trim(CDS_Main.FieldByName('shouhuotaitou2').AsString) + ' 现抬头' + trim(edit1.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button3Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if cpname.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改出到品名吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET NEWNAME=' + QuotedStr(cpname.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改出到品名')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原品名' + trim(CDS_Main.FieldByName('NEWNAME').AsString) + ' 现品名' + trim(cpname.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button4Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if Edit2.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改出到机台吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET newcarno=' + QuotedStr(Edit2.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改出到机台')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原机台' + trim(CDS_Main.FieldByName('newcarno').AsString) + ' 现机台' + trim(edit2.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button5Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if Edit3.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改出到批号吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET newbatchno=' + QuotedStr(Edit3.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改出到批号')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原批号' + trim(CDS_Main.FieldByName('newbatchno').AsString) + ' 现批号' + trim(edit3.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button6Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if KHPM.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改客户品名吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET khpm=' + QuotedStr(KHPM.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改出到批号')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原客户品名' + trim(CDS_Main.FieldByName('khpm').AsString) + ' 现客户品名' + trim(KHPM.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button7Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if KHNAME.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改出到客户吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE CK_PBCP_CR SET khname=' + QuotedStr(KHNAME.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改出到客户')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原客户' + trim(CDS_Main.FieldByName('KHName2').AsString) + ' 现客户' + trim(KHNAME.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button8Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
  FReal: Double;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(Edit6.Text, FReal) = False then
  begin
    Application.MessageBox('空加数格式不正确', '提示', 0);
    Exit;
  end;

  if Application.MessageBox('确定要修改空加数吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET FHKONGJIA=' + QuotedStr(Edit6.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改空加数')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原空加' + trim(CDS_Main.FieldByName('FHKONGJIA').AsString) + ' 现空加' + trim(Edit6.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.Button9Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if ComboBox1.Text = '' then
  begin
    Application.MessageBox('所填数据不能为空！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要修改批次吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET pici=' + QuotedStr(ComboBox1.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改批次')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原批次' + trim(CDS_Main.FieldByName('pici').AsString) + ' 现批次' + trim(ComboBox1.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

procedure TfrmPBOuGLtListMX.KHPMBtnClick(Sender: TObject);
begin
  try
    frmZDYHelp := TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag := 'KHPM';
      flagname := '客户品名';
      if ShowModal = 1 then
      begin
        Self.KHPM.Text := Trim(frmZDYHelp.ClientDataSet1.fieldbyname('ZdyName').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmPBOuGLtListMX.KHNAMEPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachment := TfrmZdyAttachment.Create(Application);
    with frmZdyAttachment do
    begin
      if ShowModal = 1 then
      begin
        KHNAME.Text := Trim(CDS_HZ.fieldbyname('CoName').AsString);

      end;
    end;
  finally
    frmZdyAttachment.Free;
  end;
end;

procedure TfrmPBOuGLtListMX.cpnamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmCPManageFMSel := TfrmCPManageFMSel.Create(Application);
    with frmCPManageFMSel do
    begin
      if ShowModal = 1 then
      begin

        cpname.Text := frmCPManageFMSel.CDS_Main.fieldbyname('CYName').AsString;

      end;
    end;
  finally
    frmCPManageFMSel.Free;
  end;
end;

procedure TfrmPBOuGLtListMX.Button2Click(Sender: TObject);
begin
  Panel2.Visible := False;
end;

procedure TfrmPBOuGLtListMX.Button10Click(Sender: TObject);
var
  FFMainId, FPrice, FHZ, FCKOrderNo, mvalue: string;
  FReal: Double;
begin
  if CDS_Main.IsEmpty then
    Exit;
  if CDS_Main.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  if TryStrToFloat(Edit4.Text, FReal) = False then
  begin
    Application.MessageBox('单价格式不正确', '提示', 0);
    Exit;
  end;

  if Application.MessageBox('确定要修改单价吗？', '提示', 32 + 4) <> IDYES then
    Exit;

  try
    ADOQueryCmd.Connection.BeginTrans;
    CDS_Main.DisableControls;
    with CDS_Main do
    begin
      First;
      while CDS_Main.Locate('SSel', True, []) = True do
      begin
        begin
          with ADOQueryCmd do
          begin
            Close;
            sql.Clear;

            sql.Add('UPDATE WFB_MJJY_PB SET cpprice=' + QuotedStr(Edit4.Text));
            SQL.Add('WHERE MJID=' + quotedstr(trim(CDS_Main.fieldbyname('MJID').asstring)));
            sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
            sql.Add(' ' + quotedstr(trim(DName)));
            sql.Add(',getdate() ');
            sql.Add(',' + quotedstr(trim(self.Caption)));
            sql.Add(',' + quotedstr(trim('修改单价')));
            sql.Add(',' + quotedstr(trim('条码号：' + trim(CDS_Main.FieldByName('mjid').AsString) + ' 原单价' + trim(CDS_Main.FieldByName('cpprice').AsString) + ' 现单价' + trim(Edit4.Text))));
            sql.Add(',' + quotedstr(trim('成功')));
            sql.Add(')');
            ExecSQL;
          end;

          CDS_Main.Delete;
        end;
      end;
    end;
    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.CommitTrans;

    InitGrid();
    Exit;
  except

    CDS_Main.EnableControls;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('撤销异常！', '提示', 0);
  end;
end;

end.

