예제 #1
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            //Constroi o objeto
            Sample sample = new Sample();

            sample.Name        = textBoxName.Text;
            sample.Category    = comboBoxCategory.Text;
            sample.Description = textBoxDescription.Text;
            sample.Date        = dateTimePickerData.Text;

            sample.Carbonates = numericUpDownCarbonates.Value;
            sample.Latitude   = numericUpDownLatitude.Value;
            sample.Longitude  = numericUpDownLongitude.Value;

            sample.Weight0  = Convert.ToDecimal(dataGridView1.Rows[0].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight1  = Convert.ToDecimal(dataGridView1.Rows[1].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight2  = Convert.ToDecimal(dataGridView1.Rows[2].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight3  = Convert.ToDecimal(dataGridView1.Rows[3].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight4  = Convert.ToDecimal(dataGridView1.Rows[4].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight5  = Convert.ToDecimal(dataGridView1.Rows[5].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight6  = Convert.ToDecimal(dataGridView1.Rows[6].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight7  = Convert.ToDecimal(dataGridView1.Rows[7].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight8  = Convert.ToDecimal(dataGridView1.Rows[8].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight9  = Convert.ToDecimal(dataGridView1.Rows[9].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight10 = Convert.ToDecimal(dataGridView1.Rows[10].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight11 = Convert.ToDecimal(dataGridView1.Rows[11].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight12 = Convert.ToDecimal(dataGridView1.Rows[12].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight13 = Convert.ToDecimal(dataGridView1.Rows[13].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight14 = Convert.ToDecimal(dataGridView1.Rows[14].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight15 = Convert.ToDecimal(dataGridView1.Rows[15].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight16 = Convert.ToDecimal(dataGridView1.Rows[16].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight17 = Convert.ToDecimal(dataGridView1.Rows[17].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight18 = Convert.ToDecimal(dataGridView1.Rows[18].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight19 = Convert.ToDecimal(dataGridView1.Rows[19].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight20 = Convert.ToDecimal(dataGridView1.Rows[20].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight21 = Convert.ToDecimal(dataGridView1.Rows[21].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight22 = Convert.ToDecimal(dataGridView1.Rows[22].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight23 = Convert.ToDecimal(dataGridView1.Rows[23].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight24 = Convert.ToDecimal(dataGridView1.Rows[24].Cells["Pesos"].Value.ToString().Replace(".", ","));
            sample.Weight25 = Convert.ToDecimal(dataGridView1.Rows[25].Cells["Pesos"].Value.ToString().Replace(".", ","));

            if (buttonSave.Text == "Editar")
            {
                //Edita dados no banco de dados
                DatabaseConnect database = new DatabaseConnect(DatabaseFile);
                database.EditRow(sample, "Samples", textBoxId.Text);

                //Atualiza a tabela da área de trabalho
                MainForm form = (MainForm)this.Owner;
                form.updateDataGrid(null, null, null, true);

                //Limpa a janela atual
                this.Close();
            }
            else
            {
                //Insere dados no banco de dados
                DatabaseConnect database = new DatabaseConnect(DatabaseFile);
                database.Insert(sample, "Samples");

                //Atualiza a tabela da área de trabalho
                MainForm form = (MainForm)this.Owner;
                form.updateDataGrid(null, null, null, true);

                MainForm mainForm = new MainForm();
                IniFile  ini      = new IniFile(mainForm.SettingsFile);
                if (ini.Read("FORMINSERTOPEN") == "1")
                {
                    textBoxName.Text = "";
                    Clear();
                }
                else
                {
                    //Limpa a janela atual
                    this.Close();
                }
            }
        }