private void button2_Click(object sender, EventArgs e) { try { using (var tiba = new TibaContext()) { var item = new ItemMaster() { Code = getCode(), MajorGp = major_gpComboBox.Text, Mark = markComboBox.Text, Type = typeComboBox.Text, Color = colorComboBox.Text, Size = sizeComboBox.Text, Store = storeComboBox.Text, Location = locationComboBox.Text, Unit = unitComboBox.Text, Reorder = reorderTextBox.Text, ItemDesc = getDesc() }; var balance = new Models.Balance() { Year = DateTime.Today.Year, Code = getCode(), ItemDesc = getDesc(), Avg = "0", Count = "0", Store = storeComboBox.Text }; tiba.ItemMaster.Add(item); tiba.SaveChanges(); tiba.Balance.Add(balance); tiba.SaveChanges(); } this.item_masterTableAdapter.Dispose(); this.item_masterTableAdapter.Fill(this.tibasport_dbDataSet.item_master); this.balanceTableAdapter.Dispose(); this.balanceTableAdapter.Fill(this.tibasport_dbDataSet.balance); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("هل تريد مسح تلك البيانات ؟", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { var selectedrow = item_masterDataGridView.SelectedRows.OfType <DataGridViewRow>().Where(r => !r.IsNewRow).ToArray(); using (var tiba = new TibaContext()) { foreach (var i in selectedrow) { var record = tiba.ItemMaster.Where(x => x.Id == int.Parse(i.Cells[0].Value.ToString())).First(); tiba.ItemMaster.Remove(record); } tiba.SaveChanges(); this.item_masterTableAdapter.Dispose(); this.item_masterTableAdapter.Fill(this.tibasport_dbDataSet.item_master); } c.set_autoinc("item_master", "id", item_masterDataGridView); } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { } } }
private void btnEdit_Click(object sender, EventArgs e) { try { var selectedrow = item_masterDataGridView.SelectedRows.OfType <DataGridViewRow>().Where(r => !r.IsNewRow).ToArray(); using (var tiba = new TibaContext()) { var record = tiba.ItemMaster.Where(x => x.Id == int.Parse(selectedrow[0].Cells[0].Value.ToString())).First(); record.Code = getCode(); record.MajorGp = major_gpComboBox.Text; record.Mark = markComboBox.Text; record.Type = typeComboBox.Text; record.Color = colorComboBox.Text; record.Size = sizeComboBox.Text; record.Store = storeComboBox.Text; record.Location = locationComboBox.Text; record.Unit = unitComboBox.Text; record.Reorder = reorderTextBox.Text; record.ItemDesc = getDesc(); tiba.SaveChanges(); this.item_masterTableAdapter.Dispose(); this.item_masterTableAdapter.Fill(this.tibasport_dbDataSet.item_master); } } catch (Exception ex) { MessageBox.Show(ex.InnerException.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }