Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (txtE.Text == String.Empty || txtI.Text == String.Empty || txtL.Text == String.Empty || txtP.Text == String.Empty)
            {
                MessageBox.Show("Hesaplama yapmak için boş alanları doldurunuz.");
                return;
            }
            double E = Convert.ToDouble(txtE.Text),
                   I = Convert.ToDouble(txtI.Text),
                   L = Convert.ToDouble(txtL.Text),
                   P = Convert.ToDouble(txtP.Text);

            if (cmbL.Text == "cm")
            {
                L = L / 100;
            }
            if (cmbP.Text == "N")
            {
                P = P / 1000;
            }
            if (cmbE.Text == "Pa")
            {
                E = E / 1000000;
            }
            if (cmbI.Text == "cm⁴")
            {
                I = I / 100000000;
            }

            double result = CalculateCaseFirst.MidSpanLoad(L, P, E, I);

            txtResult.Text = result + " mm";
            try
            {
                Domain.Model.BeamDeflectionDb.Calculation cal = null;
                using (ICalculationRepository calRepo = new CalculationRepository(new Datacore.Data.BeamDeflectionDbContext()))
                {
                    var calResult = calRepo.Insert(new Domain.Model.BeamDeflectionDb.Calculation
                    {
                        Result    = result,
                        LoadId    = _Load.ID,
                        UserId    = CurrentUser.ID,
                        IsActive  = true,
                        IsDeleted = false,
                        UnitId    = ResultUnit.ID
                    });
                    cal = calResult.Result;
                    var allResult = calRepo.FindList(x => x.UserId == CurrentUser.ID);
                    if (allResult.Result != null)
                    {
                        allResult.Result.Reverse();
                        txtBefore.Text = String.Empty;
                        int count = 0;
                        allResult.Result.ForEach(x => {
                            if (count == 10)
                            {
                                return;
                            }

                            txtBefore.AppendText(x.Result + "\n");

                            count++;
                        });
                    }
                }
                using (IVariableRepository variableRepo = new VariableRepository(new Datacore.Data.BeamDeflectionDbContext()))
                {
                    List <Variable> variables = new List <Variable> {
                        new Variable
                        {
                            Name          = "Span Length",
                            Display       = "L",
                            CalculationId = cal.ID,
                            IsActive      = true,
                            IsDeleted     = false,
                            Value         = Convert.ToDouble(txtL.Text),
                            UnitId        = ((Unit)cmbL.SelectedItem).ID
                        },
                        new Variable
                        {
                            Name          = "Point Load",
                            Display       = "P",
                            CalculationId = cal.ID,
                            IsActive      = true,
                            IsDeleted     = false,
                            Value         = Convert.ToDouble(txtP.Text),
                            UnitId        = ((Unit)cmbP.SelectedItem).ID
                        },
                        new Variable
                        {
                            Name          = "Modules of Elasticity",
                            Display       = "E",
                            CalculationId = cal.ID,
                            IsActive      = true,
                            IsDeleted     = false,
                            Value         = Convert.ToDouble(txtE.Text),
                            UnitId        = ((Unit)cmbE.SelectedItem).ID
                        },
                        new Variable
                        {
                            Name          = "Moment of Inertia",
                            Display       = "I",
                            CalculationId = cal.ID,
                            IsActive      = true,
                            IsDeleted     = false,
                            Value         = Convert.ToDouble(txtI.Text),
                            UnitId        = ((Unit)cmbI.SelectedItem).ID
                        }
                    };
                    variableRepo.InsertList(variables);
                }
            }
            catch (Exception)
            {
                return;
            }
        }