Example #1
0
        private void CostumerRegisterDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                try
                {
                    //currentDate = new DateTime();
                    //string todaysDate = currentDate.Date.ToString();

                    if ((costumerRegisterDataGrid1.SelectedItem as CostumerRegister).FirstName == firstNameTextBox.Text && (costumerRegisterDataGrid1.SelectedItem as CostumerRegister).LastName == lastNameTextBox.Text && (costumerRegisterDataGrid1.SelectedItem as CostumerRegister).TellNo == phoneNumberTextBox1.Text)
                    {
                        AlertOK decision = new AlertOK("You are Attempting to duplicate a record!", "Item already exists!");
                        decision.ShowDialog();
                        //MessageBox.Show("You are Attempting to duplicate and item!", "Item already exists!", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                    else
                    {
                        CostumerRegister newMember = new CostumerRegister()
                        {
                            FirstName = firstNameTextBox.Text,
                            LastName  = lastNameTextBox.Text,
                            Gender    = genderComboBox.Text,
                            TellNo    = phoneNumberTextBox1.Text,

                            Occupation           = occupationTextBox1.Text,
                            NxtOfKinName         = nextOfKinName.Text,
                            NxtOfKinNumber       = nextOfKinPhone.Text,
                            NxtOfKinRelationship = nextOfKinRelation.Text,

                            DateRegistered = DateTime.Now.ToString(),
                            Address1       = address1TextBox.Text,
                            Address2       = address2TextBox.Text
                        };

                        test.CostumerRegisters.Add(newMember);
                        test.SaveChanges();
                        costumerRegisterDataGrid1.ItemsSource = test.CostumerRegisters.ToList();
                        RegPanel.IsEnabled = false;
                    }
                }
                catch (Exception)
                {
                    //AlertOK alerting = new AlertOK("Something went wrong", ex.Message);
                    //alerting.ShowDialog();
                    //MessageBox.Show(ex.Message);
                    RefreshDataGrid();
                }
            }

            //costumerRegisterDataGrid1.ItemsSource = test.CostumerRegisters.ToList();
            //RefreshDataGrid();
        }
Example #2
0
        /// <summary>
        /// Update Values on the Data Grid View
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtUpdate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //currentDate = new DateTime();
                //string todaysDate = currentDate.ToString();

                var Id = (costumerRegisterDataGrid1.SelectedItem as CostumerRegister).ClientID;
                CostumerRegister updatMember = (from m in test.CostumerRegisters where m.ClientID == Id select m).Single();

                updatMember.FirstName = firstNameTextBox.Text;
                updatMember.LastName  = lastNameTextBox.Text;
                updatMember.Gender    = genderComboBox.Text;
                updatMember.TellNo    = phoneNumberTextBox1.Text;

                updatMember.Occupation           = occupationTextBox1.Text;
                updatMember.NxtOfKinName         = nextOfKinName.Text;
                updatMember.NxtOfKinNumber       = nextOfKinPhone.Text;
                updatMember.NxtOfKinRelationship = nextOfKinRelation.Text;

                //updatMember.DateRegistered = DateTime.Now.ToString();
                updatMember.Address1 = address1TextBox.Text;
                updatMember.Address2 = address2TextBox.Text;

                test.SaveChanges();
                costumerRegisterDataGrid1.ItemsSource = test.CostumerRegisters.ToList();

                //NotifyTrasition();
            }
            catch (Exception ex)
            {
                AlertOK alerting = new AlertOK("Something went wrong check your enteries again", ex.Message);
                alerting.ShowDialog();
                //MessageBox.Show(ex.Message, "Something went wrong! Check your Enteries again", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }