private void button1_Click_2(object sender, EventArgs e)
        {
            pt = new ProductsData();
            ut = new UserData();
            try
            {
                if (!File.Exists(productaddress + BarcodeBox2.Text))
                {
                    MessageBox.Show("Sorry The Id You Have Entered Is Not Valid");
                }
                else
                {
                    FileStream      fs = new FileStream(productaddress + BarcodeBox2.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    BinaryFormatter b  = new BinaryFormatter();
                    pt = (ProductsData)b.Deserialize(fs);
                    fs.Close();
                    ItemDescriptionBox2.Text = pt.itemdescription;
                    UnitBox2.Text            = pt.unit;


                    QuantityBox2.Text    = pt.quantity.ToString();
                    UnitPriceBox2.Text   = pt.unitprice.ToString();
                    RetailPriceBox2.Text = pt.retailprice.ToString();

                    FileStream      fs2 = new FileStream(useraddress + "USER", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    BinaryFormatter b2  = new BinaryFormatter();
                    ut = (UserData)b2.Deserialize(fs2);
                    fs2.Close();
                }
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.Message);
            }
        }
        private void button4_Click(object sender, EventArgs e)
        {
            pt                 = new ProductsData();
            pt.barcode         = BarcodeBox2.Text;
            pt.itemdescription = ItemDescriptionBox2.Text;
            pt.unit            = UnitBox2.Text;
            pt.quantity        = long.Parse(QuantityBox2.Text);
            pt.unitprice       = double.Parse(UnitPriceBox2.Text);
            pt.retailprice     = double.Parse(RetailPriceBox2.Text);


            if (!Directory.Exists(productaddress))
            {
                Directory.CreateDirectory(productaddress);
            }
            try
            {
                FileStream      fs = new FileStream(productaddress + BarcodeBox2.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                BinaryFormatter b  = new BinaryFormatter();
                b.Serialize(fs, pt);
                fs.Close();
                MessageBox.Show("Product Has Been Updated Successfully,Thank You");
                ClearButton2.PerformClick();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
        private void ViewRecords_Load(object sender, EventArgs e)
        {
            //
            ut = new UserData();

            try
            {
                FileStream      fs = new FileStream(useraddress + "USER", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                BinaryFormatter b  = new BinaryFormatter();
                ut = (UserData)b.Deserialize(fs);
                fs.Close();
            }
            catch (Exception exe)
            {
                MessageBox.Show(exe.Message);
            }


            ///
            ExcelExample.logic.CreateExcelDoc excell_app = new ExcelExample.logic.CreateExcelDoc();
            ///

            excell_app.createHeaders(1, 1, "Barcode", "A1", "B1", 2, "YELLOW", true, 10, "n");
            excell_app.createHeaders(1, 3, "Item Description", "C1", "D1", 2, "YELLOW", true, 10, "n");
            string barc = ut.barcode;

            string[] split = barc.Split(new Char[] { ' ' });
            int      i     = 2;

            foreach (string s in split)
            {
                if (s.Trim() != "")
                {
                    if (File.Exists(productaddress + s))
                    {
                        FileStream      fs = new FileStream(productaddress + s, FileMode.Open, FileAccess.Read);
                        BinaryFormatter b  = new BinaryFormatter();
                        st = (ProductsData)b.Deserialize(fs);
                        fs.Close();

                        string[] row0 = { st.barcode, st.itemdescription, st.unit, st.quantity.ToString(), st.unitprice.ToString(), st.retailprice.ToString() };

                        excell_app.createHeaders(i, 1, st.barcode.ToString(), "A" + i.ToString(), "B" + i.ToString(), 0, "GRAY", true, 10, "");
                        dataGridView1.Rows.Add(row0);
                        i++;
                    }
                }
            }
        }
 private void button5_Click(object sender, EventArgs e)
 {
     pt = new ProductsData();
     try
     {
         FileStream      fs = new FileStream(productaddress + BarcodeBox3.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite);
         BinaryFormatter b  = new BinaryFormatter();
         pt = (ProductsData)b.Deserialize(fs);
         fs.Close();
         ItemDescriptionBox3.Text = pt.itemdescription;
     }
     catch (Exception exe)
     {
         MessageBox.Show(exe.Message);
     }
 }
        private void button1_Click(object sender, EventArgs e)
        {
            pt = new ProductsData();
            ut = new UserData();


            if (!Directory.Exists(useraddress))
            {
                Directory.CreateDirectory(useraddress);
            }

            try
            {
                FileStream      fs3 = new FileStream(useraddress + "USER", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                BinaryFormatter b3  = new BinaryFormatter();
                ut                 = (UserData)b3.Deserialize(fs3);
                pt.barcode         = BarcodeBox.Text;
                pt.itemdescription = ItemDescriptionBox.Text;

                pt.unit        = UnitBox.Text;
                pt.quantity    = long.Parse(QuantityBox.Text);
                pt.unitprice   = double.Parse(UnitPriceBox.Text);
                pt.retailprice = double.Parse(RetailPriceBox.Text);

                ut.barcode = String.Concat(BarcodeBox.Text + " ", ut.barcode);;

                fs3.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }



            if (!Directory.Exists(productaddress))
            {
                Directory.CreateDirectory(productaddress);
            }

            try
            {
                if (File.Exists(productaddress + pt.barcode))
                {
                    MessageBox.Show("This BARCODE is already exist. Please allot another one.");
                }
                else if (BarcodeBox.Text == "")
                {
                    MessageBox.Show("Barcode ID can not be empty!");
                }
                else
                {
                    FileStream      fs = new FileStream(productaddress + pt.barcode, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    BinaryFormatter b  = new BinaryFormatter();
                    b.Serialize(fs, pt);
                    fs.Close();
                    MessageBox.Show("Product Has Been Added Successfully,Thank You");

                    FileStream      fs2 = new FileStream(useraddress + "USER", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    BinaryFormatter b2  = new BinaryFormatter();
                    b2.Serialize(fs2, ut);
                    fs2.Close();
                    ClearButton.PerformClick();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }