Beispiel #1
0
        private void menuDataSource_Click(object sender, EventArgs e)
        {
            if (_viewContentCollection.Count > 0)
            {
                FormQueryData form = new FormQueryData();
                form.Solution = SolutionInstance.GetInstance().Solution;
                if (form.ShowDialog() == DialogResult.OK)
                {
                    if (ActiveViewContent != null)
                    {
                        FormContent fc = (FormContent)ActiveViewContent;
                        fc.Text    = SolutionInstance.GetInstance().Solution.SolutionName + "*";
                        fc.IsDirty = true;
                        if (SolutionInstance.GetInstance().Solution.DataSetList.Count == 0)
                        {
                            return;
                        }

                        SnDataSet ds = SolutionInstance.GetInstance().Solution.DataSetList[0] as SnDataSet;
                        foreach (IComponent ctrl in fc.ViewContent.Host.Container.Components)
                        {
                            if (ctrl is ParamTextBox || ctrl is ParamComboBox || ctrl is ParamDateTimePicker ||
                                ctrl is ParamRadioButton || ctrl is Search)
                            {
                                (ctrl as ICommonAttribute).DataSetName = ds.DataSetID + "-" + ds.DataSetName;
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("请先定义查询方案!", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        public void neighbors_should_have_expected_coordinates()
        {
            FlightDatabase   db  = new FlightDatabase(GetFlightDataPath());
            Meeting          m   = new Meeting(3712, db);
            SolutionInstance sol = m.GetRandomInstance();

            IReadOnlyList <int>            originalCoordinates = sol.Coordinates;
            IEnumerable <SolutionInstance> neighbors           = sol.Neighbors;

            neighbors.Count().Should().BeInRange(18, 36);  // If no degenerate case

            // Check for uniqueness of neighbor
            List <int[]> coordinatesOfNeighbors = new List <int[]>();

            foreach (var neighbor in neighbors)
            {
                coordinatesOfNeighbors.Add(neighbor.Coordinates.ToArray());
            }

            // Every set of coordinate should be unique
            coordinatesOfNeighbors.Distinct().Count().Should().Be(coordinatesOfNeighbors.Count());

            // Verifying that the distance is one (we have only moved one point in one of the 18 axes
            foreach (var coordinates in coordinatesOfNeighbors)
            {
                coordinates.Zip(originalCoordinates, (one, two) => Math.Abs(one - two)).Sum().Should().Be(1);
            }

            int i = coordinatesOfNeighbors.Count();
        }
Beispiel #3
0
        public void LoadFromFileName(string fileName)
        {
            Stream       stream       = new FileStream(fileName, FileMode.Open);
            BinaryReader binaryReader = new BinaryReader(stream, System.Text.Encoding.Unicode);

            byte[] buffer = binaryReader.ReadBytes((int)stream.Length);

            //string xmlContent = File.ReadAllText(fileName);

            try
            {
                string xmlContent = System.Text.Encoding.Unicode.GetString(buffer);

                binaryReader.Close();
                stream.Close();

                if (xmlContent.IndexOf("<SnControl.Solution>") == -1)
                {
                    xmlContent = File.ReadAllText(fileName);
                }

                string xmlSolutionContent = xmlContent.Substring(xmlContent.IndexOf("<SnControl.Solution>"), xmlContent.IndexOf("</SnControl.Solution>") - xmlContent.IndexOf("<SnControl.Solution>"));
                xmlSolutionContent += "</SnControl.Solution>";
                string xmlFormContent = xmlContent.Substring(xmlContent.IndexOf("<System.Windows.Forms.Form"), xmlContent.IndexOf("</QuerySolution>") - xmlContent.IndexOf("<System.Windows.Forms.Form"));

                XmlSolutionReader xmlSolutionReader = new XmlSolutionReader(_solution);
                _solution = xmlSolutionReader.SetUpSolution(xmlSolutionContent);
                if (_solution == null)
                {
                    Controls.Clear();
                    return;
                }
                SolutionInstance.GetInstance().Solution = _solution;

                IDesignerLoaderProvider loaderProvider = new XmlDesignerLoaderProvider(xmlFormContent);
                IDesignerGenerator      generator      = new XmlDesignerGenerator();

                _designerViewContent = new FormsDesignerViewContent(this, loaderProvider, generator);
                //加载XML内容
                _designerViewContent.Reload();
                _designPanel      = new DesignPanel(_designerViewContent.DesignSurface);
                _designPanel.Dock = DockStyle.Fill;
                Controls.Add(_designPanel);

                if (!_designPanel.SetRootDesigner())
                {
                    Controls.Clear();
                    return;
                }
                _designerViewContent.PropertyContainer.Host = _designPanel.Host;
                _designerViewContent.PropertyContainer.SelectableObjects = _designerViewContent.Host.Container.Components;
            }
            catch (ApplicationException e)
            {
                MessageBox.Show(e.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
        private void NewSolution(string solutionID, string solution)
        {
            FormContent form = new FormContent();

            form.Solution              = SolutionInstance.GetInstance().Solution;
            form.Solution.SolutionID   = solutionID;
            form.Solution.SolutionName = solution;
            form.Text    = solution + "*";
            form.TabText = solution + "*";
            form.Init();
            form.Show(dockPanel);
            ViewContentCollection.Add(form);
            this.InitDockForm();
        }
Beispiel #5
0
        protected override void BuildRenderTree(RenderTreeBuilder builder)
        {
            base.BuildRenderTree(builder);

            if (SolutionInstance == null)
            {
                return;
            }
            var visualizerType = VisualizerHandler.GetVisualizer(SolutionInstance.GetType());

            if (visualizerType == null)
            {
                return;
            }

            builder.OpenComponent(0, visualizerType);
            builder.AddAttribute(1, "SolutionInstance", SolutionInstance);
            builder.CloseComponent();
        }
Beispiel #6
0
        public static (uint[], uint) SolveBounded(uint[] values, uint[] weights, uint[] stock, uint capacity)
        {
            if (values == null || weights == null || stock == null || (values.Length != weights.Length) || (values.Length != stock.Length))
            {
                throw new InvalidOperationException();
            }

            Dictionary <(int, uint, uint), SolutionInstance> solutionMap = new Dictionary <(int, uint, uint), SolutionInstance>();

            SolutionInstance bestSolution = new SolutionInstance()
            {
                CapacityLeft = capacity,
                ValueSum     = 0,
                ChosenItems  = new uint[values.Length],
            };

            bestSolution = RecursiveSolve(values, weights, stock, bestSolution, 0, solutionMap);

            return(bestSolution.ChosenItems, bestSolution.ValueSum);
        }
Beispiel #7
0
        public void Save(string fileName)
        {
            _fileName = fileName;
            XmlDocument  doc       = new XmlDocument();
            XmlElement   element   = doc.CreateElement("QuerySolution");
            XmlAttribute attribute = doc.CreateAttribute("version");

            attribute.InnerText = "1.0";
            element.Attributes.Append(attribute);
            doc.AppendChild(element);

            element = new XmlSolutionGenerator().GetElementFor(doc, SolutionInstance.GetInstance().Solution);

            foreach (XmlNode node in element.ChildNodes)
            {
                doc.DocumentElement.AppendChild(doc.ImportNode(node, true));
            }

            element = new XmlDesignerGenerator().GetElementFor(doc, _designPanel.Host);

            foreach (XmlNode node in element.ChildNodes)
            {
                doc.DocumentElement.AppendChild(doc.ImportNode(node, true));
            }

            doc.Save(fileName);

            //Stream stream = new FileStream(fileName, FileMode.Create);
            //BinaryWriter binaryWriter = new BinaryWriter(stream, System.Text.Encoding.Unicode);
            //byte[] buffer = System.Text.Encoding.Unicode.GetBytes(doc.InnerXml);
            //binaryWriter.Write(buffer);

            //binaryWriter.Close();
            //stream.Close();

            IsDirty = false;
            OnDirtyChanged(this, EventArgs.Empty);
        }
Beispiel #8
0
        private void menuNew_Click(object sender, EventArgs e)
        {
            if (!CheckSave())
            {
                FormNewProject formNewProject = new FormNewProject();
                if (formNewProject.ShowDialog(this) == DialogResult.OK)
                {
                    InitMenuToolBar(false);
                    Solution solution = new Solution()
                    {
                        SolutionID               = formNewProject.ProjectID,
                        SolutionName             = formNewProject.ProjectDepict,
                        SolutionComment          = formNewProject.ProjectMemo,
                        SolutionConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[QueryDAO.DataType].ConnectionString,
                        SolutionDataBaseType     = QueryDAO.DataType
                    };

                    SolutionInstance.GetInstance().Solution = solution;
                    NewSolution(formNewProject.ProjectID, formNewProject.ProjectDepict);
                    InitMenuToolBar(true);
                    OpenPath = string.Empty;
                }
            }
        }
        private void FormQueryResult_Load(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            Stream       stream       = new FileStream(FileName, FileMode.Open);
            BinaryReader binaryReader = new BinaryReader(stream, System.Text.Encoding.Unicode);

            byte[] buffer = binaryReader.ReadBytes((int)stream.Length);

            //string xmlContent = File.ReadAllText(fileName);
            string      xmlContent;
            string      solutionContent;
            string      xmlForm = string.Empty;
            XmlDocument doc     = new XmlDocument();

            try
            {
                xmlContent = System.Text.Encoding.Unicode.GetString(buffer);

                binaryReader.Close();
                stream.Close();

                if (xmlContent.IndexOf("<SnControl.Solution>") == -1)
                {
                    xmlContent = File.ReadAllText(FileName);
                }

                solutionContent = xmlContent.Substring(xmlContent.IndexOf("<SnControl.Solution>"),
                                                       xmlContent.IndexOf("</SnControl.Solution>") - xmlContent.IndexOf("<SnControl.Solution>")) + "</SnControl.Solution>";

                XmlSolutionReader xmlSolutionReader = new XmlSolutionReader(_solution);
                _solution = xmlSolutionReader.SetUpSolution(solutionContent);
                SolutionInstance.GetInstance().Solution = _solution;
                Text = _solution.SolutionName;

                xmlForm = xmlContent.Substring(xmlContent.IndexOf("<System.Windows.Forms.Form"), xmlContent.IndexOf("</QuerySolution>") - xmlContent.IndexOf("<System.Windows.Forms.Form"));
                doc.LoadXml(xmlForm);
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (doc.DocumentElement.Attributes["version"] == null)
            {
                CreateObject(xmlForm);
            }
            else
            {
                foreach (XmlElement element in doc.DocumentElement.ChildNodes)
                {
                    CreateObject(element, true);
                }
            }

            string      resultType  = "";
            object      result      = string.Empty;
            IEnumerator enumControl = _componentContainer.GetEnumerator();
            Method      method      = new Method(this._dao);

            while (enumControl.MoveNext())
            {
                var ctl = enumControl.Current as ICommonAttribute;
                if (ctl == null)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(ctl.Function))
                {
                    continue;
                }
                method.ExecMethod(ctl.Function, out resultType, out result);
                switch (resultType)
                {
                case "字符":
                case "日期":
                    ((Control)ctl).Text = result.ToString();
                    break;

                case "数据集":
                    if (ctl is ParamComboBox)
                    {
                        ((ParamComboBox)ctl).DataSource   = ((DataTable)result).DefaultView;
                        ((ParamComboBox)ctl).SelectedItem = null;
                    }
                    break;

                default: break;
                }
            }

            Size = new Size(Size.Width, Size.Height + 1);
            Size = new Size(Size.Width, Size.Height - 1);
        }
Beispiel #10
0
 private static SolutionInstance RecursiveSolve(uint[] values, uint[] weights, uint[] stock, SolutionInstance currentSolution, int itemIdx,
                                                Dictionary <(int, uint, uint), SolutionInstance> solutionMap)
Beispiel #11
0
        private void toolRun_Click(object sender, EventArgs e)
        {
            if (ActiveViewContent != null)
            {
                FormContent form = ActiveViewContent as FormContent;

                if (ActiveViewContent.TabPageText.IndexOf("*") >= 0)
                {
                    switch (MessageBox.Show("是否保存对该查询方案的修改?", "提示信息", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                    {
                    case DialogResult.Yes:
                        //form.Save();
                        menuSave_Click(menuSave, EventArgs.Empty);
                        break;

                    case DialogResult.No:
                        break;

                    case DialogResult.Cancel:
                        return;
                    }
                }

                string filePath = string.IsNullOrEmpty(OpenPath) ? Application.StartupPath + "\\Query\\" + SolutionInstance.GetInstance().Solution.SolutionName + ".qs" : OpenPath;

                if (File.Exists(filePath))
                {
                    FormQueryResult formQueryResult = new FormQueryResult();
                    formQueryResult.FileName = filePath;
                    formQueryResult.ShowDialog();
                }
            }
        }