Example #1
0
        //获取需要导入的表
        public void GetImportTables()
        {
            NameValueCollection Params = HttpContext.Request.Form;//参数
            string page    = Params["page"];
            string rows    = Params["rows"];
            int    intPage = int.Parse((page == null || page == "0") ? "1" : page);
            //每页显示条数
            int pageSize = int.Parse((rows == null || rows == "0") ? "10" : rows);
            //每页的开始记录  第一页为1  第二页为number +1
            int    start      = (intPage - 1) * pageSize;
            string ServerName = Params["ServerName"];
            string ServerUser = Params["ServerUser"];
            string ServerPwd  = Params["ServerPwd"];

            ServerPwd = NHibernateHelper.DecryptAES(ServerPwd, "zhangzhangdebing"); //解密
            string    DatabaseCode = Params["DatabaseCode"];                        //数据库编码
            string    DatabaseName = Params["DatabaseName"];                        //数据库名称
            string    SearchValue  = Params["SearchValue"];                         //查询条件
            DataTable dt           = new DataTable();
            DataTable dt2          = new DataTable();
            Hashtable hasTable     = new Hashtable();

            try
            {
                //根据数据库编码,获取表名称
                string tablesName = string.Empty;
                if (DatabaseCode != null)
                {
                    tablesName = DTables.GetTablesName(new Guid(DatabaseCode));
                }
                string SqlConnection = string.Format("server={0};database={1};uid={2};pwd={3};", ServerName, DatabaseName, ServerUser, ServerPwd);
                string Sql           = "select name,crdate as createdate from sysobjects where xtype='U' and name!='sysdiagrams'";//排除sysdiagrams表
                if (!string.IsNullOrEmpty(tablesName))
                {
                    Sql += string.Format(" and name not in({0})", tablesName);
                }
                if (!string.IsNullOrEmpty(SearchValue))
                {
                    Sql += string.Format(" and name like '%{0}%'", SearchValue);
                }
                dt = SQLHelper.GetDataTable(SqlConnection, Sql);
                //拼装分页SQL
                Sql = string.Format(@"select top {1} * from ({0}) as t
                where t.name not in (select top {2} t2.name from ({0}) as t2)", Sql, pageSize, start);
                dt2 = SQLHelper.GetDataTable(SqlConnection, Sql);
                hasTable.Add("total", dt.Rows.Count);//总数据行数
                hasTable.Add("rows", dt2);
            }
            catch (Exception ex)
            {
                NHibernateHelper.WriteErrorLog("获取需要导入的表异常", ex);
                return;
            }
            Response.Write(JsonHelper.ToJson(hasTable));
            Response.End();
        }
Example #2
0
        //导入指定表到数据库
        public void ImportTables()
        {
            NameValueCollection Params = HttpContext.Request.Form;//参数

            //批量添加表信息
            string[] tables     = Params["tables"].Split(',');                      //表名称数据集
            string   ServerName = Params["ServerName"];                             //服务器名称
            string   ServerUser = Params["ServerUser"];                             //用户名
            string   ServerPwd  = Params["ServerPwd"];                              //密码

            ServerPwd = NHibernateHelper.DecryptAES(ServerPwd, "zhangzhangdebing"); //解密
            string DatabaseName = Params["DatabaseName"];                           //指定数据库名称
            string databaseCode = Params["databaseCode"];                           //数据库信息编码
            string groupCode    = Params["groupCode"];                              //功能分组编码
            bool   resultT      = false;

            try
            {
                for (int i = 0; i < tables.Length; i++)
                {
                    resultT = false;
                    string tableName = tables[i];
                    //表名是否,重复则不执行保存操作
                    if (!DTables.RepeatTablesName(tableName, databaseCode, groupCode, User.Identity.Name))
                    {
                        Tables table = new Tables();
                        table.Author       = User.Identity.Name;
                        table.DatabaseCode = new Guid(databaseCode);
                        table.GroupCode    = new Guid(groupCode);
                        table.Name         = tableName;
                        table.Alias        = tableName;
                        table.Code         = Guid.NewGuid();

                        //根据表名,获取表字段信息
                        string    SqlConnection = string.Format("server={0};database={1};uid={2};pwd={3};", ServerName, DatabaseName, ServerUser, ServerPwd);
                        DataTable dt            = DColumn.GetTableColumn(tableName, SqlConnection);
                        if (dt.Rows.Count > 0)
                        {
                            DTables.Add(table);//添加表
                            resultT = BatchAddColumn(resultT, table, dt);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NHibernateHelper.WriteErrorLog("导入指定表发生异常", ex);
                return;
            }
            Response.Write(resultT ? "{HasError:false,msg:'指定表导入成功!'}" : "{HasError:true,msg:'指定表导入失败,请稍候再试!'}");
            Response.End();
        }
Example #3
0
        //同步列字段及说明信息
        public void SynchronousColumnBewrite()
        {
            NameValueCollection Params = HttpContext.Request.Form;                  //参数
            string ServerName          = Params["ServerName"];                      //服务器名称
            string ServerUser          = Params["ServerUser"];                      //用户名
            string ServerPwd           = Params["ServerPwd"];                       //密码

            ServerPwd = NHibernateHelper.DecryptAES(ServerPwd, "zhangzhangdebing"); //解密
            string DatabaseName = Params["DatabaseName"];                           //指定数据库名称

            string[] TablesCode = Params["tablesCodes"].Split(',');                 //表编码集合
            string[] TablesName = Params["tablesNames"].Split(',');                 //表名称集合
            try
            {
                string SqlConnection = string.Format("server={0};database={1};uid={2};pwd={3};", ServerName, DatabaseName, ServerUser, ServerPwd);
                string exMsg         = string.Empty;        //异常记录
                for (int i = 0; i < TablesCode.Length; i++) //循环表编码集合
                {
                    //根据表编码,获取列字段信息(主表)
                    DataTable columnDt = DColumn.GetTableColumn(TablesName[i], SqlConnection);
                    if (columnDt.Rows.Count == 0)
                    {
                        exMsg += "主表[" + TablesName[i] + "],列字段信息为空。<br/>";
                        continue;
                    }
                    //根据表编码,获取列字段信息(副表)
                    IList <Column> columnlist = DColumn.GetColumn(new Guid(TablesCode[i]));
                    if (columnlist.Count == 0)
                    {
                        exMsg += "副表[" + TablesName[i] + "],列字段信息为空。<br/>";
                        continue;
                    }
                    //获取(副表同步主表)说明的SQL语句
                    SynchronousChief(Params, new Guid(TablesCode[i]), TablesName[i], SqlConnection, columnDt, columnlist);
                    //根据(主表同步副表)字段
                    SynchronousSide(Params, new Guid(TablesCode[i]), columnDt, columnlist);
                }
                Response.Write("{HasError:false,msg:'同步成功!<br/>" + exMsg + "'}");
            }
            catch (Exception ex)
            {
                Response.Write("{HasError:true,msg:'同步失败!<br/>异常:" + ex.Message.Replace("\r\n", "<br/>") + "'}");
            }
            Response.End();
        }