Created
November 4, 2017 01:33
-
-
Save mohan-mu/e56c20a3cb5187e16f139b156d117ab3 to your computer and use it in GitHub Desktop.
c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.Data.OracleClient; | |
using System.Configuration; | |
using MongoDB.Bson; | |
using MongoDB.Driver; | |
using MongoDB.Driver.Builders; | |
using MongoDB.Driver.GridFS; | |
using MongoDB.Driver.Linq; | |
using LoveSeat; | |
using LoveSeat.Interfaces; | |
using LoveSeat.Support; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Linq; | |
namespace CrimeProject | |
{ | |
public partial class LogIn : Form | |
{ | |
public LogIn() | |
{ | |
InitializeComponent(); | |
} | |
public async Task CheckMongo(String email,String password) | |
{ | |
var client = new MongoClient("mongodb://localhost:27017"); | |
var database = client.GetDatabase("crimereport"); | |
var collection = database.GetCollection<BsonDocument>("users"); | |
var filter = Builders<BsonDocument>.Filter.Eq("email", email); | |
var result = await collection.Find(new BsonDocument("email", email)).ToListAsync(); | |
foreach (var document in result) | |
{ | |
if (document["password"] == password) | |
{ | |
email_id.Text = ""; | |
passwd.Text = ""; | |
MessageBox.Show("Welcome " + document["username"].ToString().ToUpper()); | |
FrmMdi main = new FrmMdi(); | |
Hide(); | |
main.ShowDialog(); | |
} | |
else | |
{ | |
passwd.Text = ""; | |
MessageBox.Show("Unable to login ,Please check fields & Try Again"); | |
} | |
} | |
//var list = await collection.Find(new BsonDocument("username", "Jack")) | |
// .ToListAsync(); | |
//foreach (var document in list) | |
//{ | |
// Console.WriteLine(document["username"]); | |
// MessageBox.Show(document["username"].ToString()); | |
//} | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
var client = new CouchClient(); | |
var db = client.GetDatabase("crime_report"); | |
// set default design doc (not required) | |
db.SetDefaultDesignDoc("docs"); | |
// get document by ID | |
Document myDoc = db.GetDocument("12345"); | |
// get document by ID (strongly typed POCO version) | |
String myObj = db.GetDocument<String>("12345"); | |
MessageBox.Show(myObj); | |
try | |
{ | |
// string cs = ConfigurationManager.ConnectionStrings["OrcXE"].ConnectionString; | |
//// using (OracleConnection conn = new OracleConnection(cs)) | |
// //{ | |
//MySqlConnection cnn = new MySqlConnection(cs); | |
// //conn.Open(); | |
// cnn.Open(); | |
// string query="select emailid,passwd from register where emailid='" + email_id.Text + "'and passwd=md5('" + passwd.Text + "')"; | |
// // OracleCommand cmd = new OracleCommand("select email,password from register where email='" + email_id.Text + "'and password='" + passwd.Text + "'", conn); | |
// MySqlCommand cmd = new MySqlCommand(query, cnn); | |
// string c = (string)cmd.ExecuteScalar(); | |
// * | |
CheckMongo(email_id.Text, passwd.Text); | |
//if (c == email_id.Text) | |
//{ | |
//Form1 m = new Form1(); | |
//this.Close(); | |
//} | |
} | |
catch(Exception ee) | |
{ | |
MessageBox.Show("connection failed or any datatype mismatch"+ee.Message.ToString()); | |
} | |
} | |
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) | |
{ | |
Register reg = new Register(); | |
reg.ShowDialog(); | |
this.Hide(); | |
} | |
private void LogIn_Load(object sender, EventArgs e) | |
{ | |
email_id.Focus(); | |
passwd.Enabled = false; | |
btn_log_in.Enabled = false; | |
} | |
private void username_TextChanged(object sender, EventArgs e) | |
{ | |
if(email_id.Text.Length>5) | |
{ | |
passwd.Enabled = true; | |
} | |
} | |
private void passwd_TextChanged(object sender, EventArgs e) | |
{ | |
if (passwd.Text.Length >9) | |
{ | |
btn_log_in.Enabled = true; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment