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); } }
/// <summary> /// 保存XML文档 /// </summary> private void SaveXML() { DataSet ds = new DataSet("TheaterAndHall"); DataTable dtTime = new DataTable("dtTime"); dtTime.Columns.Add("StartTime"); dtTime.Columns.Add("EndTime"); DataRow dw = dtTime.NewRow(); dw["StartTime"] = dtpStart.Value.Date; dw["EndTime"] = dtpEnd.Value.Date.AddDays(1).AddSeconds(-1); dtTime.Rows.Add(dw); ds.Tables.Add(dtTime); DataTable dtModule = new DataTable("dtModule"); dtModule.Columns.Add("Name"); dtModule.Columns.Add("Value"); dtModule = SaveModule(dtModule); ds.Tables.Add(dtModule); DataTable TheaterInformation = new DataTable("TheaterInformation"); //由于下面的方法只支持List,所以在此先定义一个中间变量 List <CustomDataTypes.TheaterInfo> TheaterList = new List <CustomDataTypes.TheaterInfo>(); TheaterList.Add(TheaterInfo); if (TheaterList.Count > 0) { PropertyInfo[] propertys = TheaterList[0].GetType().GetProperties(); foreach (PropertyInfo pi in propertys) { //获取DailyPlan表的标题名称 TheaterInformation.Columns.Add(pi.Name);//, pi.PropertyType } for (int i = 0; i < TheaterList.Count; i++) { //获取数据 ArrayList tempList = new ArrayList(); foreach (PropertyInfo pi in propertys) { object obj = pi.GetValue(TheaterList[i], null); tempList.Add(obj); } object[] array = tempList.ToArray(); TheaterInformation.LoadDataRow(array, true); } } DataTable HallInformation = new DataTable("HallInformation"); hallList = dataBindingSource.DataSource as List <CustomDataTypes.HallInfo>; if (hallList.Count > 0) { PropertyInfo[] propertys = hallList[0].GetType().GetProperties(); foreach (PropertyInfo pi in propertys) { //获取DailyPlan表的标题名称 HallInformation.Columns.Add(pi.Name);//, pi.PropertyType } for (int i = 0; i < hallList.Count; i++) { //获取数据 ArrayList tempList = new ArrayList(); foreach (PropertyInfo pi in propertys) { object obj = pi.GetValue(hallList[i], null); tempList.Add(obj); } object[] array = tempList.ToArray(); HallInformation.LoadDataRow(array, true); } } ds.Tables.Add(TheaterInformation); //将放映计划信息信息加入到dataset中 ds.Tables.Add(HallInformation); //导出XML文件 ds.WriteXml(Path); StreamReader sr = new StreamReader(Path); string ss = RC6Encryption.Encrypt(sr.ReadToEnd()); sr.Dispose(); sr.Close(); StreamWriter sw = new StreamWriter(Path, false); sw.Write(ss); sw.Flush(); sw.Dispose(); sw.Close(); }