Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
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");
}
}
}
}
AnswerRe: c# application hang plz help Pin
Łukasz Nowakowski8-May-11 21:41
Łukasz Nowakowski8-May-11 21:41 
GeneralWhich kind of connects can be captured by Win32_ServerConnection!! [modified] Pin
Member 46594858-May-11 17:39
Member 46594858-May-11 17:39 
AnswerRe: Unable to get connected users by Win32_ServerConnection!! Pin
OriginalGriff8-May-11 20:31
mveOriginalGriff8-May-11 20:31 
GeneralRe: Unable to get connected users by Win32_ServerConnection!! Pin
Member 46594858-May-11 21:08
Member 46594858-May-11 21:08 
AnswerRe: Unable to get connected users by Win32_ServerConnection!! Pin
OriginalGriff8-May-11 21:18
mveOriginalGriff8-May-11 21:18 
GeneralRe: Unable to get connected users by Win32_ServerConnection!! Pin
Member 46594858-May-11 21:22
Member 46594858-May-11 21:22 
AnswerRe: Unable to get connected users by Win32_ServerConnection!! Pin
OriginalGriff8-May-11 21:29
mveOriginalGriff8-May-11 21:29 
GeneralRe: Unable to get connected users by Win32_ServerConnection!! Pin
OriginalGriff8-May-11 21:20
mveOriginalGriff8-May-11 21:20 
GeneralRe: Unable to get connected users by Win32_ServerConnection!! Pin
Member 46594858-May-11 21:25
Member 46594858-May-11 21:25 
QuestionGeneric linked list Pin
frofrofrofro7-May-11 5:56
frofrofrofro7-May-11 5:56 
AnswerRe: Generic linked list Pin
Luc Pattyn7-May-11 7:00
sitebuilderLuc Pattyn7-May-11 7:00 
AnswerRe: Generic linked list Pin
PIEBALDconsult7-May-11 14:06
mvePIEBALDconsult7-May-11 14:06 
JokeRe: Generic linked list Pin
Peter_in_27807-May-11 19:48
professionalPeter_in_27807-May-11 19:48 
GeneralRe: Generic linked list Pin
Luc Pattyn8-May-11 23:51
sitebuilderLuc Pattyn8-May-11 23:51 
GeneralRe: Generic linked list Pin
Niklas L9-May-11 5:07
Niklas L9-May-11 5:07 
AnswerRe: Generic linked list Pin
AspDotNetDev7-May-11 19:53
protectorAspDotNetDev7-May-11 19:53 
Questionlicense for the installation Pin
fazadef6-May-11 22:14
fazadef6-May-11 22:14 

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.