SAS.ClassSet.FunctionTools.Placement.AutoSelectSpareTime C# (CSharp) 메소드

AutoSelectSpareTime() 공개 메소드

public AutoSelectSpareTime ( System.Windows.Forms.ProgressBar ProgressBar1 ) : void
ProgressBar1 System.Windows.Forms.ProgressBar
리턴 void
        public void AutoSelectSpareTime(ProgressBar ProgressBar1)
        {
            List<SupervisorInfo> supervisorname = new List<SupervisorInfo>();//存储督导信息
            List<SupervisorInfo> listsparetime = new List<SupervisorInfo>();//用于存储经过对比课程表后的督导的上课时间
            List<string> ListInsertCommand = new List<string>();
            dtClasses = helper.getDs(strSelect_Class_Data, "Classes_Data").Tables[0];
            dtSupervisor = helper.getDs(strSelect_Teachers_Data, "Teachers_Data").Tables[0];
            dtSupervisor = dtSupervisor.Select("IsSupervisor=True").CopyToDataTable();
            List<DataRow[]> DrClassesArray = new List<DataRow[]>();//一个Datarow数组代表每一周每一天每一节次所有的上课记录
            for (int i = 0; i < dtSupervisor.Rows.Count;i++ )
            {

                SupervisorInfo sp = new SupervisorInfo();
                sp.SupervisorName = dtSupervisor.Rows[i][1].ToString();
                sp.SupervisorId = dtSupervisor.Rows[i][0].ToString();
                supervisorname.Add(sp);

            }
            //分别把每一周每一天每一节的记录分开,存储在DrClassArray数组中
            for (int i = 0; i < supervisorname.Count; i++)
            {
                for (int week = 1; week < 20; week++)
                {
                    for (int day = 1; day < 6; day++)
                    {
                        for (int index = 0; index < spareclass.Count; index++)
                        {
                            DataRow[] dr = dtClasses.Select(" Class_Week=" + week + "and Class_Day=" + day + " and Class_Number=" + spareclass[index] + "and Teacher='" + supervisorname[i].SupervisorName + "'");
                            if (dr.Length==0)
                            {
                                SupervisorInfo info = new SupervisorInfo();
                                info.SupervisorName = supervisorname[i].SupervisorName.ToString();
                                info.Isassigned = false;
                                foreach(SupervisorInfo s in supervisorname)
                                {
                               if (supervisorname[i].SupervisorName.Equals(s.SupervisorName))
                                 {
                                     info.SupervisorId = s.SupervisorId;
                                     info.SpareID = info.SupervisorId + week.ToString() + day.ToString() + spareclass[index].ToString();
                                        break;

                                 }

                                }
                                if (info.SupervisorId==""||info.SpareID=="")
                                {

                                    info.SupervisorId = supervisorname[i].SupervisorName;
                                     info.SpareID = info.SupervisorId + week.ToString() + day.ToString() + spareclass[index].ToString();

                                }
                                info.SpareWeek = week;
                                info.SpareDay = day;
                                info.SpareNumber = spareclass[index];
                                listsparetime.Add(info);
                            }
                            else
                            {
                                int[] array;
                                switch (spareclass[index])
                                {
                                    case 12:
                                        index += 3;
                                        break;
                                    case 13:
                                         array=new int []{12};
                                        DeleteError(array, week, day, listsparetime);
                                        index += 4;
                                        break;
                                    case 23:
                                        array=new int []{12,13};
                                        DeleteError(array, week, day, listsparetime);
                                        index += 3;
                                        break;
                                    case 24:
                                          array=new int []{12,13,23};
                                        DeleteError(array, week, day, listsparetime);
                                        index += 3;
                                        break;
                                    case 34:
                                          array=new int []{13,23,24};
                                        DeleteError(array, week, day, listsparetime);
                                        index += 2;
                                        break;
                                    case 35:
                                          array=new int []{13,24,23,34};
                                        DeleteError(array, week, day, listsparetime);
                                        index +=1;
                                        break;
                                    case 45:
                                          array=new int []{24,34,35};
                                        DeleteError(array, week, day, listsparetime);
                                        break;
                                    case 67:
                                        index += 3;
                                        break;
                                    case 68:
                                         array=new int []{67};
                                        DeleteError(array, week, day, listsparetime);
                                        index += 3;
                                        break;
                                    case 78:
                                        array=new int []{67,68};
                                        DeleteError(array, week, day, listsparetime);
                                        index += 2;
                                        break;
                                    case 79:
                                        array=new int []{67,78,68};
                                        DeleteError(array, week, day, listsparetime);
                                        index +=1;
                                        break;
                                    case 89:
                                         array=new int []{68,79,78};
                                        DeleteError(array, week, day, listsparetime);
                                        break;
                                    case 1011:
                                        index +=2;
                                        break;
                                    case 1112:
                                         array=new int []{1011,1012};
                                        DeleteError(array, week, day, listsparetime);
                                        index +=1;
                                        break;
                                    case 1012:
                                         array=new int []{1011,1112};
                                        DeleteError(array, week, day, listsparetime);
                                        break;

                                }
                            }

                        }
                    }
                }
            }

               List<SupervisorInfo> newsupervisorlist= listsparetime.Distinct<SupervisorInfo>().ToList();

            //编写数据库插入语句
               foreach (SupervisorInfo supervisor in newsupervisorlist)
            {
             string insertcommand = string.Format(@"insert into SpareTime_Data values('{0}','{1}','{2}',{3},{4},{5},{6})", supervisor.SpareID,
                       supervisor.SupervisorId, supervisor.SupervisorName, supervisor.SpareWeek, supervisor.SpareDay, supervisor.SpareNumber, supervisor.Isassigned);
             ListInsertCommand.Add(insertcommand);
            }

            //使用数据库事务条件插入请求
            helper.insertToStockDataByBatch(ListInsertCommand, ProgressBar1);
        }

Usage Example

예제 #1
0
        private void buttonX3_Click(object sender, EventArgs e)
        {
            string deletecommand = "delete * from SpareTime_Data";
            string selectcommand = "select * from SpareTime_Data";
            DataTable dt = help.getDs(selectcommand, "SpareTime_Data").Tables[0];
            if (dt.Rows.Count != 0)
            {
                if (help.Oledbcommand(deletecommand) > 0)
                {
                    try
                    {
                        Placement selecttime = new Placement();
                        selecttime.AutoSelectSpareTime(progressBar1);
                        if (progressBar1.Value == progressBar1.Maximum)
                        {
                            MessageBox.Show("自动填补成功");
                            progressBar1.Value = 0;
                            listView1.Items.Clear();
                            ListSupervisor.Clear();
                            week.Clear();
                            strweek.Clear();
                            frmSpareTime_Load(sender, e);
                        }
                        else
                        {

                        }
                    }

                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());

                    }
                }
                else
                {
                    MessageBox.Show("请手动删除当前数据表数据");
                }
            }
            else
            {
                try
                {
                    Placement selecttime = new Placement();
                    selecttime.AutoSelectSpareTime(progressBar1);
                    if (progressBar1.Value == progressBar1.Maximum)
                    {
                        MessageBox.Show("自动填补成功");
                        progressBar1.Value = 0;
                        listView1.Items.Clear();
                        ListSupervisor.Clear();
                        week.Clear();
                        strweek.Clear();
                        frmSpareTime_Load(sender, e);
                    }
                    else
                    {

                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());

                }
            }
        }