コード例 #1
0
 public Entities.SaoLuuHeThong[] LayBackUp()
 {
     try
     {
         string        path = duongdanFolder;
         DirectoryInfo DI   = new DirectoryInfo(path);
         if (!DI.Exists)
         {
             return(null);
         }
         FileInfo[] FI = DI.GetFiles("BUSuperMarketDHT*");
         Entities.SaoLuuHeThong[] slht = new Entities.SaoLuuHeThong[FI.Length];
         int j = 0;
         for (int i = FI.Length - 1; i >= 0; i--)
         {
             slht[j] = new Entities.SaoLuuHeThong(FI[i].Name, FI[i].LastWriteTime.ToShortDateString(), FI[i].Length);
             j++;
         }
         return(slht);
     }
     catch
     {
         return(null);
     }
 }
コード例 #2
0
        public bool Restore(Entities.SaoLuuHeThong slht1)
        {
            try
            {
                try
                {
                    SqlConnection.ClearAllPools();
                    string        path     = duongdanFolder;
                    DirectoryInfo FI       = new DirectoryInfo(path);
                    string        fileName = "BUSuperMarketDHT" + slht1.Name;
                    string        sql      = "ALTER DATABASE SupermarketManagementDHT ";
                    sql += "SET SINGLE_USER WITH ROLLBACK IMMEDIATE ";
                    sql += " use master ";
                    //sql += "while((select COUNT(spid) from master..sysprocesses where DBid=DB_ID('SupermarketManagement'))>0)";
                    //sql += "begin ";
                    //sql += "declare @id smallint=(select top(1)spid from master..sysprocesses where DBid=DB_ID('SupermarketManagement')) ";
                    //sql += "declare @sql nvarchar(100)=N'kill @i' ";
                    //sql += "exec sp_executesql @sql,N'@i smallint',@i=@id ";
                    //sql += "end ";
                    sql += "restore DATABASE SupermarketManagementDHT from DISK='" + path + "\\" + slht1.Name + "' with replace";
                    sql += " ALTER DATABASE SupermarketManagementDHT ";
                    sql += "SET MULTI_USER";

                    if (!FI.Exists)
                    {
                        return(false);
                    }
                    conn            = new Connection();
                    cmd             = new SqlCommand();
                    cmd.CommandText = sql;
                    cmd.Connection  = conn.openConnection();

                    cmd.ExecuteNonQuery();

                    cmd.Connection.Dispose();
                    cmd.Connection.Close();
                    cmd.Dispose();
                }
                catch
                { return(false); }
                finally
                {
                    cmd.Connection.Dispose();
                    cmd.Connection.Close();
                    cmd.Dispose();
                    conn.closeConnection();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #3
0
 public Entities.SaoLuuHeThong[] LayBackUp()
 {
     try
     {
         string path = duongdanFolder;
         DirectoryInfo DI = new DirectoryInfo(path);
         if (!DI.Exists)
         {
             return null;
         }
         FileInfo[] FI = DI.GetFiles("BUSuperMarketDHT*");
         Entities.SaoLuuHeThong[] slht = new Entities.SaoLuuHeThong[FI.Length];
         int j = 0;
         for (int i = FI.Length - 1; i >= 0; i--)
         {
             slht[j] = new Entities.SaoLuuHeThong(FI[i].Name, FI[i].LastWriteTime.ToShortDateString(), FI[i].Length);
             j++;
         }
         return slht;
     }
     catch
     {
         return null;
     }
 }