public void Stock_Load() { using (Al_MujahidEntities context = new Al_MujahidEntities()) { IQueryable<STOCK> stockQuery = from c in context.STOCKs select c; IEnumerable<STOCK> stock = stockQuery.ToList<STOCK>(); sTOCKDataGrid.ItemsSource = stock; } }
// Single edit/removal. Bulk(optional/later on) private void MenuItem_Click_1(object sender, RoutedEventArgs e) { STOCK s = (STOCK)sTOCKDataGrid.SelectedItem; using (Al_MujahidEntities context = new Al_MujahidEntities()) { var myObject = new STOCK { ID = s.ID }; context.STOCKs.Attach(myObject); context.STOCKs.Remove(myObject); context.SaveChanges(); Stock_Load(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { using (Al_MujahidEntities context = new Al_MujahidEntities()) { SUPPLIER supplier = new SUPPLIER(); if (this.cOMPANYTextBox.Text.Equals("")) { MessageBox.Show("Please enter a company name"); } else { supplier.COMPANY = this.cOMPANYTextBox.Text; } context.SUPPLIERS.Add(supplier); context.SaveChanges(); Close(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { using (Al_MujahidEntities context = new Al_MujahidEntities()) { STOCK stock = new STOCK(); var decPrice = Convert.ToDecimal(this.pRICETextBox.Text); var intQTY = Convert.ToInt32(this.qTYTextBox.Text); stock.STOCK_ID = this.sTOCK_IDTextBox.Text; stock.NAME = this.nAMETextBox.Text; stock.PRICE = decPrice; stock.QTY = intQTY; context.STOCKs.Add(stock); context.SaveChanges(); Close(); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { var stock_id = CB.Text.ToString(); var qty = Convert.ToInt32(TB.Text); MessageBox.Show(stock_id); try { using (Al_MujahidEntities ctx = new Al_MujahidEntities()) { STOCK record = (from u in ctx.STOCKs where u.STOCK_ID.ToString() == stock_id select u).FirstOrDefault(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void Button_Click_1(object sender, RoutedEventArgs e) { using (Al_MujahidEntities context = new Al_MujahidEntities()) { CUSTOMER customer = new CUSTOMER(); if (this.pHONETextBox.Text.Equals("")) { customer.PHONE = 0000; } else { var phone = Convert.ToInt64(this.pHONETextBox.Text.ToString()); customer.PHONE = phone; } customer.COMPANY = this.cOMPANYTextBox.Text; context.CUSTOMERS.Add(customer); context.SaveChanges(); Close(); } }
private void sTOCKDataGrid_CellEditEnding_1(object sender, DataGridCellEditEndingEventArgs e) { STOCK stock = (STOCK)e.Row.Item; var id = stock.ID; TextBox t = e.EditingElement as TextBox; String header = e.Column.Header.ToString(); Al_MujahidEntities ctx = new Al_MujahidEntities(); if (header.Equals("PRICE")) { STOCK record = (from u in ctx.STOCKs where u.ID == id select u).FirstOrDefault(); record.PRICE = Convert.ToDecimal(t.Text.ToString()); }else if(header.Equals("ID")) { MessageBox.Show("Cant Modify ID"); }else if(header.Equals("STOCK_ID")) { STOCK record = (from u in ctx.STOCKs where u.ID == id select u).FirstOrDefault(); record.STOCK_ID = t.Text.ToString(); }else if(header.Equals("QTY")) { STOCK record = (from u in ctx.STOCKs where u.ID == id select u).FirstOrDefault(); record.QTY = Convert.ToInt32(t.Text.ToString()); }else if(header.Equals("NAME")) { STOCK record = (from u in ctx.STOCKs where u.ID == id select u).FirstOrDefault(); record.NAME = t.Text.ToString(); } ctx.SaveChanges(); // Stock_Load(); // will change it if inefficient for large records // sTOCKDataGrid.IsReadOnly = true; }
public void Suppliers_Load() { using (Al_MujahidEntities context = new Al_MujahidEntities()) { IQueryable<SUPPLIER> supQuery = from c in context.SUPPLIERS select c; IEnumerable<SUPPLIER> suppliers = supQuery.ToList<SUPPLIER>(); if (suppliers.Count() > 0) { sUPPLIERSDataGrid.ItemsSource = suppliers; } } }
private void CUSTOMERSDataGrid_CellEditEnding_1(object sender, DataGridCellEditEndingEventArgs e) { CUSTOMER CUSTOMERs = (CUSTOMER)e.Row.Item; var id = CUSTOMERs.CUS_ID; TextBox t = e.EditingElement as TextBox; String header = e.Column.Header.ToString(); Al_MujahidEntities ctx = new Al_MujahidEntities(); if (header.Equals("Company")) { CUSTOMER record = (from u in ctx.CUSTOMERS where u.CUS_ID == id select u).FirstOrDefault(); record.COMPANY = t.Text; } else if (header.Equals("Phone")) { CUSTOMER record = (from u in ctx.CUSTOMERS where u.CUS_ID == id select u).FirstOrDefault(); record.PHONE = Convert.ToInt32(t.Text.ToString()); } ctx.SaveChanges(); CUSTOMERS_Load(); }
private void MenuItem_Click_3(object sender, RoutedEventArgs e) { CUSTOMER c = (CUSTOMER)cUSTOMERSDataGrid.SelectedItem; using (Al_MujahidEntities context = new Al_MujahidEntities()) { MessageBox.Show(c.CUS_ID.ToString()); var myObject = new CUSTOMER { CUS_ID = c.CUS_ID }; context.CUSTOMERS.Attach(myObject); context.CUSTOMERS.Remove(myObject); context.SaveChanges(); CUSTOMERS_Load(); } }
// Functions for Customers public void CUSTOMERS_Load() { using (Al_MujahidEntities context = new Al_MujahidEntities()) { IQueryable<CUSTOMER> cusQuery = from c in context.CUSTOMERS select c; IEnumerable<CUSTOMER> customers = cusQuery.ToList<CUSTOMER>(); if (customers.Count() > 0) { cUSTOMERSDataGrid.ItemsSource = customers; } } }