using System;
using System.Drawing;
using System.Windows.Forms;
using Gecko;
using Gecko.DOM;
using System.IO;
namespace Browser__OM_
{
public partial class Browser : Form
{
int counter = 0;
public Browser()
{
Xpcom.Initialize(Application.StartupPath + "\\browser");
//Directory.Delete (Application.StartupPath + "\\browser\\Cache");
GeckoPreferences.Default["browser.xul.error_pages.enabled"] = true;
GeckoPreferences.Default["security.warn_viewing_mixed"] = false;
GeckoPreferences.Default["security.default_personal_cert"] = "Ask Never";
GeckoPreferences.Default["capability.policy.strict.Window.alert"] = "noAccess";
GeckoPreferences.Default["privacy.popups.showBrowserMessage"] = false;
GeckoPreferences.Default["extensions.blocklist.enabled"] = false;
GeckoPreferences.Default["security.enable_ssl2"] = true;
GeckoPreferences.Default["security.warn_entering_weak"] = true;
GeckoPreferences.Default["security.warn_viewing_mixed"] = false;
GeckoPreferences.Default["dom.disable_open_during_load"] = true;
GeckoPreferences.Default["dom.allow_scripts_to_close_windows"] = true;
GeckoPreferences.Default["dom.popup_maximum"] = 0;
GeckoPreferences.Default["browser.popups.showPopupBlocker"] = false;
Directory.CreateDirectory(Application.StartupPath + "\\browser\\Cache");
Xpcom.ProfileDirectory = (Application.StartupPath + "\\browser\\Cache");
InitializeComponent();
GeckoPreferences.Default["extensions.blocklist.enabled"] = false;
}
public Image GetImageId(GeckoWebBrowser Screen, GeckoHtmlElement a)
{
GeckoHtmlElement captchaImg = (GeckoHtmlElement)Screen.Document.GetElementById("cimage");
Image hyt;
try
{
hyt = (Bitmap)Image.FromStream(new MemoryStream(Gecko.Utils.SaveImageElement.ConvertGeckoImageElementToPng(Screen, captchaImg, 0, 0, captchaImg.OffsetWidth, captchaImg.OffsetHeight)));
}
catch
{
hyt = null;
}
return hyt;
}
private void Form1_Load(object sender, EventArgs e)
{
Time.MinDate = DateTime.Now.Date;
Time.Value = DateTime.Now.AddDays(1).Date;
Time.CustomFormat = "dd/MM/yyyy";
Time.Format = DateTimePickerFormat.Custom;
}
private void Strt_Click(object sender, EventArgs e)
{
LogT.Start();
}
private void LogT_Tick(object sender, EventArgs e)
{
if (Screen.IsBusy == false)
{
counter++;
if (counter == 1)
{
Screen.Navigate("https://www.irctc.co.in/eticketing/loginHome.jsf");
}
if (counter == 2)
{
Image cimg = hyt;
}
}
}
private void Login_Click(object sender, EventArgs e)
{
SinT.Start();
}
private void Clock_Tick(object sender, EventArgs e)
{
try
{
if (Screen.IsBusy == false)
{
counter++;
if (counter == 1)
{
GeckoInputElement name = new GeckoInputElement(Screen.Document.GetElementsByName("j_username")[0].DomObject);
name.Value = usrnm.Text;
GeckoInputElement word = new GeckoInputElement(Screen.Document.GetElementsByName("j_password")[0].DomObject);
word.Value = psswd.Text;
GeckoInputElement cap = new GeckoInputElement(Screen.Document.GetElementsByName("j_captcha")[0].DomObject);
cap.Value = cptch.Text;
Screen.Navigate("javascript:void(document.getElementsByName('button')[0].click() ) ");
}
if (counter == 2)
{
GeckoInputElement from = new GeckoInputElement(Screen.Document.GetElementsByName("jpform:fromStation")[0].DomObject);
from.Value = Start.Text;
GeckoInputElement to = new GeckoInputElement(Screen.Document.GetElementsByName("jpform:toStation")[0].DomObject);
to.Value = End.Text;
GeckoInputElement date = new GeckoInputElement(Screen.Document.GetElementsByName("jpform:journeyDateInputDate")[0].DomObject);
date.Value = Time.Text;
Screen.Navigate("javascript:void(document.getElementsByName('jpform:jpsubmit')[0].click() ) ");
}
}
}
catch
{
MessageBox.Show("Exception");
}
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
}
}