过滤时出现问题 [英] getting an issue while filtering

查看:134
本文介绍了过滤时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和sql在酒店系统上工作,主屏幕上显示的是FlowLayoutPanel,里面满是房间,房间呈标签形状,而地板则呈按钮形状,我有2张桌子,第一张桌子称为房间",第二张桌子称为楼层" ,假设我在1楼,2楼,3楼等房间中.
关键是如何选择位于1楼,2楼或3楼的房间
通过单击地板按钮
我尝试对其进行编码,但是它不起作用

这是我的代码:-

I''m working on hotel system by C# and sql the main screen has FlowLayoutPanel filled with rooms the rooms takes labels shape and i have floors takes buttons shape, i have 2 tables the 1st called Rooms and the 2nd called "Floors", let''s say i have rooms in floor 1 ,floor 2,floor 3 ,etc
the point is how to select the rooms which are in the floor number 1 or 2 or 3
by clicking the floor buttons
i tried to code it but it doesn''t work

This is my code:-

private void FE1_Method()
        {
            foreach (DataRow C3 in this.dB1_PureEyezDataSet.Tables["Floor"].Rows)
            {
                try
                {
                    Button B2 = new Button();
                    B2.FlatStyle = FlatStyle.Standard;
                    B2.Width = 60;
                    B2.Height = 22;
                    B2.BackColor = Color.LightSteelBlue;
                    B2.AutoSize = true;
                    B2.Dock = DockStyle.Top;
                    B2.Anchor = AnchorStyles.None;
                    B2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                    B2.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
                    FLP2.Controls.Add(B2);
                    B2.Text = C3["FLOName"].ToString();
                    //---------------------------------------------
                    B2.Click +=
                    delegate(object sender, EventArgs e)
                    {
                        //i should write a simple code here to get the rooms
                    };
                }
                catch (Exception)
                {
                }
            }
        }


FLP2是FlowLayoutPanel
我只需要可以使我按楼层号过滤房间的代码

我希望我的问题很清楚

snake


FLP2 is a FlowLayoutPanel
i just need the code which can make me filter the rooms by floor number

i hope that my problem is so clear

snake

推荐答案

This[^] page from MSDN has examples.

You would need a filter expression something like
string filterExp = "Floor = 1";
string sortExp = "";
DataRow[] drarray;
drarray = dataSet1.Rooms.Select(filterExp, sortExp, DataViewRowState.CurrentRows);


(来自链接页面上的第一个示例).

注意,您将得到DataRowsArray,您必须决定如何处理.可以直接使用Array,也可以将它们添加到另一个DataTable中.

希望这可以帮助. :)


顺便说一句,由于您不断添加功能/需求的方式,您似乎将自己编码为一个角落.
这就是商业项目无法维护并最终失败的方式.

我已经指出了在给定当前代码的情况下您可以实现所需功能的一种方法. 不是,但这是解决此问题的最佳方法.

最好的方法是由用户指示/选择楼层,然后应使用Parameterized Query(有关更多信息的Google)来仅检索该楼层的房间数据.

如果相距不远,则应该停止并列出您希望应用程序具有的所有功能,然后重新开始,并牢记所有这些功能.
[/Edit]


(from the first example on the linked page).

NOTE that you get an Array of DataRows which you will have to decide how to deal with. Either use the Array as it is or add them into another DataTable.

Hope this helps. :)


Incidentally you appear to be coding yourself into a corner because of the way you keep adding features/requirements.
This is how commercial projects become unmaintainable and eventually fail.

I have pointed out a way for you to achieve what you have asked for, given your current code. It is not, however, the best way to go about this.

The best way would be for a floor to be indicated/selected by the user and then a Parameterized Query (google that for more info) should be used to only retrieve the Room data for that floor.

If you are not too far along, you should really stop and list out all the functionality that you want your application to have and then start over, bearing all of those in mind as you go.
[/Edit]


这篇关于过滤时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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