protected virtual void PrepareMatrixItemList()
        {
            MatrixItemsForCreation.Cache.Clear();
            var templateItem = GetTemplateItem();
            int cnt = 0;
            var helper = GetHelper(Base);
            List <INMatrixGenerationRule> idGenerationRules, descrGenerationRules;

            GetGenerationRules(helper, out idGenerationRules, out descrGenerationRules);
            foreach (EntryMatrix row in this.Matrix.Cache.Cached.Cast <EntryMatrix>().Where(row => row.IsPreliminary != true))
            {
                for (int i = 0; i < row.InventoryIDs.Length; i++)
                {
                    MatrixInventoryItem newItem = helper.CreateMatrixItemFromTemplate(row, i, templateItem, idGenerationRules, descrGenerationRules);
                    if (newItem != null)
                    {
                        bool firstItem = (cnt == 0);
                        if (firstItem)
                        {
                            for (int j = 0; j < newItem.AttributeIDs.Length; j++)
                            {
                                AddItemAttributeColumn(j);
                            }
                        }
                        newItem.InventoryID = ++cnt;
                        MatrixItemsForCreation.Cache.Hold(newItem);
                        if (firstItem)
                        {
                            MatrixItemsForCreation.Current = newItem;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected virtual string GetGenerationRuleSample(IEnumerable <INMatrixGenerationRule> rules)
        {
            try
            {
                var helper = GetCreateMatrixItemsHelper();

                var tempItem = new MatrixInventoryItem();
                tempItem.TemplateItemID = Item.Current.TemplateItemID;

                tempItem.AttributeIDs         = Answers.SelectMain().Select(a => a.AttributeID).ToArray();
                tempItem.AttributeValues      = new string[tempItem.AttributeIDs.Length];
                tempItem.AttributeValueDescrs = new string[tempItem.AttributeIDs.Length];

                for (int attributeIndex = 0; attributeIndex < tempItem.AttributeIDs.Length; attributeIndex++)
                {
                    var attributeID = tempItem.AttributeIDs[attributeIndex];
                    var values      = CRAttribute.Attributes[attributeID].Values;
                    var value       = values.Where(v => !v.Disabled).FirstOrDefault();
                    tempItem.AttributeValues[attributeIndex]      = value?.ValueID;
                    tempItem.AttributeValueDescrs[attributeIndex] = value?.Description;
                }

                return(helper.GenerateMatrixItemID(Item.Current, rules.ToList(), tempItem, true));
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
        }
Exemplo n.º 3
0
        protected virtual void OnNewItemSelected(int?templateItemID, MatrixInventoryItem row)
        {
            InventoryItem templateItem = InventoryItem.PK.Find(Base, templateItemID);

            if (templateItem == null)
            {
                throw new RowNotFoundException(Base.Caches <InventoryItem>(), templateItemID);
            }

            var createHelper = GetCreateMatrixItemsHelper(Base);

            createHelper.GetGenerationRules(templateItemID,
                                            out List <INMatrixGenerationRule> idGenerationRules,
                                            out List <INMatrixGenerationRule> descrGenerationRules);

            object newCD = createHelper.GenerateMatrixItemID(templateItem, idGenerationRules, row);

            MatrixItems.Cache.RaiseFieldUpdating <MatrixInventoryItem.inventoryCD>(row, ref newCD);
            row.InventoryCD   = (string)newCD;
            row.InventoryID   = null;
            row.Descr         = createHelper.GenerateMatrixItemID(templateItem, descrGenerationRules, row);
            row.New           = true;
            row.BasePrice     = templateItem.BasePrice;
            row.TaxCategoryID = templateItem.TaxCategoryID;
            row.Exists        = (InventoryItem.UK.Find(Base, row.InventoryCD) != null);
            row.Qty           = 0m;
            MatrixItems.Cache.Normalize();
        }
		public virtual string GenerateMatrixItemID(
			InventoryItem template, List<INMatrixGenerationRule> genRules, MatrixInventoryItem newItem, bool useLastAutoNumberValue = false)
		{
			StringBuilder res = new StringBuilder();

			for (int i = 0; i < genRules.Count; i++)
			{
				bool isLastSegment = (i == genRules.Count - 1);
				AppendMatrixItemIDSegment(res, template, genRules[i], isLastSegment, newItem, useLastAutoNumberValue);
			}

			return res.ToString();
		}
Exemplo n.º 5
0
        protected IEnumerable copyMatItem(PXAdapter adapter)
        {
            MatrixInventoryItem  current1 = (MatrixInventoryItem)this.Base1.MatrixItems.Current;
            AdditionalAttributes current2 = this.Base3.AdditionalAttributes.Current;
            bool?selected = current1.Selected;
            bool flag     = true;

            if (selected.GetValueOrDefault() == flag & selected.HasValue)
            {
                for (int index1 = 0; index1 < current2.AttributeIdentifiers.Length; ++index1)
                {
                    int index2 = Array.IndexOf <string>(current1.AttributeIDs, current2.AttributeIdentifiers[index1]);
                    current2.Values[index1] = current1.AttributeValues[index2];
                }
            }
            this.Base3.AdditionalAttributes.Insert(current2);
            return(adapter.Get());
        }
Exemplo n.º 6
0
        protected virtual void OnExisingItemSelected(MatrixInventoryItem row, int?inventoryID)
        {
            var inventoryItem = InventoryItem.PK.Find(Base, inventoryID);

            if (inventoryItem == null)
            {
                throw new RowNotFoundException(Base.Caches <InventoryItem>(), inventoryID);
            }

            row.InventoryCD   = inventoryItem.InventoryCD;
            row.InventoryID   = inventoryItem.InventoryID;
            row.Descr         = inventoryItem.Descr;
            row.New           = false;
            row.BasePrice     = inventoryItem.BasePrice;
            row.TaxCategoryID = inventoryItem.TaxCategoryID;
            row.Exists        = false;
            row.Qty           = IsItemStatusDisabled(inventoryItem) ? (decimal?)null : 0m;
            MatrixItems.Cache.Normalize();
        }
Exemplo n.º 7
0
        protected virtual int?FindInventoryItem(MatrixInventoryItem row)
        {
            int?lastInventoryId = null;

            string[] attributeValues = new string[row.AttributeIDs.Length];

            foreach (PXResult <CSAnswers, CSAttributeGroup, InventoryItem> result in SelectInventoryWithAttributes())
            {
                InventoryItem inventoryItem = result;
                CSAnswers     attribute     = result;

                if (lastInventoryId != inventoryItem.InventoryID)
                {
                    lastInventoryId = inventoryItem.InventoryID;
                    for (int attributeIndex = 0; attributeIndex < attributeValues.Length; attributeIndex++)
                    {
                        attributeValues[attributeIndex] = null;
                    }
                }

                for (int attributeIndex = 0; attributeIndex < attributeValues.Length; attributeIndex++)
                {
                    if (string.Equals(row.AttributeIDs[attributeIndex], attribute.AttributeID, StringComparison.OrdinalIgnoreCase) &&
                        row.AttributeValues[attributeIndex] == attribute.Value)
                    {
                        attributeValues[attributeIndex] = attribute.Value;
                        break;
                    }
                }


                if (lastInventoryId != null && attributeValues.All(v => v != null))
                {
                    return(lastInventoryId);
                }
            }

            return(null);
        }
		protected virtual void AssignInventoryAttributes(InventoryItemMaintBase graph, MatrixInventoryItem itemToCreateUpdate, Dictionary<string, string> templateAttrValues)
		{
			CSAnswers[] answers = graph.Answers.Select().RowCast<CSAnswers>().ToArray();
			foreach (CSAnswers answer in answers)
			{
				string value = null;
				for (int i = 0; i < itemToCreateUpdate.AttributeIDs.Length; i++)
				{
					if (itemToCreateUpdate.AttributeIDs[i].Equals(answer.AttributeID, StringComparison.OrdinalIgnoreCase))
					{
						value = itemToCreateUpdate.AttributeValues[i];
						break;
					}
				}
				if (value == null)
				{
					templateAttrValues.TryGetValue(answer.AttributeID, out value);
				}

				answer.Value = value;
				graph.Answers.Update(answer);
			}
		}
Exemplo n.º 9
0
 protected virtual bool AllAttributesArePopulated(MatrixInventoryItem row)
 => row?.AttributeValues?.Any(v => string.IsNullOrEmpty(v)) == false;
Exemplo n.º 10
0
 public IEnumerable insertFromExcel(PXAdapter adapter)
 {
     if (this.MatrixItems4Creation.AskExt() == WebDialogResult.OK)
     {
         int      num1     = 1;
         FileInfo fileInfo = PXContext.SessionTyped <PXSessionStatePXData>().FileInfo["ImportMatrixFile"];
         //HttpContext.Current.Session.Remove("ImportMatrixFile");
         using (XLSXReader xlsxReader = new XLSXReader(fileInfo.BinData))
         {
             xlsxReader.Reset();
             xlsxReader.IndexKeyPairs.ToDictionary <KeyValuePair <int, string>, int, string>((Func <KeyValuePair <int, string>, int>)(p => p.Key), (Func <KeyValuePair <int, string>, string>)(p => p.Value));
             xlsxReader.MoveNext();
             while (xlsxReader.MoveNext())
             {
                 try
                 {
                     InventoryItem           template          = InventoryItem.PK.Find((PXGraph)this.Base, this.Base1.Header.Current.TemplateItemID);
                     CreateMatrixItemsHelper matrixItemsHelper = new CreateMatrixItemsHelper((PXGraph)this.Base);
                     System.Collections.Generic.List <INMatrixGenerationRule> idGenerationRules;
                     System.Collections.Generic.List <INMatrixGenerationRule> descrGenerationRules;
                     matrixItemsHelper.GetGenerationRules(this.Base1.Header.Current.TemplateItemID, out idGenerationRules, out descrGenerationRules);
                     foreach (EntryMatrix row in this.Base1.Matrix.Cache.Cached.Cast <EntryMatrix>().Where <EntryMatrix>((Func <EntryMatrix, bool>)(entry =>
                     {
                         bool?isPreliminary = entry.IsPreliminary;
                         bool flag = true;
                         return(!(isPreliminary.GetValueOrDefault() == flag & isPreliminary.HasValue));
                     })))
                     {
                         for (int attributeNumber = 0; attributeNumber < row.InventoryIDs.Length; ++attributeNumber)
                         {
                             MatrixInventoryItem newItem = matrixItemsHelper.CreateMatrixItemFromTemplate(row, attributeNumber, template, idGenerationRules, descrGenerationRules);
                             if (newItem != null)
                             {
                                 newItem.InventoryCD = xlsxReader.GetValue(2);
                                 newItem.Descr       = xlsxReader.GetValue(3);
                                 newItem.InventoryID = new int?(++num1);
                                 newItem.Duplicate   = new bool?(this.Base.Caches[typeof(MatrixInventoryItem)].Cached.RowCast <MatrixInventoryItem>().Any <MatrixInventoryItem>((Func <MatrixInventoryItem, bool>)(mi => mi.InventoryCD == newItem.InventoryCD)));
                                 MatrixInventoryItem matrixInventoryItem = newItem;
                                 bool?exists = newItem.Exists;
                                 bool flag1  = true;
                                 int  num2;
                                 if (!(exists.GetValueOrDefault() == flag1 & exists.HasValue))
                                 {
                                     bool?duplicate = newItem.Duplicate;
                                     bool flag2     = true;
                                     num2 = !(duplicate.GetValueOrDefault() == flag2 & duplicate.HasValue) ? 1 : 0;
                                 }
                                 else
                                 {
                                     num2 = 0;
                                 }
                                 bool?nullable = new bool?(num2 != 0);
                                 matrixInventoryItem.Selected = nullable;
                                 System.Collections.Generic.List <string> stringList = new System.Collections.Generic.List <string>();
                                 for (int index = 15; index <= xlsxReader.IndexKeyPairs.Count; ++index)
                                 {
                                     stringList.Add(xlsxReader.GetValue(index));
                                 }
                                 newItem.AttributeValues = stringList.ToArray();
                                 this.Base1.MatrixItemsForCreation.Cache.Hold((object)newItem);
                             }
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     throw ex;
                 }
                 finally
                 {
                     xlsxReader.Dispose();
                 }
             }
         }
     }
     return(adapter.Get());
 }
		protected virtual void AppendMatrixItemIDSegment(
			StringBuilder res, InventoryItem template,
			INMatrixGenerationRule genRule, bool isLastSegment, MatrixInventoryItem newItem, bool useLastAutoNumberValue)
		{
			string segValue = string.Empty;
			switch (genRule.SegmentType)
			{
				case INMatrixGenerationRule.segmentType.TemplateID:
					segValue = template.InventoryCD;
					break;
				case INMatrixGenerationRule.segmentType.TemplateDescription:
					segValue = template.Descr;
					break;
				case INMatrixGenerationRule.segmentType.AttributeCaption:
					for (int i = 0; i < newItem.AttributeIDs.Length; i++)
					{
						if (newItem.AttributeIDs[i].Equals(genRule.AttributeID, StringComparison.OrdinalIgnoreCase))
						{
							segValue = newItem.AttributeValueDescrs[i];
							break;
						}
					}
					break;
				case INMatrixGenerationRule.segmentType.AttributeValue:
					for (int i = 0; i < newItem.AttributeIDs.Length; i++)
					{
						if (newItem.AttributeIDs[i].Equals(genRule.AttributeID, StringComparison.OrdinalIgnoreCase))
						{
							segValue = newItem.AttributeValues[i];
							break;
						}
					}
					break;
				case INMatrixGenerationRule.segmentType.Constant:
					segValue = genRule.Constant;
					break;
				case INMatrixGenerationRule.segmentType.Space:
					segValue = " ";
					break;
				case INMatrixGenerationRule.segmentType.AutoNumber when !useLastAutoNumberValue:
					segValue = AutoNumberAttribute.GetNextNumber(_graph.Caches[typeof(InventoryItem)], null, genRule.NumberingID, _graph.Accessinfo.BusinessDate);
					break;
				case INMatrixGenerationRule.segmentType.AutoNumber when useLastAutoNumberValue:
					var numberingSequence = AutoNumberAttribute.GetNumberingSequence(genRule.NumberingID, _graph.Accessinfo.BranchID, _graph.Accessinfo.BusinessDate);
					segValue = numberingSequence?.LastNbr;
					if (string.IsNullOrEmpty(segValue))
						segValue = AutoNumberAttribute.GetNextNumber(_graph.Caches[typeof(InventoryItem)], null, genRule.NumberingID, _graph.Accessinfo.BusinessDate);
					break;

				default:
					throw new PXArgumentException(nameof(INMatrixGenerationRule));
			}

			segValue = segValue ?? string.Empty;

			if (segValue.Length > genRule.NumberOfCharacters)
			{
				segValue = segValue.Substring(0, (int)genRule.NumberOfCharacters);
			}
			else if (segValue.Length < genRule.NumberOfCharacters)
			{
				segValue = segValue.PadRight((int)genRule.NumberOfCharacters);
			}

			res.Append(segValue);

			if (!isLastSegment)
			{
				if (genRule.UseSpaceAsSeparator == true)
				{
					res.Append(' ');
				}
				else
				{
					res.Append(genRule.Separator);
				}
			}
		}