protected override bool ItemColumnEvaluate(int row, Item item, bool updatePrice) { if (item == null) { return(false); } StockTakingDetail detail = operation.Details [row]; Item oldItem = (detail.ItemId >= 0) ? Item.GetById(detail.ItemId) : null; bool ret = detail.ItemEvaluate(item, GetOperationPriceGroup(), updatePrice); if (ret && (oldItem == null || item.Id != oldItem.Id)) { if (operation.LocationId >= 0 && !editMode) { double qtty = useCalculatedAvailability ? Item.GetAvailabilityAtDate(item.Id, operation.LocationId, date) : Item.GetAvailability(item.Id, operation.LocationId); detail.EnteredQuantity = qtty; detail.ExpectedQuantity = qtty; if (qtty > 0) { LotsEvaluate(operation.Details, detail); } } } foreach (StockTakingDetail stockTakingDetail in operation.Details) { stockTakingDetail.OldPriceIn = stockTakingDetail.PriceIn * 100 / (100 - stockTakingDetail.Discount); stockTakingDetail.OldPriceOut = stockTakingDetail.PriceOut * 100 / (100 - stockTakingDetail.Discount); } return(ret); }
private void btnSaveAndNew_Clicked(object o, EventArgs args) { long oldId = item.Id; item.Id = -1; if (!Validate()) { item.Id = oldId; return; } Item saved = GetItem().CommitChanges(); if (oldId > 0) { dlgEditNewItem.Respond(ResponseType.Ok); return; } item = null; InitializeEntries(); txtName.Text = saved.Name; cbeMesUnit.Entry.Text = saved.MUnit; cboVATGroup.SetSelection(saved.VatGroupId); SetPrices(saved); }
private bool Validate() { foreach (KeyValuePair <Entry, string> pair in priceGroupWarnings) { Entry txtPrice = pair.Key; if (Currency.IsValidExpression(txtPrice.Text)) { continue; } MessageError.ShowDialog(pair.Value); SelectInvalidPrice(txtPrice); return(false); } if (!CheckPricesSaleLessThanPurchase()) { return(false); } Item ret = GetItem(); if (string.IsNullOrWhiteSpace(ret.MUnit)) { if (!OnValidateCallback(Translator.GetString("Measurement unit cannot be empty!"), ErrorSeverity.Error, (int)Item.ErrorCodes.MeasUnitEmpty, null)) { return(false); } } BusinessDomain.AppConfiguration.CustomGeneratedBarcodeType = (GeneratedBarcodeType)cboBarcodeType.GetSelectedValue(); BusinessDomain.AppConfiguration.CustomGeneratedBarcodeFormat = txtBarcodeFormat.Text; return(GetItem().Validate(OnValidateCallback, null)); }
private bool ProdItemEvaluate(int row, string itemName) { ComplexRecipeDetail detail = recipe.DetailsProd [row]; if (detail.ItemId >= 0 && detail.ItemName == itemName) { return(true); } double currentQuantity = detail.Quantity; string codeLot; long lotId; Item item = Item.GetByAny(itemName, out barcodeUsed, out codeQtty, out codeLot, out lotId); if (!ProdItemEvaluate(row, item, true)) { return(false); } // no quantity from the barcode scanner if (codeQtty.IsZero()) { codeQtty = currentQuantity; } return(true); }
private bool ItemColumnEvaluate(int row, string itemName) { OperationDetail detail = selectedDetails [row]; if (detail.ItemId >= 0 && detail.ItemName == itemName) { return(true); } double currentQuantity = detail.Quantity; string codeLot; long lotId; Item item = Item.GetByAny(itemName, out barcodeUsed, out codeQtty, out codeLot, out lotId); bool result = selectedDetails [row].ItemEvaluate(item, PriceGroup.RegularPrice); // no quantity from the barcode scanner if (codeQtty.IsZero()) { codeQtty = currentQuantity; } return(result); }
public EditNewItem(Item item, long?defaultGroupId = null, bool allowSaveAndNew = true) { this.item = item; this.defaultGroupId = defaultGroupId; this.allowSaveAndNew = allowSaveAndNew; Initialize(); }
private void CellEdit(int row, PriceGroup groupColumn) { int col = grid.ColumnController.GetColumnOrdinal(Item.GetPriceGroupProperty(groupColumn)); grid.DisableEdit = false; grid.BeginCellEdit(new CellEventArgs(col, row)); currentPriceGroup = groupColumn; }
public AddServiceCharge(Item item, double initialServiceCharge) : this() { Item = item; if (Item != null) { txtItem.Text = Item.Name; } sbAmount.Value = initialServiceCharge; }
private static void RemoveQuickItem(string key, Dictionary <string, AccelKey> shortcuts) { string quickItem = BusinessDomain.QuickItems [key]; BusinessDomain.QuickItems.Remove(key); Item item = Item.GetByAny(quickItem); if (item != null) { shortcuts.Add(KeyShortcuts.GetAccelPath(item.Id.ToString(CultureInfo.InvariantCulture)), AccelKey.Zero); } }
private static void RemoveQuickItem(string key) { string quickItem = BusinessDomain.QuickItems [key]; BusinessDomain.QuickItems.Remove(key); Item item = Item.GetByAny(quickItem); if (item != null) { AccelMap.ChangeEntry(KeyShortcuts.GetAccelPath(item.Id.ToString(CultureInfo.InvariantCulture)), (uint)Key.VoidSymbol, 0, true); } }
private void SetPrices(Item sourceItem) { txtRegularPrice.Text = Currency.ToEditString(sourceItem.RegularPrice); txtTradePrice.Text = Currency.ToEditString(sourceItem.TradePrice); txtPriceGroup1.Text = Currency.ToEditString(sourceItem.PriceGroup1); txtPriceGroup2.Text = Currency.ToEditString(sourceItem.PriceGroup2); txtPriceGroup3.Text = Currency.ToEditString(sourceItem.PriceGroup3); txtPriceGroup4.Text = Currency.ToEditString(sourceItem.PriceGroup4); txtPriceGroup5.Text = Currency.ToEditString(sourceItem.PriceGroup5); txtPriceGroup6.Text = Currency.ToEditString(sourceItem.PriceGroup6); txtPriceGroup7.Text = Currency.ToEditString(sourceItem.PriceGroup7); txtPriceGroup8.Text = Currency.ToEditString(sourceItem.PriceGroup8); }
private bool CellEvaluate(string newValue, PriceGroup groupColumn) { bool ret; int row = grid.EditedCell.Row; Item item = entities [row]; double oldPrice = item.GetPriceGroupPrice(groupColumn); double newPrice; if (Currency.TryParseExpression(newValue, out newPrice)) { if (BusinessDomain.AppConfiguration.WarnPricesSaleLowerThanPurchase && item.TradeInPrice > newPrice && newPrice > 0) { string priceGroupText = Currency.GetAllSalePriceGroups() .Where(priceGroup => priceGroup.Key == (int)groupColumn) .Select(priceGroup => priceGroup.Value) .First(); using (MessageYesNoRemember dialog = new MessageYesNoRemember(Translator.GetString("Sale Price Lower than Purchase Price"), string.Empty, string.Format(Translator.GetString("The value you entered for \"{0}\" is lower than the purchase price. Do you want to continue?"), priceGroupText), "Icons.Question32.png")) { dialog.SetButtonText(MessageButtons.Remember, Translator.GetString("Do not warn me anymore")); ret = dialog.Run() == ResponseType.Yes; BusinessDomain.AppConfiguration.WarnPricesSaleLowerThanPurchase = !dialog.RememberChoice; } } else { ret = true; } if (ret) { item.SetPriceGroupPrice(groupColumn, newPrice); } } else { item.SetPriceGroupPrice(groupColumn, 0); ret = false; } if (ret && !oldPrice.IsEqualTo(newPrice) && !dirtyItems.Contains(item)) { btnNew.Sensitive = true; dirtyItems.Add(item); } return(ret); }
protected override bool ItemColumnEvaluate(int row, Item item, bool updatePrice) { TOperDetail detail = operation.Details [row]; bool itemChanged = item != null && detail.ItemId != item.Id; if (!base.ItemColumnEvaluate(row, item, updatePrice)) { return(false); } // only apply if the Item is being edited, that is, the quantity has been already entered TryApplyRulesOnDetail(detail, itemChanged && detail.AppliedPriceRules != PriceRule.AppliedActions.None); return(true); }
private void AddItemShortcut(IntPtr data, string accelPath, uint accelKey, ModifierType accelMods, bool changed) { long itemId; if (IsKeyForItem(accelPath, out itemId) && accelKey != 0 && accelKey != (uint)Key.VoidSymbol) { ItemShortcut itemShortcut = new ItemShortcut(); if (!itemShortcut.ItemEvaluate(Item.GetById(itemId), PriceGroup.RegularPrice)) { return; } itemShortcut.Shortcut = new AccelKey((Key)accelKey, KeyShortcuts.GetAllowedModifier(accelMods), AccelFlags.Visible); itemShortcuts.Add(itemShortcut); } }
private void InitializeGrid() { try { if (initialized) { return; } ColumnController cc = new ColumnController(); supportsSumming = false; for (int i = 0; i < dataQueryResult.Result.Columns.Count; i++) { DbField field = dataQueryResult.Columns [i].Field; DataType fieldType = ReportProvider.GetDataFieldType(field); string columnName = dataQueryResult.Result.Columns [i]; string columnHeaderText = ReportProvider.GetReportFieldColumnName(dataQueryResult, i); CellText cell; bool thisColumnSummable = false; switch (fieldType) { case DataType.Date: cell = new CellTextDate(columnName); break; case DataType.DateTime: cell = new CellTextDateTime(columnName); break; case DataType.Quantity: cell = new CellTextQuantity(columnName); thisColumnSummable = true; break; case DataType.CurrencyIn: cell = new CellTextCurrency(columnName, PriceType.Purchase); thisColumnSummable = true; break; case DataType.CurrencyOut: cell = new CellTextCurrency(columnName); thisColumnSummable = true; break; case DataType.Currency: cell = new CellTextCurrency(columnName, PriceType.Unknown); thisColumnSummable = true; break; case DataType.Percent: cell = new CellTextDouble(columnName) { FixedFaction = BusinessDomain.AppConfiguration.PercentPrecision }; break; case DataType.Id: case DataType.UserId: cell = new CellTextNumber(columnName); break; case DataType.DocumentNumber: cell = new CellTextNumber(columnName) { FixedDigits = BusinessDomain.AppConfiguration.DocumentNumberLength }; break; case DataType.OperationType: cell = new CellTextLookup <int> (columnName); CellTextLookup <int> cellOperationType = (CellTextLookup <int>)cell; foreach (OperationType operationType in Enum.GetValues(typeof(OperationType))) { if (operationType > 0) { cellOperationType.Lookup.Add((int)operationType, Translator.GetOperationTypeName(operationType)); } } break; case DataType.DocumentType: cell = new CellTextLookup <int> (columnName).Load(DocumentBase.GetAllDocumentTypes()); break; case DataType.BasePaymentType: cell = new CellTextLookup <int> (columnName).Load(PaymentType.GetAllBaseTypePairs()); break; case DataType.PaymentType: cell = new CellTextLookup <long> (columnName); CellTextLookup <long> cellPaymentType = (CellTextLookup <long>)cell; foreach (PaymentType paymentType in PaymentType.GetAll()) { cellPaymentType.Lookup.Add(paymentType.Id, paymentType.Name); } break; case DataType.PriceGroupType: cell = new CellTextLookup <int> (columnName).Load(Currency.GetAllPriceGroups()); break; case DataType.PartnerType: cell = new CellTextLookup <int> (columnName).Load(Partner.GetAllTypes()); break; case DataType.ItemType: cell = new CellTextLookup <int> (columnName).Load(Item.GetAllTypes()); break; case DataType.UserAccessLevel: cell = new CellTextLookup <int> (columnName).Load(User.GetAllAccessLevels()); break; case DataType.TurnoverType: cell = new CellTextLookup <int> (columnName).Load(CashBookEntry.GetAllTurnoverTypes()); break; case DataType.TurnoverDirection: cell = new CellTextLookup <int> (columnName).Load(CashBookEntry.GetAllTurnoverDirections()); break; case DataType.TaxGroupCode: cell = new CellTextLookup <string> (columnName).Load(VATGroup.AllCodes); break; case DataType.Sign: cell = new CellTextLookup <int> (columnName).Load(Payment.GetAllSignTypes()); break; case DataType.PaymentMode: cell = new CellTextLookup <int> (columnName).Load(Payment.GetAllModeTypes()); break; case DataType.Text: cell = new CellText(columnName); break; default: continue; } Column col = new Column(columnHeaderText, cell, 0.1, columnName) { MinWidth = 100, Visible = !skip.Contains(field) && CheckColumnVisible(dataQueryResult, i) }; cc.Add(col); supportsSumming |= thisColumnSummable && col.Visible; } grid.ColumnController = cc; // Prevent the grid from reapplying the old sort grid.Model = null; grid.Model = model; grid.AllowSelect = true; grid.AllowMultipleSelect = true; grid.CellsFucusable = true; grid.RulesHint = true; grid.SortColumnsHint = true; grid.RowActivated -= grid_RowActivated; grid.RowActivated += grid_RowActivated; initialized = true; } finally { EventHandler onInitialized = Initialized; if (onInitialized != null) { onInitialized(this, EventArgs.Empty); } } }
private bool ItemColumnEvaluate(int row, string value) { Item item = Item.GetByAny(value); return(item != null && itemShortcuts [row].ItemEvaluate(item, PriceGroup.RegularPrice)); }
private bool IsAlreadyAdded(Item item) { return(itemShortcuts.Find(i => i.ItemId == item.Id) != null && (itemShortcuts.Count <= grid.EditedCell.Row || itemShortcuts [grid.EditedCell.Row].ItemId != item.Id)); }
protected override bool ValidateSalePrice(Item item, int i, bool showWarning) { return(true); }
protected override bool ValidatePurchaseValue(Item item, int i, bool showWarning) { return(true); }
private bool ProdItemEvaluate(int row, Item item, bool updatePrice) { return(recipe.DetailsProd [row].ItemEvaluate(item, PriceGroup.RegularPrice, updatePrice)); }
private bool OperationDetailsValidate() { #region Validate materials if (recipe.DetailsMat.Count == 0) { return(false); } MatCurrentColumnEvaluate(); bool hasValidMaterialQuantities = false; for (int i = recipe.DetailsMat.Count - 1; i >= 0; i--) { try { // Validate Item string itemName = recipe.DetailsMat [i].ItemName.Trim(); // If the gooods field is empty then this line has to be skipped if (itemName.Length == 0) { // If this is not the first line then delete it if (i > 0) { recipe.DetailsMat.RemoveAt(i); continue; } DetailsValidationWarning(Translator.GetString("There are no valid materials!")); MatEditGridField(0, colItem.Index); return(false); } Item item = Item.GetById(recipe.DetailsMat [i].ItemId); if (item == null || item.Name != itemName) { DetailsValidationWarning(string.Format(Translator.GetString("Invalid item at row {0}!"), i + 1)); MatEditGridField(i, colItem.Index); return(false); } // Validate quantity double qty = recipe.DetailsMat [i].Quantity; if ((!editMode && qty <= 0) || (editMode && qty < 0)) { DetailsValidationWarning(string.Format(Translator.GetString("Invalid quantity of item \"{0}\"!"), item.Name)); MatEditGridField(i, colQuantity.Index); return(false); } if (qty > 0) { hasValidMaterialQuantities = true; } } catch { DetailsValidationWarning(string.Format(Translator.GetString("Error at row {0}!"), i + 1)); MatEditGridField(i, colItem.Index); return(false); } } if (!hasValidMaterialQuantities) { if (editMode) { ResponseType ret = DetailsValidationQuestion(Translator.GetString("There are no materials with quantities greater than 0! The recipe will be deleted. Are you sure?")); if (ret == ResponseType.No) { return(false); } } else { DetailsValidationWarning(Translator.GetString("The recipe must contain at least one material with quantity greater than 0.")); return(false); } } #endregion #region Validate products if (recipe.DetailsProd.Count == 0) { return(false); } ProdCurrentColumnEvaluate(); bool hasValidProductQuantities = false; for (int i = recipe.DetailsProd.Count - 1; i >= 0; i--) { try { // Validate Item string itemName = recipe.DetailsProd [i].ItemName.Trim(); // If the gooods field is empty then this line has to be skipped if (itemName.Length == 0) { // If this is not the first line then delete it if (i > 0) { recipe.DetailsProd.RemoveAt(i); continue; } DetailsValidationWarning(Translator.GetString("There are no valid products!")); ProdEditGridField(0, colSecondItem.Index); return(false); } Item item = Item.GetById(recipe.DetailsProd [i].ItemId); if (item == null || item.Name != itemName) { DetailsValidationWarning(string.Format(Translator.GetString("Invalid item at row {0}!"), i + 1)); ProdEditGridField(i, colSecondItem.Index); return(false); } // Validate quantity double qty = recipe.DetailsProd [i].Quantity; if ((!editMode && qty <= 0) || (editMode && qty < 0)) { DetailsValidationWarning(string.Format(Translator.GetString("Invalid quantity of item \"{0}\"!"), item.Name)); ProdEditGridField(i, colSecondQuantity.Index); return(false); } if (qty > 0) { hasValidProductQuantities = true; } } catch { DetailsValidationWarning(string.Format(Translator.GetString("Error at row {0}!"), i + 1)); ProdEditGridField(i, colSecondItem.Index); return(false); } } if (hasValidMaterialQuantities && !hasValidProductQuantities) { if (editMode) { ResponseType ret = DetailsValidationQuestion(Translator.GetString("There are no products with quantities greater than 0! The recipe will be deleted. Are you sure?")); if (ret == ResponseType.No) { return(false); } } else { DetailsValidationWarning(Translator.GetString("The recipe must contain at least one product with quantity greater than 0.")); return(false); } } #endregion for (int i = 0; i < recipe.DetailsMat.Count; i++) { ComplexRecipeDetail detMat = recipe.DetailsMat [i]; foreach (ComplexRecipeDetail detProd in recipe.DetailsProd) { if (detMat.ItemId != detProd.ItemId) { continue; } DetailsValidationWarning(string.Format(Translator.GetString("The item \"{0}\" is used as a material and as a product!"), detMat.ItemName)); MatEditGridField(i, colItem.Index); return(false); } } if (!hasValidMaterialQuantities || !hasValidProductQuantities) { recipe.ClearDetails(); } return(true); }
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); }
public static void OpenEntityForEdit(SourceItemId entity) { object id; long intId; object type; switch (entity.Table) { case DbTable.Unknown: break; case DbTable.ApplicationLog: break; case DbTable.Cashbook: break; case DbTable.Configuration: break; case DbTable.Currencies: break; case DbTable.CurrenciesHistory: break; case DbTable.Documents: id = entity [DataField.DocumentOperationNumber]; type = entity [DataField.DocumentType]; if (type == null) { break; } try { type = Enum.ToObject(typeof(OperationType), type); intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } FormHelper.EditOperation((OperationType)type, intId); break; case DbTable.EcrReceipts: break; case DbTable.Items: id = entity [DataField.ItemId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditGoodsbtnEdit") != UserRestrictionState.Allowed) { break; } using (EditNewItem dialog = new EditNewItem(Item.GetById(intId))) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetItem().CommitChanges(); } break; case DbTable.ItemsGroups: id = entity [DataField.ItemGroupId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditGoodsbtnEdit") != UserRestrictionState.Allowed) { break; } using (EditNewGroup <ItemsGroup> dialog = new EditNewGroup <ItemsGroup> (ItemsGroup.GetById(intId), ItemsGroup.GetAll())) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetGroup().CommitChanges(); } break; case DbTable.InternalLog: break; case DbTable.Lots: break; case DbTable.Network: break; case DbTable.NextAcct: break; case DbTable.Objects: id = entity [DataField.LocationId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditObjectsbtnEdit") != UserRestrictionState.Allowed) { break; } using (EditNewLocation dialog = new EditNewLocation(Location.GetById(intId))) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetLocation().CommitChanges(); } break; case DbTable.ObjectsGroups: id = entity [DataField.LocationsGroupsId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditObjectsbtnEdit") != UserRestrictionState.Allowed) { break; } using (EditNewGroup <LocationsGroup> dialog = new EditNewGroup <LocationsGroup> (LocationsGroup.GetById(intId), LocationsGroup.GetAll())) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetGroup().CommitChanges(); } break; case DbTable.Operations: type = entity [DataField.OperationType]; if (type == null) { break; } id = entity [DataField.OperationNumber]; try { type = Enum.ToObject(typeof(OperationType), type); intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } FormHelper.EditOperation((OperationType)type, intId); break; case DbTable.OperationDetails: break; case DbTable.OperationType: break; case DbTable.Partners: id = entity [DataField.PartnerId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPartnersbtnEdit") != UserRestrictionState.Allowed) { break; } using (EditNewPartner dialog = new EditNewPartner(Partner.GetById(intId))) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetPartner().CommitChanges(); } break; case DbTable.PartnersGroups: id = entity [DataField.PartnersGroupsId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPartnersbtnEdit") != UserRestrictionState.Allowed) { break; } using (EditNewGroup <PartnersGroup> dialog = new EditNewGroup <PartnersGroup> (PartnersGroup.GetById(intId), PartnersGroup.GetAll())) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetGroup().CommitChanges(); } break; case DbTable.Payments: type = entity [DataField.PaymentOperationType]; if (type == null) { break; } id = entity [DataField.PaymentOperationId]; try { type = Enum.ToObject(typeof(OperationType), type); intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPaysPaymentsbtnEdit") != UserRestrictionState.Allowed) { break; } Operation oper = Operation.GetById((OperationType)type, intId); if (oper == null) { break; } using (EditNewPayment dialog = new EditNewPayment(oper)) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) oper.CommitPayments(); } break; case DbTable.PaymentTypes: id = entity [DataField.PaymentTypesId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } using (EditNewPaymentType dialog = new EditNewPaymentType(PaymentType.GetById(intId))) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetPaymentType().CommitChanges(); } break; case DbTable.PriceRules: break; case DbTable.Registration: break; case DbTable.Store: break; case DbTable.System: break; case DbTable.Transformations: break; case DbTable.Users: EditUser(entity [DataField.UserId]); break; case DbTable.OperationUsers: EditUser(entity [DataField.OperationsUserId]); break; case DbTable.OperationOperators: EditUser(entity [DataField.OperationsOperatorId]); break; case DbTable.UsersGroup: EditUserGroup(entity [DataField.UsersGroupsId]); break; case DbTable.OperationUsersGroup: EditUserGroup(entity [DataField.OperationsUsersGroupsId]); break; case DbTable.OperationOperatorsGroup: EditUserGroup(entity [DataField.OperationsOperatorsGroupsId]); break; case DbTable.UsersSecurity: break; case DbTable.VatGroups: id = entity [DataField.VATGroupId]; try { intId = Convert.ToInt64(id); } catch (Exception ex) { ErrorHandling.LogException(ex); break; } if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditVATGroupsbtnEdit") != UserRestrictionState.Allowed) { return; } using (EditNewVATGroup dialog = new EditNewVATGroup(VATGroup.GetById(intId))) if (dialog.Run() == ResponseType.Ok) { using (new DbMasterScope(BusinessDomain.DataAccessProvider)) dialog.GetVATGroup().CommitChanges(); } break; } }
protected override bool ValidateLotQuantity(Item item, BindList <PurchaseDetail> details, int i, bool showWarning) { return(true); }
protected override bool SecondItemColumnEvaluate(int row, Item item, bool updatePrice) { return(operation.DetailsProd [row].ItemEvaluate(item, GetOperationPriceGroup(), updatePrice, operation)); }
protected override bool OperationDetailsValidate(bool showWarning) { if (operation.DetailsMat.Count == 0) { return(false); } CurrentColumnEvaluate(); bool hasValidMaterialQuantities = false; for (int i = operation.DetailsMat.Count - 1; i >= 0; i--) { try { // Validate Item string itemName = operation.DetailsMat [i].ItemName; // If the gooods field is empty then this line has to be skipped if (itemName.Length == 0) { // If this is not the first line then delete it if (i > 0) { operation.DetailsMat.RemoveAt(i); continue; } OperationDetailValidationWarning(Translator.GetString("There are no valid materials in the production document!"), showWarning); EditGridField(0, colItem.Index); return(false); } Item item = Item.GetById(operation.DetailsMat [i].ItemId); if (item == null || item.Name != itemName) { OperationDetailValidationWarning(string.Format(Translator.GetString("Invalid material at row {0}!"), i + 1), showWarning); EditGridField(i, operation.DetailsMat [i].SourceRecipe != null ? colQuantity.Index : colItem.Index); return(false); } // Validate quantity double qty = operation.DetailsMat [i].Quantity; if ((!editMode && qty <= 0) || (editMode && qty < 0)) { OperationDetailValidationWarning(string.Format(Translator.GetString("Invalid quantity of material \"{0}\"!"), item.Name), showWarning); EditGridField(i, colQuantity.Index); return(false); } if (operation.DetailsMat [i].SourceRecipe == null && !BusinessDomain.AppConfiguration.AutoProduction && BusinessDomain.AppConfiguration.ItemsManagementUseLots && operation.DetailsMat [i].LotId <= 0) { OperationDetailValidationWarning(string.Format(Translator.GetString("The sale cannot be saved due to insufficient quantity of item \"{0}\"."), item.Name), showWarning); EditGridField(i, colQuantity.Index); return(false); } if (qty > 0) { hasValidMaterialQuantities = true; } } catch { OperationDetailValidationWarning(string.Format(Translator.GetString("Error at row {0}!"), i + 1), showWarning); EditGridField(i, operation.DetailsMat [i].SourceRecipe != null ? colQuantity.Index : colItem.Index); return(false); } } if (!hasValidMaterialQuantities) { if (editMode) { ResponseType ret = OperationDetailValidationQuestion(Translator.GetString("There are no materials with quantities greater than 0! The production will be deleted. Are you sure?"), showWarning); if (ret == ResponseType.No) { return(false); } } else { OperationDetailValidationWarning(Translator.GetString("The production must contain at least one material with quantity greater than 0."), showWarning); return(false); } } bool hasValidProductQuantities = false; for (int i = operation.DetailsProd.Count - 1; i >= 0; i--) { try { // Validate Item string itemName = operation.DetailsProd [i].ItemName; // If the gooods field is empty then this line has to be skipped if (itemName.Length == 0) { // If this is not the first line then delete it if (i > 0) { operation.DetailsProd.RemoveAt(i); continue; } OperationDetailValidationWarning(Translator.GetString("There are no valid products in the production document!"), showWarning); EditSecondGridField(0, colItem.Index); return(false); } Item item = Item.GetById(operation.DetailsProd [i].ItemId); if (item == null || item.Name != itemName) { OperationDetailValidationWarning(string.Format(Translator.GetString("Invalid product at row {0}!"), i + 1), showWarning); EditSecondGridField(i, operation.DetailsMat [i].SourceRecipe != null ? colSecondQuantity.Index : colSecondItem.Index); return(false); } // Validate quantity double qty = operation.DetailsProd [i].Quantity; if ((!editMode && qty <= 0) || (editMode && qty < 0)) { OperationDetailValidationWarning(string.Format(Translator.GetString("Invalid quantity of product \"{0}\"!"), item.Name), showWarning); EditSecondGridField(i, colQuantity.Index); return(false); } if (qty > 0) { hasValidProductQuantities = true; } } catch { OperationDetailValidationWarning(string.Format(Translator.GetString("Error at row {0}!"), i + 1), showWarning); EditSecondGridField(i, operation.DetailsMat [i].SourceRecipe != null ? colSecondQuantity.Index : colSecondItem.Index); return(false); } } if (!hasValidProductQuantities) { if (editMode) { ResponseType ret = OperationDetailValidationQuestion(Translator.GetString("There are no products with quantities greater than 0! The recipe will be deleted. Are you sure?"), showWarning); if (ret == ResponseType.No) { return(false); } } else { OperationDetailValidationWarning(Translator.GetString("The recipe must contain at least one product with quantity greater than 0."), showWarning); return(false); } } for (int i = 0; i < operation.DetailsMat.Count; i++) { ComplexProductionDetail detMat = operation.DetailsMat [i]; if (operation.DetailsProd.All(detProd => detMat.ItemId != detProd.ItemId)) { continue; } OperationDetailValidationWarning(string.Format(Translator.GetString("The item \"{0}\" is used as a material and as a product!"), detMat.ItemName), showWarning); EditGridField(i, colItem.Index); return(false); } if (!hasValidMaterialQuantities || !hasValidProductQuantities) { operation.ClearDetails(); } CancelEditing(); return(true); }