コード例 #1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Check selected rows
            if (inspectorsGridView.SelectedRows.Count != 1)
            {
                MessageBox.Show("Odaberite jednog inspektora.");
                return;
            }
            if (companiesGridVew.SelectedRows.Count != 1)
            {
                MessageBox.Show("Odaberite jednu firmu.");
                return;
            }
            if ("".Equals(textBox1.Text.Trim()))
            {
                MessageBox.Show("Unesite u polje za opis.");
                return;
            }

            var        db = new DatabaseModel();
            lab_sample ls = new lab_sample()
            {
                date         = dateTimePicker1.Value,
                description  = textBox1.Text,
                isActive     = (sbyte)1,
                inspector_id = (int)inspectorsGridView.SelectedRows[0].Cells["idInspector"].Value,
                company_id   = (int)companiesGridVew.SelectedRows[0].Cells["idCompany"].Value
            };

            db.lab_sample.Add(ls);
            db.SaveChanges();

            MessageBox.Show("Uspješno ste dodali uzorak.");
            this.Close();
        }
コード例 #2
0
        private void brišiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (samplesGV.SelectedRows.Count == 0)
            {
                MessageBox.Show("Niste odabrali nijedan uzorak.");
                return;
            }

            DialogResult result = MessageBox.Show("Da li ste sigurni da želite obrisati odabrane uzorke?", "Brisanje uzoraka", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                int selIndex = samplesGV.SelectedRows[0].Index;
                for (int i = 0; i < samplesGV.SelectedRows.Count; i++)
                {
                    int id = 0;
                    try
                    {
                        id = (int)samplesGV.SelectedRows[i].Cells["idColumn"].Value;
                    }
                    catch (NullReferenceException)
                    {
                        //the row is already deleted
                        continue;
                    }

                    lab_sample ls = db.lab_sample.Find(id);

                    if (ls != null)
                    {
                        ls.isActive = 0;
                    }
                }
                db.SaveChanges();
                SamplesStatistics_Load(sender, e);
                if (selIndex != 0 && selIndex < samplesGV.Rows.Count)
                {
                    samplesGV.Rows[selIndex - 1].Selected = true;
                }
            }
        }