public DataTable QueryStockTakeItemCount(ArrayList ParameterList)
 {
     MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);
     try
     {
         DataTable dtResult = dbo.QueryStockTakeItemCount(ParameterList);
         return dtResult;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public DataTable QueryByID(string strID, out string strLocateNo, out string strLocateS, out string strLocateE, out string strStockDate
     , out string strStocktakeNo, out string strTotalQty, out string strTakeUserId, out string strStatus)
 {
     MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);
     DataTable dtResult;
     try
     {
         dtResult = dbo.QueryByID(strID, out strLocateNo, out strLocateS, out strLocateE, out strStockDate
     , out strStocktakeNo, out strTotalQty, out strTakeUserId, out strStatus);
         return dtResult;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void GetStockTakeItem(ArrayList ParameterList, out string strStockTakeNo, out string strID, out string strMsg, out string strResult)
        {
            MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);
            //DataTable dtResult;
            try
            {
                dbo.GetStockTakeItem(ParameterList, out strStockTakeNo, out strID, out strMsg, out strResult);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public DataTable GetLocateSection3(string V_LOCATE_SECTION_S, string V_LOCATE_SECTION_E)
 {
     MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);
     DataTable dtResult;
     try
     {
         dtResult = dbo.GetLocateSection3(V_LOCATE_SECTION_S, V_LOCATE_SECTION_E);
         return dtResult;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public string GetOrderDocumentIDAndCode()
 {
     try
     {
         DBO.MaintainStockTakeDBO db = new MaintainStockTakeDBO(ref USEDB);
         return db.GetOrderDocumentIDAndCode();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public int InsertStockTake(ArrayList ParameterList, DbTransaction RootDBT)
        {
            int result;
            bool IsRootTranscation = false;
            DBO.MaintainStockTakeDBO db = new MaintainStockTakeDBO(ref USEDB);

            try
            {
                //判斷是否有傳入Root Transcation 
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region 啟動交易或指定RootTranscation

                if (IsRootTranscation)
                {
                    //獨立呼叫啟動Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion

                result = db.InsertStockTake(ParameterList, RootDBT);

                #region 交易成功

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation成立
                    DBT.Commit();
                }

                #endregion
                return result;
            }
            catch (Exception ex)
            {
                #region 交易失敗

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation失敗
                    DBT.Rollback();
                }

                #endregion

                throw ex;
            }
            finally
            {
                #region 判斷是否關閉交易連線

                if (IsRootTranscation)
                {
                    //獨立呼叫Transcation,關閉連線
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }
        }
        public int CreateStockTake2(ArrayList ParameterList, DataTable dtData, out string V_STOCKTAKE_NO, out string N_ID)
        {
            int result;
            bool IsRootTranscation = false;
            DBO.MaintainStockTakeDBO db = new MaintainStockTakeDBO(ref USEDB);
            string strSTOCKTAKE_NO = string.Empty;
            string strPID = string.Empty;
            ArrayList Para = new ArrayList();
            try
            {

                //獨立呼叫啟動Transcation
                Conn = USEDB.CreateConnection();
                Conn.Open();
                DBT = Conn.BeginTransaction();

                //ParameterList
                //0.V_LOCATE_SECTION_S
                //1.V_LOCATE_SECTION_E
                //2.V_STOCK_DATE
                //3.V_TAKEUSER_ID
                //4.CREATEUID
                //5.CREATEDATE

                result = db.CreateStockTake2(ParameterList, DBT, out strSTOCKTAKE_NO, out strPID);

                for (int i = 0; i < dtData.Rows.Count; i++)
                {
                    Para.Clear();
                    string strLOCATE_NO = dtData.Rows[i]["LOCATE_NO"].ToString();
                    string strLOCATE_SECTION = dtData.Rows[i]["LOCATE_SECTION"].ToString();
                    string strITEM = dtData.Rows[i]["ITEM"].ToString();
                    string strPERIOD = dtData.Rows[i]["PERIOD"].ToString();
                    string strONHD_QTY = dtData.Rows[i]["ONHD_QTY"].ToString();
                    string strSTOCKTAKE_QTY = dtData.Rows[i]["STOCKTAKE_QTY"].ToString();
                    string strCOST = dtData.Rows[i]["COST"].ToString();
                    Para.Add(int.Parse(strPID));
                    Para.Add(strLOCATE_NO + strLOCATE_SECTION);
                    Para.Add(strITEM);
                    Para.Add(strPERIOD);
                    Para.Add(int.Parse(strONHD_QTY));
                    Para.Add(int.Parse(strSTOCKTAKE_QTY));
                    Para.Add(strCOST.Trim() == "" ? 0 : double.Parse(strCOST));
                    Para.Add(ParameterList[4].ToString());
                    Para.Add(ParameterList[5]);

                    result = db.InsertStockTake2(Para, DBT);
                }
                Para.Clear();
                Para.Add(ParameterList[4].ToString());//V_CREATEUID
                Para.Add(ParameterList[5]);           //D_CREATEDATE
                Para.Add(strSTOCKTAKE_NO);            //V_STOCKTAKE_NO
                Para.Add(strPID);                     //N_ID

                result = db.CreateStockTake2F(Para, DBT);

                DBT.Commit();

                V_STOCKTAKE_NO = strSTOCKTAKE_NO;
                N_ID = strPID;

                return result;
            }
            catch (Exception ex)
            {
                if (DBT != null)
                {
                    DBT.Rollback();
                }
                throw ex;
            }
            finally
            {
                if (Conn.State == ConnectionState.Connecting)
                {
                    Conn.Close();
                }
            }
        }
        public void GetCostByItem(string strItem, string strPeriod, out string strID)
        {
            MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);

            try
            {
                dbo.GetCostByItem(strItem, strPeriod, out strID);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public DataTable GetLocateSection(int iID)
 {
     MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);
     DataTable dtResult;
     try
     {
         dtResult = dbo.GetLocateSection(iID);
         return dtResult;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void CheckStockTakeItem(ArrayList ParameterList, out string strMsg, out string strResult)
        {
            MaintainStockTakeDBO dbo = new MaintainStockTakeDBO(ref USEDB);

            try
            {
                dbo.CheckStockTakeItem(ParameterList, out strMsg, out strResult);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }