Pages

Thursday, 12 September 2013

File Extension Types

 txt = 0,doc = 1, docx = 2, jpeg = 3, png = 4 ,pdf = 5 ,xls = 6 ,xlsx = 7, ppt = 8,
 pptx = 9, jpg = 10, tiff = 11 ,gif = 12 ,bmp = 13, ai = 14 ,psd = 15, avi = 16,
 mov = 17, mp4 = 18 ,wmv = 19, m4v = 20 ,mpg = 21, mkv = 22 ,mpeg = 23 ,vob = 24,
 flv = 25, mts = 26, m2t = 27 ,ts = 28, dv = 29, mp3 = 30 ,aiff = 31, m4a = 32,
 wav = 33,key = 34,pages = 35,numbers = 36,htm = 37,html = 38,threegp = 39,threegpp = 40,
 threegpp2 = 41, tif = 42, rtf = 43

Encryption and Decryption of string in .net

Here Rijndeal class will be available in System.Security.Cryptography

Public Shared Function Encrypt(ByVal PlainText As String) As String
        Dim passPhrase As String = "XYZABC"
        Dim initVector As String = "@1*desi@ew"
        Dim rijndaelKey As Rijndael = New Rijndael(passPhrase, initVector, 128, 0, 256)
        Return rijndaelKey.Encrypt(PlainText)
End Function
‘in encryption and decryption the “passphrase”  and “initvector” should be same
Public Shared Function Decrypt(ByVal Cypertext As String) As String
        Dim passPhrase As String = " XYZABC "
        Dim initVector As String = "@1*desi@ew "
        Dim rijndaelKey As Rijndael = New Rijndael(passPhrase, initVector, 128, 0, 256)
        Return rijndaelKey.Decrypt(Cypertext)
End Function

Friday, 30 August 2013

Working with Nhibernate

first add reference
rightclick --> click on manage Nuget -->serch (Nhibernate)-->Install  lesi.collections ,Nhibernate
create nhibernate configeration file to connect to database

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.GenericDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.OleDbDriver</property>
    <property name="show_sql">false</property>
    <!--<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>-->
    <property name="connection.connection_string">Provider=VFPOLEDB.1;Data Source=C:\Database1\data1.dbc </property>
  </session-factory>
</hibernate-configuration>
  next create hbm mapingfiles(xml)

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="WebLinkMVC.WebLinkMvcDemoVb.Models.CustomerClass,WebLinkMVC" table="code"
         optimistic-lock="all" dynamic-update="true"   where =" codetype='C'">
    <id name="CustomerClassificationCode" column="codevalue"  >
      <generator class="assigned"  />
    </id>
    <!--<version  name="EntityVersion" column="recver" />-->
    <property name="Id" column="primkey" insert="false" update="false" />
    <property name="CodeType" column="codetype" update="true" />
    <property name="Code" column="code" update="true" />
    <property name="RecDesc" column="recdesc" update="true" />
    <property name="Description" column="cdata" />
    <property name="Discount" column="discount" update="true" />
    <property name="DiscDays" column="discdays" update="true" /> 
    <!-- To execute the sql-update statement set dynamic-update="true" in class tag-->
    <!--<sql-update >UPDATE code SET recver = ?, cdata = ?  WHERE  codevalue=? AND codetype = 'C' AND recver = ?</sql-update>-->  
  </class>
</hibernate-mapping>

begin class 
'use namespaces
imports nhibernate
imports nhibernate.cfg


Dim sessionFactory As NHibernate.ISessionFactory
Dim session As NHibernate.ISession
public function method()

Dim fileName As String = HttpContext.Current.Server.MapPath("\Models\NHibernate\Configuration\hibernate.cfg.xml")
            Dim data = cgf.Configure(fileName)
            cgf.AddDirectory(New System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath("\Models\NHibernate\Mappings")))
            sessionFactory = data.BuildSessionFactory()
            session = sessionFactory.GetCurrentSession()
   end sub
Public Function GetCustomers() As IList(Of CustomerClass)
        Dim CustList As IList(Of CustomerClass)
        Dim query As IQuery = session.CreateQuery("from CustomerClass")
        CustList = query.List(Of CustomerClass)()
        Return CustList
    End Function    
    Public Function getcustomerbyid(ByVal custid As String) As CustomerClass
        Dim customer As customerclass
        Dim query As iquery = session.createquery("from customerclass where id=" & custid) 'get(of customerclass)(custid)
        customer = query.list(Of customerclass)().firstordefault()
        Return customer
    End Function
    Public Function UpdateCustomer(ByVal Customer As CustomerClass) As Integer
        Try
            Using tran As ITransaction = session.BeginTransaction()
                ' session.Refresh(Customer)
                session.Update(Customer)
                ' session.Save(Customer)
                tran.Commit()
            End Using
            Return 1
        Catch ex As Exception
            Return 0
        End Try
    End Function
    Public Function DeleteCustomer(ByVal Customer As CustomerClass) As Integer
        Try
            Using tran As ITransaction = session.BeginTransaction()
                session.Delete(Customer)
                tran.Commit()
            End Using
            Return 1
        Catch ex As Exception
            Return 0
        End Try
    End Function