Exemple #1
0
        private void cmbItem_Properties_ButtonClick(object sender, ButtonPressedEventArgs e)
        {
            try
            {
                if (e.Button.Kind == ButtonPredefines.Right)
                {
                    if (cmbItem.EditValue is int)
                    {
                        int itemID = Convert.ToInt32(cmbItem.EditValue);
                        new ItemForm(itemID, _quickInsert).ShowDialog();
                        db.Entry <DataAccess.Item>((DataAccess.Item)cmbItem.GetSelectedDataRow()).Reload();
                        //reset edit value
                        cmbItem.EditValue = null;
                        // cmbItem.EditValue = db.Items.Last().ID;
                        cmbItem.EditValue = itemID;
                    }
                    else
                    {
                        MessageBox.Show("الرجاء اختيار الصنف بصورة صحيحة من القائمة");
                    }
                }
                else
                if (e.Button.Kind == ButtonPredefines.Plus)
                {
                    ItemForm frm = new ItemForm(cmbItem.Text, _quickInsert);
                    if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        if (_quickInsert)
                        {
                            //Only quick items
                            this.itemBindingSource.DataSource = db.Items.Where(s => s.CategoryID == 2014).ToList();
                        }
                        else
                        {
                            this.itemBindingSource.DataSource = db.Items.ToList();
                        }
                        int lastId          = db.Items.Select(s => s.ID).Max();
                        var lastInsertedRow = db.Items.Where(s => s.ID == lastId).SingleOrDefault();
                        cmbItem.EditValue = lastInsertedRow.ID;
                        txtQunatity.Focus();
                    }
                }
                else
                if (e.Button.Kind == ButtonPredefines.Search)
                {
                    int ItemId = Convert.ToInt32(cmbItem.EditValue);    //Convert.ToInt32(cmbItem.GetColumnValue("ItemID"));
                    this.bindingSourceInventory.DataSource = null;

                    db.PurchaseInvoiceDetails.Where(s => s.ItemID == ItemId).Load();
                    purchaseDetails = db.PurchaseInvoiceDetails.Local.ToBindingList();

                    this.bindingSource2.DataSource = purchaseDetails;
                }
                else
                if (e.Button.Kind == ButtonPredefines.SpinRight)
                {
                    int ItemId       = Convert.ToInt32(cmbItem.EditValue);
                    var PurchaseItem = (from s in db.vw_Inventory where s.ItemID == ItemId select s).First();
                    if (PurchaseItem != null)
                    {
                        txtPurchasePrice.EditValue = PurchaseItem.PurchasePrice;
                        txtSalePrice.EditValue     = PurchaseItem.SalePrice;
                        txtDiscount.EditValue      = PurchaseItem.DiscountPrice;
                    }
                }
            }
            catch (Exception ex)
            {
                ModuleClass.ShowExceptionMessage(this, ex, "خطأ", null);
            }
        }