Beispiel #1
0
 private void calendar1_DoubleClick(object sender, EventArgs e)
 {
     CalendarControl.Schedule item = new CalendarControl.Schedule();
     item.Start = calendar1.SelectedDate;
     item.Item  = calendar1.SelectedDate.ToString() + "追加";
     calendar1.AddSchedule(item);
 }
Beispiel #2
0
        private void CreateStandby()
        {
            calendar1.RemoveMonth(calendar1.DrawYear, calendar1.DrawMonth);
            StandbyList.StandbyList st = Core.StandbyLists.FirstOrDefault(t => t.Year == calendar1.Year && t.Month == calendar1.Month);
            if (st == null)
            {
                return;
            }

            StandbyList.StandbyPersons[]        sp;
            List <StandbyList.StandbyPersons[]> tmpsp = new List <StandbyPersons[]>();
            int count = 0;

            while (true)
            {
                count++;
                st.Create();
                sp = st.Standby;
                tmpsp.Add(sp);
                if (sp.All(p => p.Judge()) || count >= Setting.TryCount)
                {
                    if (count >= Setting.TryCount)
                    {
                        MessageBox.Show(count.ToString() + "通りの組合せを検討した結果、条件を満たす組合せが見つかりませんでした。最適と考えられる組合せを表示します。" +
                                        "必要であれば「設定」から個人の必要条件を変更の上、再度お試し下さい。");
                        StandbyPersons[] most = null;
                        int nullcount         = DateTime.DaysInMonth(calendar1.DrawYear, calendar1.DrawMonth) * 2;
                        tmpsp.ForEach(t =>
                        {
                            if (most == null)
                            {
                                most = t;
                            }
                            else
                            {
                                int c = t.ToList().Sum(u => u.NullCount());
                                if (nullcount >= c)
                                {
                                    most      = t;
                                    nullcount = c;
                                }
                            }
                        });
                        st.Standby = most;
                    }
                    //var stold = Core.StandbyLists.FirstOrDefault(t => t.Year == st.Year && t.Month == st.Month);
                    //if (stold != null)
                    //{
                    //	Core.StandbyLists.Remove(stold);
                    //}
                    //Core.StandbyLists.Add(st);
                    //Core.Sort();
                    break;
                }
            }
            sp = st.Standby;
            for (int i = 0; i < sp.Count(); i++)
            {
                CalendarControl.Schedule item = new CalendarControl.Schedule();
                item.Start = new DateTime(calendar1.DrawYear, calendar1.DrawMonth, i + 1);
                item.Item  = sp[i].First;
                if (sp[i].First != null)
                {
                    var status = sp[i].First.Possible.First(t => t.Year == calendar1.DrawYear && t.Month == calendar1.DrawMonth).PossibleDay[i];
                    if (status == StandbyList.PossibleDays.Status.Duty)
                    {
                        item.ForeColor = Setting.DutyColor;
                    }
                }
                item.Description = "1st";
                item.BackColor   = Setting.FirstColor;
                item.Alignment   = StringAlignment.Center;
                calendar1.AddSchedule(item);

                CalendarControl.Schedule item2 = new CalendarControl.Schedule();
                item2.Start = new DateTime(calendar1.DrawYear, calendar1.DrawMonth, i + 1);

                item2.Item        = sp[i].Second;
                item2.BackColor   = Setting.SecondColor;
                item2.Alignment   = StringAlignment.Center;
                item2.Description = "2nd";
                calendar1.AddSchedule(item2);

                CalendarControl.Schedule item3 = new CalendarControl.Schedule();
                item3.Start       = new DateTime(calendar1.DrawYear, calendar1.DrawMonth, i + 1);
                item3.Item        = sp[i].Third;
                item3.BackColor   = Setting.ThirdColor;
                item3.Alignment   = StringAlignment.Center;
                item3.Description = "3rd";
                calendar1.AddSchedule(item3);

                CalendarControl.Schedule item4 = new CalendarControl.Schedule();
                item4.Start       = new DateTime(calendar1.DrawYear, calendar1.DrawMonth, i + 1);
                item4.Item        = sp[i].PCI;
                item4.BackColor   = Setting.PCIColor;
                item4.Alignment   = StringAlignment.Center;
                item4.Description = "PCI";
                calendar1.AddSchedule(item4);
            }
            PersonsAggregation();
        }
Beispiel #3
0
        private void CreateStandby()
        {
            calendar1.RemoveMonth(calendar1.DrawYear, calendar1.DrawMonth);
            StandbyList.StandbyList st = Core.StandbyLists.FirstOrDefault(t => t.Year == calendar1.Year && t.Month == calendar1.Month);
            if (st == null)
            {
                return;
            }
            st.CreateEmpty();             // 現在のデータを初期化する。

            List <StandbyList.StandbyList> tmpsp = new List <StandbyList.StandbyList>();
            List <double> listbunsan             = new List <double>();
            List <double> listbunsanh            = new List <double>();
            List <double> listbunsant            = new List <double>();
            int           count = 0;
            int           index = 0;

            StandbyList.StandbyList most = null;

            while (true)
            {
                count++;
                st.Create(Core.StandbyLists);

                tmpsp.Add(st.Clone() as StandbyList.StandbyList);
                st.Clear();
                // *分散を求めて、最も分散が小さいものを選択。(平日の当直回数のバラツキが最も少ないものを選択)
                double dutycount    = 0;
                double holidaycount = 0;
                double totalcount   = 0;
                st.Persons.ForEach(t =>
                {
                    dutycount    += st.OrdinaryDutyCount(t);
                    holidaycount += st.HolidayCount(t);
                    totalcount   += st.DutyCount(t);
                });
                double dutyaverage    = dutycount / st.Persons.Count;
                double holidayaverage = holidaycount / st.Persons.Count;
                double totalaverage   = totalcount / st.Persons.Count;

                double dutybunsan    = 0;
                double holidaybunsan = 0; // 今の所、こちらは使わない。
                double totalbunsan   = 0;

                st.Persons.ForEach(t =>
                {
                    dutybunsan    += Math.Pow((dutyaverage - st.OrdinaryDutyCount(t)), 2);
                    holidaybunsan += Math.Pow((holidayaverage - st.HolidayCount(t)), 2);
                    totalbunsan   += Math.Pow((totalaverage - st.DutyCount(t)), 2);
                });

                listbunsan.Add(dutybunsan);
                listbunsanh.Add(holidaybunsan);
                listbunsant.Add(totalbunsan);
                // *ここまで
                if (count >= 1000 /*Setting.TryCount*/)
                {
                    int nullcount = DateTime.DaysInMonth(calendar1.DrawYear, calendar1.DrawMonth);
                    tmpsp.ForEach(t =>
                    {
                        if (most == null)
                        {
                            most = t;
                        }
                        else
                        {
                            int c = t.Standby.NullCount();
                            if (nullcount >= c)
                            {
                                most      = t;
                                nullcount = c;
                            }
                        }
                    });


                    break;
                }
            }
            while (tmpsp.Count > 0)
            {
                double min = listbunsant.Min(); // 求めた分散の中で最も小さいものを選別。
                index = listbunsant.IndexOf(min);
                // 分散で選んだ予定表候補に抜けがないかをチェック。抜けがある場合はリストから削除し、再度最小の分散を選択する。
                if (tmpsp[index].Standby.NullCheck())
                {
                    Core.StandbyLists.Remove(st);
                    Core.StandbyLists.Add(tmpsp[index]);
                    break;
                }
                else
                {
                    tmpsp.RemoveAt(index);
                    listbunsant.RemoveAt(index);
                }
            }
            // 抜けのない予定表候補が見つからない場合はあきらめる。
            if (tmpsp.Count == 0)
            {
                MessageBox.Show(count.ToString() + "通りの組合せを検討した結果、条件を満たす組合せが見つかりませんでした。" +
                                "「設定」から個人の必要条件を変更の上、再度お試し下さい。");
                Core.StandbyLists.Remove(st);
                Core.StandbyLists.Add(most);
                //st = most;
            }
            // カレンダーへの表示処理
            StandbyList.StandbyList resultlist = Core.StandbyLists.FirstOrDefault(t => t.Year == calendar1.Year && t.Month == calendar1.Month);
            for (int i = 0; i < resultlist.Standby.Count; i++)
            {
                CalendarControl.Schedule item = new CalendarControl.Schedule();
                item.Start = new DateTime(calendar1.DrawYear, calendar1.DrawMonth, i + 1);
                item.Item  = resultlist.Standby[i + 1];
                if (resultlist.Standby[i + 1] != null)
                {
                    // これは削除可能?
                    var status = resultlist.Standby[i + 1].Possible.First(t => t.Year == calendar1.DrawYear && t.Month == calendar1.DrawMonth).PossibleDay[i];
                }
                item.Description = "duty";
                item.BackColor   = Setting.DutyFieldColor;
                item.Alignment   = StringAlignment.Center;
                calendar1.AddSchedule(item);
            }
            // 集計
            ShowAgrregationForm();
        }