private void btInitializeDefective_Click(object sender, RoutedEventArgs e) { try { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); Linq.Store store = PharmaLinq.Stores.SingleOrDefault(item => item.ID_Product == Convert.ToInt32(Dt.Rows[dgProducts.SelectedIndex].ItemArray[0])); store.Defective = 0; PharmaLinq.SubmitChanges(); UserControl_Loaded(sender, e); MessageBox.Show("تم التصفير "); } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
private void btnSaveDefective_Click(object sender, RoutedEventArgs e) { try { Button btn = (Button)sender; if (dgProducts.SelectedIndex != -1) { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); Linq.Store store = PharmaLinq.Stores.SingleOrDefault(item => item.ID_Product == Convert.ToInt32(Dt.Rows[dgProducts.SelectedIndex].ItemArray[0])); Linq.Product product = PharmaLinq.Products.SingleOrDefault(item => item.ID_Product == Convert.ToInt32(Dt.Rows[dgProducts.SelectedIndex].ItemArray[0])); try { int quantity = Convert.ToInt32(txtDefectiveProduct.Text); txtDefectiveProduct.Focus(); if (btn.Content.ToString() == "اضافة") { product.Quantity -= quantity; if (product.Quantity < 0) { if (product.BiggerUnit == "الثانوية" && product.UnitQuantity > 0) { product.Quantity = (int)product.SubQuantity + product.Quantity; product.UnitQuantity--; } else { quantity += product.Quantity; product.Quantity = 0; } } store.Defective += quantity; MessageBox.Show("تمت الاضافة"); } else if (btn.Content.ToString() == "ازالة") { store.Defective -= quantity; if (store.Defective < 0) { quantity += store.Defective; store.Defective = 0; } if (product.BiggerUnit == "الثانوية" && quantity >= product.SubQuantity) { quantity += -(int)product.SubQuantity; product.UnitQuantity++; } product.Quantity += quantity; MessageBox.Show("تمت الازالة "); } PharmaLinq.SubmitChanges(); } catch (Exception ex) { flag.Con.Close(); MessageBox.Show("يجب ملء هذا العنصر بعدد صحيح من دون فاصلة "); } UserControl_Loaded(sender, e); } else { MessageBox.Show("يجب تحديد عنصر "); } } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { try { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); Linq.Product product = new Linq.Product(); if (flag.Null_Checker(txtNameProduct) || flag.Null_Checker(txtBarcode) || flag.Null_Checker(txtPriece)) { goto end; } try { txtPriece.Focus(); txtPriece.SelectAll(); product.Price = Convert.ToSingle(txtPriece.Text); if (txtUnitPriece.Text != "") { txtUnitPriece.Focus(); txtUnitPriece.SelectAll(); product.Unit_Price = Convert.ToSingle(txtUnitPriece.Text); } if (txtCost.Text != "") { txtCost.Focus(); txtCost.SelectAll(); product.Cost = Convert.ToSingle(txtCost.Text); } } catch { flag.Con.Close(); MessageBox.Show("يجب ملء هذا العنصر بعدد"); goto end; } try { if (txtUnitPrecentage.Text != "") { txtUnitPrecentage.Focus(); txtUnitPrecentage.SelectAll(); product.SubQuantity = Convert.ToInt32(txtUnitPrecentage.Text); } txtQuantity.Focus(); txtQuantity.SelectAll(); product.Quantity = Convert.ToInt32(txtQuantity.Text); } catch { flag.Con.Close(); MessageBox.Show("يجب ملء هذا العنصر بعدد صحيح من دون فاصلة "); goto end; } if (flag.Dt_Comparer(DtProduct, 2, txtBarcode.Text)) { MessageBox.Show("هذا الباركود موجود"); txtBarcode.Focus(); txtBarcode.SelectAll(); return; } product.Name = txtNameProduct.Text; product.BarCode = txtBarcode.Text; product.ID_Groups = PharmaLinq.Groups.SingleOrDefault(item => item.Exist == true && item.GroupName == cmbGroup.Text).ID_Groups; product.Exist = true; product.EX_Date = txtEX_Date.Text; product.Units = txtUnit.Text; product.ID_User = IDUser; product.UnitQuantity = 0; //Bigger Unit if (rbtnMain.IsChecked == true) { product.BiggerUnit = "الأساسية"; } else if (rbtnSub.IsChecked == true) { product.BiggerUnit = "الثانوية"; } else { product.BiggerUnit = ""; } PharmaLinq.Products.InsertOnSubmit(product); PharmaLinq.SubmitChanges(); Linq.Store store = new Linq.Store(); store.ID_Product = product.ID_Product; store.Defective = 0; PharmaLinq.Stores.InsertOnSubmit(store); PharmaLinq.SubmitChanges(); MessageBox.Show("تم الحفظ"); UserControl_Loaded(sender, e); //btnSaveProduct.IsEnabled = false; //btnNewProduct.IsEnabled = true; //cmbGroup.SelectedIndex = 0; //btnEditProduct.IsEnabled = true; //btnDeletProduct.IsEnabled = true; Initil(); end :; } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }