Exemplo n.º 1
0
 private void ContactoDataGridView_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Up)
     {
         if (ContactoDataGridView.CurrentCell.RowIndex == 0)
         {
             nameTextBox.Focus();
         }
     }
     if (e.KeyCode == Keys.Enter)
     {
         AsignarCeldasDataGridViewAVariables();
         AsignarVariablesACamposDelFormulario();
         ReadOnlyCamposContacto(true);
         ContactoDataGridView.Visible = false;
         listadoDataGridView.Focus();
         ValidaCampo.Requerido(idNumberTextBox, "Por favor ingrese el numero de Identificación");
         ValidaCampo.Requerido(nameTextBox, "Por favor ingrese el Nombre");
         ValidaCampo.Requerido(addressTextBox, "Por favor ingrese la Dirección");
     }
     if (e.KeyCode == Keys.Escape)
     {
         ContactoDataGridView.Visible = false;
         nameTextBox.Focus();
     }
 }
Exemplo n.º 2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            PrinterFont       = new Font(Settings.Default.printerFontFamily, Settings.Default.printerFontSize, FontStyle.Regular);
            PrinterName       = Settings.Default.printerName;
            printerLabel.Text = PrinterName;

            ValidaCampo.Requerido(idNumberTextBox, "Por favor ingrese el numero de Identificación");
            ValidaCampo.Requerido(nameTextBox, "Por favor ingrese el Nombre");
            ValidaCampo.Requerido(addressTextBox, "Por favor ingrese la Dirección");
            ValidaCampo.Requerido(listadoDataGridView, mainPanel, "Por favor selecciona al menos un item");
            ValidaCampo.Requerido(numberDocument1TextBox, numberDocument3TextBox, 3, "Por favor escribe correctamente el numero de factura");
            ValidaCampo.Requerido(numberDocument2TextBox, numberDocument3TextBox, 3, "Por favor escribe correctamente el numero de factura");
            ValidaCampo.Requerido(numberDocument3TextBox, numberDocument3TextBox, 9, "Por favor escribe correctamente el numero de factura");

            string idNumber     = (idNumberTextBox.Text.Trim() == "") ? "null" : idNumberTextBox.Text.Trim();
            string businessName = nameTextBox.Text.Replace("'", "\\'").Trim();

            businessName = (businessName == "") ? "null" : $"'{businessName}'";
            string address = addressTextBox.Text.Replace("'", "\\'").Trim();

            address = (address == "") ? "null" : $"'{address}'";
            string additional_information = additionalInformationTextBox.Text.Replace("'", "\\'").Trim();

            additional_information = (additional_information == "") ? "null" : $"'{additional_information}'";
            string   landline         = (landlineTextBox.Text.Trim() == "") ? "null" : landlineTextBox.Text.Trim();
            string   numberInvoice    = $"{numberDocument1TextBox.Text}{numberDocument2TextBox.Text}{numberDocument3TextBox.Text}";
            string   typeIssuanceId   = $"'{GetIdItemTable("type_issuance", "name", "Emisión Normal")}'";
            string   typeDocumentId   = $"'{GetIdItemTable("type_document", "name", "FACTURA COMPRA")}'";
            string   statusDocumentId = $"'{GetIdItemTable("status_document", "name", "Autorizado")}'";
            string   paymentMethodId  = $"'{GetIdItemTable("payment_method", "name", "Otros con utilización del Sistema Financiero")}'";
            DateTime dateTime         = dateIssueDateTimePicker.Value;
            string   date_of_issue    = $"'{dateTime: yyyy-MM-dd} 18:59:59'";

            if (ValidaCampo.ErrorStatus)
            {
                if (SavedTimes == 0)
                {
                    GetIdContact(idNumber);
                    if (IdContact == "nuevo")
                    {
                        if (ConsultasSql.Insertar("contact",
                                                  "id_number, business_name, address, landline, provider",
                                                  $"'{idNumber}', {businessName}, {address}, '{landline}', true"))
                        {
                            GetIdContact(idNumber);
                        }
                    }
                    string idDocument = $"'{Guid.NewGuid()}'";
                    string contactId  = $"{IdContact}";
                    if (ConsultasSql.Insertar("document", idDocument, "number, date_of_issue, subtotal, additional_discount, total_discount, subtotal_iva0, " +
                                              "subtotal_iva12, iva_value, total_value, additional_information, typeIssuanceId, typeDocumentId, statusDocumentId, contactId, paymentMethodId",
                                              $"'{numberInvoice}', {date_of_issue}, {subtotalTextBox.Text}, {valorDescuentoTextBox.Text}, {Math.Round(SubtotalDescuentoDecimal, 2)}, {subtotal0TextBox.Text}, " +
                                              $"{subtotal12TextBox.Text}, {ivaTextBox.Text}, {totalTextBox.Text}, {additional_information}, {typeIssuanceId}, {typeDocumentId}, {statusDocumentId}, '{contactId}', {paymentMethodId}"))
                    {
                        for (int i = 0; i < listadoDataGridView.Rows.Count - 1; i++)
                        {
                            string quantity         = $"{listadoDataGridView.Rows[i].Cells["cantidadColumn"].Value}";
                            string unitary_discount = $"{listadoDataGridView.Rows[i].Cells["cantidadColumn"].Value}";
                            string subtotal         = $"{listadoDataGridView.Rows[i].Cells["subtotalColumn"].Value}";
                            string productId        = $"{listadoDataGridView.Rows[i].Cells["idColumn"].Value}";
                            if (ConsultasSql.Insertar("invoice_detailment", "quantity, unitary_discount, subtotal, documentId, productId",
                                                      $"{quantity}, {unitary_discount}, {subtotal}, {idDocument}, '{productId}'"))
                            {
                                string stock           = GetStockItem("product", "id", productId, 0);
                                string minimumStock    = GetStockItem("product", "id", productId, 1);
                                int    quantityInt     = int.Parse(quantity);
                                int    stockInt        = int.Parse(stock);
                                int    minimumStockInt = int.Parse(minimumStock);
                                stockInt += quantityInt;
                                ConsultasSql.Actualizar("product", $"stock = {stockInt}, stock_indicator = {stockInt + minimumStockInt}", "id", $"'{productId}'");
                            }
                        }
                        MessageBox.Show("Factura de compra registrada correctamente.");
                        SavedTimes                          += 1;
                        saveButton.BackColor                 = ColorTranslator.FromHtml("#56BA54");
                        saveButton.Text                      = "Registrado";
                        listadoDataGridView.Enabled          = false;
                        idNumberTextBox.Enabled              = false;
                        nameTextBox.Enabled                  = false;
                        addressTextBox.Enabled               = false;
                        landlineTextBox.Enabled              = false;
                        additionalInformationTextBox.Enabled = false;
                        descuentoTextBox.Enabled             = false;
                        descuentoButton.Enabled              = false;
                    }
                }
            }
        }