//private void btnPLU_Click(object sender, EventArgs e) //{ // int priceTakeType; // Int32 productPLU = 0; // int returnVal = 0; // Int32 productQuantity = 0; // COrderManager objOrderManager = new COrderManager(); // if (m_iType == m_cCommonConstants.TableType) // { // priceTakeType = 1; // } // else if (m_iType == m_cCommonConstants.TakeAwayType) // { // priceTakeType = 2; // } // else // { // priceTakeType = 3; // } // CCalculatorForm tableNumberForm = new CCalculatorForm("Product PLU Information", "PLU of the Product"); // tableNumberForm.ShowDialog(); // if (CCalculatorForm.inputResult.Equals("Cancel")) // return; // if (CCalculatorForm.inputResult.Equals("") || Int32.Parse(CCalculatorForm.inputResult) == 0) // { // CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); // tempMessageBox.ShowDialog(); // return; // } // productPLU = Convert.ToInt32("0" + CCalculatorForm.inputResult); // CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU); // if (Convert.ToString(objProductName.Data) == "NO") // { // CMessageBox tempMessageBox = new CMessageBox("Error", "Invalid PLU.Please enter valid PLU"); // tempMessageBox.ShowDialog(); // return; // } // ProductQuantityForm quantityForm = new ProductQuantityForm(Convert.ToString(objProductName.Data)); // quantityForm.ShowDialog(); // if (ProductQuantityForm.m_productQuantity.Equals("Cancel")) // { // return; // } // if (ProductQuantityForm.m_productQuantity.Equals("") || Int32.Parse(ProductQuantityForm.m_productQuantity) == 0) // { // CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); // tempMessageBox.ShowDialog(); // return; // } // productQuantity = Convert.ToInt32("0" + ProductQuantityForm.m_productQuantity); // CResult oResult = objOrderManager.GetPluDataByProductPLU(productPLU, priceTakeType, orderID, productQuantity); // if (oResult.IsSuccess && oResult.Data != null) // { // returnVal = int.Parse(oResult.Data.ToString()); // //for vat includr option // String queryStr = SqlQueries.GetQuery(Query.LastPLUOrderDetails); // CDalConfig oTempDal = ConfigManager.GetConfig<CDalConfig>(); // String tempConnStr = oTempDal.ConnectionString; // // Create a new data adapter based on the specified query. // SqlDataAdapter dataAdapter = new SqlDataAdapter(queryStr, tempConnStr); // // Populate a new data table and bind it to the BindingSource. // DataTable table = new DataTable(); // //table.Locale = System.Globalization.CultureInfo.InvariantCulture; // dataAdapter.Fill(table); // int CategoryID = Convert.ToInt32(table.Rows[0]["product_id"].ToString()); // Double amount = Convert.ToDouble(table.Rows[0]["amount"].ToString()); // int catLavel=Convert.ToInt32(table.Rows[0]["cat_level"].ToString()); // //vat in cat Three // double vatRate = 0; // bool vat_included = false; // double vatAmountRate = 0; // if(catLavel==3) // { // DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + CategoryID.ToString()); // vatRate = 0; // vat_included = false; // vatAmountRate = 0; // try // { // vatRate = Convert.ToDouble(temp2DataRowArray[0]["vat_Rate"].ToString()); // vat_included = Convert.ToBoolean(temp2DataRowArray[0]["vat_included"].ToString()); // if (vat_included) // { // vatAmountRate = (amount * vatRate) / 100; // // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString(); // // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString(); // } // else // { // vatAmountRate = 0.00; // } // } // catch (Exception ex) { } // } // if(catLavel==4) // { // DataRow[] temp3DataRowArray = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + CategoryID); // vatRate = 0; // vat_included = false; // vatAmountRate = 0; // try // { // vatRate = Convert.ToDouble(temp3DataRowArray[0]["vat_Rate"].ToString()); // vat_included = Convert.ToBoolean(temp3DataRowArray[0]["vat_included"].ToString()); // if (vat_included) // { // vatAmountRate = (amount * vatRate) / 100; // // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString(); // // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString(); // } // else // { // vatAmountRate = 0.00; // } // } // catch (Exception ex) { } // } // //string tableTypePrice = string.Empty; // //if (m_iType == m_cCommonConstants.TableType) // //{ // // tableTypePrice = temp2DataRowArray[0]["table_price"].ToString(); // //} // //else if (m_iType == m_cCommonConstants.TakeAwayType) // //{ // // tableTypePrice = temp2DataRowArray[0]["tw_price"].ToString(); // //} // COrderManager tempOrderManager = new COrderManager(); // COrderDetails tempOrderDetails = new COrderDetails(); // if (returnVal == 1) // { // //update Order_details table // //int tempRowIndex = tempResult; // //int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty; // //tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty; // //tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02"); // tempOrderDetails.OrderDetailsID = Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString()); // tempOrderDetails.OrderID =Convert.ToInt32(table.Rows[0]["order_id"].ToString()); // tempOrderDetails.ProductID =Convert.ToInt32( table.Rows[0]["product_id"].ToString()); // tempOrderDetails.CategoryLevel = Convert.ToInt32(table.Rows[0]["cat_level"].ToString()); // tempOrderDetails.UnitPrice = 0.00; // tempOrderDetails.OrderQuantity = Convert.ToInt32(table.Rows[0]["quantity"].ToString()); // tempOrderDetails.OrderAmount = Convert.ToDouble(table.Rows[0]["amount"].ToString()); // tempOrderDetails.OrderFoodType = table.Rows[0]["food_type"].ToString(); // // tempOrderDetails.OnlineItemSequenceNumber = Convert.ToInt64("0" + tempDataGridView.Rows[tempRowIndex].Cells[5].Value.ToString()); // // tempOrderDetails.PrintedQuantity = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[7].Value.ToString()); // if (vat_included) // { // tempOrderDetails.VatTotal = vatAmountRate; // } // else // { // tempOrderDetails.VatTotal = 0.00; // } // //if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) // //{ // // tempOrderManager.UpdateOrderDetails(tempOrderDetails); // //} // //else // //{ // // tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails); // //} // try // { // tempOrderManager.UpdateOrderDetails(tempOrderDetails); // } // catch { } // } // //tempOrderDetails.VatTotal = vatAmountRate; // //tempOrderDetails.OrderDetailsID =Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString()); // //try // //{ // //tempOrderManager.UpdateOrderDetails(tempOrderDetails); // //} // //catch { } // } // if (returnVal == 0) // { // MessageBox.Show("Please enter valid plu product", RMSGlobal.MessageBoxTitle, // MessageBoxButtons.OK, MessageBoxIcon.Information); // } // else // { // COrderDetailsDAO orderDetailsDao = new COrderDetailsDAO(); // orderDetailsDao.UpdateOrderDetailsPricebyPLUProductTablePrice(productPLU, orderID, priceTakeType); // } // this.LoadOrderDetails(); // btnPLU_Click(sender, e); //} private void btnPLU_Click(object sender, EventArgs e) { int priceTakeType; Int32 productPLU = 0; int returnVal = 0; Int32 productQuantity = 0; COrderManager objOrderManager = new COrderManager(); if (m_iType == m_cCommonConstants.TableType) { priceTakeType = 1; } else if (m_iType == m_cCommonConstants.TakeAwayType) { priceTakeType = 2; } else { priceTakeType = 3; } CCalculatorForm tableNumberForm = new CCalculatorForm("Product PLU Information", "PLU of the Product"); tableNumberForm.ShowDialog(); if (CCalculatorForm.inputResult.Equals("Cancel")) return; if (CCalculatorForm.inputResult.Equals("") || Int32.Parse(CCalculatorForm.inputResult) == 0) { CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); tempMessageBox.ShowDialog(); return; } productPLU = Convert.ToInt32("0" + CCalculatorForm.inputResult); // Add for find updating order_detail int id = productPLU; long order = orderID; COrderDetailsDAO aDao = new COrderDetailsDAO(); List<COrderDetails> aList = aDao.OrderDetailsGetAll(); // CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU, priceTakeType); CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU); var check = (from orderdetail in aList where (orderdetail.OrderID == orderID && orderdetail.ProductID == objProductName.Productid) select orderdetail); if (Convert.ToString(objProductName.Data) == "NO") { CMessageBox tempMessageBox = new CMessageBox("Error", "Invalid PLU.Please enter valid PLU"); tempMessageBox.ShowDialog(); return; } ProductQuantityForm quantityForm = new ProductQuantityForm(Convert.ToString(objProductName.Data)); quantityForm.ShowDialog(); if (ProductQuantityForm.m_productQuantity.Equals("Cancel")) { return; } if (ProductQuantityForm.m_productQuantity.Equals("") || Int32.Parse(ProductQuantityForm.m_productQuantity) == 0) { CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); tempMessageBox.ShowDialog(); return; } productQuantity = Convert.ToInt32("0" + ProductQuantityForm.m_productQuantity); // Add for updating order_detail when orderwith same product if (check.Count() == 1) { COrderDetails aOrderDetails = new COrderDetails(); aOrderDetails = check.Single(); //double vat = aOrderDetails.Amount_with_vat - aOrderDetails.OrderAmount; //vat = (vat * 100) / aOrderDetails.OrderAmount; productQuantity += aOrderDetails.OrderQuantity; aOrderDetails.OrderQuantity = productQuantity; aOrderDetails.OrderAmount = aOrderDetails.UnitPrice * productQuantity; aOrderDetails.PrintedQuantity = aOrderDetails.PrintedQuantity; aOrderDetails.VatTotal = (objProductName.VateRate * aOrderDetails.OrderAmount) / 100.0; aOrderDetails.Amount_with_vat = aOrderDetails.OrderAmount + aOrderDetails.VatTotal; COrderDetailsDAO aCOrderDetailsDao = new COrderDetailsDAO(); aCOrderDetailsDao.OrderDetailsUpdate(aOrderDetails); //COrderDetailsDAO orderDetailsDao = new COrderDetailsDAO(); //orderDetailsDao.UpdateOrderDetailsPricebyPLUProductTablePrice(productPLU, orderID, priceTakeType); } if (check.Count() == 0) { CResult oResult = objOrderManager.GetPluDataByProductPLU(productPLU, priceTakeType, orderID, productQuantity); if (oResult.IsSuccess && oResult.Data != null) { returnVal = int.Parse(oResult.Data.ToString()); //for vat includr option String queryStr = SqlQueries.GetQuery(Query.LastPLUOrderDetails); CDalConfig oTempDal = ConfigManager.GetConfig<CDalConfig>(); String tempConnStr = oTempDal.ConnectionString; // Create a new data adapter based on the specified query. SqlDataAdapter dataAdapter = new SqlDataAdapter(queryStr, tempConnStr); // Populate a new data table and bind it to the BindingSource. DataTable table = new DataTable(); //table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); int CategoryID = Convert.ToInt32(table.Rows[0]["product_id"].ToString()); Double amount = Convert.ToDouble(table.Rows[0]["amount"].ToString()); int catLavel = Convert.ToInt32(table.Rows[0]["cat_level"].ToString()); //vat in cat Three double vatRate = 0; bool vat_included = false; double vatAmountRate = 0; if (catLavel == 3) { DataRow[] temp2DataRowArray = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + CategoryID.ToString()); vatRate = 0; vat_included = false; vatAmountRate = 0; try { vatRate = Convert.ToDouble(temp2DataRowArray[0]["vat_Rate"].ToString()); vat_included = Convert.ToBoolean(temp2DataRowArray[0]["vat_included"].ToString()); if (vat_included) { vatAmountRate = (amount * vatRate) / 100; // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString(); // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString(); } else { vatAmountRate = 0.00; } } catch (Exception ex) { } } if (catLavel == 4) { DataRow[] temp3DataRowArray = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + CategoryID); vatRate = 0; vat_included = false; vatAmountRate = 0; try { vatRate = Convert.ToDouble(temp3DataRowArray[0]["vat_Rate"].ToString()); vat_included = Convert.ToBoolean(temp3DataRowArray[0]["vat_included"].ToString()); if (vat_included) { vatAmountRate = (amount * vatRate) / 100; // tableTypePrice = (Double.Parse(tableTypePrice) - vatAmountRate).ToString(); // tableTypePrice = Convert.ToDouble(tableTypePrice).ToString(); } else { vatAmountRate = 0.00; } } catch (Exception ex) { } } //string tableTypePrice = string.Empty; //if (m_iType == m_cCommonConstants.TableType) //{ // tableTypePrice = temp2DataRowArray[0]["table_price"].ToString(); //} //else if (m_iType == m_cCommonConstants.TakeAwayType) //{ // tableTypePrice = temp2DataRowArray[0]["tw_price"].ToString(); //} COrderManager tempOrderManager = new COrderManager(); COrderDetails tempOrderDetails = new COrderDetails(); if (returnVal == 1) { //update Order_details table //int tempRowIndex = tempResult; //int qty = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[1].Value.ToString()) + m_iSavedOrderedQty; //tempDataGridView.Rows[tempRowIndex].Cells[1].Value = qty; //tempDataGridView.Rows[tempRowIndex].Cells[2].Value = ((double)(Double.Parse(tableTypePrice) * qty)).ToString("F02"); tempOrderDetails.OrderDetailsID = Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString()); tempOrderDetails.OrderID = Convert.ToInt32(table.Rows[0]["order_id"].ToString()); tempOrderDetails.ProductID = Convert.ToInt32(table.Rows[0]["product_id"].ToString()); tempOrderDetails.CategoryLevel = Convert.ToInt32(table.Rows[0]["cat_level"].ToString()); tempOrderDetails.UnitPrice = 0.00; tempOrderDetails.OrderQuantity = Convert.ToInt32(table.Rows[0]["quantity"].ToString()); tempOrderDetails.OrderAmount = Convert.ToDouble(table.Rows[0]["amount"].ToString()); tempOrderDetails.OrderFoodType = table.Rows[0]["food_type"].ToString(); // tempOrderDetails.OnlineItemSequenceNumber = Convert.ToInt64("0" + tempDataGridView.Rows[tempRowIndex].Cells[5].Value.ToString()); // tempOrderDetails.PrintedQuantity = int.Parse(tempDataGridView.Rows[tempRowIndex].Cells[7].Value.ToString()); if (vat_included) { tempOrderDetails.VatTotal = vatAmountRate; } else { tempOrderDetails.VatTotal = 0.00; } //if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) //{ // tempOrderManager.UpdateOrderDetails(tempOrderDetails); //} //else //{ // tempOrderManager.UpdateOnlineOrderDetails(tempOrderDetails); //} try { tempOrderDetails.Amount_with_vat = tempOrderDetails.OrderAmount + tempOrderDetails.VatTotal; tempOrderManager.UpdateOrderDetails(tempOrderDetails); } catch { } } //tempOrderDetails.VatTotal = vatAmountRate; //tempOrderDetails.OrderDetailsID =Convert.ToInt32(table.Rows[0]["order_detail_id"].ToString()); //try //{ //tempOrderManager.UpdateOrderDetails(tempOrderDetails); //} //catch { } } if (returnVal == 0) { MessageBox.Show("Please enter valid plu product", RMSGlobal.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { COrderDetailsDAO orderDetailsDao = new COrderDetailsDAO(); orderDetailsDao.UpdateOrderDetailsPricebyPLUProductTablePrice(productPLU, orderID, priceTakeType); } } this.LoadOrderDetails(); btnPLU_Click(sender, e); }
private void btnPLU_Click(object sender, EventArgs e) { COrderManager objOrderManager = new COrderManager(); this.NewOrder(); //////Start //PLUPopup objPLUPopup = new PLUPopup(); int priceTakeType; Int32 productPLU = 0; int returnVal = 0; Int32 productQuantity = 0; priceTakeType = -99; //objPLUPopup.ShowDialog(this); //if (PLUPopup.m_productCode == "Cancel") //{ // return; //} //productPLU = Convert.ToInt32("0" + PLUPopup.m_productCode); CCalculatorForm tableNumberForm = new CCalculatorForm("Product PLU Information", "PLU of the Product"); tableNumberForm.ShowDialog(); if (CCalculatorForm.inputResult.Equals("Cancel")) return; if (CCalculatorForm.inputResult.Equals("") || Int32.Parse(CCalculatorForm.inputResult) == 0) { CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); tempMessageBox.ShowDialog(); return; } productPLU = Convert.ToInt32("0" + CCalculatorForm.inputResult); CResult objProductName = objOrderManager.GetProductByProductPLU(productPLU); if (Convert.ToString(objProductName.Data) == "NO") { CMessageBox tempMessageBox = new CMessageBox("Error", "Invalid PLU.Please enter valid PLU"); tempMessageBox.ShowDialog(); return; } ProductQuantityForm quantityForm = new ProductQuantityForm(Convert.ToString(objProductName.Data)); quantityForm.ShowDialog(); if (ProductQuantityForm.m_productQuantity.Equals("Cancel")) { return; } if (ProductQuantityForm.m_productQuantity.Equals("") || Int32.Parse(ProductQuantityForm.m_productQuantity) == 0) { CMessageBox tempMessageBox = new CMessageBox("Error", "Input invalid!"); tempMessageBox.ShowDialog(); return; } productQuantity = Convert.ToInt32("0" + ProductQuantityForm.m_productQuantity); CResult oResult = objOrderManager.GetPluDataByProductPLU(productPLU, priceTakeType, orderID, productQuantity); if (oResult.IsSuccess && oResult.Data != null) { returnVal = int.Parse(oResult.Data.ToString()); } if (returnVal == 0) { MessageBox.Show("Please enter valid plu product", RMSGlobal.MessageBoxTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } ///End new this.FillNonFoods(); btnPLU_Click(sender, e); }