国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

C# 體檢套餐管理系統

2019-11-08 02:29:44
字體:
來源:轉載
供稿:網友

 1.創建體檢項目維護系統中的檢查項目類 ,體檢套餐類和一個泛型類如下圖

 

 2.窗體的搭建,如下圖:

                       

   3.編寫代碼:

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace _05_體檢套餐{    public partial class FrmMain : Form    {        public FrmMain()        {            InitializeComponent();        }         PRivate List<HealthCheckItem> checkItems = new List<HealthCheckItem>();                public List<HealthCheckItem> CheckItems        {            get { return checkItems; }            set { checkItems = value; }        }         // 創建套餐類表的集合               private List<HealthCheckSet> checkSets = new List<HealthCheckSet>();        public List<HealthCheckSet> CheckSets        {            get { return checkSets; }            set { checkSets = value; }        }                // 初始化檢查項目信息              public void IntitalHealthCheckItem()        {            //創建檢查項目的對象            HealthCheckItem healthCheckItem1 = new HealthCheckItem();            healthCheckItem1.Name = "請選擇";            //將數據添加到集合中            this.checkItems.Add(healthCheckItem1);            //創建檢查項目的對象            HealthCheckItem healthCheckItem2 = new HealthCheckItem();            healthCheckItem2.Name = "肝功";            healthCheckItem2.Description = "檢查肝功能指標";            healthCheckItem2.Price = 50;            this.checkItems.Add(healthCheckItem2);            //創建檢查項目的對象            HealthCheckItem healthCheckItem3 = new HealthCheckItem();            healthCheckItem3.Name = "身高";            healthCheckItem3.Description = "檢查身體的高度";            healthCheckItem3.Price = 10;            this.checkItems.Add(healthCheckItem3);            //創建檢查項目的對象            HealthCheckItem healthCheckItem4 = new HealthCheckItem();            healthCheckItem4.Name = "體重";            healthCheckItem4.Description = "檢查身體重量指標";            healthCheckItem4.Price = 20;            this.checkItems.Add(healthCheckItem4);            //創建檢查項目的對象            HealthCheckItem healthCheckItem5 = new HealthCheckItem();            healthCheckItem5.Name = "視力";            healthCheckItem5.Description = "檢查視覺能力";            healthCheckItem5.Price = 30;            this.checkItems.Add(healthCheckItem5);            //創建檢查項目的對象            HealthCheckItem healthCheckItem6 = new HealthCheckItem();            healthCheckItem6.Name = "聽力";            healthCheckItem6.Description = "檢查聽覺能力";            healthCheckItem6.Price = 23;            this.checkItems.Add(healthCheckItem6);            //創建檢查項目的對象            HealthCheckItem healthCheckItem7 = new HealthCheckItem();            healthCheckItem7.Name = "B超";            healthCheckItem7.Description = "檢查B超";            healthCheckItem7.Price = 80;            this.checkItems.Add(healthCheckItem7);            //創建檢查項目的對象            HealthCheckItem healthCheckItem8 = new HealthCheckItem();            healthCheckItem8.Name = "心電圖";            healthCheckItem8.Description = "檢查心電圖";            healthCheckItem8.Price = 50;            this.checkItems.Add(healthCheckItem8);        }        //將檢查項目的數據綁定到下拉列表框               public void LoadComboxHealthCheckItem()        {            //定義數組保存            String[] checkItemsName = new String[checkItems.Count];            for (int i = 0; i < checkItemsName.Length; i++)            {                checkItemsName[i] = checkItems[i].Name;            }            //綁定數據源            this.comboBoxCkeck.DataSource = checkItemsName;            //默認選中第一個            this.comboBoxCkeck.SelectedIndex = 0;        }                    // 初始化套餐信息              public void IntitalHealthCheckSet()        {            HealthCheckSet healthCheckSet1 = new HealthCheckSet();            healthCheckSet1.Name = "請選擇";            this.checkSets.Add(healthCheckSet1);            HealthCheckSet healthCheckSet2 = new HealthCheckSet();            healthCheckSet2.Name = "入學體檢";            this.checkSets.Add(healthCheckSet2);        }              // 將套餐數據綁定到下拉列表框              public void LoadHealthCheckSet()        {            String[] healthCheckSetNames = new String[checkSets.Count];            for (int i = 0; i < healthCheckSetNames.Length; i++)            {                healthCheckSetNames[i] = checkSets[i].Name;            }            this.comboBoxList.DataSource = healthCheckSetNames;        }        private void FrmMain_Load(object sender, EventArgs e)        {            //最大化不可用            this.MaximizeBox = false;            //設置添加不可用            this.buttonAd.Enabled = false;            //設置刪除不可用            this.buttondelete.Enabled = false;            //設置為只讀狀態            this.comboBoxCkeck.DropDownStyle = ComboBoxStyle.DropDownList;            this.comboBoxList.DropDownStyle = ComboBoxStyle.DropDownList;            //默認選中一行            this.dataGridViewset.SelectionMode = DataGridViewSelectionMode.FullRowSelect;            this.labelset.Text = "";            this.labelp.Text = "";            //調用初始化檢查項方法            IntitalHealthCheckItem();            //調用將檢查項目的數據綁定到下拉列表框的方法            LoadComboxHealthCheckItem();            //調用初始化套餐信息的方法            IntitalHealthCheckSet();            //調用將套餐數據綁定到下拉列表框的方法            LoadHealthCheckSet();            LoadcheckSetsItems();        }        // 加載初始化對應的套餐功能項                public void LoadcheckSetsItems()        {            //創建套餐類的對象            HealthCheckSet healthCheckSet = null;            //創建檢查項的對象            HealthCheckItem healthCheckItem = null;            string nameSet = "入學體檢";            //循環遍歷得到對應的對象            foreach (HealthCheckSet item in checkSets)            {                if (nameSet.Equals(item.Name))                {                    healthCheckSet = item;                    break;                }            }            //清除對應的套餐對應的功能項            healthCheckSet.HealthCheckItems.Clear();            string name = "肝功";            //循環遍歷得到對應的對象            foreach (HealthCheckItem item in checkItems)            {                if (name.Equals(item.Name))                {                    healthCheckItem = item;                    break;                }            }            //創建檢查項的對象            HealthCheckItem healthCheckItem1 = null;            string name1 = "視力";            //循環遍歷得到對應的對象            foreach (HealthCheckItem item in checkItems)            {                if (name1.Equals(item.Name))                {                    healthCheckItem1 = item;                    break;                }            }            //創建檢查項的對象            HealthCheckItem healthCheckItem2 = null;            string name2 = "身高";            //循環遍歷得到對應的對象            foreach (HealthCheckItem item in checkItems)            {                if (name2.Equals(item.Name))                {                    healthCheckItem2 = item;                    break;                }            }            //將對象添加到            healthCheckSet.HealthCheckItems.Add(healthCheckItem);            //將對象添加到            healthCheckSet.HealthCheckItems.Add(healthCheckItem1);            //將對象添加到            healthCheckSet.HealthCheckItems.Add(healthCheckItem2);        }        // 將數據綁定到DatagridView        public void LoadDatagridView(HealthCheckSet healthCheckSet)        {            //將數據綁定到DatagridView            this.dataGridViewset.DataSource = new BindingList<HealthCheckItem>(healthCheckSet.HealthCheckItems);        }        HealthCheckSet healthCheckSet = null;        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)        {              /// 當用戶選中的是“請選擇”的時候綁定數據為以下的集合            List<HealthCheckItem> i = new List<HealthCheckItem>();            //獲取當前選中的項            string name = this.comboBoxList.SelectedItem.ToString();            //判斷用戶是否選中套餐名            if (name.Equals("請選擇"))            {                //數據源為null                this.dataGridViewset.DataSource = i;                this.labelset.Text = "";                this.labelp.Text = "";                return;            }            //根據用戶選中的套餐名查找對應的檢查信息            foreach (HealthCheckSet item in checkSets)            {                if (name.Equals(item.Name))                {                    healthCheckSet = item;                    break;                }            }            //調用將套餐對應的數據綁定到DatagridView的方法            LoadDatagridView(healthCheckSet);            //加載價格            healthCheckSet.CaloPrice();            this.labelset.Text = healthCheckSet.Name;            this.labelp.Text = healthCheckSet.Price.ToString();            //將按年調為可用狀態            this.buttonAd.Enabled = true;            this.buttondelete.Enabled = true;        }                     //當用戶點擊”添加套餐“的時候響應的事件        private void buttonAdd_Click(object sender, EventArgs e)        {            //判斷用戶書否輸入            if (this.textBoxName.Text.Trim().Equals(string.Empty))            {                MessageBox.Show("請輸入要添加的套餐內容!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                this.textBoxName.Focus();                return;            }            //獲得用戶輸入的文本            string name = this.textBoxName.Text.Trim();            //判斷是否有同名的套餐存在            foreach (HealthCheckSet hc in checkSets)            {                if (name.Equals(hc.Name))                {                    MessageBox.Show("已經有相同名字的體檢套餐存在!");                    return;                }            }            //創建套餐對象            HealthCheckSet healthCheckSet1 = new  HealthCheckSet();            healthCheckSet1.Name = name;            //將套餐對象添加到套餐集合中            this.checkSets.Add(healthCheckSet1);            //調用將套餐數據綁定到下拉列表框的方法            LoadHealthCheckSet();            //將套餐列表默認選中當前添加的項            this.comboBoxList.SelectedItem = name;            MessageBox.Show("添加成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);            this.textBoxName.Clear();        }        // 當用戶點擊”添加檢查項“的時候響應的事件        private void buttonAd_Click(object sender, EventArgs e)        {            //獲得用戶選中的項            string name = this.comboBoxCkeck.SelectedItem.ToString();            HealthCheckItem hci = null;            if (name.Equals("請選擇"))            {                MessageBox.Show("您當前為選擇相應的添加功能!", "添加提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                return;            }            //判斷套餐中是否已經存在要添加的項            foreach (HealthCheckItem item in healthCheckSet.HealthCheckItems)            {                if (name.Equals(item.Name))                {                    MessageBox.Show("您已經添加了“" + item.Name + "”此檢查項", "添加提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                    return;                }            }            //循環遍歷得到用戶選中的添加項的對象            foreach (HealthCheckItem item in checkItems)            {                if (name.Equals(item.Name))                {                    hci = item;                    break;                }            }            //HealthCheckSet checkset = new HealthCheckSet();            healthCheckSet.HealthCheckItems.Add(hci);            //價格刷新            healthCheckSet.CaloPrice();            this.labelset.Text = healthCheckSet.Name;            this.labelp.Text = healthCheckSet.Price.ToString();            //調用datagridview加載的方法            LoadDatagridView(healthCheckSet);            MessageBox.Show("添加成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);        }        private void buttondelete_Click(object sender, EventArgs e)        {            //判斷用戶是否選中            if (this.dataGridViewset.SelectedRows.Count > 0)            {                //獲得用戶選中的行的首行首列                string name = Convert.ToString(this.dataGridViewset.SelectedRows[0].Cells[0].Value);                //創建檢查的項                HealthCheckItem checkitem = null;                //循環遍歷集合得到對應的對象                foreach (HealthCheckItem item in healthCheckSet.HealthCheckItems)                {                    if (name.Equals(item.Name))                    {                        checkitem = item;                        break;                    }                }                //刪除用戶選中的套餐的選中的項的方法                healthCheckSet.HealthCheckItems.Remove(checkitem);                //價格刷新                healthCheckSet.CaloPrice();                this.labelset.Text = healthCheckSet.Name;                this.labelp.Text = healthCheckSet.Price.ToString();                //調用datagridview加載的方法                LoadDatagridView(healthCheckSet);                MessageBox.Show("刪除成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);          }        }                                                 }    }

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 孝义市| 兴安盟| 雅江县| 呼图壁县| 广州市| 疏附县| 新绛县| 芮城县| 舟曲县| 邵阳县| 大埔县| 南汇区| 韩城市| 疏附县| 宿迁市| 普兰县| 饶河县| 乌什县| 上蔡县| 淮南市| 大足县| 肃宁县| 屯昌县| 西乌珠穆沁旗| 苏州市| 新安县| 东莞市| 桃江县| 双流县| 衡阳县| 喜德县| 会泽县| 融水| 花莲市| 印江| 昌乐县| 门源| 准格尔旗| 柞水县| 突泉县| 龙南县|