예제 #1
0
            public int FillBySelectStr(MyOrderSet.OrderDataTable dataTable, string SelectStr)
            {
                SaveStr = base.CommandCollection[0].CommandText;
                base.CommandCollection[0].CommandText = SelectStr;
                int result = Fill(dataTable);

                base.CommandCollection[0].CommandText = SaveStr;
                return(result);
            }
예제 #2
0
        decimal selectData(DateTime time1, DateTime time2)
        {
            if (m_ProductDic.Count == 0)
            {
                Message("載入產品估算成本...");
                foreach (var pd in Product)
                {
                    if (pd.Code > 0)
                    {
                        m_ProductDic.Add(pd.ProductID, pd.IsEvaluatedCostNull()? 0 : pd.EvaluatedCost);
                    }
                }
            }
            TimeData timedata = new TimeData();
            decimal  costtemp = 0;
            string   sT1      = time1.ToString("MMdd");
            string   sT2      = time2.ToString("MMdd");
            string   duration = "<" + sT1 + "-" + sT2 + ">";

#if (UseSQLServer)
            string sqlstr = "Where Floor(ID/1000000)>" + sT1 + " and Floor(ID/1000000)<=" + sT2;
#else
            string sqlstr = "Where INT(ID/1000000)>" + sT1 + " and INT(ID/1000000)<=" + sT2;
#endif
            MyOrderSet.OrderDataTable     Order     = new MyOrderSet.OrderDataTable();
            MyOrderSet.OrderItemDataTable OrderItem = new MyOrderSet.OrderItemDataTable();
            //m_OrderAdapter.FillBySelectStr(Order, "Select * From [Order] " + sqlstr + " and oldid=0 And deleted=false Order by ID");
            //m_OrderItemAdapter.FillBySelectStr(OrderItem, "Select * From [OrderItem] " + sqlstr + " Order by ID");
            m_OrderSet.OrderItem.Clear();
            m_OrderSet.Order.Clear();
            //try  // 讓上一級處理
            {
                Message("載入" + duration + "售出單...");
                m_OrderAdapter.FillBySelectStr(m_OrderSet.Order, "Select * From [Order] " + sqlstr + " Order by ID");
                Message("載入" + duration + "售出明細...");
                m_OrderItemAdapter.FillBySelectStr(m_OrderSet.OrderItem, "Select * From [OrderItem] " + sqlstr + " Order by ID");
            }
            //catch (Exception ex) { MessageBox.Show(ex.Message); }
            Message("開始計算" + duration + "銷售品總成本...");
            progressBar1.Visible = true;
            progressBar1.Maximum = m_OrderSet.Order.Count + 1;
            int i = 0;
            foreach (var item in m_OrderSet.Order)
            {
                progressBar1.Value = i++;
                Application.DoEvents();
                if (item.Deleted)
                {
                    continue;
                }
                if (item.OldID != 0)
                {
                    continue;
                }
                //var orderItem = from row in OrderItem where (row.ID == item.ID) select row;
                //foreach (var item1 in orderItem)
                var rows = item.GetOrderItemRows();
                foreach (MyOrderSet.OrderItemRow item1 in rows)
                {
                    decimal cost = 0;
                    if (m_ProductDic.TryGetValue(item1.ProductID, out cost))
                    {
                        costtemp += cost * item1.No;
                    }
                }
            }
            progressBar1.Visible = false;
            Application.DoEvents();
            return(costtemp);
        }