コード例 #1
0
        private void dataGridView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var currentRow = dataGridView.CurrentRow;

            if (currentRow != null)
            {
                FormElementWarehouse formElementWarehouse = new FormElementWarehouse();
                int       idWarehouse = Int32.Parse(currentRow.Cells["id"].Value.ToString());
                Warehouse Warehouse   = db.Warehouse.Find(idWarehouse);

                formElementWarehouse.textBoxId.Text      = currentRow.Cells["id"].Value.ToString();
                formElementWarehouse.textBoxName.Text    = currentRow.Cells["name"].Value.ToString();
                formElementWarehouse.textBoxAddress.Text = currentRow.Cells["address"].Value.ToString();


                DialogResult result = formElementWarehouse.ShowDialog(this);
                if (result == DialogResult.OK && Warehouse != null)
                {
                    Warehouse.name    = formElementWarehouse.textBoxName.Text.ToString();
                    Warehouse.address = formElementWarehouse.textBoxAddress.Text.ToString();

                    db.SaveChanges();
                    checkFilter();
                    dataGridView.Refresh();
                }
            }
        }
コード例 #2
0
        private void buttonCreate_Click(object sender, EventArgs e)
        {
            FormElementWarehouse formElementWarehouse = new FormElementWarehouse();
            DialogResult         result = formElementWarehouse.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                Warehouse Warehouse = new Warehouse();
                Warehouse.name    = formElementWarehouse.textBoxName.Text.ToString();
                Warehouse.address = formElementWarehouse.textBoxAddress.Text.ToString();

                db.Warehouse.Add(Warehouse);
                db.SaveChanges();
                checkFilter();
                dataGridView.Refresh();
            }
        }