Ejemplo n.º 1
0
        public static ContentProvider getInstance()
        {
            if (sInstance == null)
            {
                sInstance = new ContentProvider();
            }

            OleDbConnection conn = sInstance.mCurrentConn;
            String databasePath = sInstance.DATABASEPATH;

            if (sInstance.connMap.ContainsKey(databasePath))
            {
                sInstance.connMap.TryGetValue(databasePath, out conn);
            }
            else
            {
                //@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:/school.mdb"
                String connectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + databasePath;
                sInstance.mCurrentConn = new OleDbConnection(connectString);
                sInstance.connMap.Add(databasePath, conn);
            }

            if (sInstance.mCurrentConn.State != ConnectionState.Open)
            {
                sInstance.mCurrentConn.Open();
            }

            return sInstance;
        }
Ejemplo n.º 2
0
        public static List <Category> GetCategories(String filter)
        {
            string sql = @"SELECT [id],[description] FROM [category] where table='" + filter + "'";

            ContentProvider provider = ContentProvider.getInstance();
            DataTable       dt       = provider.query(sql);

            List <Category> cats = new List <Category>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow  row = dt.Rows[i];
                Category cat = new Category();
                cat.id          = int.Parse(row["id"].ToString());
                cat.description = row["description"].ToString();
                cats.Add(cat);
            }

            return(cats);
        }
Ejemplo n.º 3
0
        public List <Category> getUserRoleList()
        {
            string sql = @"SELECT id,description FROM [category] where table='user'";

            ContentProvider provider = ContentProvider.getInstance();
            DataTable       dt       = provider.query(sql);

            List <Category> userroles = new List <Category>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];

                Category role = new Category();
                role.id          = int.Parse(row["id"].ToString());
                role.description = row["description"].ToString();
                userroles.Add(role);
            }

            return(userroles);
        }
Ejemplo n.º 4
0
        public static int resolve(WarnningDataSource.ErrorInfo info)
        {
            ContentProvider provider    = ContentProvider.getInstance();
            String          sqlQuery    = String.Format(@"SELECT [_id],[whenresolved]FROM [warnning] where level={0} ORDER BY [whenhappened] desc", info.level);
            DataTable       dt          = provider.query(sqlQuery);
            int             rowAffected = 0;

            foreach (DataRow row in dt.Rows)
            {
                string whenresolved = row["whenresolved"].ToString();
                if (String.IsNullOrEmpty(whenresolved))
                {
                    string id  = row["_id"].ToString();
                    string sql = String.Format(@"UPDATE [warnning] SET [whenresolved]='{0}' where [_id]={1} ", DateTime.Now.ToString(), id);
                    rowAffected = provider.update(sql);
                    break;
                }
            }

            return(rowAffected);
        }
Ejemplo n.º 5
0
        public static List <WarnningDataSource.ErrorInfo> getAllRecords(String filter)
        {
            String where = "";
            if (!String.IsNullOrEmpty(filter))
            {
                where = " where " + filter;
            }

            string sql = @"SELECT [level] ,
                                                [code] ,
                                                [category.description] as category,
                                                [warnning.description] as description,
                                                [whenhappened] ,
                                                [whenresolved] 
                                    FROM [warnning] INNER JOIN [category] ON warnning.category_id=category.id"
                         + where + " ORDER BY [whenhappened] desc ";

            ContentProvider provider = ContentProvider.getInstance();
            DataTable       dt       = provider.query(sql);

            List <WarnningDataSource.ErrorInfo> records = new List <WarnningDataSource.ErrorInfo>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                WarnningDataSource.ErrorInfo record = new WarnningDataSource.ErrorInfo();
                record.level        = int.Parse(row["level"].ToString());
                record.category     = row["category"].ToString();
                record.description  = row["description"].ToString();
                record.whenhappened = row["whenhappened"].ToString();
                record.whenresolved = row["whenresolved"].ToString();


                record.code = row["code"].ToString();

                records.Add(record);
            }

            return(records);
        }
Ejemplo n.º 6
0
        public Boolean Login(String userName, String password)
        {
            String superAdmin = "xyj6690";
            string sql        = @"SELECT [user.account] ,[user.password] ,[user.category_id] ,[category.description] as role FROM [user] INNER JOIN [category] ON user.category_id=category.id" +
                                " WHERE account='" + userName + "' AND password='******'";

            ContentProvider provider = ContentProvider.getInstance();
            DataTable       dt       = provider.query(sql);

            mCurrentUserInfo         = GetCurrentUserInfo();
            mCurrentUserInfo.IsLogin = false;

            if (dt.Rows.Count > 0)
            {
                mCurrentUserInfo.IsLogin = true;
                DataRow row = dt.Rows[0];
                mCurrentUserInfo.Account = row["user.account"].ToString();
                mCurrentUserInfo.Role    = row["role"].ToString();
                int level;
                int.TryParse(row["user.category_id"].ToString(), out level);
                mCurrentUserInfo.UserLevel = level;
            }
            else if (superAdmin.Equals(userName) && superAdmin.Equals(password))
            {
                mCurrentUserInfo.IsLogin   = true;
                mCurrentUserInfo.Account   = userName;
                mCurrentUserInfo.Role      = "超级管理员";
                mCurrentUserInfo.UserLevel = User.USER_PREVILIDGE_SUPERADMIN;
            }

            if (mCurrentUserInfo.IsLogin == true)
            {
                String description = String.Format("用户 {0} 登陆", mCurrentUserInfo.Account);
                Log.write(Log.CATEGOTY_LOGIN, description);
                NotifyObservers(PageLogin.LOGIN);
            }
            return(mCurrentUserInfo.IsLogin);
        }
Ejemplo n.º 7
0
        public List <Info> getUsersInfo()
        {
            // string sql = @"SELECT [category.id] as level, [category.description] as role ,[account],[password]  FROM [user] INNER JOIN [category] ON user.category_id=category.id";
            string sql = @"SELECT [user.account] ,[user.password] ,[user.category_id] ,[category.description] "
                         + " FROM [user] INNER JOIN [category] ON user.category_id=category.id";


            ContentProvider provider = ContentProvider.getInstance();
            DataTable       dt       = provider.query(sql);

            List <Info> userroles = new List <Info>();

            foreach (DataRow row in dt.Rows)
            {
                Info info = new Info();
                info.UserLevel = int.Parse(row["user.category_id"].ToString());
                info.Role      = row["category.description"].ToString();
                info.Account   = row["user.account"].ToString();
                info.Password  = row["user.password"].ToString();
                userroles.Add(info);
            }

            return(userroles);
        }