C#函数返回空列表,而函数中的列表不为空

时间:2016-11-21 10:51:44

标签: c#

调用该函数:

List<ProceduraEtapuPolaFormularza> prawoPolGrida = impuls.pobierzPrawaPolFormularza(krpEtapDlaOsoby.pe_id_etapu, pole.idPola, poleGrida.id_pola_g);

功能:

public List<ProceduraEtapuPolaFormularza> pobierzPrawaPolFormularza(int peIdEtapu,int fdpIdPola,int? fdpgIdPolaG)
{
    var p = new OracleDynamicParameters();
    p.Add("p_pe_id_etapu", peIdEtapu, OracleDbType.Int32, ParameterDirection.Input);
    p.Add("p_fdp_id_pola", fdpIdPola, OracleDbType.Int32, ParameterDirection.Input);
    p.Add("p_fdpg_id_pola_g", fdpgIdPolaG, OracleDbType.Int32, ParameterDirection.Input);
    p.Add("p_refcursor", null, OracleDbType.RefCursor, ParameterDirection.Output);
    List<ProceduraEtapuPolaFormularza> queryList = new List<ProceduraEtapuPolaFormularza>();
    queryList = connection.Query<ProceduraEtapuPolaFormularza>("ktr_coliber_pcg.pobierz_pe_pola_form", param: p, commandType: CommandType.StoredProcedure).ToList<ProceduraEtapuPolaFormularza>();
    return queryList;
}

当我在调试器中时,我进入此功能并导航到&#34; return querylist&#34;它有1个元素,但当它返回函数调用时,列表计数为0。 我想补充一点,这个函数是从construcor调用的。 我尝试了几种选择:

  • 列为输出参数
  • 列为ref参数
  • 创建List的不同方式

这里有什么问题?

构造函数(外观函数&#34; TworzFormularz&#34;):

public KorespondencjaWindowForm(KorespondencjaEtapDlaOsoby _krpEtapDlaOsoby, ImpulsRepository _impuls, FormMain formMain = null, KorespondencjaMDIForm mdiParentForm = null)
{
    _formMain = formMain;
    impuls = _impuls;
    InitializeComponent();
    gridViewFormularz.CellValueChanged += GridView1_CellValueChanged1;

    krpEtapDlaOsoby = _krpEtapDlaOsoby;
    UzupelnijNaglowekISzczegoly(_krpEtapDlaOsoby.id_korespondencji);
    TworzFormularz();
    TworzFormularzKlientow();
    PobierzZalaczniki();
    DopasujLayoutGrida();
    _mdiFormParent = mdiParentForm;
    DevExpress.Skins.SkinManager.EnableFormSkins();
    DevExpress.LookAndFeel.LookAndFeelHelper.ForceDefaultLookAndFeelChanged();
    SkinManager.EnableMdiFormSkins();
    gridViewFormularz.PopupMenuShowing += GridView1_PopupMenuShowing;
    try
    {
        impuls.WczytajUstawieniaKolumnGrida(int.Parse(_formMain.podstawowyNrEwidencyjnyOsobyZalogowanej.ToString()), int.Parse(gridViewFormularz.Name), null, ref gridViewFormularz);
    }
    catch (Exception error)
    {
        Program.logger.Error("KorespondencjaWindowForm.WczytajUstawieniaKolumnGrida():" + error.Message);
    }
  gridViewKlienci.CustomColumnDisplayText += GridViewKlienci_CustomColumnDisplayText;
  //  repositoryItemLookUpEditTypAdresu.CustomDisplayText += RepositoryItemLookUpEditTypAdresu_CustomDisplayText;
    listaHistorii= impuls.pobierzHistorieKorespondencji(krpEtapDlaOsoby.id_korespondencji);
    bindingSourceHistoria.DataSource = listaHistorii;
    gridViewKlienci.RowCellStyle += gridViewKlienci_RowCellStyle;

}

现在&#34; TworzFormularz&#34;体:

public void TworzFormularz()
{

    referencjeFormularzy = new Dictionary<dynamic, FormularzDefinicjaPola>();
    Formularz f = impuls.pobierzFormularz(krpEtapDlaOsoby.form_id_formularza);
    if (f == null) //sprawdz czy znaleziono formularz
    {
        MessageBox.Show("Nie znaleziono formularza.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        this.Close();
        return;
    }
    FormularzDefinicjaPola[] pola = impuls.pobierzPolaDlaFormularza(f.fdIdDefinicji); // pobierz pola dla tego formularza

    foreach (FormularzDefinicjaPola pole in pola) // dla wszystkich pól na formularzu
    {
        List<ProceduraEtapuPolaFormularza> prawaPolFormularza = impuls.pobierzPrawaPolFormularza(krpEtapDlaOsoby.pe_id_etapu, pole.idPola, null); //prawa dostepu

        if (pole.typPola.ToUpper() == "EDIT" || pole.typPola.ToUpper() == "MEMO")
        {

            TextEdit t = new TextEdit();
            t.AutoSize = false;
            t.Location = new Point(pole.pozycjaX, pole.pozycjaY);
            t.Size = new Size(pole.szerokosc, pole.wysokosc);
            t.Name = pole.idPola.ToString();
            t.Tag = pole.typDanych;
            panelControl1.Controls.Add(t);
            t.AutoSize = false;
            LabelControl label = new LabelControl();
            label.Text = pole.opisWyswietlany;
            label.Name = pole.idPola.ToString();
            label.Location = new Point(pole.pozycjaX-label.Width-1 , pole.pozycjaY);
            panelControl1.Controls.Add(label);
            label.Location = new Point(pole.pozycjaX - label.Width-1 , pole.pozycjaY);
            panelControl1.AutoSize = false;
            label.AutoSize = false;
            //obsluga praw do pola
            ProceduraEtapuPolaFormularza prawoPola = prawaPolFormularza.FirstOrDefault();
            if (prawaPolFormularza.Count > 1)
            {
                Program.logger.Warn("KorespondencjaWindowForm.TworzFormularz(): Znaleziono wiecej jak jedno prawo do pola o definicji: " + pole.idPola + " dla etapu: " + krpEtapDlaOsoby.id_etapu);
            }
            if (prawoPola != null && prawoPola.widocznosc!=null)
            {
                if (prawoPola.widocznosc.ToUpper() == "EDYCJA" || prawoPola.widocznosc.ToUpper() == "EDIT" || prawoPola.widocznosc.ToUpper() == "EDITABLE" || prawoPola.widocznosc.ToUpper() == "EDIT ABLE" || prawoPola.widocznosc.ToUpper() == "EDIT_ABLE")
                {
                    t.Enabled = true;
                }
                else if (prawoPola.widocznosc.ToUpper() == "TYLKO ODCZYT" || prawoPola.widocznosc.ToUpper() == "TYLKO_ODCZYT" || prawoPola.widocznosc.ToUpper() == "READ" || prawoPola.widocznosc.ToUpper() == "READ_ONLY" || prawoPola.widocznosc.ToUpper() == "READ ONLY")
                {
                    t.Enabled = false;

                }
                else if (prawoPola.widocznosc.ToUpper() == "NIEWIDOCZNE" || prawoPola.widocznosc.ToUpper() == "INVISIBLE")
                {
                    t.Visible = false;
                    label.Visible = false;
                }
            }

            referencjeFormularzy.Add(t, pole);

        }
        if (pole.typPola.ToUpper() == "CXGRID")
        {
            DataTable dataSetGrida;
            PoleFormularza[] widokDefinicjiGrida = impuls.pobierzDefinicjeGrida(pole.idPola,krpEtapDlaOsoby.form_id_formularza); // przekazujemy idDefinicjiPola, oraz idFormularza
            if (widokDefinicjiGrida.Count() <= 0)
            {
                Program.logger.Error("TworzFormularz(): Nie wczytano kolumn dla grida o id_definicji: " + pole.idPola.ToString());
                continue;
            }
            //tworzenie data source dla grida
            dataSetGrida = UtworzDataTableDlaGrida(widokDefinicjiGrida,pole.idPola, true);
            gridViewFormularz.CustomUnboundColumnData += GridView1_CustomUnboundColumnData;

            PoleFormularza[] widokWartosciGrida = impuls.pobierzWidokGrida(pole.idPola, krpEtapDlaOsoby.form_id_formularza);
            //jezeli sa wiersze...
            if (widokWartosciGrida.Count() > 0)
            {
            }
            grid.DataSource = dataSetGrida;
            _formMain.LoadNavigatorImages24x24(ref grid);
            gridViewFormularz.Name = pole.idPola.ToString();
            //ustawienia grida.
            grid.Location = new Point(pole.pozycjaX, pole.pozycjaY);
            grid.Size = new Size(pole.szerokosc, pole.wysokosc);
            grid.MainView = gridViewFormularz;
            gridViewFormularz.InitNewRow
            += GridView1_InitNewRow;
            grid.Select();
            grid.Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left);
            grid.KeyPress += Grid_KeyPress;
            gridViewFormularz.OptionsBehavior.AllowAddRows =
              DevExpress.Utils.DefaultBoolean.True;
            grid.Width = panelControl1.Width;
            gridViewFormularz.OptionsSelection.MultiSelect = true;
            grid.UseEmbeddedNavigator = true;
            panelControl1.Controls.Add(grid);
            grid.ForceInitialize();
            #region utworzenie ColumnEditow
            foreach (GridColumn col in gridViewFormularz.Columns)
            {
                PoleFormularza poleGrida = widokDefinicjiGrida.Where(x => x.tytul == col.FieldName).FirstOrDefault();
                if (poleGrida == null)
                {
                    Program.logger.Error("TworzFormularz() : nie znaleziono definicji pola grid, dla pola o tytule: " + col.FieldName);
                    continue;
                }
                else if (poleGrida.rodzaj_pola == RodzajPolaEnum.B && poleGrida.lista_wartosci != null && poleGrida.lista_wartosci.Length > 0)
                {
                    //TODO: oprogramuj button
                    continue;
                }
                else if (poleGrida.rodzaj_pola == RodzajPolaEnum.B && (poleGrida.lista_wartosci == null || poleGrida.lista_wartosci.Length == 0))
                {
                    List<ProceduraEtapuPolaFormularza> prawoPolGrida = impuls.pobierzPrawaPolFormularza(krpEtapDlaOsoby.pe_id_etapu, pole.idPola, poleGrida.id_pola_g);
                    ProceduraEtapuPolaFormularza prawoPola2 = prawoPolGrida.FirstOrDefault();
                    if (prawoPola2!=null && (prawoPola2.widocznosc.ToUpper()=="NIEWIDOCZNE" || prawoPola2.widocznosc.ToUpper() == "INVISIBLE" || prawoPola2.widocznosc.ToUpper() == "NIEWIDOCZNY"))
                    {
                        col.Visible = false;
                    }

                    RepositoryItemTextEdit obj = new RepositoryItemTextEdit();
                    col.ColumnEdit = obj;
                }
                else
                {
                    using (var t = impuls.connection.BeginTransaction())
                    {
                        try
                        {

                            List<ProceduraEtapuPolaFormularza> prawoPolGrida = impuls.pobierzPrawaPolFormularza(krpEtapDlaOsoby.pe_id_etapu, pole.idPola, poleGrida.id_pola_g);
                            ProceduraEtapuPolaFormularza prawoPola2 = prawoPolGrida.FirstOrDefault();
                            if (prawoPola2 != null && (prawoPola2.widocznosc.ToUpper() == "NIEWIDOCZNE" || prawoPola2.widocznosc.ToUpper() == "INVISIBLE" || prawoPola2.widocznosc.ToUpper() == "NIEWIDOCZNY"))
                            {
                              col.Visible = false;
                            }
                            RepositoryItemComboBox obj = new RepositoryItemComboBox();
                            col.ColumnEdit = obj;

                        }
                        catch (Exception error)
                        {
                            t.Rollback();

                        }

                    }

                }
            }
            #endregion
            UzupelijWierszeGrida(ref widokWartosciGrida, ref dataSetGrida);
            UzupelnijEdytoryGrida(ref gridViewFormularz, widokDefinicjiGrida);
            gridViewFormularz.Columns["PolaFormularza"].Visible = false;
            // poczatek inicjalizacji wartosci grida (jeżeli użytkownik coś zmieni, to obsługa dalsza jest w evencie cell changed.
            //jezeli uzytkownik chce dodac nowy wiersz, jego obsluga nastąpi w initNewRowEvent.
            //   impuls.pasteClipboardToGrid(gridView1);

        }
        if (pole.typPola.ToUpper() == "COMBOBOX")
        {
            ComboBoxEdit cbEdit = new ComboBoxEdit();
            cbEdit.Name = pole.idPola.ToString();
            cbEdit.Location = new Point(pole.pozycjaX , pole.pozycjaY);
            cbEdit.Size = new Size(pole.szerokosc, pole.wysokosc);
            if (pole.listaWartosci != null && !pole.listaWartosci.ToUpper().Contains("SELF") && pole.typListy == "D")
            {
                dynamic src = impuls.pobierzSelectDlaGrida(pole.listaWartosci);
                cbEdit.Properties.Items.AddRange(src);
            }
            if (pole.typListy == "S" || pole.typListy == "B" && pole.listaWartosci != null && pole.listaWartosci.Length > 0)
            {
                string[] splity = @pole.listaWartosci.Split('\n');
                cbEdit.Properties.Items.AddRange(splity);
            }
            cbEdit.AutoSize = false;
            panelControl1.Controls.Add(cbEdit);
            cbEdit.Visible = true;
            LabelControl label = new LabelControl();

            label.Text = pole.opisWyswietlany;
            label.Name = pole.idPola.ToString();
            label.Location = new Point(pole.pozycjaX-label.Width-1, pole.pozycjaY);
            panelControl1.Controls.Add(label);
            label.Location = new Point(pole.pozycjaX - label.Width-1 , pole.pozycjaY);
            label.AutoSize = false;

            cbEdit.AutoSize = false;
            //obsluga praw do pola
            ProceduraEtapuPolaFormularza prawoPola = prawaPolFormularza.FirstOrDefault();
            if (prawaPolFormularza.Count > 1)
            {
                Program.logger.Warn("KorespondencjaWindowForm.TworzFormularz(): Znaleziono wiecej jak jedno prawo do pola o definicji: " + pole.idPola + " dla etapu: " + krpEtapDlaOsoby.id_etapu);
            }
            if (prawoPola != null && prawoPola.widocznosc != null)
            {
                if (prawoPola.widocznosc.ToUpper() == "EDYCJA" || prawoPola.widocznosc.ToUpper() == "EDIT" || prawoPola.widocznosc.ToUpper() == "EDITABLE" || prawoPola.widocznosc.ToUpper() == "EDIT ABLE" || prawoPola.widocznosc.ToUpper() == "EDIT_ABLE")
                {
                    cbEdit.Enabled = true;
                }
                else if (prawoPola.widocznosc.ToUpper() == "TYLKO ODCZYT" || prawoPola.widocznosc.ToUpper() == "TYLKO_ODCZYT" || prawoPola.widocznosc.ToUpper() == "READ" || prawoPola.widocznosc.ToUpper() == "READ_ONLY" || prawoPola.widocznosc.ToUpper() == "READ ONLY")
                {
                    cbEdit.Enabled = false;
                }
                else if (prawoPola.widocznosc.ToUpper() == "NIEWIDOCZNE" || prawoPola.widocznosc.ToUpper() == "INVISIBLE")
                {
                    cbEdit.Visible = false;
                    label.Visible = false;
                }
            }

            referencjeFormularzy.Add(cbEdit, pole);
        }

    }


    SimpleButton button = new SimpleButton();
    button.Text = "Zapisz";
    button.Click += Button_Click;
    button.Location = new Point(grid.Location.X , grid.Location.Y - 25);
    panelControl1.Controls.Add(button);
    SimpleButton buttonWyslij = new SimpleButton();
    buttonWyslij.Text = "Wyślij";


    panelControl1.ResumeLayout();
    buttonWyslij.Location = new Point(button.Location.X + button.Width + 10, button.Location.Y);
    panelControl1.PerformLayout();
    panelControl1.Controls.Add(buttonWyslij);
    buttonWyslij.Click += ButtonWyslij_Click;
    pobierzWartosciPol(pola);
}

调用函数的地方:

using (var t = impuls.connection.BeginTransaction())
{
    try
    {
        List<ProceduraEtapuPolaFormularza> prawoPolGrida = impuls.pobierzPrawaPolFormularza(krpEtapDlaOsoby.pe_id_etapu, pole.idPola, poleGrida.id_pola_g);
        ProceduraEtapuPolaFormularza prawoPola2 = prawoPolGrida.FirstOrDefault();
        if (prawoPola2 != null && (prawoPola2.widocznosc.ToUpper() == "NIEWIDOCZNE" || prawoPola2.widocznosc.ToUpper() == "INVISIBLE" || prawoPola2.widocznosc.ToUpper() == "NIEWIDOCZNY"))
        {
            col.Visible = false;
        }
        RepositoryItemComboBox obj = new RepositoryItemComboBox();
        col.ColumnEdit = obj;

    }
    catch (Exception error)
    {
        t.Rollback();

    }
}

1 个答案:

答案 0 :(得分:0)

我发布的代码没有错。 它可能是调试器的一些问题,它在任何地方都显示空值。 我创建了一个“foreach”循环来迭代列表,并输入一次。

多次重新打开后,调试器的清理和构建解决方案问题已经消失。

相关问题