private void button2_Click(object sender, RoutedEventArgs e)
        {
            //Run 1000 interations:
            int num = 1000;

            this.Cursor = Cursors.Wait;
            DateTime  start      = DateTime.Now;
            CalcSheet inputSheet = this.calcWB["Inputs"];
            Random    r          = new Random();

            this.calcWB.Engine.CalculatingSuspended = true;

            for (int i = 0; i < num; ++i)
            {
                //1) Set random values into the Inputs sheet:
                inputSheet[ageRow, 2]              = (r.Next(74) + 15).ToString();
                inputSheet[sexRow, 2]              = r.Next(2) == 1 ? "M" : "F";
                inputSheet[stateRow, 2]            = this.cboState.Items[r.Next(50)];
                inputSheet[pointsRow, 2]           = r.Next(15).ToString();
                inputSheet[modelRow, 2]            = r.Next(11).ToString();
                inputSheet[modelYearRow, 2]        = (33 + r.Next(1972)).ToString();
                inputSheet[multipleDiscountRow, 2] = r.Next(2) == 1 ? "Yes" : "No";
                inputSheet[3, 5] = this.txtBAmt.Text;

                //2) Calculations are suspended so need to pull the computed value to
                //make sure it has been calculated with the latest changes:
                this.calcWB.Engine.UpdateCalcID();
                this.calcWB.Engine.PullUpdatedValue(this.calcWB.GetSheetID("Outputs"), 1, 1);

                //3) Get the value from cell 1,1 on the output sheet:
                double d;
                if (double.TryParse(calcWB["Outputs"][1, 1].ToString(), NumberStyles.Any, null, out d))
                {
                    this.txtPrice.Text = string.Format("{0:C2}", d); //cell 1,1 on the outputs sheet has the result
                }
                else
                {
                    this.txtPrice.Text = "---";
                }

                //this.txtPrice.Text = string.Empty;
                this.calcWB.Engine.CalculatingSuspended = false;
                this.Cursor        = Cursors.Arrow;
                this.txtPrice.Text = string.Format("{0} updates in {1} seconds", num, (TimeSpan)(DateTime.Now - start));
            }
        }
Exemple #2
0
        private void Generate()
        {
            //Run 1000 interations:
            int num = 1000;


            DateTime  start      = DateTime.Now;
            CalcSheet inputSheet = viewModel.CalcWB["Inputs"];
            Random    r          = new Random();

            viewModel.CalcWB.Engine.CalculatingSuspended = true;

            for (int i = 0; i < num; ++i)
            {
                //1) Set random values into the Inputs sheet:
                inputSheet[viewModel.AgeRow, 2]              = (r.Next(74) + 15).ToString();
                inputSheet[viewModel.SexRow, 2]              = r.Next(2) == 1 ? "M" : "F";
                inputSheet[viewModel.StateRow, 2]            = viewModel.ItemState[r.Next(50)];
                inputSheet[viewModel.PointsRow, 2]           = r.Next(15).ToString();
                inputSheet[viewModel.ModelRow, 2]            = r.Next(11).ToString();
                inputSheet[viewModel.ModelYearRow, 2]        = (33 + r.Next(1972)).ToString();
                inputSheet[viewModel.MultipleDiscountRow, 2] = r.Next(2) == 1 ? "Yes" : "No";
                inputSheet[3, 5] = viewModel.TxtBAmt;

                //2) Calculations are suspended so need to pull the computed value to
                //make sure it has been calculated with the latest changes:
                viewModel.CalcWB.Engine.UpdateCalcID();
                viewModel.CalcWB.Engine.PullUpdatedValue(viewModel.CalcWB.GetSheetID("Outputs"), 1, 1);

                //3) Get the value from cell 1,1 on the output sheet:
                double d;
                if (double.TryParse(viewModel.CalcWB["Outputs"][1, 1].ToString(), NumberStyles.Any, null, out d))
                {
                    viewModel.TxtPrice = string.Format("{0:C2}", d); //cell 1,1 on the outputs sheet has the result
                }
                else
                {
                    viewModel.TxtPrice = "---";
                }

                //this.txtPrice.Text = string.Empty;
                viewModel.CalcWB.Engine.CalculatingSuspended = false;

                viewModel.TxtPrice = string.Format("{0} updates in {1} seconds", num, (TimeSpan)(DateTime.Now - start));
            }
        }
Exemple #3
0
        //Set the input values into the CalcSheets:
        public void SetSheetInputs()
        {
            CalcSheet inputSheet = this.CalcWB["Inputs"];

            inputSheet[ageRow, 2]       = Age;
            inputSheet[sexRow, 2]       = CboSex;
            inputSheet[stateRow, 2]     = CboState;
            inputSheet[pointsRow, 2]    = NPoint;
            inputSheet[modelRow, 2]     = CboModel;
            inputSheet[modelYearRow, 2] = NModelYear;
            if (ChkDiscount == true)
            {
                inputSheet[multipleDiscountRow, 2] = "Yes";
            }
            else
            {
                inputSheet[multipleDiscountRow, 2] = "No";
            }
            inputSheet[3, 5] = txtBAmt;
        }
        //Set the input values into the CalcSheets:
        private void SetSheetInputs()
        {
            CalcSheet inputSheet = this.calcWB["Inputs"];

            inputSheet[ageRow, 2] = this.nA.Value.ToString();

            inputSheet[sexRow, 2]       = ((XlsFileUsingXlsIO.Data) this.cboSex.SelectedItem).Sex;
            inputSheet[stateRow, 2]     = ((XlsFileUsingXlsIO.Data) this.cboState.SelectedItem).State;
            inputSheet[pointsRow, 2]    = this.nPoint.Value.ToString();
            inputSheet[modelRow, 2]     = ((XlsFileUsingXlsIO.Data) this.cboModel.SelectedItem).Model;
            inputSheet[modelYearRow, 2] = this.nModelYear.Value.ToString();
            if (this.chkDiscount.IsChecked == true)
            {
                inputSheet[multipleDiscountRow, 2] = "Yes";
            }
            else
            {
                inputSheet[multipleDiscountRow, 2] = "No";
            }
            inputSheet[3, 5] = this.txtBAmt.Text;
        }
Exemple #5
0
        public void InitGrid(CalcWorkbook workBook, CalcSheet sheet, int rowCount, int colCount, Size sz, Panel left, Panel top, string name)
        {
            //set the textboxes that hold the data
            this.textBoxCount = rowCount * colCount;
            textBoxes         = new TextBox[textBoxCount];
            this.rowCount     = rowCount;
            this.colCount     = colCount;
            this.leftOffSet   = left.Width;
            this.topOffSet    = top.Height;
            this.Size         = sz;
            for (int i = 0; i < textBoxCount; ++i)
            {
                TextBox tb = new TextBox();
                tb.Multiline = true;
                int row, col;
                row               = (i % this.colCount) + 1;
                col               = i / this.colCount + 1;
                tb.Bounds         = this.GetRectangle(row, col);
                tb.Visible        = true;
                this.textBoxes[i] = tb;
                tb.Leave         += new EventHandler(tb_Leave);
                tb.Enter         += new EventHandler(tb_Enter);
                tb.TextChanged   += new EventHandler(tb_TextChanged);
            }
            this.Controls.AddRange(this.textBoxes);

            //setup the labels on the rows and columns
            for (int i = 1; i <= rowCount; ++i)
            {
                Label     lb   = new Label();
                Rectangle rect = this.GetRectangle(1, i);
                rect.Offset(-leftOffSet, -top.Height);
                rect.Width   = left.Width - 6;
                lb.Bounds    = rect;
                lb.Text      = i.ToString();
                lb.Font      = new Font(lb.Font, FontStyle.Bold);
                lb.TextAlign = ContentAlignment.MiddleRight;
                lb.Visible   = true;
                left.Controls.Add(lb);
            }
            for (int i = 1; i <= colCount; ++i)
            {
                Label     lb   = new Label();
                Rectangle rect = this.GetRectangle(i, 1);
                rect.Offset(0, -top.Height);
                rect.Height  = top.Height - 2;
                lb.Bounds    = rect;
                lb.Text      = RangeInfo.GetAlphaLabel(i).ToString();
                lb.Font      = new Font(lb.Font, FontStyle.Bold);
                lb.TextAlign = ContentAlignment.BottomCenter;
                lb.Visible   = true;
                top.Controls.Add(lb);
            }

            this.workBook = workBook;
            if (sheet == null)
            {
                //create a CalcSheet and add it to the workbook
                this.sheet      = new CalcSheet(rowCount, colCount);
                this.sheet.Name = name;
                this.workBook.CalcSheetList.Add(this.sheet); //this line assigns sheet.Engine.
                if (this.workBook.Engine == null)
                {
                    this.workBook.Engine = this.sheet.Engine;
                }
            }
            else
            {
                this.sheet = sheet;
            }

            this.sheet.CalculationsSuspended  = false;
            this.sheet.Engine.UseDependencies = true;

            this.sheet.CalculatedValueChanged += new ValueChangedEventHandler(sheet_CalculatedValueChanged);
        }