'-----------------------------------------------------------------
'<copyright file="Feedback.aspx.vb" company="Kimaya" >
'   Copyright(c) Kimaya Ltd. All rights reserved.
'</copyright>
'<Desc>
'   Codebehind file for Feedback.aspx 
'</Desc>
'<DateOfCreation>
'   20/08/07
'</DateOfCreation>
'<Developer>
'   Devendra
'</Developer>


Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
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.IO
Imports ModCommon

Partial Class FeedBack
    Inherits System.Web.UI.Page

    Shared g_User As String
    Shared g_Company As String
    Shared Search As String


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            txtFeedbackName.Width = 160
            txtFeedbackEmailId.Width = 300
            txtFeedbackSuggestion.Width = 300
            txtFeedbackSuggestion.TextMode = TextBoxMode.MultiLine
            txtFeedbackSuggestion.Rows = 5
            If (Not IsPostBack) Then
                g_Company = "COM1"
                g_User = "U1"
                ClearTextBox()
                'UnLockTextBox(False)
                Call GenerateFeedbackCode()
                txtFeedbackName.Focus()
            End If
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")
        End Try

    End Sub

    Public Sub ClearTextBox()
        txtFeedbackId.Text = ""
        txtFeedbackCode.Text = ""
        txtFeedbackName.Text = ""
        txtFeedbackEmailId.Text = ""
        txtFeedbackSuggestion.Text = ""
    End Sub

    Public Sub UnLockTextBox(ByVal Action As Boolean)
        txtFeedbackId.Enabled = Action
        txtFeedbackCode.Enabled = Action
        txtFeedbackName.Enabled = Action
        txtFeedbackEmailId.Enabled = Action
        txtFeedbackSuggestion.Enabled = Action
    End Sub

    Public Sub GenerateFeedbackCode()
        Try
            Dim i As String
            Dim qry As String
            Dim code As String
            txtFeedbackId.Text = NewPrimaryKey(Me)
            i = "1"
            i = Format(Val(i), "000")
            While True
                code = "Fb" & "/" & Year(Date.Today) & "/" & Format(Month(Date.Today), "00") & "/" & Day(Date.Today) & "/" & i
                qry = "select count(*) from Feedback where Feedback_Code='" & code & "'"
                If IsAlreadyPresent(qry) Then
                    i = Val(i) + 1
                    i = Format(Val(i), "000")
                Else
                    txtFeedbackCode.Text = code
                    Exit Sub
                End If
            End While
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")     'Display the Error Message
        End Try
    End Sub


    Protected Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
        Try
            If (txtFeedbackId.Text) = "" Then
                CreateMessageAlert(Me, "Feedback Can't be left blank !!", "StrKeyVal")
                Exit Sub
            End If

            If (txtFeedbackCode.Text) = "" Then
                CreateMessageAlert(Me, "Feedback Can't be left blank !!", "StrKeyVal")
                Exit Sub
            End If

            If (txtFeedbackName.Text) = "" Then
                CreateMessageAlert(Me, "Enter name !!", "StrKeyVal")
                Exit Sub
            End If

            If (txtFeedbackEmailId.Text) = "" Then
                CreateMessageAlert(Me, "Enter Email_Id !!", "StrKeyVal")
                Exit Sub
            End If

            If (txtFeedbackSuggestion.Text) = "" Then
                CreateMessageAlert(Me, "Enter Suggestion !!", "StrKeyVal")
                Exit Sub
            End If

            Dim con As New SqlConnection
            con.ConnectionString = System.Configuration.ConfigurationManager.AppSettings("ConnectionString")
            con.Open()

            Dim cmd As New SqlCommand
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "Feedback_Proc"
            cmd.Connection = con
            cmd.Parameters.Add(New SqlParameter("@Feedback_Kid", SqlDbType.NVarChar, 10)).Value = Trim(txtFeedbackId.Text)
            cmd.Parameters.Add(New SqlParameter("@Feedback_Code", SqlDbType.NVarChar, 25)).Value = Trim(txtFeedbackCode.Text)
            cmd.Parameters.Add(New SqlParameter("@Feedback_Name", SqlDbType.NVarChar, 100)).Value = Trim(txtFeedbackName.Text)
            cmd.Parameters.Add(New SqlParameter("@Feedback_EmailId", SqlDbType.NVarChar, 100)).Value = Trim(txtFeedbackEmailId.Text)
            cmd.Parameters.Add(New SqlParameter("@Feedback_Suggestion", SqlDbType.NVarChar, 1000)).Value = Trim(txtFeedbackSuggestion.Text)
            cmd.Parameters.Add(New SqlParameter("@Feedback_CompanyId", SqlDbType.NVarChar, 10)).Value = Trim(g_Company)
            cmd.Parameters.Add(New SqlParameter("@FormName", SqlDbType.NVarChar, 100)).Value = "Feedback"
            cmd.Parameters.Add(New SqlParameter("@Mode", SqlDbType.NVarChar, 10)).Value = "Insert"
            cmd.ExecuteNonQuery()
            'CreateMessageAlert(Me, "Record saved successfully ...", "StrKeyVal")
            ClearTextBox()
            lblmessg.Visible = True
            lblmessg.Text = "Thank You For Using Feedback !!"
        Catch ex As Exception
            CreateMessageAlert(Me, ex.Message, "StrKeyVal")
        End Try
    End Sub
End Class











