Beispiel #1
0
        private void TimerEndTime_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            BeginInvoke(new MethodInvoker(delegate
            {
                if (btEnd.Text == "Для фиксации, удерживай 2 сек.")
                {
                    IReadOnlyCollection <TimeZoneInfo> timeZoneInfos = TimeZoneInfo.GetSystemTimeZones();
                    if (Tabel_client.Properties.Settings.Default.selectedTimeZone == "")
                    {
                        btEnd.Text = DateTime.Now.ToString();
                        Tabel_client.Properties.Settings.Default.dtEndFix = DateTime.Now;
                    }
                    else
                    {
                        TimeZoneInfo obj = timeZoneInfos.ElementAt(Convert.ToInt32(Tabel_client.Properties.Settings.Default.selectedTimeZone));
                        DateTime dt      = TimeZoneInfo.ConvertTime(DateTime.Now, obj);
                        btEnd.Text       = dt.ToString();
                        Tabel_client.Properties.Settings.Default.dtEndFix = dt;
                    }
                    Tabel_client.Properties.Settings.Default.Save();
                    btEnd.Enabled       = false;
                    cbCity.Enabled      = false;
                    cbPGVR.Enabled      = false;
                    cbSpecCheck.Enabled = false;
                    tbSpecAchiv.Enabled = false;
                    btAddPGVR.Enabled   = false;

                    db.year      = DateTime.Parse(btStart.Text).Year;
                    db.month     = DateTime.Parse(btStart.Text).Month;
                    db.day       = DateTime.Parse(btStart.Text).Day;
                    db.hStart    = DateTime.Parse(btStart.Text).Hour;
                    db.minStart  = DateTime.Parse(btStart.Text).Minute;
                    db.hEnd      = DateTime.Parse(btEnd.Text).Hour;
                    db.minEnd    = DateTime.Parse(btEnd.Text).Minute;
                    db.specCheck = cbSpecCheck.Text;
                    db.specAchiv = tbSpecAchiv.Text;
                    db.city      = cbCity.Text;
                    db.AddAllRows();
                    timerEndTime.Stop();
                    this.Close();
                }
            }));
        }
Beispiel #2
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            db.AddCity(cbCity.Text);
            int lastday;

            if (dataGridViewDB.RowCount == 1)
            {
                lastday = 0;
            }
            else
            {
                lastday = (Convert.ToDateTime(dataGridViewDB[0, dataGridViewDB.RowCount - 2].Value)).Day;
            }

            if (((lastday == 0) & (dtMain.Value.Day == 1)) || (dtMain.Value.Day == lastday + 1))
            {
                db.year      = dtMain.Value.Year;
                db.month     = dtMain.Value.Month;
                db.day       = dtMain.Value.Day;
                db.hStart    = dtStart.Value.Hour;
                db.minStart  = dtStart.Value.Minute;
                db.hEnd      = dtEnd.Value.Hour;
                db.minEnd    = dtEnd.Value.Minute;
                db.specCheck = cbSpec.Text;
                db.specAchiv = tbSpecAch.Text;
                db.city      = cbCity.Text;
                db.AddAllRows();
                dataGridViewDB.Rows.Clear();

                cbCity.DataSource    = db.GetTableCity();
                cbCity.DisplayMember = "City";

                List <OneDayData> Rows = db.GetTable(dtMain.Value.Year, dtMain.Value.Month);
                int i = 0;
                Rows.ForEach(q =>
                {
                    TimeSpan dinnerHour = new TimeSpan(0, 48, 0);
                    if (q.specCheck == "ком." || db.HoliIsThisDay(dtMain.Value.Year, dtMain.Value.Month, q.daynumber.Day) == true)
                    {
                        dinnerHour = new TimeSpan(0, 0, 0);
                    }
                    else
                    {
                        dinnerHour = new TimeSpan(0, 48, 0);
                    }

                    if (q.dayDuration.Duration() < dinnerHour)
                    {
                        dataGridViewDB.Rows.Add(q.daynumber.ToShortDateString(), q.city, q.specCheck, q.startday.ToShortTimeString(), q.endday.ToShortTimeString(), q.achiv, q.dayDuration.Duration());
                    }
                    else
                    {
                        dataGridViewDB.Rows.Add(q.daynumber.ToShortDateString(), q.city, q.specCheck, q.startday.ToShortTimeString(), q.endday.ToShortTimeString(), q.achiv, q.dayDuration.Duration() - dinnerHour);
                    }

                    if (db.HoliIsThisDay(dtMain.Value.Year, dtMain.Value.Month, q.daynumber.Day) == true)
                    {
                        dataGridViewDB.Rows[i].DefaultCellStyle.BackColor = Color.LightSkyBlue;
                    }
                    else
                    {
                    }
                    i++;
                });
                dataGridViewDB.Rows[dataGridViewDB.Rows.Count - 1].Selected = true;
                if (dtMain.Value.Day < DateTime.DaysInMonth(dtMain.Value.Year, dtMain.Value.Month))
                {
                    dtMain.Value = new DateTime(dtMain.Value.Year, dtMain.Value.Month, dtMain.Value.Day + 1);
                }

                if (db.HoliIsThisDay(dtMain.Value.Year, dtMain.Value.Month, dtMain.Value.Day) == true)
                {
                    dtStart.Value  = new DateTime(1753, 1, 1, 0, 0, 0);
                    dtEnd.Value    = new DateTime(1753, 1, 1, 0, 0, 0);
                    tbSpecAch.Text = "";
                    cbCity.Text    = Tabel_client.Properties.Settings.Default.city;
                    cbSpec.Text    = Tabel_client.Properties.Settings.Default.specCheck;
                }
                else
                {
                    dtStart.Value  = new DateTime(1753, 1, 1, Tabel_client.Properties.Settings.Default.hStart, Tabel_client.Properties.Settings.Default.minStart, 0);
                    dtEnd.Value    = new DateTime(1753, 1, 1, Tabel_client.Properties.Settings.Default.hEnd, Tabel_client.Properties.Settings.Default.minEnd, 0);
                    cbCity.Text    = Tabel_client.Properties.Settings.Default.city;
                    cbSpec.Text    = Tabel_client.Properties.Settings.Default.specCheck;
                    tbSpecAch.Text = Tabel_client.Properties.Settings.Default.specAchiv;
                }
            }
            else if (lastday == DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month))
            {
                MessageBox.Show("Табель текущего месяца закончен");
            }
            else
            {
                MessageBox.Show("Неверная последовательность заполения табеля! " + "\r \n" + "          Дни вводятся строго последовательно!");
            }

            //cbCity.SelectedIndex = Tabel_client.Properties.Settings.Default.cityIndex;
        }