Пример #1
0
        private void dateTimePicker_ValueChanged(object sender, EventArgs e)
        {
            if (Data.Count != 0)
            {
                Data.Clear();
                comboBoxTime.DataSource = null;
                sListTime.Clear();
            }
            string text = comboBoxDoc.SelectedItem.ToString();

            string[] str = text.Split((string[])null, StringSplitOptions.RemoveEmptyEntries);

            DataTable tableDoc = DBConnect.ShowDB(String.Format("SELECT ID_Doc FROM Doctors WHERE (Surname = '{0}')AND(Name = '{1}')AND(Patronymic = '{2}')AND([Position] = '{3}')", str[0], str[1], str[2], str[3]));

            if (tableDoc.Rows.Count != 0)
            {
                int       ID_Doc    = Convert.ToInt32(tableDoc.Rows[0]["ID_Doc"]);
                DataTable tableTime = DBConnect.ShowDB(String.Format("SELECT [Time] FROM Records WHERE (ID_Doc = {0}) AND (Data = DateValue('{1}')) ", ID_Doc, dateTimePicker.Value.ToShortDateString()));


                for (int i = 0; i < tableTime.Rows.Count; i++)
                {
                    sListTime.Add(Convert.ToDateTime(tableTime.Rows[i]["Time"]).ToShortTimeString());
                }
            }



            if ((dateTimePicker.Value.ToShortDateString() == DateTime.Now.ToShortDateString()) && (DateTime.Now.Hour > Convert.ToDateTime("8:00").Hour))
            {
                DateTime dateTime = Convert.ToDateTime(DateTime.Today.ToShortDateString() + "," + DateTime.Now.ToShortTimeString());
                var      interval = new TimeSpan(0, 30, 0);
                if ((dateTime.Minute / interval.Minutes) == 0)
                {
                    string newTime = (dateTime.Hour.ToString() + ":" + interval.Minutes.ToString());
                    dateTime = Convert.ToDateTime(DateTime.Today.ToShortDateString() + "," + newTime);
                }
                else
                {
                    dateTime = dateTime.AddHours(1);
                    dateTime = dateTime.AddMinutes(-dateTime.Minute);
                    dateTime = Convert.ToDateTime(DateTime.Today.ToShortDateString() + "," + dateTime.ToShortTimeString());
                }

                while (dateTime != Convert.ToDateTime(dateTimePicker.Value.ToShortDateString() + "," + "20:00"))
                {
                    if (sListTime.Contains(dateTime.ToShortTimeString()) == false)
                    {
                        Data.Add(dateTime.ToShortTimeString());
                    }
                    else
                    {
                        if (dateTime.ToShortTimeString() == time)
                        {
                            Data.Add(dateTime.ToShortTimeString());
                        }
                    }
                    dateTime = dateTime + interval;
                }
                comboBoxTime.DataSource = Data;
            }
            else
            {
                DateTime dateTime = Convert.ToDateTime(dateTimePicker.Value.ToShortDateString() + "," + "8:00");
                var      interval = new TimeSpan(0, 30, 0);
                while (dateTime != Convert.ToDateTime(dateTimePicker.Value.ToShortDateString() + "," + "20:00"))
                {
                    if (sListTime.Contains(dateTime.ToShortTimeString()) == false)
                    {
                        Data.Add(dateTime.ToShortTimeString());
                    }
                    else
                    {
                        if (dateTime.ToShortTimeString() == time)
                        {
                            Data.Add(dateTime.ToShortTimeString());
                        }
                    }
                    dateTime = dateTime + interval;
                }
                comboBoxTime.DataSource = Data;
            }
        }