Пример #1
0
        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
            }
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        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();
                }
            }
        }