unit U_CPAddWJE; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB, DBClient, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid, ComCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, cxTextEdit, cxButtonEdit, StdCtrls, ExtCtrls, cxCurrencyEdit, cxLookAndFeels, cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray, dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin, dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxNavigator; type TfrmCPAddWJE = class(TForm) ToolBar1: TToolBar; ToolButton1: TToolButton; TBClose: TToolButton; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; v1Column1: TcxGridDBColumn; v1Column2: TcxGridDBColumn; v1Column3: TcxGridDBColumn; v1Column4: TcxGridDBColumn; v1Column5: TcxGridDBColumn; v1Column6: TcxGridDBColumn; v1Column7: TcxGridDBColumn; v1Column8: TcxGridDBColumn; v1Column9: TcxGridDBColumn; v1Column10: TcxGridDBColumn; v1Column11: TcxGridDBColumn; cxGrid1Level1: TcxGridLevel; CDS_Sub: TClientDataSet; ADOQueryMain: TADOQuery; DataSource2: TDataSource; ADOQueryCmd: TADOQuery; ADOQueryTemp: TADOQuery; cxGridPopupMenu1: TcxGridPopupMenu; v1Column13: TcxGridDBColumn; v1Column14: TcxGridDBColumn; v1Column20: TcxGridDBColumn; v1Column41: TcxGridDBColumn; Panel1: TPanel; CheckBox1: TCheckBox; v1Column12: TcxGridDBColumn; v1Column15: TcxGridDBColumn; v1Column16: TcxGridDBColumn; v1Column17: TcxGridDBColumn; v1Column18: TcxGridDBColumn; v1Column19: TcxGridDBColumn; v1Column21: TcxGridDBColumn; v1Column22: TcxGridDBColumn; v1Column23: TcxGridDBColumn; v1Column29: TcxGridDBColumn; Tv1Column1: TcxGridDBColumn; Tv1Column2: TcxGridDBColumn; procedure FormShow(Sender: TObject); procedure TBCloseClick(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure v1Column7PropertiesEditValueChanged(Sender: TObject); procedure v1Column8PropertiesEditValueChanged(Sender: TObject); procedure v1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1Column26PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1Column27PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1Column20PropertiesEditValueChanged(Sender: TObject); procedure CheckBox1Click(Sender: TObject); procedure v1Column23PropertiesEditValueChanged(Sender: TObject); private canshu1: string; Fint: Integer; procedure InitSubGrid(); function SaveData(): Boolean; { Private declarations } public FCYID, FCYCode, FCPID, FCPNO: string; CopyInt: Integer; { Public declarations } end; var frmCPAddWJE: TfrmCPAddWJE; implementation uses U_DataLink, U_Fun, U_iniParam, U_ZDYHelp; {$R *.dfm} procedure TfrmCPAddWJE.InitSubGrid(); begin try ADOQueryMain.DisableControls; with ADOQueryMain do begin Close; SQL.Clear; SQL.Add('select * from CP_YDang where CYID=''' + Trim(FCYID) + ''''); Open; end; SCreateCDS20(ADOQueryMain, CDS_Sub); SInitCDSData20(ADOQueryMain, CDS_Sub); finally ADOQueryMain.EnableControls; end; end; procedure TfrmCPAddWJE.FormShow(Sender: TObject); var fsj, FFSj, FFQZSj, FFFSj, FFType: string; FFInt, i, j: Integer; ii: LongInt; begin //canshu1:=Trim(DParameters1); ReadCxGrid('样品编辑YT', Tv1, '样品管理1'); // if DParameters2 = '无价格' then // begin // Tv1Column3.Visible := False; // Tv1Column4.Visible := False; // Tv1Column5.Visible := False; // Tv1Column6.Visible := False; // Tv1Column7.Visible := False; // // Tv1Column3.Options.Editing := False; // Tv1Column4.Options.Editing := False; // Tv1Column5.Options.Editing := False; // Tv1Column6.Options.Editing := False; // Tv1Column7.Options.Editing := False; // end; InitSubGrid(); if CopyInt = 1 then begin FCYID := ''; end; { if Trim(YPCodeType)<>'' then begin if Trim(FCYID)='' then begin //取前缀 with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select CYNO AA from CP_YDang '); SQL.Add('where Cast(CYID as int)=(select isnull(Max(Cast(CYID as int)),0) from CP_YDang where CYType='''+Trim(FCPID)+''')'); Open; end; if Trim(ADOQueryTemp.fieldbyname('AA').asstring)='' then begin FFQZSj:=Trim(FCPNO); end else begin fsj:=Trim(ADOQueryTemp.fieldbyname('AA').asstring); FFInt:=0; i:=0; FFFSj:=Trim(Copy(fsj,Length(FCPNO)+1,Length(fsj))); while FFInt<=0 do begin FFSj:=Trim(Copy(fsj,Length(FCPNO)+1+i,Length(fsj))); if TryStrToInt(FFSj,ii) then begin if StrToInt(FFSj)>=0 then begin i:=i+1; end else begin FFInt:=1; FFQZSj:=Trim(Copy(fsj,1,Length(FCPNO)+i+1));//前缀字符串 end; if i=Length(FFFSj) then begin FFInt:=1; FFQZSj:=Trim(FCPNO); end; end else begin FFInt:=1; FFQZSj:=Trim(Copy(fsj,1,Length(FCPNO)+i+1));//前缀字符串 end; end; end; //取前缀 //取后缀 if Trim(YPCodeType)='大类' then begin i:=99; while i>=1 do begin if i=99 then begin FFType:=Trim(FCPID); end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from CP_Type where CPID='''+Trim(FFType)+''''); Open; i:=fieldbyname('CPLevel').AsInteger; if i>1 then FFType:=Trim(fieldbyname('CPParent').AsString) else if i=1 then begin FFType:=Trim(fieldbyname('CPID').AsString); i:=0; end; end; end; with ADOQueryTemp do begin Close; sql.Clear; sql.Add('exec P_Select_CP_YDang_MaxNo :CPType'); Parameters.ParamByName('CPType').Value:=Trim(FFType); Open; end; end else if Trim(YPCodeType)='小类' then begin with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select CYNO AA from CP_YDang '); SQL.Add('where Cast(CYID as int)=(select isnull(Max(Cast(CYID as int)),0) from CP_YDang where CYType='''+Trim(FCPID)+''')'); Open; end; end; if Trim(ADOQueryTemp.fieldbyname('AA').asstring)='' then begin FFFSj:='0001'; end else begin fsj:=Trim(ADOQueryTemp.fieldbyname('AA').asstring); FFInt:=0; i:=0; FFFSj:=''; fsj:=Trim( Copy( fsj,Length(FFQZSj)+1,Length(fsj) ) ); while FFInt<=0 do begin FFSj:=Trim(Copy(fsj,(Length(fsj)-i),(Length(fsj)))); if TryStrToInt(FFSj,ii) then begin if StrToInt(FFSj)>=0 then begin FFFSj:=Trim(FFSj);//后缀数字字符串 end else begin FFInt:=1; end; i:=i+1; if i=Length(fsj) then begin FFInt:=1; end; end else begin FFInt:=1; end; end; i:=Length(FFFSj); //数字编号长度 3 FFInt:=StrToInt(FFFSj)+1;//最大号 j:=Length(Trim(IntToStr(FFInt))); //最大号位数 1 FFFSj:=Trim(IntToStr(FFInt));//后缀数字字符串 while j 1 then begin ADOQueryCmd.Connection.RollbackTrans; Result := False; Application.MessageBox('编号重复!', '提示', 0); Exit; end; end; ADOQueryCmd.Connection.CommitTrans; with CDS_Sub do begin Edit; FieldByName('CYID').Value := Trim(maxId); FieldByName('CYType').Value := Trim(FCPID); Post; end; Result := True; except Result := True; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('保存失败!', '提示', 0); end; end; procedure TfrmCPAddWJE.ToolButton1Click(Sender: TObject); begin if CDS_Sub.Locate('CYNo', null, []) = True then begin Application.MessageBox('产品编号不能为空!', '提示', 0); Exit; end; {if CDS_Sub.Locate('CYName',null,[])=True then begin Application.MessageBox('中文名称不能为空!','提示',0); Exit; end; } ToolBar1.SetFocus; if SaveData() then begin Application.MessageBox('保存成功!', '提示', 0); ModalResult := 1; end; end; procedure TfrmCPAddWJE.v1Column7PropertiesEditValueChanged(Sender: TObject); var mvalue, FieldName, PriceKg, MF, KZ: string; FReal: Double; begin mvalue := Trim(TcxTextEdit(Sender).EditingText); with CDS_Sub do begin Edit; if TryStrToFloat(mvalue, FReal) = False then FieldByName('CYMF').Value := mvalue else begin if Trim(canshu1) = '英寸' then FieldByName('CYMF').Value := mvalue + '"' else FieldByName('CYMF').Value := mvalue + 'CM'; end; Post; end; FieldName := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; PriceKg := Trim(CDS_Sub.fieldbyname('CYPriceKg').AsString); if Trim(PriceKg) = '' then begin PriceKg := '0'; end; MF := Trim(CDS_Sub.fieldbyname('CYMF').AsString); KZ := Trim(CDS_Sub.fieldbyname('CYKZ').AsString); if Trim(canshu1) <> '英寸' then MF := Copy(MF, 1, Pos('C', MF) - 1) else MF := Copy(MF, 1, Pos('"', MF) - 1); KZ := Copy(KZ, 1, Pos('g', KZ) - 1); if TryStrToFloat(MF, FReal) = False then begin MF := '0'; end; if TryStrToFloat(KZ, FReal) = False then begin KZ := '0'; end; with CDS_Sub do begin Edit; if Trim(canshu1) <> '英寸' then FieldByName('CYPriceM').Value := StrToFloat(PriceKg) * StrToFloat(MF) * StrToFloat(KZ) * 1.00 / 100000 else FieldByName('CYPriceM').Value := StrToFloat(PriceKg) * StrToFloat(MF) * 2.54 * StrToFloat(KZ) * 1.00 / 100000; Post; end; end; procedure TfrmCPAddWJE.v1Column8PropertiesEditValueChanged(Sender: TObject); var mvalue, FieldName, PriceKg, MF, KZ: string; FReal: Double; begin mvalue := Trim(TcxTextEdit(Sender).EditingText); with CDS_Sub do begin Edit; if TryStrToFloat(mvalue, FReal) = False then FieldByName('CYKZ').Value := mvalue else FieldByName('CYKZ').Value := mvalue + 'g/㎡'; Post; end; FieldName := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; PriceKg := Trim(CDS_Sub.fieldbyname('CYPriceKg').AsString); if Trim(PriceKg) = '' then begin PriceKg := '0'; end; MF := Trim(CDS_Sub.fieldbyname('CYMF').AsString); KZ := Trim(CDS_Sub.fieldbyname('CYKZ').AsString); if Trim(canshu1) <> '英寸' then MF := Copy(MF, 1, Pos('C', MF) - 1) else MF := Copy(MF, 1, Pos('"', MF) - 1); KZ := Copy(KZ, 1, Pos('g', KZ) - 1); if TryStrToFloat(MF, FReal) = False then begin MF := '0'; end; if TryStrToFloat(KZ, FReal) = False then begin KZ := '0'; end; with CDS_Sub do begin Edit; if Trim(canshu1) <> '英寸' then FieldByName('CYPriceM').Value := StrToFloat(PriceKg) * StrToFloat(MF) * StrToFloat(KZ) * 1.00 / 100000 else FieldByName('CYPriceM').Value := StrToFloat(PriceKg) * StrToFloat(MF) * 2.54 * StrToFloat(KZ) * 1.00 / 100000; Post; end; end; procedure TfrmCPAddWJE.v1Column2PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'YPName'; flagname := '样品名称'; if ShowModal = 1 then begin with CDS_Sub do begin Edit; FieldByName('CYName').Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; end; finally frmZDYHelp.Free; end; end; procedure TfrmCPAddWJE.v1Column26PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); var fsj: string; begin fsj := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'GYStr'; flagname := '工艺名称'; if ShowModal = 1 then begin with CDS_Sub do begin Edit; FieldByName(fsj).Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; end; finally frmZDYHelp.Free; end; end; procedure TfrmCPAddWJE.v1Column27PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); var fsj: string; begin fsj := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'YPJGFactory'; flagname := '加工厂'; if ShowModal = 1 then begin with CDS_Sub do begin Edit; FieldByName(fsj).Value := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString); end; end; end; finally frmZDYHelp.Free; end; end; procedure TfrmCPAddWJE.v1Column20PropertiesEditValueChanged(Sender: TObject); var FieldName, mvalue, MF, KZ, PriceKg: string; FReal: Double; begin mvalue := TcxTextEdit(Sender).EditingText; FieldName := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; with CDS_Sub do begin Edit; FieldByName(FieldName).Value := mvalue; Post; end; PriceKg := Trim(CDS_Sub.fieldbyname('CYPriceKg').AsString); if Trim(PriceKg) = '' then begin PriceKg := '0'; end; MF := Trim(CDS_Sub.fieldbyname('CYMF').AsString); KZ := Trim(CDS_Sub.fieldbyname('CYKZ').AsString); if Trim(canshu1) <> '英寸' then MF := Copy(MF, 1, Pos('C', MF) - 1) else MF := Copy(MF, 1, Pos('"', MF) - 1); KZ := Copy(KZ, 1, Pos('g', KZ) - 1); if TryStrToFloat(MF, FReal) = False then begin MF := '0'; end; if TryStrToFloat(KZ, FReal) = False then begin KZ := '0'; end; with CDS_Sub do begin Edit; if Trim(canshu1) <> '英寸' then FieldByName('CYPriceM').Value := StrToFloat(PriceKg) * StrToFloat(MF) * StrToFloat(KZ) * 1.00 / 100000 else FieldByName('CYPriceM').Value := StrToFloat(PriceKg) * StrToFloat(MF) * 2.54 * StrToFloat(KZ) * 1.00 / 100000; Post; end; end; procedure TfrmCPAddWJE.CheckBox1Click(Sender: TObject); begin if CheckBox1.Checked = True then begin canshu1 := '英寸'; end else begin canshu1 := ''; end; end; procedure TfrmCPAddWJE.v1Column23PropertiesEditValueChanged(Sender: TObject); var Fieldname: string; fPrice6: double; begin Fieldname := Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName; with CDS_Sub do begin edit; fieldbyname(Fieldname).Value := TcxTextEdit(Sender).EditingText; fPrice6 := 0; if 1 - fieldbyname('Price1').AsFloat > 0 then begin fPrice6 := fieldbyname('Price2').AsFloat / (1 - fieldbyname('Price1').AsFloat); fPrice6 := fPrice6 + fieldbyname('Price3').AsFloat + fieldbyname('Price4').AsFloat + fieldbyname('Price5').AsFloat; end; FieldByName('Price6').Value := strtofloat(format('%.1f', [fPrice6])); FieldByName('Price7').Value := strtofloat(format('%.1f', [fieldbyname('Price6').AsFloat / 0.8])); post; end; Tv1.Controller.EditingController.ShowEdit(); end; end.