unit U_PRICECHANGE;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxContainer,
  cxImage, cxDBEdit, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, ShellAPI, StrUtils, cxCheckBox, cxPC, cxMemo, Menus, Math, Clipbrd,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu,
  cxDropDownEdit, cxCalc, MovePanel;

type
  TfrmPRICECHANGE = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    BegDate: TDateTimePicker;
    EndDate: TDateTimePicker;
    Label2: TLabel;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    G_ZBFACTORYNAME: TEdit;
    TBExport: TToolButton;
    Order_Main: TClientDataSet;
    RM1: TRMGridReport;
    RMXLSExport1: TRMXLSExport;
    CDS_PRT: TClientDataSet;
    RMDBPRT: TRMDBDataSet;
    RMDBDataSet1: TRMDBDataSet;
    ClientDataSet1: TClientDataSet;
    IdFTP1: TIdFTP;
    ADOQueryImage: TADOQuery;
    DSImage: TDataSource;
    ClientDataSet2: TClientDataSet;
    RMDBDataSet2: TRMDBDataSet;
    CheckBox1: TCheckBox;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    tv2Column1: TcxGridDBColumn;
    TV1Column11: TcxGridDBColumn;
    TV1Column18: TcxGridDBColumn;
    TV1Column12: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    TV1Column16: TcxGridDBColumn;
    tv2Column2: TcxGridDBColumn;
    cxGridDBColumn7: TcxGridDBColumn;
    TV1Column28: TcxGridDBColumn;
    cxGridDBColumn9: TcxGridDBColumn;
    TV1Column15: TcxGridDBColumn;
    TV1Column19: TcxGridDBColumn;
    TV1Column20: TcxGridDBColumn;
    tv2Column6: TcxGridDBColumn;
    TV1Column2: TcxGridDBColumn;
    TV1Column3: TcxGridDBColumn;
    TV1Column4: TcxGridDBColumn;
    TV1Column6: TcxGridDBColumn;
    TV1Column7: TcxGridDBColumn;
    TV1Column8: TcxGridDBColumn;
    TV1Column5: TcxGridDBColumn;
    TV1Column9: TcxGridDBColumn;
    TV1Column10: TcxGridDBColumn;
    TV1Column13: TcxGridDBColumn;
    TV1Column14: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label1: TLabel;
    M_HXCODE: TEdit;
    TV1Column17: TcxGridDBColumn;
    TV1Column21: TcxGridDBColumn;
    Label4: TLabel;
    Edit1: TEdit;
    Label5: TLabel;
    Edit2: TEdit;
    Label6: TLabel;
    Edit3: TEdit;
    Button1: TButton;
    MovePanel2: TMovePanel;
    GroupBox1: TGroupBox;
    Label7: TLabel;
    F_MSMGFJ: TEdit;
    Label8: TLabel;
    F_MSMGFFJ: TEdit;
    GroupBox2: TGroupBox;
    Label9: TLabel;
    Label10: TLabel;
    F_XXGYW: TEdit;
    F_XXGPW: TEdit;
    Label11: TLabel;
    F_XFXG: TEdit;
    GroupBox3: TGroupBox;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    F_DXGYW: TEdit;
    F_DXGPW: TEdit;
    F_DFXG: TEdit;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure M_HXCODEChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBViewClick(Sender: TObject);
    procedure Picture4DblClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure FormDestroy(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure cxTabControl1CanClose(Sender: TObject; var ACanClose: Boolean);
    procedure cxTabControl1Change(Sender: TObject);
    procedure edit1Change(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
    procedure cbbISSavedChange(Sender: TObject);
    procedure chkYDDClick(Sender: TObject);
    procedure chkwzbClick(Sender: TObject);
    procedure chkWDDClick(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure v1Column15PropertiesCustomClick(Sender: TObject);
    procedure Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
    procedure TBCopyClick(Sender: TObject);
    procedure G_ZBFACTORYNAMEKeyPress(Sender: TObject; var Key: Char);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure TCBNORKeyPress(Sender: TObject; var Key: Char);
    procedure ToolButton5Click(Sender: TObject);
    procedure TV1Column2PropertiesEditValueChanged(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    FInt, PFInt: Integer;
    CurrentPage, RecordsNumber: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitButton();
    procedure LookImage(FileName: string);
    procedure InitImage();
    procedure JSFYAll();
    { Private declarations }
  public
    canshu1, FCheJian, FCXMG: string;
    FChtType: string;
    fFlileFlag: string;
    CXTJ1, CXZ1: string;
    CXTJ2, CXZ2: string;
    { Public declarations }
  end;

var
  frmPRICECHANGE: TfrmPRICECHANGE;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp, U_FjList10, U_SketchManage, U_QXGL, U_OrderInPut; //U_ShuttleClothSCInPut2

{$R *.dfm}

procedure TfrmPRICECHANGE.JSFYAll();
var
  F_YSTS1, F_MSMGF1, F_MSXPKPF1, F_MSDPKPF1, F_MGQTF1: Double;
  F_MGF1, F_XPKPF1, F_DPKPF1: Double;
  F_PSS1, F_SOMTZBF1, F_DYQTFY1, F_MSDPZWF1, F_SOMSPSF1: Double;
  F_SOZBF1, F_PSF1: Double;
  J, K, L: Integer;
begin
  MovePanel2.Left := (self.Width - MovePanel2.Width) div 2;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  with Order_Main do
  begin
    First;
    while not Eof do
    begin
      J := 0;
      K := 0;
      L := 0;
      with Order_Main do
      begin
        Edit;
        if Edit1.Text <> '' then
        begin
          FieldByName('F_MSMGF').Value := StrToFloatDef(Edit1.Text, 0);
        end;
        if Edit2.Text <> '' then
        begin
          FieldByName('F_MSXPKPF').Value := StrToFloatDef(Edit2.Text, 0);
        end;
        if Edit3.Text <> '' then
        begin
          FieldByName('F_MSDPKPF').Value := StrToFloatDef(Edit3.Text, 0);
        end;

        Post;
      end;

      with Order_Main do
      begin
        EDIT;

        K := Order_Main.Fieldbyname('XPKPS').ASINTEGER;
        L := Order_Main.Fieldbyname('DPKPS').ASINTEGER;

        F_PSS1 := StrToFloatDef(Order_Main.Fieldbyname('F_PSS').ASSTRING, 0);   //配色数
        F_SOMTZBF1 := StrToFloatDef(Order_Main.Fieldbyname('F_SOMTZBF').ASSTRING, 0);  //S/O每套制版费
        F_SOMSPSF1 := StrToFloatDef(Order_Main.Fieldbyname('F_SOMSPSF').ASSTRING, 0);  //每色配色费
        F_DYQTFY1 := StrToFloatDef(Order_Main.Fieldbyname('F_DYQTFY').ASSTRING, 0);  //打样其他费用
        F_MSDPZWF1 := StrToFloatDef(Order_Main.Fieldbyname('F_MSDPZWF').ASSTRING, 0);  //每色大片制网费

        F_SOZBF1 := StrToFloatDef(Order_Main.Fieldbyname('F_SOZBF').ASSTRING, 0);  //S/O制版费
        F_PSF1 := StrToFloatDef(Order_Main.Fieldbyname('F_PSF').ASSTRING, 0);  //配色费

        F_YSTS1 := StrToFloatDef(Order_Main.Fieldbyname('F_YSTS').ASSTRING, 0);   //颜色套数
        F_MSMGF1 := StrToFloatDef(Order_Main.Fieldbyname('F_MSMGF').ASSTRING, 0);  //每色描稿费
        F_MSXPKPF1 := StrToFloatDef(Order_Main.Fieldbyname('F_MSXPKPF').ASSTRING, 0);    //每色小片刻盘费
        F_MSDPKPF1 := StrToFloatDef(Order_Main.Fieldbyname('F_MSDPKPF').ASSTRING, 0);   //每色大片刻盘费
        F_MGQTF1 := StrToFloatDef(Order_Main.Fieldbyname('F_MGQTF').ASSTRING, 0);   //描稿其他费

        F_MGF1 := StrToFloatDef(Order_Main.Fieldbyname('F_MGF').ASSTRING, 0);   //描稿费
  //S/O制版费=S/O每套制版费  * 颜色套数
        Fieldbyname('F_SOZBF').ASSTRING := FloatToStr(ROUNDFLOAT((F_YSTS1 * F_SOMTZBF1), 2));   //S/O制版费
  //配色费=配色数 * 每色配色费
        Fieldbyname('F_psf').ASSTRING := FloatToStr(ROUNDFLOAT((F_PSS1 * F_SOMSPSF1), 2));   //配色费
  //打样费=(S/O制版费 + 配色费 + 打样其他费用 )*K(小片数)
 // F_DYF.TEXT := FloatToStr(ROUNDFLOAT((J * (StrToFloatDef(F_SOZBF.text, 0) + StrToFloatDef(F_PSF.text, 0) + strtofloatdef(F_DYQTFY.text, 0))), 2));   //打样费
  //描稿费=每色描稿费 * 颜色套数
  //已描稿打上 就说明 描稿费用不用没有了

        if Fieldbyname('G_YMG').VALUE = 0 then
        begin
          Fieldbyname('F_MGF').ASSTRING := FloatToStr(ROUNDFLOAT((F_YSTS1 * F_MSMGF1), 2));   //描稿费
        end
        else
        begin
          Fieldbyname('F_MGF').ASSTRING := '0';
        end;
    //已有片打上 是描稿 和工厂两个里面的纸片费用制片费用都不用了
        if Fieldbyname('G_yyp').VALUE = 0 then
        begin
  //小片刻盘费=每色小片刻盘费  * 颜色套数
          Fieldbyname('F_XPKPF').ASSTRING := FloatToStr(ROUNDFLOAT((K * F_YSTS1 * F_MSXPKPF1), 2));   //小片刻盘费
  //大片刻盘费=每色大片刻盘费  * 颜色套数
          Fieldbyname('F_DPKPF').ASSTRING := FloatToStr(ROUNDFLOAT((L * F_YSTS1 * F_MSDPKPF1), 2));   //大片刻盘费
      //大片制网费=每色大片制网费 * 颜色套数
//    F_DPZWF.text := FloatToStr(ROUNDFLOAT((F_MSDPZWF1 * StrToFloatDef(F_YSTS.text, 0)), 2));   //大片制网费
          Fieldbyname('F_DPZWF').ASSTRING := FloatToStr(ROUNDFLOAT((F_MSDPZWF1 * F_YSTS1), 2));
        end
        else
        begin
          Fieldbyname('F_XPKPF').ASSTRING := '0';
          Fieldbyname('F_DPKPF').ASSTRING := '0';
          Fieldbyname('F_DPZWF').ASSTRING := '0';

        end;

//  F_XPKPF1 := StrToFloatDef(F_XPKPF.Text, 0);  //小片刻盘费
//  F_DPKPF1 := StrToFloatDef(F_DPKPF.Text, 0);  //大片刻盘费
   //描稿合计=描稿费 + 小片刻盘费 + 大片刻盘费 + 描稿其他费
        Fieldbyname('F_MGHJ').ASSTRING := FloatToStr(ROUNDFLOAT((StrToFloatDef(Fieldbyname('F_MGF').ASSTRING, 0) + StrToFloatDef(Fieldbyname('F_DPKPF').ASSTRING, 0) + StrToFloatDef(Fieldbyname('F_XPKPF').ASSTRING, 0) + StrToFloatDef(Fieldbyname('F_MGQTF').ASSTRING, 0)), 2));   //描稿合计
   //总费用 = 描稿合计 + 打样费 + 大片制网费
        Fieldbyname('F_ZFY').ASSTRING := FloatToStr(ROUNDFLOAT((StrToFloatDef(Fieldbyname('F_DPZWF').ASSTRING, 0) + StrToFloatDef(Fieldbyname('F_DYF').ASSTRING, 0) + StrToFloatDef(Fieldbyname('F_MGHJ').ASSTRING, 0)), 2));   //总费用
        POST;
      end;
      tv1.Controller.EditingController.ShowEdit();
      Next;
    end;
  end;

end;

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

end;

procedure TfrmPRICECHANGE.InitButton();
begin

end;

procedure TfrmPRICECHANGE.TBCloseClick(Sender: TObject);
begin

  WriteCxGrid(Trim(self.Caption), Tv1, '坯布生产管理');
  Close;
end;

procedure TfrmPRICECHANGE.InitGrid();
var
  fwhere, PwherE: string;
  FREAL: Double;
  i: integer;
begin

  with GroupBox1 do
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i].Tag = 9 then
      begin
        if Controls[i] is TEdit then
        begin
//          ShowMessage((TEdit(Controls[i]).name));
//          ShowMessage((TEdit(Controls[i]).Text));
          if TryStrToFloat(TEdit(Controls[i]).Text, FREAL) = False then
          begin
            Application.MessageBox('请填写正确的数字！', '提示', 0);
            Exit;
          end;
        end;
      end;

    end;
  end;
  with GroupBox2 do
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i].Tag = 9 then
      begin
        if Controls[i] is TEdit then
        begin
//          ShowMessage((TEdit(Controls[i]).name));
//          ShowMessage((TEdit(Controls[i]).Text));
          if TryStrToFloat(TEdit(Controls[i]).Text, FREAL) = False then
          begin
            Application.MessageBox('请填写正确的数字！', '提示', 0);
            Exit;
          end;
        end;
      end;

    end;
  end;
  with GroupBox3 do
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if Controls[i].Tag = 9 then
      begin
        if Controls[i] is TEdit then
        begin
//          ShowMessage((TEdit(Controls[i]).name));
//          ShowMessage((TEdit(Controls[i]).Text));
          if TryStrToFloat(TEdit(Controls[i]).Text, FREAL) = False then
          begin
            Application.MessageBox('请填写正确的数字！', '提示', 0);
            Exit;
          end;
        end;
      end;

    end;
  end;

  fwhere := '';
  PwherE := SGetFilters(Panel1, 1, 2);
  if trim(PwherE) <> '' then
    fwhere := fwhere + ' AND ' + trim(PwherE);

  if CheckBox1.Checked then
  begin
    fwhere := fwhere + ' and G_ZBDATE>' + quotedstr(FormatDateTime('yyyy-MM-dd', BegDate.DateTime));
    fwhere := fwhere + ' and G_ZBDATE<=' + quotedstr(FormatDateTime('yyyy-MM-dd', enddate.DateTime + 1));
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
//      if (StrToFloatDEF(Edit1.Text, 0) = 0) and (StrToFloatDEF(Edit2.Text, 0) = 0) and (StrToFloatDEF(Edit3.Text, 0) = 0) then
//      begin
//        SQL.Add('SELECT *  ');
//        SQL.Add(',ismg=(case when G_YMG=1 then ''已描稿'' else ''未描稿'' end)');
//        SQL.Add(',DPKPS=(SELECT COUNT(*) FROM Sketch_XMAP B WHERE A.MGID=B.MGID AND B.XMNAME=''大片'' and b.xmkp=1)');
//        SQL.Add(',XPKPS=(SELECT COUNT(*) FROM Sketch_XMAP B WHERE A.MGID=B.MGID AND B.XMNAME=''小片'' and b.xmkp=1)');
//        SQL.Add(',isjg=(case when G_NG=1 then ''非简稿'' else ''简稿'' end)');
//        SQL.Add(',ISYP=(case when G_yyp=1 then ''有'' else ''无'' end)');
//        sql.Add('FROM Sketch_main A');
//        SQL.Add('WHERE 1=1');
//
//        sql.Add(fwhere);
//        Open;
//      end
//      else
//      begin
//        SQL.Add('EXEC P_View_YHMGFYHJ ');
//        if Edit1.Text <> '' then
//        begin
//          SQL.Add('@MSMGF=' + Edit1.Text);
//        end
//        else
//        begin
//          SQL.Add('@MSMGF=0');
//        end;
//        if Edit2.Text <> '' then
//        begin
//          SQL.Add(',@MSXPKPF=' + Edit2.Text);
//        end
//        else
//        begin
//          SQL.Add(',@MSXPKPF=0');
//        end;
//        if Edit3.Text <> '' then
//        begin
//          SQL.Add(',@MSDPKPF=' + Edit3.Text);
//        end
//        else
//        begin
//          SQL.Add(',@MSDPKPF=0');
//        end;
//
//        SQL.Add(',@WSQL=' + QuotedStr(fwhere));
////        ShowMessage(SQL.Text);
//        Open;
//      end;
      sql.Add('EXEC P_View_YHMGFYHJ @F_MSMGFJ=' + F_MSMGFJ.Text);
      SQL.Add(',@F_MSMGFFJ=' + F_MSMGFFJ.Text);
      SQL.Add(',@F_XXGYW=' + F_XXGYW.Text);
      SQL.Add(',@F_XXGPW=' + F_XXGPW.Text);
      SQL.Add(',@F_XFXG=' + F_XFXG.Text);
      SQL.Add(',@F_DXGYW=' + F_DXGYW.Text);
      SQL.Add(',@F_DXGPW=' + F_DXGPW.Text);
      SQL.Add(',@F_DFXG=' + F_DFXG.Text);
      SQL.Add(',@WSQL=' + QuotedStr(fwhere));

//      ShowMessage(SQL.Text);
      Open;
    end;

    SCreateCDS20(ADOQueryMain, Order_Main);
    SInitCDSData20(ADOQueryMain, Order_Main);

  finally
    ADOQueryMain.EnableControls;
  end;
//  MovePanel2.Visible := false;
end;

procedure TfrmPRICECHANGE.InitForm();
begin
// InitButton();
  CurrentPage := 1;
  RecordsNumber := 30;

  fFlileFlag := UserDataFlag + 'HX';
  ReadCxGrid(Trim(self.Caption), Tv1, '坯布生产管理');
  BegDate.DateTime := SGetServerDate10(ADOQueryTemp) - 180;
  EndDate.DateTime := SGetServerDate10(ADOQueryTemp);

  InitGrid();
end;

procedure TfrmPRICECHANGE.TBEditClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmSketchManage := TfrmSketchManage.Create(Application);
    with frmSketchManage do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MGID').AsString);
      canshu1 := Self.canshu1;
      if ShowModal = 1 then
      begin
        InitGrid();
        Self.Order_Main.Locate('MGID', frmSketchManage.FMainId, []);
      end;
    end;
  finally
    frmSketchManage.Free;
  end;
end;

procedure TfrmPRICECHANGE.TBDelClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;

  if Order_Main.FieldByName('G_ZBDATE').AsString <> '' then
  begin
    Application.MessageBox('已经有制版日期，不能删除！', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    Order_Main.Delete;
  end;
end;

function TfrmPRICECHANGE.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Sketch_main where MGID=''' + Trim(Order_Main.fieldbyname('MGID').AsString) + '''');

      ExecSQL;
    end;

    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmPRICECHANGE.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布生产单', cxGrid1);
end;

procedure TfrmPRICECHANGE.TBRafreshClick(Sender: TObject);
begin
  BegDate.SetFocus;

  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmPRICECHANGE.TBAddClick(Sender: TObject);
begin

  try
    frmSketchManage := TfrmSketchManage.Create(Application);
    with frmSketchManage do
    begin
      PState := 0;
      FMainId := '';
      FSubId := '';
      canshu1 := Self.canshu1;
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmSketchManage.Free;
  end;
end;

procedure TfrmPRICECHANGE.M_HXCODEChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS20(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
end;

procedure TfrmPRICECHANGE.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmPRICECHANGE.TBViewClick(Sender: TObject);
begin
  try
    frmSketchManage := TfrmSketchManage.Create(Application);
    with frmSketchManage do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MGID').AsString);
      ftype := '查看';
      canshu1 := Self.canshu1;
      
      
//      TBSave.Visible := False;
//      ToolBar3.Visible := False;
//      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmSketchManage.Free;
  end;
end;

procedure TfrmPRICECHANGE.Picture4DblClick(Sender: TObject);
begin
  if TcxDBImage(Sender).Picture.Height = 0 then
    exit;

  LookImage(ADOQueryImage.fieldbyname(TcxDBImage(Sender).Hint).asstring);
end;

procedure TfrmPRICECHANGE.LookImage(FileName: string);
var
  sFieldName: string;
begin

  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

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

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

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

  if IdFTP1.Connected then
  begin

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

procedure TfrmPRICECHANGE.InitImage();
begin

  ADOQueryImage.Close;
  if Order_Main.IsEmpty then
    exit;
//  with ADOQueryImage do
//  begin
//    close;
//    sql.Clear;
//    sql.Add('select * from TP_File A');
//    sql.Add('where mgid=' + quotedstr(trim(Order_Main.fieldbyname('mgid').AsString)));
//    sql.Add('and TFType=' + quotedstr(trim('寻样')));
//    open;
//  end;
end;

procedure TfrmPRICECHANGE.ToolButton1Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmFjList10 := TfrmFjList10.Create(Application);
    with frmFjList10 do
    begin

      fkeyno := Trim(Self.Order_Main.fieldbyname('MainId').AsString);
      fType := '分析单';
      if ShowModal = 1 then
      begin

      end;
      InitGrid();
    end;
  finally
    frmFjList10.Free;
  end;
end;

procedure TfrmPRICECHANGE.Tv1CellClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  if TV1.Controller.FocusedColumn.DataBinding.FilterFieldName = 'DTP' then
  begin

    if ACellViewInfo.Value = '设计稿' then
      LookImage(Trim(Self.Order_Main.fieldbyname('IMG_SJT').AsString));
  end;
  if TV1.Controller.FocusedColumn.DataBinding.FilterFieldName = 'BQSD' then
  begin
    if ACellViewInfo.Value = '查看' then
    begin

      try
        frmQXGL := TfrmQXGL.Create(Application);
        with frmQXGL do
        begin
          FM_HXCODE := Trim(Self.Order_Main.fieldbyname('M_HXCODE').AsString);

          if ShowModal = 1 then
          begin

          end;
        end;
      finally
        frmQXGL.Free;
      end;
    end;
  end;
end;

procedure TfrmPRICECHANGE.FormDestroy(Sender: TObject);
begin
  frmPRICECHANGE := nil;
end;

procedure TfrmPRICECHANGE.ToolButton2Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Sketch_main SET SHSTATUS=''已审核'',SHtime=getdate(),SHPERSON=' + quotedstr(Trim(DName)));
      sql.Add('where MGID=' + quotedstr(trim(Order_Main.fieldbyname('MGID').AsString)));

      execsql;
    end;
    application.MessageBox('已完成！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmPRICECHANGE.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Sketch_main SET SHSTATUS=''未审核'',SHtime=NULL,SHPERSON=NULL');
      sql.Add('where MGID=' + quotedstr(trim(Order_Main.fieldbyname('MGID').AsString)));

      execsql;
    end;
    application.MessageBox('操作成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmPRICECHANGE.cxTabControl1CanClose(Sender: TObject; var ACanClose: Boolean);
begin

  InitGrid();
end;

procedure TfrmPRICECHANGE.cxTabControl1Change(Sender: TObject);
begin

  InitGrid();
end;

procedure TfrmPRICECHANGE.edit1Change(Sender: TObject);
begin
  CXTJ1 := '';
  CXZ1 := '';

end;

procedure TfrmPRICECHANGE.ComboBox2Change(Sender: TObject);
begin
  CXTJ2 := '';
  CXZ2 := '';

end;

procedure TfrmPRICECHANGE.cbbISSavedChange(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmPRICECHANGE.chkYDDClick(Sender: TObject);
begin

  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmPRICECHANGE.chkwzbClick(Sender: TObject);
begin
  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmPRICECHANGE.chkWDDClick(Sender: TObject);
begin

  CurrentPage := 1;
  InitGrid();
end;

procedure TfrmPRICECHANGE.ToolButton4Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  try
    while Order_Main.Locate('SSel', True, []) do
    begin
      with ADOQueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('update  Sketch_main SET ISSaved=1,ISSaveDate=getdate()');
        sql.Add('where MGID=' + quotedstr(trim(Order_Main.fieldbyname('MGID').AsString)));
        execsql;
      end;
      with Order_Main do
      begin
        Edit;
        FieldByName('SSel').Value := False;
        FieldByName('ISSaved').Value := True;
        Post;
      end;
    end;
  except
    application.MessageBox('操作失败！', '提示信息', 0);
  end;
end;

procedure TfrmPRICECHANGE.v1Column15PropertiesCustomClick(Sender: TObject);
begin
  Application.MessageBox('已经有制版日期，不能删除！', '提示', 0);
end;

procedure TfrmPRICECHANGE.Tv1CustomDrawIndicatorCell(Sender: TcxGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxCustomGridIndicatorItemViewInfo; var ADone: Boolean);
var
  FValue: string;
  FBounds: TRect;
begin
  FBounds := AViewInfo.Bounds;
  if (AViewInfo is TcxGridIndicatorRowItemViewInfo) then
  begin
    ACanvas.FillRect(FBounds);
    ACanvas.DrawComplexFrame(FBounds, clBtnHighlight, clBtnShadow, [bBottom, bLeft, bRight], 1);
    FValue := IntToStr(TcxGridIndicatorRowItemViewInfo(AViewInfo).GridRecord.Index + 1);
    InflateRect(FBounds, -1, -1);    //Platform   specific.   May   not   work   on   Linux.
    ACanvas.Font.Color := clBlack;
    ACanvas.Brush.Style := bsClear;
    ACanvas.DrawText(FValue, FBounds, cxAlignCenter or cxAlignTop);
    ADone := True;
  end;
end;

procedure TfrmPRICECHANGE.TBCopyClick(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  try
    frmSketchManage := TfrmSketchManage.Create(Application);
    with frmSketchManage do
    begin
      CopyInt := 99;
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('MGID').AsString);
      canshu1 := Self.canshu1;
      if ShowModal = 1 then
      begin
        InitGrid();
        Self.Order_Main.Locate('MGID', frmSketchManage.FMainId, []);
      end;
    end;
  finally
    frmSketchManage.Free;
  end;
end;

procedure TfrmPRICECHANGE.G_ZBFACTORYNAMEKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmPRICECHANGE.BTLPClick(Sender: TObject);
begin
  if CurrentPage > 1 then
    CurrentPage := CurrentPage - 1;
  InitGrid();
end;

procedure TfrmPRICECHANGE.BTNPClick(Sender: TObject);
begin
  if CurrentPage < Order_Main.FieldByName('TotalCount').AsInteger / RecordsNumber then
    CurrentPage := CurrentPage + 1;
  InitGrid();
end;

procedure TfrmPRICECHANGE.N3Click(Sender: TObject);
begin

  Clipboard.SetTextBuf(PChar(Trim(Order_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString)));
end;

procedure TfrmPRICECHANGE.TCBNORKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin

    CurrentPage := 1;
    InitGrid();
  end;
end;

procedure TfrmPRICECHANGE.ToolButton5Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    Exit;
  if order_Main.fieldbyname('frommainid').AsString = '' then
  begin
    application.MessageBox('无订单信息！', '提示信息', 0);
    exit;
  end;
  try
    frmOrderInPut := TfrmOrderInPut.Create(Application);
    with frmOrderInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.Order_Main.fieldbyname('frommainid').AsString);
      ToolBar2.Visible := False;
      TBSave.Visible := False;
      ToolButton3.Visible := False;
      ScrollBox1.Enabled := False;
      cxGrid1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmOrderInPut.Free;
  end;
end;

procedure TfrmPRICECHANGE.TV1Column2PropertiesEditValueChanged(Sender: TObject);
begin
  JSFYAll();
end;

procedure TfrmPRICECHANGE.Button1Click(Sender: TObject);
begin
  JSFYAll();
end;

end.

