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; } }
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 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; } }
//protected void btngetbak_DirectClick(object sender, Ext.Net.DirectEventArgs e) //{ // string tmp = AdName.Text; // RowSelectionModel sm = this.gridpl.GetSelectionModel() as RowSelectionModel; // if (sm.SelectedRows.Count != 1) // { // X.Msg.Alert("系统提示", "请选择一条记录还原!").Show(); // return; // } // else // { // string json = e.ExtraParams["Values"]; // Dictionary<string, string>[] companies = JSON.Deserialize<Dictionary<string, string>[]>(json); // tmp = companies[0]["Name"]; // } // SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ToString()); // string dbFileName = ""; // dbFileName = tmp; // SqlCommand command = new SqlCommand("use master ;ALTER DATABASE [BudgetNetDB] SET OFFLINE WITH ROLLBACK IMMEDIATE;restore database @name from disk=@path WITH REPLACE;", connection); // connection.Open(); // string path = ""; // path = Server.MapPath("~\\DataFile"); // path = path + "\\" + @dbFileName; // command.Parameters.AddWithValue("@name", "BudgetNetDB"); // command.Parameters.AddWithValue("@path", path); // command.ExecuteNonQuery(); // connection.Close(); // X.Msg.Alert("系统提示", "还原成功!").Show(); //} #region 原备份 //protected void btnWinAdd_DirectClick(object sender, DirectEventArgs e) //{ // SqlConnection connection = // new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ToString()); // string dbFileName = ""; // dbFileName = AdName.Text; // if (!dbFileName.EndsWith(".bak")) // { // dbFileName += ".bak"; // } // SqlCommand command = new SqlCommand("use master;backup database @name to disk=@path;", connection); // connection.Open(); // string path = Server.MapPath("~\\DataFile"); // if (!Directory.Exists(path)) // { // Directory.CreateDirectory(path); // } // path = path + "\\" + dbFileName; // if (!File.Exists(path)) // { // command.Parameters.AddWithValue("@name", "BudgetNetDB"); // command.Parameters.AddWithValue("@path", path); // int t = command.ExecuteNonQuery(); // connection.Close(); // ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>window.location.href = window.location.href;</script>"); // //GetbakBind(); // //Winadd.Hide(); // X.Msg.Confirm("系统提示", "备份成功!", new MessageBoxButtonsConfig // { // Yes = new MessageBoxButtonConfig // { // Handler = "SS.DoYesSSS()", // Text = "确定" // } // }).Show(); // } // else // { // X.Msg.Alert("系统提示", "已存在相同的文件名!").Show(); // } //} #endregion 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(); } } }
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 bool DeleteBG_Unit_Dbbak(BG_Unit_Dbbak bG_Unit_Dbbak) { return(DeleteBG_Unit_DbbakByDbID(bG_Unit_Dbbak.DbID)); }