using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConnectionSrt
{
    public class Operation
    {
        public static void Generate(string ip,string port,string dbName,string username,string password,string keyName)
        {
            var connectionString= @"Data Source ="+ ip+ ","+ port+ ";Network Library =" + dbName + ";User ID=" + username + ";Password=" + password;
            RegistryKey key = Registry.CurrentUser.CreateSubKey("software\\"+ keyName);
            key.SetValue("ConnectionString", connectionString);
            key.Close();
        }


        public static string CallConnection(string keyName)
        {
            string connection = string.Empty;
            RegistryKey key = Registry.CurrentUser.CreateSubKey("software\\"+ keyName);
            object isValue = key.GetValue("ConnectionString");
            if (isValue == null)
            {        
                return connection;
            }
            else
            {
                return  key.GetValue("ConnectionString").ToString();
            }
        }
}
}
