Exemple #1
0
        void Item2Buffer(ByteBuilder Buf, CSaleItem item)
        {
            int    index = productBindingSource.Find("ProductID", item.ProductID);
            string s     = "產品" + item.ProductID.ToString();

            if (index >= 0)
            {
                object       o  = productBindingSource.DataSource;
                BasicDataSet ds = (BasicDataSet)o;
                BasicDataSet.ProductDataTable t   = ds.Product;
                BasicDataSet.ProductRow       row = t[index];
                s = row.Name;
            }

            int m;

            do
            {
                m = GB2312.GetByteCount(s);
                if (m <= 16)
                {
                    break;
                }
                s = s.Substring(0, s.Length - 1);
            } while (true);
            int n = 16 - m + s.Length;

            Buf.AppendPadRight(s, n, GB2312);
            Buf.Append(d2str(item.Volume, 6), GB2312);
//            Buf.Append(d2str(item.Price  , 5), GB2312);
            Buf.Append(d2str(item.Total, 10), GB2312);
            Buf.Append("\r\n", GB2312);
        }
Exemple #2
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 List <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 (BasicDataSet.ProductRow row in this.basicDataSet.Product)
                {
                    if (row.ProductID == productID)
                    {
                        if (!row.IsPriceNull())
                        {
                            m.Price = (decimal)row.Price;
                        }
                        if (!row.IsUnitNull())
                        {
                            m.Unit = row.Unit;
                        }
                        else
                        {
                            m.Unit = "份";
                        }
                        break;
                    }
                }
                m_SaleList.Add(m);
            }
            cSaleItemBindingSource.DataSource = m_SaleList;
        }
Exemple #3
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 #4
0
        void Item2Buffer(ByteBuilder Buf, CSaleItem item)
        {
            string s = "產品" + item.ProductID.ToString();
            //int index = productBindingSource.Find("ProductID", item.ProductID);
            //
            //if (index >= 0)
            //{
            //    object o = productBindingSource.DataSource;
            //    BasicDataSet ds=(BasicDataSet)o;
            //    BasicDataSet.ProductDataTable t = ds.Product;
            //    BasicDataSet.ProductRow row = t[index];
            //    s = row.Name;
            //}
            var pr = from r in m_OrderSet.Product where r.ProductID == item.ProductID select r;

            if (pr.Count() > 0)
            {
                if (!pr.First().IsNameNull())
                {
                    s = pr.First().Name;
                }
            }
            int m;

            do
            {
                m = GB2312.GetByteCount(s);
                if (m <= 16)
                {
                    break;
                }
                s = s.Substring(0, s.Length - 1);
            } while (true);
            int n = 16 - m + s.Length;

            Buf.AppendPadRight(s, n, GB2312);
            Buf.Append(d2str(item.Volume, 6), GB2312);
//            Buf.Append(d2str(item.Price  , 5), GB2312);
            Buf.Append(d2str(item.Total, 10), GB2312);
            Buf.Append("\r\n", GB2312);
        }
Exemple #5
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     id;
            XmlNode sale  = root.SelectSingleNode("Product");
            XmlNode stock = root.SelectSingleNode("Ingredient");

            m_SaleList  = new List <CSaleItem>();
            m_StockList = new List <CStockItem>();
            foreach (XmlNode node in sale.ChildNodes)
            {
                if (node.Name != "ProductID")
                {
                    continue;
                }
                id = 0;
                try
                {
                    id = Convert.ToInt32(node.InnerText);
                }
                catch { continue; }
                if (id <= 0)
                {
                    continue;
                }
                CSaleItem m = new CSaleItem(id);
                foreach (var row in m_OrderSet.Product)
                {
                    if (row.ProductID == id)
                    {
                        if (!row.IsPriceNull())
                        {
                            m.Price = (decimal)row.Price;
                        }
                        if (!row.IsUnitNull())
                        {
                            m.Unit = row.Unit;
                        }
                        else
                        {
                            m.Unit = "份";
                        }
                        break;
                    }
                }
                m_SaleList.Add(m);
            }
            foreach (XmlNode node in stock.ChildNodes)
            {
                if (node.Name != "IngredientID")
                {
                    continue;
                }
                id = 0;
                try
                {
                    id = Convert.ToInt32(node.InnerText);
                }
                catch { continue; }
                if (id <= 0)
                {
                    continue;
                }
                CStockItem si   = new CStockItem(id);
                var        ings = from r in m_DataSet.Ingredient where r.IngredientID == id select r;
                if (ings.Count() > 0)
                {
                    if (!ings.First().IsUnitNull())
                    {
                        si.Unit = ings.First().Unit;
                    }
                }
                m_StockList.Add(si);
            }
            int mon = comboBoxMonth.SelectedIndex;

            if (mon > 0 && mon <= 12)
            {
                ShowTotal(CalcSaleList(mon), CalcStockList(mon));
            }
            cSaleItemBindingSource.DataSource = m_SaleList;
            stockItemBindingSource.DataSource = m_StockList;
        }
Exemple #6
0
        private decimal CalcSaleList(int month)
        {
            if (month < 1 || month > 12)
            {
                MessageBox.Show("所選月份<" + month.ToString() + ">不對!");
                return(0);
            }
            int count = m_SaleList.Count;

            if (count <= 1)
            {
                return(0);
            }
            int year = MyFunction.IntHeaderYear;
            int to   = MyFunction.DayCountOfMonth(month);

            if (month == 2 && DateTime.IsLeapYear(year))
            {
                to = 29;
            }
            LoadData(month, 1, to);    // 一律稅控制
            foreach (CSaleItem m in m_SaleList)
            {
                m.Total  = 0;
                m.Volume = 0;
            }
            bool[] debug = new bool[count];   // items code會重複, 不知為何 ,只好用此辦法
            foreach (var row in m_OrderSet.Order)
            {
                var items = row.GetOrderItemRows();
                for (int i = 0; i < count; i++)
                {
                    debug[i] = false;
                }
                foreach (var it in items)
                {
                    for (int i = 0; i < m_SaleList.Count; i++)
                    {
                        CSaleItem m = m_SaleList[i];
                        if (m.ProductID == it.ProductID)
                        {
                            if (debug[i])
                            {
                                break;                  // 重複算了二次, items存入有bug,只好先跳掉
                            }
                            debug[i]  = true;
                            m.Volume += it.No;
                            if (it.Discount)
                            {
                                m.Total += it.Price * it.No * 0.88m;
                            }
                            else
                            {
                                m.Total += it.Price * it.No;
                            }
                            break;
                        }
                    }
                }
            }
            decimal sum = 0;

            foreach (CSaleItem item in m_SaleList)
            {
                sum += item.Total;
            }
            return(sum);

            //            materialBindingSource.ResetBindings(false);
            //            Text = "物料統計 " + month.ToString() + "月 " + from.ToString() + "日 至 " + to.ToString() + "日";
            //            if (ckBoxUse12.Checked) Text += "  稅控制";
        }
Exemple #7
0
        private decimal CalcSaleList(int month, int from, int to)
        {
            int count = m_SaleList.Count;

            if (count < 1)
            {
                MessageBox.Show("請選擇產品列表");
                return(decimal.MinValue);    // 不可能是負
            }
            int year = MyFunction.IntHeaderYear;

            labelMessage.Text    = "載入資料中.";
            labelMessage.Visible = true;
            Application.DoEvents();
            LoadData(year, month, from, to);
            foreach (CSaleItem m in m_SaleList)
            {
                m.Total  = 0;
                m.Volume = 0;
            }
            labelMessage.Text = "計算中...";

            InitProgressBar(m_OrderSet.Order.Count + m_OrderSet.Shipment.Count);  //此处不用区分 是出货(出货数+0)还售货(售货数+0)还是出货和售货的和


            Application.DoEvents();

            bool[]    debug       = new bool[count]; // items code會重複, 不知為何 ,只好用此辦法
            CSaleItem lostProduct = new CSaleItem();

            lostProduct.Total  = 0;
            lostProduct.Volume = 0;
            foreach (var row in m_OrderSet.Order)
            {
                if (!row.IsDeletedNull() && row.Deleted)
                {
                    continue;                                      // 刪單不計
                }
                decimal discountRate = 0.88m, deductRate = 1m;
                if (!row.IsDiscountRateNull())
                {
                    discountRate = row.DiscountRate;
                }
                var items = row.GetOrderItemRows();
                for (int i = 0; i < count; i++)
                {
                    debug[i] = false;
                }
                decimal total = 0;
                foreach (var it in items)
                {
                    if (it.IsProductIDNull())
                    {
                        continue;
                    }
                    if (it.Discount)
                    {
                        total += it.Price * it.No * discountRate;
                    }
                    else
                    {
                        total += it.Price * it.No;
                    }
                }
                decimal income = 0;
                if (!row.IsIncomeNull())
                {
                    income = row.Income;
                }
                if (total != 0m)
                {
                    deductRate = income / total;
                }
                int hr = 0;
                if (!row.IsPrintTimeNull())
                {
                    hr = row.PrintTime.Hour;
                }
                foreach (var it in items)
                {
                    if (it.RowState == DataRowState.Deleted)
                    {
                        continue;                                      // 己刪除的
                    }
                    if (it.IsProductIDNull())
                    {
                        continue;
                    }
                    bool notFound = true;
                    for (int i = 0; i < m_SaleList.Count; i++)
                    {
                        CSaleItem m = m_SaleList[i];
                        if (m.ProductID == it.ProductID)
                        {
                            notFound = false;
                            if (debug[i])
                            {
                                break;        // 重複算了二次, items存入有bug,只好先跳掉
                            }
                            debug[i] = true;
                            if (income >= 0)            // 收入為負,退貨不計也不減回數量,計成本並回扣收入
                            {
                                m.AddVolume(it.No, hr);
                            }
                            if (it.Discount)
                            {
                                m.Total += (it.Price * it.No * discountRate) * deductRate;
                            }
                            else
                            {
                                m.Total += it.Price * it.No * deductRate;
                            }
                            break;
                        }
                    }
                    if (notFound)   // 產品表和OrderItem一定不Match了,所以找不到
                    {
                        if (it.Discount)
                        {
                            lostProduct.Total += (it.Price * it.No * discountRate) * deductRate;
                        }
                        else
                        {
                            lostProduct.Total += it.Price * it.No * deductRate;
                        }
                    }
                }

                progressBar1.Increment(1);
                Application.DoEvents();
            }
            ///出货计算
            foreach (var row in m_OrderSet.Shipment)
            {
                decimal discountRate = 0.88m, deductRate = 1m;
                //if (!row.IsDiscountRateNull()) discountRate = row.DiscountRate;
                var items = row.GetShipmentDetailRows();
                for (int i = 0; i < count; i++)
                {
                    debug[i] = false;
                }
                decimal total = 0;
                foreach (var it in items)
                {
                    if (it.IsProductIDNull())
                    {
                        continue;
                    }
                    // if (it.Discount)
                    //  total += it.Price * it.No * discountRate;
                    // else
                    //    total += it.Price * it.No;
                    // total += it.Cost * it.Volume;
                    total += it.Cost;
                }
                decimal income = 0;
                //if (!row.IsIncomeNull()) income = row.Income;
                if (!row.IsCostNull())
                {
                    income = row.Cost;
                }
                if (total != 0m)
                {
                    deductRate = income / total;
                }
                int hr = 0;
                if (!row.IsPrintTimeNull())
                {
                    hr = row.PrintTime.Hour;
                }
                foreach (var it in items)
                {
                    if (it.IsProductIDNull())
                    {
                        continue;
                    }
                    for (int i = 0; i < m_SaleList.Count; i++)
                    {
                        CSaleItem m = m_SaleList[i];
                        if (m.ProductID == it.ProductID)
                        {
                            if (debug[i])
                            {
                                break;                  // 重複算了二次, items存入有bug,只好先跳掉
                            }
                            debug[i] = true;
                            if (income >= 0)            // 收入為負,退貨不計也不減回數量,計成本並回扣收入
                            {
                                m.AddVolume(it.Volume, hr);
                            }
                            //if (it.Discount)
                            //    m.Total += (it.Price * it.No * discountRate) * deductRate;
                            //else
                            //    m.Total += it.Price * it.No * deductRate;
                            // m.Total += it.Cost * it.Volume * deductRate;
                            m.Total += it.Cost * deductRate;
                            break;
                        }
                    }
                }

                progressBar1.Increment(1);
                Application.DoEvents();
            }
            decimal sum = 0, totalCost = 0, totalVolume = 0;

            foreach (CSaleItem item in m_SaleList)
            {
                item.TotalEvaluatedCost = Math.Round(item.Volume * item.EvaluatedCost, 1);
                if (item.Total != 0)
                {
                    item.GrossProfitRate = Math.Round((item.Total - item.TotalEvaluatedCost) / item.Total * 100, 1);
                }
                else
                {
                    item.GrossProfitRate = 0;
                }
                sum         += item.Total;
                totalCost   += item.TotalEvaluatedCost;
                totalVolume += item.Volume;
            }
            progressBar1.Visible  = false;
            labelMessage.Visible  = false;
            labelTotal.Text       = sum.ToString("N1");
            labelCost.Text        = totalCost.ToString("N1");
            labelTotalVolume.Text = totalVolume.ToString("N0");
            if (sum == 0m)
            {
                labelGrossProfitRate.Text = "";
            }
            else
            {
                labelGrossProfitRate.Text = ((sum - totalCost) / sum * 100).ToString("N1");
            }
            return(sum);

            //            materialBindingSource.ResetBindings(false);
            //            Text = "物料統計 " + month.ToString() + "月 " + from.ToString() + "日 至 " + to.ToString() + "日";
            //            if (ckBoxUse12.Checked) Text += "  稅控制";
        }
Exemple #8
0
        private decimal CalcSaleList(int month, int from, int to, bool taxBased)
        {
            int count = m_SaleList.Count;

            if (count <= 1)
            {
                MessageBox.Show("請選擇產品列表");
                return(decimal.MinValue);    // 不可能是負
            }
            int year = MyFunction.IntHeaderYear;

            labelMessage.Text    = "載入資料中.";
            labelMessage.Visible = true;
            Application.DoEvents();
            LoadData(year, month, from, to, taxBased);    // 一律稅控制
            foreach (CSaleItem m in m_SaleList)
            {
                m.Total  = 0;
                m.Volume = 0;
            }
            labelMessage.Text = "計算中...";

            InitProgressBar(basicDataSet.Order.Count);
            Application.DoEvents();

            bool[] debug = new bool[count];   // items code會重複, 不知為何 ,只好用此辦法
            foreach (BasicDataSet.OrderRow row in basicDataSet.Order)
            {
                BasicDataSet.OrderItemRow[] items = row.GetOrderItemRows();
                for (int i = 0; i < count; i++)
                {
                    debug[i] = false;
                }
                foreach (BasicDataSet.OrderItemRow it in items)
                {
                    if (it.IsProductIDNull())
                    {
                        continue;
                    }
                    for (int i = 0; i < m_SaleList.Count; i++)
                    {
                        CSaleItem m = m_SaleList[i];
                        if (m.ProductID == it.ProductID)
                        {
                            if (debug[i])
                            {
                                break;                  // 重複算了二次, items存入有bug,只好先跳掉
                            }
                            debug[i]  = true;
                            m.Volume += it.No;
                            if (it.Discount)
                            {
                                m.Total += it.Price * it.No * 0.88m;
                            }
                            else
                            {
                                m.Total += it.Price * it.No;
                            }
                            break;
                        }
                    }
                }
                progressBar1.Increment(1);
                Application.DoEvents();
            }
            decimal sum = 0;

            foreach (CSaleItem item in m_SaleList)
            {
                sum += item.Total;
            }
            progressBar1.Visible = false;
            labelMessage.Visible = false;
            return(sum);

            //            materialBindingSource.ResetBindings(false);
            //            Text = "物料統計 " + month.ToString() + "月 " + from.ToString() + "日 至 " + to.ToString() + "日";
            //            if (ckBoxUse12.Checked) Text += "  稅控制";
        }