unit u_op_seae_paper_manage; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, dxExEdtr, dxCntner, dxTL, dxDBCtrl, dxDBGrid, bsSkinCtrls, DB, ADODB, ExtCtrls, RxLookup, StdCtrls, wwdbdatetimepicker, wwdblook, Menus, Mask, bsSkinBoxCtrls, bsdbctrls,DateUtils, kbmMemTable, DBCtrlsEh, ComCtrls, bsSkinTabs, dxDBTLCl, dxGrClms, cxDBLabel, cxControls, cxContainer, cxEdit, cxLabel, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxDBEdit, cxLookupEdit, cxDBLookupEdit, cxDBLookupComboBox, DBCtrls; type Tfrm_op_seae_paper_manage = class(TForm) qry_paper_detail: TADOQuery; ds2_detail: TDataSource; PopupMenu1: TPopupMenu; N1: TMenuItem; bsSkinPageControl1: TbsSkinPageControl; bsSkinTabSheet1: TbsSkinTabSheet; bsSkinTabSheet2: TbsSkinTabSheet; bsSkinPanel3: TbsSkinPanel; btn6_exit: TbsSkinButton; btn_seach2: TbsSkinButton; bsSkinButton14: TbsSkinButton; bsSkinPanel4: TbsSkinPanel; Label13: TLabel; Label14: TLabel; wwDBDateTimePicker5: TwwDBDateTimePicker; wwDBDateTimePicker6: TwwDBDateTimePicker; dxDBGrid1: TdxDBGrid; PopupMenu2: TPopupMenu; MenuItem1: TMenuItem; Edit6_searchtdh: TEdit; Label8: TLabel; bsknpnl1: TbsSkinPanel; pnl2: TbsSkinPanel; qry1_paper_in: TADOQuery; Edit1_tdzbh: TEdit; lbl14: TLabel; bsknpnl4_NewQDT: TbsSkinPanel; lbl15_searchqdthm: TLabel; ds1: TDataSource; N2: TMenuItem; qry_crm_client: TADOQuery; ds_crm_client: TDataSource; dxdbgrdclmndxdbgrd1_SColumn2: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn3: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn4_noP: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn5_noB: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn6_noE: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn7: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn8: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column1: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column2: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column3: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column4: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column5: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column6: TdxDBGridColumn; dxdbgrd1_S: TdxDBGrid; dxdbgrdclmnDBGrid1Column7: TdxDBGridColumn; dxdbgrdclmndxdbgrd1_SColumn9: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column8: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column9: TdxDBGridColumn; dxdbgrdclmnDBGrid1Column10: TdxDBGridColumn; qry1_sel: TADOQuery; ds2_sel: TDataSource; lbl9: TLabel; cbb1_printstate: TbsSkinComboBox; lbl10: TLabel; cbb2_shipinc_paper: TRxDBLookupCombo; qry2_crm_client_paper: TADOQuery; ds2_crm_client_paper: TDataSource; btn4_exit: TbsSkinButton; btn1_Refresh: TbsSkinButton; btn4_cancel: TbsSkinButton; btn1_addPaper: TbsSkinButton; edt1_pagecount: TEdit; lbl1: TLabel; bskndbtxt1: TbsSkinDBText; lbl8: TLabel; cbb1: TRxDBLookupCombo; lbl6: TLabel; cbb3_GenNoList: TbsSkinComboBox; btn1_genNolist: TbsSkinButton; Edit3_endNo: TEdit; lbl7: TLabel; Edit2_startno: TEdit; lbl3: TLabel; Edit1_preno: TEdit; lbl2: TLabel; bsSkinPanel1: TbsSkinPanel; bsSkinGroupBox1: TbsSkinGroupBox; lbl5: TLabel; lbl4: TLabel; wdbdtmpckr2_kc: TwwDBDateTimePicker; wdbdtmpckr1_kc: TwwDBDateTimePicker; cbb2: TcxDBComboBox; btn4_searchNew: TbsSkinButton; procedure btn4_exitClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure btn3_clearConditonClick(Sender: TObject); procedure btn4_searchNewClick(Sender: TObject); procedure bsknpnl1Resize(Sender: TObject); procedure btn1_addPaperClick(Sender: TObject); procedure N1Click(Sender: TObject); procedure Edit3_ztdhKeyPress(Sender: TObject; var Key: Char); procedure dxdbgrd1_SDblClick(Sender: TObject); procedure dxdbgrdclmndxdbgrd1xdbgrdclmndxdbgrd1Column13CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure dxDBGrid2Column14CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); procedure MenuItem1Click(Sender: TObject); procedure btn6_exitClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure btn11Click(Sender: TObject); procedure searchqdt(bh:string); procedure Edit1_tdzbhKeyPress(Sender: TObject; var Key: Char); procedure dxDBGrid1DblClick(Sender: TObject); procedure N2Click(Sender: TObject); procedure bsSkinPageControl1Change(Sender: TObject); procedure FormResize(Sender: TObject); procedure bsSkinButton14Click(Sender: TObject); procedure edt1_pagecountKeyPress(Sender: TObject; var Key: Char); procedure Edit6_searchtdhKeyPress(Sender: TObject; var Key: Char); procedure btn_seach2Click(Sender: TObject); procedure cbb1Change(Sender: TObject); procedure btn1_genNolistClick(Sender: TObject); procedure btn1_RefreshClick(Sender: TObject); procedure wdbdtmpckr2_kcKeyPress(Sender: TObject; var Key: Char); procedure btn4_cancelClick(Sender: TObject); private { Private declarations } employeePhone:string; m_infomation:string; m_strNo_pre,m_strNo_start,m_strNo_end:string;//记录生成提单页号时的初始值 function CheckBilldue():Boolean; procedure bindPaperIn(); function genPaperno():Boolean; procedure inctypeChange(); public { Public declarations } op:integer; end; var frm_op_seae_paper_manage: Tfrm_op_seae_paper_manage; implementation uses u_main,my_sys_function, u_sys_progress ; {$R *.dfm} //const stateNewQD = '生成签单条'; // procedure Tfrm_op_seae_paper_manage.bindPaperIn(); var str:string; shipinc:string; begin //str:=cbb1.text; shipinc:= cbb1.DisplayValues[1] ; if shipinc<>'' then str:=' and 船公司简称='''+ shipinc + '''' ; if wdbdtmpckr1_kc.Text<>'' then str:=' and 录入日期>='''+ wdbdtmpckr1_kc.Text + '''' ; if wdbdtmpckr2_kc.Text<>'' then str:=' and 录入日期<='''+ wdbdtmpckr2_kc.Text + ' 23:59:59''' ; str:= 'select * from t_op_seae_paper_in where 1=1 ' + str ; with qry1_paper_in do begin close;sql.Clear; SQL.Add(str); Open; end; end; procedure Tfrm_op_seae_paper_manage.btn4_exitClick(Sender: TObject); begin Close; end; procedure Tfrm_op_seae_paper_manage.FormShow(Sender: TObject); var str,mblstatus:string; begin loadreggrid(dxdbgrd1_S,false,caption+'1'); loadreggrid(dxDBGrid1,false,caption+'2'); qry_crm_client.Close(); qry_crm_client.Open(); qry_crm_client.First; qry1_sel.Close(); qry1_sel.Open; // qry2_crm_client_paper.Close(); qry2_crm_client_paper.Open; bsSkinPageControl1.ActivePageIndex:=0; dxdbgrd1_S.Width:=self.ClientWidth; bsknpnl1.Height :=34; self.WindowState:= wsMaximized; wwDBDateTimePicker5.Date:=Date-7; ;//StrToDateTime(Formatdatetime('YYYY-MM-DD',date-7)); wwDBDateTimePicker6.Date:=Date;//StrToDateTime(Formatdatetime('YYYY-MM-DD',date)); inctypeChange(); end; procedure Tfrm_op_seae_paper_manage.FormClose(Sender: TObject; var Action: TCloseAction); begin savereggrid(dxdbgrd1_S,caption+'1'); savereggrid(dxDBGrid1,caption+'2'); frm_op_seae_paper_manage.Hide; frm_op_seae_paper_manage.ManualFloat(frm_op_seae_paper_manage.BoundsRect ); frm_main.freeTabs('frm_op_seae_paper_manage'); action:=cafree; frm_op_seae_paper_manage:=nil; end; procedure Tfrm_op_seae_paper_manage.btn3_clearConditonClick(Sender: TObject); begin //Edit1_ywbh.text:=''; //Edit2_wtbh.text:=''; end; function replaceSQuotes(txt: string):string; begin result:=stringreplace(txt,'''','''''',[rfReplaceAll]); end; procedure Tfrm_op_seae_paper_manage.btn4_searchNewClick(Sender: TObject); var str,mblstatus:widestring; begin bindPaperIn(); end; procedure Tfrm_op_seae_paper_manage.bsknpnl1Resize(Sender: TObject); var i:integer; begin // i:=round(bsSkinPanel1.Width/11); // bsSkinButton9.Width:=i; //bsSkinButton1.Width:=i; end; procedure Tfrm_op_seae_paper_manage.btn1_addPaperClick(Sender: TObject); var str:widestring; ipagecount:integer;//入库的提单纸张数 aQuery:TAdoQuery; //qdm_Query:TAdoQuery; paperd_Query:TAdoQuery; info:string; strwtdw1,strwtdw2,zhtdh:string; dbTime:TDateTime; strNo_pre,strNo_start,strNo_end:string; blIsHasPaperNo:Boolean;//提单纸是否有编号 shipinc:string;//船公司 inputNo:Integer; i:Integer; begin strNo_pre:=''; strNo_start:=''; strNo_end:=''; shipinc:= cbb1.DisplayValues[1] ; if shipinc ='' then begin Application.MessageBox(pchar('船公司不能为空,请选择船公司'),PChar('信息提示'),MB_ICONINFORMATION); Exit; end; blIsHasPaperNo:=qry_crm_client.fieldbyname('提单纸是否编号').AsBoolean; if(blIsHasPaperNo) then begin if(cbb3_GenNoList.Items.count<1) then begin Application.MessageBox(pchar('请先生成提单纸编号!'),PChar('信息提示'),MB_ICONINFORMATION); Exit; end; strNo_pre :=trim(Edit1_preno.text); strNo_start:=trim(Edit2_startno.text); strNo_end :=Trim(Edit3_endNo.text); if(strNo_start<>m_strNo_start) or (strNo_end<>m_strNo_end) then begin Application.MessageBox(pchar('生成提单纸号后,输入的起始号码和结束号码已经改变!' +#13#10+'请重新生成提单纸号!'),PChar('信息提示'),MB_ICONINFORMATION); Exit; end; //检查号码是否已经存在 aQuery:=CreateAdoQuery(); str:='select count(1) as f_count from [t_op_seae_paper_detail] ' +' where 船公司简称=''' + cbb1.DisplayValues[1] +''' and [提单纸号]>='''+ strNo_start + ''' and [提单纸号]<='''+ strNo_end+''' and 入库序号 in (select 序号 from t_op_seae_paper_in where 船公司简称='''+cbb1.DisplayValues[1]+''' and 前缀号码='''+Trim(Edit1_preno.Text)+''')' ; with aQuery do begin close; sql.Clear; SQL.Add(str); Open; if(fieldbyname('f_count').asinteger >0 ) then begin // info:='有' +inttostr( fieldbyname('f_count').asinteger) +'张提单纸号已经存在,请确认'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); close; Exit; end; aQuery:=nil; end; end; ipagecount:=strtoint(trim(edt1_pagecount.Text)); if(ipagecount<1) then begin Application.MessageBox(pchar('请输入提单纸数量!'),PChar('信息提示'),MB_ICONINFORMATION); Exit; end; if(ipagecount>1000) then begin if(Application.MessageBox(pchar('当前要入库的提单纸为'+ inttostr(ipagecount) +'张,入库的提单纸超过1000张请确定是否继续入库?'+#13#10+'选是(Y)继续,否则取消本次入库'),'信息提醒' ,MB_ICONQUESTION+MB_YESNO) <> ID_YES) then Exit; end; // str:= 'INSERT INTO [t_sys_paperid] ([inputperson]) VALUES ('''+ employee +''');'; aQuery:=CreateAdoQuery(); aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add(str) ; aQuery.ExecSQL(); aQuery.sql.Clear(); str:= 'select MAX(paperid) as inputNo,GETDATE()as FDate from t_sys_paperid; '; aQuery.sql.add(str); aQuery.Open; aQuery.First; inputNo:=aQuery.FieldByName('inputNo').AsInteger; dbTime:=aQuery.FieldByName('FDate').AsDateTime; aQuery.Close; try frm_main.db.BeginTrans; //船公司表 //3b修改总数 aQuery.Close; aQuery.SQL.Clear; aQuery.SQL.Add('UPDATE [t_op_seae_paper_shipinc] ' + ' SET [提单纸剩余数量] = 提单纸剩余数量+ '+inttostr(ipagecount ) + ' WHERE [船公司简称] = ''' + cbb1.DisplayValues[1] +''''); aQuery.ExecSQL; //入库 with qry1_paper_in do begin Insert; FieldByName('序号').AsInteger := inputNo; FieldByName('船公司简称').AsString := shipinc; FieldByName('操作类型').AsString := '入库'; FieldByName('纸张数量').AsInteger := ipagecount; FieldByName('前缀号码').AsString := strNo_pre ; FieldByName('起始号码').AsString := strNo_start; FieldByName('结束号码').AsString := strNo_end; FieldByName('备注').AsString := ''; FieldByName('录入人').AsString := employee; FieldByName('录入日期').AsDateTime := DatabaseDateTime; end; //qry_crm_client.Post; qry1_paper_in.Post; if(blIsHasPaperNo) then begin paperd_Query:=CreateAdoQuery(); paperd_Query.Close; paperd_Query.SQL.Clear; paperd_Query.SQL.Add('select * from t_op_seae_paper_detail where 1=2'); paperd_Query.Open; // 循环插入提单纸 for i:=0 to cbb3_GenNoList.Items.count-1 do begin // with paperd_Query do begin Insert; FieldByName('入库序号').AsInteger := inputNo; FieldByName('船公司简称').AsString := shipinc; FieldByName('提单纸号').AsString := cbb3_GenNoList.Items[i]; end; end; paperd_Query.Post(); paperd_Query.Close(); cbb3_GenNoList.Items.Clear; end; frm_main.db.CommitTrans; except on ex: Exception do begin qry_crm_client.Cancel; qry1_paper_in.Cancel; frm_main.db.RollbackTrans; errorlog(ex.Message) ; Application.MessageBox(PChar('入库失败:'+ex.Message),'',MB_ICONWARNING); bindPaperIn(); Exit; end; end; qry_crm_client.Close(); qry_crm_client.Open(); dxdbgrd1_S.ClearSelection(); bindPaperIn(); // end; procedure Tfrm_op_seae_paper_manage.N1Click(Sender: TObject); begin //grid_save_xls(dxdbgrd2); end; procedure Tfrm_op_seae_paper_manage.Edit3_ztdhKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin key:=#0; //bsSkinButton8Click(Sender); end; end; procedure Tfrm_op_seae_paper_manage.dxdbgrd1_SDblClick(Sender: TObject); begin // end; procedure Tfrm_op_seae_paper_manage.dxdbgrdclmndxdbgrd1xdbgrdclmndxdbgrd1Column13CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin { if Trim(ANode.Strings[dxDBGrid2Column13.Index])<>'' then AColor:=clred; AFont.Color:=clblack; } end; procedure Tfrm_op_seae_paper_manage.dxDBGrid2Column14CustomDraw(Sender: TObject; ACanvas: TCanvas; ARect: TRect; ANode: TdxTreeListNode; AColumn: TdxDBTreeListColumn; const AText: String; AFont: TFont; var AColor: TColor; ASelected, AFocused: Boolean; var ADone: Boolean); begin {if Trim(ANode.Strings[dxDBGrid2Column14.Index])<>'' then AColor:=clred; AFont.Color:=clblack; } end; procedure Tfrm_op_seae_paper_manage.MenuItem1Click(Sender: TObject); begin grid_save_xls(dxDBGrid1); end; procedure Tfrm_op_seae_paper_manage.btn6_exitClick(Sender: TObject); begin Close; end; procedure Tfrm_op_seae_paper_manage.btn11Click(Sender: TObject); begin bsSkinPageControl1.Pages[0].Visible:=true; bsSkinPageControl1.Pages[1].Visible:=true; bsSkinPageControl1.ActivePageIndex:=0; end; procedure Tfrm_op_seae_paper_manage.searchqdt(bh:string); begin // if bh<>'' then begin // end; end; procedure Tfrm_op_seae_paper_manage.Edit1_tdzbhKeyPress(Sender: TObject; var Key: Char); var str:string; begin // if key=#13 then begin end; end; procedure Tfrm_op_seae_paper_manage.dxDBGrid1DblClick(Sender: TObject); var str:string; begin end; /// /// 检查客户是否欠费 /// function Tfrm_op_seae_paper_manage.CheckBilldue():Boolean; var FeeItems:string; amt,usd:Double; wtdw,tdh,bh,jflx:string; begin Result:=True; if(cbb3_GenNoList.Items.count<1) then begin Application.MessageBox('请生成提单纸号码!','信息提示',MB_ICONINFORMATION); Result:=False; Exit; end; //判断号码是否已经存在 end; //end CheckBilldue procedure Tfrm_op_seae_paper_manage.N2Click(Sender: TObject); var i:Integer; info,strXH,str:string; begin // 如果选择的纸 未使用,可进行纸张作废 if( dxDBGrid1.SelectedCount<1) then Exit; try qry2_crm_client_paper.DisableControls; strXH:=''; for i:=0 to dxDBGrid1.SelectedCount-1 do begin qry2_crm_client_paper.GoTobookmark(pointer(dxDBGrid1.SelectedRows[i])); //状态 if( qry2_crm_client_paper.fieldbyname('使用状态').AsString<>'未打印') then begin //空白纸作废 info:='空白纸作废只能选择未使用的空白纸'; Application.MessageBox(pchar(info),'信息提示',MB_ICONINFORMATION); Exit; end; // if(strXH='') then strXH:=qry2_crm_client_paper.fieldbyname('序号').AsString else strXH := strXH +','+ qry2_crm_client_paper.fieldbyname('序号').AsString; end; //更新状态同时修改库存 str:=''; finally qry2_crm_client_paper.EnableControls; end; end; procedure Tfrm_op_seae_paper_manage.bsSkinPageControl1Change(Sender: TObject); begin // end; procedure Tfrm_op_seae_paper_manage.FormResize(Sender: TObject); begin // bsSkinTabSheet1.Width:=self.ClientWidth; end; procedure Tfrm_op_seae_paper_manage.bsSkinButton14Click(Sender: TObject); begin wwDBDateTimePicker5.text:=''; wwDBDateTimePicker6.text:=''; Edit1_tdzbh.text:=''; Edit6_searchtdh.text:=''; end; procedure Tfrm_op_seae_paper_manage.edt1_pagecountKeyPress(Sender: TObject; var Key: Char); begin if not (Key in [#8, #13, #127, '.', '-', '0'..'9']) then Key := #0; end; procedure Tfrm_op_seae_paper_manage.Edit6_searchtdhKeyPress(Sender: TObject; var Key: Char); begin if key=#13 then begin end; end; procedure Tfrm_op_seae_paper_manage.btn_seach2Click(Sender: TObject); var str,strorder,strChgs,strtmp:string; begin strChgs:= cbb2_shipinc_paper.DisplayValues[1] ; if(strChgs='') then begin Application.MessageBox('请选择船公司','信息提醒',MB_ICONINFORMATION); exit; end; str:=''; str:=' AND d.船公司简称= ''' +strChgs +''' '; strtmp:= StringReplace(trim(Edit1_tdzbh.text),'''','',[rfReplaceAll]); if Edit1_tdzbh.text<>'' then str:=str + ' AND d.提单纸号 like ''%' +strtmp +'%'''; strtmp:= StringReplace(trim(Edit6_searchtdh.text),'''','',[rfReplaceAll]); if strtmp<>'' then str:=str + ' AND d.提单号 like ''%' +strtmp +'%'''; if cbb1_printstate.ItemIndex>0 then //0 为<无> str:=str + ' AND isnull(d.[使用状态],''未打印'')='''+cbb1_printstate.Text+''' ' ; // str:='SELECT d.[序号],d.[入库序号],d.[船公司简称],d.[提单纸号],d.[提单编号],' +'d.[提单号],d.[页号],d.[总页数],isnull(d.[使用状态],''未打印'') as [使用状态]' +',d.[操作人],d.[操作时间],d.[备注],d.[是否作废],d.[打印台账序号] ' +',m.录入人 as 入库人,m.录入日期 as 入库日期 FROM ' +' [t_op_seae_paper_detail] d,t_op_seae_paper_in m where d.入库序号=m.序号 ' + str; strorder :=' order by 入库序号,提单纸号'; if(qry2_crm_client_paper.FieldByName('纸张使用是否降序').AsBoolean) then strorder:= strorder + ' desc'; str:=str+strorder; //dxDBGrid1.Filter.Clear(); with qry_paper_detail do begin Close; SQL.Clear; SQL.Add(str); Open; end; end; procedure Tfrm_op_seae_paper_manage.cbb1Change(Sender: TObject); begin inctypeChange(); end; procedure Tfrm_op_seae_paper_manage.inctypeChange(); var blbh:Boolean; //是否编号 begin //qry_crm_client.Active:=False; //qry_crm_client.Active:= True; blbh:= (cbb1.DisplayValues[1]<>'') and qry_crm_client.fieldbyname('提单纸是否编号').AsBoolean; dxdbgrdclmndxdbgrd1_SColumn4_noP.Visible:= ((cbb1.DisplayValues[1]='') or blbh); dxdbgrdclmndxdbgrd1_SColumn5_noB.Visible:= ( (cbb1.DisplayValues[1]='') or blbh); dxdbgrdclmndxdbgrd1_SColumn6_noE.Visible:= ( (cbb1.DisplayValues[1]='') or blbh); pnl2.Visible:=blbh; if(blbh) then begin // if(pnl2.Visible=false) then // bsknpnl2.Height:= bsknpnl2.Height+pnl2.Height; //自动编号时锁定 页数输入文本框 edt1_pagecount.ReadOnly:=true; edt1_pagecount.text:='0'; end else begin // if(pnl2.Visible=true) or (bsknpnl2.Height>60) then // bsknpnl2.Height:= bsknpnl2.Height-pnl2.Height; cbb3_GenNoList.Items.Clear; edt1_pagecount.text:='0'; if cbb1.DisplayValues[1]<>'' then //无编号且船公司不为空 edt1_pagecount.ReadOnly:=False; end; bindPaperIn(); // end; procedure Tfrm_op_seae_paper_manage.btn1_genNolistClick(Sender: TObject); begin try genPaperno(); except on ex:exception do begin Application.MessageBox(PChar('生成提单纸号码失败:'+EX.Message),'',MB_ICONWARNING); end; end; end; function Tfrm_op_seae_paper_manage.genPaperno():Boolean; var i,istart,iend,ipageNoLen,Icount,icheckcount :integer; info,strStart,strEnd,strtmpNo,str00,str:string; aQuery:TAdoQuery; begin Result:=true; strStart:= Trim(Edit2_startno.text); strEnd:=Trim(Edit3_endNo.text); if(strStart='') or (strEnd='') then begin info:='格式错误:起始号码和结束号码不能为空'; Result:=false; Exit; end; ipageNoLen:=length(strEnd); if Length(strStart)<>ipageNoLen then begin info:='起始号码和结束号码长度不一致,请确认'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); Result:=false; Edit3_endNo.SetFocus; Exit; end; // info:='格式错误:起始号码和结束号码必须全为数字[0-9]'; try istart:=StrToInt(strStart) except Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); Result:=false; Edit2_startno.SetFocus; exit; end; try iend:=StrToInt(strEnd) except Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); Result:=false; Edit3_Endno.SetFocus; exit; end; icount := iend- istart; if(Icount<=0) then begin info:='[起始号码]必须小于[结束号码],请确认'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); Result:=false; Edit3_endNo.SetFocus; Exit; end; if(Icount>2000) then begin info:='生成的提单纸页数为:'+inttostr(Icount) +',已经超过了2000张,超过限制页数,请确认录入的纸张编号是否正确!'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONWARNING); Result:=false; Edit3_endNo.SetFocus; Exit; end; //检查号码是否已经存在 aQuery:=CreateAdoQuery(); str:='select count(1) as f_count from [t_op_seae_paper_detail] ' +' where 船公司简称=''' + cbb1.DisplayValues[1] +''' and [提单纸号]>='''+ strStart + ''' and [提单纸号]<='''+ strEnd+''' and 入库序号 in (select 序号 from t_op_seae_paper_in where 船公司简称='''+cbb1.DisplayValues[1]+''' and 前缀号码='''+Trim(Edit1_preno.Text)+''')' ; with aQuery do begin close; sql.Clear; SQL.Add(str); Open; if(fieldbyname('f_count').asinteger >0) then begin // info:='有' +inttostr( fieldbyname('f_count').asinteger) +'张提单纸号已经存在,请确认'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); Result:=false; Result:=false; close; exit; end; aQuery:=nil; end; //生成提单纸编号 ipageNoLen str00:='0000000000000000000'; cbb3_GenNoList.Items.Clear; cbb3_GenNoList.Items.Add(strStart); for i:=1 to icount-1 do begin istart:=istart+1; strtmpNo:=Copy(str00,1,ipageNoLen- Length(inttostr(istart)))+inttostr(istart); cbb3_GenNoList.Items.Add(strtmpNo); end; cbb3_GenNoList.Items.Add(strEnd); cbb3_GenNoList.ItemIndex:=0; // m_strNo_pre:= trim(Edit1_preno.text); m_strNo_start:= strStart; m_strNo_end:=strEnd; edt1_pagecount.Text :=inttostr(icount+1); if(Icount>100) then begin info:='生成的提单纸页数为:'+inttostr(Icount) +',已经超过了100张,请确认录入的纸张编号是否正确!'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONWARNING); end; end; procedure Tfrm_op_seae_paper_manage.btn1_RefreshClick(Sender: TObject); begin qry_crm_client.Close(); qry_crm_client.Open(); end; procedure Tfrm_op_seae_paper_manage.wdbdtmpckr2_kcKeyPress(Sender: TObject; var Key: Char); begin // 回车自动查询 if key=#13 then begin btn4_searchNewClick(btn4_searchNew); end; end; procedure Tfrm_op_seae_paper_manage.btn4_cancelClick(Sender: TObject); var rkxh,chgsh,str,info:string ; aQuery:TADOQuery; iPages:Integer; begin //入库序号的纸张是否使用 if(dxdbgrd1_S.SelectedCount<1) then begin Application.MessageBox('请选择要取消的入库序号','信息提示',MB_ICONINFORMATION); Exit; end; rkxh:= qry1_paper_in.fieldbyname('序号').AsString ; chgsh:= qry1_paper_in.fieldbyname('船公司简称').AsString ; iPages:= qry1_paper_in.fieldbyname('纸张数量').AsInteger ; // //检查号码是否已经存在 aQuery:=CreateAdoQuery(); str:=' select count(1) as f_count from t_op_seae_paper_detail ' +' where 入库序号='+ rkxh + ' and isnull(使用状态,''未使用'')<>''未使用''' ; with aQuery do begin close; sql.Clear; SQL.Add(str); Open; if(fieldbyname('f_count').asinteger >0 ) then begin // info:='有' +inttostr( fieldbyname('f_count').asinteger) +'纸号已经使用不能取消入库,请确认'; Application.MessageBox(PChar(info) ,'信息提示',MB_ICONINFORMATION); close; Exit; end; aQuery:=nil; end; //取消入库 info:='有' +inttostr(iPages) +'纸号将要取消入库,确实要取消入库吗?'; if( Application.MessageBox(PChar(info) ,'信息提示',mb_iconquestion+mb_yesno)<>id_yes) then Exit; str:=' delete from t_op_seae_paper_detail where 入库序号='+rkxh+';' +#13#10 +'update t_op_seae_paper_shipinc set 提单纸剩余数量= 提单纸剩余数量-'+inttostr(iPages) +' where 船公司简称='''+chgsh +'''; ' +#13#10 +'delete from t_op_seae_paper_in where 序号='+rkxh+';'; try frm_main.db.BeginTrans; frm_main.db.execute(str); frm_main.db.CommitTrans; qry_crm_client.Active:=False; qry_crm_client.Active:=True; inctypeChange(); except on ex: Exception do begin frm_main.db.RollbackTrans; errorlog(ex.Message) ; Application.MessageBox(PChar('取消入库失败:'+ex.Message),'',MB_ICONWARNING); Exit; end; end; end; end.