using System;
using System.Data;
using System.Globalization;
using System.Net;
using System.Resources;
using System.Threading;
using System.Web.UI;
using Cryptographys;
public partial class Transactions_ExportData_FTPConfigurationForORCL : System.Web.UI.Page
{
    #region VariableDeclaration
    ExportData objExportData = new ExportData();
    ResourceManager rm;
    CultureInfo ci;
    string strSetAlert;
    #endregion
    #region PageLoad
    protected void Page_Load(object sender, EventArgs e)
    {
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        if (!IsPostBack)
        {
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "MaxLengthh('" + rm.GetString("Alert_MaximumLengthis", ci) + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("MaxLengthh", strSetAlert);
            DataSet dsFTPConfiguration = new DataSet();
            dsFTPConfiguration = objExportData.SelectFTPConfiguration();
            if (dsFTPConfiguration.Tables[0].Rows.Count > 0)
            {
                txtAddress.Text = dsFTPConfiguration.Tables[0].Rows[0]["Address"].ToString();
                txtUserName.Text = dsFTPConfiguration.Tables[0].Rows[0]["UserName"].ToString();
                txtPassword.Text = dsFTPConfiguration.Tables[0].Rows[0]["Password"].ToString();
                txtPort.Text = dsFTPConfiguration.Tables[0].Rows[0]["Port"].ToString();
            }
        }
    }
    #endregion
    #region ButtonEvents
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            // Create FtpWebRequest object from the Uri provided
            FtpWebRequest _FtpWebRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri(txtAddress.Text.Trim()));
            _FtpWebRequest.Credentials = new NetworkCredential(txtUserName.Text.Trim(), txtPassword.Text.Trim());
            // By default KeepAlive is true, where the control connection is not closed
            // after a command is executed.
            _FtpWebRequest.KeepAlive = false;
        }
        catch (Exception ex)
        {
            string Script;
            Script = "<script language='javascript'>";
            Script = Script + "alert('Incorrect Configuration');";
            Script = Script + " </script>";
            Page.RegisterStartupScript("FTP configuration", Script);
            return;
        }
        objExportData.InsertUpdateFTPConfiguration(txtAddress.Text.Trim(), txtUserName.Text.Trim(), Cryptography.Encrypt(txtPassword.Text.Trim(), "Password"), txtPort.Text.Trim());
        string strScript;
        strScript = "<script language='javascript'>";
        strScript = strScript + "alert('FTP configuration saved successfully');window.close(); ";
        strScript = strScript + " </script>";
        Page.RegisterStartupScript("FTP configuration", strScript);
    }
    #endregion
}