Esempio n. 1
0
        //Try to create new item, returns null if unsuccesful, sets Setting.DiaryDirectory
        private Diary tryCreateNewDiary()
        {
            Diary  newDiary  = new Diary();
            string directory = "";

            DiarySettings fds = new DiarySettings(newDiary);

            fds.ShowDialog();
            if (fds.DialogResult == DialogResult.OK)
            {
                if (saveDialogDiary.ShowDialog() == DialogResult.OK)
                {
                    directory          = saveDialogDiary.FileName;
                    newDiary.Directory = directory;
                }
            }

            try
            {
                newDiary = Diary.Load(directory);
            }
            catch
            {
                return(null);
            }

            Settings.Settings.SettingsHolder.DiaryDirectory = directory;
            return(newDiary);
        }
Esempio n. 2
0
        private void LoadDiary()
        {
            Diary newDiary = null;

            try
            {
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.InitialDirectory = Settings.Settings.SettingsHolder.DiaryDirectory; //todo
                dlg.Filter           = "Deníky (*.pkl)|*.pkl";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    newDiary = Diary.Load(dlg.FileName);
                }
            }
            catch
            {
                MessageBox.Show("Zadaný deník se nepodařilo otevřít.", "Chyba");
                return;
            }

            if (newDiary != null)
            {
                m_mainDiary.Clone(newDiary);
            }

            EnsureRecordVisibility(m_mainDiary.RecordsCount - 1);
            UpdateCurrentPage();
        }
Esempio n. 3
0
        public void LoadSettings()
        {
            //string directory = Storage.readString("Directory");
            Settings.Settings.Load();
            Rectangle winRec        = Settings.Settings.SettingsHolder.MainWindowPos;
            Screen    scr           = Screen.FromRectangle(winRec);
            Rectangle monitorBounds = scr.Bounds;

            Diary newDiary = null;

            if (monitorBounds.IntersectsWith(winRec) && winRec.Width > 100 && winRec.Height > 100)
            {
                this.Bounds = winRec;
            }

            //Should be done after setting correct width of the window
            float[] columnsWidth = Settings.Settings.SettingsHolder.ColumnsWidths;
            if (columnsWidth != null && columnsWidth.Length == gridHistory.ColumnCount)
            {
                for (int col = 0; col < gridHistory.ColumnCount; col++)
                {
                    if (columnsWidth[col] > 0)
                    {
                        gridHistory.Columns[col].FillWeight = columnsWidth[col];
                    }
                }
            }
            List <IncomeTemplatesHolder.Template> incomeTemplates = Settings.Settings.SettingsHolder.incomeTemplates();

            templatesPanel.Controls.Clear();
            ToolTip ttip = new ToolTip();

            for (int i = 0; i < incomeTemplates.Count; i++)
            {
                Button btn = new Button();
                btn.Text     = incomeTemplates[i].m_name.Replace(" ", " ");
                btn.Tag      = i;
                btn.Width    = 100;
                btn.MouseUp += new MouseEventHandler(TemplateButtonClick);
                ttip.SetToolTip(btn, "Klikněte pravým tlačítkem pro smazání " + btn.Text);
                templatesPanel.Controls.Add(btn);
            }


            do
            {
                /*  directory = "";
                 *
                 * try
                 * {
                 *    XmlReaderSettings settings = new XmlReaderSettings();
                 *    using (XmlReader reader = XmlReader.Create(settingsFile, settings))
                 *    {
                 *        reader.ReadStartElement("DiarySettings");
                 *        directory = reader.ReadElementString("Directory");
                 *        reader.ReadEndElement();
                 *    }
                 * }
                 * catch { }*/

                if (Settings.Settings.SettingsHolder.DiaryDirectory == "")
                {
                    initFailureForm fform = new initFailureForm();
                    fform.ShowDialog();
                    if (fform.Result == initFailureForm.InitFailureResults.Cancel)
                    {
                        Application.Exit();    //todo lepeji ukoncit!!
                        return;
                    }
                    else if (fform.Result == initFailureForm.InitFailureResults.Open)
                    {
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.InitialDirectory = Settings.Settings.SettingsHolder.DiaryDirectory; //todo
                        dlg.Filter           = "Deníky (*.pkl)|*.pkl";
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            Settings.Settings.SettingsHolder.DiaryDirectory = dlg.FileName;
                        }
                    }
                    else
                    {
                        tryCreateNewDiary();
                    }
                }
                try
                {
                    newDiary = Diary.Load(Settings.Settings.SettingsHolder.DiaryDirectory);
                }
                catch
                {
                    MessageBox.Show("Zadaný deník se nepodařilo otevřít.", "Chyba");
                    Settings.Settings.SettingsHolder.DiaryDirectory = "";
                }
            } while (Settings.Settings.SettingsHolder.DiaryDirectory == "");

            m_mainDiary.Clone(newDiary);
            EnsureRecordVisibility(m_mainDiary.RecordsCount - 1);
        }