C#& SQL Server:如何在sql中使用我的动态按钮

时间:2015-03-30 18:05:04

标签: c# sql-server button dynamic

我正在做电影预约系统。我创建了动态按钮为7 x 5.它们在我运行程序时出现。

让我们说动态按钮就座了。共有5列7行。我在SQL Server中创建了一个名为Saloon1的表,它有35个项目(A1,A2,B3,C5,D7(座位号))

seatNumber (nvarchar)
isReserved (bit)

例如,当我点击座位(按钮)B3Reserve按钮时,我想在表格中将isReserved更新为B3,我想要将该座位(按钮)的颜色更改为红色。当我再次打开预订窗口时,所有预留座位都需要以红色显示(我想我需要创建一个Saloon1类,并使这两个变量(seatNumberisReserved)静态。

像这样:

public class Saloon1
{
    public Saloon1()
    { }

    private static string _seatNumber;

    public static string SeatNumber
    {
       get { return Saloon1._seatNumber; }
       set { Saloon1._seatNumber = value; }
    }

    private static bool _isReserved;

    public static bool IsReserved
    {
        get { return Saloon1._isReserved; }
        set { Saloon1._isReserved = value; }
    }
}

我是对的吗?

以下是我为动力座椅(按钮)所做的事情

public Reservation()
{
        InitializeComponent();
        create_array_buttons(7, 5, 50, 30, 70, 20, 100, 93);
}


void create_Button(string name, int x_size, int y_size,  int x_location, int y_location)
{
        Button mybutton = new Button();
        mybutton.Name = name;
        mybutton.Width = x_size;
        mybutton.Height = y_size;
        mybutton.BackgroundImage = Resource1.SeatAvailable; // background is green if seat is available.
        mybutton.Location = new Point(x_location, y_location);
        mybutton.Click += new EventHandler(mybutton_Click);
        this.Controls.Add(mybutton);
}

void create_array_buttons(int x_num_buttons, int y_num_buttons, int sizeX, int sizeY, int x_offset, int y_offset, int location_x, int location_y)
{
        int button_number = 1;

        for (int x = 0; x < x_num_buttons; x++)
        {
            for (int y = 0; y < y_num_buttons; y++)
            {
                create_Button("seat" + Convert.ToString(button_number), sizeX, sizeY, (x * sizeX) + x_offset * x + location_x, (y * sizeY) + y_offset * y + location_y);

                button_number++;
            }
        }
}

protected void mybutton_Click(object sender, EventArgs e)
{
        Button button = sender as Button;
        button.BackgroundImage = Resource1.SeatSelected; // background will be gray when clicked
}

0 个答案:

没有答案