예제 #1
0
        public bool ItemEvaluate(Item newItem, PriceGroup priceGroup, bool updatePrice = false)
        {
            if (!CheckItemCanEvaluate(newItem))
            {
                return(false);
            }

            Item oldItem = itemId >= 0 ? Item.GetById(itemId) : null;

            if (ItemName != newItem.Name)
            {
                ItemCode  = newItem.Code;
                ItemName  = newItem.Name;
                ItemName2 = newItem.Name2;
            }

            Item = newItem;
            if (oldItem == null || newItem.Id != oldItem.Id)
            {
                ItemId      = newItem.Id;
                ItemGroupId = newItem.GroupId;
                VatGroup    = newItem.GetVATGroup();
                itemType    = newItem.Type;

                if (string.IsNullOrEmpty(newItem.MUnit))
                {
                    MesUnit [] units = MesUnit.GetByItem(newItem);
                    MUnitName = units == null?Translator.GetString("pcs.") : units [0].Name;
                }
                else
                {
                    MUnitName = newItem.MUnit;
                }

                if (oldItem == null)
                {
                    ResetQuantity();
                }
            }

            if (oldItem == null || newItem.Id != oldItem.Id || updatePrice)
            {
                UpdatePrices(newItem, priceGroup);
                VATEvaluate();
                TotalEvaluate();
            }

            var afterHandler = AfterItemEvaluate;

            if (afterHandler != null)
            {
                afterHandler(this, new AfterItemEvaluateArgs {
                    Item = newItem
                });
            }

            return(true);
        }
예제 #2
0
        private void InitializeEntries()
        {
            LazyListModel <MesUnit> units = MesUnit.GetAll();

            if (item == null)
            {
                item = new Item();

                if (defaultGroupId.HasValue)
                {
                    gEditPanel.SelectGroupId((int)defaultGroupId);
                }

                if (BusinessDomain.AppConfiguration.AutoGenerateItemCodes)
                {
                    item.AutoGenerateCode();
                }
            }
            else
            {
                gEditPanel.SelectGroupId(item.GroupId);
            }

            txtCode.Text               = item.Code;
            txtName.Text               = item.Name;
            txtDisplayName.Text        = item.Name2;
            txtCatalogNumber1.Text     = item.Catalog;
            txtCatalogNumber2.Text     = item.Catalog2;
            txtCatalogNumber3.Text     = item.Catalog3;
            txvDescription.Buffer.Text = item.Description;

            txtBarCode1.Text = item.BarCode;
            txtBarCode2.Text = item.BarCode2;

            barcodes.Clear();
            if (!string.IsNullOrWhiteSpace(item.BarCode3))
            {
                foreach (string barcode in item.BarCode3.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    barcodes.Add(barcode);
                }
            }

            if (barcodes.Count == 0)
            {
                barcodes.Add(string.Empty);
            }

            List <KeyValuePair <object, string> > barCodeTypes = Enum.GetValues(typeof(GeneratedBarcodeType))
                                                                 .Cast <object> ()
                                                                 .Select(value => new KeyValuePair <object, string> (value, value.ToString()))
                                                                 .OrderBy(p => p.Value).ToList();

            cboBarcodeType.Load(barCodeTypes, "Key", "Value", BusinessDomain.AppConfiguration.CustomGeneratedBarcodeType);
            txtBarcodeFormat.Text = BusinessDomain.AppConfiguration.CustomGeneratedBarcodeFormat;

            List <MesUnit> validUnits = units.Where(u => !string.IsNullOrWhiteSpace(u.Name)).ToList();

            cbeMesUnit.Load(validUnits, "Name", "Name");
            if (!string.IsNullOrWhiteSpace(item.MUnit))
            {
                cbeMesUnit.Entry.Text = item.MUnit;
            }
            txtMesRatio.Text = Number.ToEditString(item.MUnitRatio);
            cbeMesUnit2.Load(validUnits, "Name", "Name");
            if (!string.IsNullOrWhiteSpace(item.MUnit))
            {
                cbeMesUnit2.Entry.Text = item.MUnit2;
            }
            txtMinimalQty.Text = Quantity.ToEditString(item.MinimalQuantity);
            txtNominalQty.Text = Quantity.ToEditString(item.NominalQuantity);

            LazyListModel <VATGroup>            allGroups = VATGroup.GetAll();
            List <KeyValuePair <long, string> > vatList   = new List <KeyValuePair <long, string> > (allGroups
                                                                                                     .Select(vatGroup => new KeyValuePair <long, string> (vatGroup.Id,
                                                                                                                                                          string.Format("{0} ({1})", vatGroup.Name, Percent.ToString(vatGroup.VatValue)))));

            cboVATGroup.Load(vatList, "Key", "Value", item.VatGroupId);

            SetPrices(item);
        }