Beispiel #1
0
        //OnDisconnected
        private void OnDisconnected(SemacV14.Entity.TerminalEntity En)
        {
            EventLog.Write("{0}-{1}", "OnDisconnected", "OnDisconnected");
            try {
                lock (TerminalTable)
                {
                    DBO.CardReader dt = new DBO.CardReader();
                    foreach (DataRow row in TerminalTable.Rows)
                    {
                        if (row["TerminalID"].ToString() == En.TerminalID.ToString())
                        {
                            TerminalTable.Rows.Remove(row);
                            dt.TerminalID = En.TerminalID.ToString();
                            dt.Status     = dt.Status = En.Status.Equals("On Line") ? "1" : "0";
                            BO.updateCardReaderState(dt);
                            break;
                        }
                    }
                }
                Msg = string.Format("OnDisconnected,CardReader:{0},{1}", TerminalTable.Rows.Count.ToString(), En.ToMyString);
                EventLog.Write("{0}-{1}", "OnDisconnected", Msg);
                Console.WriteLine(Msg);

                _timer.Enabled = false;
            }
            catch (Exception ex) { EventLog.WriteError("{0}-{1}", "OnDisconnected", ex.ToString()); }
        }
Beispiel #2
0
        //OnConnected
        private void OnConnected(SemacV14.Entity.TerminalEntity En)
        {
            EventLog.Write("{0}-{1}", "OnConnected", "Start");
            try
            {
                ChannelID  = En.ChannelID;
                TerminalID = En.TerminalID;
                MacAddress = En.MacAddress;

                lock (this.TerminalTable)
                {
                    DataRow row = this.TerminalTable.NewRow();
                    row["ChannelID"]       = En.ChannelID;             //Connection ID
                    row["Status"]          = En.Status;                //On Line status
                    row["TerminalID"]      = En.TerminalID.ToString(); //TerminalID
                    row["IPAddress"]       = En.IPAddress;             //IP Address
                    row["MacAddress"]      = En.MacAddress;            //MAC Address
                    row["SerialNo"]        = En.SerialNo;              //Serial No.
                    row["ModelName"]       = En.ModelName;             //Model Name
                    row["FirmwareVersion"] = En.FirmwareVersion;       //Firmware Version

                    this.TerminalTable.Rows.Add(row);
                }

                EventLog.Write("{0}-{1}", "OnConnected", "Start-UpdateCardReaderState");
                int            iResult = 0;//0.Insert ,1.Update
                DBO.CardReader dt      = new DBO.CardReader();
                foreach (DataRow dr in dtCardReader.Rows)
                {
                    if (dr["TerminalID"].ToString() == En.TerminalID.ToString())
                    {
                        iResult = 1;
                        break;
                    }
                }
                dt.Status          = En.Status.Equals("On Line")?"1":"0";
                dt.TerminalID      = En.TerminalID.ToString();
                dt.IPAddress       = En.IPAddress;
                dt.MacAddress      = En.MacAddress;
                dt.SerialNo        = En.SerialNo;
                dt.ModelName       = En.ModelName;
                dt.FirmwareVersion = En.FirmwareVersion;
                dt.IsUse           = "Y";
                if (iResult == 0)
                {
                    BO.insertCardReader(dt);
                }
                else
                {
                    BO.updateCardReader(dt);
                }

                Msg = string.Format("OnConnected,CardReader:{0},{1}", TerminalTable.Rows.Count.ToString(), En.ToMyString);
                EventLog.Write("{0}-{1}", "OnConnected", Msg);
                Console.WriteLine(Msg);

                _timer.Enabled = true;
            }
            catch (Exception ex) { EventLog.Write("Error:{0}-{1}", "OnConnected", ex.ToString()); }
        }
Beispiel #3
0
        public static void updateCardReader(DBO.CardReader dt)
        {
            using (SqlConnection con = new SqlConnection(StaticConstant.MM_conn))
            {
                con.Open();
                string sql = @"
UPDATE [dbo].[CardReader]
   SET Status=@Status, IPAddress=@IPAddress
        ,MacAddress=@MacAddress, SerialNo=@SerialNo, ModelName=@ModelName
        ,FirmwareVersion=@FirmwareVersion
        ,LastModify=GETDATE(), IsUse=@IsUse
WHERE TerminalID = @TerminalID
 ";
                using (SqlCommand command = con.CreateCommand())
                {
                    command.CommandText = sql;
                    command.Parameters.AddWithValue("@Status", dt.Status);
                    command.Parameters.AddWithValue("@TerminalID", dt.TerminalID);
                    command.Parameters.AddWithValue("@IPAddress", dt.IPAddress);
                    command.Parameters.AddWithValue("@MacAddress", dt.MacAddress);
                    command.Parameters.AddWithValue("@SerialNo", dt.SerialNo);
                    command.Parameters.AddWithValue("@ModelName", dt.ModelName);
                    command.Parameters.AddWithValue("@FirmwareVersion", dt.FirmwareVersion);
                    command.Parameters.AddWithValue("@IsUse", dt.IsUse);
                    command.ExecuteNonQuery();
                }
            }
        }
Beispiel #4
0
        public static void insertCardReader(DBO.CardReader dt)
        {
            using (SqlConnection con = new SqlConnection(StaticConstant.MM_conn))
            {
                con.Open();
                string sql = @"
INSERT INTO [dbo].[CardReader]
        ([Status],[TerminalID],[IPAddress],[MacAddress]
        ,[SerialNo],[ModelName],[FirmwareVersion]
        ,[LastModify],[IsUse])
VALUES (@Status,@TerminalID,@IPAddress,@MacAddress
        ,@SerialNo,@ModelName,@FirmwareVersion
        ,Getdate(),@IsUse)
 ";
                using (SqlCommand command = con.CreateCommand())
                {
                    command.CommandText = sql;
                    command.Parameters.AddWithValue("@Status", dt.Status);
                    command.Parameters.AddWithValue("@TerminalID", dt.TerminalID);
                    command.Parameters.AddWithValue("@IPAddress", dt.IPAddress);
                    command.Parameters.AddWithValue("@MacAddress", dt.MacAddress);
                    command.Parameters.AddWithValue("@SerialNo", dt.SerialNo);
                    command.Parameters.AddWithValue("@ModelName", dt.ModelName);
                    command.Parameters.AddWithValue("@FirmwareVersion", dt.FirmwareVersion);
                    command.Parameters.AddWithValue("@IsUse", dt.IsUse);
                    command.ExecuteNonQuery();
                }
            }
        }
Beispiel #5
0
        public static void updateCardReaderState(DBO.CardReader dt)
        {
            using (SqlConnection con = new SqlConnection(StaticConstant.MM_conn))
            {
                con.Open();
                string sql = @"
UPDATE [dbo].[CardReader]
   SET Status=@Status,LastModify=GETDATE()
WHERE TerminalID = @TerminalID
 ";
                using (SqlCommand command = con.CreateCommand())
                {
                    command.CommandText = sql;
                    command.Parameters.AddWithValue("@Status", dt.Status);
                    command.Parameters.AddWithValue("@TerminalID", dt.TerminalID);
                    command.ExecuteNonQuery();
                }
            }
        }