private void btnImport_Click(object sender, EventArgs e) { try { string oldstr; string pathstr; OpenFileDialog file = new OpenFileDialog(); file.Filter = "授权文件(*.key)|*.key|所有文件(*.*)|*.*"; if (file.ShowDialog() == DialogResult.OK) { TheaterInfo = new CustomDataTypes.TheaterInfo(); hallList = new List <CustomDataTypes.HallInfo>(); pathstr = file.FileName; StreamReader sr = new StreamReader(pathstr); oldstr = sr.ReadToEnd(); string ss = RC6Encryption.Decrypt(oldstr); sr.Dispose(); sr.Close(); StreamWriter sw = new StreamWriter(pathstr, false); sw.Write(ss); sw.Flush(); sw.Dispose(); sw.Close(); DataSet ds = new DataSet(); ds.ReadXml(pathstr); sw = new StreamWriter(pathstr, false); sw.Write(oldstr); sw.Flush(); sw.Dispose(); sw.Close(); SetInfo(ds); Rebind(); } } catch { } }
private void btnOK_Click(object sender, EventArgs e) { try { string oldstr; string pathstr = txtPath.Text; if (File.Exists(pathstr) == true) { StreamReader sr = new StreamReader(pathstr); oldstr = sr.ReadToEnd(); string ss = RC6Encryption.Decrypt(oldstr); sr.Dispose(); sr.Close(); StreamWriter sw = new StreamWriter(pathstr, false); sw.Write(ss); sw.Flush(); sw.Dispose(); sw.Close(); DataSet ds = new DataSet(); ds.ReadXml(pathstr); sw = new StreamWriter(pathstr, false); sw.Write(oldstr); sw.Flush(); sw.Dispose(); sw.Close(); dataManager.SetInfo(ds); MessageBox.Show("导入授权文件成功!", "信息提示"); DialogResult = DialogResult.OK; } else { MessageBox.Show("选择的授权文件不存在,请重新选择!", "信息提示"); } } catch (Exception ex) { MessageBox.Show("导入授权文件失败!\n" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }