Example #1
0
        public IConnection BuildConnection(DbEnum dbType)
        {
            var dbConfig   = DbConfigService.GetInstance(dbType);
            var connString = dbConfig.CreateConfigJson();

            return(InitializeConnection(connString));
        }
Example #2
0
        public ActionResult Update(Dbconfig dbconfig)
        {
            DbConfigService dbconfigService = DbConfigService.GetInstance();

            dbconfig = dbconfigService.GetDbcongifById(dbconfig.id);
            return(View(dbconfig));
        }
Example #3
0
        public ActionResult Delete()
        {
            int             id = int.Parse(Request.QueryString["Id"].ToString());
            DbConfigService dbconfigService = DbConfigService.GetInstance();

            dbconfigService.Delete(id);
            return(RedirectToAction("Index"));
        }
Example #4
0
        public ActionResult Detail(Dbconfig dbconfig)
        {
            string          code            = Request.QueryString["id"].ToString();
            DbConfigService dbconfigService = DbConfigService.GetInstance();

            dbconfig = dbconfigService.GetDbcongifById(dbconfig.id);
            return(View(dbconfig));
        }
Example #5
0
        public ActionResult Index()
        {
            DbConfigService  dbconfigService = DbConfigService.GetInstance();
            IList <Dbconfig> dbconfigs       = dbconfigService.GetDbcongifs();

            if (dbconfigs.Count > 0)
            {
                ViewData["dbconfigsService"] = dbconfigs;
            }
            else
            {
                return(RedirectToAction("Success", "Home"));
            }
            return(View());
        }
Example #6
0
        static void Main(string[] args)
        {
            var dbConfigService = DbConfigService.GetInstance(DbEnum.File);

            // File
            Console.WriteLine("Db Info : Arquivo");
            Console.WriteLine(dbConfigService.CreateConfigJson());

            // Queue
            Console.WriteLine("Db Info : Mensageria");
            dbConfigService.DbType = DbEnum.Queue;
            Console.WriteLine(dbConfigService.CreateConfigJson());

            // Environment Variable
            Environment.SetEnvironmentVariable("host", "192.168.0.1");
            Environment.SetEnvironmentVariable("port", "3666");
            Environment.SetEnvironmentVariable("user", "userEnvironment");
            Environment.SetEnvironmentVariable("password", "passEnvironment");
            Environment.SetEnvironmentVariable("database", "EnvironmentDatabase");

            Console.WriteLine("Db Info : Variaveis de Ambiente");
            dbConfigService.DbType = DbEnum.EnvironmentVariables;
            Console.WriteLine(dbConfigService.CreateConfigJson());

            // Database

            Console.WriteLine("Database : EnvironmentVariables");
            var connService = new DbConnectionService(DbEnum.EnvironmentVariables);

            Console.WriteLine(connService.GetConnString());
            connService.Execute("SELECT * FROM tb_teste t WHERE t.id = 0");
            Console.WriteLine("-----------------------------------------");

            Console.WriteLine("Database : File");
            connService = new DbConnectionService(DbEnum.File);
            Console.WriteLine(connService.GetConnString());
            connService.Execute("SELECT * FROM tb_teste t WHERE t.id = 0");
            Console.WriteLine("-----------------------------------------");

            Console.ReadKey();
        }
Example #7
0
        public ActionResult Add(Dbconfig dbconfig)
        {
            PlantService plantInfoService = PlantService.GetInstance();
            Plant        plantInfo        = plantInfoService.GetPlantInfoById(dbconfig.id);

            if (plantInfo == null)
            {
                ModelState.AddModelError("Error", "该电站不存在");
            }
            else
            {
                //if (string.IsNullOrEmpty(dbconfig.Id))
                //    ModelState.AddModelError("Code", "采集器编号不能为空");
                if (string.IsNullOrEmpty(dbconfig.year))
                {
                    ModelState.AddModelError("Year", "年份不能为空");
                }
                if (string.IsNullOrEmpty(dbconfig.url))
                {
                    ModelState.AddModelError("地址", "地址不能为空");
                }
                if (ModelState.IsValid)
                {
                    // 创建电站数据分布服务
                    DbConfigService dbconfigService = DbConfigService.GetInstance();
                    try
                    {
                        // 添加电站数据分布
                        dbconfigService.Add(dbconfig);
                    }
                    catch
                    {
                        ModelState.AddModelError("Error", "已存在该电站信息");
                    }
                }
            }
            return(View(dbconfig));
        }