Example #1
0
        /// <summary>
        /// adding item to order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonOrderItemsInOrderTab_Click(object sender, EventArgs e)
        {
            if (textBoxOrderNumberInOrderTab.Text == "" || !(comboBoxOrderItemsInAddOrderTab.SelectedIndex > -1))
            {
                MessageBox.Show("please enter value by double click on the order \n Or choosing product");
            }
            else
            {
                using (testDBEntities db = new testDBEntities())
                {
                    t_Items item = db.t_Items.Where(x => x.ItemDescription.Equals(comboBoxOrderItemsInAddOrderTab.Text)).FirstOrDefault();
                    model_OrdersItem.t_Items = item;
                    t_Orders order = db.t_Orders.Where(x => x.ID == model_t_Orders.ID).FirstOrDefault();

                    long order_id = order.ID;

                    model_OrdersItem.t_Orders = order;
                    db.OrdersItems.Add(model_OrdersItem);
                    db.SaveChanges();

                    evalTotalAmount(order_id);
                    ClearDataGridView_t_Orders();
                    populateDataGridView_t_Orders();
                    MessageBox.Show("Added Successfully");
                }
            }
        }
Example #2
0
        /// <summary>
        /// evaluting total amount in order after add/del item
        /// </summary>
        /// <param name="order_id"></param>
        private void evalTotalAmount(long order_id)
        {
            using (testDBEntities db = new testDBEntities())
            {
                //MessageBox.Show(m_order_item.t_Orders.ID.ToString());
                List <OrdersItem> all_OrdersItems = db.OrdersItems.Where(x => x.t_Orders.ID == order_id).ToList <OrdersItem>();

                decimal total = 0;
                foreach (OrdersItem order_item in all_OrdersItems)
                {
                    total += (decimal)order_item.t_Items.ItemPrice;
                }

                t_Orders order = db.t_Orders.Where(x => x.ID == order_id).FirstOrDefault();
                order.TotalAmount = total;

                db.Entry(order).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Example #3
0
        /// <summary>
        /// insert data to textbox's by clicking on row of datagridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridViewOrders_DoubleClick(object sender, EventArgs e)
        {
            if (dataGridViewOrders.CurrentRow.Index != -1)
            {
                model_t_Orders.ID = Convert.ToInt32(dataGridViewOrders.CurrentRow.Cells["_ID"].Value);
                using (testDBEntities db = new testDBEntities())
                {
                    model_t_Orders = db.t_Orders.Where(x => x.ID == model_t_Orders.ID).FirstOrDefault();

                    textBoxRefaundAmount.Text     = model_t_Orders.RefaundAmount.ToString();
                    textBoxOrders_CustName.Text   = model_t_Orders.CustomerName;
                    textBoxOrdersCust_Adress.Text = model_t_Orders.CustomerAddress;
                    textBoxCustomerPhone.Text     = model_t_Orders.CustomerPhone;
                    textBoxOrdersToatl.Text       = model_t_Orders.TotalAmount.ToString();

                    dateTimePickerOrders.Text         = model_t_Orders.OrderDate.ToString();
                    textBoxOrdersCustomerCity.Text    = model_t_Orders.CustomerCity;
                    textBoxOrderNumberInOrderTab.Text = model_t_Orders.OrderNumber;
                }
            }
        }