コード例 #1
0
        private void OpenRsrcs(string file)
        {
            cRsrcs cs = new cRsrcs();

            if (cs.Deserialize(file))
            {
                // Открытие настроек:
                tbTopic.Text = cs.Options.Topic;
                // Открытие задач и нарядов:
                dgvTasks.Rows.Clear();
                for (int i = 0; i < cs.Tasks.Count; i++)
                {
                    dgvTasks.Rows[dgvTasks.Rows.Add("", cs.Tasks[i].Name, cs.Tasks[i].Group)].DefaultCellStyle.BackColor = cs.Tasks[i].Selection;
                }
                // Открытие штатки:
                dgvSoldiers.Rows.Clear();
                for (int i = 0; i < cs.Soldiers.Count; i++)
                {
                    dgvSoldiers.Rows.Add("",
                                         cs.Soldiers[i].Profession,
                                         cs.Soldiers[i].Group,
                                         cs.Soldiers[i].Category,
                                         cs.Soldiers[i].FIO,
                                         cs.Soldiers[i].Money,
                                         cs.Soldiers[i].Date,
                                         cs.Soldiers[i].Task);
                }
                // Обновление интерфейса:
                tcRsrcs.SelectedTab = tcRsrcs.TabPages[0];
                _file = file;
                UpdateCaption();
                UpdateSoldiers();
            }
        }
コード例 #2
0
        private bool SaveRsrcs(string file)
        {
            // В _file адрес, куда сохранять.
            cRsrcs          cs = new cRsrcs();
            DataGridViewRow r  = null;

            // Сохранение настроек:
            cs.Options.Topic = tbTopic.Text;
            // Сохранение штатки:
            for (int i = 0; i < dgvSoldiers.Rows.Count - 1; i++)
            {
                r = dgvSoldiers.Rows[i];
                cs.Soldiers.Add(new sSoldier((string)(r.Cells["cProfession"].Value == null ? "" : r.Cells["cProfession"].Value),
                                             (string)(r.Cells["cGroup"].Value == null ? "" : r.Cells["cGroup"].Value),
                                             (string)(r.Cells["cCategory"].Value == null ? "" : r.Cells["cCategory"].Value),
                                             (string)(r.Cells["cFIO"].Value == null ? "" : r.Cells["cFIO"].Value),
                                             (bool)(r.Cells["cMoney"].Value == null ? false : r.Cells["cMoney"].Value),
                                             (string)(r.Cells["cDate"].Value == null ? "" : r.Cells["cDate"].Value),
                                             (string)(r.Cells["cTask"].Value == null ? "" : r.Cells["cTask"].Value)));
            }
            // Сохранение задач и нарядов:
            for (int i = 0; i < dgvTasks.Rows.Count - 1; i++)
            {
                r = dgvTasks.Rows[i];
                cs.Tasks.Add(new sTask((string)(r.Cells["cName"].Value == null ? "" : r.Cells["cName"].Value),
                                       (string)(r.Cells["cTGroup"].Value == null ? "" : r.Cells["cTGroup"].Value),
                                       (Color)r.DefaultCellStyle.BackColor));
            }
            // Запись в файл:
            if (cs.Serialize(file))
            {
                _file = file;
                UpdateCaption();
                return(true);
            }
            UpdateCaption();
            return(false);
        }