Beispiel #1
0
        private void saveInvoiceBtn_Click(object sender, RoutedEventArgs e)
        {
            var   db            = new DataBase();
            var   dt            = db.SelectInvoicePos(_id);
            int   index         = 1;
            float sumNetValue   = 0;
            float sumVatValue   = 0;
            float sumGrossValue = 0;
            int   vat           = 0;

            try
            {
                foreach (DataRow dr in dt.Rows)
                {
                    float.TryParse(dr["VAT_Value"].ToString(), out var vatValue);
                    float.TryParse(dr["Gross_Value"].ToString(), out var grossValue);
                    float.TryParse(dr["Net_Value"].ToString(), out var netValue);
                    int.TryParse(dr["VAT"].ToString(), out var vatResult);
                    sumNetValue   += netValue;
                    sumVatValue   += vatValue;
                    sumGrossValue += grossValue;
                    vat            = vatResult;
                }

                sumNetValue   = (float)Math.Round(sumNetValue, 2);
                sumVatValue   = (float)Math.Round(sumVatValue, 2);
                sumGrossValue = (float)Math.Round(sumGrossValue, 2);
                int    zlote        = (int)Math.Round(sumGrossValue, 2);
                int    grosze       = (int)(100 * Math.Round(sumGrossValue, 2)) % 100;
                string kwotaSlownie = KwotaSlownie.LiczbaSlownie(zlote) + " " +
                                      KwotaSlownie.WalutaSlownie(zlote, "PLN") + " " +
                                      KwotaSlownie.LiczbaSlownie(grosze) + " " +
                                      KwotaSlownie.WalutaSlownie(grosze, ".PLN");

                int splitPayment;
                int.TryParse(clientIdTxtBox.Text, out var clientIdResult);
                DateTime.TryParse(issuingDateDatePick.SelectedDate.ToString(), out var issuedateResult);
                DateTime.TryParse(sellDateDatePick.SelectedDate.ToString(), out var saledateResult);
                DateTime.TryParse(paymentDateDatePick.SelectedDate.ToString(), out var paymentdateResult);
                bool splitPaymentCheck = Convert.ToBoolean(splitPaymentCheckBox.IsChecked);
                splitPayment = splitPaymentCheck ? 1 : 0;
                db.UpdateInvoice(invoiceNumberTxtBox.Text, clientIdResult, clientNameTxtBox.Text, NipTxtBox.Text,
                                 clientAddressTxtBox.Text, clientAddressPosNumberTxtBox.Text, clientAddressLocNumberTxtBox.Text,
                                 ClientPostalCodeTxtBox.Text, ClientCityTxtBox.Text, ClientCountryTxtBox.Text, issuedateResult,
                                 saledateResult, paymentdateResult, paymentMethodCBox.Text, accountNumberCBox.Text, splitPayment,
                                 noteTxtBox.Text, sumNetValue, sumVatValue, vat, sumGrossValue,
                                 issuingUserNameLbl.Content.ToString(), currencyCBox.Text, 1f, splitPaymentAccountCBox.Text, _id,
                                 kwotaSlownie);



                MessageBox.Show("Faktura zapisana");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
Beispiel #2
0
        private void closeBtn_Click(object sender, RoutedEventArgs e)
        {
            var   db            = new DataBase();
            var   dt            = db.SelectInvoicePos(_id);
            int   index         = 1;
            float sumNetValue   = 0;
            float sumVatValue   = 0;
            float sumGrossValue = 0;
            int   vat           = 0;

            try
            {
                foreach (DataRow dr in dt.Rows)
                {
                    float.TryParse(dr["VAT_Value"].ToString(), out var vatValue);
                    float.TryParse(dr["Gross_Value"].ToString(), out var grossValue);
                    float.TryParse(dr["Net_Value"].ToString(), out var netValue);
                    int.TryParse(dr["VAT"].ToString(), out var vatResult);
                    sumNetValue   += netValue;
                    sumVatValue   += vatValue;
                    sumGrossValue += grossValue;
                    vat            = vatResult;
                }

                sumNetValue   = (float)Math.Round(sumNetValue, 2);
                sumVatValue   = (float)Math.Round(sumVatValue, 2);
                sumGrossValue = (float)Math.Round(sumGrossValue, 2);
                int    zlote        = (int)Math.Round(sumGrossValue, 2);
                int    grosze       = (int)(100 * Math.Round(sumGrossValue, 2)) % 100;
                string kwotaSlownie = KwotaSlownie.LiczbaSlownie(zlote) + " " +
                                      KwotaSlownie.WalutaSlownie(zlote, "PLN") + " " +
                                      KwotaSlownie.LiczbaSlownie(grosze) + " " +
                                      KwotaSlownie.WalutaSlownie(grosze, ".PLN");
                if (_id != -1)
                {
                    db.UpdatePaymentValues((float)Math.Round(sumNetValue, 2), (float)Math.Round(sumVatValue, 2), vat,
                                           sumGrossValue = (float)Math.Round(sumGrossValue, 2), _id, kwotaSlownie);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }

            int result = 0;
            var di     = new DataTable();

            di = null;
            try
            {
                di = db.SelectInvoiceId("new");
            }
            catch (Exception exception)
            {
                System.Windows.MessageBox.Show(exception.ToString());
            }

            try
            {
                int.TryParse(di.Rows[0]["InvoiceID"].ToString(), out result);
            }
            catch (Exception exception)
            {
                //  System.Windows.MessageBox.Show(exception.ToString());
            }



            db.DeleteAllInvoicePos(result);
            db.DeleteAllPaymentPos(result);
            db.DeleteInvoiceNumber("new");


            this.Close();
        }
Beispiel #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var   db            = new DataBase();
            var   dt            = db.SelectInvoicePos(_id);
            int   index         = 1;
            float sumNetValue   = 0;
            float sumVatValue   = 0;
            float sumGrossValue = 0;
            int   vat           = 0;

            try
            {
                if (_id != -1)
                {
                    int id_pos = 0;
                    positionsStack.Children.Remove(sumPanel);
                    positionsStack.Children.Add(new InvoicePossitionViewClass(1, _id, id_pos, "", "", "",
                                                                              "", "", "", "", "", ""));
                    positionsStack.Children.Add(sumPanel);
                }
                else
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        float.TryParse(dr["VAT_Value"].ToString(), out var vatValue);
                        float.TryParse(dr["Gross_Value"].ToString(), out var grossValue);
                        float.TryParse(dr["Net_Value"].ToString(), out var netValue);
                        int.TryParse(dr["VAT"].ToString(), out var vatResult);
                        sumNetValue   += netValue;
                        sumVatValue   += vatValue;
                        sumGrossValue += grossValue;
                        vat            = vatResult;
                    }

                    sumNetValue   = (float)Math.Round(sumNetValue, 2);
                    sumVatValue   = (float)Math.Round(sumVatValue, 2);
                    sumGrossValue = (float)Math.Round(sumGrossValue, 2);
                    int    zlote        = (int)Math.Round(sumGrossValue, 2);
                    int    grosze       = (int)(100 * Math.Round(sumGrossValue, 2)) % 100;
                    string kwotaSlownie = KwotaSlownie.LiczbaSlownie(zlote) + " " +
                                          KwotaSlownie.WalutaSlownie(zlote, "PLN") + " " +
                                          KwotaSlownie.LiczbaSlownie(grosze) + " " +
                                          KwotaSlownie.WalutaSlownie(grosze, ".PLN");

                    int splitPayment;
                    int.TryParse(clientIdTxtBox.Text, out var clientIdResult);
                    DateTime.TryParse(issuingDateDatePick.SelectedDate.ToString(), out var issuedateResult);
                    DateTime.TryParse(sellDateDatePick.SelectedDate.ToString(), out var saledateResult);
                    DateTime.TryParse(paymentDateDatePick.SelectedDate.ToString(), out var paymentdateResult);
                    bool splitPaymentCheck = Convert.ToBoolean(splitPaymentCheckBox.IsChecked);
                    splitPayment = splitPaymentCheck ? 1 : 0;
                    db.InsertInvoice(invoiceNumberTxtBox.Text, clientIdResult, clientNameTxtBox.Text, NipTxtBox.Text,
                                     clientAddressTxtBox.Text, clientAddressPosNumberTxtBox.Text, clientAddressLocNumberTxtBox.Text,
                                     ClientPostalCodeTxtBox.Text, ClientCityTxtBox.Text, ClientCountryTxtBox.Text, issuedateResult,
                                     saledateResult, paymentdateResult, paymentMethodCBox.Text, accountNumberCBox.Text, splitPayment,
                                     noteTxtBox.Text, sumNetValue, sumVatValue, vat, sumGrossValue,
                                     issuingUserNameLbl.Content.ToString(), currencyCBox.Text, 1f, splitPaymentAccountCBox.Text,
                                     kwotaSlownie);
                    var did = db.SelectInvoiceId(invoiceNumberTxtBox.Text);
                    int.TryParse(did.Rows[0]["InvoiceID"].ToString(), out var invoiceIdResult);
                    _id = invoiceIdResult;
                    int id_pos = 0;
                    positionsStack.Children.Remove(sumPanel);
                    positionsStack.Children.Add(new InvoicePossitionViewClass(1, _id, id_pos, "", "", "",
                                                                              "", "", "", "", "", ""));
                    positionsStack.Children.Add(sumPanel);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Błąd");
            }
        }