Exemple #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var choice = e.Parameter as Choice;
            if (choice != null)
            {
               
                _isObject = choice.Object;
                _isBorrowed = choice.Borrowed;

                if (_isBorrowed && _isObject)
                    welcomeBlock.Text = "You borrowed an Object.";
                else if (_isBorrowed && !_isObject)
                    welcomeBlock.Text = "You borrowed some Money.";
                else if (!_isBorrowed && _isObject)
                    welcomeBlock.Text = "You lend an Object.";
                else if (!_isBorrowed && !_isObject)
                    welcomeBlock.Text = "You lend some Money.";

                if (_isObject)
                {
                    currencyBox.Visibility = Visibility.Collapsed;
                    amountBox.Width = 362;
                }
                else
                {
                    categoryBox.Visibility = Visibility.Collapsed;
                    photoButton.Visibility = Visibility.Collapsed;
                    objectnameBox.Visibility = Visibility.Collapsed;
                }

                addButton.Content = "Add";
                photoButton.Content = "Add photo ?";
                textBlock.Text = "COLLECTOR -    add entry";
            }
            else if (e.Parameter is ProjectClasses.Entry)
            {
                _ent = (ProjectClasses.Entry)e.Parameter;

                _isObject = _ent.Object != null? true:false;

                if (_ent.Type.tid == 1 && _ent.Object != null)
                    welcomeBlock.Text = "You borrowed an Object.";
                else if (_ent.Type.tid == 1 && _ent.Object == null)
                    welcomeBlock.Text = "You borrowed some Money.";
                else if (_ent.Type.tid == 2 && _ent.Object != null)
                    welcomeBlock.Text = "You lend an Object.";
                else if (_ent.Type.tid == 2 && _ent.Object == null)
                    welcomeBlock.Text = "You lend some Money.";

                if (_ent.Object != null)
                {
                    currencyBox.Visibility = Visibility.Collapsed;
                    amountBox.Width = 362;
                }
                else
                {
                    categoryBox.Visibility = Visibility.Collapsed;
                    photoButton.Visibility = Visibility.Collapsed;
                    objectnameBox.Visibility = Visibility.Collapsed;
                }

                titleBox.Text = _ent.title;
                nameBox.Text = _ent.who;
                if (_ent.Object != null)
                {

                    amountBox.Text = _ent.Object.quantity.ToString();
                    categoryBox.PlaceholderText = _ent.Object.Category.cname;
                    objectnameBox.Text = _ent.Object.name;
                    // image.Source = await Base64Converter.FromBase64(_ent.Object.image);
                }
                else
                {
                    amountBox.Text = _ent.amount.ToString(CultureInfo.InvariantCulture.NumberFormat);

                    currencyBox.PlaceholderText = _ent.Currency.cursign;
                }
                initialPicker.Date = new DateTimeOffset(_ent.date);
                reminderPicker.Date = new DateTimeOffset(_ent.deadline);

                descriptionBox.Text = _ent.descr;

                prioritySwitch.IsOn = (_ent.priority != 0);

                addButton.Content = "Edit";
                photoButton.Content = "Change photo ?";
                textBlock.Text = "COLLECTOR -    edit entry";

            }
            base.OnNavigatedTo(e);
        }
Exemple #2
0
        private async void Add_debt_click(object sender, RoutedEventArgs e)
        {



            var objectQuan = 0;
            decimal moneyAmount = 0;
            ProjectClasses.Category cat = null;
            ProjectClasses.Currency cur = null;
            try
            {



                if (titleBox.Text == "" || nameBox.Text == "")
                    throw new Exception("title and name are NOT optional fields");

                if (!_isObject)
                {
                    moneyAmount = decimal.Parse(amountBox.Text, CultureInfo.InvariantCulture.NumberFormat);
                }
                else
                {
                    objectQuan = int.Parse(amountBox.Text);
                }
            }
            catch (Exception ex)
            {
                ErrorDialog(ex.Message);
                return;
            }

            if ((string)addButton.Content == "Add")
            {

                try
                {

                    if (!_isObject)
                    {

                        if (currencyBox.SelectedItem != null)
                            cur = (ProjectClasses.Currency)currencyBox.SelectedItem;
                        else throw new Exception("You forget to choose Currency");

                    }
                    else
                    {

                        if (categoryBox.SelectedItem != null) cat = (ProjectClasses.Category)categoryBox.SelectedItem;
                        else throw new Exception("You forget to choose Category ");

                    }
                }
                catch (Exception ex)
                {
                    ErrorDialog(ex.Message);
                    return;
                }

              
                    ProjectClasses.Entry debt;
                    var type = (_isBorrowed) ? 1 : 2;


                    if (_isObject)
                    {

                    var cat_final = ProjectClasses.AllCategories.First(o => o.cname == cat.cname);

                    var  obj = new ProjectClasses.Object
                        {
                            name = objectnameBox.Text,
                            image = null,
                            quantity = objectQuan,
                            catid = cat_final.cid,
                        };

                    
                    var received_object = (ProjectClasses.Object)await SerwerFunction.Getfromserver<ProjectClasses.Object>("Objects", "POST", obj);
                    

                    debt = new ProjectClasses.Entry
                        {
                            typeid = type,
                            title = titleBox.Text,
                            objectid = received_object.oid,
                            who = nameBox.Text,
                            descr = descriptionBox.Text,
                            priority = (byte) (prioritySwitch.IsOn ? 1 : 0),
                            date = initialPicker.Date.DateTime,
                            deadline = reminderPicker.Date.DateTime.AddMinutes(hourPicker.Time.TotalMinutes),
                            archived = 0,
                            userid = SerwerFunction.Uid,
                            amount = received_object.quantity
                    };
                        

                    }
                    else
                    {


                       var cur_final =  ProjectClasses.AllCurrencies.First(o => o.cursign == cur.cursign);

                         debt = new ProjectClasses.Entry
                        {
                            typeid = type,
                            title = titleBox.Text,
                            date = initialPicker.Date.DateTime,
                            who = nameBox.Text,
                            amount = moneyAmount,
                            descr = descriptionBox.Text,
                            priority = (byte) (prioritySwitch.IsOn ? 1 : 0),
                            deadline = reminderPicker.Date.DateTime.AddMinutes(hourPicker.Time.TotalMinutes),
                            currencyid = cur_final.crid,
                            archived = 0,
                            userid = SerwerFunction.Uid,
                        
                            
                        };

                    
                }


                


                var received_debt = (ProjectClasses.Entry)await SerwerFunction.Getfromserver<ProjectClasses.Entry>("Entries" , "POST", debt);


                   
                


                // var remeinder_task = new Notifify(reminderPicker.date.DateTime, hourPicker.Time);

                //   remeinder_task.set_Notification();

                Frame.Navigate(typeof(MainPage));
            }
            else
            {
               



                    if (!_isObject)
                    {

                    if (currencyBox.SelectedItem == null)
                        cur = ProjectClasses.AllCurrencies.First((o => o.cursign == currencyBox.PlaceholderText));
                    else
                        cur = (ProjectClasses.Currency)currencyBox.SelectedItem;


                }
                else
                    {

                    if (categoryBox.SelectedItem == null)
                        cat = ProjectClasses.AllCategories.First((o => o.cname == categoryBox.PlaceholderText));
                    else cat = (ProjectClasses.Category)categoryBox.SelectedItem;
                }

                _ent.title = titleBox.Text;
                    _ent.descr = descriptionBox.Text;
                    _ent.who = nameBox.Text;
                    _ent.date = initialPicker.Date.DateTime;
                    _ent.deadline = reminderPicker.Date.DateTime;
                    _ent.priority = (byte) (prioritySwitch.IsOn ? 1 : 0);

                if (_ent.Object != null)
                {
                    _ent.Object.Category = cat;
                    _ent.Object.name = objectnameBox.Text;
                    _ent.Object.quantity = int.Parse(amountBox.Text);
                   //_ent.Object.image = _base64;

                    
                }
                else
                {
                    _ent.amount = (decimal) float.Parse(amountBox.Text, CultureInfo.InvariantCulture.NumberFormat);
                    _ent.Currency = cur;
                   
                }

                //  var remeinder_task = new Notifify(reminderPicker.date.DateTime, hourPicker.Time);

                //remeinder_task.set_Notification();
                _ent.Type = null;
                int objId = _ent.id;
                _ent.Object = null;
                _ent.Currency = null;
                _ent.User = null;
              

                var received_debt = (ProjectClasses.Entry)await SerwerFunction.Getfromserver<ProjectClasses.Entry>("Entries/" + objId, "PUT", _ent);

                Frame.Navigate(typeof(MainPage));
                
            }
        }