private void btnSaveUpdate_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { var item = context.Items.FirstOrDefault(s => s.Nr == nr); item.Name = txtName.Text; item.Price = Convert.ToDecimal(txtPrice.Text); context.SaveChanges(); DisplayData(); } }
private void btnInsert_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { context.Sellers.Add(new Seller { Name = txtName.Text, LastName = txtLastName.Text, Employed = Convert.ToDateTime(txtEmployed.Text), Salary = Convert.ToDecimal(txtSalary.Text), Number = txtNumber.Text }); context.SaveChanges(); } DisplayData(); }
private void btnNewPurchase_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { context.Purchases.Add(new Purchase { Name = txtName.Text, LastName = txtLastName.Text, ItemNr = Convert.ToInt32(txtItemNr.Text), SellerId = Convert.ToInt32(txtSellerId.Text), Date = Convert.ToDateTime(txtDate.Text) }); context.SaveChanges(); } DisplayData(); }
private void btnInsert_Click_1(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { context.Items.Add(new Item { Name = txtName.Text, Price = Convert.ToDecimal(txtPrice.Text) }); context.SaveChanges(); } DisplayData(); }
private void btnSaveUpdate_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { var customer = context.Customers.FirstOrDefault(s => s.Name == name && s.LastName == lastName); customer.Name = txtName.Text; customer.LastName = txtLastName.Text; customer.Email = txtEmail.Text; DisplayData(); } }
private void btnInsert_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { context.Customers.Add(new Customer { Name = txtName.Text, LastName = txtLastName.Text, Email = txtEmail.Text }); context.SaveChanges(); } DisplayData(); }
private void btnBuy_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { string name = txtName.Text; string lastName = txtLastName.Text; DateTime data = Convert.ToDateTime(txtDate.Text); context.Purchases.Add(new Purchase { Name = txtName.Text, LastName = txtLastName.Text, ItemNr = Form3Items.nr, Date = Convert.ToDateTime(txtDate.Text) }); } }
private void btnUpdate_Click_1(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; nr = Int32.Parse(Convert.ToString(selectedRow.Cells["Nr"].Value)); var item = context.Items.FirstOrDefault(s => s.Nr == nr); txtName.Text = item.Name; txtPrice.Text = Convert.ToString(item.Price); } }
private void btnDelete_Click(object sender, EventArgs e) { using (var context = new ShopEntities()) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; id = Int32.Parse(Convert.ToString(selectedRow.Cells["Id"].Value)); var seller = context.Sellers.FirstOrDefault(s => s.Id == id); context.Sellers.Remove(seller); context.SaveChanges(); DisplayData(); } }
private void btnDelete_Click_1(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; nr = Int32.Parse(Convert.ToString(selectedRow.Cells["Nr"].Value)); var item = context.Items.FirstOrDefault(s => s.Nr == nr); context.Items.Remove(item); context.SaveChanges(); DisplayData(); } }
private void btnSaveUpdate_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { var seller = context.Sellers.FirstOrDefault(s => s.Id == id); seller.Name = txtName.Text; seller.LastName = txtLastName.Text; seller.Employed = Convert.ToDateTime(txtEmployed.Text); seller.Salary = Convert.ToDecimal(txtSalary.Text); seller.Number = txtNumber.Text; context.SaveChanges(); DisplayData(); } }
private void btnDelete_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; string name = Convert.ToString(selectedRow.Cells["Name"].Value); string lastName = Convert.ToString(selectedRow.Cells["LastName"].Value); var customer = context.Customers.FirstOrDefault(s => s.Name == name && s.LastName == lastName); context.Customers.Remove(customer); context.SaveChanges(); DisplayData(); } }
private void btnUpdate_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; id = Int32.Parse(Convert.ToString(selectedRow.Cells["Id"].Value)); var seller = context.Sellers.FirstOrDefault(s => s.Id == id); txtName.Text = seller.Name; txtLastName.Text = seller.LastName; txtEmployed.Text = Convert.ToString(seller.Employed); txtSalary.Text = Convert.ToString(seller.Salary); txtNumber.Text = seller.Number; } }
private void btnUpdate_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex]; name = Convert.ToString(selectedRow.Cells["Name"].Value); lastName = Convert.ToString(selectedRow.Cells["LastName"].Value); var customer = context.Customers.FirstOrDefault(s => s.Name == name && s.LastName == lastName); txtName.Text = customer.Name; txtLastName.Text = customer.LastName; txtEmail.Text = customer.Email; DisplayData(); } }
private void btnStatistics_Click(object sender, EventArgs e) { using (ShopEntities context = new ShopEntities()) { var statistics = (from s in context.Sellers select new { SellerId = s.Id, SellerName = s.Name, SellerLastName = s.LastName, SellerSales = context.Purchases.Count(t => t.SellerId == s.Id) }).ToList(); dataGridView1.DataSource = statistics; context.SaveChanges(); connection.Close(); } }
static void Main() { using (ShopEntities context = new ShopEntities()) { //context.Sellers.Add(new Seller { Name = "Akvile", LastName = "Saviokaite", Employed = new DateTime(2016, 8, 2), Salary = 300m, Number = "+37066622288" }); //context.Sellers.Add(new Seller { Name = "Aiste", LastName = "Dindaite", Employed = new DateTime(2015, 1, 15), Salary = 353m, Number = "+37013245584" }); //context.Sellers.Add(new Seller { Name = "Danute", LastName = "Budryte", Employed = new DateTime(2014, 5, 13), Salary = 500.35m, Number = "+37012345655" }); //context.Sellers.Add(new Seller { Name = "Ema", LastName = "Ragelyte", Employed = new DateTime(2016, 1, 31), Salary = 330.5m, Number = "+37056840220" }); //context.Customers.Add(new Customer { Name = "Bronius", LastName = "Asmena", Email = "*****@*****.**" }); //context.Customers.Add(new Customer { Name = "Jonas", LastName = "Juodelis", Email = "*****@*****.**" }); //context.Customers.Add(new Customer { Name = "Ona", LastName = "Maciulyte", Email = "*****@*****.**" }); //context.Customers.Add(new Customer { Name = "Marius", LastName = "Marcelijus" }); //context.Customers.Add(new Customer { Name = "Brigita", LastName = "Jurgela", Email = "*****@*****.**" }); //context.Items.Add(new Item { Name = "J10 Dzinsai", Price = 34.99m }); //context.Items.Add(new Item { Name = "J15 Dzinsai", Price = 49.99m }); //context.Items.Add(new Item { Name = "T05 Maikute", Price = 20.99m }); //context.Items.Add(new Item { Name = "T10 Maikute", Price = 19.99m }); //context.Items.Add(new Item { Name = "T20 Maikute", Price = 23.49m }); //context.Items.Add(new Item { Name = "S100 Batai", Price = 74.75m }); //context.Items.Add(new Item { Name = "S115 Batai", Price = 34.55m }); //context.Purchases.Add(new Purchase { Name = "Bronius", LastName = "Asmena", ItemNr = 2, SellerId = 4, Date = new DateTime(2016, 11, 25) }); //context.Purchases.Add(new Purchase { Name = "Bronius", LastName = "Asmena", ItemNr = 1, SellerId = 2, Date = new DateTime(2016, 7, 11) }); //context.Purchases.Add(new Purchase { Name = "Jonas", LastName = "Juodelis", ItemNr = 3, SellerId = 2, Date = new DateTime(2016, 1, 5) }); //context.Purchases.Add(new Purchase { Name = "Ona", LastName = "Maciulyte", ItemNr = 3, SellerId = 3, Date = new DateTime(2016, 11, 25) }); //context.Purchases.Add(new Purchase { Name = "Ona", LastName = "Maciulyte", ItemNr = 7, SellerId = 1, Date = new DateTime(2016, 8, 28) }); //context.Purchases.Add(new Purchase { Name = "Ona", LastName = "Maciulyte", ItemNr = 5, SellerId = 4, Date = new DateTime(2016, 2, 24) }); //context.Purchases.Add(new Purchase { Name = "Marius", LastName = "Marcelijus", ItemNr = 4, SellerId = 3, Date = new DateTime(2015, 12, 15) }); //context.Purchases.Add(new Purchase { Name = "Brigita", LastName = "Jurgela", ItemNr = 7, SellerId = 1, Date = new DateTime(2016, 11, 25) }); //context.Purchases.Add(new Purchase { Name = "Brigita", LastName = "Jurgela", ItemNr = 1, SellerId = 2, Date = new DateTime(2016, 11, 25) }); //context.Purchases.Add(new Purchase { Name = "Brigita", LastName = "Jurgela", ItemNr = 3, SellerId = 3, Date = new DateTime(2016, 12, 02) }); context.SaveChanges(); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); }