Exemple #1
0
 public void CreateNewState(StateRows state)
 {
     if (Index < History.Count)
         History.RemoveRange(Index, History.Count - Index);
     History.Add(state);
     Index++;
 }
Exemple #2
0
        private bool LoadState(StateRows stateRows, StateTypes stateType)
        {
            var source = DataTableGet(Table.TableSecSource.Name);
            if (source == null) return false;
            if (stateRows == null) return false;
            var rows = new List<DataRow>();

            foreach (var row in stateRows.Rows)
            {
                try
                {
                    DataRow dataRow = source.Rows.Find(new object[] { row.Item, row.Loc });
                    var fieldsValues = stateType == StateTypes.Undo ? row.FieldsValuesPrevious : row.FieldsValuesNext;
                    foreach (var field in fieldsValues)
                    {
                        dataRow[field.Field] = field.Value;
                    }
                    rows.Add(dataRow);

                    if (rows.Count > 0)
                        ((OracleDataAdapter)_adapters[Table.TableSecSource.Name]).Update(rows.ToArray());

                }
                catch (Exception ex)
                {
                    Error = ex.Message;
                    return false;
                }
            }
            return true;
        }
Exemple #3
0
        public bool DataTableSecSourceUpdateStatus(FormActions actionType, SortedSet<IL> setIL, ref SortedSet<IL> lockedIL)
        {
            var source = DataTableGet(Table.TableSecSource.Name);
            if (source == null) return false;

            var rows = new List<DataRow>();

            var stateRows = new StateRows();

            foreach (var il in setIL)
            {
                var row = source.Rows.Find(new[] { (object)il.Item, (object)il.Loc });
                //if (row.GetLocType() == LocTypes.W && row.GetItemType() != ItemTypes.ExpendMaterial) continue;

                if (!CheckPermissions2(row, actionType))
                {
                    if (!lockedIL.Contains(il))
                        lockedIL.Add(il);
                    continue;
                }

                var action = row.GetAction();
                var measureStatus = row.GetMeasureStatus();
                var measureStatusNew = row.GetMeasureStatusNew();

                object actionWrite = null;
                object measureStatusNewWrite = null;

                switch (actionType)
                {
                    case FormActions.Add:
                        {
                            measureStatusNewWrite = MeasureStatuses.InAssortment;
                            if (measureStatus == MeasureStatuses.NotInAssortment)
                            {
                                if (measureStatusNew == MeasureStatuses.NotInAssortment && action == Actions.Delete)
                                    actionWrite = Actions.NoAction;
                                else
                                    actionWrite = Actions.Leave;
                            }
                            else
                            {
                                if (measureStatusNew == MeasureStatuses.NotInAssortment)
                                    actionWrite = action == Actions.NoAction ? Actions.Leave : Actions.NoAction;
                                else
                                    actionWrite = action;
                            }
                            break;
                        }
                    case FormActions.Delete:
                        {
                            measureStatusNewWrite = MeasureStatuses.NotInAssortment;

                            if (row["DIM_ITEMLOC_SUPPLIER"] != DBNull.Value) row["DIM_ITEMLOC_SUPPLIER_NEW"] = row["DIM_ITEMLOC_SUPPLIER"];
                            if (row["DIM_ITEMLOC_SUPPLIER_DESC_NEW"] != DBNull.Value) row["DIM_ITEMLOC_SUPPLIER_DESC_NEW"] = row["DIM_ITEMLOC_SUPPLIER_DESC"];
                            if (row.GetOrderPlaceNew() != OrderPlaces.None) row["DIM_ITEMLOC_ORDERPLACE_NEW"] = row["DIM_ITEMLOC_ORDERPLACE"];
                            else row["DIM_ITEMLOC_ORDERPLACE_NEW"] = 3;
                            if (row.GetSourceMethodNew() != SourceMethods.None && row.GetSourceMethodNew() == SourceMethods.T) row["DIM_ITEMLOC_SOURCEWH_NEW"] = DBNull.Value;

                            row["DIM_ITEMLOC_SOURCEMETHOD_NEW"] = (char)SourceMethods.S;

                            if (row["DIM_ITEMLOC_SOURCEWH"] != DBNull.Value) row["DIM_ITEMLOC_SOURCEWH_NEW"] = row["DIM_ITEMLOC_SOURCEWH"];

                            if (measureStatus == MeasureStatuses.InAssortment) actionWrite = Actions.Delete;
                            else
                            {
                                if (measureStatusNew == MeasureStatuses.InAssortment)
                                    actionWrite = action == Actions.NoAction ? Actions.Delete : Actions.NoAction;
                                else
                                    actionWrite = action;
                            }
                            break;
                        }
                    case FormActions.Modify:
                        {
                            measureStatusNewWrite = measureStatusNew;
                            actionWrite = (action == Actions.NoAction &&
                                           measureStatusNew == MeasureStatuses.InAssortment)
                                              ? Actions.Modify
                                              : action;

                            // Cleanup SourceMethodNew if permission type is 'W'
                            if (UserStoreList.ContainsKey(Convert.ToInt32(il.Loc)))
                                if (UserStoreList[Convert.ToInt32(il.Loc)] == LocPermissionTypes.WarehouseTransit)
                                    if (row.GetSourceMethod() == SourceMethods.S &&
                                        row.GetSourceMethodNew() == SourceMethods.S)
                                        row["DIM_ITEMLOC_SOURCEMETHOD_NEW"] = DBNull.Value;

                            break;
                        }
                    case FormActions.ModifyCancel:
                        {
                            measureStatusNewWrite = measureStatusNew;
                            actionWrite = action == Actions.Modify ? Actions.NoAction : action;
                            break;
                        }
                    case FormActions.Restore:
                        {
                            measureStatusNewWrite = measureStatus;
                            actionWrite = Actions.NoAction;

                            row["DIM_ITEMLOC_SUPPLIER_NEW"] = row["DIM_ITEMLOC_SUPPLIER"];
                            row["DIM_ITEMLOC_SUPPLIER_DESC_NEW"] = row["DIM_ITEMLOC_SUPPLIER_DESC"];
                            row["DIM_ITEMLOC_ORDERPLACE_NEW"] = row["DIM_ITEMLOC_ORDERPLACE"];
                            row["DIM_ITEMLOC_SOURCEMETHOD_NEW"] = row["DIM_ITEMLOC_SOURCEMETHOD"];
                            row["DIM_ITEMLOC_SOURCEWH_NEW"] = row["DIM_ITEMLOC_SOURCEWH"];

                            break;
                        }
                }

                // Save row state
                stateRows.Rows.Add(new StateRow
                {
                    Item = row.GetItem(),
                    Loc = row.GetLoc(),
                    FieldsValuesPrevious = new List<FieldValue>
                    {
                        new FieldValue { Field = "ACTION", Value = (int)action },
                        new FieldValue { Field = "MEASURE_STATUS_NEW", Value = (int)measureStatusNew }
                    },
                    FieldsValuesNext = new List<FieldValue>
                    {
                        new FieldValue { Field = "ACTION", Value = (int)actionWrite },
                        new FieldValue { Field = "MEASURE_STATUS_NEW", Value = (int)measureStatusNewWrite }
                    }
                });

                row["ACTION"] = (int)actionWrite;
                row["MEASURE_STATUS_NEW"] = (int)measureStatusNewWrite;
                rows.Add(row);
            }

            Steps.CreateNewState(stateRows);
            try
            {
                if (rows.Count > 0)
                {
                    ((OracleDataAdapter)_adapters[Table.TableSecSource.Name]).Update(rows.ToArray());
                    DocChanged(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                Error = ex.Message;
                return false;
            }
            return true;
        }