Exemplo n.º 1
0
        /// <summary>
        /// Ask user and save an Excel sheet or something he's selected.
        /// </summary>
        /// <returns>True if exporting gone till the end.</returns>
        public static bool ExportWoman()
        {
            DateRangeForm form = new DateRangeForm();

            if (form.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter =
                TEXT.Get["Excel_files"] + " (*.xls)|*.xls|" +
                TEXT.Get["CSV_files"] + " (*.csv)|*.csv";
            dialog.RestoreDirectory             = true;
            dialog.CheckPathExists              = true;
            dialog.Title                        = TEXT.Get["Point_the_file"];
            dialog.SupportMultiDottedExtensions = true;
            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            string fileName = dialog.FileName;

            if (!fileName.EndsWith(".csv", StringComparison.OrdinalIgnoreCase) &&
                !fileName.EndsWith(".xls", StringComparison.OrdinalIgnoreCase))
            {
                MsgBox.Show(TEXT.Get["File_ext_must_to_be"], TEXT.Get["Error"]);
                return(false);
            }

            try
            {
                using (ReportWriter report = fileName.EndsWith(".csv") ?
                                             (ReportWriter)(new CsvWriter(fileName)) : (ReportWriter)(new XlsWriter(fileName)))
                {
                    report.WriteHeader();
                    for (DateTime day = form.From; day <= form.To; day = day.AddDays(1))
                    {
                        report.WriteDay(CurrentWoman.GetOneDayInfo(day));
                    }
                }
            }
            catch (Exception ex)
            {
                MsgBox.Error(TEXT.Get["Cant_export"] + "\n" + ex.Message, TEXT.Get["Error"]);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        private static void CallbackDoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var s   = GetFileStream("http://ovulyashki.dp.ua/lastversion/");
                var doc = new XmlDocument();
                doc.Load(s);
                XmlNode rootNode = doc.ChildNodes[1];
                var     release  = new Release()
                {
                    Date      = rootNode["dateadd"].InnerText,
                    FileName  = rootNode["filename"].InnerText,
                    Version   = rootNode["version"].InnerText,
                    ChangeLog = rootNode["changelog"].InnerText,
                    FileSize  = rootNode["filesize"].InnerText,
                    Downloads = rootNode["downloads"].InnerText,
                    Url       = rootNode["url"].InnerText
                };
                s.Close();

                if (release.IsItNewVersion())
                {
                    bool updateUs = false;
                    Program.ApplicationForm.Invoke(new MethodInvoker(() =>
                    {
                        updateUs = MsgBox.YesNo(release.GetFormattedText(), TEXT.Get["Ovulyashki"]);
                    }));
                    if (updateUs)
                    {
                        DownloadUpdate(release);
                    }
                }
                else
                {
                    Program.ApplicationForm.BeginInvoke(new MethodInvoker(() =>
                    {
                        MsgBox.Show(TEXT.Get["Latest_application"], TEXT.Get["Ovulyashki"]);
                    }));
                }
            }
            catch (Exception ex)
            {
                Program.ApplicationForm.BeginInvoke(new MethodInvoker(() =>
                {
                    MsgBox.Error(TEXT.Get.Format("Unable_to_update", ex.Message), TEXT.Get["Error"]);
                }));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves a woman to the given path.
        /// </summary>
        /// <param name="w">Woman to save.</param>
        /// <param name="path"><Path to the new/overwritten file./param>
        /// <returns>True if file successfully saved.</returns>
        public static bool SaveWomanTo(Woman w, string path)
        {
            try
            {
                // Serialize to memory stream to make sure data is serializable.
                var saveMemoryStream   = new MemoryStream();
                var testSaveDataStream = new BZip2OutputStream(saveMemoryStream, 9);

                // Make sure serialization goes well.
                new XmlSerializer(w.GetType()).Serialize(testSaveDataStream, w);
                testSaveDataStream.Close();
                var data = saveMemoryStream.ToArray();

                testSaveDataStream.Close();

                // Dispose resources.
                saveMemoryStream.Dispose();
                testSaveDataStream.Dispose();

                // Prepare to read the saved data.
                var loadMemoryStream   = new MemoryStream(data);
                var testLoadDataStream = new BZip2InputStream(loadMemoryStream);

                // Make sure we can read it back.
                new XmlSerializer(typeof(Woman)).Deserialize(testLoadDataStream);
                testLoadDataStream.Close();

                // Dispose resources.
                loadMemoryStream.Dispose();
                testLoadDataStream.Dispose();

                // Make sure we have access to the file system.
                var filestream = new FileStream(path, FileMode.Create);

                // Save to file.
                filestream.Write(data, 0, data.Length);
                filestream.Close();
            }
            catch (Exception ex)
            {
                MsgBox.Error(TEXT.Get["Unable_to_save_file"] + ex.Message, TEXT.Get["Error"]);
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        void calendarItem_Click(object sender, EventArgs e)
        {
            var dic  = ((sender as ToolStripDropDownItem).Tag as Dictionary <int, string>);
            var week = Program.CurrentWoman.Conceptions.GetPregnancyWeekNumber(FocusDate);

            if (dic.ContainsKey(week))
            {
                var url = dic[week];
                try
                {
                    Process.Start(url);
                }
                catch
                {
                    MsgBox.Error(TEXT.Get["Unable_to_start_browser"] + url, TEXT.Get["Error"]);
                }
            }
        }