点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 企业网站>> MVC通用企业门户网站源码>> 源文件浏览
[商业版 299金币] WebForm,下载次数:32 次 | 关键字: mvc easyui 门户网站

源码截图

源码目录树

当前路径:PD.Access/Server.cs     using System;
using System.Text;
using System.Reflection;
using System.Data;
using System.Collections.Generic;

namespace PD.Access
{
    public class Server
    {
        public string modelName = string.Empty;
        public string primaryKey = string.Empty;

        public Server(string modelname, string primarykey)
        {
            this.modelName = modelname;
            this.primaryKey = primarykey;
        }

        public int ObjectInsert(object model)
        {
            Type modeltype = model.GetType();
            StringBuilder sb = new StringBuilder();

            sb.Append("insert into [" + modeltype.Name + "] (");

            string fields = string.Empty;
            string values = string.Empty;

            foreach (PropertyInfo pi in modeltype.GetProperties())
            {
                object value = pi.GetValue(model, null);
                if (pi.Name.Equals("status") || pi.Name.Equals("errmsg"))
                {
                    break;
                }

                try
                {
                    Type valuetype = value.GetType();

                    fields += "[" + pi.Name + "],";

                    if (valuetype == typeof(int))
                    {
                        values += value.ToString() + ",";
                    }
                    else if (valuetype == typeof(string))
                    {
                        values += "'" + value.ToString() + "',";
                    }
                    else if (valuetype == typeof(decimal))
                    {
                        values += value.ToString() + ",";
                    }
                    else if (valuetype == typeof(bool))
                    {
                        values += "'" + (Convert.ToBoolean(value) ? "1" : "0") + "',";
                    }
                    else if (valuetype == typeof(DateTime))
                    {
                        values += "'" + Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm:ss") + "',";
                    }
                    else if (valuetype == typeof(Guid))
                    {
                        values += "cast('" + value.ToString() + "' as uniqueidentifier ),";
                    }
                }
                catch { continue; }
            }

            sb.Append(fields.TrimEnd(','));
            sb.Append(") values (");
            sb.Append(values.TrimEnd(','));
            sb.Append(")");

            return Access.ExecuteNonQuery(sb.ToString());
        }

        public int ObjectUpdate(object model)
        {
            Type modeltype = model.GetType();
            StringBuilder sb = new StringBuilder();
            sb.Append("update [" + modeltype.Name + "] set ");

            string values = string.Empty;
            string where = string.Empty;

            foreach (PropertyInfo pi in modeltype.GetProperties())
            {
                object value = pi.GetValue(model, null);

                if (pi.Name.Equals("status") || pi.Name.Equals("errmsg"))
                {
                    break;
                }

                try
                {
                    Type valuetype = value.GetType();

                    if (pi.Name.ToLower() == primaryKey.ToLower())
                    {
                        where = "[" + pi.Name + "] = '" + value.ToString() + "'";
                    }
                    else
                    {
                        if (valuetype == typeof(int) && value != null)
                        {
                            values += "[" + pi.Name + "] = " + value.ToString() + ",";
                        }
                        else if (valuetype == typeof(string) && value != null)
                        {
                            values += "[" + pi.Name + "] = '" + value.ToString() + "',";
                        }
                        else if (valuetype == typeof(bool) && value != null)
                        {
                            values += "[" + pi.Name + "] = '" + (Convert.ToBoolean(value) ? "1" : "0") + "',";
                        }
                        else if (valuetype == typeof(decimal) && value != null)
                        {
                            values += "[" + pi.Name + "] = " + Convert.T...
对不起,完整源码文件,请先购买后再查看
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:2852517674
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
分享该页面
关闭侧边栏