private void btnCalc_Click(object sender, EventArgs e) { if (fromPicker.Value > toPicker.Value) { MessageBox.Show("啟始日期不能大於結束日期!"); return; } DateTime from = fromPicker.Value; DateTime to = toPicker.Value; Dictionary <int, CalcScrape> dic = new Dictionary <int, CalcScrape>(); if (checkBox1.Checked) { DoCalcScrape(from, to, 1, ref dic); } if (checkBox2.Checked) { DoCalcScrape(from, to, 2, ref dic); } if (checkBox3.Checked) { DoCalcScrape(from, to, 3, ref dic); } SortableBindingList <CalcScrape> list = new SortableBindingList <CalcScrape>(); decimal volume = 0, cost = 0, soldValue = 0; foreach (var v in dic.Values) { if (v.Volume > 0) { volume += v.Volume; cost += v.Cost; soldValue += v.SoldValue; list.Add(v); } } txBoxVolume.Text = volume.ToString("N1"); txBoxSoldValue.Text = soldValue.ToString("N1"); txBoxCost.Text = cost.ToString("N2"); dgvCalc.DataSource = list; }
private void comboBoxAccTitle_SelectedIndexChanged(object sender, EventArgs e) { ComboBox box = sender as ComboBox; if (box.SelectedValue == null) { return; } m_SelectedTitleCode = box.SelectedValue.ToString(); if (DontRefresh) { return; } if (m_SelectedMonth < 0 || m_SelectedMonth > 12) { labelMessage.Text = "請選擇月份!!!"; return; } SortableBindingList <CLedgerRow> lendgerTable = CalcLedger(m_SelectedMonth, m_SelectedTitleCode); dgvCLedgerTable.DataSource = lendgerTable; dgvCLedgerTable.Focus(); }
SortableBindingList <CLedgerRow> CalcLedger(int mon, string selectedTitleCode) { SortableBindingList <CLedgerRow> LedgerTable = new SortableBindingList <CLedgerRow>(); var accTitle = damaiDataSet.AccountingTitle.FindByTitleCode(selectedTitleCode); if (accTitle == null) { return(LedgerTable); } bool isVirtual = accTitle.IsIsVirtualNull()?false : accTitle.IsVirtual; bool isDebt = accTitle.IsIsDebtNull() ?false : accTitle.IsDebt; Decimal DebtSum = 0, CreditSum = 0; List <DamaiDataSet.AccVouchRow> accList = new List <DamaiDataSet.AccVouchRow>(); bool wholeYear = (mon <= 0 || mon > 12); if (wholeYear) { var nullList = from acc in damaiDataSet.AccVouch where acc.IsAccVoucherTimeNull() select acc; foreach (var r in nullList) { accList.Add(r); } } var nonNullList = from acc in damaiDataSet.AccVouch where !acc.IsAccVoucherTimeNull() orderby acc.AccVoucherTime select acc; foreach (var r in nonNullList) { accList.Add(r); } foreach (var acc in accList) { bool isCurrent = true; if (acc.IsAccVoucherTimeNull()) { if (!wholeYear) { continue; } } else { if (acc.AccVoucherTime.Year != MyFunction.IntHeaderYear) { continue; } if (!wholeYear) { if (acc.AccVoucherTime.Month != mon) { isCurrent = false; } if (acc.AccVoucherTime.Month > mon) { continue; } } } if (isVirtual && !isCurrent) { continue; // 虛科目非當期 不用累加 } var details = acc.GetAccVouchDetailRows(); if (details == null || details.Count() == 0) { continue; } foreach (var d in details) { string titleCode = d.TitleCode; int i = titleCode.IndexOf('.'); if (i >= 0) { titleCode = titleCode.Substring(0, i); } if (titleCode != selectedTitleCode) { continue; } DebtSum += d.Debt; CreditSum += d.Credit; if (!isCurrent) { continue; } CLedgerRow row = new CLedgerRow(); if (!acc.IsAccVoucherTimeNull()) { row.Date = acc.AccVoucherTime; } row.Debt = d.Debt; row.Credit = d.Credit; if (isDebt) { row.Sum = DebtSum - CreditSum; } else { row.Sum = CreditSum - DebtSum; } row.Note = d.Note.TrimEnd(); // row.sum最後再一起算 //string titleName = ""; //if (othersideTitle != null) //{ // if (char.IsDigit(othersideTitle[0])) // { // int tmp; // AccTitle t = NewList.FindTitleByCode(othersideTitle, out tmp); // if (t != null) titleName = t.Name; // } // else // titleName = othersideTitle; //} //row.OthersideAccTitle = titleName; LedgerTable.Add(row); } } return(LedgerTable); }
private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { const int LinePerPage = 26; m_Graphics = e.Graphics; PageSettings settings = e.PageSettings; Rectangle inner = e.MarginBounds; Rectangle outter = e.PageBounds; SortableBindingList <CMonthlyPay> list = this.dgViewMonthlyPay.DataSource as SortableBindingList <CMonthlyPay>; if (list == null || PageIndex <= 0) { e.HasMorePages = false; return; } int start = (PageIndex - 1) * LinePerPage; int end = start + LinePerPage; DataGridView view = this.dgViewMonthlyPay; if (end > view.Rows.Count) { end = view.Rows.Count; e.HasMorePages = false; } else { e.HasMorePages = true; } m_Font = new Font("細明體", 18.0f); m_Brush = SystemBrushes.WindowText; m_Pen = SystemPens.WindowText; int x = inner.Left; int y = inner.Top; string str = " " + MyFunction.IntHeaderYear.ToString() + "年" + comboBoxMonth.Text + "廠商貨款總表"; DataGridViewColumnCollection columns = view.Columns; m_Graphics.DrawString(str, m_Font, m_Brush, new PointF(x, y)); int height = inner.Height / LinePerPage; y += 2 * height; int top = y - 4; m_Graphics.DrawLine(m_Pen, x, top, inner.Right, top); for (int j = 0; j < columns.Count; j++) { DataGridViewColumn col = columns[j]; str = col.HeaderText; PrintColumn(str, x, y, col); x += view.Columns[j].Width; } int middle = x + 4; int realPayWidth = (inner.Right - middle) / 2; PrintColumn("實付", x, y, realPayWidth); x += realPayWidth; PrintColumn("簽收", x, y, realPayWidth); for (int i = start; i < end; i++) { DataGridViewRow row = view.Rows[i]; y += height; x = inner.Left; m_Graphics.DrawLine(m_Pen, x, y - 4, inner.Right, y - 4); for (int j = 0; j < columns.Count; j++) { DataGridViewCell cell = row.Cells[j]; str = cell.FormattedValue.ToString(); PrintColumn(str, x, y, columns[j]); x += columns[j].Width; } } int bottom = (y + height) - 4; int l = inner.Left, r = inner.Right; m_Graphics.DrawLine(m_Pen, l, bottom, r, bottom); m_Graphics.DrawLine(m_Pen, l, top, l, bottom); m_Graphics.DrawLine(m_Pen, r, top, r, bottom); m_Graphics.DrawLine(m_Pen, middle, top, middle, bottom); middle += realPayWidth; m_Graphics.DrawLine(m_Pen, middle, top, middle, bottom); if (m_PrintTotal && e.HasMorePages == false) // 這是最後一頁 { m_PrintTotal = false; x = inner.Left + columns[0].Width; y += (2 * height); PrintColumn("小計", x, y, columns[1]); x += columns[1].Width; PrintColumn(textBoxTotal.Text, x, y, columns[2]); } }
private void btnOrderList_Click(object sender, EventArgs e) { int mon = cbBoxMonth.SelectedIndex + 1; int day = cbBoxDay.SelectedIndex + 1; if (mon < 1 || mon > 12 || day < 1 || day > 31) { MessageBox.Show("所選日期有誤!"); return; } LoadData(mon, day); TabControl tc = tabControl1; // worry about IsPrintTimeNull() var groups = from row in m_OrderSet.Order orderby row.PrintTime group row by row.PrintTime.Hour; if (groups.Count() == 0) { MessageBox.Show(mon.ToString() + "月" + day.ToString() + "日沒有資料!"); return; } tc.TabPages.Clear(); tc.TabPages.Add(m_TabPageStatics); var listXX = new List <MyOrderRow>(); SortableBindingList <HourStatics> listStatics = new SortableBindingList <HourStatics>(); labelDgvTitle.Text = mon.ToString() + "月" + day.ToString() + "日統計表"; TabPage page = null; decimal total = 0; int count = 0; // 一直加Tab,加行時 Height會改變, 所以先在前面算好餘裕 int WidthX = (m_TabPageStatics.Width - MyLayout.OffsetX) / MyLayout.NoX; int HeightY = (m_TabPageStatics.Height - MyLayout.OffsetY - 60) / MyLayout.NoY; foreach (var gr in groups) { SuspendLayout(); if (gr.Key > 6 && gr.Key < 23) { string tabName = gr.Key.ToString("d2"); page = null; HourStatics st = new HourStatics(gr.Key); listStatics.Add(st); int x = 0, y = 0; foreach (var order in gr) { if (page == null) { page = AddTabControl1Item(tabName); } CreateLabel(page, x, y, order, WidthX, HeightY); if (!order.Deleted) { total += order.Income; st.Revenue += order.Income; if (!order.IsIncomeNull() && order.Income >= 0) // 退貨的不加入單數 { count++; st.OrderCount++; } } if (++x >= MyLayout.NoX) { x = 0; if (++y >= MyLayout.NoY) { y = 0; page = null; tabName += '.'; } } } } else { foreach (var order in gr) { listXX.Add(order); } } ResumeLayout(); PerformLayout(); } if (listXX.Count != 0) { int x = 0, y = 0; SuspendLayout(); string tabName = "99"; page = null; HourStatics st = new HourStatics(99); listStatics.Add(st); foreach (var order in listXX) { if (page == null) { page = AddTabControl1Item(tabName); } CreateLabel(page, x, y, order, WidthX, HeightY); if (!order.Deleted) { total += order.Income; st.Revenue += order.Income; if (!order.IsIncomeNull() && order.Income >= 0) // 退貨的不加入單數 { count++; st.OrderCount++; } } if (++x >= MyLayout.NoX) { x = 0; if (++y >= MyLayout.NoY) { y = 0; page = null; tabName += '.'; } } } ResumeLayout(); PerformLayout(); } // 統計頁 foreach (HourStatics hs in listStatics) { if (hs.OrderCount != 0) { hs.Average = Math.Round(hs.Revenue / hs.OrderCount, 1); } } dgvStatics.DataSource = listStatics; tc.SelectedIndex = 0; // if (page != null) tc.SelectTab(page); ResetListView(); lvItems.Focus(); labelOrderCount.Text = count.ToString(); labelTotalRevenue.Text = total.ToString("N1"); if (count != 0) { labelTotalAverage.Text = Math.Round(total / count, 1).ToString(); } }
private void cbBoxTable_SelectedIndexChanged(object sender, EventArgs e) { ComboBox box = sender as ComboBox; string tableName = box.SelectedItem.ToString(); XmlNode root = Cfg.Load(ConfigName, tableName); if (root == null) { MessageBox.Show("載入<" + tableName + ">失敗!"); return; } textBoxName.Text = tableName; int productID; XmlNode sale = root.SelectSingleNode("Product"); // XmlNode stock = root.SelectSingleNode("Ingredient"); m_SaleList = new SortableBindingList <CSaleItem>(); // m_StockList = new List<StockItem>(); foreach (XmlNode node in sale.ChildNodes) { if (node.Name != "ProductID") { continue; } productID = 0; try { productID = Convert.ToInt32(node.InnerText); } catch { continue; } if (productID <= 0) { continue; } CSaleItem m = new CSaleItem(productID); foreach (var row in m_OrderSet.Product) { if (row.ProductID == productID) { if (!row.IsPriceNull()) { m.Price = (decimal)row.Price; } if (!row.IsUnitNull()) { m.Unit = row.Unit; } else { m.Unit = "份"; } if (!row.IsEvaluatedCostNull()) { m.EvaluatedCost = row.EvaluatedCost; } else { m.EvaluatedCost = 0m; } break; } } m_SaleList.Add(m); } cSaleItemBindingSource.DataSource = m_SaleList; }
// 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 + ">無進貨!"); } }