Exemple #1
0
        private void Add2List(SortableBindingList <CIngredient> list, int id, decimal cost, decimal volume)
        {
            foreach (CIngredient p in list)
            {
                if (p.ID == id)
                {
                    p.TotalCost += cost;
                    p.OrderCount++;
                    p.Volume += volume;
                    if (p.Volume != 0)
                    {
                        p.UnitCost = p.TotalCost / p.Volume;
                    }
                    return;
                }
            }
            CIngredient p1 = new CIngredient(id);

            p1.TotalCost += cost;
            p1.OrderCount++;
            p1.Volume += volume;
            if (p1.Volume != 0)
            {
                p1.UnitCost = p1.TotalCost / p1.Volume;
            }
            list.Add(p1);
        }
Exemple #2
0
        CMonthlyPay FindOrAdd(int id, SortableBindingList <CMonthlyPay> list)
        {
            foreach (CMonthlyPay p in list)
            {
                if (p.VenderID == id)
                {
                    return(p);
                }
            }
            CMonthlyPay pay = new CMonthlyPay();

            pay.VenderID = id;
            list.Add(pay);
            return(pay);
        }
Exemple #3
0
        CMonthlyIncome FindOrAdd(int id, SortableBindingList <CMonthlyIncome> list)
        {
            foreach (CMonthlyIncome p in list)
            {
                if (p.CustomerID == id)
                {
                    return(p);
                }
            }
            CMonthlyIncome pay = new CMonthlyIncome();

            pay.CustomerID = id;
            list.Add(pay);
            return(pay);
        }
Exemple #4
0
 private void btnAddAllProduct_Click(object sender, EventArgs e)
 {
     foreach (var row in m_OrderSet.Product)
     {
         if (row.IsCodeNull())
         {
             continue;
         }
         if (row.Code <= 0)
         {
             continue;                      // 有代碼才加入
         }
         int productID = row.ProductID;
         var inList    = from l in m_SaleList where l.ProductID == productID select l;
         if (inList.Count() > 0)
         {
             continue;                    // 己經有了不用再加
         }
         CSaleItem m = new CSaleItem(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;
         }
         m_SaleList.Add(m);
     }
     cSaleItemBindingSource.ResetBindings(false);
 }
Exemple #5
0
        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;
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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();
            }
        }
Exemple #8
0
        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;
        }