private void btnSave_Click(object sender, RoutedEventArgs e) { try { Db = new Linq.DbDataContext(Connection); Linq.AspNetUser customer = new Linq.AspNetUser(); Linq.DbDataContext CodeDb = new Linq.DbDataContext(flag.SubCon); Linq.Code code = CodeDb.Codes.FirstOrDefault(); if (!isnew) { if (dgvCustomer.SelectedIndex != -1) { if (MessageBox.Show("هل تريد حفظ التعديلات؟", "تعديل", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } customer = Db.AspNetUsers.SingleOrDefault(item => item.Exist == true && item.Id == Convert.ToString(Dt.Rows[dgvCustomer.SelectedIndex].ItemArray[0])); } else { MessageBox.Show("الرجاء اختيار عنصر من القائمة"); return; } } customer.Name = txtName.Text; customer.Code = txtCode.Text; customer.Phone1 = txtPhone1.Text; customer.Phone2 = txtPhone2.Text; customer.Address = txtAddress.Text; //customer.Note = txtNote.Text; customer.Exist = true; if (isnew) { Db.AspNetUsers.InsertOnSubmit(customer); code.CustomerCode = customer.Code; } Db.SubmitChanges(); CodeDb.SubmitChanges(); if (isnew) { MessageBox.Show("تم الحفظ"); } usc_Initialize(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { string note = txtNote.Text; if (MainWindow.frm.offline) { Db = new Linq.DbDataContext(flag.SubCon); note += " لم يتم الرفع"; } else { Db = new Linq.DbDataContext(flag.Con); } Linq.Order order = new Linq.Order(); Linq.DbDataContext CodeDb = new Linq.DbDataContext(flag.SubCon); Linq.Code code = CodeDb.Codes.FirstOrDefault(); if (!isnew) { if (dgvOrder.SelectedIndex != -1) { if (MessageBox.Show("هل تريد حفظ التعديلات؟", "تعديل", MessageBoxButton.YesNo) == MessageBoxResult.No) { return; } order = Db.Orders.SingleOrDefault(item => item.Exist == true && item.ID_Order == Convert.ToInt32(Dt.Rows[dgvOrder.SelectedIndex].ItemArray[0])); } else { MessageBox.Show("الرجاء اختيار عنصر من القائمة"); return; } } order.Barcode = txtBarcode.Text; order.Customer = txtCustomer.Text; order.CustomerPhone = txtCustomerPhone.Text; order.Recipient = txtRecipient.Text; order.RecipientPhone1 = txtRecipientPhone1.Text; order.RecipientPhone2 = txtRecipientPhone2.Text; order.Address = txtAddress.Text; order.City = txtCity.Text; order.PackagePrice = Convert.ToDecimal(txtPackagePrice.Text); order.PackageNumber = Convert.ToInt32(txtPackageNumber.Text); order.DeliveryPrice = Convert.ToDecimal(txtDeliveryPrice.Text); order.TotalPrice = Convert.ToDecimal(txtTotalPrice.Text); order.Delegate = txtDelegate.Text; order.State = cmbState.Text; order.Date = Convert.ToDateTime(txtDate.Text); order.DateState = Convert.ToDateTime(txtDate.Text); order.Note = note; order.Exist = true; order.User = MainWindow.frm.user; if (selectindx == true) { order.Province = provine; selectindx = false; } if (isnew) { Db.Orders.InsertOnSubmit(order); code.Barcode = order.Barcode; } Db.SubmitChanges(); CodeDb.SubmitChanges(); if (isnew) { MessageBox.Show("تم الحفظ"); } usc_Initialize(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }