Exemplo n.º 1
0
        public IActionResult DBScript()
        {
            //type source name uname passwd
            M_APIResult retMod = new M_APIResult(Failed);

            try
            {
                string connStr = GetConnstr();
                DBCenter.DB = SqlBase.CreateHelper("mssql");
                DBCenter.DB.ConnectionString = SiteConfig.SiteInfo.ConnectionString = connStr;
                if (!DataConvert.CBool(GetParam("ignoreSql")))
                {
                    string sqlPath = function.VToP("/App_Data/Data.sql");
                    DBHelper.ExecuteSqlScript(GetConnstr(), sqlPath);
                }
                SiteConfig.Update();
                retMod.retcode = M_APIResult.Success;
            }
            catch (Exception ex)
            {
                retMod.retmsg = ex.Message;
                ZLLog.L("安装时出错,原因:" + ex.Message);
            }
            return(Content(retMod.ToString()));
        }
Exemplo n.º 2
0
 public Startup(IConfiguration configuration)
 {
     Configuration = configuration;
     //DBCenter.DB = SqlBase.CreateHelper("mysql");
     //DBCenter.DB.ConnectionString = "server=localhost;database=zoomlacms;uid=root;pwd=111111aa;SslMode=None;";
     CompHelper.Startup();
     DBCenter.DB = SqlBase.CreateHelper("mssql");
     DBCenter.DB.ConnectionString = SiteConfig.SiteInfo.ConnectionString;
 }
Exemplo n.º 3
0
        protected void Test_Btn_Click(object sender, EventArgs e)
        {
            DBConnectText.Text = DBConnectText.Text.Trim();
            TestResult_L.Text  = "";
            string  success = "<span style='color:green'>测试成功</span>";
            SqlBase db      = SqlBase.CreateHelper(DataSource_DP.SelectedValue);

            try
            {
                db.ConnectionString = DBConnectText.Text;
                db.Table_List();
                TestResult_L.Text = success;
            }
            catch (Exception ex) { TestResult_L.Text = "<span style='color:red;'>连接失败,原因:" + ex.Message + "</span>"; }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 用于标签
        /// </summary>
        /// <param name="type">数据源类型或数据源ID</param>
        public static SqlBase GetDSByType(string type)
        {
            B_DataSource dsBll = new B_DataSource();

            switch (type)
            {
            case "main":
            case "second":
            case "new":
                return(DBCenter.DB);

            default:
                M_DataSource dsMod = dsBll.SelReturnModel(Convert.ToInt32(type));
                SqlBase      db    = SqlBase.CreateHelper(dsMod.Type);
                db.ConnectionString = dsMod.ConnectionString;
                return(db);
            }
        }
Exemplo n.º 5
0
        static DBCenter()
        {
            //根据类型,初始化不同的辅助类,和读取连接字符串
            string dbtype = ConfigurationManager.AppSettings["DBType"];

            if (string.IsNullOrEmpty(dbtype))
            {
                dbtype = "mssql";
            }
            DB = SqlBase.CreateHelper(dbtype);
            switch (dbtype)//为多数据库读取
            {
            case "oracle":
                DB.ConnectionString = ConfigurationManager.ConnectionStrings["OraConnection String"].ConnectionString;
                break;

            default:
                DB.ConnectionString = SafeC.Cert_Decry(ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString);
                break;
            }
        }
Exemplo n.º 6
0
        //根据csv或xlsx,将数据导入数据库
        public void ContentManage_Import()
        {
            HttpPostedFileBase file = Request.Files["fileImp"];

            if (file == null)
            {
                function.WriteErrMsg("没有上传数据文件"); return;
            }
            string exName = Path.GetExtension(file.FileName).ToLower();

            if (!exName.Equals(".csv") && !exName.Equals(".xls") && !exName.Equals(".xlsx"))//判断扩展名
            {
                function.WriteErrMsg("上传的文件不是符合扩展名csv,请重新选择!"); return;
            }
            string vpath = SafeSC.SaveFile(ZLHelper.GetUploadDir_System("Content", "Import", "yyyyMMdd"), function.GetRandomString(6) + exName, IOHelper.StreamToBytes(file.InputStream));
            //导入文件到数据集对象
            DataTable dt = null;

            if (exName.Equals(".csv"))
            {
                OfficeHelper office = new OfficeHelper();
                dt = office.OpenCSV(vpath);
            }
            else
            {
                SqlBase excel = SqlBase.CreateHelper("excel");
                excel.ConnectionString = vpath;
                dt = excel.ExecuteTable(new SqlModel()
                {
                    tbName = excel.Table_List().Rows[0]["name"].ToString()
                });
            }
            SafeSC.DelFile(vpath);
            DataSet newDs = Import_CreateTable(dt);

            Import_SaveDB(newDs);//保存到数据库
        }