📄 uform_custom_edit.~pas
字号:
unit Uform_custom_edit;
//客户管理窗口,用于设置各个客户的相关属性
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, DB, ADODB, ComCtrls, StdCtrls, Buttons, ExtCtrls,
ToolWin;
type
Tform_custom_edit = class(TForm)
Panel1: TPanel;
Image1: TImage;
Label2: TLabel;
Label4: TLabel;
Label3: TLabel;
Label1: TLabel;
Bevel1: TBevel;
Image2: TImage;
recordset_temp: TADOQuery;
ImageList1: TImageList;
Apart_list: TListView;
Panel2: TPanel;
button_add: TBitBtn;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure button_addClick(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
intCount:integer;
end;
var
form_custom_edit: Tform_custom_edit;
implementation
uses Uform_custom_input, Uform_main, Uform_use_dollor;
{$R *.dfm}
procedure Tform_custom_edit.BitBtn3Click(Sender: TObject);
//关闭窗口
begin
close;
end;
procedure Tform_custom_edit.BitBtn1Click(Sender: TObject);
//向数据库中添加新客户
var
ListItem: TListItem;
p:^integer;
temp:string;
begin
//不断将用户输入的客户名称添加到数据库,直至用户希望停止为止
repeat
//初始化新增客户窗口的内容
form_custom_input.Caption :='客户管理';
form_custom_input.Label1.Caption :='客户管理';
form_custom_input.Label2.Caption :='客户管理';
form_custom_input.string_custom_id :='';
form_custom_input.string_mname :='';
form_custom_input.string_fname :='';
form_custom_input.string_tel :='';
form_custom_input.string_address :='';
form_custom_input.string_postcode :='';
form_custom_input.int_area :=0;
form_custom_input.int_from :=0;
//显示新增客户窗口
form_custom_input.ShowModal ;
//判断用户是否正确输入新增客户名称
if form_custom_input.bYesno =false then exit;
//将输入内容添进数据库
temp:='insert into [CUSTOM]' +
'([CUSTOM_CODE],[CUSTOM_MNAME],[CUSTOM_FNAME],[CUSTOM_TEL],[CUSTOM_AREA],[CUSTOM_ADD],[CUSTOM_FROM],[CUSTOM_POST],[CUSTOM_DATE])' +
' values(''' + form_custom_input.string_custom_id +''',''' + form_custom_input.string_mname + ' '',''' +
form_custom_input.string_fname + ' '','''+
form_custom_input.string_tel + ' '','+
inttostr(form_custom_input.int_area )+ ','''+
form_custom_input.string_address + ' '',' +
inttostr(form_custom_input.int_from)+ ','''+
form_custom_input.string_postcode + ''',#' +
datetimetostr(now)+ '#)';
form_main.Dconnect.Execute (temp);
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add ('select [CUSTOM_ID],[CUSTOM_CODE],[CUSTOM_MNAME],[CUSTOM_FNAME],[CUSTOM_TEL],[AREA_NAME],[CUSTOM_ADD],[FROM_NAME],[CUSTOM_POST],[CUSTOM_DATE] ' +
'from [CUSTOM],[AREA],[FROM] '+
'where [CUSTOM_AREA]=[AREA_ID] and [CUSTOM_FROM]=[FROM_ID]');
recordset_temp.Open ;
recordset_temp.Last ;
//更新客户列表的内容
listitem:=apart_LIST.Items.Add ;
listitem.Caption :=recordset_temp.Fields[1].AsString ;
listitem.ImageIndex :=0;
listitem.SubItems.Add(recordset_temp.Fields[2].asstring);
listitem.SubItems.Add(recordset_temp.Fields[3].asstring);
listitem.SubItems.Add(recordset_temp.Fields[4].asstring);
listitem.SubItems.Add(recordset_temp.Fields[5].asstring);
listitem.SubItems.Add(recordset_temp.Fields[6].asstring);
listitem.SubItems.Add(recordset_temp.Fields[7].asstring);
listitem.SubItems.Add(recordset_temp.Fields[8].asstring);
listitem.SubItems.Add(DateTimeToStr(recordset_temp.Fields[9].AsDateTime));
new(p);
p^ := recordset_temp.Fields[0].AsInteger ;
listitem.Data :=p;
//更新客户数量
intCount := intCount+1;
Label4.Caption :=inttostr(intCount) + '名';
until messagebox(self.Handle ,'您是否还要登记新的客户?','提示',MB_YESNO or MB_ICONASTERISK)<> IDYES;
end;
procedure Tform_custom_edit.FormShow(Sender: TObject);
//在本窗口开启时调用数据库内容初始化窗口内容
var
i:integer;
ListItem: TListItem;
p:^integer;
begin
//清除原先内容
apart_list.Items.Clear ;
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add (
'select [CUSTOM_ID],[CUSTOM_CODE],[CUSTOM_MNAME],[CUSTOM_FNAME],[CUSTOM_TEL],[AREA_NAME],[CUSTOM_ADD],[FROM_NAME],[CUSTOM_POST],[CUSTOM_DATE] ' +
'from [CUSTOM],[AREA],[FROM] '+
'where [CUSTOM_AREA]=[AREA_ID] and [CUSTOM_FROM]=[FROM_ID]');//选择CUSTOM,AREA,FROM表中的所有内容
recordset_temp.Open ;
intCount:=recordset_temp.RecordCount ;
Label4.Caption :=inttostr(intCount) + '名';//初始化客户数目
//读取FROM表中所有的客户,显示在窗口中
for i:=1 to recordset_temp.RecordCount do
begin
listitem:=apart_LIST.Items.Add ;
listitem.Caption :=recordset_temp.Fields[1].AsString ;
listitem.ImageIndex :=0;
listitem.SubItems.Add(recordset_temp.Fields[2].asstring);
listitem.SubItems.Add(recordset_temp.Fields[3].asstring);
listitem.SubItems.Add(recordset_temp.Fields[4].asstring);
listitem.SubItems.Add(recordset_temp.Fields[5].asstring);
listitem.SubItems.Add(recordset_temp.Fields[6].asstring);
listitem.SubItems.Add(recordset_temp.Fields[7].asstring);
listitem.SubItems.Add(recordset_temp.Fields[8].asstring);
listitem.SubItems.Add(DateTimeToStr(recordset_temp.Fields[9].AsDateTime));
new(p);
p^ := recordset_temp.Fields[0].AsInteger ;
listitem.Data :=p;
recordset_temp.Next;
end;
end;
procedure Tform_custom_edit.BitBtn2Click(Sender: TObject);
//删除某一客户
var
temp:pchar;
p:^integer;
count1:integer;
count2:integer;
begin
//是否在部门列表中选择某部门
if apart_list.Selected =nil then exit ;
//搜寻数据库中相关的评价记录,交易记录
p:=apart_list.Selected.Data ;
recordset_temp.SQL.Clear;
recordset_temp.sql.Add('seleCt count([JY_ID]) from [JY] where [JY_CUSTOMID] =' + inttostr(p^));
recordset_temp.Open ;
count1:=recordset_temp.Fields[0].asinteger;
recordset_temp.Close ;
recordset_temp.SQL.Clear;
recordset_temp.sql.Add('seleCt count([PJ_ID]) from [PJ] where [PJ_CU_ID] =' + inttostr(p^));
recordset_temp.Open ;
count2:=recordset_temp.Fields[0].asinteger;
recordset_temp.Close ;
//再次询问用户以确定删除
temp:=pchar('您是否确定要删除['+apart_list.Selected.caption + ']' + #13 + #13 +
'您将关联删除' + inttostr(count1) + '条交易纪录' + #13 +
'您将关联删除' + inttostr(count2) + '条评价纪录' );
p:=Apart_list.Selected.Data;
if messagebox(self.Handle, temp,
'警告',MB_yesno or MB_ICONQUESTION )=IDyes then
begin
//删除数据库中对应内容
form_main.Dconnect.Execute('delete * from [JY] where [JY_CUSTOMID]=' + inttostr(p^));
form_main.Dconnect.Execute('delete * from [PJ] where [PJ_CU_ID]=' + inttostr(p^));
form_main.Dconnect.Execute('delete * from [CUSTOM] where [CUSTOM_ID]=' + inttostr(p^));
Dispose(p);
//更新窗口显示
apart_list.Selected.Delete ;
intCount := intCount-1;
Label4.Caption :=inttostr(intCount) + '名';
end;
apart_list.SetFocus ;
end;
procedure Tform_custom_edit.button_addClick(Sender: TObject);
//修改原有的客户名称
var
p:^integer;
begin
//是否在列表中选择某一客户
if apart_list.Selected =nil then exit ;
//查询数据库
recordset_temp.SQL.Clear ;
p:=Apart_list.Selected.Data;
recordset_temp.SQL.Add ('select * from [CUSTOM] where [CUSTOM_ID]=' + inttostr(p^));
recordset_temp.Open ;
//确认数据库中存在该客户
if recordset_temp.RecordCount <>0 then
begin
//初始化修改客户名称窗口
form_custom_input.string_custom_id :=recordset_temp.Fields[1].AsString ;
form_custom_input.string_mname:=recordset_temp.Fields[2].AsString ;
form_custom_input.string_fname :=recordset_temp.Fields[3].AsString ;
form_custom_input.string_tel :=recordset_temp.Fields[4].AsString ;
form_custom_input.int_area :=recordset_temp.Fields[5].AsInteger ;
form_custom_input.string_address :=recordset_temp.Fields[6].AsString ;
form_custom_input.int_from :=recordset_temp.Fields[7].AsInteger ;
form_custom_input.string_postcode :=recordset_temp.Fields[8].AsString ;
form_custom_input.ShowModal ;
//判断用户是否正确输入客户名称
if form_custom_input.bYesno =true then
begin
//修改对应内容
recordset_temp.Edit;
recordset_temp.Fields[1].AsString :=form_custom_input.string_custom_id ;
recordset_temp.Fields[2].AsString :=form_custom_input.string_mname + ' ';
recordset_temp.Fields[3].AsString :=form_custom_input.string_fname + ' ' ;
recordset_temp.Fields[4].AsString :=form_custom_input.string_tel + ' ' ;
recordset_temp.Fields[5].AsInteger :=form_custom_input.int_area ;
recordset_temp.Fields[6].AsString :=form_custom_input.string_address + ' ' ;
recordset_temp.Fields[7].AsInteger :=form_custom_input.int_from ;
recordset_temp.Fields[8].AsString :=form_custom_input.string_postcode ;
recordset_temp.Post ;
//修改客户列表对应内容
recordset_temp.SQL.Clear ;
recordset_temp.SQL.Add (
'select [CUSTOM_ID],[CUSTOM_CODE],[CUSTOM_MNAME],[CUSTOM_FNAME],[CUSTOM_TEL],[AREA_NAME],[CUSTOM_ADD],[FROM_NAME],[CUSTOM_POST],[CUSTOM_DATE] ' +
'from [CUSTOM],[AREA],[FROM] '+
'where [CUSTOM_AREA]=[AREA_ID] and [CUSTOM_FROM]=[FROM_ID] and [CUSTOM_ID]=' + inttostr(p^));
recordset_temp.Open ;
apart_list.Selected.Caption :=form_custom_input.string_custom_id ;
apart_list.Selected.SubItems.Clear ;
apart_list.Selected.SubItems.Add(recordset_temp.Fields[2].asstring);
apart_list.Selected.SubItems.Add(recordset_temp.Fields[3].asstring);
apart_list.Selected.SubItems.Add(recordset_temp.Fields[4].asstring);
apart_list.Selected.SubItems.Add(recordset_temp.Fields[5].asstring);
apart_list.Selected.SubItems.Add(recordset_temp.Fields[6].asstring);
apart_list.Selected.SubItems.Add(recordset_temp.Fields[7].asstring);
apart_list.Selected.SubItems.Add(recordset_temp.Fields[8].asstring);
apart_list.Selected.SubItems.Add(DateTimeToStr(recordset_temp.Fields[9].AsDateTime));
end;
end;
end;
procedure Tform_custom_edit.BitBtn4Click(Sender: TObject);
//调用消费登记窗口为指定用户添加消费纪录
var
p:^integer;
begin
//是否选择某一用户
if apart_list.Selected = nil then exit ;
//初始化消费登记窗口
p:=Apart_list.Selected.Data;
form_use_dollor.Edit1.Text :=apart_list.Selected.Caption ;
form_use_dollor.cid := p^;
//显示消费登记窗口
form_use_dollor.ShowModal ;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -