コード例 #1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (textBoxTechnologyName.Text.Trim() != "")
            {
                technology.TechnologyName  = textBoxTechnologyName.Text;
                textBoxTechnologyName.Text = "";
            }

            if (textBoxTimePerMeter.Text.Trim() != "")
            {
                // TimePermeter nazywa się pole w tabeli Technology
                technology.TimePermeter  = int.Parse(textBoxTimePerMeter.Text);
                textBoxTimePerMeter.Text = "";
            }

            if (textBoxSpeedFactor.Text.Trim() != "")
            {
                technology.SpeedFactor  = int.Parse(textBoxSpeedFactor.Text);
                textBoxSpeedFactor.Text = "";
            }

            db.SaveChanges();
            productionTechnology.refreshDataGridView();
            productionTechnology.selectRow(technology.IdTechnology);
            productionTechnology.Show();
            this.Close();
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (textBoxSpeedFactor.Text == "" || textBoxTechnologyName.Text == "" || textBoxTimePerMeter.Text == "")
            {
                MessageBox.Show("Proszę uzupełnić wszystkie pola!!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Technology technology = new Technology();
                technology.TechnologyName = textBoxTechnologyName.Text;

                bool ifTimePerMeter = int.TryParse(textBoxTimePerMeter.Text, out int timePerMeter);
                if (ifTimePerMeter)
                {
                    // TimePermeter nazywa się pole w tabeli Technology
                    if (timePerMeter > 0)
                    {
                        technology.TimePermeter = timePerMeter;
                    }
                    else
                    {
                        textBoxTimePerMeter.Text = "Wpisz liczbę > 0";
                    }
                }
                else
                {
                    textBoxTimePerMeter.Text = "Wpisz liczbę całkowitą";
                }

                bool ifSpeedFactor = int.TryParse(textBoxSpeedFactor.Text, out int speedFactor);
                if (ifSpeedFactor)
                {
                    if (speedFactor > 0)
                    {
                        technology.SpeedFactor = speedFactor;
                    }
                    else
                    {
                        textBoxSpeedFactor.Text = "Wpisz liczbę > 0";
                    }
                }
                else
                {
                    textBoxSpeedFactor.Text = "Wpisz liczbę całkowitą";
                }

                if (technology.TimePermeter > 0 && technology.SpeedFactor > 0)
                {
                    db.Technologies.Add(technology);
                    db.SaveChanges();
                    productionTechnology.refreshDataGridView();
                    productionTechnology.selectRow(technology.IdTechnology);
                    productionTechnology.Show();
                    this.Close();
                }
            }
        }