Esempio n. 1
0
 public ServerNode(ServerInfo dbs)
 {
     NodeType = NodeType.Server;
     Server = dbs;
     this.IsConnected = false;
     this.Text = dbs.ToString();
     this.ImageIndex = DataConvert.GetInt32(IconType.Server);
     this.SelectedImageIndex = DataConvert.GetInt32(IconType.Server);
 }
Esempio n. 2
0
 private static bool IsExistServerNode(XmlDocument xmldoc, ServerInfo server)
 {
     XmlNode objRootNode = xmldoc.SelectSingleNode(Constants.NODE_ROOT + Constants.CHAR_SLASH + Constants.NODE_SERVERS);
     foreach (XmlNode xn in objRootNode.ChildNodes)
     {
         if (xn.ChildNodes[0].InnerText == server.DatabaseType &&
             xn.ChildNodes[1].InnerText == server.ServerName &&
             xn.ChildNodes[2].InnerText == server.ConnectionString &&
             xn.ChildNodes[3].InnerText == server.DatabaseName)
         {
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
        //private static void EditAccountNode(XmlDocument xmldoc, string email, ServerInfo server)
        //{
        //    XmlNode objRootNode = xmldoc.SelectSingleNode(DatabaseConstants.NODE_ROOT + DatabaseConstants.CHAR_SLASH + DatabaseConstants.NODE_SERVERS);
        //    foreach (XmlNode xn in objRootNode.ChildNodes)
        //    {
        //        if (xn.ChildNodes[0].InnerText == email)
        //        {
        //            xn.ChildNodes[0].InnerText = user.Email;
        //            xn.ChildNodes[1].InnerText = user.Password;
        //            xn.ChildNodes[2].InnerText = user.UserName;
        //            xn.ChildNodes[3].InnerText = user.UserId;
        //            break;
        //        }
        //    }
        //}

        private static void DeleteServerNode(XmlDocument xmldoc, ServerInfo server)
        {
            XmlNode objRootNode = xmldoc.SelectSingleNode(Constants.NODE_ROOT + Constants.CHAR_SLASH + Constants.NODE_SERVERS);
            foreach (XmlNode xn in objRootNode.ChildNodes)
            {
                if (xn.ChildNodes[0].InnerText == server.DatabaseType &&
                    xn.ChildNodes[1].InnerText == server.ServerName &&
                    xn.ChildNodes[2].InnerText == server.ConnectionString &&
                    xn.ChildNodes[3].InnerText == server.DatabaseName)
                {
                    objRootNode.RemoveChild(xn);
                    break;
                }
            }
        }
Esempio n. 4
0
        private static void InsertAccounNode(XmlDocument xmldoc, ServerInfo server)
        {

            XmlNode objRootNode = xmldoc.SelectSingleNode(Constants.NODE_ROOT + Constants.CHAR_SLASH + Constants.NODE_SERVERS);
            XmlElement objChildNode = xmldoc.CreateElement(Constants.NODE_DBSERVER);
            objRootNode.AppendChild(objChildNode);
            XmlElement emtType = xmldoc.CreateElement(Constants.DB_DATABASETYPE);
            emtType.InnerText = server.DatabaseType;
            XmlElement emtServerName = xmldoc.CreateElement(Constants.DB_SERVERNAME);
            emtServerName.InnerText = server.ServerName;
            XmlElement emtConnectionString = xmldoc.CreateElement(Constants.DB_CONNECTIONSTRING);
            emtConnectionString.InnerText = server.ConnectionString;
            XmlElement emtDatabaseName = xmldoc.CreateElement(Constants.DB_DATABASENAME);
            emtDatabaseName.InnerText = server.DatabaseName;
            objChildNode.AppendChild(emtType);
            objChildNode.AppendChild(emtServerName);
            objChildNode.AppendChild(emtConnectionString);
            objChildNode.AppendChild(emtDatabaseName);
        }
Esempio n. 5
0
        public static string DeleteServer(ServerInfo server)
        {
            try
            {
                XmlDocument objXmlDoc = GetCGConfigFile();
                if (objXmlDoc == null)
                    return "Config file doesn't exist!";

                DeleteServerNode(objXmlDoc, server);

                string configFile = Path.Combine(Application.StartupPath, Constants.FILE_CGCONFIG);

                objXmlDoc.Save(configFile);

                return "Ok";
            }
            catch
            {
                return "Fail";
            }
        }
Esempio n. 6
0
        public static string EditServer(ServerInfo server)
        {
            try
            {
                XmlDocument objXmlDoc = GetCGConfigFile();
                if (objXmlDoc == null)
                    return "Config file doesn't exist!";

                if (IsExistServerNode(objXmlDoc, server))
                    return "The server has already existed!";
                else
                    InsertAccounNode(objXmlDoc, server);

                string configFile = Path.Combine(Application.StartupPath, Constants.FILE_CGCONFIG);

                objXmlDoc.Save(configFile);

                return Constants.STATUS_SUCCESS;
            }
            catch
            {
                return Constants.STATUS_FAIL;
            }
        }
Esempio n. 7
0
        public static Collection<ServerInfo> GetServers()
        {
            try
            {
                XmlDocument objXmlDoc = GetCGConfigFile();
                if (objXmlDoc == null)
                    return null;

                DataView dv = GetData(objXmlDoc, Constants.NODE_ROOT + Constants.CHAR_SLASH + Constants.NODE_SERVERS);

                Collection<ServerInfo> servers = new Collection<ServerInfo>();

                for (int ix = 0; ix < dv.Table.Rows.Count; ix++)
                {
                    ServerInfo server = new ServerInfo();
                    server.DatabaseType = dv.Table.Rows[ix][0].ToString();
                    server.ServerName = dv.Table.Rows[ix][1].ToString();
                    server.ConnectionString = dv.Table.Rows[ix][2].ToString();
                    server.DatabaseName = dv.Table.Rows[ix][3].ToString();
                    servers.Add(server);
                }

                return servers;
            }
            catch
            {
                return null;
            }
        }
Esempio n. 8
0
        private void OnDeleteClick(object o, EventArgs e)
        {
            if (MessageBox.Show("Are you sure?","Confirm",MessageBoxButtons.OKCancel,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button2)== DialogResult.OK)
            {
                ServerNode sn = (ServerNode)this.SelectedNode;
                ServerInfo dbServer = new ServerInfo();
                dbServer = sn.Server;
                if (dbServer != null)
                {
                    string ret = ConfigCtrl.DeleteServer(dbServer);
                    if (ret != CGConstants.STATUS_SUCCESS)
                    {
                        MessageBox.Show(ret, CGConstants.MSG_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    BaseNode bn = (BaseNode)sn.Parent;
                    bn.Nodes.Remove(sn);
                }
            }
        }
Esempio n. 9
0
 public DlgAddSqlServer()
 {
     NewSqlServer = new ServerInfo();
     InitializeComponent();
 }
Esempio n. 10
0
 public static Collection<DatabaseInfo> GetDataBases(ServerInfo server)
 {
     return GetDataBases(server.ConnectionString, server.ServerName, server.DatabaseName);
 }