Пример #1
0
        private void SaveScoreDataToFile()
        {
            List <int> GrpScore = new List <int>();
            List <int> StdScore = new List <int>();

            foreach (var g in groups)
            {
                GrpScore.Add(g.Score);
            }
            foreach (var s in stds)
            {
                StdScore.Add(s.Score);
            }
            ScoreData data = new ScoreData(Tools.GetMD5HashFromFile(GrpLocal),
                                           Tools.GetMD5HashFromFile(StdLocal),
                                           GrpScore, StdScore);

            if (Info.SerializerScore(data, ScLocal))
            {
                MessageBox.Show("保存完成!");
            }
            else
            {
                MessageBox.Show("保存失败。");
            }
            data     = null;
            GrpScore = null;
            StdScore = null;
        }
Пример #2
0
        private void ReadScoreData_Click(object sender, RoutedEventArgs e)
        {
            if (!File.Exists(ScLocal))
            {
                MessageBox.Show("文件不存在"); return;
            }
            if (MessageBox.Show(" 导入数据会覆盖现在的数据,是否继续?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.Cancel)
            {
                return;
            }
            ScoreData data = Info.DeserializeScore(ScLocal);

            if (data.GroupInfoMD5 != Tools.GetMD5HashFromFile(GrpLocal) ||
                data.StdDataMD5 != Tools.GetMD5HashFromFile(StdLocal))
            {
                if (MessageBox.Show("积分文件和小组或学生数据文件不匹配,是否继续导入?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information)
                    == MessageBoxResult.No)
                {
                    return;
                }
            }
            foreach (var g in groups)
            {
                g.Score = data.GroupScore.FirstOrDefault();
                data.GroupScore.RemoveAt(0);
            }
            foreach (var s in stds)
            {
                s.Score = data.StudentScore.FirstOrDefault();
                data.StudentScore.RemoveAt(0);
            }
            data = null;
        }
Пример #3
0
        /// <summary>
        /// 序列化积分信息
        /// </summary>
        /// <param name="score">积分信息</param>
        /// <param name="FileName">文件位置</param>
        /// <returns>序列化是否成功</returns>
        static public bool SerializerScore(ScoreData score, string FileName)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScoreData));

            using (FileStream fs = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                try
                {
                    xmlSerializer.Serialize(fs, score);
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误信息", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
            }
        }