Exemplo n.º 1
0
    /// <summary>
    /// Initializes Tables of the Company and add them to TableList property.
    /// </summary>
    private void InitTableCollection()
    {
        Dictionary<int, Table> dt = new Dictionary<int, Table>();

        SqlConnection conn = new SqlConnection(
            ConfigurationManager.ConnectionStrings["TotoCafeDB"].ConnectionString
                                              );
        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "SELECT [Table].TableID, [Table].TableName, [Table].AvailabilityID FROM [Table] " +
                                "INNER JOIN Availability ON [Table].AvailabilityID = Availability.AvailabilityID " +
                                "WHERE (Availability.Availability = @Availability) AND ([Table].CompanyID = @CompanyID) " +
                                "ORDER BY [Table].TableName";

        cmd.Parameters.AddWithValue("@CompanyID", this.CompanyID);
        cmd.Parameters.AddWithValue("@Availability", "AVAILABLE");

        cmd.Connection = conn;

        try
        {
            conn.Open();

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Table t = new Table();

                t.TableID = int.Parse(dr["TableID"].ToString());
                t.TableName = dr["TableName"].ToString();
                t.AvailabilityID = int.Parse(dr["AvailabilityID"].ToString());
                t.CompanyID = this.CompanyID;
                t.QrCode = "TotoCafe-" + this.CompanyID.ToString() + "-" + t.TableID;
                t.InitActiveController();//Current open controller..

                dt.Add(t.TableID, t);
            }
        }
        catch (Exception) { }
        finally { conn.Close(); }
        this.Tables = dt;
    }