コード例 #1
0
        /// <summary>
        /// Manages the opening of a new/showing of an existing Instance of a Form.
        /// </summary>
        /// <param name="AForm">Type of the Form to be opened.</param>
        /// <param name="AParentForm">Parent Form (can be null).</param>
        /// <param name="AFormWasAlreadyOpened">False if a new Form was opened, true if a
        /// Singleton Instance of the Form was activated.</param>
        /// <param name="ARunShowMethod">Set to true to run the Forms' Show() Method. (Default=true).</param>
        /// <param name="AContext">Context in which the Form runs (default=""). Can get evaluated for
        /// security purposes.</param>
        /// <returns>An Instance of the Form (either newly created or just activated).</returns>
        public static Form OpenNewOrExistingForm(Type AForm, Form AParentForm, out bool AFormWasAlreadyOpened, bool ARunShowMethod = true,
                                                 string AContext = "")
        {
            Form OpenScreen;
            Form NewScreen;

            if (AForm == null)
            {
                throw new ArgumentNullException("Argument 'AForm' must not be null");
            }

            AFormWasAlreadyOpened = false;

            OpenScreen = TFormsList.GFormsList[AForm.FullName];

            if ((OpenScreen != null) &&
                (OpenScreen.Modal != true))
            {
                if (TFormsList.GSingletonForms.Contains(AForm.Name))
                {
                    OpenScreen.BringToFront();

                    AFormWasAlreadyOpened = true;

                    return(OpenScreen);
                }
            }

            NewScreen = (Form)Activator.CreateInstance(AForm, new object[] { AParentForm, AContext });

            if (ARunShowMethod)
            {
                NewScreen.Show();
            }

            return(NewScreen);
        }
コード例 #2
0
ファイル: AppParser.cs プロジェクト: ajarrott/NewBalance
        public List <Cell> ReturnCellsInRow(int rowNumber)
        {
            List <Cell> cols     = new List <Cell>();
            int         colIndex = 0;

            foreach (List <string> l in _parsedFile)
            {
                MultipleCell multi = null;

                // there will be 5 items in each .APP file
                if (l.Count != 5)
                {
                    break;
                }

                string label = l[0];
                string type  = l[1];
                int    digits; // not really necessary for this application, but leaving for reverse compatibility
                int.TryParse(l[2], out digits);

                int precision;
                int.TryParse(l[3], out precision);
                string connectionInfo = l[4];

                switch (type)
                {
                // keyboard cell
                case "K":
                    if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0)
                    {
                        colIndex--;
                    }
                    KCell k = new KCell(label, digits, precision, connectionInfo, rowNumber, colIndex);
                    if (MultipleCell.IsMultiCell(label))
                    {
                        multi = BuildMultipleCell(k, cols);
                        if (multi != null)
                        {
                            cols.Add(multi);
                        }
                    }
                    else
                    {
                        cols.Add(k);
                    }
                    break;

                // weight cell
                case "W":
                    if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0)
                    {
                        colIndex--;
                    }
                    WCell w = new WCell(label, digits, precision, connectionInfo, rowNumber, colIndex);

                    if (MultipleCell.IsMultiCell(label))
                    {
                        multi = BuildMultipleCell(w, cols);
                        if (multi != null)
                        {
                            cols.Add(multi);
                        }
                    }
                    else
                    {
                        cols.Add(w);
                    }
                    break;

                // calculation cell
                case "C":
                    List <string> names =
                        connectionInfo.Split(new char[] { '(', ')', '+', '-', '*', '/', '^' }).ToList();

                    // need for TryParse
                    double n;

                    List <string> dependencyNamesPossibleDupes = (from name in names
                                                                  where name.Length > 0 &&
                                                                  !double.TryParse(name, out n) // make sure the value isn't an integer
                                                                  select name).ToList();

                    List <string> dependencyNames = dependencyNamesPossibleDupes.Distinct().ToList();

                    List <Cell> dependencies = new List <Cell>();

                    foreach (string name in dependencyNames)
                    {
                        Cell dependency = cols.First(x => x.Label == name);

                        if (dependency != null)
                        {
                            dependencies.Add(dependency);
                        }
                    }

                    if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0)
                    {
                        colIndex--;
                    }

                    CCell c = new CCell(label, digits, precision, connectionInfo, rowNumber, colIndex,
                                        dependencies);

                    if (MultipleCell.IsMultiCell(label))
                    {
                        multi = BuildMultipleCell(c, cols);
                        if (multi != null)
                        {
                            cols.Add(multi);
                        }
                    }
                    else
                    {
                        cols.Add(c);
                    }

                    break;

                // mirror cell
                case "M":
                    // find cell to mirror
                    var columnToMirror = cols.FirstOrDefault(x => x.Label == connectionInfo);

                    if (MultipleCell.IsMultiCell(label) && cols.OfType <MultipleCell>().ToList().Count > 0)
                    {
                        colIndex--;
                    }
                    MCell m = new MCell(label, digits, precision, connectionInfo, rowNumber, colIndex, columnToMirror);

                    if (MultipleCell.IsMultiCell(label))
                    {
                        multi = BuildMultipleCell(m, cols);
                        if (multi != null)
                        {
                            cols.Add(multi);
                        }
                    }
                    else
                    {
                        cols.Add(m);
                    }
                    break;

                // newscreen, for backwards compatibility
                case "0":
                    NewScreen newScreen = new NewScreen(label, digits, precision, connectionInfo, rowNumber, colIndex);
                    cols.Add(newScreen);
                    break;
                }

                colIndex++;
            }

            return(cols);
        }