github : https://github.com/minseung-moon/CShopTestProject/tree/master/kiosk
초기 틀만 잡는거라 데이터베이스 연결 없이 진행하였습니다!
Model / Menu.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kiosk.Model
{
class Menu
{
// 메뉴 이름
public string Name { get; set; }
// 메뉴 가격
public int Price { get; set; }
// 주문 수량
public int Each { get; set; }
// 개체 출력 양식
public override string ToString()
{
return $"{Name} : {Price} : {Each}개";
}
}
}
using kiosk.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kiosk.Repository
{
interface IKioskRepository
{
// 주문
void AddMenu(string name, int price);
// 계산
int Billing();
// 주문한 메뉴 확인
List<Menu> SelectOrders();
// 주문한 갯수
int CountingMenu();
// 초기화
void Reset();
}
}
using kiosk.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace kiosk.Repository
{
class KioskRepository : IKioskRepository
{
// 주문한 메뉴 개체 인스턴스
public static List<Menu> menus = new List<Menu>();
// 주문
public void AddMenu(string name, int price)
{
menus.Add(new Menu { Name = name, Price = price, Each = 1 });
// 중복 제거, 특정 기준으로 그룹화를 시켜준 다음 그룹 중 첫번째 값만 리스트 형식으로 리턴
// object가 아닌 literal value List 였다면 .Distinct().ToList() 사용
menus = menus
.GroupBy(item => item.Name)
.Select(item => new Menu { Name = item.First().Name, Price = item.First().Price, Each = (item.First().Each - 1) + item.Count()})
.ToList();
}
// 계산
public int Billing()
{
return menus.Sum((menu) => (menu.Price * menu.Each));
}
// 주문한 메뉴 확인
public List<Menu> SelectOrders()
{
return menus;
}
// 주문한 갯수
public int CountingMenu()
{
return menus.Sum(menu => menu.Each);
}
// 초기화
public void Reset()
{
menus.Clear();
}
}
}
using kiosk.Repository;
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 kiosk
{
public partial class HambergerForm : UserControl
{
private KioskRepository repository = new KioskRepository();
private TextBox textbox;
private Label label1;
private Label label2;
public HambergerForm(TextBox textBox, Label labe1, Label label2)
{
InitializeComponent();
this.textbox = textBox;
this.label1 = labe1;
this.label2 = label2;
bulgogi.CheckedChanged += CheckItem;
doublebulgogi.CheckedChanged += CheckItem;
cheese.CheckedChanged += CheckItem;
doublecheese.CheckedChanged += CheckItem;
}
private void CheckItem(object sender, EventArgs e)
{
RadioButton rd = (RadioButton)sender;
bool flag = rd.Checked;
if(flag)
{
string str = "";
textbox.Text = "";
repository.AddMenu(rd.Text, 5000);
repository.SelectOrders().ForEach(menu => {
str += $"{menu.ToString()}\r\n";
});
textbox.Text = str;
label1.Text = $"가격 : {repository.Billing()}";
label2.Text = $"수량 : {repository.CountingMenu()}";
}
}
}
}
using kiosk.Repository;
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 kiosk
{
public partial class SideForm : UserControl
{
private KioskRepository repository = new KioskRepository();
private TextBox textbox;
private Label label1;
private Label label2;
public SideForm(TextBox textBox, Label labe1, Label label2)
{
InitializeComponent();
this.textbox = textBox;
this.label1 = labe1;
this.label2 = label2;
frenchfrice.CheckedChanged += CheckItem;
marinaedfrise.CheckedChanged += CheckItem;
applepie.CheckedChanged += CheckItem;
eggtart.CheckedChanged += CheckItem;
}
private void CheckItem(object sender, EventArgs e)
{
CheckBox ck = (CheckBox)sender;
bool flag = ck.Checked;
if (flag)
{
string str = "";
textbox.Text = "";
repository.AddMenu(ck.Text, 5000);
repository.SelectOrders().ForEach(menu => {
str += $"{menu.ToString()}\r\n";
});
textbox.Text = str;
label1.Text = $"가격 : {repository.Billing()}";
label2.Text = $"수량 : {repository.CountingMenu()}";
}
}
}
}
using kiosk.Repository;
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 kiosk
{
public partial class DrinksForm : UserControl
{
private KioskRepository repository = new KioskRepository();
private TextBox textbox;
private Label label1;
private Label label2;
public DrinksForm(TextBox textBox, Label labe1, Label label2)
{
InitializeComponent();
this.textbox = textBox;
this.label1 = labe1;
this.label2 = label2;
coke.CheckedChanged += CheckItem;
zecoke.CheckedChanged += CheckItem;
sider.CheckedChanged += CheckItem;
}
private void CheckItem(object sender, EventArgs e)
{
RadioButton rd = (RadioButton)sender;
bool flag = rd.Checked;
if (flag)
{
string str = "";
textbox.Text = "";
repository.AddMenu(rd.Text, 5000);
repository.SelectOrders().ForEach(menu => {
str += $"{menu.ToString()}\r\n";
});
textbox.Text = str;
label1.Text = $"가격 : {repository.Billing()}";
label2.Text = $"수량 : {repository.CountingMenu()}";
}
}
}
}
using kiosk.Repository;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace kiosk
{
public partial class Form1 : Form
{
private Control control = null;
private KioskRepository repository = new KioskRepository();
public Form1()
{
InitializeComponent();
}
private void hanburger_Click(object sender, EventArgs e)
{
if (control != null) panel1.Controls.Remove(control);
control = new HambergerForm(added, price, counter);
panel1.Controls.Add(control);
}
private void side_Click(object sender, EventArgs e)
{
if (control != null) panel1.Controls.Remove(control);
control = new SideForm(added, price, counter);
panel1.Controls.Add(control);
}
private void drinks_Click(object sender, EventArgs e)
{
if (control != null) panel1.Controls.Remove(control);
control = new DrinksForm(added, price, counter);
panel1.Controls.Add(control);
}
private void bill_Click(object sender, EventArgs e)
{
MessageBox.Show($"총 결제 금액은 {price.Text.Replace("가격 : ", "")}원 입니다");
String str1 = $"str1 : ko[{getString("str1")}], en[{getString("en", "str1")}]";
String str2 = $"str2 : ko[{getString("str2")}], en[{getString("en", "str2")}]";
String msg = str1 + "\n\n" + str2;
MessageBox.Show(msg);
}
private void reset_Click(object sender, EventArgs e)
{
repository.Reset();
string str = "";
added.Text = "";
repository.SelectOrders().ForEach(menu => {
str += $"{menu.ToString()}\r\n";
});
added.Text = str;
price.Text = $"가격 : {repository.Billing()}";
counter.Text = $"수량 : {repository.CountingMenu()}";
}
// 언어 지역화
// 기본값은 한국어로 하며, 설정파일(ini) 등에서 값을 가져와 저장하여 사용
// https://srctree.tistory.com/33
public static string sLanguage = "ko";
public static string getString(string name)
{
return getString(sLanguage, name);
}
public static string getString(string code, string name)
{
if(code.Equals("en"))
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
return Properties.StringLib.ResourceManager.GetString(name);
}
else
{
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ko-KR");
return Properties.StringLib.ResourceManager.GetString(name);
}
}
}
}