示例#1
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);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
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);
        }
示例#5
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);
        }