C语言实现的会员卡计费系统源码

5星 · 超过95%的资源 需积分: 32 18 下载量 131 浏览量 更新于2024-07-17 8 收藏 20KB DOCX 举报
"会员卡计费系统是一个课程大作业,包含源码,主要涉及会员信息管理,如姓名、卡号、性别、年龄、余额、电话等,并实现了会员消费记录的功能。" 会员卡计费系统是一个典型的面向对象编程案例,用于模拟实际生活中会员消费的计费流程。在这个系统中,关键的数据结构是一个名为`member`的结构体,它包含了以下成员: 1. `name`:存储会员姓名,使用字符数组`char name[MAX]`。 2. `id`:存储会员卡号,同样用字符数组`char id[MAX]`表示。 3. `sex`:存储会员性别,使用两个字符的数组`char sex[2]`,通常存储“男”或“女”。 4. `age`:存储会员年龄,使用整型变量`int age`。 5. `money`:存储会员的余额,使用浮点型变量`float money`。 6. `tel`:存储会员电话,使用12个字符长度的数组`char tel[12]`。 7. `next`:这是一个指针,`struct member* next`,用于链接下一个`member`结构体,形成链表结构。 8. `cost`:记录会员消费金额,使用浮点型变量`float cost`。 系统还定义了多个功能函数,例如: - `menu()`:用于显示主菜单,通常包括会员注册、查询、消费记录等功能。 - `save(mem* p)`:这个函数用于保存会员信息,可能将数据写入文件以便持久化存储。 - `get_last(mem* p)`:获取链表的最后一个元素的指针,便于在链表尾部添加新节点。 - `creat_member(mem* pNew)`:会员登记函数,接收新会员的信息,包括卡号、姓名、性别、年龄等,并将这些信息存入`member`结构体。 在`creat_member()`函数中,可以看到使用`scanf`和`getchar`来读取用户输入,并通过条件判断来验证输入的合法性(例如性别只能是“f”或“m”)。使用`goto`语句实现错误输入时的循环提示,直到用户输入正确为止。 此外,系统可能还包含其他功能,如查询会员信息、修改信息、消费记录的增加和查询等。源码中没有给出完整的功能实现,但可以推测整个系统会涉及到文件操作(读写会员信息),以及链表操作(插入、删除、遍历)等编程技术。这为学习C语言、数据结构以及简单的数据库操作提供了实践平台。
2008-11-28 上传
Imports System.Data.SqlClient Imports System.DateTime Partial Class member Inherits System.Web.UI.UserControl Dim sys As New SySDB '新增 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If Me.txt_num.Text = "" Then Response.Write("<script>alert('請輸入卡號!')</script>") : Exit Sub If Me.txt_name.Text = "" Then Response.Write("<script>alert('請輸入姓名!')</script>") : Exit Sub If Me.txt_email.Text = "" Then RegularExpressionValidator3.Enabled = False If Me.txt_passport.Text = "" Then RegularExpressionValidator1.Enabled = False addmember() End Sub Private Sub addmember() sys.InsertCommand = "insert into member(CardId,name,age,birthday,sex,address,mail,phone,passport,addtime) values (@CardId,@name,@age,@birthday,@sex,@address,@mail,@phone,@passport,@addtime)" sys.InsertParameters.Add("CardId", Me.txt_num.Text.Trim) sys.InsertParameters.Add("name", Me.txt_name.Text.Trim) sys.InsertParameters.Add("age", Me.txt_age.Text.Trim) sys.InsertParameters.Add("birthday", Me.year.Text.Trim.ToString) sys.InsertParameters.Add("sex", Me.sex.SelectedValue.Trim) sys.InsertParameters.Add("address", Me.txt_address.Text.Trim) sys.InsertParameters.Add("mail", Me.txt_email.Text.Trim) sys.InsertParameters.Add("phone", Me.txt_phone.Text.Trim) sys.InsertParameters.Add("passport", Me.txt_passport.Text.Trim) sys.InsertParameters.Add("addtime", Format(Now, "yyyy/MM/dd")) '加入操作時間 Me.Button1.Attributes.Add("onclick", "return confirm('請先確定資料是否正確?')") Try If sys.Insert > 0 Then Response.Write("<script>alert('恭喜!你已經成功新增一個會員!')</script>") Else Response.Write("<script>alert('新增會員失敗')</script>") End If Catch ex As Exception MsgBox(ex.Message.ToString) End Try cleardata() Me.btn_delete.Enabled = False Me.btn_edit.Enabled = False Me.txt_num.ReadOnly = False Me.txt_num.BackColor = Drawing.Color.Yellow End Sub Private Sub cleardata() Me.txt_num.Text = "" Me.txt_name.Text = "" Me.txt_age.Text = "" Me.year.Text = "" Me.sex.SelectedValue = "女" Me.txt_address.Text = "" Me.txt_email.Text = "" Me.txt_phone.Text = "" Me.txt_passport.Text = "" End Sub ' Private Sub loadmonth() ' Dim i As Integer = 1 ' For i = 1 To 12 Step 1 ' month.Items.Add(i) 'Next ' End Sub ' Private Sub loadday() ' 'Dim i As Integer ' Dim j As Integer = 1 ' For j = 1 To 31 Step 1 ' day.Items.Add(j) ' 'j = j + 1 ' Next ' End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Me.Page.IsPostBack = False Then load_total() End If End Sub Sub load_total() sys.SelectCommand = "SELECT count(*) as a1 FROM [member]" sys.DataSourceMode = SqlDataSourceMode.DataReader Dim dr As SqlDataReader = sys.Select() While dr.Read Me.total.Text = "現有會員:" & dr("a1") & "位" End While End Sub '查找 Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click sys.SelectCommand = "select * from member where CardId like @CardId" sys.SelectParameters.Add(New ControlParameter("CardId", Me.txt_num.ID)) Me.Controls.Add(sys) Dim dv As Data.DataView = sys.Select(New DataSourceSelectArguments) Dim i As Integer '讀入資料,使用for循环来绑定资料  For i = 0 To dv.Table.Rows.Count - 1 Me.txt_num.Text = dv.Table.Rows(i)("CardId").ToString Me.txt_name.Text = dv.Table.Rows(i)("name").ToString Me.txt_age.Text = dv.Table.Rows(i)("age").ToString Me.year.Text = dv.Table.Rows(i)("birthday").ToString Me.sex.SelectedValue = dv.Table.Rows(i)("sex").ToString Me.txt_address.Text = dv.Table.Rows(i)("address").ToString Me.txt_email.Text = dv.Table.Rows(i)("mail").ToString Me.txt_passport.Text = dv.Table.Rows(i)("passport").ToString Me.txt_phone.Text = dv.Table.Rows(i)("phone").ToString Next If Me.txt_num.Text <> "" Then Me.btn_delete.Enabled = True Me.btn_edit.Enabled = True Me.txt_num.ReadOnly = True Me.txt_num.BackColor = Drawing.Color.Red End If End Sub Protected Sub btn_clear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_clear.Click cleardata() Me.btn_delete.Enabled = False Me.btn_edit.Enabled = False Me.txt_num.ReadOnly = False Me.txt_num.BackColor = Drawing.Color.Yellow End Sub '編輯 Protected Sub btn_edit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_edit.Click Try sys.UpdateCommand = "update member set name = @name, age=@age,birthday=@birthday,sex=@sex,address=@address,mail=@mail,phone=@phone,passport=@passport where CardId=@CardId" sys.UpdateParameters.Add("name", Me.txt_name.Text.Trim.ToString) sys.UpdateParameters.Add("age", Me.txt_age.Text.Trim) sys.UpdateParameters.Add("birthday", Me.year.Text.Trim.ToString) sys.UpdateParameters.Add("sex", Me.sex.SelectedValue.ToString) sys.UpdateParameters.Add("address", Me.txt_address.Text.Trim.ToString) sys.UpdateParameters.Add("mail", Me.txt_email.Text.Trim.ToString) sys.UpdateParameters.Add("phone", Me.txt_phone.Text.Trim.ToString) sys.UpdateParameters.Add("passport", Me.txt_passport.Text.Trim.ToString) sys.UpdateParameters.Add("CardId", Me.txt_num.Text.Trim) sys.Update() Me.btn_edit.Attributes.Add("onclick", "return confirm('請先確定會員資料是否正確?')") '彈出提示窗口 If sys.Update > 0 Then Response.Write("<script>alert('會員資料更新成功!')</script>") Else Response.Write("<script>alert('會員資料更新失敗!')</script>") End If Catch ex As Exception MsgBox(ex.Message.ToString) End Try cleardata() Me.btn_delete.Enabled = False Me.btn_edit.Enabled = False Me.txt_num.ReadOnly = False Me.txt_num.BackColor = Drawing.Color.Yellow End Sub '刪除操作 Protected Sub btn_delete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_delete.Click Try sys.DeleteCommand = "delete from member where CardId =@CardId" sys.DeleteParameters.Add("CardId", Me.txt_num.Text.Trim) sys.Delete() Me.btn_delete.Attributes.Add("onclick", "return confirm('是否要刪除此會員?')") If sys.Delete > 0 Then Response.Write("<script>alert('已經成功刪除此會員!')</script>") End If Catch ex As Exception MsgBox(ex.Message.ToString) End Try cleardata() Me.btn_delete.Enabled = False Me.btn_edit.Enabled = False Me.txt_num.ReadOnly = False Me.txt_num.BackColor = Drawing.Color.Yellow End Sub End Class