0

そのため、ストアド プロシージャを介して DB にアクセスし、必要なデータをポップアップ ボックスに取り込むことができます。問題は、どの行をクリックしても、同じデータがフィールドに入力され続けることです。特定の行を選択して、その特定の行のデータを DB から取得するにはどうすればよいですか? 助けてくれてありがとう

フォーム1

public partial class DSC_Mon : Form
{
    DSCU_SvcConsumer.MTCaller Caller;
    DataSet dsZA;
    DataSet dsOut;

    public DSC_Mon()
    {
        InitializeComponent();
        Caller = new DSCU_SvcConsumer.MTCaller();
        dsZA = new DataSet();
        dsOut = new DataSet();
    }

    private void DSC_Mon_Load(object sender, EventArgs e)
    {
        timer1.Enabled = true;
    }

    private void LoadData()
    {
        if (!dsZA.Tables.Contains("Query"))
        {
            DataTable dtZA = dsZA.Tables.Add("Query");
            dtZA.Columns.Add("str");
            dtZA.Rows.Add(string.Format(@"exec MON_GetStatus"));
        }
        //dtZA.Rows.Add(string.Format(@"select * from am_company"));

        dsOut.Clear();
        dsOut.Merge(Caller.CallRequest("ZuluAction", dsZA));
        if (gridEXMon.DataSource == null)
        {
            gridEXMon.DataSource = dsOut;
            gridEXMon.DataMember = "Table";
        }
        //gridEXMon.RetrieveStructure();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        timer1.Enabled = false;
        LoadData();
        timer1.Enabled = true;
    }

    private void gridEXMon_DoubleClick(object sender, EventArgs e)
    {
        ReportInfo report = new ReportInfo();
        report.ShowDialog();
    }
}

プライベート void gridEXMon_DoubleClick を次のように置き換えました。

private void gridEXMon_RowDoubleClick(object sender, Janus.Windows.GridEX.RowActionEventArgs e)
    {
        if (e.Row.RowIndex < 0)
            return;

        int rowIndex = Convert.ToInt32(e.Row.RowIndex);

        ReportInfo report = new ReportInfo(rowIndex);
        report.ShowDialog();
    }

ポップアップ ダイアログ

public partial class ReportInfo : Form
{
    public ReportInfo()
    {
        InitializeComponent();

        DSCU_SvcConsumer.MTCaller caller = new DSCU_SvcConsumer.MTCaller();

        DataSet dsZA = new DataSet();
        DataSet dsOut = new DataSet();
        if (!dsZA.Tables.Contains("Query"))
        {
            DataTable dtZA = dsZA.Tables.Add("Query");
            dtZA.Columns.Add("str");
            dtZA.Rows.Add(string.Format(@"MON_ReportInfo"));
        }

        dsOut.Clear();
        dsOut.Merge(caller.CallRequest("ZuluAction", dsZA));

        DataTable dt = dsOut.Tables["Table"];
        DataRow dr = dt.Rows[0];
        if (dt != null)
        {
            systemNameTextBox.Text = dr["System"].ToString();
            contactName1TextBox.Text = dr["Manager"].ToString();
            functionNameTextBox.Text = dr["Function"].ToString();
            durationMSTextBox.Text = dr["Speed"].ToString();
        }
    }

次に、rowIndex をポップアップに送信しました。

        DataTable dt = dsOut.Tables["Table"];
        DataRow dr = dt.Rows[rowIndex];
        systemNameTextBox.Text = dr["System"].ToString();
        contactName1TextBox.Text = dr["Manager"].ToString();
        functionNameTextBox.Text = dr["Function"].ToString();
        durationMSTextBox.Text = dr["Speed"].ToString();
    }
4

2 に答える 2

1

グリッドからデータを取得して、データベースへの余分な呼び出しを ReportInfo クラスに保存することをお勧めします。

コードは次のとおりです。

private void gridEXMon_DoubleClick(object sender, EventArgs e)
    {
        if (e.Row.RowIndex < 0)
            return;

        ReportInfo report = new ReportInfo();

        String System = Convert.ToInt32(e.Row.Cells["System"].Value);
        String Manager = Convert.ToString(e.Row.Cells["Manager"].Value);
        String Function = Convert.ToDecimal(e.Row.Cells["Function"].Value);
        String Speed = Convert.ToInt32(e.Row.Cells["Speed"].Value);

        report.ShowDialog(System, Manager, Function, Speed);
    }

次に、ReportInfo クラスの ctor は次のようになります。

public partial class ReportInfo : Form
{
    public ReportInfo(String System, String Manager, String Function, String Speed)
    {
        InitializeComponent();

        systemNameTextBox.Text = System;
        contactName1TextBox.Text = Manager;
        functionNameTextBox.Text = Function;
        durationMSTextBox.Text = Speed;
    }
}
于 2014-11-12T02:40:27.107 に答える
0

あなたは試しましたか:

gridEXMon.DataSource = dsOut.Tables[0];
// next line is not required if you've already defined proper grid structure 
gridEXMon.RetrieveStructure(); 

Janus には、ここで利用できる独自のフォーラムもあります。有益な情報がたくさんあります。ブラウジングには IE を使用します。Janus フォーラムは IE でのみ正常に動作します...

編集:

どのReportInfoレコードを選択したかをクラスはどのように知ることができますか? 特に、以下のコードがある場合:

DataTable dt = dsOut.Tables["Table"];
DataRow dr = dt.Rows[0]; // always first record is taken!

おそらく、ctor を行インデックスで定義する必要があります。

public ReportInfo(int rowIndex)
{
    ...
    DataTable dt = dsOut.Tables["Table"];
    DataRow dr = dt.Rows[rowIndex];
    ....
}
于 2014-11-11T19:21:05.247 に答える