• MVP 模式是否应该这样修改2?


    最后,当然是界面实现。

    这时业务操作对象及客户资料数据接口已定义好后,你可使用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();
            }
        }
    }

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

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

  • 相关阅读:
    codeforces 1251 F. Red-White Fence
    NTT 模板
    快速傅里叶变换模板
    codeforces 1251E (贪心)
    平衡树
    lucas定理
    P3709 大爷的字符串题 (莫队)
    洛谷 P3258 [JLOI2014]松鼠的新家 (树链剖分或树上差分)
    算法-图(5)深度优先遍历图
    计算机网络-链路层(3)交换局域网
  • 原文地址:https://www.cnblogs.com/henxiao25/p/1736969.html
Copyright © 2020-2023  润新知