Exemple #1
0
        void referTables(object id)
        {
            if (m_sysTable == null || m_sysTable.refer == null)
            {
                return;
            }

            var key        = m_table + "_" + ID;
            var sqlSetDict = new Dictionary <string, string>();

            sqlSetDict.Add(key, null);

            var tableList = YoConvert.ToList(m_sysTable.refer);

            foreach (var table in tableList)
            {
                var refer = new YoCacheRefer(table, m_act);

                if (!refer.CheckDisplayChange(sqlSetDict))
                {
                    continue;
                }
                refer.referRows(key, id);
            }
        }
Exemple #2
0
        bool ui2db(ref object value, sys_column yoColumn)
        {
            var result = true;

            switch (yoColumn.datatype)
            {
            case DataType.ID:
            case DataType.Refer:
                result = YoConvert.ToInt(ref value);
                break;

            case DataType.Number:
            case DataType.Calc:
                result = YoConvert.ToDouble(ref value);
                break;

            case DataType.Text:
            case DataType.Set:
                result = YoConvert.ToString(ref value);
                break;

            case DataType.Datetime:
                result = YoConvert.ToDatetime(ref value);
                break;
            }
            return(result);
        }
Exemple #3
0
        public YoSelect Limit(JObject obj)
        {
            while (true)
            {
                if (obj == null)
                {
                    break;
                }

                object v1 = obj[k1];
                if (v1 == null || !YoConvert.ToInt(ref v1))
                {
                    break;
                }

                object v2 = obj[k2];
                if (v2 != null)
                {
                    if (!YoConvert.ToInt(ref v2))
                    {
                        v2 = null;
                    }
                }

                var temp = v2 != null ? ", " : null;

                m_limit = string.Format(" LIMIT {0}{1}{2} ", v1, temp, v2);
                break;
            }
            return(this);
        }
Exemple #4
0
 public bool VerifyChange(int uid, string password, string passwordNew)
 {
     return(Change(uid, passwordNew, passwordDb => {
         password = YoConvert.ToMD5(password);
         return password == passwordDb;
     }));
 }
Exemple #5
0
        void init()
        {
            if (m_sysTable.title != null)
            {
                m_titleFields          = YoConvert.ToList(m_sysTable.title);
                m_sysTable.translation = ConfigHelper.Translate(m_sysTable.table_name, m_trans);
            }

            var yoColumnList = (new ColumnModel()).GetList(m_sysTable.id);

            m_yoColumnDict = YoConvert.List2Dict(yoColumnList, column_name, yoColumn => {
                if (yoColumn.set != null)
                {
                    var setList      = YoConvert.ToList(yoColumn.set);
                    yoColumn.setDict = new Dictionary <string, string>();
                    foreach (var setKey in setList)
                    {
                        var setValue = ConfigHelper.Translate(setKey, m_trans);
                        yoColumn.setDict.Add(setKey, setValue);
                    }
                }
                yoColumn.translation = ConfigHelper.Translate(yoColumn.column_name, m_trans);
                return(yoColumn);
            });
        }
Exemple #6
0
        string getWhere(string key, JObject obj)
        {
            string result = null;

            while (true)
            {
                if (string.IsNullOrEmpty(key))
                {
                    break;
                }

                if (!m_yoColumnDict.ContainsKey(key))
                {
                    break;
                }

                if (obj == null)
                {
                    break;
                }

                object v1 = obj[k1];
                object v2 = obj[k2];
                switch (m_yoColumnDict[key].datatype)
                {
                case DataType.ID:
                case DataType.Refer:
                case DataType.Number:
                case DataType.Calc: {
                    if (v1 != null && YoConvert.ToDouble(ref v1))
                    {
                        result += string.Format(" `{0}` >= {1} ", key, v1);
                    }

                    if (v2 != null && YoConvert.ToDouble(ref v2))
                    {
                        if (result != null)
                        {
                            result += "AND";
                        }
                        result += string.Format(" `{0}` <= {1} ", key, v2);
                    }
                }
                break;

                default: {
                    if (v1 != null && YoConvert.ToString(ref v1))
                    {
                        result += string.Format(" `{0}` like '%{1}%' ", key, v1);
                    }
                }
                break;
                }

                break;
            }
            return(result);
        }
Exemple #7
0
 public bool Add(sys_user row)
 {
     if (!check(row))
     {
         return(false);
     }
     row.password = YoConvert.ToMD5(row.password);
     return(AddRow(row));
 }
Exemple #8
0
 public bool ChangePassword(sys_user row, string passwordNew)
 {
     row.password = passwordNew;
     if (!check(row))
     {
         return(false);
     }
     row.password = YoConvert.ToMD5(row.password);
     return(ModifyRow(row));
 }
Exemple #9
0
        public bool Register(Dictionary <string, object> dict, string code)
        {
            if (DateTime.Now.Day.ToString() != code)
            {
                return(false);
            }

            var user = YoConvert.Dict2Class <sys_user>(dict);

            return(m_userModel.Add(user));
        }
Exemple #10
0
        public int GetCount()
        {
            var result = 0;
            var sql    = string.Format("SELECT COUNT(1) FROM `{0}` {1}", m_table, m_where);
            var obj    = getFirst(sql);

            if (YoConvert.ToInt(ref obj))
            {
                result = (int)obj;
            }
            return(result);
        }
Exemple #11
0
        public bool Login(string uname, string password)
        {
            bool result = false;

            while (true)
            {
                // get user
                object obj = uname;
                if (YoConvert.ToInt(ref obj))
                {
                    m_userModel.FindMobile(uname);
                }
                else
                {
                    m_userModel.FindUname(uname);
                }

                var user = m_userModel.Row;
                if (user == null)
                {
                    m_errorDict[SYS] = "no user";
                    break;
                }

                password = YoConvert.ToMD5(password);
                if (user.password != password)
                {
                    m_errorDict[SYS] = "wrong password";
                    break;
                }

                // get token
                if (m_tokenModel.FindUid(user.id))
                {
                    result = m_tokenModel.Update(m_tokenModel.Row);
                    break;
                }

                var token = new sys_token();
                token.ticket = YoConvert.ToMD5(user.id + "_" + DateTime.Now);
                token.uid    = user.id;
                result       = m_tokenModel.Add(token);

                break;
            }
            return(result);
        }
Exemple #12
0
        bool checkUptime()
        {
            bool result = false;

            while (true)
            {
                if (!m_yoColumnDict.ContainsKey(UPTIME))
                {
                    result = true;
                    break;
                }

                // ui uptime
                if (!m_uiDict.ContainsKey(UPTIME))
                {
                    break;
                }

                object uiUptime = m_uiDict[UPTIME];
                if (!YoConvert.ToDatetime(ref uiUptime))
                {
                    break;
                }

                // db uptime
                var uptime = m_dataRow[UPTIME];
                if (!YoConvert.ToDatetime(ref uptime))
                {
                    break;
                }

                if ((DateTime)uptime != (DateTime)uiUptime)
                {
                    break;
                }

                result = true;
                break;
            }
            return(result);
        }
Exemple #13
0
        object db2ui(object value, sys_column yoColumn)
        {
            object result = value;

            switch (yoColumn.datatype)
            {
            case DataType.Number:
            case DataType.Calc: {
                object format = yoColumn.format;
                if (format != null && YoConvert.ToInt(ref format))
                {
                    result = string.Format("{0:F" + format + "}", value);
                }
            }
            break;

            case DataType.Datetime:
                if (yoColumn.format != null && YoConvert.ToDatetime(ref value))
                {
                    result = ((DateTime)value).ToShortDateString();
                }
                break;

            case DataType.Set:
                if (value != null && yoColumn.setDict != null)
                {
                    var setKey = value.ToString();
                    if (yoColumn.setDict.ContainsKey(setKey))
                    {
                        result = yoColumn.setDict[setKey];
                    }
                }
                break;
            }
            return(result);
        }