public CSplitByItemForm(Int64 inOrderID, Double inTotalAmount, Double inDiscount, String inTableType, DataTable inItemList,Double servicecharge, Double vat) { InitializeComponent(); m_iOrderID = inOrderID; m_sTableType = inTableType; m_dtItemList = inItemList; m_dTotalAmount = inTotalAmount; m_dDiscount = inDiscount; m_dservicecharge = servicecharge; m_dvat = vat; ordertotal = (inTotalAmount+inDiscount-vat); m_dtSecondList = new DataTable(); m_dtSecondList.Columns.Add("Item"); m_dtSecondList.Columns.Add("Qty"); m_dtSecondList.Columns.Add("Price"); //m_dtThirdList = new DataTable(); //m_dtThirdList.Columns.Add("Price"); try { for (int rowIndex = 0; rowIndex < m_dtItemList.Rows.Count; rowIndex++) { SpiltItem aSpiltItem=new SpiltItem(); String ListBoxItem = ""; // String Mybox = ""; aSpiltItem.ItemName = m_dtItemList.Rows[rowIndex]["Item"].ToString(); aSpiltItem.Price = Convert.ToDouble(m_dtItemList.Rows[rowIndex]["Price"]); aSpiltItem.Qty = Convert.ToInt32(m_dtItemList.Rows[rowIndex]["Qty"]); FirstSpiltItems.Add(aSpiltItem); ListBoxItem = m_dtItemList.Rows[rowIndex]["Qty"].ToString() + "-"; ListBoxItem += m_dtItemList.Rows[rowIndex]["Item"].ToString(); ListBoxItem += "-"; ListBoxItem += m_dtItemList.Rows[rowIndex]["Price"].ToString(); g_PrintBill1ListBox.Items.Add(ListBoxItem); // g_PrintBill1ListBox.DataSource= //Mybox += m_dtItemList.Rows[rowIndex]["Price"].ToString(); //g_PrintBill1ListBox.Items.Add(Mybox); } // g_PrintBill1ListBox.DataSource = FirstSpiltItems; } catch (Exception exp) { throw exp; } }
private void FillSecondList(DataRow tempDataRow) { try { string itemname = tempDataRow[0].ToString(); SpiltItem aSpiltItem = (from item in FirstSpiltItems where item.ItemName == itemname select item).Single(); int qty = aSpiltItem.Qty; int flag = 0; double itemprice = aSpiltItem.Price; foreach (SpiltItem item in SecondSpiltItems) { if(item.ItemName==itemname) { flag = 1; item.Price += (itemprice/qty); item.Qty += 1; } } if(flag==0) { SpiltItem aItem=new SpiltItem(); aItem.ItemName = itemname; aItem.Qty = 1; aItem.Price = (itemprice/qty); SecondSpiltItems.Add(aItem); DataRow temp2DataRow = m_dtSecondList.NewRow(); temp2DataRow[0] = tempDataRow[0]; temp2DataRow[1] = (Convert.ToInt32(tempDataRow[1])).ToString(); temp2DataRow[2] = tempDataRow[2]; m_dtSecondList.Rows.Add(temp2DataRow); } if(qty-1==0) { SpiltItem aItem = new SpiltItem(); aItem.ItemName = itemname; aItem.Qty = qty; aItem.Price = itemprice; List<SpiltItem> tempSpiltItems = new List<SpiltItem>(); foreach (SpiltItem firstSpiltItem in FirstSpiltItems) { if(firstSpiltItem.ItemName!=itemname) { tempSpiltItems.Add(firstSpiltItem); } } FirstSpiltItems = tempSpiltItems; m_dtItemList.Rows.Remove(tempDataRow); } else if(qty-1>0) { foreach (SpiltItem spiltItem in FirstSpiltItems) { if(spiltItem.ItemName==itemname) { spiltItem.Qty -= 1; spiltItem.Price -= (itemprice/qty); } } } } catch (Exception) { } FillFirstBox(FirstSpiltItems); FillSecondBox(SecondSpiltItems); }