Esempio n. 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);
            }
        }
Esempio n. 2
0
        public override void Save()
        {
            try
            {
                var dialog = MessageBox.Show("Do you really want to process the order?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dialog == DialogResult.OK)
                {
                    Purshase.ProcessSaleOrder(this.id_purshase);
                    _cusotmer            = new CustomerModel();
                    this.id_purshase     = "SHP" + Security.Security.generateIdNumber();
                    txtCustomerName.Text = "";
                    txtCode.Text         = "";
                    dgvProducts.Rows.Clear();
                }
                MessageBox.Show("Order Processed!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                dialog = MessageBox.Show("Do you want to process a new order?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dialog == DialogResult.OK)
                {
                    InitializeSale();
                }
                else
                {
                    this.Close();
                }
            }
            catch (Exception)
            {
                //The sale could not be completed

                MessageBox.Show("The sale could not be completed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
Esempio n. 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                var id_customer = _cusotmer.id;
                var id_product  = txtCode.Text;
                var quantity    = int.Parse(txtQuantity.Text);
                if (quantity > 0 && quantity <= in_stock)
                {
                    Purshase.AddProduct(id_purshase, id_customer, id_product, quantity);
                }
                else
                {
                    MessageBox.Show("The amount must not be 0 or greater than " + in_stock.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                var listProduct = Purshase.GetProductSelected(id_purshase, id_product, id_customer);

                bool exists = false;
                for (int i = 0; i < dgvProducts.Rows.Count; i++)
                {
                    var row = dgvProducts.Rows[i];
                    if (row.Cells[0].Value.ToString() == listProduct.id_product)
                    {
                        row.Cells[4].Value = listProduct.quantity_desired.ToString();
                        row.Cells[5].Value = listProduct.amount.ToString();
                        exists             = true;
                        break;
                    }
                }
                if (!exists)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    row.CreateCells(dgvProducts);
                    row.Cells[0].Value = listProduct.id_product;
                    row.Cells[1].Value = listProduct.product_name;
                    row.Cells[2].Value = listProduct.product_mark;
                    row.Cells[3].Value = listProduct.product_price.ToString();
                    row.Cells[4].Value = listProduct.quantity_desired.ToString();
                    row.Cells[5].Value = listProduct.amount.ToString();
                    dgvProducts.Rows.Add(row);
                }


                txtCurrentAmount.Text = listProduct.total_amount.ToString();
                txtCode.Text          = "";
                txtNameProduct.Text   = "";
                txtMark.Text          = "";
                txtPrice.Text         = "";
                txtQuantity.Text      = "0";
                count           = 0;
                btnFind.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            var dialog = MessageBox.Show("Do you really want to cancel this order and begin a new one?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dialog == DialogResult.OK)
            {
                Purshase.CancelSaleOrder(this.id_purshase);
                InitializeSale();
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (dgvProducts.Rows[dgvProducts.CurrentRow.Index].Selected)
     {
         //Develop this action
         var id_item = dgvProducts.Rows[dgvProducts.CurrentRow.Index].Cells[0].Value.ToString();
         Purshase.RemoveProduct(this.id_purshase, id_item);
         dgvProducts.Rows.RemoveAt(dgvProducts.CurrentRow.Index);
     }
     else
     {
         MessageBox.Show("You must select the product to remove.", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Esempio n. 7
0
 public override void Cancel()
 {
     try
     {
         var dialog = MessageBox.Show("Do you really want to cancel the order?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
         if (dialog == DialogResult.OK)
         {
             Purshase.CancelSaleOrder(this.id_purshase);
             MessageBox.Show("Order Cancelled!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             this.Close();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("There was a problem cancelling de order", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 8
0
        public IHttpActionResult BuyBook(int id)
        {
            var book = context.Books.Find(id);

            if (book == null)
            {
                return(this.BadRequest("Book doesn't exist."));
            }

            if (book.Copies < 1)
            {
                return(this.BadRequest("Book is out of stock."));
            }

            string userId   = this.User.Identity.GetUserId();
            var    purshase = new Purshase()
            {
                Price          = book.Price,
                DateOfPurshase = DateTime.Now,
                isRecalled     = false,
                UserId         = userId,
                BookId         = book.Id
            };

            book.Copies--;
            context.Purshases.Add(purshase);
            context.SaveChanges();

            var viewPurshase = new PurshaseViewModel
            {
                Price          = purshase.Price,
                DateOfPurshase = purshase.DateOfPurshase,
                isRecalled     = purshase.isRecalled,
                User           = this.User.Identity.GetUserName(),
                Book           = purshase.Book.Title
            };

            return(this.Ok(viewPurshase));
        }
Esempio n. 9
0
 public override void Save()
 {
     if (ckbCancelOrder.Checked)
     {
         try
         {
             Purshase.CancelSaleOrder(txtIdPurshase.Text);
             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);
         }
     }
     else
     {
         string        id_product    = dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[0].Value.ToString();
         string        name          = dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[1].Value.ToString();
         string        mark          = dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[2].Value.ToString();
         double        price         = double.Parse(dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[3].Value.ToString());
         int           quantity      = int.Parse(dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[4].Value.ToString());
         double        amount        = double.Parse(dgvProducts.Rows[dgvProducts.SelectedCells[0].RowIndex].Cells[5].Value.ToString());
         double        total_amount  = double.Parse(txtCurrentAmount.Text);
         var           product       = new Purshase_Product(id_product, name, mark, price, quantity, amount, total_amount);
         ReturnDetails returnDetails = new ReturnDetails(txtIdPurshase.Text, product);
         returnDetails.updateQuantity = new ReturnDetails.UpdateQuantity(UpdateQuantityEventHandler);
         returnDetails.ShowDialog();
     }
 }
Esempio n. 10
0
        public override void Save()
        {
            if (dgvProducts.Rows.Count != 0)
            {
                var dialog = MessageBox.Show("Do you really want to process the order?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dialog == DialogResult.OK)
                {
                    try
                    {
                        Purshase.ProcessSaleOrder(this.id_purshase);
                        Billing bill = new Billing(this.id_purshase);
                        bill.ShowDialog();
                    }
                    catch (Exception ex)
                    {
                        //The sale could not be completed

                        MessageBox.Show("Error: " + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
                dialog = MessageBox.Show("Do you want to process a new order?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dialog == DialogResult.OK)
                {
                    InitializeSale();
                }
                else
                {
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("We can't process this purshase without products.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 11
0
        public IHttpActionResult BuyBook(int id)
        {
            var book = context.Books.Find(id);

            if (book == null)
            {
                return this.BadRequest("Book doesn't exist.");
            }

            if (book.Copies < 1)
            {
                return this.BadRequest("Book is out of stock.");
            }

            string userId = this.User.Identity.GetUserId();
            var purshase = new Purshase()
            {
                Price = book.Price,
                DateOfPurshase = DateTime.Now,
                isRecalled = false,
                UserId = userId,
                BookId = book.Id
            };

            book.Copies--;
            context.Purshases.Add(purshase);
            context.SaveChanges();

            var viewPurshase = new PurshaseViewModel
            {
                Price = purshase.Price,
                DateOfPurshase = purshase.DateOfPurshase,
                isRecalled = purshase.isRecalled,
                User = this.User.Identity.GetUserName(),
                Book = purshase.Book.Title
            };

            return this.Ok(viewPurshase);
        }