예제 #1
0
        /// <summary>
        /// 获得某一仓库、某一物料、某一类型商品的库存
        /// </summary>
        /// <param name="SStorehouseId"></param>
        /// <param name="matId"></param>
        /// <param name="matType"></param>
        /// <returns></returns>
        public static StockStatus GetStockNum(string SStorehouseId, string matId, int matType)
        {
            double stockNum = 0; //当前库存
            double firstCount = 0; //期初数量
            double stockInCount = 0; //收入数量
            double stockOutCount = 0; //发出数量
            SqlDBConnect db = new SqlDBConnect();

            //查找最近一次结存的数量
            string maxBalanceTime = StockStatusDAO.GetBalanceTime();
            string strSql_ = "select FirstCount,FirstCostPrice,BalanceTime from T_Stock_Status " +
                              "where StoreHouseId='{0}' and MatId='{1}' and MatType={2} and BalanceTime='{3}'";
            strSql_ = string.Format(strSql_, SStorehouseId, matId, matType, maxBalanceTime);
            DataTable dt_ = db.Get_Dt(strSql_);
            if (dt_ != null && dt_.Rows.Count > 0)
                firstCount = Convert.ToDouble(dt_.Rows[0]["FirstCount"].ToString().Trim());

            //入库
            string sql_1 = "select sum(num) num from T_Receipt_Main_Det where SourceStoreH='{0}' and MatId='{1}' and MatType='{2}' and CurWorkMonth >= '{3}' " +
                           "and ReceiptTypeID < '51' and ReceiptTypeID != 'YS' and ReceiptTypeID != 'YF'";
            sql_1 = string.Format(sql_1, SStorehouseId, matId, matType, maxBalanceTime);
            DataTable dt_1 = db.Get_Dt(sql_1);
            if (dt_1 != null && dt_1.Rows.Count > 0)
            {
                if (dt_1.Rows[0]["num"].ToString().Trim() != "")
                    stockInCount = Convert.ToDouble(dt_1.Rows[0]["num"].ToString().Trim());
            }

            //出库
            string sql_2 = "select sum(num) num from T_Receipt_Main_Det where SourceStoreH='{0}' and MatId='{1}' and MatType='{2}' and CurWorkMonth >= '{3}' " +
                           "and ReceiptTypeID >= '51' and ReceiptTypeID <=  '90'";
            sql_2 = string.Format(sql_2, SStorehouseId, matId, matType, maxBalanceTime);
            DataTable dt_2 = db.Get_Dt(sql_2);
            if (dt_2 != null && dt_2.Rows.Count > 0)
            {
                if (dt_2.Rows[0]["num"].ToString().Trim() != "")
                    stockOutCount = Convert.ToDouble(dt_2.Rows[0]["num"].ToString().Trim());
            }
            stockNum = firstCount + stockInCount - stockOutCount;

            StockStatus stockStatus = new StockStatus();
            stockStatus.firstCount = firstCount;
            stockStatus.stockInCount = stockInCount;
            stockStatus.stockOutCount = stockOutCount;
            stockStatus.stockNum = stockNum;

            return stockStatus;
        }
예제 #2
0
        /// <summary>
        /// 获得某一仓库、某一物料、某一类型商品的库存
        /// </summary>
        /// <param name="SStorehouseId"></param>
        /// <param name="matId"></param>
        /// <param name="matType"></param>
        /// <returns></returns>
        public static StockStatus GetStockNum(string SStorehouseId, string matId, int matType)
        {
            double       stockNum      = 0; //当前库存
            double       firstCount    = 0; //期初数量
            double       stockInCount  = 0; //收入数量
            double       stockOutCount = 0; //发出数量
            SqlDBConnect db            = new SqlDBConnect();

            //查找最近一次结存的数量
            string maxBalanceTime = StockStatusDAO.GetBalanceTime();
            string strSql_        = "select FirstCount,FirstCostPrice,BalanceTime from T_Stock_Status " +
                                    "where StoreHouseId='{0}' and MatId='{1}' and MatType={2} and BalanceTime='{3}'";

            strSql_ = string.Format(strSql_, SStorehouseId, matId, matType, maxBalanceTime);
            DataTable dt_ = db.Get_Dt(strSql_);

            if (dt_ != null && dt_.Rows.Count > 0)
            {
                firstCount = Convert.ToDouble(dt_.Rows[0]["FirstCount"].ToString().Trim());
            }

            //入库
            string sql_1 = "select sum(num) num from T_Receipt_Main_Det where SourceStoreH='{0}' and MatId='{1}' and MatType='{2}' and CurWorkMonth >= '{3}' " +
                           "and ReceiptTypeID < '51' and ReceiptTypeID != 'YS' and ReceiptTypeID != 'YF'";

            sql_1 = string.Format(sql_1, SStorehouseId, matId, matType, maxBalanceTime);
            DataTable dt_1 = db.Get_Dt(sql_1);

            if (dt_1 != null && dt_1.Rows.Count > 0)
            {
                if (dt_1.Rows[0]["num"].ToString().Trim() != "")
                {
                    stockInCount = Convert.ToDouble(dt_1.Rows[0]["num"].ToString().Trim());
                }
            }

            //出库
            string sql_2 = "select sum(num) num from T_Receipt_Main_Det where SourceStoreH='{0}' and MatId='{1}' and MatType='{2}' and CurWorkMonth >= '{3}' " +
                           "and ReceiptTypeID >= '51' and ReceiptTypeID <=  '90'";

            sql_2 = string.Format(sql_2, SStorehouseId, matId, matType, maxBalanceTime);
            DataTable dt_2 = db.Get_Dt(sql_2);

            if (dt_2 != null && dt_2.Rows.Count > 0)
            {
                if (dt_2.Rows[0]["num"].ToString().Trim() != "")
                {
                    stockOutCount = Convert.ToDouble(dt_2.Rows[0]["num"].ToString().Trim());
                }
            }
            stockNum = firstCount + stockInCount - stockOutCount;

            StockStatus stockStatus = new StockStatus();

            stockStatus.firstCount    = firstCount;
            stockStatus.stockInCount  = stockInCount;
            stockStatus.stockOutCount = stockOutCount;
            stockStatus.stockNum      = stockNum;

            return(stockStatus);
        }