Beispiel #1
0
        private bool FinishOrder()
        {
            var ord = HelperOrder.GetOrder(HelperOrder.GetOrderList().Count);

            if (ord != null)
            {
                ord.orderStatus = "Tamamlanmış";
                var result = HelperOrder.CUD(ord, EntityState.Modified);
                if (result)
                {
                    openOrder = false;
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Beispiel #2
0
        private void BtAddToBasket_Click(object sender, EventArgs e)
        {
            int empID = Convert.ToInt32(cBoxEmployee.SelectedValue);
            int proID = Convert.ToInt32(cBoxProduct.SelectedValue);
            var pro   = HelperProduct.GetProduct(proID);

            if (pro != null)
            {
                if (!Helper.isNumber(tbQuantity.Text) || Convert.ToInt32(tbQuantity.Text) <= 0)
                {
                    btAddToBasket.Enabled = false;
                    MessageBox.Show("Hatalı giriş yaptınız!");
                }

                else if (pro.quantity < Convert.ToInt32(tbQuantity.Text))
                {
                    if (pro.quantity == 0)
                    {
                        MessageBox.Show("Bu ürün tükenmiştir!");
                    }
                    else
                    {
                        MessageBox.Show($"Bu üründen stokta {pro.quantity} adet kaldı!");
                    }
                }

                else
                {
                    if (!openOrder)
                    {
                        Orders ord = new Orders {
                            orderDate   = DateTime.Now.Date,
                            orderStatus = "Açık",
                            amount      = 0,
                            customerID  = cusID
                        };

                        var result1 = HelperOrder.CUD(ord, EntityState.Added);
                        if (result1)
                        {
                            openOrder = true;
                            OrderDetails ordDet = new OrderDetails {
                                productID       = proID,
                                priceEach       = HelperProduct.GetProduct(proID).proPrice,
                                quantityOrdered = Convert.ToInt32(tbQuantity.Text),
                                orderID         = ord.orderID,
                                employeeID      = empID
                            };

                            var result2 = HelperOrderDet.CUD(ordDet, EntityState.Added);
                            if (result2)
                            {
                                btFinishOrder.Enabled = true;
                                MessageBox.Show("Ürün sepete eklendi!");
                                ord.amount += ordDet.priceEach * ordDet.quantityOrdered;
                                HelperOrder.CUD(ord, EntityState.Modified);
                            }
                            else
                            {
                                MessageBox.Show("HATA!");
                            }
                        }
                    }

                    else
                    {
                        OrderDetails ordDet = new OrderDetails {
                            productID       = proID,
                            priceEach       = pro.proPrice,
                            quantityOrdered = Convert.ToInt32(tbQuantity.Text),
                            orderID         = HelperOrder.GetOrderList().Count,
                            employeeID      = empID
                        };

                        var ord    = HelperOrder.GetOrder(Convert.ToInt32(ordDet.orderID));
                        var result = HelperOrderDet.CUD(ordDet, EntityState.Added);
                        if (result)
                        {
                            btFinishOrder.Enabled = true;
                            MessageBox.Show("Ürün sepete eklendi!");
                            ord.amount += ordDet.priceEach * ordDet.quantityOrdered;
                            HelperOrder.CUD(ord, EntityState.Modified);
                        }
                        else
                        {
                            MessageBox.Show("HATA!");
                        }
                    }

                    pro.quantity -= Convert.ToInt32(tbQuantity.Text);
                    HelperProduct.CUD(pro, EntityState.Modified);
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            //Satışı tamamla butonu
            //toplam tutar hesapla
            int totalPrice = 0;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                totalPrice += Convert.ToInt32(dataGridView1.Rows[i].Cells[5].Value);
            }
            label1.Text = totalPrice.ToString();

            Cashier cashier = HelperCashier.GetByName(label3.Text);

            customer = HelperCustomer.GetByID(customer.CustomerID);
            Order or = new Order()
            {
                customerID = customer.CustomerID,
                orderDate  = DateTime.Now,
                cashierID  = cashier.cashierID,
                totalPrice = Convert.ToInt32(label1.Text),
            };
            var ekle = HelperOrder.CUD(or, System.Data.Entity.EntityState.Added);

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                p.Add(HelperProduct.GetByID(Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value)));
            }
            int k = 0;

            foreach (var item in p)
            {
                for (; k < dataGridView1.Rows.Count;)
                {
                    item.stock -= Convert.ToInt32(dataGridView1.Rows[k].Cells[4].Value);
                    var a = HelperProduct.CUD(item, System.Data.Entity.EntityState.Modified);
                    break;
                }
                k++;
            }

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                //fiş için yapılanlar
                List <string> temp       = new List <string>();
                string        ad         = dataGridView1.Rows[i].Cells[0].Value.ToString();
                string        id         = dataGridView1.Rows[i].Cells[1].Value.ToString();
                string        birimFiyat = dataGridView1.Rows[i].Cells[2].Value.ToString();
                string        indirim    = dataGridView1.Rows[i].Cells[3].Value.ToString();
                string        adet       = dataGridView1.Rows[i].Cells[4].Value.ToString();
                string        tutar      = dataGridView1.Rows[i].Cells[5].Value.ToString();
                temp.Add(ad);
                temp.Add(id);
                temp.Add(birimFiyat);
                temp.Add(indirim);
                temp.Add(adet);
                temp.Add(tutar);
                receipt.Add(temp);
            }
            foreach (var item in p)
            {
                ord = new OrderDetail();

                ord.orderID   = or.orderID;
                ord.productID = item.productID;
                ord.unitPrice = item.unitPrice;
                for (; j < dataGridView1.Rows.Count; j++)
                {
                    ord.count = Convert.ToInt32(dataGridView1.Rows[j].Cells[4].Value);
                    break;
                }
                j++;

                var ekle2 = HelperOrderDetail.CUD(ord, System.Data.Entity.EntityState.Added);
            }

            ReceiptForm rpf = new ReceiptForm(receipt, customer, label1.Text);

            rpf.Show();
            this.Hide();
        }