Пример #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            ClaseFacturaServicios ObjFactura = new ClaseFacturaServicios();

            try
            {
                ObjFactura.NumFactura = int.Parse(label6.Text);
                ObjFactura.NitEmpresa = long.Parse(label9.Text);
                ObjFactura.Fecha      = Convert.ToDateTime(dateTimePicker1.Value.ToShortDateString());
                ObjFactura.IdEmpleado = long.Parse(comboBox1.SelectedValue.ToString());
                ObjFactura.IdCliente  = long.Parse(textBox1.Text);



                bool insertarfacturaOK = ObjFactura.InsertarFacturaServicios();

                if (insertarfacturaOK == true)
                {
                    bool insertardetalleOK = false;
                    int  filas             = dataGridView1.Rows.Count;

                    for (int i = 0; i < filas - 1; i++)
                    {
                        ObjFactura.NitEmpresa  = long.Parse(label9.Text);
                        ObjFactura.NumFactura  = int.Parse(label6.Text);
                        ObjFactura.IdServicios = long.Parse(dataGridView1.Rows[i].Cells["IdServicios"].Value.ToString());
                        ObjFactura.Cantidad    = int.Parse(dataGridView1.Rows[i].Cells["Cantidad"].Value.ToString());
                        ObjFactura.ValorIva    = long.Parse(dataGridView1.Rows[i].Cells["ValorIva"].Value.ToString());
                        ObjFactura.SubTotal    = long.Parse(dataGridView1.Rows[i].Cells["SubTotal"].Value.ToString());

                        insertardetalleOK = ObjFactura.InsertarDetalleFServicios();
                    }

                    if (insertardetalleOK == true)
                    {
                        MessageBox.Show("La Factura Fue Generada correctamente");
                        FormConFacServicios FConsultarFactura = new FormConFacServicios();
                        FConsultarFactura.MdiParent  = Principal.ActiveForm;
                        FConsultarFactura.NumFactura = int.Parse(label6.Text);
                        FConsultarFactura.Show();

                        this.Close();
                    }
                    else
                    {
                        if (ObjFactura.NumFactura == 1)
                        {
                            MessageBox.Show("El Sistema Fue ajustado con exito, puede iniciar a generar sus facturas");
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show("La Factura Fue Generada pero no se pudo completar  el detalle");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("La Factura No Pudo Generarse. " + ObjFactura.Mensaje);
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Error!: " + Ex.Message + " " + ObjFactura.Mensaje);
            }
        }
Пример #2
0
        private void FormFacturaServicios_Load(object sender, EventArgs e)
        {
            ClaseConsultas        ObjConsultas = new ClaseConsultas();
            ClaseFacturaServicios ObjFactura   = new ClaseFacturaServicios();

            int numregistros = 0;

            try
            {
                DataSet DatosEmpresa = ObjConsultas.ConsultarEmpresa();

                long   NitEmpresa    = long.Parse(DatosEmpresa.Tables["DatosConsultados"].Rows[0]["NitEmpresa"].ToString());
                String NombreEmpresa = (DatosEmpresa.Tables["DatosConsultados"].Rows[0]["Nombre"].ToString());
                label9.Text  = NitEmpresa.ToString();
                label10.Text = NombreEmpresa;



                DataSet DatosUltimaFactura = ObjFactura.ConsultarUltimaFServicios();
                numregistros = DatosUltimaFactura.Tables["DatosConsultados"].Rows.Count;

                if (numregistros == 0)
                {
                    MessageBox.Show("Importante: No hay ninguna Factura Generada Aun, Por favor Ingrese una Primera Factura De Prueba Para Ajustar El Sistema");
                    label6.Text = "1";
                }
                else
                {
                    int NumUltimaFactura = int.Parse(DatosUltimaFactura.Tables["DatosConsultados"].Rows[0]["NumFactura"].ToString());
                    int NumNuevaFactura  = NumUltimaFactura + 1;
                    label6.Text = NumNuevaFactura.ToString();
                    MessageBox.Show("Bienvenido, Ingrese su Factura N°" + NumNuevaFactura);
                }

                DataSet DatosEmpleados = ObjConsultas.ConsultarListadoEmpleado();
                numregistros = DatosEmpleados.Tables["DatosConsultados"].Rows.Count;

                if (numregistros == 0)
                {
                    MessageBox.Show("No hay empleados registrados en el sistema");
                }
                else
                {
                    comboBox1.DataSource    = DatosEmpleados.Tables["DatosConsultados"];
                    comboBox1.DisplayMember = DatosEmpleados.Tables["DatosConsultados"].Columns["NombreCompleto"].ToString();
                    comboBox1.ValueMember   = DatosEmpleados.Tables["DatosConsultados"].Columns["IdEmpleado"].ToString();
                }

                DataSet DatosServicios = ObjConsultas.ConsultarListadoServicios();
                numregistros = DatosServicios.Tables["DatosConsultados"].Rows.Count;

                if (numregistros == 0)
                {
                    MessageBox.Show("No hay Servicios registrados en el sistema");
                }
                else
                {
                    comboBox2.DataSource    = DatosServicios.Tables["DatosConsultados"];
                    comboBox2.DisplayMember = DatosServicios.Tables["DatosConsultados"].Columns["Nombre"].ToString();
                    comboBox2.ValueMember   = DatosServicios.Tables["DatosConsultados"].Columns["IdServicios"].ToString();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Se ha presentado un error, Cierre e Intente nuevamente. " + Ex.Message);
            }
        }
        public void MostrarFactura(int NumFactura)
        {
            ClaseFacturaServicios ObjFactura = new ClaseFacturaServicios();


            try
            {
                DataSet DatosFactura = ObjFactura.ConsultarFServicios(NumFactura);


                int numregistros = DatosFactura.Tables["DatosConsultados"].Rows.Count;

                if (numregistros == 0)
                {
                    MessageBox.Show("La Factura N° " + NumFactura + "Aun No Ha Sido Creada ");
                }
                else
                {
                    groupBox1.Visible = false;
                    groupBox2.Visible = true;



                    label5.Text = label5.Text + "" + NumFactura;

                    String Fecha = "Fecha: " + DatosFactura.Tables["DatosConsultados"].Rows[0]["Fecha"].ToString();
                    label6.Text = label6.Text + " " + Fecha;

                    String Cliente = DatosFactura.Tables["DatosConsultados"].Rows[0]["Cliente"].ToString();
                    label2.Text = label2.Text + " " + Cliente;

                    String IdCliente = DatosFactura.Tables["DatosConsultados"].Rows[0]["IdCliente"].ToString();
                    label7.Text = label7.Text + " " + IdCliente;

                    String Telefono = DatosFactura.Tables["DatosConsultados"].Rows[0]["Telefono"].ToString();
                    label8.Text = label8.Text + " " + Telefono;



                    String Vendedor = DatosFactura.Tables["DatosConsultados"].Rows[0]["Empleado"].ToString();
                    label10.Text = label10.Text + " " + Vendedor;

                    DataSet DatosDetalleFactura = ObjFactura.ConsultarDetalleFServicios(NumFactura);
                    dataGridView1.DataSource = DatosDetalleFactura.Tables["DatosConsultados"];

                    DataSet DatosTotalFactura = ObjFactura.ConsultarValorTotalS(NumFactura);
                    label11.Text = label11.Text + " " + DatosTotalFactura.Tables["DatosConsultados"].Rows[0]["TotalFactura"].ToString();


                    String NitEmpresa = "NitEmpresa: " + DatosFactura.Tables["DatosConsultados"].Rows[0]["NitEmpresa"].ToString();
                    label4.Text = label4.Text + " " + NitEmpresa;

                    String Nombre = DatosFactura.Tables["DatosConsultados"].Rows[0]["Nombre"].ToString();
                    label3.Text = label3.Text + " " + Nombre;

                    String Direccion = "Direccion: " + DatosFactura.Tables["DatosConsultados"].Rows[0]["Direccion"].ToString();
                    label12.Text = label12.Text + " " + Direccion;
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Se ha presentado Un Error Al Intentar Consultar Esta Factura. Cierre e intente Nuevamente.  " + Ex.Message);
            }
        }