Exemplo n.º 1
0
    void InitTables()
    {
        myDS = new DataSet();
        myDS.EnforceConstraints = false;

        string columnlist = QueryCreator.SortedColumnNameList(SourceTable);

        Added           = Conn.CreateTableByName(tablename, columnlist);
        Added.TableName = "added";
        Added.Namespace = SourceTable.Namespace;

        myDS.Tables.Add(Added);
        DataAccess.SetTableForReading(Added, tablename);
        CopyKeyWhenBlank(SourceTable, Added);

        ToAdd           = Conn.CreateTableByName(tablename, columnlist);
        ToAdd.TableName = "toadd";
        myDS.Tables.Add(ToAdd);
        DataAccess.SetTableForReading(ToAdd, tablename);
        CopyKeyWhenBlank(SourceTable, ToAdd);

        //Riempie la Table delle righe "ToAdd" prendendole dal DB. Questa tabella
        // contiene anche righe già "added" in memoria, che vanno quindi escluse.
        //Inoltre va integrata con righe che erano "added" e sono state rimosse
        // in memoria
        DataAccess.RUN_SELECT_INTO_TABLE(Conn, ToAdd, sorting, filterSQL, null, true);

        //Riempie la Table delle righe "Added". Questa contiene anche righe che sono
        // state rimosse in memoria, e quindi vanno rimosse (e integrate a "ToAdd")
        QueryCreator.MergeDataTable(Added, SourceTable);

        //Per tutte le righe rimosse in memoria (che rispettano il filtro): le toglie da
        // Added e le mette in ToAdd.
        string tomovefilter = GetData.MergeFilters(notentitychildfilter, filter);

        DataRow[] RowsToMove = Added.Select(tomovefilter);
        foreach (DataRow ToMove in RowsToMove)
        {
            string verifyexistentfilter = QueryCreator.WHERE_KEY_CLAUSE(ToMove,
                                                                        DataRowVersion.Default, false);
            //Just for sure I remove from ToAdd those rows I'm going to add to it!
            DataRow[] ToRemoveFromToAdd = ToAdd.Select(verifyexistentfilter);
            foreach (DataRow ToRemFromToAdd in ToRemoveFromToAdd)
            {
                ToRemFromToAdd.Delete();
                ToRemFromToAdd.AcceptChanges();
            }
            //Adds the row to ToAdd
            AddRowToTable(ToAdd, ToMove);

            //Remove the row from Added
            ToMove.Delete();
            if (ToMove.RowState != DataRowState.Detached)
            {
                ToMove.AcceptChanges();
            }
        }


        //Per tutte le righe rimosse in memoria rimanenti (ossia che NON rispettano
        // il filtro) : le rimuovo da Added
        DataRow[] ToRemoveFromAdded = Added.Select(notentitychildfilter);
        foreach (DataRow ToRemFromAdded in ToRemoveFromAdded)
        {
            ToRemFromAdded.Delete();
            if (ToRemFromAdded.RowState != DataRowState.Detached)
            {
                ToRemFromAdded.AcceptChanges();
            }
        }

        //Per tutte le righe rimaste in Added: le rimuove da ToAdd
        DataRow[] ToRemoveFromToAdd2 = Added.Select();
        foreach (DataRow ToRemFromToAdd in ToRemoveFromToAdd2)
        {
            string    ToRemKeyFilter = QueryCreator.WHERE_KEY_CLAUSE(ToRemFromToAdd, DataRowVersion.Default, false);
            DataRow[] ToRemove       = ToAdd.Select(ToRemKeyFilter);
            foreach (DataRow ToRem in ToRemove)
            {
                ToRem.Delete();
                if (ToRem.RowState != DataRowState.Detached)
                {
                    ToRem.AcceptChanges();
                }
            }
        }
        MetaData M = linked.Dispatcher.Get(tablename);

        M.DescribeColumns(ToAdd, listingtype);
        M.DescribeColumns(Added, listingtype);

        HT["Added"] = Added;
        HT["ToAdd"] = ToAdd;
        SetDataTable(ToAdd, GridToAdd);
        SetDataTable(Added, GridAdded);
    }
Exemplo n.º 2
0
        DataTable CalcAvailableIDClassesFor(object codicetipoclass)
        {
            Meta.GetFormData(true);
            DataRow currClass = DS.expensesorted.Rows[0];

            //If codicetipoclass not allowed, leave empty ClassMovimentiAllowed
            DataRow[] CurrTipoClasses = DS.sortingkind.Select(QHC.CmpEq("idsorkind", codicetipoclass));
            if (CurrTipoClasses.Length == 0)
            {
                return(null);
            }

            int currfase = fase;

            //ClassMovimentiAllowed = ClassMovimenti.Clone();
            //ClassMovimentiAllowed.Clear();
            DataTable ClassMovimentiAllowed = Meta.Conn.CreateTableByName("sorting", "*");


            object IDForSP = DBNull.Value;

            if (!Meta.InsertMode)
            {
                IDForSP = currClass["idexp"];
            }

            decimal curramount = CfgFn.GetNoNullDecimal(currClass["amount"]);

            //Calls sp_root_tipoclasses_spesa to get roots classes available
            DataSet OutDS = Meta.Conn.CallSP("compute_root_idsor_expense",
                                             new object[9] {
                codicetipoclass,
                Meta.GetSys("esercizio"),
                IDForSP,
                rExpense["idreg"],
                rExpense["idupb"],
                currfase,
                rExpense["idfin"],
                rExpense["idman"],
                curramount
            });

            if ((OutDS != null) && (OutDS.Tables.Count > 0))
            {
                QueryCreator.MergeDataTable(ClassMovimentiAllowed, OutDS.Tables[0]);
            }

            foreach (DataRow CurrImpClass in SourceImpClass.Rows)
            {
                if (CurrImpClass.RowState == DataRowState.Deleted)
                {
                    continue;
                }


                int currfaseImpclass = fase;

                try {
                    OutDS = Meta.Conn.CallSP("compute_filtered_idsor_expense",
                                             new object[33] {
                        codicetipoclass,
                        Meta.GetSys("esercizio"),
                        IDForSP,                                                           // CurrSpesa["idspesa"],
                        rExpense["idreg"],
                        rExpense["idupb"],
                        currfase,
                        rExpense["idfin"],
                        rExpense["idman"],
                        curramount,
                        codicetipoclass,
                        CurrImpClass["idsor"],
                        CurrImpClass["idsubclass"],
                        CurrImpClass["amount"],
                        CurrImpClass["description"],
                        CurrImpClass["flagnodate"],
                        CurrImpClass["tobecontinued"],
                        CurrImpClass["start"],
                        CurrImpClass["stop"],
                        CurrImpClass["valuen1"],
                        CurrImpClass["valuen2"],
                        CurrImpClass["valuen3"],
                        CurrImpClass["valuen4"],
                        CurrImpClass["valuen5"],
                        CurrImpClass["values1"],
                        CurrImpClass["values2"],
                        CurrImpClass["values3"],
                        CurrImpClass["values4"],
                        CurrImpClass["values5"],
                        CurrImpClass["valuev1"],
                        CurrImpClass["valuev2"],
                        CurrImpClass["valuev3"],
                        CurrImpClass["valuev4"],
                        CurrImpClass["valuev5"],
                    });
                }
                catch (Exception E) {
                    MessageBox.Show(E.Message);
                }
                if ((OutDS != null) && (OutDS.Tables.Count > 0))
                {
                    if (ClassMovimentiAllowed == null)
                    {
                        ClassMovimentiAllowed = OutDS.Tables[0];
                    }
                    else
                    {
                        QueryCreator.MergeDataTable(ClassMovimentiAllowed, OutDS.Tables[0]);
                    }
                }
            }
            return(ClassMovimentiAllowed);
        }