Example #1
0
    public static List <Menu> GetMenu()
    {
        try
        {
            using (QPCHARTEntities sce = new QPCHARTEntities())
            {
                string Sql = @"select* from Menu";

                List <Menu> list   = sce.Database.SqlQuery <Menu>(Sql).ToList();
                List <Menu> result = new List <Menu>();
                int         i;
                int         bengNum = 0;

                foreach (var item in list)
                {
                    if (item.pId == 0)
                    {
                        bengNum++;
                        result.Add(item);
                        continue;
                    }

                    //Sql = @"select Val from " + item.name + "where Val<>0";
                    for (i = 0; i < 13; i++)
                    {
                        Menu itemChid = new Menu();

                        itemChid = item.CloneJson <Menu>();
                        //itemChid.name += i.ToString();
                        //itemChid.id += 1;
                        itemChid.pId = i + 1;
                        result.Add(itemChid);
                    }
                    //if (sce.Database.SqlQuery<double>(Sql).ToList().Count != 0)
                    //{
                    //    result.Add(item);
                    //}
                }

                return(result);
                //return sce.Database.SqlQuery<Menu>(Sql).ToList();
                //return sce.Menu.ToList();
            }
        }
        catch (Exception ex)
        {
            return(null);
        }
    }
Example #2
0
    /**
     * 该类主要处理web页面通过ajax请求
     **/
    #endregion

    /// <summary>
    /// 根据表名获取数据
    /// </summary>
    /// <param name="tb"></param>
    /// <returns></returns>

    public void GetData()
    {
        try
        {
            using (QPCHARTEntities sce = new QPCHARTEntities())
            {
                string Sql = "select top(1) * from dbo.value order by [DateTime] desc";
                List <TestStructure> result = sce.Database.SqlQuery <TestStructure>(Sql).ToList();
                object JSONObj = (Object)JsonConvert.SerializeObject(result);
                Response.Write(JSONObj);
                //  一定要加,不然前端接收失败
                Response.End();
            }
        }
        catch (Exception ex)
        {
        }
    }
Example #3
0
 public static string DelAnn(string _DateTime, string tb)
 {
     try
     {
         using (QPCHARTEntities sce = new QPCHARTEntities())
         {
             string Sql = @"update  " + tb + " set Ann = NULL where DateTime = @p2";
             return(sce.Database.ExecuteSqlCommand(Sql,
                                                   new SqlParameter {
                 ParameterName = "p2", Value = DateTime.Parse(_DateTime)
             }) > 0 ? "Success" : "");
         }
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
Example #4
0
    public static List <SysUser> autoLogin()
    {
        List <SysUser> user = null;

        if (loginValidation())//如果已经登录
        {
            string[] currUserInfo = SessionHelper.Gets("CurrLoginUser");
            string   userName     = currUserInfo[0];
            string   password     = currUserInfo[1];
            try
            {
                using (QPCHARTEntities sce = new QPCHARTEntities())
                {
                    string Sql = @"select * from SysUser where YongHu=@p1 and MiMa=@p2";
                    user = sce.Database.SqlQuery <SysUser>(Sql,
                                                           new SqlParameter {
                        ParameterName = "p1", Value = userName
                    },
                                                           new SqlParameter {
                        ParameterName = "p2", Value = password
                    }).ToList();
                }
                if (user.Count <= 0)
                {
                    return(null);
                }

                /*
                 * 写入session
                 * 生命周期为10分钟
                 * */
                string[] userInfo = { user[0].YongHu, user[0].MiMa, user[0].Level.ToString() };
                SessionHelper.Del("CurrLoginUser");
                SessionHelper.Adds("CurrLoginUser", userInfo, 10);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        return(user);
    }
Example #5
0
    public static List <SysUser> login(string userName, string password)
    {
        List <SysUser> user = null;

        password = md5Encode(password);
        userName = userName.Trim();
        try
        {
            /**
             *@QPCHARTEntities : 与数据库链接时对应的实体名称
             * */
            using (QPCHARTEntities sce = new QPCHARTEntities())
            {
                string Sql = @"select * from SysUser where YongHu=@p1 and MiMa=@p2";
                user = sce.Database.SqlQuery <SysUser>(Sql,
                                                       new SqlParameter {
                    ParameterName = "p1", Value = userName
                },
                                                       new SqlParameter {
                    ParameterName = "p2", Value = password
                }).ToList();
            }
            if (user.Count <= 0)
            {
                return(user);
            }

            /*
             * 写入session
             * 生命周期为10分钟
             * */
            string[] userInfo = { user[0].YongHu, user[0].MiMa, user[0].Level.ToString() };
            SessionHelper.Del("CurrLoginUser");
            SessionHelper.Adds("CurrLoginUser", userInfo, 10);
        }
        catch (Exception ex)
        {
            return(null);
        }
        return(user);
    }
Example #6
0
    public static string reg(string userName, string password)
    {
        userName = userName.Trim();
        password = md5Encode(password);
        try
        {
            using (QPCHARTEntities sce = new QPCHARTEntities())
            {
                string Sql   = @"select * from SysUser where YongHu =@p1";
                int    count = sce.Database.SqlQuery <SysUser>(Sql,
                                                               new SqlParameter {
                    ParameterName = "p1", Value = userName
                }).ToList().Count();
                if (count > 0)
                {
                    return("UserExisted");
                }

                Sql = @"insert SysUser(YongHu,MiMa,Level) values('" + userName + "','" + password + "',0)";

                /*
                 * 写入session
                 * 生命周期为10分钟
                 * */
                string[] userInfo = { userName, password, "0" };
                SessionHelper.Del("CurrLoginUser");
                SessionHelper.Adds("CurrLoginUser", userInfo, 10);

                return(sce.Database.ExecuteSqlCommand(Sql) > 0 ? userName : "");
            }
        }
        catch (Exception ex)
        {
            return(null);
        }
    }