Example #1
0
        private void g_RemoveButton_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_iDataGridViewCurrentRowIndex == -1)
                {
                    CMessageBox tempMessageBox = new CMessageBox("Error!", "Please select ordered food or beverage.");
                    tempMessageBox.ShowDialog();
                    return;
                }
                if (m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[0].Value.ToString().Equals(""))
                {
                    return;
                }

                int totalQuantity = Convert.ToInt32(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[1].Value.ToString());
               // int printedQuantity = Convert.ToInt32(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value.ToString());
                int printedQuantity = Convert.ToInt32(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[8].Value.ToString());

                //If printed items are equal to total quantity or greater
                if (totalQuantity <= printedQuantity)
                {
                    CMessageBox tempMessageBox = new CMessageBox("Printed", "Current item(s) has already been sent to kitchen.");
                    tempMessageBox.ShowDialog();
                    return;
                }

                COrderManager tempOrderManager1 = new COrderManager();
                CResult oResult1 = tempOrderManager1.OrderDetailsByOrderDetailID(Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value.ToString()));
                COrderDetails aDetails = new COrderDetails();
                if (oResult1.IsSuccess && oResult1.Data != null)
                {
                    aDetails = (COrderDetails)oResult1.Data;
                }
                if (aDetails.GuestPrintQuantity >= totalQuantity)
                {
                    CMessageBox tempMessageBox = new CMessageBox("Printed", " All ready Guest Bill Printed so that impossible of item decrease");
                    tempMessageBox.ShowDialog();
                    return;
                }

                if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".ToUpper().Replace(" ", "")) //If the order is not online order
                {

                    COrderManager tempOrderManager = new COrderManager();
                    //int qty = Int32.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[1].Value.ToString());
                    ////Double amount = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value.ToString());

                    ////For Vat and Unit vat
                    //Double itemTotalVat = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value.ToString());
                    //Double unitVat = itemTotalVat / qty;
                    //itemTotalVat = itemTotalVat - unitVat;
                    //Double amount = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[3].Value.ToString());
                    //Double unitPrice = amount / qty;

                    int qty = Int32.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[1].Value.ToString());
                    //Double amount = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value.ToString());

                    //For Vat and Unit vat
                    Double itemTotalVat = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value.ToString());
                    Double unitVat = itemTotalVat / qty;
                    // itemTotalVat = itemTotalVat - unitVat;
                    Double amount = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[3].Value.ToString());
                    Double unitPrice = amount / qty;

                    if (qty == 1)
                    {
                        tempOrderManager.DeleteOrderDetails(Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value.ToString()));
                        m_dDataGridView.Rows.RemoveAt(m_iDataGridViewCurrentRowIndex);
                    }
                    else
                    {
                        qty = qty - 1;
                        if (qty < 1)
                        {
                            qty = 0;
                        }

                        COrderDetails tempOrderDetails = new COrderDetails();
                    //    CResult oResult = tempOrderManager.OrderDetailsByOrderDetailID(Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[6].Value.ToString()));
                        CResult oResult = tempOrderManager.OrderDetailsByOrderDetailID(Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value.ToString()));

                        if (oResult.IsSuccess && oResult.Data != null)
                        {
                            tempOrderDetails = (COrderDetails)oResult.Data;
                        }
                        //tempOrderDetails.OrderQuantity = qty;
                        //tempOrderDetails.OrderAmount = qty * unitPrice;
                        //tempOrderDetails.PrintedQuantity = tempOrderDetails.PrintedQuantity - 1;

                        //Add by deb
                        tempOrderDetails.OrderQuantity = qty;
                        tempOrderDetails.OrderAmount = qty * unitPrice;
                        tempOrderDetails.VatTotal = unitVat * qty;

                        if (tempOrderDetails.PrintedQuantity <= 0)
                        {
                            tempOrderDetails.PrintedQuantity = 0;
                        }
                        //tempOrderDetails.OrderDetailsID = Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[6].Value.ToString());
                        tempOrderDetails.Amount_with_vat = tempOrderDetails.OrderAmount + tempOrderDetails.VatTotal;
                        tempOrderManager.UpdateOrderDetails(tempOrderDetails);
                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[1].Value = qty;

                        //m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value = tempOrderDetails.PrintedQuantity;
                       // m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value = ((double)(qty * unitPrice)).ToString("F02");
                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[8].Value = tempOrderDetails.PrintedQuantity;
                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[3].Value = ((double)(qty * unitPrice)).ToString("F02");
                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value = ((double)(unitVat * qty)).ToString("F02");

                    }
                }
                else //Proceed for online order
                {
                    if (this.TotalItems() < 2)
                    {
                        MessageBox.Show("You can not remove all the items from online", RMSGlobal.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    COrderManager tempOrderManager = new COrderManager();
                    int qty = Int32.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[1].Value.ToString());
                    Double amount = Double.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value.ToString());
                    Double unitPrice = amount / qty;
                    if (qty == 1)
                    {
                        tempOrderManager.DeleteOnlineOrderDetails(Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[5].Value.ToString())); //Taking the order sequence number.Here named category ranking
                        m_dDataGridView.Rows.RemoveAt(m_iDataGridViewCurrentRowIndex);
                    }
                    else
                    {
                        qty = qty - 1;
                        if (qty < 1)
                        {
                            qty = 0;
                        }

                        COrderDetails tempOrderDetails = new COrderDetails();

                        tempOrderDetails.OrderQuantity = qty;
                        tempOrderDetails.OrderAmount = qty * unitPrice;
                        tempOrderDetails.OnlineItemSequenceNumber = Convert.ToInt64("0" + m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[5].Value);

                        tempOrderDetails.OrderDetailsID = Int64.Parse(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[6].Value.ToString());
                        tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails);
                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[1].Value = qty;

                        ///For printed items
                        int printedItems = Convert.ToInt32(m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value) - 1;
                        if (printedItems < 1)
                        {
                            printedItems = 0;
                        }
                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[7].Value = printedItems;

                        m_dDataGridView.Rows[m_iDataGridViewCurrentRowIndex].Cells[2].Value = ((double)(qty * unitPrice)).ToString("F02");
                    }
                }
                m_dDataGridView.Update();
                TotalAmountCalculation();
                m_dDataGridView.ClearSelection();
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, RMSGlobal.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.SetPrintedItemBackColor(); //set the back color
        }