zoukankan      html  css  js  c++  java
  • erp的核心代码,替代orm

            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 += "
     union all 
    ";
                }
                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 += "
     union all 
    ";
                }
                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 += "
     union all 
    ";
                }
                result[3].Value = zsql;
    
                return result;
    
            }
    

      

  • 相关阅读:
    时间管理的心理建设与优先矩阵
    在oracle中计算时间差
    android环境搭建
    有效沟通的六个步骤
    5招教你把握Java性能监控(转自51testing)
    选项卡TabHost
    Excel导入导出数据库02
    画廊视图Gallery
    拖动条SeekBar及星级评分条
    在应用程序级别之外使用注册为allowDefinition='MachineToApplication' 的节是错误的
  • 原文地址:https://www.cnblogs.com/coolyylu/p/9393962.html
Copyright © 2011-2022 走看看