示例#1
0
        private void btnActualizar_Click(object sender, EventArgs e)
        {
            NHelper.setConnectionString(this.txtUser.Text, txtPassword.Text, txtDB.Text, txtServer.Text, txtPort.Value.ToString());
            clsRepo repo = new clsRepo();

            try
            {
                IList <Dominio.Revision> lista = repo.Seleccionar <Dominio.Revision>();
                if (lista != null)
                {
                    foreach (Dominio.Revision r in lista)
                    {
                        cmbRevision.Items.Add(r);
                    }
                }
            }
            catch (Exception ex)
            {
                commons.mensajeError(ex.Message, this.Text);
            }
            if (cmbRevision.Items.Count > 0)
            {
                cmbRevision.SelectedIndex = 0;
            }
        }
示例#2
0
 public IList <TClase> Seleccionar <TClase>() where TClase : class
 {
     using (ISession session = NHelper.GetCurrentSession())
     {
         return(session.CreateCriteria <TClase>().List <TClase>());
     }
 }
示例#3
0
        private void btnConectar_Click(object sender, EventArgs e)
        {
            NHelper.setConnectionString(this.txtUser.Text, txtPassword.Text, txtDB.Text, txtServer.Text, txtPort.Value.ToString());
            try
            {
                using (ISession session = NHelper.OpenSession())
                {
                    /*Crear revision*/
                    if (chkCrearRevision.Checked)
                    {
                        clsRepo          repo = new clsRepo();
                        Dominio.Revision rev  = new Dominio.Revision();

                        rev.descripcion = txtDescripcion.Text;

                        repo.Insertar <Dominio.Revision>(rev);
                        commons.Revision_Actual = rev;
                    }
                    else
                    {
                        /*Usa revision ya hecha*/

                        if (cmbRevision.Items.Count > 0)//si se selecciono una revision
                        {
                            commons.Revision_Actual = (Dominio.Revision)cmbRevision.SelectedItem;
                        }
                        else
                        {
                            commons.mensajeInformativo("Seleccione una revision o cree una nueva", this.Text);
                            return;
                        }
                    }

                    writeConfigOfGUI();

                    /*Prueba de conexion*/

                    this.Visible = false;

                    frmMain i = new frmMain();
                    i.ShowDialog();

                    Close();
                }
            }
            catch (Exception ex)
            {
                string mensaje = "";
                while (ex != null)
                {
                    mensaje = mensaje + "##" + ex.Message + "\n";
                    ex      = ex.InnerException;
                }
                MessageBox.Show(mensaje, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
示例#4
0
        public static ISession GetCurrentSession()
        {
            if (SessionFactory == null)
            {
                NHelper.OpenSession();
            }


            return(SessionFactory.OpenSession());
        }
示例#5
0
        public int ContadorRows <TClase>() where TClase : class
        {
            int rows = 0;

            using (ISession session = NHelper.GetCurrentSession())
            {
                rows = session.QueryOver <TClase>()
                       .Select(Projections.RowCount())
                       .FutureValue <int>()
                       .Value;
            }

            return(rows);
        }
示例#6
0
        public List <System.Type> getEntidades()
        {
            List <System.Type> clases = null;
            var metaData = NHelper.GetCurrentSession().SessionFactory.GetAllClassMetadata();

            if (metaData != null && metaData.Count > 0)
            {
                clases = new List <Type>();
                foreach (var x in metaData)
                {
                    var  y = x.Value;
                    Type xy;
                    clases.Add(xy = y.GetMappedClass(EntityMode.Poco));
                }
            }
            return(clases);
        }
示例#7
0
        public int Actualizacion(string sql)
        {
            int i = 0;

            using (ISession session = NHelper.GetCurrentSession())
            {
                using (IDbConnection sql_con = session.Connection)
                {
                    IDbCommand cmd = sql_con.CreateCommand();

                    cmd.CommandText = sql;

                    i = cmd.ExecuteNonQuery();
                }
            }
            return(i);
        }
示例#8
0
 public void Actualizar <TClase>(TClase Objeto)
 {
     try
     {
         using (ISession session = NHelper.GetCurrentSession())
         {
             using (ITransaction transaction = session.BeginTransaction())
             {
                 session.Delete(Objeto);
                 transaction.Commit();
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error: " + e.Message);
     }
 }
示例#9
0
        public List <string> getEntidadesNombre()
        {
            List <string> tablas = null;

            var metaData = NHelper.GetCurrentSession().SessionFactory.GetAllClassMetadata();

            if (metaData != null)
            {
                tablas = new List <string>();
                foreach (var x in metaData)
                {
                    var usrm = x.Value as NHibernate.Persister.Entity.AbstractEntityPersister;
                    //var cols = usrm.KeyColumnNames;
                    string table = usrm.TableName;
                    tablas.Add(table);
                }
            }
            return(tablas);
        }
示例#10
0
        public DataTable Seleccionar(string sql)
        {
            DataTable dt;

            using (ISession session = NHelper.GetCurrentSession())
            {
                using (IDbConnection sql_con = session.Connection)
                {
                    dt = new DataTable();
                    IDbCommand cmd = sql_con.CreateCommand();

                    cmd.CommandText = sql;

                    var reader = cmd.ExecuteReader();

                    dt = GetDataTableFromDataReader(reader);
                }
            }
            return(dt);
        }