/// <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 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); } } } }
/// <summary> /// Collecting the online orders and prints automatically /// </summary> private void PrintOnlineOrders() { Int64 onlineOrderId = 0; for (int orderIndex = 0; orderIndex < m_onlineOrders.Length; orderIndex++) { onlineOrderId = Convert.ToInt64("0" + m_onlineOrders[orderIndex]); COrderManager tempOrderManager = new COrderManager(); CResult objResult = new CResult(); objResult= tempOrderManager.GetOnlineOrderPrintStatus(onlineOrderId); COrderInfo tempOrderInfo = new COrderInfo(); tempOrderInfo = (COrderInfo)objResult.Data; int printStatus = tempOrderInfo.OnlineOrderPrintStatus; if (printStatus < 2) //If not printed then print the online orders { List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.GetOnlineOrderDetailsByOrderID(onlineOrderId);//Collecting the orders details if (oResult.IsSuccess && oResult.Data != null) { tempOrderDetailsList = (List<COrderDetails>)oResult.Data; } if (tempOrderDetailsList.Count > 0) { this.GetPrintedCopy(onlineOrderId, tempOrderDetailsList); } } tempOrderManager.ChangeOnlineOrderPrintStatus(onlineOrderId); } }