Beispiel #1
0
        private void Restore()
        {
            System.Threading.Thread.Sleep(5000);


            DbEntities newdb = new DbEntities();

            DbEntityRefresh.Refresh(newdb);
            try
            {
                sourcepath = txtfilename.Text;
                File.Move(sourcepath, Path.ChangeExtension(sourcepath, ".db"));

                if (File.Exists(destpath + "/Database.db"))
                {
                    File.Delete(destpath + "/Database.db");
                }

                File.Copy(Path.GetDirectoryName(sourcepath) + "/Database.db", destpath + "/Database.db");

                File.Move(Path.GetDirectoryName(sourcepath) + "/Database.db", Path.ChangeExtension(Path.GetDirectoryName(sourcepath) + "/Database.db", ".backupsms"));

                var schoolname    = newdb.Randoms.Where(c => c.ID == 1).FirstOrDefault();
                var schooladdress = newdb.Randoms.Where(c => c.ID == 2).FirstOrDefault();
                var schoolcontact = newdb.Randoms.Where(c => c.ID == 3).FirstOrDefault();
                var schoolemail   = newdb.Randoms.Where(c => c.ID == 4).FirstOrDefault();
                var ownername     = newdb.Randoms.Where(c => c.ID == 5).FirstOrDefault();
                var softid        = newdb.Randoms.Where(c => c.ID == 18).FirstOrDefault();

                string fileName = Application.StartupPath + @"\bin\License.lic";


                // Check if file already exists. If yes, delete it.
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }

                // Create a new file
                using (StreamWriter sw = File.CreateText(fileName))
                {
                    sw.WriteLine("Owner Name:" + ownername.Text);
                    sw.WriteLine("School Name:" + schoolname.Text);
                    sw.WriteLine("School Address:" + schooladdress.Text);
                    sw.WriteLine("School Contact:" + schoolcontact.Text);
                    sw.WriteLine("School Email:" + schoolemail.Text);
                    sw.WriteLine("Installation Date:" + DateTime.Now.ToString("dd/MM/yyyy"));
                    sw.WriteLine("IsActivated:" + ClsTripleDES.Encrypt("False"));
                    string ency = DateTime.Now.ToString("dd/MM/yyyy") + "," + DateTime.Now.AddDays(5).ToString("dd/MM/yyyy") + "," + softid.Text + "," + ownername.Text + "," + schoolname.Text + "," + "True";
                    sw.WriteLine("Licensed Hash:" + ClsTripleDES.Encrypt(ency));
                }

                string[] lines = File.ReadAllLines(Application.StartupPath + @"\bin\User.Config");
                lines[0] = "Owner Name:" + txtowner.Text;
                lines[1] = "School Name:" + txtschoolname.Text;
                lines[2] = "FirstRun:" + "False";
                lines[3] = "DefaultPrinter:null";

                File.WriteAllLines(Application.StartupPath + @"\bin\User.Config", lines);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                newdb.Dispose();
            }
        }