private void btnCancel_Click(object sender, RoutedEventArgs e) { logger.Trace("Customer clear button clicked! Previous ID: {0}", _customer.ID); var temp = CustomerTextEnteredEventHandler; if (temp != null) { var ex = new CustomerEnterEventArgs { Customer = null, Discount = 0 }; temp(this, ex); } Clear(); }
private void tbCustomer_CustomerTextEntered(object sender, CustomerEnterEventArgs e) { _POSWindowViewModel.TempCustomer = e.Customer; _discount_percentage = e.Discount; Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(delegate() { ddli.FilterBox.Focus(); })); //calculateSaleInfo(); }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { String customer_tag = (sender as TextBox).Text; if (customer_tag.Length > 0) { DataSet ds = new DataSet(); String selectQuery = String.Format(@"SELECT c._id, c.`first_name`, c.`last_name`, SUM(cp.`sale_point`) AS sale_point FROM customer_point AS cp LEFT JOIN customer AS c ON c._id = cp.`customer_id` WHERE customer_id IN ( SELECT cu1._id FROM customer AS cu1 INNER JOIN customer_card AS cc1 ON cu1.`_id` = cc1.`customer_id` INNER JOIN card AS c1 ON c1.`_id` = cc1.`card_id` WHERE (c1.`card_number` = '{0}' OR c1.`card_nfc_number` = '{0}')) AND cp.`expiredate` > NOW()", customer_tag); try { conn.Open(); MySqlCommand cmd = new MySqlCommand(selectQuery, conn); MySqlDataAdapter adp = new MySqlDataAdapter(cmd); adp.Fill(ds, "customer"); //logger.Trace("TAG: {0}...IS NOT NULL {1}", ds.Tables["customer"].Rows.Count, !DBNull.Value.Equals(ds.Tables["customer"].Rows[0]["_id"])); if (!DBNull.Value.Equals(ds.Tables["customer"].Rows[0]["_id"])) { DataRow dataRow = ds.Tables["customer"].Rows[0]; _customer = new Customer { ID = dataRow.Field<uint>("_id"), FirstName = dataRow.Field<string>("first_name"), LastName = dataRow.Field<string>("last_name"), Sale_Point = dataRow.Field<double>("sale_point"), }; tbCustomerInfo.Text = String.Format("{0} {1}: {2} điểm ", _customer.LastName, _customer.FirstName, Math.Round(_customer.Sale_Point, 2)); //HACK: Chương trình giảm giá khách hàng double _discount_percentage = 0; if (_customer.Sale_Point > 1000) _discount_percentage = 0.02; if (_customer.Sale_Point > 5000) _discount_percentage = 0.05; var temp = CustomerTextEnteredEventHandler; if (temp != null) { var customerEnterEvent = new CustomerEnterEventArgs { Customer = _customer, Discount = _discount_percentage }; temp(this, customerEnterEvent); } (sender as TextBox).Text = "";//clear text (sender as TextBox).IsEnabled = false; btnCancel.Visibility = Visibility.Visible; conn.Close(); logger.Trace("Customer entered! ID: {0}", _customer.ID); } } catch (MySqlException ex) { MessageBox.Show(ex.ToString()); } finally { if (conn.State == ConnectionState.Open) conn.Close(); } } }