public mUsuario(string conn,int idEmpresa, int idClienteEmpresa)
 {
     this.connString = conn;
     objClienteEmpresa = new mClienteEmpresa(conn, idClienteEmpresa);
     objEmpresa = new mEmpresa(conn, idEmpresa);
     objFactura = new mFactura(conn);
 }
        protected void BtBuscar_Click(object sender, EventArgs e)
        {
            DateTime fi, ff,fft;

            if (edEjercico.Text == String.Empty)
            {
                edEjercico.Text = DateTime.Today.Year.ToString();
            }

            fi = Convert.ToDateTime("01/" + cbMesInicio.SelectedValue + "/" + edEjercico.Text);

            fft = Convert.ToDateTime("01/" + cbMesFin.SelectedValue + "/" + edEjercico.Text);

            ff = fft.AddMonths(1);
            ff = ff.AddDays(-1);
            /*
            if (CalendarDesde.SelectedDate.Year == 1)
            {
                Message.Text = "Debe seleccionar una Fecha de inicio.";
                return;
            }
            if (CalendarHasta.SelectedDate.Year == 1)
            {
                Message.Text = "Debe seleccionar una Fecha de Fin.";
                return;
            }

             * */
            mFactura fac = new mFactura(DatosComun.constr);
            DataTable dt = fac.getDataReportFacturas(DatosComun.constr, Convert.ToInt32(DDLClientes.SelectedValue), fi, ff,
                   Convert.ToInt32(RBList.SelectedValue));//metodo creado en la clase factura para devolver
            string reporteLoad = "";

            if (dt.Rows.Count <= 0)
            {
                Message.Text = "No existen datos con estos parametros.";
                return;
            }

            switch (Convert.ToInt32(RBList.SelectedValue))
            {
                case 1:
                    reporteLoad= "~/Reports/GeneralReport.rpt";
                    break;
                case 2:
                    reporteLoad="~/Reports/EmitidosReport.rpt";
                    break;
                case 3:
                    reporteLoad="~/Reports/RecibidosReport.rpt";
                    break;
            }

            Session.Add("Data", dt);
            Session.Add("Report",reporteLoad);
            Response.Redirect("~/Presentacion/FrmReport.aspx");
            //CRViewer.ReportSource = reporte;
        }
Beispiel #3
0
        private void verToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            var Formulario = Application.OpenForms.OfType <mFactura>().FirstOrDefault(); //Evita que los formularios se habran mas de una vez buscando si el formulario existe

            mFactura Entrada = Formulario ?? new mFactura(0);                            //Condicion de validacion del formulario

            //?? Condicion SI Si Form es nulo quiere decir que jamas de ha creado la instancia por lo cual toma valor formulario de lo contrario hace referencia a Form
            //? Si simplificado (Condicion)? True :False
            Abrir(Entrada);
        }
        public mUsuario(string conn, int idEmpresa, int idClienteEmpresa, DataTable dtUserdata)
        {
            this.connString = conn;
            this.dtUserdata = dtUserdata;
            this.IDUsuario = Convert.ToInt32(dtUserdata.Rows[0]["idUsuario"].ToString());
            this.IDEmpresa = Convert.ToInt32(dtUserdata.Rows[0]["IDEmpresa"].ToString());
            this.IDClienteEmpresa = Convert.ToInt32(dtUserdata.Rows[0]["IDClienteEmpresa"].ToString());
            this.Nombre =dtUserdata.Rows[0]["Nombre"].ToString();
            this.NombreCuenta = dtUserdata.Rows[0]["NombreCuenta"].ToString();

            objClienteEmpresa = new mClienteEmpresa(conn, idClienteEmpresa);
            objEmpresa = new mEmpresa(conn, idEmpresa);
            objFactura = new mFactura(conn);
        }
        public mUsuario(string conn, string nombreCuenta, string Clave)
        {
            this.connString = conn;
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@NombreCuenta", nombreCuenta);
            param[1] = new SqlParameter("@Clave", Clave);
            DataTable dt = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "spLogIn", param).Tables[0];

            this.IDUsuario = Convert.ToInt32(dt.Rows[0]["IDUsuario"].ToString());
            this.IDEmpresa = Convert.ToInt32(dt.Rows[0]["IDEmpresa"].ToString());
            this.IDClienteEmpresa = Convert.ToInt32(dt.Rows[0]["IDClienteEmpresa"].ToString());
            this.Nombre = dt.Rows[0]["Nombre"].ToString();
            this.NombreCuenta = dt.Rows[0]["NombreCuenta"].ToString();
            this.Clave = dt.Rows[0]["NombreCuenta"].ToString();
            objClienteEmpresa = new mClienteEmpresa(conn, this.IDClienteEmpresa);
            objEmpresa = new mEmpresa(conn, this.IDEmpresa);
            objFactura = new mFactura(conn);
        }
Beispiel #6
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (this.ListaDetalle.Rows.Count > 0)
     {
         Utileria.Llenar();
         foreach (DataGridViewRow Fila in ListaDetalle.Rows)
         {
             Utileria.Listado.Rows.Add(Fila.Cells[0].Value, Fila.Cells[1].Value, Fila.Cells[2].Value, Fila.Cells[3].Value, Fila.Cells[4].Value, Fila.Cells[5].Value, Fila.Cells[6].Value);
         }
         mFactura Formulario = new mFactura(1);
         Formulario.Show();
         this.Visible = false;
     }
     else
     {
         MessageBox.Show("No se puede generar una factura vacia", "Agregar productos o servicios", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        protected void BiImportarArchivo_Click(object sender, EventArgs e)
        {
            string appPath = Request.PhysicalApplicationPath;
            var pathTemp = Server.MapPath("~/Documentos/Temp");
            var pathMove = Server.MapPath("~/Documentos/Move");
            string fileXML,fileMove;
                 //filePDF, dirPDF
            DirectoryInfo dirXML;
            Boolean insertFac = true;
            int errorCount, correctosCount,totalArchivos, tipoFactura;

            errorCount = 0;
            correctosCount = 0;
            totalArchivos = 0;
            tipoFactura = 0;

            lLog.Text = "Log de Eventos: ";

            //if (RBEmitidaRecibida.SelectedValue == "0")
            //    TipoFactura = "EMITIDAS";
            //else TipoFactura = "RECIBIDA";

            //LFile.Text = "...";

            if ((FileUploaderXML.HasFile))
            {
                foreach (HttpPostedFile postedFile in FileUploaderXML.PostedFiles)
                {
                    insertFac = true;

                    fac = new mFactura(Datos.DatosComun.constr);
                    try
                    {
                        fileXML = "";
                        fileXML = Path.Combine(pathTemp, Path.GetFileName(postedFile.FileName));
                        fileMove = "";
                        fileMove = Path.Combine(pathMove, Path.GetFileName(postedFile.FileName));
                        postedFile.SaveAs(fileXML);
                        postedFile.SaveAs(fileMove);

                        string text;// = File.ReadAllText(fileXML);
                        StringBuilder sb = new StringBuilder();
                        using (StreamReader sr = new StreamReader(fileMove))
                        {
                            String line;
                            // Read and display lines from the file until the end of
                            // the file is reached.
                            while ((line = sr.ReadLine()) != null)
                            {
                                sb.AppendLine(line);
                            }
                        }

                        text = sb.ToString();
                        DataTable dt = null;
                        dt = fac.extracXMLtoDatatable(fileXML, text);
                        fac.importDataTableToObj(fac.GetInversedDataTable(dt, "Nodo_Atributo", null));

                        if (fac.Emisor_rfc == mUser.objClienteEmpresa.RFC)
                        {
                            tipoComprobante = "egreso";
                            tipoFactura = 1;
                        } else
                            if (fac.Receptor_RFC == mUser.objClienteEmpresa.RFC)
                            {
                                tipoComprobante = "ingreso";
                                tipoFactura = 0;
                            }
                            else
                            {
                                lLog.Text = lLog.Text + "<br/>" + "Esta factura no pertenece a este cliente: RFC del Cliente <b>" + mUser.objClienteEmpresa.RFC +
                                     "</b> RFC EMISOR: <b>" + fac.Emisor_rfc + "</b> RFC Receptor: <b>" + fac.Receptor_RFC + "</b>";
                                insertFac = false;
                            }

                        if ( insertFac )
                        {

                            /*
                             * try
                            {
                                fac.ValidaCFDI();
                                LRespSAT.Text = fac.oacuse.Estado;
                            }
                            catch (Exception vCFDI)
                            {
                                LMensajeValidacionCFDI.Text = "Ocurrió un error a validar factura en el SAT.<br/>" + vCFDI.Message;
                            }
                            */

                            string fecha = fac.Comprobante_fecha;
                            string pathXML = Server.MapPath("/Documentos/" + fac.Emisor_rfc + "/" + fecha.Substring(0, 4) + "/" + fecha.Substring(5, 2) + "/XML/" + tipoComprobante);

                            dirXML = new DirectoryInfo(pathXML);
                            if (dirXML.Exists == false)
                            {
                                dirXML.Create();
                            }

                            fac.TipoFactura = tipoFactura;
                            //fac.TipoFactura = Convert.ToInt32(RBEmitidaRecibida.SelectedValue);
                            fac.ArchivoXML = Path.GetFileName(postedFile.FileName);

                            File.Copy(fileMove, Path.Combine(pathXML, Path.GetFileName(postedFile.FileName)),true);
                            File.Delete(fileMove);
                            File.Delete(fileXML);
                            //LFile.Text += Path.GetFileName(postedFile.FileName).ToString() + ": Archivo subidos correctamente.<br/>";

                           // if (fac.insertFactura(fac, Convert.ToInt32((string)Session["IDClienteEmpresa"])) == 1)
                            if (fac.insertFactura(fac, mUser.IDClienteEmpresa) == 1)
                            {
                                //  GridView1.DataBind();
                            }
                            else
                            {
                               // LFile.Text += fac.ArchivoXML + ": Error al guardar la factura.<br/>";
                                return;
                            }

                            //if (FileUploadPDF.HasFile)
                            //{
                            //    try
                            //    {
                            //        filePDF = Path.Combine(pathTemp, FileUploadPDF.FileName);
                            //        FileUploadPDF.SaveAs(filePDF);
                            //        string pathPDF = Server.MapPath("/Documentos/" + fac.Emisor_rfc + "/" + fecha.Substring(0, 4) + "/" + fecha.Substring(5, 2) + "/PDF/" + TipoFactura);
                            //        dirPDF = new DirectoryInfo(pathPDF);

                            //        if (dirPDF.Exists == false)
                            //        {
                            //            dirPDF.Create();
                            //        }
                            //        File.Move(filePDF, Path.Combine(pathPDF, FileUploadPDF.FileName));
                            //    }
                            //    catch (Exception ePDF)
                            //    {
                            //        LMensajeSubirPDF.Text += "Ocurrió un error al subir archivo PDF.<br/>" + ePDF.Message;
                            //    }
                            //}

                            correctosCount++;
                           // lLog.Text = lLog.Text + " <br/> Archivo importado Correctamente: <b>" + fac.ArchivoXML +"</b>";
                        }
                    }
                    catch (Exception ex)
                    {
                        errorCount++;

                        lLog.Text = lLog.Text + " <br/> " + ex.Message.ToString() + " corresponde al archivo: <b> ( " + postedFile.FileName + ")</b> ";
                            // "Ocurrió un error en la importación, por favor informe al administrador.";
                    }

                    totalArchivos++;

                }
            }
            else
            {
                //LFile.Text = "You have not specified a file.";
            }

              //  totalArchivos = correctosCount + errorCount;
            lLog.Text = lLog.Text + "<br/> <br/> <b> Se importaron "+correctosCount+" archivos de "+ totalArchivos + "</b>";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if ( (string)Session["IDUsuario"] == null ||  (string)Session["IDClienteEmpresa"] == "0"  )
            {
                Session.RemoveAll();
                Response.Redirect("~/Default.aspx");
            }

            mUser = Session["User"] as mUsuario;

            fac = new mFactura(Datos.DatosComun.constr);
        }