예제 #1
0
        }  // end btnClear_Click

        // Checks if Product List is empty and, if not, copies the data for the
        // ith Product to the appropriate group textboxes using the display sub.
        // Also checks to determine if the next button should be enabled.
        private void getItem(int i)
        {
            if (thisProductList.Count() == 0)
            {
                btnDelete.Enabled = false;
                btnEdit.Enabled   = false;
                // btnToString.Enabled = false;
                //lblUserMessage.Text = "Please select an operation";
            }
            else if (i < 0 || i >= thisProductList.Count())
            {
                MessageBox.Show("getItem error: index out of range");
                return;
            }
            else
            {
                currentIndex = i;
                //thisProductList.getAnItem(i).Display(this);     // *****************
                // thisOwlList.RemoveAt(i);
                //lblUserMessage.Text = "Object Type: " + thisProductList.getAnItem(i).GetType().ToString() +
                // " List Index: " + i.ToString();
                btnFind.Enabled   = true;
                btnDelete.Enabled = true;
                btnEdit.Enabled   = true;
            } // end else
        }     // end getItem
예제 #2
0
        // This class manages s serializable file object by reading from and writing to a file

        // Write the Product List to file as a serialized binary object
        public static bool writeToFile(ProductList plist, string fn)
        {
            Stream          thisFileStream;
            BinaryFormatter serializer = new BinaryFormatter();

            if (plist.Count() > 0)
            {
                try
                {
                    thisFileStream = File.Create(fn);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("File open error: Owl Member List not written", "SFManager File Open");
                    MessageBox.Show(ex.ToString());
                    return(false);
                }  // end Try

                try
                {
                    serializer.Serialize(thisFileStream, plist);
                    MessageBox.Show("File write: Owl Member List was written to serializable file.");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("File write error: Owl Member List not written", "SFManager File Write");
                    MessageBox.Show(ex.ToString());
                    return(false);
                }
                finally
                {
                    thisFileStream.Close();
                }  // end Try
            }
            else
            {
                MessageBox.Show("No Product in List");
            }
            // end if

            return(true);  // The file write succeeded
        }  // end WriteToFile