예제 #1
0
        private void InitTest(Wrappers.Test fromLoadTest, Test toTest)
        {
            List <Task> listTasksInTest = new List <Task> ();
            Dictionary <Task, List <Title> > rtbInTask             = new Dictionary <Task, List <Title> > ();
            Dictionary <Task, List <PictureBoxScalable> > pbInTask = new Dictionary <Task, List <PictureBoxScalable> > ();
            Dictionary <Task, List <TextContainer> >      tbInTask = new Dictionary <Task, List <TextContainer> > ();
            List <Panel> listPanelTasks = new List <Panel> ();

            //Dictionary<Task, List<Label>> _listTBLabels = new Dictionary<Task, List<Label>> ();

            foreach (Task paneltask in fromLoadTest.Tasks)
            {
                //int textBoxNumber = 0;
                rtbInTask.Add(paneltask, new List <Title>());
                pbInTask.Add(paneltask, new List <PictureBoxScalable>());
                tbInTask.Add(paneltask, new List <TextContainer>());
                //_listTBLabels.Add(paneltask, new List<Label> ());

                listTasksInTest.Add(paneltask);

                foreach (TaskElement taskElem in paneltask.TaskElements)
                {
                    if (taskElem.Type.Equals("RichTextBox"))
                    {
                        Title bufTitle = new Title(taskElem.Name)
                        {
                            Instance =
                            {
                                Height   = taskElem.Height,
                                Width    = taskElem.Width,
                                Location = taskElem.Point,
                                Text     = taskElem.Text,
                                Font     = new Font("Microsoft Sans Serif", 15.75F, FontStyle.Regular, GraphicsUnit.Point, 204),
                            }
                        };
                        rtbInTask[paneltask].Add(bufTitle);
                    }

                    if (taskElem.Type.Equals("PictureBox"))
                    {
                        using (var stream = File.Open(new DynamicParams().GetPath() + "\\" + taskElem.Media, FileMode.Open))
                        {
                            var ms = new MemoryStream((int)stream.Length);
                            stream.CopyTo(ms);
                            ms.Position = 0;
                            PictureBoxScalable bufPbs = new PictureBoxScalable(taskElem.Name)
                            {
                                Instance =
                                {
                                    Size     = new Size(taskElem.Width, taskElem.Height),
                                    Image    = new Bitmap(ms),
                                    Location = taskElem.Point
                                }
                            };
                            pbInTask[paneltask].Add(bufPbs);
                        }
                    }

                    if (taskElem.Type.Equals("TextBox"))
                    {
                        TextContainer bufTc = new TextContainer(taskElem.Name)
                        {
                            Instance =
                            {
                                Height   = taskElem.Height,
                                Width    = taskElem.Width,
                                Location = taskElem.Point,
                                Text     = taskElem.Answer,
                                TabIndex = taskElem.Index
                            }
                        };
                        tbInTask[paneltask].Insert(0, bufTc);
                    }
                }
            }

            foreach (Task task in listTasksInTest)
            {
                var indexLabel = 1;
                var buf1       = new Panel
                {
                    BackColor = SystemColors.ControlDark,
                    Location  = new Point(0, 0),
                    Name      = task.Name,
                    Size      = new Size(1110, 618),
                    TabIndex  = 0
                };
                listPanelTasks.Add(buf1);

                //Добавление панели с заданием

                var panelQestionFoo = new Panel
                {
                    BackColor  = SystemColors.GradientInactiveCaption,
                    Location   = new Point(5, 5),
                    Name       = "panelQuestion",
                    Size       = new Size(761, 610),
                    TabIndex   = 0,
                    AutoScroll = true,
                    AllowDrop  = true
                };

                panelQestionFoo.DragEnter += toTest.panelQuestion_DragEnter;
                panelQestionFoo.DragDrop  += toTest.panelQuestion_DragDrop;

                toTest.createPasteFunc(panelQestionFoo);

                foreach (var pb in pbInTask[task])
                {
                    pb.setParent(panelQestionFoo);
                    panelQestionFoo.Controls.Add(pb.Instance);
                    ControlMover.Add(pb.Instance);
                    pb.Instance.SizeMode = PictureBoxSizeMode.StretchImage;
                }



                int j = tbInTask[task].Count;
                foreach (TextContainer tb in tbInTask[task])
                {
                    tb.Instance.Name = "TextBox, Text: " + j;
                    tb.setParent(panelQestionFoo);
                    tb.AddAnswerTitle(tb.Instance.TabIndex);
                    panelQestionFoo.Controls.Add(tb.Instance);
                    tb.Instance.BringToFront();
                    ControlMover.Add(tb.Instance);

                    indexLabel++;


                    TbList.Add(tb.Instance);
                    j--;
                }

                foreach (Title rtb in rtbInTask[task])
                {
                    rtb.setParent(panelQestionFoo);
                    panelQestionFoo.Controls.Add(rtb.Instance);
                    ControlMover.Add(rtb.Instance);
                    rtb.Instance.BringToFront();
                }



                listPanelTasks[listPanelTasks.Count - 1].Controls.Add(panelQestionFoo);
                toTest.Controls.Find("panelMiddle", true)[0].Controls.Add(listPanelTasks[listPanelTasks.Count - 1]);

                PanelWrapper bufPw = new PanelWrapper
                {
                    Entity       = listPanelTasks[listPanelTasks.Count - 1],
                    Identifier   = indexLabel,
                    PictureIndex = pbInTask[task].Count
                };
                indexLabel++;

                var bufLl = toTest.createLinkLabel(listPanelTasks.Count - 1);

                bufPw.Entity.Name = bufLl.Text;

                toTest.ListPanelsTasks.Add(bufLl, bufPw);
                toTest.LinkLabelButtonDel.Add(bufLl, toTest.createButtonDelTask(listPanelTasks.Count - 1));


                PanelWrapper bufPw2 = new PanelWrapper {
                    Entity = panelQestionFoo
                };
                toTest._currentPanelQuestion = bufPw2;
            }


            Control currentPanelListOfTasks = toTest.Controls.Find("panelListOfTasks", true)[0];


            toTest.ListPanelsTasks.Remove((LinkLabel)currentPanelListOfTasks.Controls[1]);
            toTest.LinkLabelButtonDel.Remove((LinkLabel)currentPanelListOfTasks.Controls[1]);

            currentPanelListOfTasks.Controls.Remove(currentPanelListOfTasks.Controls[1]);
            currentPanelListOfTasks.Controls.Remove(currentPanelListOfTasks.Controls[1]);

            toTest._currentTask = toTest.ListPanelsTasks[(LinkLabel)(toTest.Controls.Find("panelListOfTasks", true)[0].Controls[1])];
            toTest._currentPanelQuestion.Entity = (Panel)toTest._currentTask.Entity.Controls.Find("panelQuestion", true)[0];
        }
예제 #2
0
파일: FormHello.cs 프로젝트: Voenkaff/Test
        private void initTest(Wrappers.Test fromLoadTest, Test toTest)
        {
            List <Task> _listTasksInTest = new List <Task> {
            };
            Dictionary <Task, List <Title> > _RTBInTask             = new Dictionary <Task, List <Title> > {
            };
            Dictionary <Task, List <PictureBoxScalable> > _PBInTask = new Dictionary <Task, List <PictureBoxScalable> > {
            };
            Dictionary <Task, List <TextContainer> > _TBInTask      = new Dictionary <Task, List <TextContainer> > {
            };
            List <Panel> _listPanelTasks = new List <Panel> {
            };

            //Dictionary<Task, List<Label>> _listTBLabels = new Dictionary<Task, List<Label>> { };

            foreach (Task paneltask in fromLoadTest.Tasks)
            {
                //int textBoxNumber = 0;
                _RTBInTask.Add(paneltask, new List <Title> {
                });
                _PBInTask.Add(paneltask, new List <PictureBoxScalable> {
                });
                _TBInTask.Add(paneltask, new List <TextContainer> {
                });
                //_listTBLabels.Add(paneltask, new List<Label> { });

                _listTasksInTest.Add(paneltask);


                //foreach (TaskElement taskElem in paneltask.TaskElements)
                //{
                //    if (taskElem.Type.Equals("System.Windows.Forms.TextBox"))
                //    {

                //        textBoxNumber++;

                //    }
                //}

                foreach (TaskElement taskElem in paneltask.TaskElements)
                {
                    if (taskElem.Type.Equals("System.Windows.Forms.RichTextBox"))
                    {
                        Title bufTitle = new Title(taskElem.Name)
                        {
                            Instance =
                            {
                                Height   = taskElem.Height,
                                Width    = taskElem.Width,
                                Location = taskElem.Point,
                                Text     = taskElem.Text,
                                Font     = new System.Drawing.Font("Microsoft Sans Serif", 15.75F,
                                                                   System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
                                                                   ((byte)(204))),
                            }
                        };
                        _RTBInTask[paneltask].Add(bufTitle);
                    }

                    if (taskElem.Type.Equals("System.Windows.Forms.PictureBox"))
                    {
                        using (var stream = File.Open(new DynamicParams().GetPath() + "/" + taskElem.Media,
                                                      FileMode.Open))
                        {
                            var binaryFormatter = new BinaryFormatter();
                            var image           = ((SerializablePicture)binaryFormatter.Deserialize(stream)).Picture;


                            PictureBoxScalable bufPBS = new PictureBoxScalable(taskElem.Name)
                            {
                                Instance =
                                {
                                    Size     = new Size(taskElem.Width, taskElem.Height),
                                    Image    = image,
                                    Location = taskElem.Point
                                }
                            };
                            _PBInTask[paneltask].Add(bufPBS);
                        }
                    }

                    if (taskElem.Type.Equals("System.Windows.Forms.TextBox"))
                    {
                        TextContainer bufTC = new TextContainer(taskElem.Name)
                        {
                            Instance =
                            {
                                Height   = taskElem.Height,
                                Width    = taskElem.Width,
                                Location = taskElem.Point,
                                Text     = taskElem.Answer,
                                TabIndex = taskElem.Index
                            }
                        };
                        _TBInTask[paneltask].Insert(0, bufTC);


                        //textBoxNumber--;
                    }
                }
            }

            foreach (Task task in _listTasksInTest)
            {
                var indexLabel = 1;
                var buf1       = new Panel
                {
                    BackColor = System.Drawing.SystemColors.ControlDark,
                    Location  = new System.Drawing.Point(0, 0),
                    Name      = task.Name,
                    Size      = new System.Drawing.Size(1110, 618),
                    TabIndex  = 0
                };
                _listPanelTasks.Add(buf1);

                //Добавление панели с заданием

                var panelQestionFoo = new Panel();
                panelQestionFoo.BackColor  = System.Drawing.SystemColors.GradientInactiveCaption;
                panelQestionFoo.Location   = new System.Drawing.Point(5, 5);
                panelQestionFoo.Name       = "panelQuestion";
                panelQestionFoo.Size       = new System.Drawing.Size(761, 610);
                panelQestionFoo.TabIndex   = 0;
                panelQestionFoo.AutoScroll = true;

                panelQestionFoo.AllowDrop  = true;
                panelQestionFoo.DragEnter += new DragEventHandler(toTest.panelQuestion_DragEnter);
                panelQestionFoo.DragDrop  += new DragEventHandler(toTest.panelQuestion_DragDrop);

                toTest.createPasteFunc(panelQestionFoo);

                foreach (PictureBoxScalable pb in _PBInTask[task])
                {
                    pb.SetParent(panelQestionFoo);
                    panelQestionFoo.Controls.Add(pb.Instance);
                    ControlMover.Add(pb.Instance);
                    pb.Instance.SizeMode = PictureBoxSizeMode.StretchImage;
                }


                int j = _TBInTask[task].Count;
                foreach (TextContainer tb in _TBInTask[task])
                {
                    tb.Instance.Name = "System.Windows.Forms.TextBox, Text: " + j;
                    tb.SetParent(panelQestionFoo);
                    tb.AddAnswerTitle(tb.Instance.TabIndex);
                    panelQestionFoo.Controls.Add(tb.Instance);
                    tb.Instance.BringToFront();
                    ControlMover.Add(tb.Instance);

                    indexLabel++;


                    TBList.Add(tb.Instance);
                    j--;
                }

                foreach (Title rtb in _RTBInTask[task])
                {
                    rtb.SetParent(panelQestionFoo);
                    panelQestionFoo.Controls.Add(rtb.Instance);
                    ControlMover.Add(rtb.Instance);
                    rtb.Instance.BringToFront();
                }


                _listPanelTasks[_listPanelTasks.Count - 1].Controls.Add(panelQestionFoo);
                toTest.Controls.Find("panelMiddle", true)[0].Controls.Add(_listPanelTasks[_listPanelTasks.Count - 1]);

                PanelWrapper bufPW = new PanelWrapper();
                bufPW.Entity       = _listPanelTasks[_listPanelTasks.Count - 1];
                bufPW.Identifier   = indexLabel;
                bufPW.PictureIndex = _PBInTask[task].Count;
                indexLabel++;

                LinkLabel bufLL = toTest.createLinkLabel(_listPanelTasks.Count - 1);

                bufPW.Entity.Name = bufLL.Text;

                toTest.ListPanelsTasks.Add(bufLL, bufPW);
                toTest.LinkLabelButtonDel.Add(bufLL, toTest.createButtonDelTask(_listPanelTasks.Count - 1));


                PanelWrapper bufPW2 = new PanelWrapper();
                bufPW2.Entity = panelQestionFoo;
                toTest._currentPanelQuestion = bufPW2;
            }


            Control currentPanelListOfTasks = toTest.Controls.Find("panelListOfTasks", true)[0];


            toTest.ListPanelsTasks.Remove((LinkLabel)currentPanelListOfTasks.Controls[1]);
            toTest.LinkLabelButtonDel.Remove((LinkLabel)currentPanelListOfTasks.Controls[1]);

            currentPanelListOfTasks.Controls.Remove(currentPanelListOfTasks.Controls[1]);
            currentPanelListOfTasks.Controls.Remove(currentPanelListOfTasks.Controls[1]);

            //toTest.ListPanelsTasks.Remove((LinkLabel)currentPanelListOfTasks.Controls[1]);


            toTest._currentTask =
                toTest.ListPanelsTasks[(LinkLabel)(toTest.Controls.Find("panelListOfTasks", true)[0].Controls[1])];
            toTest._currentPanelQuestion.Entity =
                (Panel)toTest._currentTask.Entity.Controls.Find("panelQuestion", true)[0];


            //foreach (TextBox tb in TBList)
            //{
            //    tb.Move += moveTBWithLB;
            //}
        }