티스토리 뷰

프로그래밍/C#

C# datagridView 예제

뽀로로친구에디 2019. 12. 5. 11:27

1. C# datagridView 예제 레이아웃

 

2. ID 텍스트박스 

 

3. Name Coffee 콤보박스 

 

4. Type 콤보박스 

 

5. Quanity 콤보박스 

 

6. Payment 텍스트박스 추가

 

 

7. 소스코드

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 Coffee_Shop_Mangement
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(namecombo.SelectedItem.ToString()=="Latte")
            {
                if(typecombo.SelectedItem.ToString()=="Frapp")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 9000).ToString();
                }
                if (typecombo.SelectedItem.ToString() == "Ice")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 7000).ToString();
                }
                if (typecombo.SelectedItem.ToString() == "Hot")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 5000).ToString();
                }


            }
            if(namecombo.SelectedItem.ToString()=="Chappuccino")
            {
                if (typecombo.SelectedItem.ToString() == "Frapp")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 10000).ToString();
                }
                if (typecombo.SelectedItem.ToString() == "Ice")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 8000).ToString();
                }
                if (typecombo.SelectedItem.ToString() == "Hot")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 5000).ToString();
                }
            }
            if (namecombo.SelectedItem.ToString() == "Chocolate")
            {
                if (typecombo.SelectedItem.ToString() == "Frapp")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 8500).ToString();
                }
                if (typecombo.SelectedItem.ToString() == "Ice")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 6500).ToString();
                }
                if (typecombo.SelectedItem.ToString() == "Hot")
                {
                    paytext.Text = (float.Parse(quanitycombo.Text) * 5000).ToString();
                }
                
            }

            dataGridView1.Rows.Add(idtext.Text, namecombo.Text, typecombo.Text, quanitycombo.Text, paytext.Text);
        }

        private void idtext_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(char.IsNumber(e.KeyChar))
            {

            }
            else
            {
                e.Handled = e.KeyChar != (char)Keys.Back;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            idtext.Text = "";
            namecombo.Text = "";
            typecombo.Text = "";
            quanitycombo.Text = "";
            paytext.Text = "";
        }

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

댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
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
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글