Example #1
0
        private void Btn_btn_BookOrder_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(tb_BookPrice.Text))                   //ถ้าในกล่องข้อความว่างเปล่า
            {
                MessageBox.Show("Please choose the book");
            }
            else if (String.IsNullOrEmpty(tb_BookQty.Text))
            {
                MessageBox.Show("Please insert the quantity");
            }
            else if (String.IsNullOrEmpty(tb_CustomerID.Text))
            {
                MessageBox.Show("Please insert CustomerID");
            }
            else
            {
                int keyCheck = 1;
                foreach (string list in DataAccessCustomers.CheckCustomerID())
                {
                    if (list == tb_CustomerID.Text)
                    {
                        keyCheck = 2;

                        if (MessageBox.Show("คุณต้องการซื้อหนังสือ : " + tb_BookTitle.Text + "\n" + "จำนวน = " + tb_BookQty.Text + " เล่ม ใช่หรือไม่?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                        {
                            DataAccessTransaction.AddData(tb_BookID.Text, tb_CustomerID.Text, tb_BookQty.Text, tb_TotalPrice.Text);

                            MessageBox.Show("ลูกค้ารหัส : " + tb_CustomerID.Text + "\n" + "ทำการซื้อหนังสือรหัส : " + tb_BookID.Text + ", ชื่อ : " + tb_BookTitle.Text + "\n" + "จำนวน : " + tb_BookQty.Text + " เล่ม" + "\n" + "ราคา : " + tb_TotalPrice.Text + " บาท", "สรุปรายการขาย");

                            tb_BookID.Clear();
                            tb_BookQty.Clear();
                            tb_TotalPrice.Clear();
                            tb_CustomerID.Clear();
                        }


                        break;
                    }
                }

                if (keyCheck == 1)
                {
                    MessageBox.Show("Customer ID : " + tb_CustomerID.Text + " not found");
                    tb_CustomerID.Clear();
                }
            }
        }
        private void Btn_add_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(tb_CustomerID.Text))                   //ถ้าในกล่องข้อความว่างเปล่า
            {
                MessageBox.Show("Please input 'Customer ID' ");
            }
            else if (String.IsNullOrEmpty(tb_CustomerName.Text))
            {
                MessageBox.Show("Please input 'Name' ");
            }
            else if (String.IsNullOrEmpty(tb_CustomerAddress.Text))
            {
                MessageBox.Show("Please input 'Address' ");
            }
            else if (String.IsNullOrEmpty(tb_CustomerEmail.Text))
            {
                MessageBox.Show("Please input 'Email' ");
            }
            else
            {
                int keyCheck = 1;
                foreach (string list in DataAccessCustomers.CheckCustomerID())
                {
                    if (list == tb_CustomerID.Text)
                    {
                        keyCheck = 2;
                        MessageBox.Show("ID : " + list + " already exist");
                        break;
                    }
                }

                if (keyCheck == 1)
                {
                    DataAccessCustomers.AddData(tb_CustomerID.Text, tb_CustomerName.Text, tb_CustomerAddress.Text, tb_CustomerEmail.Text);
                    MessageBox.Show("added ID " + tb_CustomerID.Text + " done");
                    tb_CustomerAddress.Clear();
                    tb_CustomerEmail.Clear();
                    tb_CustomerName.Clear();
                    tb_CustomerID.Clear();
                }
            }
        }