コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: ayokyun/playmart
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            RawKeyboard rk = new RawKeyboard();
            kbList = rk.DeviceNameList();
            SelectedDeviceName = kbList[0];

            //Init Keyboard
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            _rawinput = new RawInput(Process.GetCurrentProcess().MainWindowHandle, CaptureOnlyInForeground);
            _rawinput.AddMessageFilter();   // Adding a message filter will cause keypresses to be handled
            Win32.DeviceAudit();            // Writes a file DeviceAudit.txt to the current directory
            _rawinput.KeyPressed += OnKeyPressed;


            // 이미지 백그라운드 설정
            this.Background = new ImageBrush(new BitmapImage(new Uri(BaseUriHelper.GetBaseUri(this), System.AppDomain.CurrentDomain.BaseDirectory + @"\skin.jpg")));

            // 창 사이즈 조절용
            orginalWidth = this.Width;
            originalHeight = this.Height;
            if (this.WindowState == WindowState.Maximized)
            {
                ChangeSize(this.ActualWidth, this.ActualHeight);
            }
            this.SizeChanged += new SizeChangedEventHandler(Window_SizeChanged);

            //바코드파일 읽어서 리스트로 가지고 있기
            string path = System.AppDomain.CurrentDomain.BaseDirectory + @"\barcode.txt";

            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader sr = new StreamReader(fs, Encoding.Default))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrEmpty(line.Trim()))
                        {
                            //객체 생성해서 넣기
                            string[] data = line.Split(';');
                            if (!list.ContainsKey(data[0]))
                                list.Add(data[0], new Item { Barcode = data[0], Name = data[1], Amount = Convert.ToInt32(data[2].Replace(",", string.Empty)), Count = 1 });
                        }
                    }
                }
            }


            //샘플 데이터 삽입
            //int cnt = 0;
            //foreach (KeyValuePair<string, Item> i in list)
            //{
            //    if (cnt > 50)
            //    {
            //        break;
            //    }
            //    cartItems.Add(i.Value.Barcode, new Item { Barcode = i.Value.Barcode, Amount = i.Value.Amount, Name = i.Value.Name, Count = 1 });
            //    cnt++;
            //}



            lvCart.ItemsSource = cartItems;
            UpdateTotalAmount();


            //버튼 텍스트 변경
            Label lbAdd = (Label)btnADD.Template.FindName("Content", btnADD);
            lbAdd.Content = "추가+";
            Label lbRemove = (Label)btnREMOVE.Template.FindName("Content", btnREMOVE);
            lbRemove.Content = "제거-";
            Label lbInit = (Label)btnInit.Template.FindName("Content", btnInit);
            lbInit.Content = "초기화";
            Label lbCard = (Label)btnCard.Template.FindName("Content", btnCard);
            lbCard.Content = "카드결제";
            Label lbCash = (Label)btnCash.Template.FindName("Content", btnCash);
            lbCash.Content = "현금결제";

            btnADD.IsEnabled = false;
        }