Thread threadBackup;
private void btnLoad_Click(object sender, EventArgs e)
{
if (MessageBox.Show(GetValue("restorequestion") + "\r\n", GetValue("restorebackup"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
{
((MainForm)this.ParentForm).SetBlockOnApplication();
threadBackup = new Thread(new ThreadStart(test));
threadBackup.Start();
}
}
private void test()
{
//if (MessageBox.Show(GetValue("restorequestion") + "\r\n", GetValue("restorebackup"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
//{
int intDBVersion = AmEngine.Instance.GetDbVersion();
try
{
Backup.Backup bck = new Adra.Backup.Backup();
Cursor.Current = Cursors.WaitCursor;
LoadBackupFile();
if (!bck.RestoreEngagement(myOper, myDsBackup, m_intDbVersion))
{
MessageBox.Show(GetValue("restorefailed"), GetValue("restorebackup"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
//MessageBox.Show(GetValue("restorefinished"), GetValue("restorebackup"), MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult dialog = MessageBox.Show(GetValue("restorefinished"), GetValue("restorebackup"), MessageBoxButtons.OK, MessageBoxIcon.Information);
if (dialog == DialogResult.OK)
{
Restart();
}
}
//LoadBackupFile();
Cursor.Current = Cursors.Default;
}
catch (Exception exe)
{
if (m_intDbVersion != intDBVersion)
{
MessageBox.Show(GetValue("mismatchbetweendbVersionandbackupversion"), GetValue("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
MessageBox.Show(GetValue("selectBackupFile"), GetValue("restorebackup"), MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
//}
//LoadBackupFile();
Cursor.Current = Cursors.Default;
}
delegate void SetControlValueCallback(Control oControl, string propName, object propValue);
private void SetControlPropertyValue(Control oControl, string propName, object propValue)
{
if (oControl.InvokeRequired)
{
SetControlValueCallback d = new SetControlValueCallback(SetControlPropertyValue);
oControl.Invoke(d, new object[] { oControl, propName, propValue });
}
else
{
Type t = oControl.GetType();
PropertyInfo[] props = t.GetProperties();
foreach (PropertyInfo p in props)
{
if (p.Name.ToUpper() == propName.ToUpper())
{
p.SetValue(oControl, propValue, null);
}
}
}
}
public void LoadBackupFile()
{
try
{
myDsBackup = new DsAmDb();
XmlTextReader xmlReader = new XmlTextReader(@txtBackupFilePath.Text + "/" + ((string)listBoxBakupFiles.SelectedItem));
XmlDataDocument xmlDs = new XmlDataDocument(myDsBackup);
xmlDs.Load(xmlReader);
m_intDbVersion = Convert.ToInt32(xmlDs.DataSet.Tables["DbVersion"].Rows[0].ItemArray[0]);
myDsBackup = (DsAmDb)xmlDs.DataSet.Copy();
xmlReader.Close();
if (myOper.Engagement_ID == (int)myDsBackup.Engagement.Rows[0]["Engagement_ID"])
{
//lstBoxEngagement.DataSource = myDsBackup.Engagement;
//lstBoxClient.DataSource = myDsBackup.Client;
SetControlPropertyValue(btnLoad, "Enabled", true);
//btnRestoreClient.Enabled = true;
this.Cursor = Cursors.Default;
}
else
{
//TODO: Translate this one:
//MessageBox.Show("*Engasjement matcher ikke!");
MessageBox.Show(GetValue("engvsdbinconsistens"), GetValue("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
SetControlPropertyValue(lstBoxEngagement, "DataSource", null);
SetControlPropertyValue(lstBoxClient, "DataSource", null);
SetControlPropertyValue(btnLoad, "Enabled", false);
SetControlPropertyValue(btnRestoreClient, "Enabled", false);
this.Cursor = Cursors.Default;
return;
}
}
catch (Exception ex)
{
MessageBox.Show(GetValue("errorreadingbackup"), GetValue("error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Cursor = Cursors.Default;
return;
}
}
Open in new window