private void dgCustomer_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (dgCustomer.SelectedIndex != -1) { Linq.Customer customer = (Linq.Customer)dgCustomer.SelectedItem; CustomerID = customer.ID_Customer; txtNameCustomer.IsEnabled = true; txtPhoneCustomer.IsEnabled = true; btnSaveCustomer.IsEnabled = false; btnNewCustomer.IsEnabled = true; btnEditCustomer.IsEnabled = true; btnDeletCustomer.IsEnabled = true; txtNameCustomer.Text = customer.CustomerName; txtPhoneCustomer.Text = customer.CustomerPhone.ToString(); } } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
private void btnEditCustomer_Click(object sender, RoutedEventArgs e) { try { if (CustomerID != 0) { if (MessageBox.Show("هل تريد تعديل العنصر المحدد؟", "تعديل", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); Linq.Customer customer = PharmaLinq.Customers.Single(item => item.Exist == true && item.ID_Customer == CustomerID); txtPhoneCustomer.Focus(); txtPhoneCustomer.SelectAll(); try { if (txtPhoneCustomer.Text == "") { } else { customer.CustomerPhone = Convert.ToInt32(txtPhoneCustomer.Text); } } catch (Exception ex) { flag.Con.Close(); MessageBox.Show("يجب ملء هذا العنصر برقم صحيح"); return; } customer.CustomerName = txtNameCustomer.Text; customer.Exist = true; MessageBox.Show("تم التعديل"); PharmaLinq.SubmitChanges(); flag.Fill_DataGrid(dgCustomer, PharmaLinq.Customers.Where(item => item.Exist == true)); ReInitialize(); } } else { MessageBox.Show("الرجاء اختيار عنصر"); } } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
private void btnSaveCustomer_Click(object sender, RoutedEventArgs e) { try { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); Linq.Customer customer = new Linq.Customer(); txtPhoneCustomer.Focus(); txtPhoneCustomer.SelectAll(); try { if (txtPhoneCustomer.Text == "") { } else { customer.CustomerPhone = Convert.ToInt32("0" + txtPhoneCustomer.Text); } } catch (Exception ex) { flag.Con.Close(); txtPhoneCustomer.Focus(); MessageBox.Show("يجب ملء هذا العنصر برقم صحيح"); return; } customer.CustomerName = txtNameCustomer.Text; customer.Exist = true; PharmaLinq.Customers.InsertOnSubmit(customer); PharmaLinq.SubmitChanges(); MessageBox.Show("تم الحفظ"); flag.Fill_DataGrid(dgCustomer, PharmaLinq.Customers.Where(item => item.Exist == true)); ReInitialize(); } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
private void btnDeletCustomer_Click(object sender, RoutedEventArgs e) { try { if (dgCustomer.SelectedIndex == 0) { MessageBox.Show("لايمكن حذف هذا العنصر"); return; } if (CustomerID != 0) { if (MessageBox.Show("هل تريد حذف العنصر المحدد؟", "حذف", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); Linq.Customer customer = PharmaLinq.Customers.Single(item => item.Exist == true && item.ID_Customer == CustomerID); customer.Exist = false; PharmaLinq.SubmitChanges(); MessageBox.Show("تم الحذف"); flag.Fill_DataGrid(dgCustomer, PharmaLinq.Customers.Where(item => item.Exist == true)); txtNameCustomer.Clear(); txtPhoneCustomer.Clear(); } } else { MessageBox.Show("الرجاء اختيار عنصر"); } } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }