Exemple #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                var info = Purshase.GetPurshase(txtIdPurshase.Text);
                txtIdCustomer.Text    = info.id_customer;
                txtName.Text          = info.customer_name;
                txtDate.Text          = info.date;
                txtCurrentAmount.Text = info.products.First().total_amount.ToString();

                foreach (var product in info.products)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dgvProducts);

                    row.Cells[0].Value = product.id_product;
                    row.Cells[1].Value = product.product_name;
                    row.Cells[2].Value = product.product_mark;
                    row.Cells[3].Value = product.product_price;
                    row.Cells[4].Value = product.quantity_desired;
                    row.Cells[5].Value = product.amount;

                    dgvProducts.Rows.Add(row);
                }
                txtFindProduct.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemple #2
0
        private void UpdateQuantityEventHandler(object sender, object sender2)
        {
            try
            {
                string id_product = dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[0].Value.ToString();
                int    quantity   = int.Parse(dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[4].Value.ToString());
                //MessageBox.Show(string.Format("Order: '{0}, Product: '{1}', Quantity: '{2}', Condition: '{3}'", txtIdPurshase.Text, id_product, sender.ToString(), sender2.ToString()));
                int    count     = int.Parse(sender.ToString());
                string condition = sender2.ToString();
                if (count > 0)
                {
                    Purshase.ReturnProduct(txtIdPurshase.Text, id_product, count, condition);
                    MessageBox.Show("Return success", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                PurshaseInfo info = Purshase.GetPurshase(txtIdPurshase.Text);
                if (info.products != null)
                {
                    dgvProducts.Rows.Clear();
                    txtCurrentAmount.Text = info.products.First().total_amount.ToString();
                    foreach (var product in info.products)
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dgvProducts);

                        row.Cells[0].Value = product.id_product;
                        row.Cells[1].Value = product.product_name;
                        row.Cells[2].Value = product.product_mark;
                        row.Cells[3].Value = product.product_price;
                        row.Cells[4].Value = product.quantity_desired;
                        row.Cells[5].Value = product.amount;

                        dgvProducts.Rows.Add(row);
                    }
                }
                else
                {
                    MessageBox.Show("The order has been cancel.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    var dialog = MessageBox.Show("Do you want to process a new order?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (dialog == DialogResult.OK)
                    {
                        Initialize();
                    }
                    else
                    {
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }