?? khhjgl.~pas
字號:
unit khhjgl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, jpeg, Mask, Grids, DBGrids, DB;
type
TForm30 = class(TForm)
Image1: TImage;
Panel1: TPanel;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
Panel4: TPanel;
Label3: TLabel;
Label4: TLabel;
Label12: TLabel;
Label6: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Edit8: TEdit;
Label9: TLabel;
Label1: TLabel;
Label2: TLabel;
MaskEdit1: TMaskEdit;
Label5: TLabel;
Label7: TLabel;
Shape1: TShape;
Label8: TLabel;
Label10: TLabel;
Shape2: TShape;
Label11: TLabel;
Edit4: TEdit;
StringGrid1: TStringGrid;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure FormShow(Sender: TObject);
Procedure ClearStrings;
Function JCxmlb: Boolean;
procedure BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BitBtn3Click(Sender: TObject);
procedure MaskEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
Function SumPrice: Real;
Function Kinds: Integer;
Function IsNull: Boolean;
Function SumSL: integer;
Procedure Clear;
Procedure ClearStringEnd;
Procedure ClearString;
Function CurrentIsCF: Boolean;
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure DBGrid1DblClick(Sender: TObject);
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit8Exit(Sender: TObject);
procedure Edit8KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit8KeyPress(Sender: TObject; var Key: Char);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form30: TForm30;
x,y: Integer;
Ss:Boolean = False ;//判斷當焦點在StringGrid1上時是否按回車鍵
s1: Boolean = False;//在StringGrid1的OnSetEditText事件中是否執行相關代碼,其作用是防止連續出現對話框
s2: Boolean = False; //在StringGrid1的OnSetEditText事件中是否執行相關代碼,其作用是防止刪除行時,統計的數量金額錯誤
implementation
uses Data2,wlzgl;
{$R *.dfm}
procedure TForm30.FormShow(Sender: TObject);
begin
StringGrid1.Cells[0,0]:=' 客戶編號';
StringGrid1.Cells[1,0]:=' 客戶名稱';
StringGrid1.Cells[2,0]:=' 商品編號';
StringGrid1.Cells[3,0]:=' 商品名稱';
StringGrid1.Cells[4,0]:=' 數量';
StringGrid1.Cells[5,0]:=' 金額';
StringGrid1.Cells[6,0]:=' 折扣';
Edit4.Text := czymc;
end;
procedure TForm30.BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
TBitBtn(Sender).Font.Color := clRed;
end;
procedure TForm30.BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
TBitBtn(Sender).Font.Color := clBlue;
end;
procedure TForm30.BitBtn3Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
Label7.Caption := FormatDateTime('yyyy-mm-dd',Now());
s:= 'HP'+ FormatDateTime('yyyymmdd',Now());
With datam.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(單據編號) as ss From 客戶集中呼叫票號表 ');
Open;
end;
If datam.ADOQuery1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(datam.ADOQuery1.FieldByName('ss').Value) ;
i:= StrToInt(Trim(Copy(m,11,5))) ;
if i<9 then
s:= s + '00'+ InttoStr(i +1)
else if i<99 then
s:= s + '0'+ InttoStr(i +1)
else
s:= s +InttoStr(i +1);
end;
Label10.Caption := s;
MaskEdit1.SetFocus;
end;
procedure TForm30.MaskEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = Vk_ReTurn then
if Trim(MaskEdit1.Text)<>'' then
begin
if (Trim(Label7.Caption)='')or(Trim(Label10.Caption)='')then
begin
Application.MessageBox('請添加單據編號或呼叫時間。','提示',64);
BitBtn3.SetFocus;
Exit;
end;
with datam.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 客戶基礎信息表 where 電話 = :a');
Parameters.ParamByName('a').Value := Trim(MaskEdit1.Text);
Open;
end;
if datam.ADOQuery1.RecordCount>0 then
begin
MaskEdit1.ReadOnly := True;
StringGrid1.Cells[6,StringGrid1.RowCount-1]:= '1.0';
StringGrid1.Cells[0,StringGrid1.RowCount-1] := datam.ADOQuery1.FieldByName('客戶編號').Value;
StringGrid1.Cells[1,StringGrid1.RowCount-1] := datam.ADOQuery1.FieldByName('客戶全稱').Value;
end
else
begin
Application.MessageBox('該號碼不存在。','提示',64);
MaskEdit1.Clear;
MaskEdit1.SetFocus;
Exit;
end;
StringGrid1.SetFocus;
StringGrid1.Col := 3;
end;
end;
procedure TForm30.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
y := ACol;
x := ARow;
if (ACol = 3)and( Trim(StringGrid1.Cells[2,x])='')or(ACol = 4)and(Trim(StringGrid1.Cells[2,x])<>'') then
StringGrid1.Options := StringGrid1.Options +[goEditing]
else
StringGrid1.Options := StringGrid1.Options -[goEditing];
end;
procedure TForm30.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
mm: Boolean;
begin
if y = 4 then
begin
mm := (Key <#8)or(Key >#8)and(Key<#48)or(Key>#57);
if mm then
Key := #0;
end;
end;
procedure TForm30.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
R,L: Integer;
cp: String;// 記錄當前行的價格
cl: String;//記錄當前行的數量
begin
S1 := False;
s2 := False;
ss := False;
if key = VK_Delete then
begin
if StringGrid1.RowCount>2 then
begin
If Application.MessageBox('確實要刪除該條記錄嗎?','提示',MB_YESNO )= ID_Yes then
begin
if IsNull = False then
begin
cl := StringGrid1.Cells[4,x];
cp := StringGrid1.Cells[5,x];
if CurrentIsCf = False then
Label15.Caption := IntToStr(StrToInt(Label15.Caption)-1);
end;
ClearString;
if x <> StringGrid1.RowCount-1 then
begin
For r := x+1 to StringGrid1.RowCount-1 do
For l := 0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[l,r-1]:= StringGrid1.Cells[l,r];
end;
ClearStringEnd;
StringGrid1.RowCount := StringGrid1.RowCount-1;
s2 := True;
if Trim(cl)<>'' then
Label16.Caption := IntToStr(StrToInt(Label16.Caption)- StrToInt(cl));
if Trim(cp)<>'' then
Label17.Caption := FloatToStr(StrToFloat(Label17.Caption)-StrToFloat(cp));
Exit;
end;
end
else if StringGrid1.RowCount = 2 then
begin
If Application.MessageBox('確實要刪除該條記錄嗎?','提示',MB_YESNO )= ID_Yes then
begin
ClearString;
Label15.Caption := '0';
Label16.Caption :='0';
Label17.Caption := '0.0';
StringGrid1.SetFocus;
StringGrid1.Col := 3;
end;
end;
end;
if (key = Vk_Next)and(DBGrid1.Visible = True)then
begin
DBGrid1.SetFocus;
Exit;
end;
if (Key = VK_Down)and(IsNull = False)and(x = StringGrid1.RowCount-1) then
begin
StringGrid1.RowCount := StringGrid1.RowCount+1;
StringGrid1.Cells[0,StringGrid1.RowCount-1]:= StringGrid1.Cells[0,StringGrid1.RowCount-2];
StringGrid1.Cells[1,StringGrid1.RowCount-1]:= StringGrid1.Cells[1,StringGrid1.RowCount-2];
StringGrid1.Cells[6,StringGrid1.RowCount-1]:= '1.0';
StringGrid1.Col := 3;
Exit;
end;
if Key = Vk_ReTurn then
if Trim(StringGrid1.Cells[2,x])='' then
begin
Ss := True;
DataSource1.DataSet := Nil;
DBGrid1.Visible := False;
with datam.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 商品基礎信息表 where 商品名稱 = :a ');
Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[3,x]);
Open;
end;
if datam.ADOQuery1.RecordCount>0 then
If datam.ADOQuery1.RecordCount>1 then
begin
DataSource1.DataSet := datam.ADOQuery1;
DBGrid1.Visible := True;
end
else
begin
StringGrid1.Cells[2,x]:= datam.ADOQuery1.FieldByName('商品編號').Value;
StringGrid1.Cells[3,x]:= datam.ADOQuery1.FieldByName('商品名稱').Value;
StringGrid1.SetFocus;
StringGrid1.Col := 4;
end
else
begin
Application.MessageBox('該商品不存在。','提示',64);
ClearStrings;
StringGrid1.SetFocus;
end;
end;
if (Key = VK_Shift)and(JCxmlb = True) then
BitBtn4.SetFocus;
end;
procedure TForm30.ClearStrings;
begin
StringGrid1.Cells[2,x]:= '';
StringGrid1.Cells[3,x]:= '';
StringGrid1.Cells[4,x]:= '';
StringGrid1.Cells[5,x]:= '';
end;
procedure TForm30.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var
Jg: Real;
a1: Integer;
begin
Jg := 0.0;
if (Trim(StringGrid1.Cells[2,x])<>'')and(Trim(StringGrid1.Cells[3,x])<>'')then
if (Trim(StringGrid1.Cells[4,x])<>'')and(s2 = False) then
begin
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -