decimal CalcStockList(int month) { List <CStockItem> list = new List <CStockItem>(); foreach (CStockItem item in m_StockList) { list.Add(new CStockItem(item.IngredientID)); } var voucher = new MyVoucherTable(); int count = 0, checkedCount = 0; foreach (var vr in m_DataSet.Voucher) { if (vr.IsStockTimeNull()) { continue; } if (month != 0) { if (vr.StockTime.Month != month) { continue; } } if (vr.StockTime.Year != MyFunction.IntHeaderYear) { continue; } if (!vr.IsRemovedNull()) { if (vr.Removed) { continue; } } var row = voucher.NewVoucherRow(); row.ItemArray = vr.ItemArray; voucher.AddVoucherRow(row); count++; if (vr.Locked) { checkedCount++; } decimal checkSum = 0; foreach (var dr in vr.GetVoucherDetailRows()) { if (dr.IsIngredientIDNull()) { continue; } decimal co = 0, vo = 0; if (!dr.IsCostNull()) { co = dr.Cost; } checkSum += co; int ingredientID = dr.IngredientID; foreach (CStockItem p in list) { if (p.IngredientID == ingredientID) { p.TotalCost += co; p.OrderCount++; if (!dr.IsVolumeNull()) { vo = dr.Volume; } p.Volume += vo; if (p.Volume != 0) { p.UnitCost = p.TotalCost / p.Volume; } break; } } } decimal vrCost = 0; if (!vr.IsCostNull()) { vrCost = vr.Cost; } if (checkSum != vrCost) { MessageBox.Show("警告!<序号" + vr.ID.ToString() + ">號細項和" + checkSum.ToString("f1") + "和總和" + vrCost.ToString("f1") + "不符!"); } } m_StockList = list; decimal sum = 0; foreach (CStockItem p in list) { sum += p.TotalCost; } return(sum); }
// id= int.MaxValue 統計全部供貨商 void Calculate(int monthFrom, int dayFrom, int monthTo, int dayTo, int id, string name) { if (id <= 0) { return; // 沒有選擇供貨商 } SortableBindingList <CIngredient> list = new SortableBindingList <CIngredient>(); var voucher = new MyVoucherTable(); int count = 0, checkedCount = 0; foreach (var vr in m_DataSet.Voucher) { if (vr.IsStockTimeNull()) { continue; } if (vr.StockTime.Year != MyFunction.IntHeaderYear) { continue; } if (id != int.MaxValue) { if (vr.IsVendorIDNull()) { continue; } if (vr.VendorID != id) { continue; } } int month = vr.StockTime.Month; if (month < monthFrom) { continue; } else if (month == monthFrom) { if (vr.StockTime.Day < dayFrom) { continue; } } if (month > monthTo) { continue; } else if (month == monthTo) { if (vr.StockTime.Day > dayTo) { continue; } } if (!vr.IsRemovedNull()) { if (vr.Removed) { continue; } } var row = voucher.NewVoucherRow(); row.ItemArray = vr.ItemArray; voucher.AddVoucherRow(row); count++; if (vr.Locked) { checkedCount++; } decimal checkSum = 0; foreach (var dr in vr.GetVoucherDetailRows()) { if (dr.IsIngredientIDNull()) { continue; } decimal co = 0, vo = 0; if (!dr.IsCostNull()) { co = dr.Cost; } if (!dr.IsVolumeNull()) { vo = dr.Volume; } checkSum += co; Add2List(list, dr.IngredientID, co, vo); } decimal vrCost = 0; if (!vr.IsCostNull()) { vrCost = vr.Cost; } if (checkSum != vrCost) { MessageBox.Show("警告!<序号" + vr.ID.ToString() + ">號細項和" + checkSum.ToString("f1") + "和總和" + vrCost.ToString("f1") + "不符!"); } } decimal sum = 0; foreach (CIngredient p in list) { sum += p.TotalCost; } textBox1.Text = sum.ToString("N1"); labelCount.Text = "己核可 " + checkedCount.ToString() + "單(共" + count.ToString() + "單)"; this.dataGridView1.DataSource = list; this.voucherDGView.DataSource = voucher; if (list.Count == 0) { MessageBox.Show(monthFrom.ToString() + "至" + monthTo.ToString() + "月份 供貨商<" + name + ">無進貨!"); } }