Click here to Skip to main content
15,921,062 members
Home / Discussions / C#
   

C#

 
QuestionNeed concept regarding website visit tracking software c# Pin
Tridip Bhattacharjee9-May-11 21:35
professionalTridip Bhattacharjee9-May-11 21:35 
AnswerRe: Need concept regarding website visit tracking software c# Pin
ambarishtv9-May-11 22:56
ambarishtv9-May-11 22:56 
AnswerRe: Need concept regarding website visit tracking software c# Pin
Eddy Vluggen10-May-11 0:36
professionalEddy Vluggen10-May-11 0:36 
AnswerRe: Need concept regarding website visit tracking software c# Pin
Dave Kreskowiak10-May-11 1:17
mveDave Kreskowiak10-May-11 1:17 
QuestionMaskedTextBox for IP address entry sample? Pin
9ine9-May-11 20:56
9ine9-May-11 20:56 
AnswerRe: MaskedTextBox for IP address entry sample? Pin
Blue_Boy9-May-11 21:00
Blue_Boy9-May-11 21:00 
QuestionWhere to keep the public variables & Functions? VS2010 Pin
Paramu19739-May-11 2:37
Paramu19739-May-11 2:37 
AnswerRe: Where to keep the public variables & Functions? VS2010 Pin
PIEBALDconsult9-May-11 2:43
mvePIEBALDconsult9-May-11 2:43 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
Luc Pattyn9-May-11 2:51
sitebuilderLuc Pattyn9-May-11 2:51 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
PIEBALDconsult9-May-11 3:01
mvePIEBALDconsult9-May-11 3:01 
QuestionRe: Where to keep the public variables & Functions? VS2010 Pin
#realJSOP9-May-11 8:18
professional#realJSOP9-May-11 8:18 
AnswerRe: Where to keep the public variables & Functions? VS2010 Pin
PIEBALDconsult9-May-11 14:40
mvePIEBALDconsult9-May-11 14:40 
AnswerRe: Where to keep the public variables & Functions? VS2010 Pin
Luc Pattyn9-May-11 2:49
sitebuilderLuc Pattyn9-May-11 2:49 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
PIEBALDconsult9-May-11 3:13
mvePIEBALDconsult9-May-11 3:13 
AnswerRe: Where to keep the public variables & Functions? VS2010 Pin
#realJSOP9-May-11 8:15
professional#realJSOP9-May-11 8:15 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
SilimSayo9-May-11 11:38
SilimSayo9-May-11 11:38 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
PIEBALDconsult9-May-11 14:14
mvePIEBALDconsult9-May-11 14:14 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
SilimSayo11-May-11 6:30
SilimSayo11-May-11 6:30 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
PIEBALDconsult11-May-11 14:31
mvePIEBALDconsult11-May-11 14:31 
AnswerRe: Where to keep the public variables & Functions? VS2010 Pin
Shameel9-May-11 18:10
professionalShameel9-May-11 18:10 
GeneralRe: Where to keep the public variables & Functions? VS2010 Pin
Paramu197310-May-11 0:12
Paramu197310-May-11 0:12 
QuestionSpace in a c# wordAddIn project Pin
Pierre besquent9-May-11 0:43
Pierre besquent9-May-11 0:43 
Questionkdtele disconnect problem Pin
mobasher8-May-11 23:22
mobasher8-May-11 23:22 
AnswerRe: kdtele disconnect problem Pin
Dave Kreskowiak9-May-11 1:23
mveDave Kreskowiak9-May-11 1:23 
Questionc# application hang plz help Pin
spider_vikas8-May-11 20:57
spider_vikas8-May-11 20:57 
code is


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using RfidApiLib;
using System.IO;
using System.Data.SqlClient;
using System.Threading;
namespace Service_Ambu_Exit
{
public partial class Form1 : Form
{
RfidApi api = new RfidApi();
public int TagCnt = 0;
string ip;
string portNo;
string p_type = "";
string p1 = "";
string arr1;
int intcount = 0;
public Form1()
{
InitializeComponent();
}






private int connectReader()
{
try
{
StreamReader sr1 = new StreamReader("ipandport.txt");
string[] str2;
string[] str3;
string arr3;
arr3 = sr1.ReadLine();
str2 = arr3.Split('=');
ip = str2[1].Trim();



StreamReader sr3 = new StreamReader("ipandport.txt");
string arr2;
arr2 = sr3.ReadLine();
arr2 = sr3.ReadLine();
str3 = arr2.Split('=');
portNo = str3[1].Trim();




int status;
int port;

string s = "";
try
{
port = int.Parse(portNo);
s = ip;

}
catch (Exception)
{
logfile("Please mention the valid ip address and port in settings file.");
return 0;
}
status = api.TcpConnectReader(ip, port);


if (status != 0)
{
logfile("Connect Reader Failed.");
return 0;
}


if (ip == "172.16.100.3".Trim() || ip == "172.16.100.4".Trim())
{
p1 = "STAFF".Trim();
}
else if (ip == "172.16.100.5".Trim() || ip == "172.16.100.7".Trim() || ip == "172.16.100.6".Trim())
{
p1 = "AMBULANCE".Trim();
}
else if (ip == "172.16.100.2".Trim() || ip == "172.16.100.1".Trim())
{
p1 = "BASEMENT".Trim();
}

StreamReader sr = new StreamReader("RFSettings.txt");
string[] str1;
string arr;
arr = sr.ReadLine();
str1 = arr.Split(':');
arr1 = str1[1].Trim();


}
catch (Exception e)
{
logfile(e.Message.ToString());
} return 1;

}

private void Form1_Load(object sender, EventArgs e)
{

try
{

int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);

}
logfile("Reader Connected.");
timer1.Start();
//timer2.Start();

}
catch (Exception e1)
{
logfile(e1.Message.ToString());

}
}

private void logfile(string str)
{
try
{
string month = string.Format("{0:MM}", DateTime.Now);
string year = string.Format("{0:yyyy}", DateTime.Now);
if (Directory.Exists("log/" + year + ""))
{

}
else
{
Directory.CreateDirectory("log/" + year + "");
}

if (Directory.Exists("log/" + year + "/" + month + ""))
{

}
else
{
Directory.CreateDirectory("log/" + year + "/" + month + "");
}




if (Directory.Exists("log/" + year + "/" + month + ""))
{

StreamWriter sw; //= new StreamWriter("log/" + year + "/" + month + "/RFlog.txt");
if (File.Exists("log/" + year + "/" + month + "/RFlog.txt"))
{
string str2 = DateTime.Now.ToString() + " " + str;
sw = File.AppendText("log/" + year + "/" + month + "/RFlog.txt");
sw.WriteLine(str2);
sw.Close();
}
else
{
sw = File.CreateText("log/" + year + "/" + month + "/RFlog.txt");

string str1 = DateTime.Now.ToString() + " " + str;
sw.WriteLine(str1);
sw.Close();
}
}
}
catch (Exception e)
{

}



}




private void check_status()
{
try
{
SqlConnection con = new SqlConnection(arr1);

SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "EXEC TAG_ZONE_STATUS_DEMO";
SqlDataAdapter da = new SqlDataAdapter(com);
DataTable dt = new DataTable();
da.Fill(dt);

SqlCommand com1 = new SqlCommand();
com1.Connection = con;
com1.CommandText = "select * from temp_tbl";
SqlDataAdapter da1 = new SqlDataAdapter(com1);
DataSet ds = new DataSet();
da1.Fill(ds);

if (ds.Tables[0].Rows[0][0].ToString() == "ALLOW")
{
if (p1 == p_type)
{
SqlCommand com2 = new SqlCommand();
com2.Connection = con;
com2.CommandText = "UPDATE tbl_tag_reader_master SET FLAG = 1 WHERE TAG_ID = '" + ds.Tables[0].Rows[0]["TAG_ID"] + "'";
con.Open();
com2.ExecuteNonQuery();
con.Close();
api.SetOutPort(0, 0);
Thread.Sleep(2000);

api.SetOutPort(0, 1);
}

}
}
catch (Exception ex)
{
logfile(ex.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);

}
logfile("Reader Connected.Out Cmd");
timer1.Start();

}
}

private void timer1_Tick(object sender, EventArgs e)
{


try
{

intcount = intcount + 1;
api.ClearIdBuf();
int status;
byte tag_cnt = 0;
int i, j;
byte[,] isobuf = new byte[100, 12];
string s = "";
string s1 = "";
string[] s2 = null;
string s3;
byte tagflag = 0;
DateTime dt;
dt = DateTime.Now;
string dt1 = dt.ToString("yyyy-MM-dd HH:mm:ss");
status = api.EpcMultiTagIdentify(ref isobuf, ref tag_cnt, ref tagflag);
if (status != 0)
{
DllNotFoundException dl = new DllNotFoundException();
throw dl;


}
else if (tag_cnt > 0)
{
for (i = 0; i < tag_cnt; i++)
{
s1 = string.Format("NO.{0Big Grin | :-D }: ", TagCnt);
for (j = 0; j < 12; j++)
{
s = string.Format("{0:X2}", isobuf[i, j]);
s1 += s;
}
s2 = s1.Split(':');
s3 = DateTime.Now.ToString();
SqlConnection con1 = new SqlConnection(arr1);
SqlCommand com1 = new SqlCommand();
com1.Connection = con1;
com1.CommandText = "select count(*) from TBL_VEHICLE_OWNER_PERMISSION_MASTER where TAG_UID='" + s2[1].Trim() + "'";
SqlDataAdapter da23 = new SqlDataAdapter(com1);
DataTable dt23 = new DataTable();
da23.Fill(dt23);
int c23 = Int32.Parse(dt23.Rows[0][0].ToString());
if (c23 > 0)
{
SqlCommand com2 = new SqlCommand();
com2.Connection = con1;
com2.CommandText = "select PARKING_TYPE from TBL_VEHICLE_OWNER_PERMISSION_MASTER where TAG_UID='" + s2[1].Trim() + "'";
SqlDataAdapter da24 = new SqlDataAdapter(com2);
DataTable dt24 = new DataTable();
da24.Fill(dt24);
p_type = dt24.Rows[0][0].ToString();

}
else
{
p_type = "";
}




SqlCommand com;

com = new SqlCommand();
com.Connection = con1;
com.CommandText = "select * from tbl_tag_reader_master where tag_id='" + s2[1].Trim() + "' and datediff(second,timetag,'" + dt1 + "')<8";
DataTable dt12 = new DataTable();
SqlDataAdapter da12 = new SqlDataAdapter(com);
da12.Fill(dt12);
if (dt12.Rows.Count > 0)
{
}
else
{
com = new SqlCommand();
com.Connection = con1;
com.CommandText = "insert into tbl_tag_reader_master values('" + ip + "','" + s2[1].Trim() + "','" + System.DateTime.Now.ToString() + "','" + null + "','" + null + "','" + null + "','" + null + "','" + null + "','" + null + "')";
con1.Open();
com.ExecuteNonQuery();
con1.Close();
check_status();
TagCnt++;
}





}
}
if (intcount > 1800)
{
timercount2();
intcount = 0;
}
timer1.Start();
}
catch (DllNotFoundException d1)
{
logfile("Connection Broken. Reattempting Connection...");
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);

}
logfile("Reader Connected.Timer");
timer1.Start();
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
// Thread.Sleep(2000);

}
logfile("Reader Connected.Timer");

}
}

private void timer2_Tick(object sender, EventArgs e)
{

}
private void timercount2()
{
try
{
api.TcpCloseConnect();
int i = 0;
while (i == 0)
{
i = connectReader();
//Thread.Sleep(2000);

}
logfile("Reader Connected.Timer2");
}
catch (Exception e1)
{
logfile(e1.Message.ToString());
int i = 0;
while (i == 0)
{
i = connectReader();
//Thread.Sleep(2000);

}
logfile("Reader Connected.Timer2");
}
}
}
}

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.