实全软件科技有限公司

衡斅-衡量使人觉悟

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  31 随笔 :: 10 文章 :: 67 评论 :: 68115 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

最后,当然是界面实现。

这时业务操作对象及客户资料数据接口已定义好后,你可使用WebForm 、WinForm 或者WPF 等实现界面编辑,我这里使用的是WinForm 实现。

客户资料编辑界面

客户编辑界面

下面编辑界面的后台代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HenXiao.WinUI
{
    public partial class FrmCustomerEdit : Form,ICustomer
    {
        HxCustomerHelper helper = null;

        public FrmCustomerEdit()
        {
            InitializeComponent();
            helper = new HxCustomerHelper(this);
        }

        #region ICustomer 成员

        private int cstId = 0;
        public int CstId
        {
            get
            {
                return this.cstId;
            }
            set
            {
                this.cstId = value;
            }
        }

        public string CstNo
        {
            get
            {
                return this.txtCstNo.Text;
            }
            set
            {
                this.txtCstNo.Text = value;
            }
        }

        public string CstName
        {
            get
            {
                return this.txtCstName.Text;
            }
            set
            {
                this.txtCstName.Text = value;
            }
        }

        public DateTime CstBirthday
        {
            get
            {
                if (this.dtpCstBirthday.Text == "")
                    return DateTime.MinValue;
                else
                    return Convert.ToDateTime(this.dtpCstBirthday.Text);
            }
            set
            {
                this.dtpCstBirthday.Text = value.ToString();
            }
        }

        public string CstTele
        {
            get
            {
                return this.txtCstTele.Text;
            }
            set
            {
                this.txtCstTele.Text = value;
            }
        }

        public string CstZip
        {
            get
            {
                return this.txtCstZip.Text;
            }
            set
            {
                this.txtCstZip.Text = value;
            }
        }

        public string CstAddr
        {
            get
            {
               return this.txtAddr.Text;
            }
            set
            {
                this.txtAddr.Text = value;
            }
        }

        public string CstExp
        {
            get
            {
                return this.txtCstExp.Text;
            }
            set
            {
                this.txtCstExp.Text = value;
            }
        }

        public string CstSex
        {
            get
            {
                return this.cmbCstSex.Text;
            }
            set
            {
                this.cmbCstSex.Text = value;
            }
        }

        public string CstCertType
        {
            get
            {
                return this.cmbCstCertType.Text;
            }
            set
            {
                this.cmbCstCertType.Text = value;
            }
        }

        public string CstCertNo
        {
            get
            {
                return this.txtCstCertNo.Text;
            }
            set
            {
                this.txtCstCertNo.Text = value;
            }
        }

        public string CstEmail
        {
            get
            {
                return this.txtCstEmail.Text;
            }
            set
            {
                this.txtCstEmail.Text = value;
            }
        }

        public string CstCompany
        {
            get
            {
                return this.txtCstCompany.Text;
            }
            set
            {
                this.txtCstCompany.Text = value;
            }
        }

        #endregion

        private void FrmCustomer_Load(object sender, EventArgs e)
        {
            this.cmbCstCertType.Items.Add("身份证");
            this.cmbCstCertType.Items.Add("护照");
            this.cmbCstCertType.Items.Add("军官证");

            this.cmbCstSex.Items.Add("男");
            this.cmbCstSex.Items.Add("女");

            this.helper.DataLoad();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this.helper.Save())
            {
                MessageBox.Show("保存成功。", "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }
            else
                MessageBox.Show(this.helper.ErrorMessage,"保存出错",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

这样,这个事例基本完成,编辑界面后台基本无任何业务逻辑。

有更好方法实现业务逻辑与界面分隔,欢迎指教。

posted on   衡斅  阅读(188)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言
点击右上角即可分享
微信分享提示