Exemple #1
0
        private void SetProduct(Debts debts, Product product)
        {
            foreach (Debt debt in debts.TripDebts)
            {
                Person person = debt.Person;

                if (debt.CheckBoxIsDebtor.Checked)
                {
                    if (debt.TextBoxDebt.Text != "" && double.TryParse(debt.TextBoxDebt.Text, out double fixedDebt))
                    {
                        product.AddDebtorWithFixedDebt(person, fixedDebt);
                    }
                    else
                    {
                        double.TryParse(debt.TextBoxFactor.Text, out double factor);
                        product.AddDebtorWithFactor(person, factor);
                    }
                }

                string textBoxPayment = debt.TextBoxPayment.Text;

                if (textBoxPayment != "" && double.TryParse(textBoxPayment, out double paymentMoney))
                {
                    product.AddPayer(person, paymentMoney);
                }
            }
        }
Exemple #2
0
 private void FillListBoxProductsFromDebts(Debts debts)
 {
     listBoxProducts.Items.Clear();
     foreach (Product product in debts.trip.Products)
     {
         listBoxProducts.Items.Add(product);
     }
 }
Exemple #3
0
 private void FillDebtsesFromAllTrips()
 {
     foreach (Trip trip in AllTrips.Trips)
     {
         Debts debts = new Debts(trip, peopleOnPanels, listBoxPeople);
         Debtses.Add(debts);
     }
 }
Exemple #4
0
        private void buttonAddTrip_Click(object sender, EventArgs e)
        {
            string tripName = string.IsNullOrEmpty(textBoxTripName.Text) ? "NonameTrip" : textBoxTripName.Text;
            Trip   trip     = new Trip(tripName);
            Debts  debts    = new Debts(trip, peopleOnPanel, listBoxPeople);

            debtsList.AddDebtsAndTrip(debts);
            textBoxTripName.Text = "";
        }
Exemple #5
0
        public ProductForm(Debts debts, Product product, ListBox listBoxProduct, Form mainForm, int index)
        {
            this.debts          = debts;
            this.product        = product;
            this.listBoxProduct = listBoxProduct;
            this.mainForm       = mainForm;
            this.index          = index;

            InitializeComponent();
            CreateAndFillAndDoVisiblePeoplePanel();
            Location = MousePosition;
            Show();
        }
Exemple #6
0
        private void FillPayGroupLeaderListBox(Debts debts)
        {
            listBoxPayGroupLeader.Items.Clear();

            if (listBoxTrips.SelectedItems.Count == 1)
            {
                List <Person> leaders = debts.trip.GetPayGroupLeaders();

                foreach (Person person in leaders)
                {
                    listBoxPayGroupLeader.Items.Add(person);
                }
            }
        }
Exemple #7
0
        private void buttonAddPerson_Click(object sender, EventArgs e)
        {
            if (listBoxTrips.SelectedItems.Count == 1)
            {
                Debts selectedDebts = debtsList.ListBoxDebts.SelectedItem as Debts;

                string personName = string.IsNullOrEmpty(textBoxPerson.Text) ? "NoNamePerson" : textBoxPerson.Text;
                Person person     = new Person(personName);

                selectedDebts.AddDebtInListAndListBox(person);
                selectedDebts.trip.AddPerson(person);
                textBoxPerson.Text = "";
            }
        }
Exemple #8
0
        private void listBoxProducts_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                int index = this.listBoxProducts.IndexFromPoint(e.Location);
                if (index != ListBox.NoMatches)
                {
                    Debts debts = listBoxTrips.SelectedItem as Debts;

                    listBoxProducts.SelectedIndex = index;
                    Product product = listBoxProducts.Items[index] as Product;

                    ProductForm productForm = new ProductForm(debts, product, listBoxProducts, this, index);
                }
            }
        }
Exemple #9
0
        private void buttonProductDelete_Click(object sender, EventArgs e)
        {
            if (listBoxProducts.SelectedItems.Count == 1)
            {
                Product product = listBoxProducts.SelectedItem as Product;

                string dialogCaption = string.Format("Удаляем \"{0}\"", product.Name);
                if (MessageBox.Show("Вы уверены?", dialogCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Debts debts = listBoxTrips.SelectedItem as Debts;
                    debts.trip.RemoveProduct(product);
                    listBoxProducts.Items.Remove(product);
                    textBoxProductInfo.Text = "";
                }
            }
        }
Exemple #10
0
        public PersonForm(Debts debts, Debt debt, ListBox listBoxPeople, Form1 main, int index)
        {
            Location = MousePosition;
            InitializeComponent();
            this.debt  = debt;
            this.debts = debts;

            this.listBoxPeople = listBoxPeople;
            this.main          = main;
            this.index         = index;

            textBoxPersonName.Text   = debt.Person.Name;
            textBoxPersonFactor.Text = debt.Person.DebtFactor.ToString();

            Show();
        }
Exemple #11
0
        private void buttonDeletePerson_Click(object sender, EventArgs e)
        {
            if (listBoxPeople.SelectedItems.Count == 1)
            {
                Debt debt = listBoxPeople.SelectedItem as Debt;

                string dialogCaption = string.Format("Удаляем \"{0}\"", debt.Person.Name);
                if (MessageBox.Show("Вы уверены?", dialogCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Debts debts = listBoxTrips.SelectedItem as Debts;

                    debts.RemoveDebtAndPersonFromListAndTrip(debt);

                    textBoxPersonInfo.Text = "";

                    debt.PersonOnPanelMain.Clear();
                    debts.ReloadDebtsPanel();

                    ShowSelectedProductInfo();
                }
            }
            else if (listBoxPeople.SelectedItems.Count > 1)
            {
                string dialogCaption = string.Format("Удаляем людей.");
                if (MessageBox.Show("Вы уверены?", dialogCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    Debts debts = listBoxTrips.SelectedItem as Debts;

                    List <Debt> removingDebts = new List <Debt>();
                    foreach (Debt debt in listBoxPeople.SelectedItems)
                    {
                        removingDebts.Add(debt);
                    }

                    foreach (Debt debt in removingDebts)
                    {
                        debts.RemoveDebtAndPersonFromListAndTrip(debt);
                        debt.PersonOnPanelMain.Clear();
                    }

                    textBoxPersonInfo.Text = "";
                    debts.ReloadDebtsPanel();
                    ShowSelectedProductInfo();
                }
            }
        }
Exemple #12
0
        private void listBoxTrips_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBoxProductInfo.Text = "";
            textBoxPersonInfo.Text  = "";
            listBoxPayGroupDoing.Items.Clear();
            PotentialPayGroupLeader = null;

            if (listBoxTrips.SelectedItems.Count == 1)
            {
                Debts debts = (sender as ListBox).SelectedItem as Debts;

                debts.ReloadListBoxPeopleAndDebtsPanel();
                FillListBoxProductsFromDebts(debts);
                FillPayGroupLeaderListBox(debts);

                _currentTrip = debts.trip;
            }
        }
Exemple #13
0
        private void listBoxPeople_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                listBoxPeople.ClearSelected();

                int index = this.listBoxPeople.IndexFromPoint(e.Location);
                if (index != ListBox.NoMatches)
                {
                    Debts debts = listBoxTrips.SelectedItem as Debts;

                    listBoxPeople.SelectedIndex = index;
                    Debt debt = listBoxPeople.Items[index] as Debt;

                    PersonForm personForm = new PersonForm(debts, debt, listBoxPeople, this, index);
                }
            }
        }
Exemple #14
0
        private void buttonDeletTrip_Click(object sender, EventArgs e)
        {
            if (listBoxTrips.SelectedItems.Count == 1)
            {
                Debts debts = listBoxTrips.SelectedItem as Debts;

                string dialogCaption = string.Format("Удаляем \"{0}\"", debts.trip.Name);
                if (MessageBox.Show("Вы уверены?", dialogCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    debtsList.RemoveDebtsAndTpripAndRemoveFromListBox(debts);

                    listBoxPeople.Items.Clear();
                    listBoxProducts.Items.Clear();
                    panelDebts.Controls.Clear();
                    textBoxPersonInfo.Text  = "";
                    textBoxProductInfo.Text = "";
                }
            }
        }
Exemple #15
0
        private void buttonAddProduct_Click(object sender, EventArgs e)
        {
            if (debtsList.ListBoxDebts.SelectedItems.Count == 1 && !string.IsNullOrEmpty(textBoxProduct.Text))
            {
                Debts debts       = debtsList.ListBoxDebts.SelectedItem as Debts;
                Trip  currentTrip = debts.trip;

                string  productName = textBoxProduct.Text;
                Product product     = new Product(productName);

                currentTrip.AddProduct(product);
                listBoxProducts.Items.Add(product);

                SetProduct(debts, product);

                textBoxProduct.Text = "";

                ShowSelectedPersonInfo();
            }
        }
Exemple #16
0
 public void AddDebtsAndTrip(Debts debts)
 {
     ListBoxDebts.Items.Add(debts);
     Debtses.Add(debts);           //TODO тут возможно нужно будет делать проверку на наличие в списках
     AllTrips.AddTrip(debts.trip); //TODO тут возможно нужно будет делать проверку на наличие в списках
 }
Exemple #17
0
 public void RemoveDebtsAndTpripAndRemoveFromListBox(Debts debts)
 {
     ListBoxDebts.Items.Remove(debts);
     Debtses.Remove(debts);
     AllTrips.RemoveTrip(debts.trip);
 }