Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UPCRMRecordImplicitOfflineFieldSetter"/> class.
 /// </summary>
 /// <param name="record">The record.</param>
 /// <param name="_offlineStationNumber">The offline station number.</param>
 public UPCRMRecordImplicitOfflineFieldSetter(UPCRMRecord record, int _offlineStationNumber)
 {
     this.Record               = record;
     this.infoAreaId           = this.Record.InfoAreaId;
     this.dataStore            = UPCRMDataStore.DefaultStore;
     this.tableInfo            = this.dataStore.TableInfoForInfoArea(this.infoAreaId);
     this.offlineStationNumber = _offlineStationNumber;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// The link info from parent link string.
        /// </summary>
        /// <param name="singleParentLink">
        /// The single parent link.
        /// </param>
        /// <returns>
        /// The <see cref="UPCRMLinkInfo"/>.
        /// </returns>
        public UPCRMLinkInfo LinkInfoFromParentLinkString(string singleParentLink)
        {
            UPCRMTableInfo tableInfo = UPCRMDataStore.DefaultStore.TableInfoForInfoArea(this.InfoAreaId);

            string[] stringParts = singleParentLink.Split(':');

            return(stringParts.Length > 1
                       ? tableInfo.LinkInfoForTargetInfoAreaIdLinkId(stringParts[0], stringParts[1].ToInt())
                       : tableInfo.LinkInfoForTargetInfoAreaIdLinkId(singleParentLink, -1));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UPCRMFieldInfo" /> class.
        /// </summary>
        /// <param name="fieldId">The field identifier.</param>
        /// <param name="crmtableInfo">The crmtable information.</param>
        /// <returns> UPCRMFieldInfo</returns>
        public static UPCRMFieldInfo Create(int fieldId, UPCRMTableInfo crmtableInfo)
        {
            var tableInfo = crmtableInfo.DataStore.DatabaseInstance.GetTableInfoByInfoArea(crmtableInfo.InfoAreaId);
            var fieldInfo = tableInfo?.GetFieldInfo(fieldId);

            if (fieldInfo == null)
            {
                return(null);
            }

            return(new UPCRMFieldInfo
            {
                InfoAreaId = crmtableInfo.InfoAreaId,
                FieldId = fieldId,
                fieldInfo = fieldInfo
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Applies the changes from record.
        /// </summary>
        /// <param name="record">The record.</param>
        public void ApplyChangesFromRecord(UPCRMRecord record)
        {
            UPCRMTableInfo tableInfo = this.UndoRequest.DataStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId());

            if (record.FieldValues != null)
            {
                foreach (UPCRMFieldValue value in record.FieldValues)
                {
                    UPCRMFieldInfo fieldInfo = tableInfo.FieldInfoForFieldId(value.FieldId);
                    if (fieldInfo != null)
                    {
                        UPCRMUndoField undoField = new UPCRMUndoField(fieldInfo.DatabaseFieldName, value.Value, null);
                        this.AddFieldValue(undoField);
                    }
                }
            }

            if (record.Links != null)
            {
                foreach (UPCRMLink link in record.Links)
                {
                    UPCRMLinkInfo linkInfo = tableInfo.LinkInfoForTargetInfoAreaIdLinkId(link.InfoAreaId, link.LinkId);
                    if (linkInfo?.HasColumn ?? false)
                    {
                        UPCRMUndoField undoField = new UPCRMUndoField(linkInfo.LinkFieldName, link.RecordId, null);
                        this.AddFieldValue(undoField);
                        string infoAreaColumnName = linkInfo.InfoAreaLinkFieldName;
                        if (!string.IsNullOrEmpty(infoAreaColumnName))
                        {
                            undoField = new UPCRMUndoField(infoAreaColumnName, link.InfoAreaId, null);
                            this.AddFieldValue(undoField);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Sources the field result row for link.
        /// </summary>
        /// <param name="link">The link.</param>
        /// <returns></returns>
        List <string> SourceFieldResultRowForLink(UPCRMLink link)
        {
            UPCRMTableInfo sourceTableInfo = this.dataStore.TableInfoForInfoArea(link.InfoAreaId);
            UPCRMLinkInfo  linkInfo        = this.tableInfo.LinkInfoForTargetInfoAreaIdLinkId(link.InfoAreaId, link.LinkId);
            bool           noFields        = true;

            if (sourceTableInfo == null || linkInfo?.LinkFieldArray == null)
            {
                return(null);
            }

            List <UPCRMFieldSetterField> fieldMap = new List <UPCRMFieldSetterField>(linkInfo.LinkFieldArray.Count);

            foreach (UPCRMLinkInfoField field in linkInfo.LinkFieldArray)
            {
                UPCRMFieldInfo fieldInfo = sourceTableInfo.FieldInfoForFieldId(field.TargetFieldId);
                if (fieldInfo != null)
                {
                    fieldMap.Add(new UPCRMFieldSetterSourceField(field.TargetFieldId));
                    noFields = false;
                }
                else
                {
                    UPCRMFieldSetterSourceLink sourceLink = null;
                    List <UPCRMLinkInfo>       allLinks   = sourceTableInfo.LinksWithField();
                    foreach (UPCRMLinkInfo currentLinkInfo in allLinks)
                    {
                        foreach (UPCRMLinkInfoField linkInfoField in currentLinkInfo.LinkFieldArray)
                        {
                            if (linkInfoField.FieldId == field.TargetFieldId)
                            {
                                UPCRMTableInfo parentTableInfo = this.dataStore.TableInfoForInfoArea(currentLinkInfo.TargetInfoAreaId);
                                UPCRMLinkInfo  parentIdentLink = parentTableInfo.IdentLink;
                                if (parentIdentLink != null)
                                {
                                    if (parentIdentLink.FirstField.TargetFieldId == linkInfoField.TargetFieldId)
                                    {
                                        sourceLink = new UPCRMFieldSetterSourceLink(currentLinkInfo.TargetInfoAreaId, currentLinkInfo.LinkId, 0);
                                        break;
                                    }

                                    if (parentIdentLink.SecondField.TargetFieldId == linkInfoField.TargetFieldId)
                                    {
                                        sourceLink = new UPCRMFieldSetterSourceLink(currentLinkInfo.TargetInfoAreaId, currentLinkInfo.LinkId, 1);
                                        break;
                                    }
                                }
                            }
                        }

                        if (sourceLink != null)
                        {
                            break;
                        }
                    }

                    if (sourceLink != null)
                    {
                        fieldMap.Add(sourceLink);
                        noFields = false;
                    }
                    else
                    {
                        fieldMap.Add(new UPCRMFieldSetterField());
                    }
                }
            }

            if (noFields)
            {
                return(null);
            }

            List <UPCRMField> queryFields = new List <UPCRMField>();
            int resultPosition            = 0;

            foreach (UPCRMFieldSetterField fieldSetterField in fieldMap)
            {
                if (fieldSetterField.IsField)
                {
                    queryFields.Add(fieldSetterField.FieldWithInfoAreaId(link.InfoAreaId));
                    fieldSetterField.ResultPosition = resultPosition++;
                }
            }

            foreach (UPCRMFieldSetterField fieldSetterField in fieldMap)
            {
                if (fieldSetterField.IsLink)
                {
                    queryFields.Add(fieldSetterField.FieldWithInfoAreaId(link.InfoAreaId));
                    fieldSetterField.ResultPosition = resultPosition++;
                }
            }

            UPContainerMetaInfo crmQuery = new UPContainerMetaInfo(queryFields, linkInfo.TargetInfoAreaId);
            UPCRMResult         result   = crmQuery.ReadRecord(link.RecordIdentification);

            if (result != null && result.RowCount == 1)
            {
                UPCRMResultRow row         = (UPCRMResultRow)result.ResultRowAtIndex(0);
                List <string>  resultArray = new List <string>(fieldMap.Count);
                foreach (UPCRMFieldSetterField field in fieldMap)
                {
                    if (field.IsField)
                    {
                        resultArray.Add(row.RawValueAtIndex(field.ResultPosition));
                    }
                    else if (field.IsLink)
                    {
                        string recordId = row.RawValueAtIndex(field.ResultPosition);
                        if (string.IsNullOrEmpty(recordId))
                        {
                            resultArray.Add(string.Empty);
                        }
                        else if (recordId.StartsWith("new") && recordId.Length == 15)
                        {
                            long offlineLnr = (Convert.ToInt64(recordId.Substring(3, 8), 16) << 16) + Convert.ToInt64(recordId.Substring(11, 4), 16);
                            if (this.offlineStationNumber > 0 && offlineLnr > 0)
                            {
                                if (((UPCRMFieldSetterSourceLink)field).FieldIndex == 0)
                                {
                                    resultArray.Add(this.offlineStationNumber.ToString());
                                }
                                else
                                {
                                    resultArray.Add(offlineLnr.ToString());
                                }
                            }
                        }
                        else if (((UPCRMFieldSetterSourceLink)field).FieldIndex == 0)
                        {
                            resultArray.Add(recordId.StatNoFromRecordIdString());
                        }
                        else
                        {
                            resultArray.Add(recordId.RecordNoFromRecordIdString());
                        }
                    }
                    else
                    {
                        resultArray.Add(string.Empty);
                    }
                }

                return(resultArray);
            }

            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks the update before cache save with database.
        /// </summary>
        /// <param name="database">The database.</param>
        /// <returns>0, if success, else error number</returns>
        private int CheckUpdateBeforeCacheSaveWithDatabase(DatabaseBase database)
        {
            UPCRMTableInfo tableInfo       = this.UndoRequest.DataStore.TableInfoForInfoArea(this.RecordIdentification.InfoAreaId());
            StringBuilder  selectStatement = new StringBuilder();

            selectStatement.Append("SELECT ");
            bool first = true;

            List <string> allColumns = this.FieldDictionary.Keys.ToList();

            foreach (string columnName in allColumns)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    selectStatement.Append(", ");
                }

                selectStatement.Append(columnName);
            }

            if (first)
            {
                selectStatement.Append("recid");
            }

            selectStatement.Append($" FROM {tableInfo.DatabaseTableName} WHERE recid = ?");
            CRMDatabase       db = this.UndoRequest.DataStore.DatabaseInstance;
            DatabaseRecordSet rs = new DatabaseRecordSet(db);

            if (!rs.Query.Prepare(selectStatement.ToString()))
            {
                return(-1);
            }

            rs.Query.Bind(1, this.RecordIdentification.RecordId());
            int ret = rs.Execute();

            if (ret != 0)
            {
                return(ret);
            }

            int rc = rs.GetRowCount();

            if (rc == 0)
            {
                this.Mode          = "UpdateNew";
                this.UndoOperation = "Delete";
                return(0);
            }

            if (rc > 1)
            {
                return(-1);
            }

            this.UndoOperation = "Update";
            int         colIndex = 0;
            DatabaseRow row      = rs.GetRow(0);

            foreach (string col in allColumns)
            {
                string v = row.GetColumn(colIndex++);
                if (v != null)
                {
                    UPCRMUndoField undoField = this.FieldDictionary[col];
                    undoField.OldValue = v;
                }
            }

            return(0);
        }