public void loadProductRecords()
        {
            clsDBProductRecord      dbProductRecord = new clsDBProductRecord();
            List <clsProductRecord> productRecords  = dbProductRecord.ProductRecordList();

            Int32 Index = 0;

            lstProductRecords.Items.Clear();
            while (Index < productRecords.Count)
            {
                clsProductRecord productRecord = productRecords[Index];

                ListViewItem NewItem = new ListViewItem();
                NewItem.Text = productRecord.SerialNo_IMEI;
                NewItem.SubItems.Add(productRecord.SupplierName);
                NewItem.SubItems.Add(productRecord.DeviceModel);
                NewItem.SubItems.Add("£" + productRecord.Price.ToString("F"));
                NewItem.SubItems.Add(productRecord.DateBought.ToShortDateString());
                NewItem.SubItems.Add(productRecord.Description);
                NewItem.SubItems.Add(productRecord.Status);

                NewItem.Tag = productRecord;
                lstProductRecords.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                lstProductRecords.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                lstProductRecords.Items.Add(NewItem); //Add the item to ListView

                Index++;                              //move the index to the next record
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (lstProductRecords.SelectedItems.Count > 0)
            {
                ListViewItem     selectedItem  = lstProductRecords.SelectedItems[0];
                clsProductRecord productRecord = (clsProductRecord)selectedItem.Tag;

                frmAddProductRecord showForm = new frmAddProductRecord(this, productRecord);
                showForm.Show();
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (isValid())
            {
                clsProductRecord productRecord = new clsProductRecord();
                productRecord.SerialNo_IMEI = txtSerialNo_IMEI.Text;
                clsDevice clsDevice = (clsDevice)cmbDeviceName.SelectedItem;
                if (clsDevice != null)
                {
                    productRecord.DeviceId = clsDevice.ID;
                }

                clsSupplier clsSupplier = (clsSupplier)cmbSupplierName.SelectedItem;
                if (clsSupplier != null)
                {
                    productRecord.SupplierId = clsSupplier.ID;
                }

                productRecord.Price       = Convert.ToDecimal(txtPrice.Text);
                productRecord.DateBought  = dateTimePicker1.Value;
                productRecord.Description = txtDescription.Text;
                productRecord.Status      = txtStatus.Text;
                productRecord.Returned    = chkReturned.Checked;

                clsDBProductRecord fbs = new clsDBProductRecord();
                Int32 added            = 0;
                if (txtID.Text.Length > 0)
                {
                    productRecord.ID = Convert.ToInt32(txtID.Text);
                    added            = fbs.UpdateProductRecord(productRecord);
                }
                else
                {
                    added = fbs.InsertProductRecord(productRecord);
                }

                if (added > 0)
                {
                    frmListProductRecord.loadProductRecords();
                    Close();
                }
                else
                {
                    txtErrorMessage.Text    = "Could not added ProductRecord.";
                    txtErrorMessage.Visible = true;
                }
            }
            else
            {
                txtErrorMessage.Text    = "Specify valid values";
                txtErrorMessage.Visible = true;
            }
        }
        public void TestProperties()
        {
            clsProductRecord pr = new clsProductRecord();
            Int32            id = 1;

            pr.ID = id;
            Assert.AreEqual(pr.ID, id);

            string serialNo_IMEI = "12345678910112";

            pr.SerialNo_IMEI = serialNo_IMEI;
            Assert.AreEqual(pr.SerialNo_IMEI, serialNo_IMEI);

            Int32 supplierID = 2;

            pr.SupplierId = supplierID;
            Assert.AreEqual(pr.SupplierId, supplierID);

            string supplierName = "Cosco";

            pr.SupplierName = supplierName;
            Assert.AreEqual(pr.SupplierName, supplierName);

            Int32 deviceId = 3;

            pr.DeviceId = deviceId;
            Assert.AreEqual(pr.DeviceId, deviceId);

            string deviceModel = "Samsung";

            pr.DeviceModel = deviceModel;
            Assert.AreEqual(pr.DeviceModel, deviceModel);

            decimal price = 15;

            pr.Price = price;
            Assert.AreEqual(pr.Price, price);

            string description = "Asdgdg";

            pr.Description = description;
            Assert.AreEqual(pr.Description, description);

            string status = "Basfa";

            pr.Status = status;
            Assert.AreEqual(pr.Status, status);

            Boolean returned = true;

            pr.Returned = returned;
            Assert.AreEqual(pr.Returned, returned);
        }
Example #5
0
 public Int32 InsertProductRecord(clsProductRecord productRecord)
 {
     //add the parameters
     db.AddParameter("@SerialNo_IMEI", productRecord.SerialNo_IMEI);
     db.AddParameter("@SupplierId", productRecord.SupplierId);
     db.AddParameter("@DeviceId", productRecord.DeviceId);
     db.AddParameter("@Price", productRecord.Price);
     db.AddParameter("@DateBought", productRecord.DateBought);
     db.AddParameter("@Description", productRecord.Description);
     //db.AddParameter("@Status", productRecord.Status);
     db.AddParameter("@Returned", productRecord.Returned);
     //execute the stored procedure returning the primary key value of the new record
     return(db.Execute("sproc_tblProductRecord_Insert"));
 }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (lstProductRecords.SelectedItems.Count > 0)
            {
                ListViewItem     selectedItem  = lstProductRecords.SelectedItems[0];
                clsProductRecord productRecord = (clsProductRecord)selectedItem.Tag;

                // Display a message box asking users if they
                // want to delete the selected ProductRecord.
                if (MessageBox.Show("Are you sure to Delete this ProductRecord ", "Delete ProductRecord",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    == DialogResult.Yes)
                {
                    // code for deleting the record goes here
                    clsDBProductRecord dbProductRecord = new clsDBProductRecord();
                    dbProductRecord.DeleteProductRecord(productRecord.ID);
                    loadProductRecords();
                }
            }
        }
        public void loadSuppliers(clsProductRecord productRecord)
        {
            clsDBSupplier      dbSupplier = new clsDBSupplier();
            List <clsSupplier> suppliers  = dbSupplier.SupplierList();

            Int32 Index = 0;

            cmbSupplierName.DisplayMember = "Name";
            cmbSupplierName.ValueMember   = "ID";
            cmbSupplierName.Items.Clear();
            while (Index < suppliers.Count)
            {
                clsSupplier supplier = suppliers[Index];
                cmbSupplierName.Items.Add(supplier); //add the supplier to the list
                if (productRecord != null && (productRecord.SupplierId == supplier.ID))
                {
                    cmbSupplierName.SelectedItem = supplier;
                }

                Index++; //move the index to the next record
            }
        }
        public void loadDevices(clsProductRecord productRecord)
        {
            clsDBDevice      dbDevice = new clsDBDevice();
            List <clsDevice> devices  = dbDevice.DeviceList();

            Int32 Index = 0;

            cmbDeviceName.DisplayMember = "Model";
            cmbDeviceName.ValueMember   = "ID";
            while (Index < devices.Count)
            {
                clsDevice device = devices[Index];
                cmbDeviceName.Items.Add(device);
                if (productRecord != null && (productRecord.DeviceId == device.ID))
                {
                    cmbDeviceName.SelectedItem = device;
                }


                Index++; //move the index to the next record
            }
        }
        public frmAddProductRecord(frmProductRecords frmSup, clsProductRecord productRecord)
        {
            InitializeComponent();
            frmListProductRecord = frmSup;

            if (productRecord != null)
            {
                txtID.Text                   = Convert.ToString(productRecord.ID);
                txtSerialNo_IMEI.Text        = productRecord.SerialNo_IMEI;
                cmbSupplierName.SelectedItem = productRecord.SupplierId;
                cmbDeviceName.SelectedItem   = productRecord.DeviceId;
                txtPrice.Text                = productRecord.Price.ToString("F");
                dateTimePicker1.Value        = productRecord.DateBought;
                txtDescription.Text          = productRecord.Description;
                txtStatus.Text               = productRecord.Status;
                chkReturned.Checked          = productRecord.Returned;

                btnAdd.Text = "Edit";
            }
            loadDevices(productRecord);
            loadSuppliers(productRecord);
        }
Example #10
0
        public List <clsProductRecord> ProductRecordList()
        {
            //create an array list of type lstProductRecords
            List <clsProductRecord> lstProductRecords = new List <clsProductRecord>();
            //var to store the count of records
            Int32 RecordCount;
            //var to store the index for the loop
            Int32 Index = 0;

            //get the count of records
            db.Execute("sproc_tblProductRecord_SelectAll");

            RecordCount = db.Count;
            //keep looking till all records are processed
            while (Index < RecordCount)
            {
                //create a blank productRecord
                clsProductRecord productRecord = new clsProductRecord();
                //copy the data from the table to the RAM
                productRecord.ID            = Convert.ToInt32(db.DataTable.Rows[Index]["ProductId"]);
                productRecord.SerialNo_IMEI = Convert.ToString(db.DataTable.Rows[Index]["SerialNo_IMEI"]);
                productRecord.SupplierId    = Convert.ToInt32(db.DataTable.Rows[Index]["SupplierId"]);
                productRecord.SupplierName  = Convert.ToString(db.DataTable.Rows[Index]["SupplierName"]);
                productRecord.DeviceId      = Convert.ToInt32(db.DataTable.Rows[Index]["DeviceId"]);
                productRecord.DeviceModel   = Convert.ToString(db.DataTable.Rows[Index]["Model"]);
                productRecord.Price         = Convert.ToDecimal(db.DataTable.Rows[Index]["Price"]);
                productRecord.DateBought    = Convert.ToDateTime(db.DataTable.Rows[Index]["DateBought"]);
                productRecord.Description   = Convert.ToString(db.DataTable.Rows[Index]["Description"]);
                productRecord.Status        = Convert.ToString(db.DataTable.Rows[Index]["Status"]);
                productRecord.Returned      = Convert.ToBoolean(db.DataTable.Rows[Index]["Returned"]);
                //add the blank page to the array list
                lstProductRecords.Add(productRecord);
                //increase the index
                Index++;
            }
            //return the list as the return value of the function
            return(lstProductRecords);
        }
        public void InstanceOK()
        {
            clsProductRecord pr = new clsProductRecord();

            Assert.IsNotNull(pr);
        }