Beispiel #1
0
        private void btnConfirm_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int gst;
                if (int.TryParse(txtGST.Text.Trim(), out gst))
                {
                    BudgetHelper client = new BudgetHelper();
                    client.UpdateGST(user, gst);
                    client.Close();

                    MessageBox.Show("GST have been added/updated", "Updated GST",
                        MessageBoxButton.OK, MessageBoxImage.Information);
                    this.Close();

                }
                else
                {
                    MessageBox.Show("GST Percentage must be numeric", "Invalid input", MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void loadBudgetItems()
        {
            budgetItemList = new List<BudgetItemState>();
            BudgetHelper client = new BudgetHelper();
            try
            {
                decimal totalAmount = 0;
                OptimizedBudgetItems budgetItems = client.GetBudgetItem(event_.EventID);
                if (budgetItems != null)
                {
                    List<OptimizedBudgetItemsDetails> budgetItemsList = budgetItems.BudgetItemsList.ToList<OptimizedBudgetItemsDetails>();

                    foreach (OptimizedBudgetItemsDetails budgetItem in budgetItemsList)
                    {
                        Items item = client.GetItemDetail(budgetItem);
                        BudgetItemState bis = new BudgetItemState(item, budgetItem.IsBought);
                        if (budgetItem.IsBought)
                        {
                            totalAmount += item.ActualPrice;
                        }
                        else
                        {
                            item.ActualPrice = 0;
                            totalAmount += item.EstimatedPrice;
                        }

                        budgetItemList.Add(bis);
                    }

                    lvBudgetItem.ItemsSource = budgetItemList;
                }
                //.ItemsSource = incomeList;
                txtTotalExpenditure.Text = "$" + totalAmount.ToString("0.00");
                expenditure = totalAmount;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }
        }
Beispiel #3
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     BudgetHelper client = new BudgetHelper();
     this.txtGST.Text = client.GetGST().ToString();
     client.Close();
 }
 private void loadIncome()
 {
     BudgetHelper client = new BudgetHelper();
     try
     {
         decimal totalAmount = 0;
         incomeList = client.ViewBudgetIncome(user, event_.EventID).ToList<BudgetIncome>();
         lvBudgetIncome.ItemsSource = incomeList;
         foreach (BudgetIncome item in incomeList)
         {
             totalAmount += item.IncomeAfterGST;
         }
         //.ItemsSource = incomeList;
         this.txtTotalIncome.Text = "$" + totalAmount.ToString("0.00");
         income = totalAmount;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         client.Close();
     }
 }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            BudgetHelper client = new BudgetHelper();
            OptimizedBudgetItems budget = client.GetBudgetItem(event_.EventID);
            client.Close();

            if (budget != null)
            {
                if (MessageBox.Show("You already have an optimized item list, all previous changes will be overwritten" +
                Environment.NewLine + Environment.NewLine +
                "Do you want to overwrite? (It cannot be undone)", "Confirm Overwrite",
                MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    save();
                }
                else
                {
                    return;
                }
            }
            else
            {
                save();
            }
        }
        private void btnUpdateItem_Click(object sender, RoutedEventArgs e)
        {
            decimal price;
            if (txtItemActualPrice.Text.Trim().CompareTo("N.A") == 0)
            {
                txtItemActualPrice.Text = "-1.00";
            }
            bool isdecimal = decimal.TryParse(txtItemActualPrice.Text, out price);
            if (!isdecimal)
            {
                MessageBox.Show("Invalid Actual Price");
                txtItemActualPrice.Text = "";
                txtItemActualPrice.Focus();
                return;
            }

            OptimizedBudgetItemsDetails budgetItem = lvBItem.GetEditItem();
            BudgetHelper client = new BudgetHelper();
            try
            {
                Items item2Edit = client.GetItemDetail(budgetItem);
                client.UpdateActualPrice(user, item2Edit, price);
                clearBudgetItemForm();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occured: " + ex.Message,
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                client.Close();
            }
            loadBudgetItems();
        }
        private void saveOptimalList()
        {
            //Use threading to stop system from "Hanging" as it may take a long time to save
            //as a list of objects are sent over via SOAP
            System.Threading.Thread thread = new System.Threading.Thread(
                new System.Threading.ThreadStart(
                delegate()
                {
                    System.Windows.Threading.DispatcherOperation
                    dispatcherOp = this.Dispatcher.BeginInvoke(
                    System.Windows.Threading.DispatcherPriority.Normal,
                    new Action(delegate()
                    {
                        Mouse.OverrideCursor = Cursors.Wait;
                        MessageBox.Show("Please wait while we save your desired optimal list...");

                        BudgetHelper client = new BudgetHelper();
                        try
                        {
                            int sat = int.Parse(txtTotalSat.Text.Trim());
                            decimal price = decimal.Parse(txtTotalPrice.Text.Trim());
                            client.SaveBudgetList(user, event_.EventID, sat, price,
                                ((List<Items>)lstItemList.ItemsSource).ToArray());
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("An Expection has occured: " + ex.Message, "Exception while saving optimal item list",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        finally
                        {
                            client.Close();
                        }
                    }
                ));

                    dispatcherOp.Completed += new EventHandler(saveOptimalList_Completed);
                }
            ));

            thread.Start();
        }
        private void lv_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Helper.IdleHelper.startIdleTimer();
            if (lvBItem.lv.SelectedIndex == -1)
            {
                Helper.IdleHelper.stopIdleTimer();
                clearBudgetItemForm();
                return;
            }

            OptimizedBudgetItemsDetails budgetItem = lvBItem.GetEditItem();
            BudgetHelper client = new BudgetHelper();
            try
            {
                Items item2Edit = client.GetItemDetail(budgetItem);
                if (item2Edit != null)
                {
                    mapItem(item2Edit);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occured: " + ex.Message,
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                client.Close();
            }
        }
        private void loadBudgetItems()
        {
            BudgetHelper client = new BudgetHelper();
            try
            {
                OptimizedBudgetItems budget = client.GetBudgetItem(event_.EventID);
                txtTotalPrice.Text = budget.TotalEstimatedPrice.ToString("0.00");
                txtTotalSat.Text = budget.TotalSatisfaction.ToString();
                txtGenDate.Text = budget.GeneratedDate.ToString("dd MMM yyyy");
                btnCancelEditItem.IsEnabled = btnUpdateItem.IsEnabled = true;
                //loadList
                lvBItem.SetExistingSource(budget.BudgetItemsList.ToList<OptimizedBudgetItemsDetails>());
                lvBItem.lv.SelectedIndex = -1;

            }
            catch (NullReferenceException)
            {
                txtTotalPrice.Text = "N.A";
                txtTotalSat.Text = "N.A";
                txtGenDate.Text = "N.A";
                btnCancelEditItem.IsEnabled = btnUpdateItem.IsEnabled = false;
                lvBItem.lv.SelectedIndex = -1;
                MessageBox.Show("There is no optimized list yet");

            }
            catch (Exception ex)
            {
                txtTotalPrice.Text = "N.A";
                txtTotalSat.Text = "N.A";
                txtGenDate.Text = "N.A";
                btnCancelEditItem.IsEnabled = btnUpdateItem.IsEnabled = false;
                lvBItem.lv.SelectedIndex = -1;
                MessageBox.Show("An error has occured: " + ex.Message,
                    "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                client.Close();
            }
        }
        //TODO: Save Changes and Test Method!
        public override bool saveChanges()
        {
            if (txtName.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please enter the income's name.", "Invalid Input",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return false;
            }
            else if (txtSource.Text.Trim().Length == 0)
            {
                MessageBox.Show("Please enter the source of the income.", "Invalid Input",
                  MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return false;
            }
            else if (txtIncb4Gst.Text.Trim().Length == 0)
            {
                MessageBox.Show("Income must be numeric!", "Invalid Input",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                txtIncb4Gst.Focus();
                return false;
            }
            else if (dtpReceivedDate.SelectedDate==null)
            {
                MessageBox.Show("Please Select your received date!", "Invalid Date",
                    MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return false;
            }
            try
            {
                BudgetHelper client = new BudgetHelper();
                if (selectedIndex == -1)
                {
                    BudgetIncome bIncome = new BudgetIncome();
                    bIncome.Name = txtName.Text;
                    bIncome.Description = txtDescription.Text;
                    bIncome.DateReceived = dtpReceivedDate.SelectedDate.Value;
                    bIncome.EventID = event_.EventID;
                    bIncome.GstValue = decimal.Parse(txtGst.Text.Trim());
                    bIncome.IncomeBeforeGST = decimal.Parse(txtIncb4Gst.Text.Trim());
                    bIncome.IsGstLiable = chkGSTLiable.IsChecked.Value;
                    bIncome.Source = txtSource.Text;
                    bIncome.IncomeID = client.AddIncome(user, event_.EventID, bIncome);
                    incomeList.Add(bIncome);
                    CollectionViewSource.GetDefaultView(lstIncomeList.ItemsSource).Refresh();
                    clearAll();
                }
                else
                {
                    BudgetIncome bIncome = incomeList[selectedIndex];
                    bIncome.Name = txtName.Text;
                    bIncome.Description = txtDescription.Text;
                    bIncome.DateReceived = dtpReceivedDate.SelectedDate.Value;
                    bIncome.EventID = event_.EventID;
                    bIncome.GstValue = decimal.Parse(txtGst.Text.Trim());
                    bIncome.IncomeBeforeGST = decimal.Parse(txtIncb4Gst.Text.Trim());
                    bIncome.IsGstLiable = chkGSTLiable.IsChecked.Value;
                    bIncome.Source = txtSource.Text;
                    client.EditBudgetIncome(user, event_.EventID, bIncome.IncomeID, bIncome);
                    incomeList[selectedIndex] = bIncome;
                    CollectionViewSource.GetDefaultView(lstIncomeList.ItemsSource).Refresh();
                    changed = false;
                }
                client.Close();

                MessageBox.Show("Operation succeeded!");
                loadIncome();
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return false;
            }
        }
 private void loadIncome()
 {
     BudgetHelper client = new BudgetHelper();
     try
     {
         txtGstPercent.Text = client.GetGST().ToString();
         incomeList = client.ViewBudgetIncome(user, event_.EventID).ToList<BudgetIncome>();
         lstIncomeList.ItemsSource = incomeList;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         client.Close();
     }
     clearAll();
     CalculateNettIncome();
 }
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (lstIncomeList.SelectedIndex == -1)
                return;
            BudgetHelper client = new BudgetHelper();

            try
            {
                BudgetIncome bIncome = (BudgetIncome)lstIncomeList.SelectedItem;
                client.DeleteBudgetIncome(user, bIncome.IncomeID, event_.EventID);
                MessageBox.Show("Operation succeeded!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                client.Close();
            }
            loadIncome();
            CalculateNettIncome();
        }