如何使用T-SQL备份还原数据库及c#如何调用执行? C#中索引器的作用和实现。 jquery控制元素的隐藏和显示的几种方法。 localStorage、sessionStorage用法总结 在AspNetCore中扩展Log系列 - 介绍开源类库的使用(一) span<T>之高性能字符串操作实测
如何使用T-SQL备份还原数据库及c#如何调用执行?
准备材料:Microsoft SQL Server一部、需要还原的bak文件一只
一、备份
数据库备份语句:user master backup database 数据库名 to disk='保存路径\dbName.bak'
实战操作:这里要使用sql语句对TEST数据库进行备份,当然你也可以使用mssql自带工具进行操作,咦,麻烦死了
一句sql:
use master backup database TEST to disk='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\TEST.bak'
截图童叟无欺:

二、还原 相对较为麻烦,因为有日志文件的问题还有杀死连接的问题。
数据库还原语句:
use master restore database 数据库名 from disk='保存路径\dbName.bak' WITH MOVE 'dbName_Data' to '保存路径\test20160428.mdf',
move 'dbName_Log' to '保存路径\test20160428_Log.mdf'
实战操作:这里我重新找了一个bak文件进行还原。源Bak文件名:FTZMIS20151218.bak
①首先,首先要查找到源bak文件中的数据文件和日志文件名称,需要一条SQL语句
sql:
restore filelistonly from disk = 'F:\华美数据核对20160407\FTZMIS20151218.bak'---查找BAK文件相关信息
结果:LogicalName列下的值就分别问数据文件名称和日志文件名称,待会要用到。

②正题开始,进行还原操作。
sql:
restore database kaifang from disk = 'F:\华美数据核对20160407\FTZMIS20151218.bak'--源bak文件 with REPLACE--这句的意思是是否覆盖目标数据,也就是这里的数据库:kaifang , move 'ABOQDB' to 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\FTZMIS.mdf'--数据文件还原后存放的新位置 ,move 'ABOQDB_log' to 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\FTZMIS_1.ldf'--日志文件还原后存放的新位置
截图:暂无,还原还在执行
截图来了,

C#中索引器的作用和实现。
官方描述:索引器允许类或结构的实例就像数组一样进行索引。索引器形态类似于,不同之处在于它们的取值函数采用参数。
这一功能在创建集合类的场合特别有用,而在其他某些情况下,比如处理大型文件或者抽象有些资源等,能让类具有类似数组行为也是非常有用的。
大致结构:
<modifier><return type> this [argument list]
{
get{//读}
set{//写}
}
其中:
modifier:修饰符,如:public,private,protected
this:是C#中一个特殊的关键字,表示引用类的当前实例。这里是当前类的索引。
argument list:这里是索引器的参数
一个简单例子,通过索引器返回一个字符串:
class Sample {
public string this [int index] {
get {return "当前索引号为:" + index; }
}
}
Sample s=new Sample();
Console.WriteLine(s[23]);
//结果
//当前索引号为:23
技巧:
1.在定义索引器的时候,不一定只采用一个参数,同一类中还可以拥有一个以上的索引器,也就是重载。
2.索引器的参数可以采用任何类型,不过int是最为合理的类型。
属性和索引器差别:
1.类的每一个属性都必须拥有唯一的名称,而类里定义的每一个索引器都必须拥有唯一的签名(signature)或者参数列表(这样就可以实现索引器重载)。
2.属性可以是static(静态的)而索引器则必须是实例成员。
3.为索引器定义的访问函数可以访问传递给索引器的参数,而属性访问函数则没有参数。
接口(interface):
类似数组的行为常受到程序实现者的喜爱,所以你还可以为接口定义索引器,IList和 IDictionary集合接口都声明了索引器以便访问其存储的项目。 在为接口声明索引器的时候,记住声明只是表示索引器的存在。你只需要提供恰当的访问函数即可,不必包括范围修饰符。以下代码把索引器声明为接口IImplementMe的一部分:
interface IImplementMe { string this[int index] { get; set; }
相应实现的类则必须为IimplementMe的索引器具体定义get和set访问函数。
官方代码实例:
class SampleCollection<T>
{
// Declare an array to store the data elements.
private T[] arr = new T[100];
// Define the indexer, which will allow client code
// to use [] notation on the class instance itself.
// (See line 2 of code in Main below.)
public T this[int i]
{
get
{
// This indexer is very simple, and just returns or sets
// the corresponding element from the internal array.
return arr[i];
}
set
{
arr[i] = value;
}
}
}
// This class shows how client code uses the indexer.
class Program
{
static void Main(string[] args)
{
// Declare an instance of the SampleCollection type.
SampleCollection<string> stringCollection = new SampleCollection<string>();
// Use [] notation on the type.
stringCollection[0] = "Hello, World";
System.Console.WriteLine(stringCollection[0]);
}
}
// Output:
// Hello, World.
码友实例:
非常实用
namespace Study
{
class Program
{
static void Main(string[] args)
{
ScoreIndex s = new ScoreIndex();
s["张三", 1] = 90;
s["张三", 2] = 100;
s["张三", 3] = 80;
s["李四", 1] = 60;
s["李四", 2] = 70;
s["李四", 3] = 50;
Console.WriteLine("张三课程编号为1的成绩为:" + s["张三",1]);
Console.WriteLine("张三的所有成绩为:");
ArrayList temp;
temp = s["张三"];
foreach (IndexClass b in temp)
{
Console.WriteLine("姓名:" + b.Name + "课程编号:" + b.CourseID + "分数:" + b.Score);
}
Console.ReadKey();
}
}
class IndexClass
{
private string _name;
private int _courseid;
private int _score;
public IndexClass(string _name, int _courseid, int _score)
{
this._name = _name;
this._courseid = _courseid;
this._score = _score;
}
public string Name
{
get { return _name; }
set { this._name = value; }
}
public int CourseID
{
get { return _courseid; }
set { this._courseid = value; }
}
public int Score
{
get { return _score; }
set { this._score = value; }
}
}
class ScoreIndex
{
private ArrayList arr;
public ScoreIndex()
{
arr = new ArrayList();
}
public int this[string _name, int _courseid]
{
get
{
foreach (IndexClass a in arr)
{
if (a.Name == _name && a.CourseID == _courseid)
{
return a.Score;
}
}
return -1;
}
set
{
arr.Add(new IndexClass(_name, _courseid, value)); //arr["张三",1]=90
}
}
//重载索引器
public ArrayList this[string _name]
{
get
{
ArrayList temp = new ArrayList();
foreach (IndexClass b in arr)
{
if (b.Name == _name)
{
temp.Add(b);
}
}
return temp;
}
}
}
}
jquery控制元素的隐藏和显示的几种方法。
组织略显凌乱,请耐心看!
使用jquery控制div的显示与隐藏,一句话就能搞定,例如:
1.$("#id").show()表示为display:block,
$("#id").hide()表示为display:none;
2.$("#id").toggle()切换元素的可见状态。如果元素是可见的,切换为隐藏的;如果元素是隐藏的,则切换为可见的。
3.$("#id").css('display','none');//隐藏
$("#id").css('display','block');//显示
或者
$("#id")[0].style.display='none';
display=none 控制对象的隐藏
display=block控制对象的显示
4.$("#id").css('visibility','hidden');//元素隐藏
$("#id").css('visibility','visible');//元素显示
CSS visibility 属性规定元素是否可见。
visible 元素可见。
hidden 元素不可见。
collapse 在表格元素中使用时,此值可删除一行或一列,但它不影响表格的布局。被行或列占据的空间会留给其他内容使用。如果此值被用在其他的元素上,会呈现为 "hidden"。
inherit 从父元素继承 visibility 属性的值。
注意:
display:none和visible:hidden都能把网页上某个元素隐藏起来,在视觉效果上没有区别,但是在一些DOM操作中两者有区别:
display:none ---不为被隐藏的对象保留其物理空间,即该对象在页面上彻底消失,通俗来说就是看不见也摸不到。
visible:hidden--- 使对象在网页上不可见,但该对象在网页上所占的空间没有改变,即它仍然具有高度、宽度等属性,通俗来说就是看不见但摸得到。
//第1种方法 ,给元素设置style属性
$("#hidediv").css("display", "block");
//第2种方法 ,给元素换class,来实现隐藏div,前提是换的class样式定义好了隐藏属性
$("#hidediv").attr("class", "blockclass");
//第3种方法,通过jquery的css方法,设置div隐藏
$("#blockdiv").css("display", "none");
$("#hidediv").show();//显示div
$("#blockdiv").hide();//隐藏div



![clipboard[1] clipboard[1]](https://img2018.cnblogs.com/blog/914305/201811/914305-20181120135057840-822690421.png)
![clipboard[2] clipboard[2]](https://img2018.cnblogs.com/blog/914305/201811/914305-20181120135058836-602002408.png)
![clipboard[3] clipboard[3]](https://img2018.cnblogs.com/blog/914305/201811/914305-20181120135059513-517698324.png)






浙公网安备 33010602011771号