예제 #1
0
        private int sizeCount;                  //number of size options

        //Constructor
        public NewPiece(Form pParent, CatalogPiece pPiece)
        {
            //assign parameters
            parent       = pParent;
            currentPiece = pPiece;
            //instatiate
            nudPounds        = new List <NumericUpDown>();
            txtDimensions    = new List <TextBox>();
            txtDescriptions  = new List <TextBox>();
            nudPrices        = new List <NumericUpDown>();
            lblDeletes       = new List <Label>();
            fileName         = "";
            connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\PineSpringsPottery.accdb";
            connection       = new OleDbConnection(connectionString);
            InitializeComponent();
        }
예제 #2
0
        public static List <CatalogPiece> GetPieces()
        {
            List <CatalogPiece> pieces       = new List <CatalogPiece>();
            string          connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\PineSpringsPottery.accdb";
            OleDbConnection connection       = new OleDbConnection(connectionString);

            //Open connection if not already
            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }
            string selectStatement = "SELECT  PIECE_CATALOG.PieceNo, PIECE_CATALOG.PieceName, PIECE_CATALOG.Description, PIECE_CATALOG.Picture.FileName, PIECE_CATALOG.Picture.FileData " +
                                     "FROM PIECE_CATALOG ORDER BY PieceName;";

            //Create Command for select statement
            OleDbCommand selectCmd = new OleDbCommand(selectStatement, connection);

            //execute reader and close reader
            OleDbDataReader reader = selectCmd.ExecuteReader();

            while (reader.Read())
            {
                CatalogPiece temp = new CatalogPiece();
                temp.pieceNo     = Convert.ToInt32(reader["PieceNo"]);
                temp.pieceName   = Convert.ToString(reader["PieceName"]);
                temp.description = Convert.ToString(reader["Description"]);
                string filename = Convert.ToString(reader["PIECE_CATALOG.Picture.FileName"]);
                if (filename != "")
                {
                    byte[] image = GetImageBytesFromOLEField((byte[])reader["PIECE_CATALOG.Picture.FileData"]);
                    try
                    {
                        MemoryStream memStream = new MemoryStream(image);
                        temp.picture = new Bitmap(memStream);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    temp.picture = new Bitmap((System.Drawing.Image)(Resources.noimage));
                }
                temp.sizeOptions = new List <CatalogPieceSize>();
                string subSelectStatement = "SELECT PIECE_SIZE.SizeNo, PIECE_SIZE.Dimensions, PIECE_SIZE.BasePrice, PIECE_SIZE.SizeDescription, PIECE_SIZE.TotalPounds " +
                                            "FROM PIECE_SIZE WHERE PIECE_SIZE.PieceNo = " + temp.pieceNo + " ORDER BY SizeNo;";
                OleDbCommand subSelectCmd = new OleDbCommand(subSelectStatement, connection);
                //execute reader and close reader
                OleDbDataReader subReader = subSelectCmd.ExecuteReader();

                while (subReader.Read())
                {
                    CatalogPieceSize subTemp = new CatalogPieceSize();
                    subTemp.sizeNo          = Convert.ToInt32(subReader["SizeNo"]);
                    subTemp.totalPounds     = Convert.ToDecimal(subReader["TotalPounds"]);
                    subTemp.sizeDescription = Convert.ToString(subReader["SizeDescription"]);
                    subTemp.dimensions      = Convert.ToString(subReader["Dimensions"]);
                    subTemp.basePrice       = Convert.ToDecimal(subReader["BasePrice"]);
                    temp.sizeOptions.Add(subTemp);
                }
                pieces.Add(temp);
            }
            connection.Close();
            return(pieces);
        }