Ejemplo n.º 1
0
        private void SaveItem_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtFullName.Text) || string.IsNullOrWhiteSpace(txtUserName.Text) ||
                    string.IsNullOrWhiteSpace(txtPassword.Text))
                {
                    MessageBox.Show("These Fields cannot be empty!");
                }
                var db    = new AMDDataContext();
                var Users = from p in db.Users
                            where p.Username == txtUserName.Text
                            select p;
                if (Users.Count() != 0)
                {
                    MessageBox.Show("User already exists!");
                }
                else
                {
                    //var NewUser = new users with { FullName = txtFullName.Text, Username = txtUserName.Text, Password = txtPassword, Role = txtRole}
                    var NewUser = new User();
                    NewUser.FullName = txtFullName.Text;
                    NewUser.Username = txtUserName.Text;
                    NewUser.Password = txtPassword.Text;
                    if (rdbAdminRole.IsChecked == true)
                    {
                        NewUser.Role = "Admin";
                        db.Users.InsertOnSubmit(NewUser);
                        db.SubmitChanges();

                        MessageBox.Show("User successfully added as Admin!");
                    }
                    else
                    {
                        NewUser.Role = "User";
                        db.Users.InsertOnSubmit(NewUser);
                        db.SubmitChanges();

                        MessageBox.Show("User successfully added as User!");
                    }
                }
            }
            catch (Exception a)
            {
                MessageBox.Show(a.Message);
            }
        }
        private void RemoveCustomer_Click(object sender, RoutedEventArgs e)
        {
            DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Are you sure you want delete this Customer?", "Delete Customer", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                try
                {
                    AMDDataContext db             = new AMDDataContext();
                    var            DeleteCustomer = from p in db.Customers
                                                    where p.CustomerID == txtCustomerID.Text
                                                    select p;

                    foreach (var customer in DeleteCustomer)
                    {
                        db.Customers.DeleteOnSubmit(DeleteCustomer.FirstOrDefault());
                        db.SubmitChanges();
                    }

                    System.Windows.Forms.MessageBox.Show("Customer deleted successfully!", "AMD Enterprise", MessageBoxButtons.OK);

                    txtCustomerFullName.Text = string.Empty;

                    txtCustomerID.Text = string.Empty;

                    var customerid = from p in db.Customers
                                     select p;
                    var FilterCustomer = customerid.Where(o => o.CustomerID.StartsWith(txtCustomerID.Text));

                    dgvItems.ItemsSource = null;
                }
                catch (Exception a)
                {
                    System.Windows.Forms.MessageBox.Show(a.Message);
                }
            }
            else
            {
                return;
            }
        }
        private void SaveItems_Click(object sender, RoutedEventArgs e)
        {
            //foreach (var row in dgvItems1.rows)
            //{

            //}

            AMDDataContext db       = new AMDDataContext();
            Customer       SaveItem = new Customer();

            if (PrintButtonClicked == true)
            {
                SaveItem.CustomerID   = txtCustomerID.Text;
                SaveItem.CustomerName = txtCustomerFullName.Text;
                SaveItem.DateBought   = DateTime.Now;
                SaveItem.PaymentType  = PaymentType.Text;
                SaveItem.Cash         = txtCash.Text;
                SaveItem.Transfer     = txtTransfer.Text;
                SaveItem.Bank         = Bank.Text;
                SaveItem.Comment      = txtCustomerComment.Text;

                PrintButtonClicked = false;

                Reciept = false;
            }
            else
            {
                SaveItem.CustomerID   = txtCustomerID.Text;
                SaveItem.ItemName     = ItemsToPrint.Text;
                SaveItem.DateBought   = DateTime.Now;
                SaveItem.Price        = Convert.ToDouble(txtPiecesShopPrice.Text);
                SaveItem.Quantity     = Convert.ToInt32(ItemsNumber.Text);
                SaveItem.Total        = (SaveItem.Price * SaveItem.Quantity);
                SaveItem.ReducedPrice = Convert.ToDouble(txtReducedPrice.Text);

                System.Windows.Forms.MessageBox.Show("Customer successfully saved!");

                double PiecesPrice = Convert.ToDouble(txtPiecesShopPrice.Text);

                int itemsNo = Convert.ToInt32(ItemsNumber.Text);

                double TotalPayment = (PiecesPrice * itemsNo);

                Payment += TotalPayment;

                txtTotal.Text = Payment.ToString();

                txtCustomerDetailsName.Text = txtCustomerFullName.Text;

                txtPaymenttype.Text = PaymentType.Text;
            }

            if (Bank.SelectedIndex == -1)
            {
                txtBank.Text = "No Bank";
            }
            else
            {
                txtBank.Text = Bank.Text;
            }

            db.Customers.InsertOnSubmit(SaveItem);
            db.SubmitChanges();


            var customerid = from p in db.Customers
                             select p;
            var FilterCustomer = customerid.Where(o => o.CustomerID.StartsWith(txtCustomerID.Text));

            dgvItems.ItemsSource = FilterCustomer;

            //ICollectionView linqview = CollectionViewSource.GetDefaultView(customerid);
            //linqview.Filter = new Predicate<object>(o =>
            //((Customer)o).CustomerID.StartsWith(txtCustomerID.Text));
        }
Ejemplo n.º 4
0
        private void SaveItem_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(ItemName.Text) || string.IsNullOrWhiteSpace(BaleQuantity.Text) ||
                string.IsNullOrWhiteSpace(BaleActualPrice.Text) || string.IsNullOrWhiteSpace(BaleShopPrice.Text) ||
                string.IsNullOrWhiteSpace(PiecesPerBale.Text) || string.IsNullOrWhiteSpace(ItemComment.Text))
            {
                MessageBox.Show("All Fields are required please!");
                return;
            }

            if (!int.TryParse(BaleQuantity.Text, out a))
            {
                MessageBox.Show("Bale Quantity must be in Number please!");
                return;
            }
            if (!int.TryParse(BaleActualPrice.Text, out a))
            {
                MessageBox.Show("Bale Actual Price must be in Number please!");
                return;
            }
            if (!int.TryParse(BaleShopPrice.Text, out a))
            {
                MessageBox.Show("Bale Shop price must be in Number please!");
                return;
            }
            if (!int.TryParse(PiecesPerBale.Text, out a))
            {
                MessageBox.Show("pieces Per Bale must be in Number please!");
                return;
            }

            var db = new AMDDataContext();

            var Items = from p in db.Items
                        where p.ItemName == ItemName.Text
                        select p;

            if (Items.Count() != 0)
            {
                MessageBox.Show("Item already exists!");
            }
            else
            {
                var NewItem = new Item();
                NewItem.ItemName               = ItemName.Text;
                NewItem.DateArrived            = DateTime.Now;
                NewItem.BaleQuantity           = Convert.ToInt32(BaleQuantity.Text);
                NewItem.BaleActualPrice        = Convert.ToInt32(BaleActualPrice.Text);
                NewItem.BaleShopPrice          = Convert.ToInt32(BaleShopPrice.Text);
                NewItem.PiecesPerBale          = Convert.ToInt32(PiecesPerBale.Text);
                NewItem.ItemComment            = ItemComment.Text;
                NewItem.TotalPieces            = (Convert.ToInt32(BaleQuantity.Text) * Convert.ToInt32(PiecesPerBale.Text));
                NewItem.PiecesActualPrice      = (Convert.ToInt32(BaleActualPrice.Text) / Convert.ToInt32(PiecesPerBale.Text));
                NewItem.PiecesShopPrice        = (Convert.ToInt32(BaleShopPrice.Text) / Convert.ToInt32(PiecesPerBale.Text));
                NewItem.PiecesActualPriceTotal = (Convert.ToInt32(PiecesPerBale.Text) * (Convert.ToInt32(BaleActualPrice.Text) / Convert.ToInt32(PiecesPerBale.Text)));
                NewItem.PiecesPerBaleTotal     = (Convert.ToInt32(BaleQuantity.Text) * Convert.ToInt32(PiecesPerBale.Text));
                NewItem.PiecesShopPriceTotal   = (Convert.ToInt32(PiecesPerBale.Text) * (Convert.ToInt32(BaleShopPrice.Text) / Convert.ToInt32(PiecesPerBale.Text)));
                NewItem.BaleActualPriceTotal   = (Convert.ToInt32(BaleActualPrice.Text) * Convert.ToInt32(BaleQuantity.Text));
                NewItem.BaleShopPriceTotal     = (Convert.ToInt32(BaleShopPrice.Text) * Convert.ToInt32(BaleQuantity.Text));

                db.Items.InsertOnSubmit(NewItem);
                db.SubmitChanges();

                MessageBox.Show("Item successfully added!");
            }
        }