Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                ClassLibrary.Supplier supplier = new ClassLibrary.Supplier();

                object  id          = dataGridView1.CurrentRow.Cells["SUPPLIER_id"].Value;
                DataRow selectedRow = dtSuppliers.Rows.Find(id);

                DialogResult dlgResult = MessageBox.Show
                                             ("Are you sure you want to delete \nselected supplier with id of " + id,
                                             "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dlgResult == DialogResult.Yes)
                {
                    supplier.Id = Convert.ToInt32(id);
                    supplier.Delete();
                    displayAllSuppliers();
                }
                else if (dlgResult == DialogResult.No)
                {
                    // No, stop
                }
            }
            catch (Exception ex)
            {
                DialogResult dlgResult = MessageBox.Show
                                             ("Cant delete the record!\n you are ordering a part from this supplier. please delete the order first",
                                             "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #2
0
        //-----------------------------------------------------------------------------------------------
        private void btnSaveToDatabase_Click(object sender, EventArgs e)
        {
            if (
                (txtName.Text == "") ||
                (txtPhone.Text == "") ||
                (txtEmail.Text == "") ||
                (txtAddress.Text == "") ||
                (txtProvince.Text == "") ||
                (txtPostalCode.Text == "")
                )
            {
                MessageBox.Show("please fill all the empty fields");
            }
            else if (!Regex.IsMatch(txtPostalCode.Text, "^\\D{1}\\d{1}\\D{1}-\\d{1}\\D{1}\\d{1}$"))
            {
                MessageBox.Show("please enter the correct postal code formatting! A0A-0A0");
            }
            else if (!Regex.IsMatch(txtPhone.Text, "(^(\\+?\\-? *[0-9]+)([,0-9 ]*)([0-9 ])*$)|(^ *$)"))
            {
                MessageBox.Show("please enter a valid phone number");
            }
            else
            {
                ClassLibrary.Supplier supplier = new ClassLibrary.Supplier();
                supplier.Name       = txtName.Text;
                supplier.Address    = txtAddress.Text;
                supplier.Phone      = txtPhone.Text;
                supplier.PostalCode = txtPostalCode.Text;
                supplier.Province   = txtProvince.Text;
                supplier.Email      = txtEmail.Text;
                if (txtFailiureRate.Text != "")
                {
                    supplier.TimesFailed = Convert.ToInt32(txtFailiureRate.Text);
                }
                //ADD MODE
                if (drSupllier == null)
                {
                    //add supplier
                    int lastInsertedId = supplier.Add();
                }

                //EDIT MODE
                else
                {
                    //update supplier information
                    int supid = Convert.ToInt32(drSupllier.ItemArray[0]);
                    supplier.SupId = supid;
                    supplier.Update();
                }

                //refresh the disCustomer form
                frmDisSupplier.displayAllSuppliers();
                Close();
            }
        }
Example #3
0
        public void displayAllSuppliers()
        {
            ClassLibrary.Supplier supplier = new ClassLibrary.Supplier();

            dtSuppliers = supplier.GetAll().Tables[0];

            //set the customer_id column as primary key so you can search the table later
            dtSuppliers.PrimaryKey   = new DataColumn[] { dtSuppliers.Columns["SUPPLIER_id"] };
            dataGridView1.DataSource = dtSuppliers;

            dataGridView1.Columns["SUPPLIER_id"].HeaderText          = "ID";
            dataGridView1.Columns["SUPPLIER_name"].HeaderText        = "Name";
            dataGridView1.Columns["SUPPLIER_timesfailed"].HeaderText = "Failed";
            dataGridView1.Columns["SUPPLIER_phone"].HeaderText       = "Phone";
            dataGridView1.Columns["SUPPLIER_email"].HeaderText       = "Email";
            dataGridView1.Columns["SUPPLIER_address"].HeaderText     = "Address";
            dataGridView1.Columns["SUPPLIER_postalcode"].HeaderText  = "Postalcode";
            dataGridView1.Columns["SUPPLIER_province"].HeaderText    = "Province";
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
        }
Example #4
0
        //-------------------------------------------------------------------------------------------------
        private void frmAddPart_Load(object sender, EventArgs e)
        {
            supplerlist = new BindingList <SupplierList>();

            //add parts to the combobox
            ClassLibrary.Supplier supplier = new ClassLibrary.Supplier();
            dtSupplier = supplier.GetAll().Tables[0];
            cmbSuppliers.DataSource    = dtSupplier;
            cmbSuppliers.DisplayMember = "SUPPLIER_name";



            if (drRow == null)
            {
            }
            else
            {
                txtName.Text  = drRow.ItemArray[1].ToString();
                txtColor.Text = drRow.ItemArray[2].ToString();

                ClassLibrary.SupplierPart supplierpart = new ClassLibrary.SupplierPart();
                supplierpart.PartId = Convert.ToInt32(drRow.ItemArray[0]);
                DataTable thisTable = supplierpart.GetSupplierPartsByPartId().Tables[0];
                foreach (DataRow row in thisTable.Rows)
                {
                    //add to generic list
                    supplerlist.Add(new SupplierList
                    {
                        SupplierID   = Convert.ToInt32(row.ItemArray[0]),
                        SupplierName = row.ItemArray[1].ToString(),
                        price        = String.Format("{0:c}", row.ItemArray[2]),
                    });
                }
                dataGridView1.DataSource = supplerlist;
            }
        }