private void dgvCurrentOrders_SelectionChanged(object sender, EventArgs e) { m_orderID = Convert.ToInt64("0" + dgvCurrentOrders.CurrentRow.Cells[0].Value); m_onlineOrderID = Convert.ToInt64("0" + dgvCurrentOrders.CurrentRow.Cells[2].Value); lsvCurrent.Items.Clear(); lsvRemovable.Items.Clear(); if (m_onlineOrderID < 1) { COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(m_orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; m_slOrderedItems = new SortedList(); for (int itemIndex = 0; itemIndex < tempOrderDetailsList.Count; itemIndex++) { Int64 tempProductID = tempOrderDetailsList[itemIndex].ProductID; int tempCategoryLevel = tempOrderDetailsList[itemIndex].CategoryLevel; string tempProductName = ""; if (tempCategoryLevel == 3) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID); if (tempDataRowArr.Length > 0) //Added by Baruri .This was a bug previously when no row found. { tempProductName = tempDataRowArr[0]["cat3_name"].ToString(); } } else if (tempCategoryLevel == 4) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID); int tempCat3_id = 0; if (tempDataRowArr.Length > 0) { tempCat3_id = Convert.ToInt32("0" + tempDataRowArr[0]["cat3_id"]); } tempProductName = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0]["cat4_name"].ToString(); tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id); if (tempDataRowArr.Length > 0)//If rows found { tempProductName += " " + tempDataRowArr[0]["cat3_name"].ToString(); } } else if (tempCategoryLevel == 0) { tempProductName = tempOrderDetailsList[itemIndex].OrderRemarks; } //if remarks exists append it... otherwise append nothing... string appendString = ""; if (tempCategoryLevel != 0) { appendString = (tempOrderDetailsList[itemIndex].OrderRemarks.Equals("")) ? ("") : (" (" + tempOrderDetailsList[itemIndex].OrderRemarks + ")"); } if (tempOrderDetailsList[itemIndex].PrintedQuantity > 0) { ListViewItem lsvItem = new ListViewItem(tempProductName + appendString); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].PrintedQuantity.ToString()); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].OrderAmount.ToString("F02")); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].ProductID.ToString()); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].OrderDetailsID.ToString()); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].OrderFoodType.ToString()); lsvCurrent.Items.Add(lsvItem); //For taking the track of the ordered items. COrderDetails objOrderedItems=new COrderDetails(); objOrderedItems.OrderDetailsID=tempOrderDetailsList[itemIndex].OrderDetailsID; objOrderedItems.OrderID=m_orderID; objOrderedItems.ProductID=tempOrderDetailsList[itemIndex].ProductID; objOrderedItems.OrderQuantity=tempOrderDetailsList[itemIndex].OrderQuantity; objOrderedItems.PrintedQuantity=tempOrderDetailsList[itemIndex].PrintedQuantity; objOrderedItems.OrderAmount = tempOrderDetailsList[itemIndex].OrderAmount; m_slOrderedItems.Add(objOrderedItems.OrderDetailsID, objOrderedItems); } } } else { //Loading the online orders information m_slOrderedItems = new SortedList(); COrderManager tempOrderManager = new COrderManager(); string remarks = ""; string itemName = ""; List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.GetOnlineOrderDetailsByOrderID(m_orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; for (int itemIndex = 0; itemIndex < tempOrderDetailsList.Count; itemIndex++) { remarks = tempOrderDetailsList[itemIndex].OrderRemarks.ToString(); itemName = tempOrderDetailsList[itemIndex].ItemName.ToString(); if (remarks.Length > 0) { itemName = itemName + "(" + remarks + ")"; } if (tempOrderDetailsList[itemIndex].PrintedQuantity > 0) { ListViewItem lsvItem = new ListViewItem(itemName); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].PrintedQuantity.ToString()); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].OrderAmount.ToString("F02")); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].ProductID.ToString()); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].OnlineItemSequenceNumber.ToString()); lsvItem.SubItems.Add(tempOrderDetailsList[itemIndex].OrderFoodType.ToString()); lsvCurrent.Items.Add(lsvItem); //For taking the track of the ordered items. COrderDetails objOrderedItems = new COrderDetails(); objOrderedItems.OrderDetailsID = tempOrderDetailsList[itemIndex].OnlineItemSequenceNumber; //Here details id contains online ordered item sequence number objOrderedItems.OrderID = m_orderID; objOrderedItems.ProductID = tempOrderDetailsList[itemIndex].ProductID; objOrderedItems.OrderQuantity = tempOrderDetailsList[itemIndex].OrderQuantity; objOrderedItems.PrintedQuantity = tempOrderDetailsList[itemIndex].PrintedQuantity; objOrderedItems.OrderAmount = tempOrderDetailsList[itemIndex].OrderAmount; m_slOrderedItems.Add(objOrderedItems.OrderDetailsID, objOrderedItems); } } } }
private bool CheckStockControl() { CCategory3DAO cCategory3Dao = new CCategory3DAO(); COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; string stockMessage = "Stock is unavailable "; bool isStockAvailable = true; foreach (COrderDetails orderDetail in tempOrderDetailsList) { CCategory3 cCategory3 = cCategory3Dao.GetAllCategory3ByCategory3ID(Convert.ToInt32(orderDetail.ProductID)); if ((orderDetail.OrderQuantity - orderDetail.KitchenQuantity) > cCategory3.MUnitsInStock && cCategory3.MNonStockable) { //stockMessage += "\n " + orderDetail.Product_Name + " " + (orderDetail.OrderQuantity - cCategory3.MUnitsInStock); stockMessage += "\n " + cCategory3.Category3Name + ": Needed: " + (orderDetail.OrderQuantity - orderDetail.KitchenQuantity) + " But Have " + (cCategory3.MUnitsInStock); isStockAvailable = false; } } if (!isStockAvailable) { CUserInfoDAO aUserInfoDao = new CUserInfoDAO(); CUserInfo aUserInfo = new CUserInfo(); aUserInfo = aUserInfoDao.GetUserInfoByUsername(RMSGlobal.LoginUserName); if (aUserInfo.Type == 0) { DialogResult dialogResult = MessageBox.Show("Do You Proceed", "Stock Alert", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { isStockAvailable = true; } else if (dialogResult == DialogResult.No) { } } } if (!isStockAvailable || !CheckRawProduct(tempOrderDetailsList)) { CMessageBox cMessageBox = new CMessageBox("Finished Product", stockMessage); cMessageBox.ShowDialog(); //MessageBox.Show(stockMessage); return false; } else { foreach (COrderDetails orderDetails in tempOrderDetailsList) { CCategory3 cCategory3 = cCategory3Dao.GetAllCategory3ByCategory3ID(Convert.ToInt32(orderDetails.ProductID)); if (!cCategory3.MNonStockable) { cCategory3Dao.UpdateStock(Convert.ToInt32(orderDetails.ProductID), orderDetails.OrderQuantity - orderDetails.KitchenQuantity); COrderDetailsDAO cOrderDetailsDao = new COrderDetailsDAO(); cOrderDetailsDao.UpdateKitchenQuantity(orderDetails); } } } // parrentForm.scre return true; }
/// <summary> /// This function loads the items details information. /// </summary> private void LoadOrderDetails() { g_FoodDataGridView.Rows.Clear(); g_BeverageDataGridView.Rows.Clear(); FillRMSDataGridView(); g_FoodDataGridView.ClearSelection(); g_BeverageDataGridView.ClearSelection(); if (m_orderUserName.Replace(" ", "").ToUpper() != "Web User".Replace(" ", "").ToUpper()) { COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; for (int itemIndex = 0; itemIndex < tempOrderDetailsList.Count; itemIndex++) { Int64 tempProductID = tempOrderDetailsList[itemIndex].ProductID; int tempCategoryLevel = tempOrderDetailsList[itemIndex].CategoryLevel; string tempProductName = ""; if (tempCategoryLevel == 3) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID); if (tempDataRowArr.Length > 0) //Added by Baruri .This was a bug previously when no row found. { tempProductName = tempDataRowArr[0]["cat3_name"].ToString(); } } else if (tempCategoryLevel == 4) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID); int tempCat3_id = 0; if (tempDataRowArr.Length > 0) { tempCat3_id = Convert.ToInt32("0" + tempDataRowArr[0]["cat3_id"]); } tempProductName = Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0]["cat4_name"].ToString(); tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id); if (tempDataRowArr.Length > 0)//If rows found { tempProductName += " " + tempDataRowArr[0]["cat3_name"].ToString(); } } else if (tempCategoryLevel == 0) { tempProductName = tempOrderDetailsList[itemIndex].OrderRemarks; } int tempFoodType = 1; if (tempCategoryLevel == 3) { tempFoodType = int.Parse(Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID)[0].GetParentRow(Program.initDataSet.Relations["category2_to_category3"])["cat2_type"].ToString()); } else if (tempCategoryLevel == 4) { int tempCat3_id = int.Parse(Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0].GetParentRow(Program.initDataSet.Relations["category3_to_category4"])["cat3_id"].ToString()); tempFoodType = int.Parse(Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id)[0].GetParentRow(Program.initDataSet.Relations["category2_to_category3"])["cat2_type"].ToString()); } else { tempFoodType = -1; } DataGridView tempDataGridView = new DataGridView(); if (tempFoodType == 1)//Food Type { tempDataGridView = g_FoodDataGridView; } else if (tempFoodType == 0)//Nonfood Type { tempDataGridView = g_BeverageDataGridView; } else if (tempFoodType == -1) { if (tempOrderDetailsList[itemIndex].OrderFoodType == "Food") { tempDataGridView = g_FoodDataGridView; } else { tempDataGridView = g_BeverageDataGridView; } } //if remarks exists append it... otherwise append nothing... bool sele = false; string appendString = ""; if (tempCategoryLevel != 0) appendString = (tempOrderDetailsList[itemIndex].OrderRemarks.Equals("")) ? ("") : (" (" + tempOrderDetailsList[itemIndex].OrderRemarks + ")"); string[] tempDataGridViewRow = { tempProductName+appendString, tempOrderDetailsList[itemIndex].OrderQuantity.ToString(), ((double)tempOrderDetailsList[itemIndex].VatTotal).ToString("F02"), ((double)tempOrderDetailsList[itemIndex].OrderAmount).ToString("F02"), tempOrderDetailsList[itemIndex].ProductID.ToString(), tempOrderDetailsList[itemIndex].CategoryLevel.ToString(), (Int64.MaxValue-1)+"",//max rank tempOrderDetailsList[itemIndex].OrderDetailsID.ToString(), tempOrderDetailsList[itemIndex].PrintedQuantity.ToString(), tempOrderDetailsList[itemIndex].UnitPrice.ToString("F2"), }; //not misc item... rank is specified if (tempCategoryLevel != 0) { try { tempDataGridViewRow[6] = Program.initDataSet.Tables["Category" + tempCategoryLevel].Select("cat" + tempCategoryLevel + "_id = " + tempProductID)[0]["cat" + tempCategoryLevel + "_rank"].ToString(); } catch { } } try { tempDataGridView.Rows.Add(tempDataGridViewRow); } catch (Exception ex) { // MessageBox.Show(ex.ToString()); } ConvertRank(); if (tempDataGridView.Columns["Order_details_id"] !=null) tempDataGridView.Sort(tempDataGridView.Columns["Order_details_id"], ListSortDirection.Descending); if (tempDataGridView.Columns["dataGridViewTextBoxColumn5"] != null) tempDataGridView.Sort(tempDataGridView.Columns["dataGridViewTextBoxColumn5"], ListSortDirection.Descending); //this.FillCategory1OrderNumber();//New //tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); } //get discount COrderDiscount tempOrderDiscount = new COrderDiscount(); oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDiscount = (COrderDiscount)oResult.Data; m_dDiscountAmount = Convert.ToDecimal(tempOrderDiscount.Discount.ToString("F02")); } } else { //Loading the online orders information //g_FoodDataGridView.RowCount = 0; COrderManager tempOrderManager = new COrderManager(); string remarks = ""; string itemName = ""; List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.GetOnlineOrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; for (int counter = 0; counter < tempOrderDetailsList.Count; counter++) { remarks = tempOrderDetailsList[counter].OrderRemarks.ToString(); itemName = tempOrderDetailsList[counter].ItemName.ToString(); if (remarks.Length > 0) { itemName = itemName + "(" + remarks + ")"; } string[] tempDataGridViewRow = { itemName, tempOrderDetailsList[counter].OrderQuantity.ToString(), tempOrderDetailsList[counter].OrderAmount.ToString("F02"), tempOrderDetailsList[counter].CategoryID.ToString(), tempOrderDetailsList[counter].CategoryLevel.ToString(), tempOrderDetailsList[counter].Rank.ToString(), tempOrderDetailsList[counter].OrderDetailsID.ToString(), tempOrderDetailsList[counter].PrintedQuantity.ToString(), tempOrderDetailsList[counter].UnitPrice.ToString("F2"), }; if (tempOrderDetailsList[counter].OrderFoodType.Replace(" ", "").ToUpper() == "Food".Replace(" ", "").ToUpper()) { g_FoodDataGridView.Rows.Add(tempDataGridViewRow); g_FoodDataGridView.Sort(g_FoodDataGridView.Columns[5], ListSortDirection.Ascending); } else { g_BeverageDataGridView.Rows.Add(tempDataGridViewRow); //If drinks g_BeverageDataGridView.Sort(g_BeverageDataGridView.Columns[5], ListSortDirection.Ascending); } } //get discount COrderDiscount tempOrderDiscount = new COrderDiscount(); oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDiscount = (COrderDiscount)oResult.Data; m_dDiscountAmount = Convert.ToDecimal(tempOrderDiscount.Discount.ToString("F02")); } } this.TotalAmountCalculation(); g_FoodDataGridView.ClearSelection(); g_BeverageDataGridView.ClearSelection(); try { this.SetPrintedItemBackColor(); //set the back color } catch { } }
private void FillNonFoods() { g_FoodDataGridView.RowCount = 0; COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDetailsList = (List<COrderDetails>)oResult.Data; } for (int detailsCounter = 0; detailsCounter < tempOrderDetailsList.Count; detailsCounter++) { Int64 tempProductID = tempOrderDetailsList[detailsCounter].ProductID; int tempCategoryLevel = tempOrderDetailsList[detailsCounter].CategoryLevel; string tempProductName = ""; if (tempCategoryLevel == 3) { DataRow[] tempDataRowArr = Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempProductID); tempProductName = tempDataRowArr[0]["cat3_name"].ToString(); } else if (tempCategoryLevel == 4) { //Latest name is at first int tempCat3_id = int.Parse(Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0].GetParentRow(Program.initDataSet.Relations["category3_to_category4"])["cat3_id"].ToString()); tempProductName += Program.initDataSet.Tables["Category4"].Select("cat4_id = " + tempProductID)[0]["cat4_name"].ToString(); tempProductName += " " + Program.initDataSet.Tables["Category3"].Select("cat3_id = " + tempCat3_id)[0]["cat3_name"].ToString(); } else if (tempCategoryLevel == 0) tempProductName = tempOrderDetailsList[detailsCounter].OrderRemarks; int tempFoodType = 0; DataGridView tempDataGridView = new DataGridView(); tempDataGridView = g_FoodDataGridView; string[] tempDataGridViewRow = { tempProductName, tempOrderDetailsList[detailsCounter].OrderQuantity.ToString(), ((double)tempOrderDetailsList[detailsCounter].OrderAmount).ToString("F02"), tempOrderDetailsList[detailsCounter].ProductID.ToString(), tempOrderDetailsList[detailsCounter].CategoryLevel.ToString(), (Int64.MaxValue-1)+"",//max rank tempOrderDetailsList[detailsCounter].OrderDetailsID.ToString() }; //not misc item... rank is specified if (tempCategoryLevel != 0) tempDataGridViewRow[5] = Program.initDataSet.Tables["Category" + tempCategoryLevel].Select("cat" + tempCategoryLevel + "_id = " + tempProductID)[0]["cat" + tempCategoryLevel + "_rank"].ToString(); tempDataGridView.Rows.Add(tempDataGridViewRow); ConvertRank(); tempDataGridView.Sort(tempDataGridView.Columns[5], ListSortDirection.Ascending); tempDataGridView.Update(); g_FoodDataGridView.ClearSelection(); } //get discount COrderDiscount tempOrderDiscount = new COrderDiscount(); oResult = tempOrderManager.OrderDiscountGetByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) { tempOrderDiscount = (COrderDiscount)oResult.Data; m_dDiscountAmount = tempOrderDiscount.Discount; } if (category2ButtonList.Count > CATEGORY2PANEL_CAPACITY) g_NextButton.Enabled = true; else g_NextButton.Enabled = false; g_PreviousButton.Enabled = false; TotalAmountCalculation(); LoadStatusBar(); }