示例#1
0
        /// <summary>
        /// 添加密码到电子锁
        /// </summary>
        /// <param name="rentNO"></param>
        /// <param name="pass"></param>
        /// <param name="startdate"></param>
        /// <param name="enddate"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        public string AddPassword(string rentNO, string pass, string startdate, string enddate, string phone)
        {
            Dictionary <string, string> ret = new Dictionary <string, string>();
            string    sql = "select * from Rent_Locks where rentNo='" + rentNO + "' and Status='0'";
            DataTable dt  = MySQLHelper.ExecuteDataset(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql)).Tables[0];

            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["DeviceType"].ToString() == "1") //新锁
                {
                    NewLockManager managerNew = new NewLockManager();
                    string         r          = managerNew.GetPostInterface(dt.Rows[0]["DeviceID"].ToString(), phone, "2", pass, startdate, enddate); //设置临时密码
                    ret = JSONHelper.FromJson <Dictionary <string, string> >(r);
                }
                else //旧锁
                {
                    LockManager manager = new LockManager();
                    manager.AddPassword(dt.Rows[0]["DeviceID"].ToString(), pass, startdate, enddate);
                    string r = manager.UpdatePassengerInfoToDevice(dt.Rows[0]["DeviceID"].ToString(), "", "", "", pass, DateTime.Parse(startdate).ToString("yyyyMMddHHmm").Substring(2, 10), DateTime.Parse(enddate).ToString("yyyyMMddHHmm").Substring(2, 10), "3");
                    ret = JSONHelper.FromJson <Dictionary <string, string> >(r);
                }
            }
            else
            {
                ret.Add("ret", "1");
                ret.Add("msg", "未发现智能锁信息,无法添加密码");
            }

            return(JSONHelper.ToJson(ret));
        }
示例#2
0
        /// <summary>
        /// 删除密码和IC卡
        /// </summary>
        /// <param name="aarId"></param>
        /// <returns></returns>
        public string ClearPasswordToLock(string aarId)
        {
            Dictionary <string, string> dic = new Dictionary <string, string>();
            RentAttribute a  = new RentAttribute(int.Parse(aarId));
            DataTable     dt = MySQLHelper.ExecuteDataset(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand("select * from Rent_Locks where rentno='" + a.RentNo + "'")).Tables[0];

            if (dt.Rows.Count > 0)
            {
                string returnStr1 = string.Empty;
                if (dt.Rows[0]["DeviceType"].ToString() == "1") //新锁
                {
                    NewLockManager managerNew = new NewLockManager();
                    //清空临时卡
                    string iCCard = managerNew.delAction(a.RRAContactTel, "临时卡片", a.RRAStartDate.ToString(), a.RRAEndDate.ToString(), dt.Rows[0]["DeviceID"].ToString(), "1");
                    //清空临时密码
                    string password = managerNew.delAction(a.RRAContactTel, "临时密码", a.RRAStartDate.ToString(), a.RRAEndDate.ToString(), dt.Rows[0]["DeviceID"].ToString(), "1");
                    Dictionary <string, object> retIC = new Dictionary <string, object>();
                    retIC = JSONHelper.FromJson <Dictionary <string, object> >(iCCard);
                    Dictionary <string, object> retPass = new Dictionary <string, object>();
                    retPass = JSONHelper.FromJson <Dictionary <string, object> >(password);
                    if (retIC["ret"].ToString() == "1" || retPass["ret"].ToString() == "1")
                    {
                        returnStr1 = "ICCard:" + retIC["msg"].ToString() + "Pass:"******"msg"].ToString();
                    }
                }
                else  //旧锁
                {
                    string sql = "select * from Rent_Locks_ICCards where LockID='" + dt.Rows[0]["DeviceID"].ToString() + "' and StartDate='" + a.RRAStartDate.ToString("yyyy-MM-dd HH:mm:ss") + "' and EndDate='" + a.RRAEndDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";

                    LockManager manager = new LockManager();
                    DataTable   dt1     = MySQLHelper.ExecuteDataset(MySQLHelper.SqlConnString, MySQLHelper.CreateCommand(sql)).Tables[0];
                    foreach (DataRow row in dt1.Rows)
                    {
                        string returnStr = manager.UpdatePassengerInfoToDevice(dt.Rows[0]["DeviceID"].ToString(), row["ICCard"].ToString(), "", "", "", a.RRAStartDate.ToString("yyyyMMddHHmm").Substring(2, 10), a.RRAEndDate.ToString("yyyyMMddHHmm").Substring(2, 10), "2");
                    }

                    returnStr1 = manager.UpdatePassengerInfoToDevice(dt.Rows[0]["DeviceID"].ToString(), "", "", "", a.RRANationName, a.RRAStartDate.ToString("yyyyMMddHHmm").Substring(2, 10), a.RRAEndDate.ToString("yyyyMMddHHmm").Substring(2, 10), "4");
                }

                dic.Add("ret", "0");
                dic.Add("msg", returnStr1);
            }
            else
            {
                dic.Add("ret", "1");
                dic.Add("msg", "未发现智能锁信息,无法添加密码");
            }
            return(JSONHelper.ToJson(dic));
        }