Disply的正确方法您将数据搜索到另一种形式 [英] Right way to Disply you Searched data into another form

查看:201
本文介绍了Disply的正确方法您将数据搜索到另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在按钮(搜索)后面完成了这个查询工作。

I have done this query work behind a button(search).

private void irfanUrdu(string searchtext)
        {
            BindingClear();
            OleDbConnection connection = new OleDbConnection(conStr);
            
           if (comboBoxSurahName.SelectedIndex >= 0 && comboBoxSurahName.SelectedIndex <= 113)
            {
                 searchsql  =  "Select Juz_Surah,Surah_Name,Ayat_No,Surah_Ayat,trans_irfanulquran_urdu FROM Quran Where trans_irfanulquran_urdu LIKE ''%" + searchtext + "%'' AND Juz_Surah=" + comboBoxSurahName.SelectedValue + ";";
            }
            else if (comboBoxSurahName.SelectedIndex == -1 || comboBoxSurahName.SelectedIndex == 114)
            {
                searchsql =  "Select Juz_Surah,Surah_Name,Ayat_No,Surah_Ayat,trans_irfanulquran_urdu FROM Quran Where trans_irfanulquran_urdu LIKE ''%" + searchtext + "%'';";

            }
            connection.Open();
            OleDbDataAdapter da = new OleDbDataAdapter(searchsql, connection);
            //DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            da.Fill(ds, "Quran");
            connection.Close();

            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "Quran";
            sd.dataGridviewDetail.DataSource = ds;
            sd.dataGridviewDetail.DataMember = "Quran";
            bindingManager = this.BindingContext[ds, "Quran"];

            sd.label7.Text = searchtext;
            sd.textBoxAyatText.DataBindings.Add("Text", ds, "Quran.Surah_Ayat");
            sd.textBoxTranslation.DataBindings.Add("Text", ds, "Quran.trans_irfanulquran_urdu");
            sd.textBoxAyatNo.DataBindings.Add("Text", ds, "Quran.Ayat_No");
            sd.textBoxSurahNo.DataBindings.Add("Text", ds, "Quran.Juz_Surah");
            sd.textBoxSName.DataBindings.Add("Text", ds, "Quran.Surah_Name");
            string count = "select Count(*) from Quran WHERE trans_irfanulquran_urdu LIKE ''%" + searchtext + "%'';";
            
              if (comboBoxSurahName.SelectedIndex >= 0 && comboBoxSurahName.SelectedIndex <= 113)
            {
                count =count = "select Count(*) from Quran WHERE trans_irfanulquran_urdu LIKE ''%" + searchtext + "%'' AND Juz_Surah=" + comboBoxSurahName.SelectedValue + ";";
            }
            else if (comboBoxSurahName.SelectedIndex == -1 || comboBoxSurahName.SelectedIndex == 114)
            {
                count = "select Count(*) from Quran WHERE trans_irfanulquran_urdu LIKE ''%" + searchtext + "%'';";

            }
            
            connection.Open();
            OleDbCommand command = new OleDbCommand(count, connection);
            // textBoxTotalRecord.Clear();
            textBoxTotalRecord.Text = command.ExecuteScalar().ToString();
            connection.Close();

        }





在dot运算符的帮助下(例如sd.label7.Text = searchtext; I我在上面进行了编码的粗体表示我也在不同的文本框和网格视图中将搜索到的数据显示为另一种形式。

这是将搜索到的数据显示在另一个中的正确方式或样式(不同)form?



with the help of dot operator (Like e.g sd.label7.Text = searchtext; I have bold that coding above) i am also showing my searched data into an other form in different textboxes and in a grid view .
is this the right way or style to show my searched data into another (different) form?

推荐答案

错误的方法。你正在做什么被认为是非常糟糕的做法。



一旦你在表格上公开控制,你就锁定了那个表格的设计,所以你不能在不考虑对外界的影响的情况下对其进行任何更改。具体来说,您甚至无法重命名控件以使其更易于使用:Label7现在必须永远保留Label7 - 您无法将其更改为labSearchText以使目标表单的代码更加自我记录。 br />


你不能用网格或属性视图替换文本框,如果那看起来更好,因为外界知道它们存在,并且可以做它喜欢的事情正确的方式(OOP方式)是使用公共属性(具有合理名称的单个字符串,当前设置文本框,标签等等)。使用它们。



)或者实现一个包含所有这些的数据传输类,并在目标表单中设置一个属性。

这样,显示实现对表单保持私有,而数据接口不是表单更改时更改。 (对于数据传输类,它通常可以重复用于其他目的)
Wrong way. What you are doing is considered very bad practice.

As soon as you make controls public on a form, you lock the design of that form so you can''t make any changes to it without considering the effects on the outside world. Specifically, you can''t even rename controls to make them easier to work with: "Label7" must now stay "Label7" forever - you cannot change it to "labSearchText" to make the code of the destination form more self documenting.

You can''t replace the textboxes with a grid, or property view if that would look better, because the outside world knows they exist, and can do what it likes with them.

The proper way (the OOPs way) is to use public properties (either individual strings with sensible names that currently set the textboxes, labels, and so forth) or implement a data transfer class that contains all of them, and set a property in the destination form to that.
That way, the display implementation remains private to the form, and the data interface does not change when the form does. (In the case of a data transfer class, it can often be reused to other purposes)


这篇关于Disply的正确方法您将数据搜索到另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆