public static BG_Unit_Dbbak AddBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak)
        {
            string sql =
                "INSERT BG_Unit_Dbbak (DbName, DbCreationTime)" +
                "VALUES (@DbName, @DbCreationTime)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@DbName", bG_Unit_Dbbak.DbName),
                    new SqlParameter("@DbCreationTime", bG_Unit_Dbbak.DbCreationTime)
                };

                string IdStr = DBUnity.ExecuteScalar(CommandType.Text, sql, para);
                int newId = Convert.ToInt32(IdStr);
                return GetBG_Unit_DbbakByDbID(newId);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 public static bool ModifyBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak)
 {
     return BG_Unit_DbbakService.ModifyBG_Unit_Dbbak(bG_Unit_Dbbak);
 }
 public static bool DeleteBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak)
 {
     return BG_Unit_DbbakService.DeleteBG_Unit_Dbbak(bG_Unit_Dbbak);
 }
 public static BG_Unit_Dbbak AddBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak)
 {
     return BG_Unit_DbbakService.AddBG_Unit_Dbbak(bG_Unit_Dbbak);
 }
        public static BG_Unit_Dbbak GetBG_Unit_DbbakByDbID(int dbID)
        {
            string sql = "SELECT * FROM BG_Unit_Dbbak WHERE DbID = @DbID";

            try
            {
                SqlParameter para = new SqlParameter("@DbID", dbID);
                DataTable dt = DBUnity.AdapterToTab(sql, para);

                if(dt.Rows.Count > 0)
                {
                    BG_Unit_Dbbak bG_Unit_Dbbak = new BG_Unit_Dbbak();

                    bG_Unit_Dbbak.DbID = dt.Rows[0]["DbID"] == DBNull.Value ? 0 : (int)dt.Rows[0]["DbID"];
                    bG_Unit_Dbbak.DbName = dt.Rows[0]["DbName"] == DBNull.Value ? "" : (string)dt.Rows[0]["DbName"];
                    bG_Unit_Dbbak.DbCreationTime = dt.Rows[0]["DbCreationTime"] == DBNull.Value ? DateTime.MinValue : (DateTime)dt.Rows[0]["DbCreationTime"];

                    return bG_Unit_Dbbak;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
 public static bool DeleteBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak)
 {
     return DeleteBG_Unit_DbbakByDbID( bG_Unit_Dbbak.DbID );
 }
        public static bool ModifyBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak)
        {
            string sql =
                "UPDATE BG_Unit_Dbbak " +
                "SET " +
                    "DbName = @DbName, " +
                    "DbCreationTime = @DbCreationTime " +
                "WHERE DbID = @DbID";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@DbID", bG_Unit_Dbbak.DbID),
                    new SqlParameter("@DbName", bG_Unit_Dbbak.DbName),
                    new SqlParameter("@DbCreationTime", bG_Unit_Dbbak.DbCreationTime)
                };

                int t = DBUnity.ExecuteNonQuery(CommandType.Text, sql, para);
                if(t>0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }
    protected void btnWinAdd_DirectClick(object sender, DirectEventArgs e)
    {
        string dbFileName = "";

        dbFileName = AdName.Text;
        string sql = "  CREATE DATABASE  {0}"
         + " DECLARE  @sql  NVARCHAR (MAX)"
         + " DECLARE  @sql1  NVARCHAR (MAX)"
         + " DECLARE  @sql2  NVARCHAR (MAX)"
         + " DECLARE @i int"
         + " DECLARE @tabname  NVARCHAR (MAX)"
         + " set @i=1"
         + " while @i<=(select count(tab.name) from SysObjects as tab where xtype='u'  and name not like '%_Unit_%' )"
         + " begin"
         + " set  @tabname=(select top(1) * from (select top(@i) tab.name from SysObjects as tab where xtype='u' and name not like"
         + "       '%_Unit_%'  order by name asc) as a  order by name desc)"
         + "   SET @sql1 =  'select * into {0}.[dbo].'+@tabname+' from ' +@tabname "
         + "   SET @sql2 =  'drop table {0}.[dbo].'+@tabname    +  @sql1 "
         + " SET @sql =  ''if object_id(N'{0}.[dbo].'+@tabname+'',N'U') is not null   EXEC(@sql2)    else  EXEC(@sql1) "
         + " EXEC(@sql); "
         + " set @i= @i+1 "
         + " end ";
        sql = string.Format(sql, dbFileName);
        int t = DBUnity.ExecuteNonQuery(CommandType.Text, sql, null);
        if (t > 0)
        {
            BG_Unit_Dbbak dbbak = new BG_Unit_Dbbak();
            dbbak.DbName = dbFileName;
            dbbak.DbCreationTime = DateTime.Now;
            if (BG_Unit_DbbakService.AddBG_Unit_Dbbak(dbbak).DbID > 0)
            {
                X.Msg.Confirm("系统提示", "备份成功!", new MessageBoxButtonsConfig
           {
               Yes = new MessageBoxButtonConfig
               {
                   Handler = "SS.DoYesSSS()",
                   Text = "确定"
               }
           }).Show();
            }

        }
    }