示例#1
0
        private void button_Calculate_Click(object sender, EventArgs e)
        {
            try
            {
                button_Next.Enabled = true;

                int numberOfRows     = Convert.ToInt32(numericUpDown_InputData_Rows.Value);
                int numberOfCollumns = Convert.ToInt32(numericUpDown_InputData_Collumns.Value);

                // read mainArray
                double[][] mainArray = new double[numberOfRows][];
                for (int i = 0; i < numberOfRows; i++)
                {
                    mainArray[i] = new double[numberOfCollumns];
                }

                for (int i = 0; i < numberOfRows; i++)
                {
                    for (int j = 0; j < numberOfCollumns; j++)
                    {
                        mainArray[i][j] = Convert.ToDouble(dataGridView_InputData_MainArray.Rows[i].Cells[j].Value);
                    }
                }

                // read Stocks
                double[] stocks = new double[numberOfRows];
                for (int i = 0; i < numberOfRows; i++)
                {
                    stocks[i] = Convert.ToDouble(dataGridView_InputData_Stocks.Rows[i].Cells[0].Value);
                }

                // read Requires
                double[] requires = new double[numberOfCollumns];
                for (int i = 0; i < numberOfCollumns; i++)
                {
                    requires[i] = Convert.ToDouble(dataGridView_InputData_Requires.Rows[0].Cells[i].Value);
                }

                // initialize Table
                Table = new DifferentialRentMethod(numberOfRows, numberOfCollumns, mainArray, stocks, requires);

                tabControl.SelectedIndex = 1;
                Table.Initialize();
                FillDataGrid(Table);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
示例#2
0
        private void FillDataGrid(DifferentialRentMethod table)
        {
            // write result
            label_Result.Text = @"Результат - " + Table.Result;

            // write mainArray
            for (int i = 0; i < table.NumberOfRows; i++)
            {
                for (int j = 0; j < table.NumberOfCollumns; j++)
                {
                    dataGridView_Result_MainArray.Rows[i].Cells[j].Style.BackColor = Color.White;
                    dataGridView_Result_MainArray.Rows[i].Cells[j].Value           = table.MainArray[i][j];

                    // write engageCell
                    var engageCell = Table.EngageCells.Find(cell => cell.Position.X == i && cell.Position.Y == j);
                    if (engageCell != null)
                    {
                        dataGridView_Result_MainArray.Rows[i].Cells[j].Value += " (" + engageCell.Amount + ")";
                    }
                }
            }

            // write Stocks
            for (int i = 0; i < table.NumberOfRows; i++)
            {
                dataGridView_Result_Stocks.Rows[i].Cells[0].Value = table.Stocks[i];
            }

            // write Requires
            for (int i = 0; i < table.NumberOfCollumns; i++)
            {
                dataGridView_Result_Requires.Rows[0].Cells[i].Value = table.Requires[i];
            }

            // write ExcessiveAmount
            for (int i = 0; i < table.NumberOfRows; i++)
            {
                dataGridView_Result_ExcessiveAmount.Rows[i].Cells[0].Value = table.ExcessiveAmount[i];
            }

            // write CollumnsDifferences
            for (int i = 0; i < table.NumberOfCollumns; i++)
            {
                dataGridView_Result_CollumnsDifferences.Rows[0].Cells[i].Value = table.CollumnsDifferences[i] == -1 ? "-" : table.CollumnsDifferences[i].ToString();
            }
        }