深入.net和C#编程第三章上机练习1


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericDemo
{
    /// <summary>
    /// 性别枚举
    /// </summary>
    public enum Gender
    {
        男,
        女
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenericDemo
{
   
    /// <summary>
    /// 员工类
    /// </summary>
    public class SE
    {
        public string ID { get; set; }
        /// <summary>
        /// 年龄
        /// </summary>
        public int Age { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        public Gender Gender { get; set; }
      
        /// <summary>
        /// 人气值

        /// </summary>
        private int _popularity = 0;
        public int Popularity
        {
            get { return _popularity; }
            set { _popularity = value; }
        }
        public string SayHi()
        {
            string message = string.Format("大家好,我是 {0}, 今年 {1}岁,我的人气值高达 {3}!",this.Name,this.Age,this.Popularity);
            return message;
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/*
 * 打卡记录窗体
 * **/
namespace GenericDemo
{
    public partial class frmCardRecord : Form
    {
       
        public frmCardRecord()
        {
            InitializeComponent();
        
        }
        //窗体加载
        private void frmCardRecord_Load(object sender, EventArgs e)
        {
        }
    }
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/*
 * 新增或者修改集合中的数据。
 * **/
namespace GenericDemo
{
    public partial class frmMaintance : Form
    {
        /// <summary>
        /// 维护类型 1表示新增,0表示修改
        /// </summary>
        public int MaintanceType { get; set; }
        //主窗体引用
        public frmMain FrmParent { get; set; }
        public frmMaintance()
        {
            InitializeComponent();
            this.cmbSex.SelectedIndex = 0;
        }
        //保存记录
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                #region 输入处理
                SE pr = new SE();
                pr.ID = this.txtWorkNO.Text.Trim();
                pr.Age = Int32.Parse(this.txtAge.Text.Trim());
                if (this.cmbSex.SelectedItem.ToString() == "男")
                {
                    pr.Gender = Gender.男;
                }
                else
                {
                    pr.Gender = Gender.女;
                }
                pr.Name = this.txtName.Text.Trim();
                #endregion
                if (this.MaintanceType == 1)//添加
                {
                    #region 添加操作
                    foreach (SE item in FrmParent.programmerList)
                    {
                        if (item.ID == pr.ID)
                        {
                            MessageBox.Show("此工号已经存在!");
                            return;
                        }
                    }
                    FrmParent.programmerList.Add(pr);
                    #endregion
                }
                else
                {
                    #region 修改操作
                   
                    #endregion
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("出错:" + ex.Message);
            }
            finally
            {
                this.FrmParent.BindGrid(FrmParent.programmerList);//刷新父窗体的信息。
            }
        }
    }
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace GenericDemo
{
    public partial class frmMain : Form
    {
        /// <summary>
        /// 列表,用于保存员工(程序员)对象
        /// </summary>
        public List<SE> programmerList = new List<SE>();
       
        public frmMain()
        {
            InitializeComponent();
            this.dgvProgrammer.AutoGenerateColumns = false;
        }
     
        /// <summary>
        /// 绑定List中的数据到DataGridView
        /// </summary>
        public void BindGrid(List<SE> list)
        {
            this.dgvProgrammer.DataSource = new BindingList<SE>(list);
        }
       
       
        /// <summary>
        /// 添加按钮的响应操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsbtnAdd_Click(object sender, EventArgs e)
        {
            frmMaintance frm = new frmMaintance();
            frm.MaintanceType = 1;
            frm.FrmParent = this;
            frm.ShowDialog();
        }
    }
}
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值