コード例 #1
0
        private void ResetOnLostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                if (newDiscountId.Text == "")
                {
                    UpdateDiscountButton.Visibility = Visibility.Hidden;
                    CreateDiscountButton.Visibility = Visibility.Visible;
                    newDiscount();
                }
                else
                {
                    UpdateDiscountButton.Visibility = Visibility.Visible;
                    CreateDiscountButton.Visibility = Visibility.Hidden;

                    int.TryParse(newDiscountId.Text.ToString(), out serachID);

                    searchDiscount = context.DiscountTables.Find(serachID);

                    DiscountTitle.Text  = searchDiscount.DiscountTitle;
                    DiscountAmount.Text = searchDiscount.DiscountAmount.ToString();
                }
            }
            catch (NullReferenceException err)
            {
                this.ShowMessageAsync("Invalid", "The Id box is empty or the entered Id doesn't exists");
                Debug.WriteLine(err.ToString());
            }
        }
コード例 #2
0
        private void createButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                DiscountTable modal = new DiscountTable();

                modal.DiscountAmount       = 0;
                modal.DiscountTitle        = DiscountTitle.Text.ToString();
                modal.DiscountByPercentage = int.Parse(DiscountPercentage.Text.ToString());
                context.DiscountTables.Add(modal);
                context.SaveChanges();
                this.ShowMessageAsync("Created", "New Discount created successfully!");
                newDiscount();
            }
            catch (FormatException)
            {
                this.ShowMessageAsync("Format Exception", "The fields weren't filled properly");
            }
            clearNow();
        }
コード例 #3
0
        protected void forUpdate(DiscountTable dt)
        {
            try
            {
                dt.DiscountTitle        = DiscountTitle.Text.ToString();
                dt.DiscountAmount       = 0;
                dt.DiscountByPercentage = int.Parse(DiscountPercentage.Text.ToString());

                context.Entry(dt).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();

                this.ShowMessageAsync("Done", "Discount Updated");

                UpdateDiscountButton.Visibility = Visibility.Hidden;
                CreateDiscountButton.Visibility = Visibility.Visible;
            }
            catch (NullReferenceException)
            {
                this.ShowMessageAsync("Invalid", "Some values are invalid");
            }
        }
コード例 #4
0
        private void saveButtonClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var FeeAfter = int.Parse(feeAfter.Text.ToString());
                var id       = int.Parse(Id.Text.ToString());

                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Other"].ConnectionString;
                conn.Open();

                SqlCommand cmd = new SqlCommand("DicountExists", conn);

                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@AdmissionNumber", id);
                cmd.Parameters.AddWithValue("@FeeID", choose);

                string exist = null;
                using (var reader = cmd.ExecuteReader())
                {
                    reader.Read();

                    exist = reader["Discount"].ToString();
                }
                if (exist == "True")
                {
                    var c = context.UpdateDiscount
                            (
                        admissionNumber: id,
                        feeID: choose,
                        discountID: applyDiscount
                            );

                    this.ShowMessageAsync("Updated", "Student already existed with the discount on the fee.");
                }
                else
                {
                    StudentDiscountTable modal = new StudentDiscountTable();

                    modal.AdmissionNumber = id;
                    modal.FeeID           = choose;
                    modal.DiscountID      = applyDiscount;
                    modal.DiscountedFee   = FeeAfter;

                    context.StudentDiscountTables.Add(modal);
                    context.SaveChanges();

                    searchDiscount = context.DiscountTables.Find(applyDiscount);
                    searchDiscount.DiscountAmount = FeeAfter;

                    context.Entry(searchDiscount).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();

                    this.ShowMessageAsync("Added", "Student discount added to the fee");
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
            clearAll();
        }