private void SaveRecord2Local(TrainRecord tr)
        {
            try
            {
                string recordPath = Path.Combine(Application.StartupPath, CConstValues.TRAIN_RECORD_DIR_NAME);
                if (!Directory.Exists(recordPath))
                {
                    Directory.CreateDirectory(recordPath);
                }

                string recordFileName = Path.Combine(recordPath, tr.Guid + ".xml");
                if (File.Exists(recordFileName))
                {
                    File.Delete(recordFileName);
                }

                XmlSerializer xs = new XmlSerializer(typeof(TrainRecord));

                using (XmlTextWriter xtw = new XmlTextWriter(recordFileName, Encoding.Default))
                {
                    xs.Serialize(xtw, tr);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载已有培训记录失败,错误消息位:" + ex.Message);
            }
        }
Пример #2
0
        public frmViewRecord(TrainRecord record, IViewTrainRecord tr)
        {
            InitializeComponent();

            m_curRecord    = record;
            m_recordViewer = tr;
        }
        private DataGridViewRow CreateRecordDataRow(TrainRecord tr)
        {
            DataGridViewRow dgvr = new DataGridViewRow();

            dgvr.CreateCells(dgvRecords);
            UpdateRecordDataRow(dgvr, tr);
            return(dgvr);
        }
        private void DeleteTrainRecord(TrainRecord tr)
        {
            string recordPath     = Path.Combine(Application.StartupPath, CConstValues.TRAIN_RECORD_DIR_NAME);
            string recordFileName = Path.Combine(recordPath, tr.Guid + ".xml");

            if (File.Exists(recordFileName))
            {
                File.Delete(recordFileName);
            }
        }
        private Dictionary <string, TrainRecord> GetEditedRecords()
        {
            Dictionary <string, TrainRecord> newRecords = new Dictionary <string, TrainRecord>();

            foreach (DataGridViewRow dgvr in dgvRecords.Rows)
            {
                TrainRecord tr = dgvr.Tag as TrainRecord;
                newRecords.Add(tr.Guid, tr);
            }

            return(newRecords);
        }
Пример #6
0
        private void UpdateRecordInfo(TrainRecord record)
        {
            dtpDate.Value    = record.Date;
            txtPosition.Text = record.Position;
            txtHost.Text     = record.Host;
            txtTheme.Text    = record.Theme;
            txtTime.Text     = record.Duration.ToString();
            txtContent.Text  = record.Content;

            if (record.Participants.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (TrainParticipant tp in record.Participants)
                {
                    sb.Append(string.Format("{0},{1};", tp.Department, tp.Name));
                }

                txtPeople.Text = sb.ToString().TrimEnd(';');
            }
        }
        private void UpdateRecordDataRow(DataGridViewRow dgvr, TrainRecord tr)
        {
            dgvr.Tag = tr;

            dgvr.Cells[0].Value = dgvRecords.Rows.Count + 1;
            dgvr.Cells[1].Value = tr.Date.ToString();
            dgvr.Cells[2].Value = tr.Position;
            dgvr.Cells[3].Value = tr.Host;
            dgvr.Cells[4].Value = tr.Theme;
            dgvr.Cells[5].Value = tr.Content;
            dgvr.Cells[6].Value = tr.Duration;

            if (tr.Participants.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                foreach (TrainParticipant tp in tr.Participants)
                {
                    sb.Append(tp.Department + "," + tp.Name + ";");
                }

                dgvr.Cells[7].Value = sb.ToString();
            }
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                string recordPath = Path.Combine(Application.StartupPath, CConstValues.TRAIN_RECORD_DIR_NAME);
                if (!Directory.Exists(recordPath))
                {
                    Directory.CreateDirectory(recordPath);
                }

                string[] recordPaths = Directory.GetFiles(recordPath, "*.xml");

                if (recordPaths != null && recordPaths.Length > 0)
                {
                    XmlSerializer xs = new XmlSerializer(typeof(TrainRecord));

                    foreach (string rp in recordPaths)
                    {
                        using (XmlTextReader xtr = new XmlTextReader(rp))
                        {
                            TrainRecord tr = (TrainRecord)xs.Deserialize(xtr);
                            if (tr != null)
                            {
                                dgvRecords.Rows.Add(CreateRecordDataRow(tr));

                                m_initRecords.Add(tr.Guid, tr.DeepClone());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载已有培训记录失败,错误消息位:" + ex.Message);
            }
        }
        public frmRecord(TrainRecord record)
        {
            InitializeComponent();

            m_record = record;
        }
Пример #10
0
 private void btnNextRecord_Click(object sender, EventArgs e)
 {
     m_curRecord = m_recordViewer.Change2NextRecord();
     UpdateRecordInfo(m_curRecord);
     UpdateViewRecordButtonStatus();
 }