private void ListViewItem_Selected(object sender, RoutedEventArgs e) { USC.USC_SALES Sales = new USC.USC_SALES(); GridUsc.Children.Clear(); Sales.IDUser = IDUSER_main; GridUsc.Children.Add(Sales); }
private void UserControl_Unloaded(object sender, RoutedEventArgs e) { try { usc = null; } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { try { DtCustomer = flag.Fill_DataGrid_join("select CustomerName,ID_Customer from Customers where Exist = 'true'"); string[] names = { "ID_Product", "Name", "Price", "Unit", "Quantity_SaleAction", "EX_Date", "SalePrecentage", "TotalPrice" }; flag.Create_Columns(names, Dt); DelDt.Columns.Add("Del"); QuantityDt.Columns.Add("Quantity"); QuantityDt.Columns.Add("Unit"); flag.Fill_ComboBox(DtCustomer, cmbCustomer); string[] items = { "نقدي", "شيك", "بطاقة ائتمانية" }; cmbPayType.ItemsSource = items; cmbPayType.SelectedIndex = 0; cmbUnit.IsEnabled = Properties.Settings.Default.UnitEnabled; if (Properties.Settings.Default.UnitEnabled == false) { UnitColumn.Visibility = Visibility.Collapsed; } if (Properties.Settings.Default.EX_DateEnabled == false) { EX_DateColumn.Visibility = Visibility.Collapsed; } flag.Focus_txt(txtBarcode, txtSearchBill); usc = this; if (MainWindow.GetMainForm.Bill != "0") { txtSearchBill.Text = MainWindow.GetMainForm.Bill; } MainWindow.GetMainForm.Bill = "0"; } catch (Exception ex) { flag.Con.Close(); MessageBox.Show(ex.Message); } }
public void Save() { if (dgSale.Items.Count > 0) { PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con); int j = 0; Linq.Sale sale = new Linq.Sale(); if (!isnew) { if (DelDt.Rows.Count > 0) { for (int i = 0; i < dgSale.Items.Count; i++) { try { for (j = 0; j < DelDt.Rows.Count; j++) { if (Convert.ToInt32(Dt.Rows[i].ItemArray[8]) == Convert.ToInt32(DelDt.Rows[j].ItemArray[0])) { salePrice -= Convert.ToDouble(Dt.Rows[i].ItemArray[7]); txtPaid.Text = (Convert.ToDouble(txtPaid.Text) - Convert.ToDouble(Dt.Rows[i].ItemArray[7])).ToString(); } } } catch (Exception ex) { } } } sale = PharmaLinq.Sales.Single(item => item.Exist == true && item.ID_Sale == Convert.ToInt32(txtSaleID.Text)); } for (int i = 0; i < Dt.Rows.Count; i++) { Linq.SalesAction saleaction = new Linq.SalesAction(); Linq.Product product = PharmaLinq.Products.Single(item => item.ID_Product == Convert.ToInt32(Dt.Rows[i].ItemArray[0])); if (!isnew && (i + 1) <= dtcount) { saleaction = PharmaLinq.SalesActions.Single(item => item.Exist == true && item.ID_Sale == Convert.ToInt32(txtSaleID.Text) && item.ID_SaleAction == Convert.ToInt32(Dt.Rows[i].ItemArray[8])); if (QuantityDt.Rows[i].ItemArray[1].ToString() == "قطعة") { if (product.BiggerUnit == "الثانوية") { product.Quantity += (Convert.ToInt32(QuantityDt.Rows[i].ItemArray[0]) % (int)product.SubQuantity); product.UnitQuantity += (Convert.ToInt32(QuantityDt.Rows[i].ItemArray[0]) / product.SubQuantity); if (product.Quantity >= product.SubQuantity) { product.Quantity -= (int)product.SubQuantity; product.UnitQuantity++; } } else { product.Quantity += Convert.ToInt32(QuantityDt.Rows[i].ItemArray[0]); } } else { if (product.BiggerUnit == "الثانوية") { product.UnitQuantity += Convert.ToInt32(QuantityDt.Rows[i].ItemArray[0]); } else { product.Quantity += (Convert.ToInt32(QuantityDt.Rows[i].ItemArray[0]) / (int)product.SubQuantity); product.UnitQuantity += (Convert.ToInt32(QuantityDt.Rows[i].ItemArray[0]) % product.SubQuantity); if (product.UnitQuantity >= product.SubQuantity) { product.UnitQuantity -= (int)product.SubQuantity; product.Quantity++; } } } for (j = 0; j < DelDt.Rows.Count; j++) { if (saleaction.ID_SaleAction == Convert.ToInt32(DelDt.Rows[j].ItemArray[0])) { saleaction.Exist = false; goto skip; } } } saleaction.ID_Sale = Convert.ToInt32(txtSaleID.Text); saleaction.ID_Product = Convert.ToInt32(Dt.Rows[i].ItemArray[0]); saleaction.Quantity_SaleAction = Convert.ToInt32(Dt.Rows[i].ItemArray[4]); saleaction.Price = Convert.ToDecimal(Dt.Rows[i].ItemArray[2]); saleaction.TotalPrice = Convert.ToDecimal(Dt.Rows[i].ItemArray[7]); saleaction.SalePrecentage = Convert.ToInt32(Dt.Rows[i].ItemArray[6]); saleaction.Unit = Convert.ToString(Dt.Rows[i].ItemArray[3]); saleaction.Exist = true; if (isnew || i + 1 > dtcount) { PharmaLinq.SalesActions.InsertOnSubmit(saleaction); } //Quantity Decrement if (Dt.Rows[i].ItemArray[3].ToString() == "قطعة") { if (product.BiggerUnit == "الثانوية") { product.Quantity -= (Convert.ToInt32(Dt.Rows[i].ItemArray[4]) % (int)product.SubQuantity); product.UnitQuantity -= (Convert.ToInt32(Dt.Rows[i].ItemArray[4]) / product.SubQuantity); if (product.Quantity < 0) { product.Quantity += (int)product.SubQuantity; product.UnitQuantity--; } } else { product.Quantity -= Convert.ToInt32(Dt.Rows[i].ItemArray[4]); } } else { if (product.BiggerUnit == "الثانوية") { product.UnitQuantity -= Convert.ToInt32(Dt.Rows[i].ItemArray[4]); } else { product.Quantity -= (Convert.ToInt32(Dt.Rows[i].ItemArray[4]) / (int)product.SubQuantity); product.UnitQuantity -= (Convert.ToInt32(Dt.Rows[i].ItemArray[4]) % product.SubQuantity); if (product.UnitQuantity < 0) { product.UnitQuantity += (int)product.SubQuantity; product.Quantity--; } } } //End Quantity Decrement skip :; PharmaLinq.SubmitChanges(); } sale.SalePrice = Convert.ToDecimal(salePrice); sale.Exist = true; sale.PayType = cmbPayType.Text; sale.paid = Convert.ToDecimal(txtPaid.Text); sale.ID_Customer = Convert.ToInt32(DtCustomer.Rows[cmbCustomer.SelectedIndex].ItemArray[1]); if (isnew) { sale.ID_Sale = Convert.ToInt32(txtSaleID.Text); sale.SaleDate = Convert.ToDateTime(DateTime.Now.ToString("MM/dd/yyyy HH:mm")); sale.ID_User = IDUser; PharmaLinq.Sales.InsertOnSubmit(sale); } PharmaLinq.SubmitChanges(); MessageBox.Show("تم حفظ الفاتورة"); USC_SALES usc_sale = new USC_SALES { IDUser = IDUser }; MainWindow.GetMainForm.GridUsc.Children.Clear(); MainWindow.GetMainForm.GridUsc.Children.Add(usc_sale); } else { MessageBox.Show("يجب اضافة منتجات"); } }