Exemplo n.º 1
0
        public override pdaRow addNewRow()
        {
            if (canvasMain.Children.Count == 0)
            {
                StackPanel s = new StackPanel();
                s.SetValue(Canvas.LeftProperty, (double)20);
                s.SetValue(Canvas.TopProperty, (double)20);
                canvasMain.Children.Add(s);
            }
            StackPanel sp = ((StackPanel)canvasMain.Children[0]);

            if (sp.Children.Count == MAX - 1)
            {
                MessageBox.Show("You can not add more than " + MAX.ToString() + " rows");
                return(null);
            }

            if (sp.ActualHeight > canvasMain.ActualHeight)
            {
                canvasMain.Height = canvasMain.ActualHeight + 50;
            }

            pdaRow row = new pdaRow();

            row.txtCurrentState.GotFocus    += new RoutedEventHandler(txtCurrentState_GotFocus);
            row.txtCurrentState.LostFocus   += new RoutedEventHandler(txtCurrentState_LostFocus);
            row.txtCurrentState.KeyUp       += new KeyEventHandler(keyUpEventHandled);
            row.txtCurrentState.TextChanged += new TextChangedEventHandler(txtCurrentState_TextChanged);

            row.cbInputSymbol.ItemsSource       = inputs;
            row.cbInputSymbol.SelectionChanged += new SelectionChangedEventHandler(cbInputSymbol_SelectionChanged);
            row.cbInputSymbol.KeyUp            += new KeyEventHandler(keyUpEventHandled);

            row.cbStackTop.ItemsSource       = stackSymbols;
            row.cbStackTop.SelectionChanged += new SelectionChangedEventHandler(cbStackTop_SelectionChanged);
            row.cbStackTop.KeyUp            += new KeyEventHandler(keyUpEventHandled);

            row.lbl.MouseLeftButtonDown += new MouseButtonEventHandler(mutexSelectRow);
            row.lbl.MouseLeftButtonUp   += new MouseButtonEventHandler(lbl_MouseLeftButtonUp);//to supress canvas's event only

            row.txtNextState.GotFocus    += new RoutedEventHandler(txtNextState_GotFocus);
            row.txtNextState.LostFocus   += new RoutedEventHandler(txtNextState_LostFocus);
            row.txtNextState.KeyDown     += new KeyEventHandler(tb2_KeyDown);
            row.txtNextState.KeyUp       += new KeyEventHandler(keyUpEventHandled);
            row.txtNextState.TextChanged += new TextChangedEventHandler(txtNextState_TextChanged);

            row.cbAction.KeyUp            += new KeyEventHandler(keyUpEventHandled);
            row.cbAction.SelectionChanged += isEditedHandler;

            rows.Add(row);
            sp.Children.Add(row.sp);

            return(row);
        }
    }     // simple getter & setter for Y

    void ForceValidate()
    {
        const MAX = 1000;
        const MIN = -1000;

        if (this.X >= MIN && this.X <= MAX && this.Y >= MIN && this.Y <= MAX)
        {
            return;
        }
        this = default(Point);     // Yes you can reasign "this" in structs using C#
    }
Exemplo n.º 3
0
        private void Start()
        {
            trans      = transform;
            uiJoyStick = Joystick_NGUI2.NGUIJoyStick.ins;

            Camera _c = Camera.main;
            float  _h = _c.orthographicSize - 1f;
            float  _w = _c.orthographicSize * _c.aspect - 1f;

            MIN.Set(-_w, -_h);
            MAX.Set(+_w, +_h);
            //Debug.Log(_w + ":" + _h);
        }
        //private void Awake()
        //{
        //	ins = this;
        //}

        private void Start()
        {
            //plane		= new Plane(Vector3.back, Vector3.zero);
            //cam		= Camera.main;
            trans      = transform;
            uiJoyStick = Joystick_NGUI.NGUIJoyStick.ins;

            Camera _c = Camera.main;
            float  _h = _c.orthographicSize - 1f;
            float  _w = _c.orthographicSize * _c.aspect - 1f;

            MIN.Set(-_w, -_h);
            MAX.Set(+_w, +_h);

            //Debug.Log(MIN + ":" + MAX);
        }
Exemplo n.º 5
0
            public void Solve()
            {
                int       N = NextInt(), Ma = NextInt(), Mb = NextInt();
                const int MAX = 500;
                var       dp  = new int[N + 1, MAX, MAX];    //dp[i,a,b]=i?????a:b????????

                (N + 1).REP(i => MAX.REP(j => MAX.REP(k => dp[i, j, k] = int.MaxValue)));
                dp[0, 0, 0] = 0;
                var asum = 0;

                N.REP(i =>
                {
                    int ai = NextInt(), bi = NextInt(), ci = NextInt();
                    asum  += ai;

                    MAX.REP(a =>
                    {
                        MAX.REP(b =>
                        {
                            if (dp[i, a, b] == int.MaxValue)
                            {
                                return;
                            }
                            dp[i + 1, a, b]           = Min(dp[i, a, b], dp[i + 1, a, b]);
                            dp[i + 1, a + ai, b + bi] = Min(dp[i + 1, a + ai, b + bi], dp[i, a, b] + ci);
                        });
                    });
                });
                var min = int.MaxValue;

                (asum / Max(Ma, Mb)).REP(i => { if (i != 0)
                                                {
                                                    min = Min(dp[N, i * Ma, i * Mb], min);
                                                }
                                         });

                if (min == int.MaxValue)
                {
                    "-1".WL();
                }
                else
                {
                    min.WL();
                }

                return;
            }
Exemplo n.º 6
0
        public DocumentCollector AddAggregateFunction(AggregateFunctionType type, IEvaluable field)
        {
            if (_aggregations == null)
            {
                _aggregations = new List <DocumentCollector>();
            }
            IAggregation function;

            switch (type)
            {
            case AggregateFunctionType.AVG:
                function = new AVG();
                break;

            case AggregateFunctionType.COUNT:
                function = new COUNT();
                break;

            case AggregateFunctionType.MAX:
                function = new MAX();
                break;

            case AggregateFunctionType.MIN:
                function = new MIN();
                break;

            case AggregateFunctionType.SUM:
                function = new SUM();
                break;

            //case AggregateFunctionType.FIRST:
            //    function = new FIRST(field);
            //    break;
            //case AggregateFunctionType.LAST:
            //    function = new LAST(field);
            //    break;
            default:
                throw new QuerySystemException(ErrorCodes.Query.AGGREGATION_INVALID_FUNCTION);
            }
            var aggregator = new DocumentCollector(function, field);

            _aggregations.Add(aggregator);
            return(aggregator);
        }
Exemplo n.º 7
0
 RETURNS NVARCHAR(MAX)
 AS
Exemplo n.º 8
0
        private void Execute(bool doExecute)
        {
            ClearLog();
            intervals.Clear();

            string _input = tbInput.Text;

            if (!string.IsNullOrEmpty(_input))
            {
                string[] input = _input.Trim().Split(',');
                if (input != null && input.Length > 0)
                {
                    foreach (string s in input)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            string[] _inputrange = s.Split(':');
                            if (_inputrange.Length == 1)
                            {
                                PrimesBigInteger ipt = null;
                                validator.Value = s;
                                Primes.WpfControls.Validation.ValidationResult res = validator.Validate(ref ipt);
                                if (res == Primes.WpfControls.Validation.ValidationResult.OK)
                                {
                                    if (ipt.IsPrime(10))
                                    {
                                        intervals.Add(new List <PrimesBigInteger> {
                                            ipt, ipt
                                        });
                                        if (ipt.CompareTo(MAX) > 0)
                                        {
                                            log.Info(string.Format(rsc.proot_warningbignumber, s));
                                        }
                                    }
                                    else
                                    {
                                        log.Info(string.Format(rsc.proot_noprime, s));
                                    }
                                }
                                else
                                {
                                    log.Info(string.Format(rsc.proot_novalidnumber, new object[] { s, MIN.ToString(), MAX.ToString() }));
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(_inputrange[0]) && string.IsNullOrEmpty(_inputrange[1]))
                                {
                                    log.Info(rsc.proot_rangeboth);
                                }
                                else if (string.IsNullOrEmpty(_inputrange[0]))
                                {
                                    log.Info(string.Format(rsc.proot_rangeupper, _inputrange[1]));
                                }
                                else if (string.IsNullOrEmpty(_inputrange[1]))
                                {
                                    log.Info(string.Format(rsc.proot_rangedown, _inputrange[0]));
                                }
                                else
                                {
                                    PrimesBigInteger i1 = IsGmpBigInteger(_inputrange[0]);
                                    PrimesBigInteger i2 = IsGmpBigInteger(_inputrange[1]);
                                    if (i1 != null && i2 != null)
                                    {
                                        if (i1.CompareTo(i2) >= 0)
                                        {
                                            log.Info(string.Format(rsc.proot_wronginterval, s));
                                        }
                                        else
                                        {
                                            intervals.Add(new List <PrimesBigInteger> {
                                                i1, i2
                                            });
                                            if (i2.CompareTo(MAXWARN) > 0)
                                            {
                                                log.Info(string.Format(rsc.proot_warningbiginterval, s));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                if (doExecute && intervals.Count > 0)
                {
                    StartThread();
                }
            }
            else
            {
                Info(rsc.proot_insert);
            }
        }
Exemplo n.º 9
0
        private PrimesBigInteger IsGmpBigInteger(string s)
        {
            PrimesBigInteger ipt = null;

            validator.Value = s;
            Primes.WpfControls.Validation.ValidationResult res = validator.Validate(ref ipt);
            if (res != Primes.WpfControls.Validation.ValidationResult.OK)
            {
                log.Info(string.Format(rsc.proot_novalidnumber, new object[] { s, MIN.ToString(), MAX.ToString() }));
                return(null);
            }
            return(ipt);
        }
        private void CountdownThread_DoWork(object sender, DoWorkEventArgs e)
        {
            #region Variables

            string  FROM;
            string  TO;
            string  Compression;
            decimal MAX;
            string  MAX1;

            #endregion

            while (CountdownThread.CancellationPending == false)
            {
                FROM        = XmlReader.GetWorld();
                TO          = XmlReader.GetBackupTo();
                Compression = XmlReader.UseCompression();
                MAX1        = XmlReader.GetBackupTime();
                MAX         = Convert.ToDecimal(MAX1);

                #region Do if variables not set

                if (FROM == "" || TO == "" || MAX == 0 || MAX1 == "")
                {
                    while (CountdownThread.CancellationPending == false)
                    {
                        WaitTimer.Stop();
                        Log.MakeLog(null, "required things are blank:  FROM:   " + FROM + "   TO:   " + TO + "  COMPRESSION:" + Compression + "TIMER:   " + MAX.ToString());
                        this.Invoke((MethodInvoker) delegate() { StartButton.Enabled = true; });
                        this.Invoke((MethodInvoker) delegate() { StopButton.Enabled = false; });
                        CountdownThread.CancelAsync();
                        this.Invoke((MethodInvoker) delegate() { HelpLabel.Visible = true; });
                        e.Cancel = true;
                        return;
                    }
                }

                #endregion

                if (dec != 0.00M && !CountdownThread.CancellationPending)  //reset value when thread runs//
                {
                    dec = 0.00M;
                }

                #region Assign variables


                DirFrom = FROM;
                DirTo   = TO;



                if (!DirFrom.EndsWith("\\") && DirFrom != "FTP")
                {
                    DirFrom = DirFrom + "\\";
                }
                if (!DirTo.EndsWith("\\") && DirTo != "FTP")
                {
                    DirTo = DirTo + "\\";
                }

                #endregion

                while (dec < MAX && !CountdownThread.CancellationPending)  //Checks the time left is less than the total time
                {
                    //do nothing//
                }

                DateNTime = DateTime.Now.ToString("MM.dd.yyyy  hh-mm-ss");

                #region Create directory and copy world

                if (Directory.Exists(DirTo) && DirTo != "FTP")
                {
                    if (!Directory.Exists(DirTo + DateNTime))  //create the directory for the current time if it does not exist
                    {
                        Directory.CreateDirectory(DirTo + DateNTime);
                    }

                    if (DirFrom == "FTP")  //if the from directory is FTP, start FTP downloading
                    {
                        Ftp_Download FTP = new Ftp_Download();
                        FTP.main(DateNTime);
                        if (Compression == "yes")
                        {
                            CompressionBackground.RunWorkerAsync();
                        }
                    }
                    else if (DirTo == "FTP")
                    {
                        Ftp_Upload upload = new Ftp_Upload();
                        upload.Upload(DateNTime);
                    }
                    else if (DirFrom != "FTP")  //if the from directory is not FTP, copy the directory.
                    {
                        #region create directories


                        foreach (string dirPath in Directory.GetDirectories(DirFrom, "*", SearchOption.AllDirectories))
                        {
                            Directory.CreateDirectory(dirPath.Replace(DirFrom, DirTo + DateNTime + "\\"));
                        }


                        foreach (string newPath in Directory.GetFiles(DirFrom, "*.*", SearchOption.AllDirectories))
                        {
                            File.Copy(newPath, newPath.Replace(DirFrom, DirTo + DateNTime + "\\"));
                        }


                        #endregion



                        if (Compression == "yes")
                        {
                            CompressionBackground.RunWorkerAsync();
                        }
                    }
                    else
                    {
                        //error
                    }
                }
                else if (!Directory.Exists(DirTo) && DirTo != "FTP")
                {
                    Directory.CreateDirectory(DirTo);
                    if (DirFrom == "FTP")
                    {
                        Ftp_Download FTP = new Ftp_Download();
                        FTP.main(DateNTime);
                        if (Compression == "yes")
                        {
                            CompressionBackground.RunWorkerAsync();
                        }
                    }
                    else
                    {
                        foreach (string CreateDir in Directory.GetDirectories(DirFrom, "*", SearchOption.AllDirectories))
                        {
                            Directory.CreateDirectory(CreateDir.Replace(DirFrom, DirTo + DateNTime + "\\"));  //create each sub directory
                        }
                        foreach (string file in Directory.GetFiles(DirFrom, "*", SearchOption.AllDirectories))
                        {
                            File.Copy(file, file.Replace(DirFrom, DirTo + DateNTime + "\\"));  //copy each file in sub directories, and in main directory
                        }

                        if (Compression == "yes")
                        {
                            CompressionBackground.RunWorkerAsync();
                        }
                    }
                }
                else if (DirTo == "FTP")
                {
                    Ftp_Upload Upload = new Ftp_Upload();
                    Upload.Upload(DateNTime);
                }
                else
                {
                    //Error//
                    MessageBox.Show("ERROR");
                }
                #endregion
            }
        }