Example #1
0
        //输入员工号获取工具
        private void gettool_Click(object sender, EventArgs e)
        {
            var stuffGet = PublicMethods.transferToInt(StuffNo.Text);

            if (stuffGet != -1)
            {
                var toolGet = stuffUsingTool.First(p => p.stuff == PublicMethods.transferToInt(StuffNo.Text));
                if (stuffAndToolOnWork.Where(p => p.stuff == toolGet.stuff).Any())
                {
                    MessageBox.Show("您已经处于工作状态!");
                    return;
                }
                if (!toolWaiting.Any())
                {
                    var rd           = PublicMethods.getRandomNumber(0, 199);
                    var stuffAndTool = stuffAndToolOnWork[rd];
                    stuffAndToolOnWork.RemoveAt(rd);
                    toolWaiting.Remove(stuffAndTool.using_tool);
                    MessageBox.Show(stuffAndTool.stuff + "号工人因满员而强制下班!");
                }
                if (toolWaiting.Contains(toolGet.using_tool))
                {
                    MessageBox.Show(toolGet.using_tool + "号工具给你使用");
                    toolWaiting.Remove(toolGet.using_tool);
                    var temp = new Stuff_using_tool();
                    temp.stuff      = stuffGet;
                    temp.using_tool = toolGet.using_tool;
                    stuffAndToolOnWork.Add(temp);
                }
                else
                {
                    //工人熟悉工具在使用,就分配一个默认使用它的人数最少的工具,并且将此工人的默认使用工具改成此工具
                    var toolUseList = stuffUsingTool.GroupBy(p => p.using_tool).OrderBy(p => p.Count()).Select(p => new { tool = p.Key, useNumber = p.Count() }).ToList();
                    for (int i = 0; i < 200; i++)
                    {
                        //如果此工具空闲,则交付工人使用
                        if (toolWaiting.Contains(toolUseList[i].tool))
                        {
                            var temp = new Stuff_using_tool();
                            temp.stuff      = stuffGet;
                            temp.using_tool = toolUseList[i].tool;
                            stuffAndToolOnWork.Add(temp);            //添加工作中的工人工具编号
                            toolWaiting.Remove(toolUseList[i].tool); //移除该空闲工具
                            stuffUsingTool.Remove(toolGet);          //移除旧的工人熟练使用的工具号
                            //添加新的工人熟练使用的工具号
                            stuffUsingTool.Insert(stuffGet, new Stuff_using_tool {
                                stuff = stuffGet, using_tool = toolUseList[i].tool
                            });
                            MessageBox.Show(toolUseList[i].tool + "号工具给你临时使用,请熟悉此工具");
                            break;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("员工号不正确!");
            }
        }
Example #2
0
        //
        private void returntool_Click(object sender, EventArgs e)
        {
            var toolGet = PublicMethods.transferToInt(ToolNo.Text);

            if (toolGet != -1)
            {
                var stuffNo = stuffAndToolOnWork.FirstOrDefault(p => p.using_tool == toolGet);
                if (stuffNo != null)
                {
                    toolWaiting.Add(toolGet);
                    stuffAndToolOnWork.Remove(stuffAndToolOnWork.First(p => p.using_tool == toolGet));
                    MessageBox.Show(stuffNo.stuff + "号工人下班," + toolGet + "号工具已归还");
                }
                else
                {
                    MessageBox.Show("请勿重复下班!");
                }
            }
            else
            {
                MessageBox.Show("工具号不正确!");
            }
        }