private void BtnAdd_Click(object sender, EventArgs e)
        {
            BLInvoices   bLInvoices    = new BLInvoices();
            InvoiceModel facturaCreata = new InvoiceModel();

            if (String.IsNullOrWhiteSpace(tbNumar.Text))
            {
                errorProvider1.SetError(tbNumar, "Camp obligatoriu!");
            }
            else if (cbAdrese.SelectedIndex == -1)
            {
                errorProvider1.SetError(cbAdrese, "Nu se poate adauga un client fara adrese pe factura!");
            }
            else
            {
                try
                {
                    string nrFactura = tbNumar.Text;
                    facturaCreata.InvoiceId               = factura.InvoiceId;
                    facturaCreata.InvoiceNumber           = nrFactura;
                    facturaCreata.InvoiceDate             = dateTimePickerFactura.Value;
                    facturaCreata.Observations            = tbObs.Text;
                    facturaCreata.adresa.PartnerId        = Convert.ToInt32(cbClient.SelectedValue);
                    facturaCreata.client.ClientId         = Convert.ToInt32(cbClient.SelectedValue);
                    facturaCreata.adresa.PartnerAddressId = Convert.ToInt32(cbAdrese.SelectedValue);

                    DialogResult dialogResult = MessageBox.Show("Sigur doriti sa modificati datele clientului?", "Adresa Client", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        bLInvoices.UpdateInvoice(facturaCreata, out bool status, out string message);
                        MessageBox.Show(message, "Status", MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                        form.initializareDataGridView();
                        this.Close();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        this.Hide();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            BLInvoices   bLInvoices    = new BLInvoices();
            InvoiceModel facturaCreata = new InvoiceModel();

            if (String.IsNullOrWhiteSpace(tbNumar.Text))
            {
                errorProvider1.SetError(tbNumar, "Camp obligatoriu!");
            }
            else
            {
                string nrFactura = tbNumar.Text;
                facturaCreata.InvoiceNumber    = nrFactura;
                facturaCreata.InvoiceDate      = dateTimePickerFactura.Value;
                facturaCreata.Observations     = tbObs.Text;
                facturaCreata.user.UserId      = LoginForm.UserId;
                facturaCreata.adresa.PartnerId = Convert.ToInt32(cbClient.SelectedValue);
                facturaCreata.client.ClientId  = Convert.ToInt32(cbClient.SelectedValue);
                if (string.IsNullOrEmpty(cbAdrese.Text) || cbAdrese.SelectedIndex == -1)
                {
                    MessageBox.Show("Nu se poate face factura pentru un client fara adrese!", "Status", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                else
                {
                    facturaCreata.adresa.PartnerAddressId = Convert.ToInt32(cbAdrese.SelectedValue);
                    bLInvoices.InsertInvoice(facturaCreata, out bool status, out string message);
                    MessageBox.Show(message, "Status", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    DialogResult dialogResult = MessageBox.Show("Doriti sa adaugati si detalii pentru factura introdusa?", "Detalii Factura", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        InvoiceDetailsForm form = new InvoiceDetailsForm(facturaCreata);
                        form.Show();
                    }
                    else if (dialogResult == DialogResult.No)
                    {
                        this.Hide();
                    }
                }
                InvoicesForm invoicesForm = new InvoicesForm();
                invoicesForm.initializareDataGridView();
            }
        }