unit U_ClothInquiryInPut; 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, dxSkinsCore, dxSkinsDefaultPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu, dxDateTimeWheelPicker, dxGDIPlusClasses, Vcl.Menus, MovePanel, cxCheckBox, cxImage, cxDBEdit, Vcl.DBCtrls, U_BaseInput, System.ImageList, Vcl.ImgList, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdFTP, ShellAPI; type TfrmClothInquiryInPut = class(TfrmBaseInput) ToolBar1: TToolBar; TBSave: TToolButton; TBClose: TToolButton; ScrollBox1: TScrollBox; Label3: TLabel; MVCDate: TDateTimePicker; ADOTemp: TADOQuery; ADOCmd: TADOQuery; DS_1: TDataSource; Order_Sub: TClientDataSet; Label10: TLabel; MVCNo: TEdit; Label14: TLabel; Label20: TLabel; BuyName: TBtnEditC; GPM_1: TcxGridPopupMenu; Sellname: TBtnEditC; Label27: TLabel; IsTax: TComboBox; Label29: TLabel; Label30: TLabel; QiYun: TBtnEditC; MuDi: TBtnEditC; Label5: TLabel; Currency: TComboBox; Label11: TLabel; Label12: TLabel; YunShu: TBtnEditC; Payment: TBtnEditC; Label4: TLabel; GSChuanYangNote: TBtnEditC; Label13: TLabel; JiaGeSY: TBtnEditC; Label1: TLabel; CKChuanYangNote: TBtnEditC; Label8: TLabel; Packing: TBtnEditC; Label15: TLabel; Label16: TLabel; DlyDate: TDateTimePicker; ShippMent: TEdit; ToolButton3: TToolButton; lblSalesId: TLabel; Label25: TLabel; SalesId: TEdit; TallyId: TEdit; Panel1: TPanel; Panel2: TPanel; GroupBox5: TGroupBox; cxGrid2: TcxGrid; TV2: TcxGridDBTableView; TV2Column1: TcxGridDBColumn; TV2Column2: TcxGridDBColumn; TV2Column3: TcxGridDBColumn; cxGridLevel1: TcxGridLevel; ToolBar2: TToolBar; ToolButton1: TToolButton; ToolButton2: TToolButton; cxGrid1: TcxGrid; Tv1: TcxGridDBTableView; Tv1Column7: TcxGridDBColumn; v1XHNo: TcxGridDBColumn; VC_SCSCode: TcxGridDBColumn; v1Column4: TcxGridDBColumn; Tv1Column3: TcxGridDBColumn; v1Column5: TcxGridDBColumn; v1Column1: TcxGridDBColumn; Tv1Column5: TcxGridDBColumn; v1Column8: TcxGridDBColumn; Tv1Column1: TcxGridDBColumn; Tv1Column8: TcxGridDBColumn; v1Column6: TcxGridDBColumn; v1Column7: TcxGridDBColumn; v1OrderUnit: TcxGridDBColumn; v1PRTPrice: TcxGridDBColumn; v1Column2: TcxGridDBColumn; cxGrid1Level1: TcxGridLevel; TV2Column4: TcxGridDBColumn; CDS_2: TClientDataSet; DS_2: TDataSource; GPM_2: TcxGridPopupMenu; ToolButton4: TToolButton; procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBSaveClick(Sender: TObject); procedure ToolButton1Click(Sender: TObject); procedure ToolButton2Click(Sender: TObject); procedure BuyNameBtnUpClick(Sender: TObject); procedure BuyNameBtnDnClick(Sender: TObject); procedure v1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1Column7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); procedure SalesmanBtnUpClick(Sender: TObject); procedure v1Column15PropertiesEditValueChanged(Sender: TObject); procedure SellNameBtnUpClick(Sender: TObject); procedure QiYunBtnUpClick(Sender: TObject); procedure ShippMentKeyPress(Sender: TObject; var Key: Char); procedure ToolButton3Click(Sender: TObject); procedure ToolButton4Click(Sender: TObject); procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); private FLeft, FTop: Integer; fuserName, Fstatus: string; procedure InitData(); procedure InitHistoricalPrice(); function TestData(): Boolean; function SaveData(): Boolean; procedure SetXH(); { Private declarations } public CopyInt: Integer; PState: string; fFlileFlag: string; FMVCMID: string; FAuthority, FGSTT: string; { Public declarations } end; var frmClothInquiryInPut: TfrmClothInquiryInPut; newh: hwnd; implementation uses U_DataLink, U_RTFun, U_ZDYHelp, U_CompanySel, U_ClothInfoSel, U_PictureUpload; {$R *.dfm} procedure TfrmClothInquiryInPut.InitHistoricalPrice(); begin with ADOTemp do begin Close; SQL.Clear; sql.Add('select TOP 30 * '); sql.Add('from MV_Cloth_Main A inner join MV_Cloth_Sub B on A.MVCMId=B.MVCMId '); sql.Add('where B.C_Code=''' + Trim(Order_Sub.FieldByName('C_Code').AsString) + ''''); sql.Add('and isnull(A.status,''0'')<>''-1'''); sql.Add('and MVCType=''询价'''); sql.Add('order by A.MVCDate '); Open; end; SCreateCDS(ADOTemp, CDS_2); SInitCDSData(ADOTemp, CDS_2); end; procedure TfrmClothInquiryInPut.SetXH(); var i: Integer; begin with Order_Sub do begin First; i := 1; while not Eof do begin with Order_Sub do begin Edit; FieldByName('XHNoTemp').Value := i; Post; end; i := i + 1; Next; end; end; with Order_Sub do begin Order_Sub.IndexFieldNames := ''; First; i := 1; while not Eof do begin with Order_Sub do begin Edit; FieldByName('SerialNo').Value := FieldByName('XHNoTemp').AsInteger; Post; end; i := i + 1; Next; end; Order_Sub.IndexFieldNames := 'SerialNo'; end; end; procedure TfrmClothInquiryInPut.ShippMentKeyPress(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; function TfrmClothInquiryInPut.TestData(): Boolean; begin try if Trim(MVCNo.Text) = '' then raise Exception.Create('报价号不能为空!'); if Trim(SellName.Text) = '' then raise Exception.Create('我方单位不能为空!'); if Trim(BuyName.Text) = '' then raise Exception.Create('对方单位不能为空!'); if Order_Sub.IsEmpty then raise Exception.Create('明细不能为空!'); if Order_Sub.Locate('C_Code', null, []) then raise Exception.Create('产品编号不能为空!'); if Order_Sub.Locate('C_Code', '', []) then raise Exception.Create('产品编号不能为空!'); if Order_Sub.Locate('C_Name', null, []) then raise Exception.Create('品名不能为空!'); if Order_Sub.Locate('C_Name', '', []) then raise Exception.Create('品名不能为空!'); if Order_Sub.Locate('C_Color', null, []) then raise Exception.Create('颜色不能为空!'); if Order_Sub.Locate('C_Color', '', []) then raise Exception.Create('颜色不能为空!'); if Order_Sub.Locate('QtyUnit', null, []) then raise Exception.Create('数量单位不能为空!'); if Order_Sub.Locate('QtyUnit', '', []) then raise Exception.Create('数量单位不能为空!'); Result := True; except Result := false; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); end; end; procedure TfrmClothInquiryInPut.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmClothInquiryInPut.InitData(); var maxno: string; begin //刷新产品信息 with ADOTemp do begin Close; SQL.Clear; sql.Add(' select * from MV_Cloth_Sub '); sql.Add('where MVCMID=''' + Trim(FMVCMID) + ''''); sql.Add(' order by SerialNo '); Open; end; SCreateCDS(ADOTemp, Order_Sub); SInitCDSData(ADOTemp, Order_Sub); //刷新条款信息 with ADOTemp do begin Close; sql.Clear; sql.Add('select * from MV_Cloth_Main where MVCMID=''' + Trim(FMVCMID) + ''''); Open; end; SCSHData(ADOTemp, ScrollBox1, 2); BuyName.TxtCode := Trim(ADOTemp.FieldByName('BuyNo').AsString); Sellname.TxtCode := Trim(ADOTemp.FieldByName('SellNo').AsString); Fstatus := Trim(ADOTemp.FieldByName('status').AsString); if PState = '新增' then begin MVCDate.DateTime := SGetServerDateTime(ADOTemp); DlyDate.DateTime := MVCDate.DateTime; MVCNo.Text := '自动生成'; end; if PState = '复制' then begin PState := '新增'; FMVCMID := ''; MVCNo.Text := '自动生成'; with Order_Sub do begin First; while not Eof do begin if GetLSNo(ADOCmd, maxno, 'MVS', 'MV_Cloth_Sub', 4, 1) = False then begin Application.MessageBox('取子流水号失败!', '提示', 0); Exit; end; Edit; FieldByName('MVCMID').Value := ''; FieldByName('MVCSID').Value := maxno; Post; Next; end; end; end; end; procedure TfrmClothInquiryInPut.QiYunBtnUpClick(Sender: TObject); var fsj: string; FWZ: Integer; begin fsj := Trim(TEdit(Sender).Hint); FWZ := Pos('/', fsj); try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := Copy(fsj, 1, FWZ - 1); flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ); if ShowModal = 1 then begin TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmClothInquiryInPut.FormShow(Sender: TObject); begin inherited; readCxGrid(trim(self.Caption) + 'Tv1', Tv1, '询价管理'); readCxGrid(trim(self.Caption) + 'Tv2', Tv2, '询价管理'); fFlileFlag := UserDataFlag + 'HX'; InitData(); end; function TfrmClothInquiryInPut.SaveData(): Boolean; var maxno: string; fMVCNo, fmxType, fDate: string; begin try ADOCmd.Connection.BeginTrans; //////////////// 保存主表 ////////////////////// if Trim(FMVCMID) = '' then begin if GetLSNo(ADOTemp, maxno, 'MVM', 'MV_Cloth_Main', 3, 1) = False then raise Exception.Create('取最大号失败!'); fDate := 'XJ' + FormatDateTime('yy', SGetServerDate(ADOTemp)); if trim(MVCNo.Text) = '自动生成' then begin if GetLSNo(ADOTemp, fMVCNo, fDate, 'MV_Cloth_Main', 4, 0) = False then raise Exception.Create('取最报价编号失败!'); MVCNo.Text := fMVCNo; end; end else begin maxno := Trim(FMVCMID); end; with ADOCmd do begin Close; sql.Clear; SQL.Add('select * from MV_Cloth_Main where MVCMID=''' + Trim(FMVCMID) + ''''); Open; end; with ADOCmd do begin if Trim(FMVCMID) = '' then begin Append; FieldByName('Filler').Value := Trim(DName); FieldByName('status').Value := '0'; end else begin Edit; FieldByName('Editer').Value := Trim(DName); FieldByName('EditTime').Value := SGetServerDateTime(ADOTemp); end; FieldByName('MVCMID').Value := Trim(maxno); RTSetsavedata(ADOCmd, 'MV_Cloth_Main', ScrollBox1, 2); FieldByName('BuyNo').Value := Trim(BuyName.TxtCode); FieldByName('SellNo').Value := Sellname.TxtCode; FieldByName('MVCType').Value := '询价'; Post; end; with ADOCmd do begin Close; sql.Clear; sql.Add('select * from MV_Cloth_Main where MVCNo=''' + Trim(MVCNo.Text) + ''''); Open; end; if ADOCmd.RecordCount > 1 then raise Exception.Create('报价单号重复!'); FMVCMID := Trim(maxno); //////////////// 保存主表 ////////////////////// /// //////////////// 保存子表 ////////////////////// with Order_Sub do begin First; while not Eof do begin maxno := Trim(Order_Sub.fieldbyname('MVCSID').AsString); with ADOCmd do begin Close; SQL.Clear; sql.Add('select * from MV_Cloth_Sub '); sql.Add(' where MVCMID=''' + Trim(FMVCMID) + ''''); sql.Add(' and MVCSID=''' + Trim(maxno) + ''''); Open; end; with ADOCmd do begin if ADOCmd.IsEmpty then Append else Edit; RTSetSaveDataCDS(ADOCmd, Tv1, Order_Sub, 'MV_Cloth_Sub', 0); FieldByName('MVCMID').Value := Trim(FMVCMID); FieldByName('MVCSID').Value := Trim(maxno); Post; end; with Order_Sub do begin Edit; FieldByName('MVCSID').Value := Trim(maxno); Post; end; Next; end; end; //////////////// 保存子表 ////////////////////// /// //////////////// 更新报价 ////////////////////// // with ADOCmd do // begin // close; // sql.Clear; // sql.Add('EXEC P_Con_Up_PiQty '); // sql.Add('@DataID=' + quotedstr(Trim(FMVCMID))); // execsql; // end; //////////////// 更新报价 ////////////////////// ADOCmd.Connection.CommitTrans; Result := True; except ADOCmd.Connection.RollbackTrans; application.MessageBox(PChar(Exception(ExceptObject).Message), '提示信息', 0); Result := False; end; end; procedure TfrmClothInquiryInPut.TBSaveClick(Sender: TObject); begin MVCDate.SetFocus; if TestData() = false then exit; if SaveData() then begin Application.MessageBox('保存成功!', '提示', 0); end; end; procedure TfrmClothInquiryInPut.ToolButton1Click(Sender: TObject); var i: Integer; maxno: string; begin if GetLSNo(ADOCmd, maxno, 'MVS', 'MV_Cloth_Sub', 4, 1) = False then begin ADOCmd.Connection.RollbackTrans; Application.MessageBox('取子流水号失败!', '提示', 0); Exit; end; if Trim(MVCNo.Text) = '' then begin Application.MessageBox('报价号不能为空!', '提示', 0); Exit; end; i := Order_Sub.RecordCount; //当前的dataset有多少行记录 i := i + 1; CopyAddRow(Tv1, Order_Sub); with Order_Sub do begin Edit; FieldByName('SSEL').Value := FALSE; FieldByName('SerialNo').Value := i; FieldByName('MVCSID').Value := maxno; FieldByName('C_Color').Value := ''; FieldByName('Price').Value := null; Post; end; SetXH(); end; procedure TfrmClothInquiryInPut.ToolButton2Click(Sender: TObject); begin if Order_Sub.IsEmpty then Exit; if Application.MessageBox('确定要删除数据吗?', '提示', 32 + 4) <> IDYES then Exit; while Order_Sub.Locate('SSel', True, []) do begin with ADOTemp do begin Close; sql.Clear; sql.Add('select * from Trade_Plan_Sub where MVCSID=''' + Trim(Order_Sub.fieldbyname('MVCSID').AsString) + ''''); open; end; if ADOTemp.IsEmpty = false then begin exit; application.MessageBox('该明细已经在生产!', '提示信息'); end; if Trim(Order_Sub.fieldbyname('MVCSID').AsString) <> '' then begin with ADOCmd do begin Close; sql.Clear; sql.Add('delete MV_Cloth_Sub where MVCSID=''' + Trim(Order_Sub.fieldbyname('MVCSID').AsString) + ''''); ExecSQL; end; end; Order_Sub.Delete; end; SetXH(); end; procedure TfrmClothInquiryInPut.ToolButton3Click(Sender: TObject); begin WriteCxGrid(trim(self.Caption) + 'Tv1', Tv1, '询价管理'); WriteCxGrid(trim(self.Caption) + 'Tv2', Tv2, '询价管理'); end; procedure TfrmClothInquiryInPut.ToolButton4Click(Sender: TObject); begin GroupBox5.Visible := not GroupBox5.Visible; end; procedure TfrmClothInquiryInPut.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean); begin InitHistoricalPrice(); end; procedure TfrmClothInquiryInPut.BuyNameBtnUpClick(Sender: TObject); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '我司'; if ShowModal = 1 then begin self.BuyName.TxtCode := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString); self.BuyName.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString); end; end; finally frmCompanySel.Free; end; end; procedure TfrmClothInquiryInPut.BuyNameBtnDnClick(Sender: TObject); begin TBtnEditC(Sender).Text := ''; TBtnEditC(Sender).TxtCode := ''; end; procedure TfrmClothInquiryInPut.v1Column4PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'MPRTCodeName'; flagname := '产品名称'; if ShowModal = 1 then begin Order_Sub.Edit; Order_Sub.fieldbyname('PRTCodeName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); Order_Sub.fieldbyname('PRTCode').Value := Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString); Order_Sub.Post; end; end; finally frmZDYHelp.Free; end; tv1.Controller.EditingController.ShowEdit(); end; procedure TfrmClothInquiryInPut.v1Column6PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'C_MF'; flagname := '门幅信息'; if ShowModal = 1 then begin Order_Sub.Edit; Order_Sub.fieldbyname('C_MF').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); // Order_Sub.fieldbyname('PRTCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString); Order_Sub.Post; end; end; finally frmZDYHelp.Free; end; tv1.Controller.EditingController.ShowEdit(); end; procedure TfrmClothInquiryInPut.v1Column7PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); begin try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := 'C_KZ'; flagname := '克重信息'; if ShowModal = 1 then begin Order_Sub.Edit; Order_Sub.fieldbyname('C_KZ').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); // Order_Sub.fieldbyname('PRTCode').Value:=Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString); Order_Sub.Post; end; end; finally frmZDYHelp.Free; end; tv1.Controller.EditingController.ShowEdit(); end; procedure TfrmClothInquiryInPut.v1Column10PropertiesButtonClick(Sender: TObject; AButtonIndex: Integer); var MCYNo: string; begin frmClothInfoSel := TfrmClothInfoSel.Create(self); with frmClothInfoSel do begin if showmodal = 1 then begin Order_Sub.Edit; Order_Sub.fieldbyname('C_Code').Value := frmClothInfoSel.CDS_1.fieldbyname('C_Code').asstring; Order_Sub.fieldbyname('C_Name').Value := frmClothInfoSel.CDS_1.fieldbyname('C_Name').asstring; Order_Sub.fieldbyname('C_EName').Value := frmClothInfoSel.CDS_1.fieldbyname('C_EName').asstring; Order_Sub.fieldbyname('C_Spec').Value := frmClothInfoSel.CDS_1.fieldbyname('C_Spec').asstring; Order_Sub.fieldbyname('C_Composition').Value := frmClothInfoSel.CDS_1.fieldbyname('C_Composition').asstring; Order_Sub.fieldbyname('C_Color').Value := frmClothInfoSel.CDS_1.fieldbyname('C_Color').asstring; Order_Sub.fieldbyname('C_Width').Value := frmClothInfoSel.CDS_1.fieldbyname('C_Width').asstring; Order_Sub.fieldbyname('C_GramWeight').Value := frmClothInfoSel.CDS_1.fieldbyname('C_GramWeight').asstring; Order_Sub.Post; end; free; end; tv1.Controller.EditingController.ShowEdit(); end; procedure TfrmClothInquiryInPut.SalesmanBtnUpClick(Sender: TObject); var fsj: string; FWZ: Integer; begin fsj := Trim(TEdit(Sender).Hint); FWZ := Pos('/', fsj); try frmZDYHelp := TfrmZDYHelp.Create(Application); with frmZDYHelp do begin flag := Copy(fsj, 1, FWZ - 1); flagname := Copy(fsj, FWZ + 1, Length(fsj) - FWZ); if ShowModal = 1 then begin TEdit(Sender).Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString); end; end; finally frmZDYHelp.Free; end; end; procedure TfrmClothInquiryInPut.v1Column15PropertiesEditValueChanged(Sender: TObject); var mvalue: string; begin mvalue := TcxTextEdit(Sender).EditingText; if Trim(mvalue) = '' then begin mvalue := '0'; end; with Order_Sub do begin Edit; FieldByName('YongJinPrice').Value := mvalue; FieldByName('YongJin').Value := FieldByName('YongJinPrice').AsFloat * FieldByName('PRTOrderQty').AsFloat; Post; end; end; procedure TfrmClothInquiryInPut.SellNameBtnUpClick(Sender: TObject); begin try frmCompanySel := TfrmCompanySel.Create(Application); with frmCompanySel do begin FCoType := '供应商'; if ShowModal = 1 then begin self.Sellname.TxtCode := Trim(frmCompanySel.CDS_1.fieldbyname('CoCode').AsString); self.Sellname.Text := Trim(frmCompanySel.CDS_1.fieldbyname('CoAbbrName').AsString); end; end; finally frmCompanySel.Free; end; end; end.