Imports System
Imports System.Net
Imports System.Net.Mail
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Globalization
Imports Microsoft.VisualBasic

Public Class FirstClass
    Private con As SqlConnection
    Public cmd As SqlCommand
    Private dt As DataTable
    Private da As SqlDataAdapter


    Public Sub New()
        con = New SqlConnection(ConfigurationManager.ConnectionStrings("KhabrNameh").ConnectionString)
        cmd = New SqlCommand()
        dt = New DataTable()
        cmd.Connection = con

        da = New SqlDataAdapter(cmd)
    End Sub

    Public Function dbOut(ByVal sql As String) As DataTable
        cmd.CommandText = sql
        con.Open()
        da.Fill(dt)
        con.Close()
        Return dt
    End Function

    Public Function SP_dbOut(ByVal SP_Name As String) As DataTable
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = SP_Name
        con.Open()
        da.Fill(dt)
        con.Close()
        Return dt
    End Function

    Public Sub exeCommand(ByVal spName As String)
        con.Open()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = spName
        cmd.ExecuteNonQuery()

        con.Close()
    End Sub

    Public Sub exeCommand1(ByVal strName As String)
        Try
            cmd.CommandText = strName
            con.Open()
            cmd.ExecuteNonQuery()
        Catch
        Finally
            con.Close()

        End Try
    End Sub



    Public Function dtr101(ByVal sql As String) As SqlDataReader
        'cmd = new SqlCommand(sql, con); 
        cmd.CommandText = sql
        con.Open()
        Dim dtr As SqlDataReader = cmd.ExecuteReader()

        'dtr.GetString(); 
        Return dtr
    End Function

    Public Function dtShamsi() As String
        Dim strMydate As String
        Dim calFar1 As New PersianCalendar()
        strMydate = ((calFar1.GetYear(DateTime.Now).ToString() & "/") + calFar1.GetMonth(DateTime.Now).ToString("00") & "/") + calFar1.GetDayOfMonth(DateTime.Now).ToString("00")
        Return strMydate
    End Function

    Public Function recordDuplicate(ByVal sql As String) As Integer

        Dim i As Integer = 0
        cmd.CommandText = sql
        con.Open()
        da.Fill(dt)
        If dt.Rows.Count <= 0 Then
            i = 0
        Else
            i = 1
        End If
        con.Close()
        Return i
    End Function

    Public Sub alarmMailFromSite(ByVal MailFrom As String, ByVal MailTo As String, ByVal SubjectOfMail As String, ByVal BodyOfMail As String)
        Try
            Dim message As New MailMessage(MailFrom, MailTo, SubjectOfMail, BodyOfMail)
            message.IsBodyHtml = True
            Dim emailClient As New SmtpClient("mail.bitasoft.ir")
            Dim SMTPUserInfo As New System.Net.NetworkCredential("a@bitasoft.ir", "gooliofIRAN*")
            message.ReplyTo = New MailAddress("NoReply_LostPassword@bitasoft.ir", "No Reply")
            'message.Bcc.Add(new MailAddress("najafzade@gmail.com", "Admin_Of_News.bitasoft.ir")); 
            message.Priority = MailPriority.High
            emailClient.UseDefaultCredentials = False
            emailClient.Credentials = SMTPUserInfo
            emailClient.Send(message)
        Catch ex As Exception
            ' Label3.Text = ex.ToString(); 
        End Try
    End Sub

End Class
