Ejemplo n.º 1
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (_canChange)
     {
         if (MessageBox.Show("Czy chcesz usunąć wpis?", "Usuwanie", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
             {
                 var entry = db.Entry(_payments);
                 if (entry.State == System.Data.Entity.EntityState.Detached)
                 {
                     db.Payments.Attach(_payments);
                 }
                 db.Payments.Remove(_payments);
                 db.SaveChanges();
                 ReloadGrid();
                 Clear();
             }
         }
     }
     else
     {
         MessageBox.Show("Kliknij 2x na wiersz, który chcesz usunąć - następnie usuń");
     }
 }
Ejemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            //sprawdzic czy jest uzupelnione
            if (txtValue.Text != "" & txtPlace.Text != "" & txtType.Text != "" & dateTimePickPayments.Value.ToString() != "" && txtNamePayment.Text != "")
            {
                _payments.ValuePayment = decimal.Parse(txtValue.Text);
                _payments.PlaceName    = txtPlace.Text.Trim();
                _payments.TypeName     = txtType.Text.Trim();
                _payments.DatePayment  = dateTimePickPayments.Value;
                _payments.ShopName     = txtNamePayment.Text.Trim();

                using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
                {
                    if (_payments.IdPayment == 0) //insert
                    {
                        db.Payments.Add(_payments);
                    }
                    else //update
                    {
                        db.Entry(_payments).State = System.Data.Entity.EntityState.Modified; //ustawienie flagi na update
                    }
                    db.SaveChanges();
                }
                ReloadGrid();
                Clear();
            }
            else
            {
                MessageBox.Show("Uzupełnij dane - następnie dodaj");
            }
        }
Ejemplo n.º 3
0
 private void ReloadGrid()
 {
     using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
     {
         _paymentsLst = db.Payments.ToList <Payments>();
         gridViewPayments.DataSource = _paymentsLst;
     }
 }
Ejemplo n.º 4
0
 private void ReloadGrid()
 {
     using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
     {
         _incomesLst = db.Incomes.ToList <Incomes>();
         gridViewIncomes.DataSource = _incomesLst;
     }
 }
Ejemplo n.º 5
0
        private void PreparePoints()
        {
            if (_all)
            {
                using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
                {
                    List <Payments> _paymentsLst = new List <Payments>();
                    _paymentsLst = db.Payments.ToList <Payments>();
                    chart.Series.Add("Przychody");

                    List <Incomes> _incomesLst = new List <Incomes>();
                    _incomesLst = db.Incomes.ToList <Incomes>();
                    chart.Series.Add("Wydatki");

                    foreach (Incomes inc in _incomesLst)
                    {
                        chart.Series["Przychody"].Points.AddXY(inc.DateIncome, inc.ValueOfIncome);
                        chart.Series["Przychody"]["PixelPointWidth"] = "15";
                    }
                    foreach (Payments payment in _paymentsLst)
                    {
                        chart.Series["Wydatki"].Points.AddXY(payment.DatePayment, payment.ValuePayment);
                        chart.Series["Wydatki"]["PixelPointWidth"] = "15";
                    }
                }
            }
            else
            {
                int counterOfPoint = 0;
                if (_incomesLst != null)
                {
                    // _incomesLst.Where(incIt => incIt.DateIncome > _dateFrom && incIt.DateIncome < _dateTo).GroupBy(grp => grp.TypeIncome).ToList()
                    //tworzenie wykresu wydatków
                    foreach (Incomes inc in _incomesLst.Where(incIt => incIt.DateIncome > _dateFrom && incIt.DateIncome < _dateTo).Distinct().ToList())
                    {
                        //chart.Series[_nameSeries].Points.AddXY(inc.TypeIncome, inc.ValueOfIncome);
                        chart.Series[_nameSeries].Points.AddXY(inc.TypeIncome, inc.ValueOfIncome);// _incomesLst.Where(y=>y.TypeIncome == inc.TypeIncome).Sum(x=>x.ValueOfIncome).Value);
                        chart.Series[_nameSeries].Points.ElementAt(counterOfPoint).ToolTip = inc.ValueOfIncome.ToString();
                        counterOfPoint++;
                    }
                }
                else
                {
                    //tworzenie wykresu przychodów
                    foreach (Payments payment in _paymnetsLst.Where(payIt => payIt.DatePayment > _dateFrom && payIt.DatePayment < _dateTo).ToList())
                    {
                        chart.Series[_nameSeries].Points.AddXY(payment.TypeName, payment.ValuePayment);
                        chart.Series[_nameSeries].Points.ElementAt(counterOfPoint).ToolTip = payment.ValuePayment.ToString();
                        counterOfPoint++;
                    }
                }
                SetBarWidth();
            }
            SetScrollbars();
        }
Ejemplo n.º 6
0
        private void gridViewIncomes_DoubleClick(object sender, EventArgs e)
        {
            if (gridViewIncomes.CurrentRow.Index != -1)
            {
                _canChange       = true;
                _incom.IdIncomes = Convert.ToInt32(gridViewIncomes.CurrentRow.Cells["IdIncomes"].Value);
                using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
                {
                    _incom = db.Incomes.Where(id => id.IdIncomes == _incom.IdIncomes).FirstOrDefault();

                    txtValue.Text             = _incom.ValueOfIncome.ToString();
                    txtName.Text              = _incom.NameIncome;
                    txtType.Text              = _incom.TypeIncome;
                    dateTimePicekIncome.Value = _incom.DateIncome.Value;
                }
            }
        }
Ejemplo n.º 7
0
        private void gridViewPayments_DoubleClick(object sender, EventArgs e)
        {
            if (gridViewPayments.CurrentRow.Index != -1)
            {
                _canChange          = true;
                _payments.IdPayment = Convert.ToInt32(gridViewPayments.CurrentRow.Cells["IdPayment"].Value);
                using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
                {
                    _payments = db.Payments.Where(id => id.IdPayment == _payments.IdPayment).FirstOrDefault();

                    txtValue.Text = _payments.ValuePayment.ToString();
                    txtPlace.Text = _payments.PlaceName;
                    txtType.Text  = _payments.TypeName;
                    dateTimePickPayments.Value = _payments.DatePayment.Value;
                    txtNamePayment.Text        = _payments.ShopName;
                }
            }
        }
Ejemplo n.º 8
0
        private void btnFiltr_Click(object sender, EventArgs e)
        {
            if (cmbField.SelectedValue.ToString() != "" && cmbOperand.SelectedValue.ToString() != "" && txtValueFilter.Text != "")
            {
                decimal x = 0;
                if (cmbField.SelectedValue.ToString() == "Kwota" && decimal.TryParse(txtValueFilter.Text, out x))
                {
                    using (OCTOPUSEntities4 db = new OCTOPUSEntities4())
                    {
                        List <Payments> payments = new List <Payments>();
                        payments = db.Payments.ToList <Payments>();
                        List <Payments> paymentsFiltered = new List <Payments>();

                        switch (cmbField.SelectedValue.ToString())
                        {
                        case "Kwota":
                            if (cmbOperand.SelectedValue.ToString() == "=")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment == decimal.Parse(txtValueFilter.Text)).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment == decimal.Parse(txtValueFilter.Text)).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment == decimal.Parse(txtValueFilter.Text)).ToList();
                                }
                            }
                            if (cmbOperand.SelectedValue.ToString() == "<")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment < decimal.Parse(txtValueFilter.Text)).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment < decimal.Parse(txtValueFilter.Text)).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment < decimal.Parse(txtValueFilter.Text)).ToList();
                                }
                            }
                            if (cmbOperand.SelectedValue.ToString() == ">")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment > decimal.Parse(txtValueFilter.Text)).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment > decimal.Parse(txtValueFilter.Text)).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.ValuePayment < decimal.Parse(txtValueFilter.Text)).ToList();
                                }
                            }
                            gridViewPayments.DataSource = paymentsFiltered;
                            break;

                        case "Data":
                            if (cmbOperand.SelectedValue.ToString() == "=")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.DatePayment.ToString().Remove(10, 9) == txtValueFilter.Text).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.DatePayment.ToString().Remove(10, 9) == txtValueFilter.Text).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.DatePayment.ToString().Remove(10, 9) == txtValueFilter.Text).ToList();
                                }
                            }
                            gridViewPayments.DataSource = paymentsFiltered;
                            break;

                        case "Nazwa":
                            if (cmbOperand.SelectedValue.ToString() == "=")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ShopName == txtValueFilter.Text).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.ShopName == txtValueFilter.Text).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.ShopName == txtValueFilter.Text).ToList();
                                }
                            }
                            gridViewPayments.DataSource = paymentsFiltered;
                            break;

                        case "Typ":
                            if (cmbOperand.SelectedValue.ToString() == "=")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.TypeName == txtValueFilter.Text).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.TypeName == txtValueFilter.Text).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.TypeName == txtValueFilter.Text).ToList();
                                }
                            }
                            gridViewPayments.DataSource = paymentsFiltered;
                            break;

                        case "Miejsce":
                            if (cmbOperand.SelectedValue.ToString() == "=")
                            {
                                if (cmbSortType.SelectedValue.ToString() == "Malejące")
                                {
                                    paymentsFiltered = payments.Where(p => p.PlaceName == txtValueFilter.Text).ToList().OrderByDescending(o => o.ValuePayment).ToList();
                                }
                                else if (cmbSortType.SelectedValue.ToString() == "Rosnące")
                                {
                                    paymentsFiltered = payments.Where(p => p.PlaceName == txtValueFilter.Text).ToList().OrderBy(o => o.ValuePayment).ToList();
                                }
                                else
                                {
                                    paymentsFiltered = payments.Where(p => p.PlaceName == txtValueFilter.Text).ToList();
                                }
                            }
                            gridViewPayments.DataSource = paymentsFiltered;
                            break;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Popraw dane!!");
                }
            }
        }