21-03-13, 05:24 PM
كود النسخ الاحتياطي:
كود استرجاع قاعدة البيانات:
كود تصفير قاعدة البيانات:
هذا والله تعالى أعلم وأجل
وصلى الله على سيدنا محمد وعلى آله وصحبه أجمعين
:#C
كود :
[align=left]SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "نسخة احتياطية";
sfd.FileName = string.Empty;
sfd.Filter = "نسخة احتياطية|*.bak";
if (sfd.ShowDialog() == DialogResult.OK)
try
{
string dbname = string.Format("{0}{1} {2}{3}",
System.IO.Path.GetDirectoryName(sfd.FileName),
System.IO.Path.GetFileNameWithoutExtension(sfd.FileName),
DateTime.Today.ToShortDateString().Replace('/','-'),
System.IO.Path.GetExtension(sfd.FileName));
db.ExecuteCommand("backup database PhoneBookDB to disk ='" + dbname + "'");
MessageBox.Show("تم إنشاء النسخة الإحتياطية", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex) { MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error); }
sfd.Dispose();
sfd = null;
[/align]
:VB
كود :
[align=left]Dim sfd As New SaveFileDialog()
sfd.Title = "نسخة احتياطية"
sfd.FileName = String.Empty
sfd.Filter = "نسخة احتياطية|*.bak"
If sfd.ShowDialog() = DialogResult.OK Then
Try
Dim dbname As String = String.Format("{0}{1} {2}{3}", _
System.IO.Path.GetDirectoryName(sfd.FileName), _
System.IO.Path.GetFileNameWithoutExtension(sfd.FileName), _
DateTime.Today.ToShortDateString().Replace("/"c, "-"c), _
System.IO.Path.GetExtension(sfd.FileName))
db.ExecuteCommand("backup database PhoneBookDB to disk ='" & dbname & "'")
MessageBox.Show("تم إنشاء النسخة الإحتياطية", Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
sfd.Dispose()
sfd = Nothing
[/align]
كود استرجاع قاعدة البيانات:
:#C
كود :
[align=left]if (MessageBox.Show("سوف يتم استبدال جميع البيانات\nهل تريد الاستمرار", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "استرجاع";
ofd.FileName = string.Empty;
ofd.Filter = "نسخة احتياطية|*.bak";
if (ofd.ShowDialog() == DialogResult.OK)
try
{
db.ExecuteCommand("restore database PhoneBookDB from disk ='" + ofd.FileName + "'");
MessageBox.Show("تم استرجاع النسخة", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex) { MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error); }
ofd.Dispose();
ofd = null;
[/align]
:VB
كود :
[align=left]If MessageBox.Show("سوف يتم استبدال جميع البيانات" & vbCrLf & "هل تريد الاستمرار", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then Exit Sub
Dim ofd As New OpenFileDialog()
ofd.Title = "استرجاع"
ofd.FileName = String.Empty
ofd.Filter = "نسخة احتياطية|*.bak"
If ofd.ShowDialog() = DialogResult.OK Then
Try
db.ExecuteCommand("restore database PhoneBookDB from disk ='" & ofd.FileName & "'")
MessageBox.Show("تم استرجاع النسخة", Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If
ofd.Dispose()
ofd = Nothing
[/align]
كود تصفير قاعدة البيانات:
:#C
كود :
[align=left]if (MessageBox.Show("سوف تفقد جميع البيانات\nهل تريد الاستمرار", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
try { db.DeleteDatabase(); db.CreateDatabase(); GetData(); }
catch (Exception ex) { MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error); }[/align]
:VB
كود :
[align=left]If MessageBox.Show("سوف تفقد جميع البيانات" & vbCrLf & "هل تريد الاستمرار", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then Exit Sub
Try
db.DeleteDatabase()
db.CreateDatabase()
GetData()
Catch ex As Exception
MessageBox.Show(ex.Message, "خطأ", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try[/align]
هذا والله تعالى أعلم وأجل
وصلى الله على سيدنا محمد وعلى آله وصحبه أجمعين