Exemplo n.º 1
0
        string getStatus(DateItem date)
        {
            string   status = date.FormatText;
            DateTime now    = DateTime.Now;
            var      delta  = date.Date - now;

            status = status.Replace("%yD", date.Date.Year.ToString());
            status = status.Replace("%dD", date.Date.Day.ToString());
            status = status.Replace("%hD", date.Date.Hour.ToString());
            status = status.Replace("%mD", date.Date.Minute.ToString());
            status = status.Replace("%sD", date.Date.Second.ToString());

            status = status.Replace("%yN", now.Year.ToString());
            status = status.Replace("%dN", now.Day.ToString());
            status = status.Replace("%hN", now.Hour.ToString());
            status = status.Replace("%mN", now.Minute.ToString());
            status = status.Replace("%sN", now.Second.ToString());

            status = status.Replace("%yT", (int)delta.TotalDays / 365 > 0 ? Dict.Years((int)(delta.TotalDays / 365)) : "");
            status = status.Replace("%dT", (int)delta.TotalDays % 365 > 0 ? Dict.Days((int)delta.TotalDays % 365) : "");
            status = status.Replace("%hT", (int)delta.TotalHours % 24 > 0 ? Dict.Hours((int)delta.TotalHours % 24) : "");
            status = status.Replace("%mT", (int)delta.TotalMinutes % 60 > 0 ? Dict.Minutes((int)delta.TotalMinutes % 60) : "");
            status = status.Replace("%sT", (int)delta.TotalSeconds % 60 > 0 ? Dict.Seconds((int)delta.TotalSeconds % 60) : "");

            status = status.Replace("%yT", (int)delta.TotalDays / 365 > 0 ? ((int)(delta.TotalDays / 365)).ToString() : "");
            status = status.Replace("%dT", (int)delta.TotalDays % 365 > 0 ? ((int)delta.TotalDays % 365).ToString() : "");
            status = status.Replace("%hT", (int)delta.TotalHours % 24 > 0 ? ((int)delta.TotalHours % 24).ToString() : "");
            status = status.Replace("%mT", (int)delta.TotalMinutes % 60 > 0 ? ((int)delta.TotalMinutes % 60).ToString() : "");
            status = status.Replace("%sT", (int)delta.TotalSeconds % 60 > 0 ? ((int)delta.TotalSeconds % 60).ToString() : "");

            status.Replace("  ", " ");
            return(status);
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex != -1)
            {
                settings.Dates[listBox1.SelectedIndex].Name       = textBox1.Text;
                settings.Dates[listBox1.SelectedIndex].FormatText = textBox2.Text;
                settings.Dates[listBox1.SelectedIndex].Date       = dateTimePicker1.Value;
                settings.Dates[listBox1.SelectedIndex].Repeat     = checkBox1.Checked;

                File.WriteAllText(appData + @"\CustomStatus\Settings.json", JsonConvert.SerializeObject(settings));
                listBox1.Items[listBox1.SelectedIndex] = textBox1.Text;

                listBox1.SelectedIndex = -1;
                textBox1.Text          = textBox2.Text = "";
                dateTimePicker1.Value  = DateTime.Now;
                checkBox1.Checked      = false;
            }
            else
            {
                if (!String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrEmpty(textBox2.Text) && DateTime.Now < dateTimePicker1.Value)
                {
                    DateItem dateItem = new DateItem();
                    dateItem.Name       = textBox1.Text;
                    dateItem.FormatText = textBox2.Text;
                    dateItem.Date       = dateTimePicker1.Value;
                    dateItem.Repeat     = checkBox1.Checked;

                    foreach (var date in settings.Dates)
                    {
                        if (date.Date > dateItem.Date)
                        {
                            settings.Dates.Insert(settings.Dates.IndexOf(date) + 1, dateItem);
                            break;
                        }
                    }
                    if (settings.Dates.Count == 0)
                    {
                        settings.Dates.Insert(0, dateItem);
                    }

                    File.WriteAllText(appData + @"\CustomStatus\Settings.json", JsonConvert.SerializeObject(settings));
                    listBox1.Items.Insert(settings.Dates.IndexOf(dateItem), textBox1.Text);

                    textBox1.Text         = textBox2.Text = "";
                    dateTimePicker1.Value = DateTime.Now;
                    checkBox1.Checked     = false;
                }
                else
                {
                    MessageBox.Show("Ошибка заполнения полей!", "CustomStatus");
                }
            }
        }