Пример #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string ver = string.Empty;
                //ver = client.GetVersion();
                //MessageBox.Show(ver);

                TRReaderServiceLib.ReaderInfo rdrInfo = new TRReaderServiceLib.ReaderInfo();
                rdrInfo.ReaderName = txtReaderName.Text;
                rdrInfo.ReaderDescription = txtReaderDesc.Text;
                rdrInfo.IPAddress = txtIPAddress.Text.Replace(" ", "");
                rdrInfo.PortNo = uint.Parse(txtPortNo.Text);
                rdrInfo.MAC = txtMACAdd.Text;
                rdrInfo.LocationRef = txtLocRef.Text;
                rdrInfo.LocationDescription = txtLocDescription.Text;
                rdrInfo.ReaderGroupId = rdrGroupID;
                rdrInfo.ReaderTypeId = ((ReaderType) cmbReaderType.SelectedValue).ReaderTypeID;

                var res = groupObj.AddReader(rdrInfo);
                if (res.IsSuccess)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                    MessageBox.Show("Unable to Add Reader.", "Add Reader", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add reader, you may want to verify IPAddress and Port settings.");
            }
        }
Пример #2
0
        public void InitReader(IReaderService readerService, string endpoint, ReaderInfo objReader, int pReadTimeOutInMS = 1000)
        {
            rdrServiceEndpoint = endpoint;
            DisconnectExistingReader();
            SetToDefault();

            if (objReader == null)
            {
                throw new ApplicationException("Please check configuration ! Null RFIDReader object supplied.");
            }

            readTimeOutInMS = pReadTimeOutInMS;

            readerInfo = objReader;
            if (readerService == null)
                throw new ApplicationException("Error :  supplied object of Reader Service is NULL/Invalid.");

            readerServiceObj = readerService;

            SetToDefault();
            //string wcfServiceConn = frmMain.frmMainObj.objReaderGrpBO.ReaderGroups[readerInfo.ReaderGroupId].ReaderWCFConnectionString;
            //client = frmMain.frmMainObj.objReaderGrpBO.InitService(wcfServiceConn);
            //if (client == null)
            //    throw new ApplicationException("Error :  Could not connect to Reader Service on given connection - " + wcfServiceConn);
        }
        public RFIDMotorolaReader(ReaderInfo readerInfo, uint timeOut, int readerPulseInterval_inMins = 15)
        {
            try
            {
                #region Param Validation
                if (readerInfo == null)
                {
                    throw new ArgumentNullException("readerInfo", "Parameter can't be Empty/Null.");
                }

                if (string.IsNullOrWhiteSpace(readerInfo.IPAddress))
                {
                    throw new ArgumentNullException("readerInfo.IPAddress", "Parameter can;t be Empty/Null.");
                }
                #endregion Param Validation

                mReaderInfo = readerInfo;
                mTimeOut = timeOut;

                mReaderPulseInterval_inMins = readerPulseInterval_inMins;

            }
            catch (Exception ex)
            {
                LoggerAgent.Error("Error in creating instance of reader. ReaderId: " + readerInfo.ReaderId, ex);
                throw new ApplicationException("Failed to create new instance of reader.", ex);
            }
        }
Пример #4
0
        public frmModifyReader(ReaderInfo readerInfo, IReaderService client)
        {
            InitializeComponent();

            this.client = client;
            this.readerInfo = readerInfo;

            FillForm();
        }
Пример #5
0
 public ResultObject AddReader(ReaderInfo rdrInfo)
 {
     IReaderService rdrClient = InitService(lstReaderGroups[rdrInfo.ReaderGroupId].ReaderWCFConnectionString);
     if (rdrClient != null)
     {
         var res = rdrClient.AddReader(rdrInfo);
         return res;
     }
     return null;
 }
Пример #6
0
 public ResultObject AddReader(ReaderInfo rdrInfo)
 {
     string url = "";
     url = System.Configuration.ConfigurationManager.AppSettings["ServiceUrl"].ToString();
     IReaderService rdrClient = InitService(url);
     if (rdrClient != null)
     {
         var res = rdrClient.AddReader(rdrInfo);
         return res;
     }
     return null;
 }
Пример #7
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            TRReaderServiceLib.ReaderInfo rdrInfo = new TRReaderServiceLib.ReaderInfo();
            rdrInfo.ReaderId = this.readerInfo.ReaderId;
            rdrInfo.ReaderName = txtReaderName.Text;
            rdrInfo.ReaderDescription = txtReaderDesc.Text;
            rdrInfo.IPAddress = txtIPAddress.Text.Replace(" ","");
            rdrInfo.PortNo = uint.Parse(txtPortNo.Text);
            rdrInfo.MAC = txtMACAdd.Text;
            rdrInfo.LocationRef = txtLocRef.Text;
            rdrInfo.LocationDescription = txtLocDescription.Text;
            rdrInfo.ReaderGroupId = this.readerInfo.ReaderGroupId;
            rdrInfo.ReaderTypeId = this.readerInfo.ReaderTypeId;

            ResultObject res = client.ModifyReader(rdrInfo);
            if (res.IsSuccess)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
                MessageBox.Show("Unable to Modify Reader.", "Modify Reader", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
Пример #8
0
        protected void btnAddZone_Click(object sender, EventArgs e)
        {
            string strScript = "";
            using (Neophotonics_webDbHelper BAdbHelper = new Neophotonics_webDbHelper())
            {
                //Checkboxselection HH
                #region
                //if (rdtypeHH.Checked == true)
                //{

                //    if (txtdesc.Text.Length > 0)
                //    {

                //        string id = value.ToString();

                //        string[] ids = Regex.Split(id, ".");

                //        string desc = txtdesc.ToString();

                //        string[] wordsdesc = Regex.Split(desc, "\r\n");

                //        foreach (string strval in wordsdesc)
                //      {

                //          string[] words = Regex.Split(value, ".");
                //            BAdbHelper.AddParameter("@ZoneDescription", SqlDbType.VarChar, txtdesc.Text);
                //            BAdbHelper.AddParameter("@BuildingId", SqlDbType.Int, drpBildingName.SelectedValue);
                //            BAdbHelper.AddParameter("@ReaderId", SqlDbType.Int, ddReader.SelectedValue);

                //            BAdbHelper.Command.CommandType = System.Data.CommandType.StoredProcedure;
                //            BAdbHelper.Command.CommandText = "SP_Zone_Add";

                //        }
                //        int i = BAdbHelper.ExecuteNoneQuery();
                //        Response.Redirect("~/Setup/ZoneView.aspx?RespMsg=Zone Added Successfully", true);
                //    }
                //}
                #endregion
                if (drpBildingName.SelectedItem.Text == "-Select-" )
                {

                    strScript = "<script>";
                    strScript = strScript + "alert('Please select Building.');";
                    strScript = strScript + "</script>";
                    ClientScript.RegisterStartupScript(this.GetType(), "clientscript", strScript.ToString());
                    return;
                }
                if (ddReader.SelectedItem.Text == "-Select-")
                {

                    strScript = "<script>";
                    strScript = strScript + "alert('Please select Hardware.');";
                    strScript = strScript + "</script>";
                    ClientScript.RegisterStartupScript(this.GetType(), "clientscript", strScript.ToString());
                    return;
                }

                if (txtdesc.Text == "")
                {

                    strScript = "<script>";
                    strScript = strScript + "alert('Please Enter Description.');";
                    strScript = strScript + "</script>";
                    ClientScript.RegisterStartupScript(this.GetType(), "clientscript", strScript.ToString());
                    return;
                }

                try
                {

                    BAdbHelper.AddParameter("@Type", SqlDbType.VarChar, rdtypeRD.Checked);
                    BAdbHelper.AddParameter("@ZoneDescription", SqlDbType.VarChar, txtdesc.Text);
                    BAdbHelper.AddParameter("@BuildingId", SqlDbType.Int, drpBildingName.SelectedValue);
                    BAdbHelper.AddParameter("@ReaderId", SqlDbType.Int, ddReader.SelectedValue);

                    BAdbHelper.Command.CommandType = System.Data.CommandType.StoredProcedure;
                    BAdbHelper.Command.CommandText = "SP_Zone_Add";
                    DataSet ReaderDataSet = BAdbHelper.ExcuteDatset(BAdbHelper.Command);
                    if (ReaderDataSet.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow row in ReaderDataSet.Tables[0].Rows)
                         {

                        TRReaderServiceLib.ReaderInfo rdrInfo = new TRReaderServiceLib.ReaderInfo();
                        rdrInfo.ReaderName =row["DeviceName"].ToString();
                        rdrInfo.ReaderDescription = row["DeviceName"].ToString();
                        rdrInfo.IPAddress = row["DeviceIPAddress"].ToString();
                        rdrInfo.PortNo = uint.Parse( row["DevicePortNumber"].ToString());
                        rdrInfo.MAC = row["DeviceMAC"].ToString();
                        rdrInfo.LocationRef = row["LocationRef"].ToString();
                        rdrInfo.LocationDescription = row["LocationRef"].ToString();
                        rdrInfo.ReaderGroupId = int.Parse  (row["ReaderGroupID"].ToString());
                        rdrInfo.ReaderTypeId =int.Parse( row["ReaderTypeID"].ToString());
                        rdrInfo.AntennaPower = int.Parse(row["AntennaPower"].ToString());

                        var res = AddReader(rdrInfo);
                         }

                    }

                }
                catch (Exception ex)
                {

                }
                Response.Redirect("~/Setup/ZoneView.aspx?RespMsg=Zone Added Successfully", true);

            }
        }
Пример #9
0
        public ResultObject AddReader(ReaderInfo objReaderInfo)
        {
            lock (objLock)
            {
                LoggerAgent.Trace("Entering...");

                ResultObject objRes = new ResultObject();
                objRes.MethodInfo = "ReaderService.AddReader ";

                try
                {

                    // -- Adding reader to DB ----
                    ReaderDA objReaderDA = new ReaderDA();
                    objRes = objReaderDA.AddReader(objReaderInfo);

                    if (objRes.IsSuccess == false)
                    {
                        return objRes;
                    }

                    // --- Connecting to actual reader ---
                    RFIDMotorolaReader rdrObject = null;
                    try
                    {
                        rdrObject = new RFIDMotorolaReader(objReaderInfo, 1000, readerPulseMonitor_InMin);
                        objRes.IsSuccess = rdrObject.Connect(pollCycle, true);
                    }
                    catch (Exception ex)
                    {
                        objRes.IsSuccess = false;
                        objRes.ErrorMessage = "Unable to connect to Reader. IP Address " + objReaderInfo.IPAddress;
                        objRes.ErrorMessageInternal = "Error : " + ex.ToString();
                    }

                    //Reader-Service collection will cache actual reader.
                    dicReaders[objReaderInfo.ReaderId] = rdrObject;

                    //Set result object: - /*set online status*/
                    objReaderInfo.IsOnline = objRes.IsSuccess;
                    //Set readerInfo in result object
                    // NOTE: ReaderId key is already SET by DAL call.
                    // objRes.ResultData["ReaderInfo"] = objReaderInfo;
                    objRes.MethodInfo = "ReaderService.AddReader ";
                    objRes.TimeStampString = DateTime.Now.ToString();

                    LoggerAgent.Debug("Reader status:  "
                        + " Reader IP:Port = " + rdrObject.ReaderInfo.IPAddress + ":"  + rdrObject.ReaderInfo.PortNo.ToString()
                        + ", IsOnline = " + rdrObject.ReaderInfo.IsOnline.ToString() );
                }
                catch (Exception ex)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "Unable to Add Reader. IP Address " + objReaderInfo.IPAddress;
                    objRes.ErrorMessageInternal = "Error : " + ex.ToString();

                    LoggerAgent.Error("Error : Failed to AddReader. " + objRes.ErrorMessage, ex);
                }
                finally
                {
                    LoggerAgent.Trace("Leaving...");
                }

                LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
                return objRes;
            }
        }
Пример #10
0
        public ResultObject ReconnectReader(ReaderInfo objReaderInfo)
        {
            LoggerAgent.Trace("Entering...");

            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderService.ReconnectReader ";
            try
            {
                //param validation
                if (objReaderInfo == null)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ReconnectReader Error : Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                if (objReaderInfo.ReaderId <= 0)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ReconnectReader Error : ReaderId is invalid. Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                var reader = dicReaders[objReaderInfo.ReaderId];
                reader.Reconnect(pollCycle, true);

                objRes.IsSuccess = true;

            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to ReconnectReader " + objReaderInfo.ReaderId.ToString();
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();

                LoggerAgent.Error("Error in Reconnecting reader, ReaderId = " + objReaderInfo.ReaderId.ToString(), ex);
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            //reset the methodinfo
            objRes.MethodInfo = "ReaderService.ReconnectReader ";

            LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
            LoggerAgent.Trace("Leaving...");

            return objRes;
        }
Пример #11
0
        public ResultObject ModifyReader(ReaderInfo objReaderInfo)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = "ReaderService.ModifyReader ";
            try
            {
                //param validation
                if (objReaderInfo ==  null)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ModifyReader Error : Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                if (objReaderInfo.ReaderId <= 0)
                {
                    objRes.IsSuccess = false;
                    objRes.ErrorMessage = "ModifyReader Error : ReaderId is invalid. Invalid ReaderInfo object supplied.";
                    objRes.ErrorMessageInternal = string.Empty;
                    objRes.TimeStampString = DateTime.Now.ToString();
                    return objRes;
                }

                ReaderDA objReaderDA = new ReaderDA();
                objRes = objReaderDA.ModifyReader(objReaderInfo);
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to modify reader " + objReaderInfo.ReaderId.ToString();
                objRes.ErrorMessageInternal = "Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            //reset the methodinfo
            objRes.MethodInfo = "ReaderService.ModifyReader ";

            LoggerAgent.Info("Result status = " + ResultObject.GetLogString(objRes));
            LoggerAgent.Trace("Leaving...");
            return objRes;
        }
Пример #12
0
        public ResultObject AddReader(ReaderInfo readerInfo)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = " ReaderDA.AddReader ";
            string insertSql =
                                    "INSERT INTO [RF].[Reader] " +
                                                 " ([ReaderGroupID] " +
                                                 ", [ReaderTypeID] " +
                                                 ", [ReaderName] " +
                                                 ", [ReaderDescription] " +
                                                 ", [IPAddress] " +
                                                 ", [PortNo] " +
                                                 ", [MACAddress] " +
                                                 ", [AntennaPower] " +
                                                 ", [ReaderPower] " +
                                                 ", [LocationRef] " +
                                                 ", [LocationDescription] " +
                                                 ", [IsDeleted]  " +
                                                 ", [CreateDateTime]  " +
                                                 ", [UpdateDateTime] ) " +
                                                 " VALUES " +
                                                 "(@ReaderGroupID " +
                                                 ", @ReaderTypeID " +
                                                 ", @ReaderName " +
                                                 ", @ReaderDescription " +
                                                 ", @IPAddress " +
                                                 ", @PortNo " +
                                                 ", @MACAddress " +
                                                 ", @AntennaPower " +
                                                 ", @ReaderPower " +
                                                 ", @LocationRef " +
                                                 ", @LocationDescription " +
                                                 ", @IsDeleted " +
                                                 ", @CreateDateTime " +
                                                 ", @UpdateDateTime ); ";

            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = insertSql;

                    dbhelper.AddParameter("@ReaderGroupID", SqlDbType.Int, readerInfo.ReaderGroupId);
                    dbhelper.AddParameter("@ReaderTypeID", SqlDbType.Int, readerInfo.ReaderTypeId);
                    dbhelper.AddParameter("@ReaderName", SqlDbType.NVarChar, readerInfo.ReaderName);
                    dbhelper.AddParameter("@ReaderDescription", SqlDbType.NVarChar, readerInfo.ReaderDescription);
                    dbhelper.AddParameter("@IPAddress", SqlDbType.NVarChar, readerInfo.IPAddress);
                    dbhelper.AddParameter("@PortNo", SqlDbType.Int, readerInfo.PortNo);
                    dbhelper.AddParameter("@MACAddress", SqlDbType.VarChar, readerInfo.MAC == null ? "  " : readerInfo.MAC);
                    dbhelper.AddParameter("@AntennaPower", SqlDbType.VarChar, (float)readerInfo.AntennaPower);
                    dbhelper.AddParameter("@ReaderPower", SqlDbType.Float, (float)1.0); // readerInfo.AntennaPower);
                    dbhelper.AddParameter("@LocationRef", SqlDbType.NVarChar, readerInfo.LocationRef);
                    dbhelper.AddParameter("@LocationDescription", SqlDbType.NVarChar, readerInfo.LocationDescription);
                    dbhelper.AddParameter("@IsDeleted", SqlDbType.Bit, 0);
                    dbhelper.AddParameter("@CreateDateTime", SqlDbType.DateTime, DateTime.Now);
                    dbhelper.AddParameter("@UpdateDateTime", SqlDbType.DateTime, DateTime.Now);

                    int i = dbhelper.ExecuteNoneQuery();

                    objRes.IsSuccess = true;
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to add reader into database";
                objRes.ErrorMessageInternal = " Error : " + ex.ToString();
            }

            //try to return readerId for newly added reader
            ResultObject internalResultObject = new ResultObject();
            internalResultObject = GetReaderByReaderName(readerInfo.ReaderName);

            //Assign readerId to main result object with key "ReaderId"
            objRes.ResultData["ReaderId"] = internalResultObject.IsSuccess ? ((ReaderInfo)internalResultObject.ResultData["ReaderInfo"]).ReaderId : -1 /*OnError reader is -1*/;
               readerInfo.ReaderId  = internalResultObject.IsSuccess ? ((ReaderInfo)internalResultObject.ResultData["ReaderInfo"]).ReaderId : -1 /*OnError reader is -1*/;
            objRes.ResultData["ReaderInsertSql"] = insertSql;
            objRes.TimeStampString = DateTime.Now.ToString();

            return objRes;
        }
Пример #13
0
        public ResultObject ModifyReader(ReaderInfo readerInfo, bool isdeleted = false)
        {
            ResultObject objRes = new ResultObject();
            objRes.MethodInfo = " ReaderDA.ModifyReader ";

            try
            {
                using (var dbhelper = new DbHelper())
                {
                    // Fetch Reader Group
                    dbhelper.Command.CommandType = System.Data.CommandType.Text;
                    dbhelper.Command.CommandText = "UPDATE [RF].[Reader] " +
                                                   "SET [ReaderGroupID] = @ReaderGroupID " +
                                                    ", [ReaderTypeID] = @ReaderTypeID " +
                                                    ", [ReaderName] = @ReaderName " +
                                                    ", [ReaderDescription] = @ReaderDescription  " +
                                                    ", [IPAddress] = @IPAddress  " +
                                                    ", [PortNo] = @PortNo  " +
                                                    ", [MACAddress] = @MACAddress " +
                                                    ", [AntennaPower] = @AntennaPower " +
                                                    ", [ReaderPower] = @ReaderPower  " +
                                                    ", [LocationRef] = @LocationRef  " +
                                                    ", [LocationDescription] = @LocationDescription  " +
                                                    ", [IsDeleted] = @IsDeleted " +
                                                    ", [UpdateDateTime] = @UpdateDateTime " +
                                                    " WHERE ReaderID = @ReaderID ;";

                    dbhelper.AddParameter("@ReaderGroupID", SqlDbType.Int, readerInfo.ReaderGroupId);
                    dbhelper.AddParameter("@ReaderTypeID", SqlDbType.Int, readerInfo.ReaderTypeId);
                    dbhelper.AddParameter("@ReaderName", SqlDbType.NVarChar, readerInfo.ReaderName);
                    dbhelper.AddParameter("@ReaderDescription", SqlDbType.NVarChar, readerInfo.ReaderDescription);
                    dbhelper.AddParameter("@IPAddress", SqlDbType.NVarChar, readerInfo.IPAddress);
                    dbhelper.AddParameter("@PortNo", SqlDbType.Int, readerInfo.PortNo);
                    dbhelper.AddParameter("@MACAddress", SqlDbType.VarChar, readerInfo.MAC == null ? " " : readerInfo.MAC);
                    dbhelper.AddParameter("@AntennaPower", SqlDbType.VarChar, (float)readerInfo.AntennaPower);
                    dbhelper.AddParameter("@ReaderPower", SqlDbType.Float, readerInfo.AntennaPower);
                    dbhelper.AddParameter("@LocationRef", SqlDbType.NVarChar, readerInfo.LocationRef);
                    dbhelper.AddParameter("@LocationDescription", SqlDbType.NVarChar, readerInfo.LocationDescription);
                    dbhelper.AddParameter("@IsDeleted", SqlDbType.Bit, isdeleted ? 1 : 0);
                    dbhelper.AddParameter("@UpdateDateTime", SqlDbType.DateTime, DateTime.Now);
                    dbhelper.AddParameter("@ReaderID", SqlDbType.Int, readerInfo.ReaderId);

                    int i = dbhelper.ExecuteNoneQuery();

                    objRes.IsSuccess = true;
                    objRes.ResultData["ReaderId"] = readerInfo.ReaderId;
                    //objRes.ResultData["ReaderInfo"] = readerInfo;
                }
            }
            catch (Exception ex)
            {
                objRes.IsSuccess = false;
                objRes.ErrorMessage = "Failed to modify reader into database";
                objRes.ErrorMessageInternal = " Error : " + ex.ToString();
            }

            objRes.TimeStampString = DateTime.Now.ToString();
            return objRes;
        }