Exemplo n.º 1
0
 //selected mode -> edit, delete, new btns enabled
 //disabling other btns prevents unnecessary bugs
 private void SetItemSelectedState()
 {
     ControlUtil.DisableButtons(_btnSave, _btnCancel, _btnAddProduct, _btnRemoveProduct);
     ControlUtil.EnableButtons(_btnEdit, _btnDelete, _btnNew);
     DisablInputForm();
     ControlUtil.EnableListBoxes(_lstOrders);
 }
Exemplo n.º 2
0
        private void _btnDelete_Click(object sender, EventArgs e)
        {
            if (_lvProducts.SelectedItems.Count > 0)
            {
                DialogResult confirm = MessageBox.Show("Are you sure you want to delete this product?",
                                                       "Delete Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (confirm == DialogResult.OK)
                {
                    Product      product = new Product();
                    ListViewItem item    = _lvProducts.SelectedItems[0];
                    product = (Product)item.Tag;
                    bool deleted = db.deleteProduct(product.Id);

                    if (deleted)
                    {
                        products.Remove(product);
                    }
                }
            }
            else
            {
                MessageBox.Show("Select a product from the list to delete.", "Product not selected",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            _lvProducts.Items.Clear();
            ListProducts();
            ControlUtil.DisableButtons(_btnSave, _btnEdit, _btnDelete);
            ControlUtil.EnableButtons(_btnNew);
            ControlUtil.ClearTextBoxes(_txtName, _txtPrice, _txtDescription);
            ControlUtil.DisableTextBoxes(_txtName, _txtPrice, _txtDescription);
            _cbOrganic.Checked = false;
            _cbOrganic.Enabled = false;
        }
Exemplo n.º 3
0
 //no items in list
 private void SetInitialState()
 {
     ControlUtil.DisableButtons(_btnEdit, _btnDelete,
                                _btnCancel, _btnSave, _btnAddProduct, _btnRemoveProduct);
     ControlUtil.EnableButtons(_btnNew);
     DisablInputForm();
 }
Exemplo n.º 4
0
        private void _lvProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_lvProducts.SelectedItems.Count > 0)
            {
                ListViewItem item = _lvProducts.SelectedItems[0];
                product              = (Product)item.Tag;
                _txtName.Text        = product.ProductName;
                _txtPrice.Text       = Convert.ToString(product.Price);
                _txtDescription.Text = product.Description;

                if (product.Organic)
                {
                    _cbOrganic.Checked = true;
                }
                else
                {
                    _cbOrganic.Checked = false;
                }
            }

            ControlUtil.DisableButtons(_btnSave);
            ControlUtil.EnableButtons(_btnEdit, _btnDelete, _btnNew);
            ControlUtil.DisableTextBoxes(_txtName, _txtPrice, _txtDescription);
            _cbOrganic.Enabled = false;
        }
Exemplo n.º 5
0
        private void _btnEdit_Click(object sender, EventArgs e)
        {
            ControlUtil.EnableButtons(this._btnSave, this._btnDelete, this._btnCancel);
            ControlUtil.DisableButtons(this._btnNew, this._btnEdit);
            EnableFields();

            this._txtName.Focus();
        }
Exemplo n.º 6
0
 private void ProductForm_Load(object sender, EventArgs e)
 {
     ControlUtil.DisableButtons(_btnSave, _btnEdit, _btnDelete);
     ControlUtil.EnableButtons(_btnNew);
     ControlUtil.ClearTextBoxes(_txtName, _txtPrice, _txtDescription);
     ControlUtil.DisableTextBoxes(_txtName, _txtPrice, _txtDescription);
     _cbOrganic.Checked = false;
     _cbOrganic.Enabled = false;
 }
Exemplo n.º 7
0
 private void _btnEdit_Click(object sender, EventArgs e)
 {
     product = proEdit;
     //editing = true;
     ControlUtil.EnableTextBoxes(_txtName, _txtPrice, _txtDescription);
     _cbOrganic.Enabled = true;
     ControlUtil.EnableButtons(_btnSave);
     ControlUtil.DisableButtons(_btnEdit, _btnDelete, _btnNew);
 }
Exemplo n.º 8
0
 private void _btnCancel_Click(object sender, EventArgs e)
 {
     ControlUtil.EnableButtons(this._btnNew, this._btnEdit);
     ControlUtil.DisableButtons(this._btnSave);
     if (this.listClient.Count > 0)
     {
         this._lstClient.SelectedIndex = 0;
     }
     RefreshFields();
 }
Exemplo n.º 9
0
 private void _btnNew_Click(object sender, EventArgs e)
 {
     ControlUtil.DisableButtons(_btnNew);
     ControlUtil.EnableButtons(_btnSave);
     ControlUtil.EnableTextBoxes(_txtName, _txtPrice, _txtDescription);
     ControlUtil.ClearTextBoxes(_txtName, _txtPrice, _txtDescription);
     _cbOrganic.Checked = false;
     _cbOrganic.Enabled = true;
     product            = proNew;
 }
Exemplo n.º 10
0
        private void _btnNew_Click(object sender, EventArgs e)
        {
            _newClient = true;

            ControlUtil.DisableButtons(this._btnNew, this._btnEdit, this._btnDelete);
            ControlUtil.EnableButtons(this._btnSave);
            ClearFields();
            EnableFields();

            // the field Name receive the focus
            this._txtName.Focus();
        }
Exemplo n.º 11
0
        private void ClientForm_Load(object sender, EventArgs e)
        {
            // load the client list
            //listClient = db.GetClients();
            LoadList();

            // load the combo with the values of enum class
            LoadZone();
            LoadClientType();

            // Load the fields with the content of the selected item on the list
            RefreshFields();

            DisableFields();
            ControlUtil.DisableButtons(this._btnSave, this._btnDelete, this._btnCancel);
        }
Exemplo n.º 12
0
        private void _btnSave_Click(object sender, EventArgs e)
        {
            if (_newClient)
            {
                _sql =
                    "INSERT INTO client (clientName, phone, address, zoneid, clientTypeId) VALUES (" +
                    "'" + this._txtName.Text + "'" +
                    ", '" + this._txtPhone.Text + "'" +
                    ", '" + this._txtAddress.Text + "'" +
                    ", " + this._cmbZone.SelectedValue +
                    ", " + this._cmbType.SelectedValue + ")";
            }
            else
            {
                _sql =
                    "UPDATE client SET clientName = '" + this._txtName.Text +
                    "', phone = '" + this._txtPhone.Text +
                    "', address = '" + this._txtAddress.Text +
                    "', zoneId = " + this._cmbZone.SelectedValue +
                    ", clientTypeId = " + this._cmbType.SelectedValue +
                    " WHERE clientId = " + this.listClient[this._lstClient.SelectedIndex].id;

                // remove the selected client, and add it again with correct values
                listClient.RemoveAt(_lstClient.SelectedIndex);
            }

            _databaseExecuted = db.ExecuteDatabase(_sql);
            _newClient        = false;

            _tempClient                  = new Client();
            this._tempClient.name        = this._txtName.Text;
            this._tempClient.phoneNumber = this._txtPhone.Text;
            this._tempClient.address     = this._txtAddress.Text;
            this._tempClient.zone        = (Zone)this._cmbZone.SelectedValue;
            this._tempClient.type        = (ClientType)this._cmbType.SelectedValue;

            listClient.Add(_tempClient);

            if (_databaseExecuted)
            {
                ControlUtil.EnableButtons(this._btnNew, this._btnEdit, this._btnDelete);
                ControlUtil.DisableButtons(this._btnSave, this._btnCancel);
                DisableFields();
                ControlUtil.ResetList(this.listClient, this._bndClients, this._lstClient, "name");
                RefreshFields();
            }
        }
Exemplo n.º 13
0
        private void _btnDelete_Click(object sender, EventArgs e)
        {
            _sql =
                "DELETE FROM client" +
                " WHERE clientId = " + this.listClient[this._lstClient.SelectedIndex].id;

            _databaseExecuted = db.ExecuteDatabase(_sql);

            if (_databaseExecuted)
            {
                listClient.RemoveAt(_lstClient.SelectedIndex);
                //ControlUtil.ResetList(this.listClient, this._bndClients, this._lstClient, "name");
                LoadList();
                RefreshFields();
                DisableFields();
                ControlUtil.DisableButtons(this._btnSave, this._btnDelete, this._btnCancel);
                ControlUtil.EnableButtons(this._btnNew, this._btnEdit);
            }
        }
Exemplo n.º 14
0
        private void _btnSave_Click(object sender, EventArgs e)
        {
            //If the product was selected from listview and the edit button was pressed
            //Edit product
            if (_lvProducts.SelectedItems.Count > 0 && product == proEdit)
            {
                ListViewItem item = _lvProducts.SelectedItems[0];
                product = (Product)item.Tag;

                product.ProductName = _txtName.Text;
                product.Price       = Convert.ToDecimal(_txtPrice.Text);
                product.Description = _txtDescription.Text;
                product.Organic     = checkIfOrganic();

                bool edited = db.updateProduct(product.Id, product.ProductName, product.Organic, product.Price, product.Description);

                if (!edited)
                {
                    MessageBox.Show("Product could not be updated. Please try again!", "Product update error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //Clear the listview
                _lvProducts.Items.Clear();

                //Update the listview with the new data
                ListProducts();

                _lvProducts.Items[0].Selected = true;
            }
            else if (product == proNew)
            {
                if (String.IsNullOrWhiteSpace(_txtName.Text) ||
                    String.IsNullOrWhiteSpace(_txtPrice.Text) ||
                    String.IsNullOrWhiteSpace(_txtDescription.Text))
                {
                    MessageBox.Show("Could not add the product! Some information is missing. " +
                                    "Please make sure to fill all the required fields.", "Product no added.",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    Product newProduct = new Product();

                    newProduct.ProductName = _txtName.Text;

                    decimal d;
                    if (decimal.TryParse(_txtPrice.Text, out d))
                    {
                        newProduct.Price = d;
                    }
                    else
                    {
                        MessageBox.Show("The product price is not valid.", "Price not valid", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    newProduct.Description = _txtDescription.Text;

                    newProduct.Organic = checkIfOrganic();

                    //check if item is already in the list, if not add it and print in the listview
                    if (products.Any(item => item.ProductName == newProduct.ProductName))
                    {
                        MessageBox.Show("The product you are trying to add already exists.", "Product exists",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        bool added = db.AddProduct(newProduct.ProductName, newProduct.Organic, newProduct.Price, newProduct.Description);
                        if (added)
                        {
                            products.Add(newProduct);
                        }
                        else
                        {
                            MessageBox.Show("The product was not added. Please try again!", "Product Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        _lvProducts.Items.Clear();
                        ListProducts();
                    }
                }
            }

            _lvProducts.Items[0].Selected = true;
            ControlUtil.DisableButtons(_btnSave);
            ControlUtil.EnableButtons(_btnEdit, _btnDelete, _btnNew);
            ControlUtil.DisableTextBoxes(_txtName, _txtPrice, _txtDescription);
            _cbOrganic.Enabled = false;
        }