예제 #1
0
        private void btnUInsert_Click(object sender, EventArgs e)
        {
            decimal n;
            int     num;

            if (cboupdCD.Text.Equals(""))
            {
                MessageBox.Show("No CD chosen! A CD must be picked!", "CD Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (txtUAlbum.Text.Equals(""))
            {
                MessageBox.Show("No album entered! This album must be entered!", "Album Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                txtUAlbum.Focus();
                return;
            }
            else if (txtUArtist.Text.Equals(""))
            {
                MessageBox.Show("No artist entered! Please type in an artist!", "Artist Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                txtUArtist.Focus();
                return;
            }

            else if (!decimal.TryParse(txtUCostPrice.Text, out n))
            {
                if (n <= 0)
                {
                    MessageBox.Show("Cost is invalid! This cost field must be re-entered!", "Cost Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                txtUCostPrice.Focus();
                return;
            }

            else if (!int.TryParse(txtuQty.Text, out num))
            {
                if (num <= 0)
                {
                    MessageBox.Show("Quality is invalid! This quality field must be re-entered!", "Quality Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                txtuQty.Focus();
                return;
            }

            char availablity = 'a';

            CD cd = new CD();

            cd.setCDID(Convert.ToInt32(txtCDID.Text));
            cd.setAlbumName(txtUAlbum.Text);
            cd.setArtist(txtUArtist.Text);
            cd.setYr(Convert.ToInt32(txtYr.Text));
            cd.setArtLabel(txtUArtistLbl.Text);
            cd.setCostPrice(Convert.ToDecimal(txtUCostPrice.Text));
            cd.setQty(Convert.ToInt32(txtuQty.Text));
            cd.setSuppId(Convert.ToInt32(cboSuppliers.Text.Substring(0, 3)));
            //cd.setAvailability('a');
            cd.setAvailability(availablity);

            cd.updCD();

            //Save Data in Supplier File
            MessageBox.Show("CD: " + cboupdCD.GetItemText(cboupdCD.SelectedItem) + "\n\nCD_ID: " + txtCDID.Text + "\nAlbum: " + txtUAlbum.Text + "\nArtist: " + txtUArtist.Text + "\nYear Released: " +
                            txtYr.Text + "\nArtist Label: " + txtUArtistLbl.Text + "\nCost Price: €" + txtUCostPrice.Text + "\nQuality: " + txtuQty.Text +
                            "\nSuppliers: " + cboSuppliers.GetItemText(cboSuppliers.SelectedItem) + "\nAvailability: " + availablity, "Updated CD Details: ", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);


            //Display confirmation message
            MessageBox.Show("CD has now been updated!", "CD Updated", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

            loadCDItems();
            // cboupdCD.SelectedIndex = -1;
            grpUCD.Visible = false;
            txtCDID.Clear();
            txtUAlbum.Clear();
            txtUArtist.Clear();
            txtYr.Clear();
            txtUArtistLbl.Clear();
            txtUCostPrice.Clear();
            txtuQty.Clear();
            cboSuppliers.SelectedIndex = -1;
        }
예제 #2
0
        private void btnInsertCD_Click(object sender, EventArgs e)
        {
            decimal number;
            int     num;


            if (txtAlbum.Text.Equals(""))
            {
                MessageBox.Show("No album entered! This album must be entered!", "Album Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                txtAlbum.Focus();
                return;
            }

            else if (txtArtist.Text.Equals(""))
            {
                MessageBox.Show("No artist entered! Please type in an artist!", "Artist Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                txtArtist.Focus();
                return;
            }



            else if (!decimal.TryParse(txtCost.Text, out number))
            {
                if (number <= 0)
                {
                    MessageBox.Show("Cost is invalid! This cost field must be re-entered!", "Cost Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                txtCost.Focus();
                return;
            }

            else if (!int.TryParse(txtQty.Text, out num))
            {
                if (num <= 0)
                {
                    MessageBox.Show("Quality is invalid! This quality field must be re-entered!", "Quality Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                txtQty.Focus();
                return;
            }

            //Set Default Values
            String availability = "a";

            CD cd = new CD();

            cd.setCDID(Convert.ToInt32(txtCDID.Text));
            cd.setAlbumName(txtAlbum.Text);
            cd.setArtist(txtArtist.Text);
            cd.setYr(Convert.ToInt32(chkYr.GetItemText(chkYr.SelectedItem)));
            cd.setArtLabel(GetRadioButtonText(grpArtistLbl));
            cd.setCostPrice(Convert.ToDecimal(txtCost.Text));
            cd.setQty(Convert.ToInt32(txtQty.Text));
            cd.setSuppId(Convert.ToInt32(cboSuppliers.Text.Substring(0, 3)));
            cd.setAvailability('a');

            cd.regCD();


            //Save Data in CD File
            MessageBox.Show("CD ID; " + txtCDID.Text + "\nAlbum: " + txtAlbum.Text + "\nArtist: " + txtArtist.Text + "\nYear Released: " + chkYr.GetItemText(chkYr.SelectedItem) +
                            "\nArtist Label: " + GetRadioButtonText(grpArtistLbl) + "\nCost Price: €" + txtCost.Text + "\nQuality: " + txtQty.Text + "\nSupplier: " + cboSuppliers.GetItemText(cboSuppliers.SelectedItem) +
                            "\nAvailabilty: " + availability, "CD Details: ", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);



            //Display confirmation message

            MessageBox.Show("CD has now been added!", "CD Confirmation", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);


            //Reset UI
            txtCDID.Text = CD.nextCD().ToString("00000");
            //txtCDID.Text = "00002";
            txtAlbum.Focus();
            txtAlbum.Clear();
            txtArtist.Clear();
            chkYr.ClearSelected();
            txtCost.Clear();
            txtQty.Clear();
            cboSuppliers.SelectedIndex = -1;


            foreach (int i in chkYr.CheckedIndices)
            {
                chkYr.SetItemCheckState(i, CheckState.Unchecked);
            }
            return;
        }