Example #1
0
        //保存表信息
        public void SaveTables()
        {
            NameValueCollection Params = HttpContext.Request.Form;//参数
            Tables tables = new Tables();

            tables.Author       = User.Identity.Name;
            tables.DatabaseCode = new Guid(Params["databaseCode"]);
            tables.GroupCode    = new Guid(Params["groupCode"]);
            tables.Name         = Params["name"];
            tables.Alias        = Params["alias"];
            string result = string.Empty;

            if (Params["code"] != null)
            {
                tables.Code = new Guid(Params["code"]);
                result      = DTables.Update(tables) != null ? "{HasError:false,msg:'表编辑成功!'}" : "{HasError:true,msg:'表编辑失败,请稍候再试!'}";
            }
            else
            {
                tables.Code = Guid.NewGuid();
                result      = DTables.Add(tables) != null ? "{HasError:false,msg:'表创建成功!'}" : "{HasError:true,msg:'表创建失败,请稍候再试!'}";
            }
            Response.Write(result);
            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();
        }