コード例 #1
0
        public ActionResult SaveDatabase(string connectionName, string hostNameOrIp, string serverUserName, string userPassword, string databaseName, string tableName, DBServerProvider databaseProvider) //FormCollection form
        {
            string message = Message.Message_OK;

            ServerConnectVariable _serverConnectVar = new ServerConnectVariable();

            _serverConnectVar.ConnectionName   = connectionName;
            _serverConnectVar.HostNameOrIP     = hostNameOrIp;
            _serverConnectVar.ServerUserName   = serverUserName;
            _serverConnectVar.UserPassword     = userPassword;
            _serverConnectVar.DatabaseName     = databaseName;
            _serverConnectVar.TableName        = tableName;
            _serverConnectVar.DatabaseProvider = databaseProvider.ToString();

            //_serverConnectVar.ConnectionName = form["ConnectionName"].ToString();
            //_serverConnectVar.HostNameOrIP = form["HostNameOrIP"].ToString();
            //_serverConnectVar.DataBaseUser = form["DataBaseUser"].ToString();
            //_serverConnectVar.UserPassword = form["UserPassword"].ToString();

            try
            {
                IServerConnect _sqlServerInterface = new SqlServerConnect(
                    _serverConnectVar.HostNameOrIP,
                    _serverConnectVar.ServerUserName,
                    _serverConnectVar.UserPassword,
                    _serverConnectVar.DatabaseName,
                    _serverConnectVar.TableName
                    );

                List <Field> getFiledList = _sqlServerInterface.GetSingleTableFieldList();

                EM_ServerConnect obj = new EM_ServerConnect(
                    _serverConnectVar.ConnectionName,
                    _serverConnectVar.HostNameOrIP,
                    _serverConnectVar.ServerUserName,
                    _serverConnectVar.UserPassword,
                    _serverConnectVar.DatabaseName,
                    _serverConnectVar.TableName,
                    _serverConnectVar.DatabaseProvider);


                IRepository <EM_ServerConnect, int> newRepo = new Repository <EM_ServerConnect, SqlDbContext, int>(new SqlDbContext());
                var result = newRepo.Create(obj);
                //db.EM_ServerConnect.Add(obj);
                //db.SaveChanges();
                message = Message.Message_OK;

                return(Json(new { TableFieldList = getFiledList, ServerInfo = _serverConnectVar, message }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }

            return(Json(new { ServerInfo = _serverConnectVar, message }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
 /*The Out parameter is used when a method returns multiple values.
  * When a parameter passes with the Out keyword/parameter in the method,
  * then that method works with the same variable value that is passed in the method call.
  */
 private void getSqlSingleTableFieldList(out List <Field> getFiledList, out string message)
 {
     getFiledList = null;
     message      = null;
     try
     {
         IServerConnect _sqlServerInterface = new SqlServerConnect(_hostName, _userName, _password, _databaseName, _tableName);
         getFiledList = _sqlServerInterface.GetSingleTableFieldList();
         message      = Message.Message_OK;
     }
     catch (Exception ex) {
         message = ex.Message;
     }
 }