码迷,mamicode.com
首页 > 其他好文 > 详细

erp的核心代码,替代orm

时间:2018-07-31 11:04:25      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:let   .property   ++   rop   ==   ati   erp   string   sel   

        public static SqlParameter[] get_array_list<T>(ArrayList rows) where T : class
        {
            Hashtable sql_add = new Hashtable();
            Hashtable sql_update = new Hashtable();
            Hashtable sql_delete = new Hashtable();


            string zsql = "";
           
            int ka = 0, ku = 0, kd = 0;
            foreach (Hashtable row in rows)
            {

                zsql += " select ";

                PropertyInfo[] properties = typeof(T).GetProperties();
                foreach (PropertyInfo p in properties)
                {
             
                    if (row[p.Name] != null)
                    {
                        string zdel_c = Get_Deli(p.PropertyType, row[p.Name].ToString());
                        zsql += zdel_c + Get_Value(p.PropertyType, row[p.Name].ToString()) + zdel_c + " as [" + p.Name + "] " + ",";
                    }
                    else
                    {

                        zsql += Get_Default_Value(p.PropertyType) + " as [" + p.Name + "] " + ",";
                    }

                }
                zsql = zsql.Substring(0, zsql.Length - 1);
                String state = row["_state"] != null ? row["_state"].ToString() : "";
                if (state == "added")
                {
                    sql_add[ka.ToString()] = zsql;
                    ka++;
                }
                if (state == "modified")
                {
                    sql_update[ku.ToString()] = zsql;
                    ku++;
                }

                if (state == "removed" || state == "deleted")
                {
                    sql_delete[kd.ToString()] = zsql;
                    kd++;
                }
                zsql = "";
            }


            SqlParameter[] result = {
                    new SqlParameter("@username" , SqlDbType.NText),
                    new SqlParameter(string.Format("@e{0}_add_array" ,typeof(T).Name), SqlDbType.NText),
                    new SqlParameter(string.Format("@e{0}_update_array" ,typeof(T).Name), SqlDbType.NText),                  
                    new SqlParameter(string.Format("@e{0}_delete_array" ,typeof(T).Name), SqlDbType.NText)
                    };

            zsql = "";
            for (int k = 0; k < sql_add.Count; k++)
            {
                zsql += sql_add[k.ToString()].ToString();
                if (k < sql_add.Count - 1) zsql += "\n union all \n";
            }
            result[1].Value = zsql;

            zsql = "";
            for (int k = 0; k < sql_update.Count; k++)
            {
                zsql += sql_update[k.ToString()].ToString();
                if (k < sql_update.Count - 1) zsql += "\n union all \n";
            }
            result[2].Value = zsql;

            zsql = "";
            for (int k = 0; k < sql_delete.Count; k++)
            {
                zsql += sql_delete[k.ToString()].ToString();
                if (k < sql_delete.Count - 1) zsql += "\n union all \n";
            }
            result[3].Value = zsql;

            return result;

        }

  

erp的核心代码,替代orm

标签:let   .property   ++   rop   ==   ati   erp   string   sel   

原文地址:https://www.cnblogs.com/coolyylu/p/9393962.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!