public bool CheckPurItemIsOnWay(string sPurNo, string sItemNo, string sPeriod)
        {
            try
            {
                DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
                int iCount = dbo.CheckPurItemIsOnWay(sPurNo, sItemNo, sPeriod);

                if (iCount == 0)
                { return false; }
                else
                { return true; }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool CheckPurchaseIsACCEPT(string sPurNo)
        {
            try
            {
                DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
                int iCount = dbo.CheckPurchaseIsACCEPT(sPurNo);

                if (iCount == 0)
                { return false; }
                else
                { return true; }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public int Check_DC_Date(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.doCheck_DC_Date(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public DataTable GetVendorDataByVendorNo(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.GetVendorData(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public DataTable GetTempErrorDataByfind(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.GetTempErrorDataByFind1(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public string GetOrderDocumentIDAndCode()
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.GetOrderDocumentIDAndCode();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public DataTable GetItemsByPurchase_No(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.GetItemsByPUR_No(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public string GetDetail_Data(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.doGetDetailData(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public DataTable QueryPrintPurchaseOrderDetail(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.PrintPurchaseOrderDetail(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// �򥻪��s�WBCO
        /// </summary>
        /// <param name="ParameterList">��J�ܼ�</param>
        /// <param name="RootDBT">�O�_���D���,�L�D�����Jnull</param>
        /// <returns>�^�Ƿs�W��ID</returns>
        public string CreateMasterAndDetail_Gift(ArrayList ParameterList,
            DataTable DetailData,
            DataTable GiftData,
            DbTransaction RootDBT)
        {
            #region
            bool IsRootTranscation = false;
            Int32 PID = 0;
            string[] sID_NO;
            string sTemp = "";
            string sPurchaseNo = "";
            try
            {
                //�P�_�O�_���ǤJRoot Transcation
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region �Ұʥ���Ϋ��wRootTranscation

                if (IsRootTranscation)
                {
                    //�W�ߩI�s�Ұ�Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion

                //�g�J Master Table
                sTemp = CreatePurchaseOrder(ParameterList, DBT);
                sID_NO = sTemp.Split(new Char[] { ';' });
                PID = int.Parse(sID_NO[0].ToString());
                sPurchaseNo = sID_NO[1].ToString();

                //�NParameterList���s��D��ID�PPURCHASRE_NO���ȡA����PID�PsPurchaseNo
                ParameterList[5] = sPurchaseNo;
                ParameterList[6] = PID;

                if (PID != 0)
                {
                    #region �s�W���Ӹ�ƻP��s VDS_MKT_PURCARD_MAIN.PUR_NO(���x���ʥd) �� VDS_MKT_BPURCARD_MAIN.PUR_NO(�Ϯѱ��ʥd)
                    foreach (DataRow dRow in DetailData.Rows)
                    {
                        CreatePurchaseOrderDetail(PID, ParameterList, dRow, DBT);

                        //��s���O�ݩ���(VDS_ITM_PERIOD_PROFILE)��,�ӫ~�����O����f����B���ʤ�B���ʶq�P���ʳ渹
                        UpdatePeriodProfile(dRow["ITEM"].ToString().Trim(), dRow["PERIOD"].ToString().Trim(), dRow["PLAN_ACCEPT_DATE"].ToString().Trim(), ParameterList[0].ToString().Trim(),
                                            dRow["PURCHASE_QTY"].ToString().Trim(), sPurchaseNo, ParameterList[4].ToString().Trim(), DBT);

                        //��s�Ϯѱ��ʥd�����x���ʥd���ʳ渹
                        if (dRow["PERIOD"].ToString().Trim() == "000000") //�b�ϮѸ̨�period�ȵ���O000000
                        {
                            Update_B_PURCARD(sPurchaseNo, dRow["ITEM"].ToString().Trim(), ParameterList[4].ToString().Trim(), DBT);
                        }
                        else
                        {
                            Update_PURCARD(sPurchaseNo, dRow["ITEM"].ToString().Trim(), dRow["PERIOD"].ToString().Trim(), ParameterList[4].ToString().Trim(), DBT);
                        }
                    }
                    #endregion

                    #region �s�W�����ث~���
                    if (GiftData != null)
                    {
                        foreach (DataRow gRow in GiftData.Rows)
                        {
                            CreatePurchaseOrderDetail(PID, ParameterList, gRow, DBT);

                            //��s�ث~�ݩ���(VDS_MKT_GIFT_PROFILE)��Ƥ�,�ӫ~�����O����f����B���ʤ�B���ʶq�P���ʳ渹
                            UpdateGiftProfile(gRow["ITEM"].ToString().Trim(), gRow["PERIOD"].ToString().Trim(), gRow["VIRTUAL_CODE"].ToString().Trim(),
                                              gRow["PLAN_ACCEPT_DATE"].ToString().Trim(), ParameterList[0].ToString().Trim(),
                                              gRow["PURCHASE_QTY"].ToString().Trim(), sPurchaseNo, ParameterList[4].ToString().Trim(), DBT);
                        }
                    }
                    #endregion

                    #region ������\
                    if (IsRootTranscation)
                    {
                        //�W�ߩI�sTranscation����
                        DBT.Commit();
                    }
                    #endregion
                    DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
                    sPurchaseNo = dbo.doQueryPurchase_NotByID(PID.ToString());
                }
                else
                {
                    throw new Exception("�s�W0�����!");
                }

                return sPurchaseNo;
            }
            catch (Exception ex)
            {
                #region �������
                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Rollback();
                }
                #endregion

                throw ex;
            }
            finally
            {
                #region �P�_�O�_��������s�u

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation,�����s�u
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }
                #endregion
            }
            #endregion
        }
        /// <summary>
        /// ��s VDS_MKT_PURCARD_MAIN.PUR_NO ����sBCO
        /// </summary>
        /// <param name="sPurchaseNo">���ʳ渹</param>
        /// <param name="sItem">�~��</param>
        /// <param name="sPeriod">���O</param>
        /// <param name="RootDBT">�O�_���D���,�L�D�����Jnull</param>
        /// <returns>�^�Ǧ��\�P�_</returns>
        public bool Update_PURCARD(string sPurchaseNo, string sItem, string sPeriod, string UpdateID, DbTransaction RootDBT)
        {
            bool IsRootTranscation = false;
            bool bResult = false;
            try
            {
                //�P�_�O�_���ǤJRoot Transcation
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region �Ұʥ���Ϋ��wRootTranscation

                if (IsRootTranscation)
                {
                    //�W�ߩI�s�Ұ�Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion

                DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
                dbo.doUpdatePurCard(sPurchaseNo, sItem, sPeriod, UpdateID, DBT);

                #region ������\

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Commit();
                }

                #endregion

                bResult = true;
                return bResult;
            }
            catch (Exception ex)
            {
                #region �������

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Rollback();
                }

                #endregion

                throw ex;
            }
            finally
            {
                #region �P�_�O�_��������s�u

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation,�����s�u
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }
        }
        /// <summary>
        /// Master ����sBCO
        /// </summary>
        /// <param name="ParameterList">��s�ܼ�</param>
        /// <param name="RootDBT">�O�_���D���,�L�D�����Jnull</param>
        /// <returns>�^�Ǧ��\�P�_</returns>
        public bool UpdatePUR_Master(ArrayList ParameterList,
            DbTransaction RootDBT,
            DataTable oldMaster)
        {
            bool IsRootTranscation = false;
            bool bResult = false;
            try
            {
                //�P�_�O�_���ǤJRoot Transcation
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region �Ұʥ���Ϋ��wRootTranscation

                if (IsRootTranscation)
                {
                    //�W�ߩI�s�Ұ�Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }

                #endregion

                DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
                dbo.doUpdateMaster(ParameterList, oldMaster.Rows[0], DBT);

                #region ������\

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Commit();
                }

                #endregion

                bResult = true;
                return bResult;
            }
            catch (Exception ex)
            {
                #region �������

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Rollback();
                }

                #endregion

                throw ex;
            }
            finally
            {
                #region �P�_�O�_��������s�u

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation,�����s�u
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }
        }
        public DataTable QuerySwitch(QueryType QT,
            ArrayList ParameterList
            )
        {
            DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
            DataTable Dt;

            try
            {
                switch (QT)
                {
                    //case QueryType.ALL:
                    //    Dt = dbo.doQueryAll();
                    //    break;
                    //case QueryType.CODE:
                    //    Dt = dbo.doQueryByCode(ParameterList);
                    //    break;
                    case QueryType.ID:
                        Dt = dbo.GetMasterByPK(ParameterList);
                        break;
                    case QueryType.Custom:
                        Dt = dbo.GetMainByWhere1(ParameterList);
                        break;
                    default:
                        Dt = new DataTable();
                        break;
                }

                return Dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// ��Master table �����װʧ@
        /// </summary>
        /// <param name="ParMasterList">��s�ܼ�</param>
        /// <param name="RootDBT">�O�_���D���,�L�D�����Jnull</param>
        /// <returns>�^�Ǽv�T����</returns>
        public void ClosePurchaseOrder(ArrayList ParMasterList,
            DataRow OldMasterRow,
            DbTransaction RootDBT
            )
        {
            bool IsRootTranscation = false;

            try
            {
                //�P�_�O�_���ǤJRoot Transcation
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region �Ұʥ���Ϋ��wRootTranscation
                if (IsRootTranscation)
                {
                    //�W�ߩI�s�Ұ�Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }
                #endregion

                DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
                dbo.doClosePurchaseOrder(ParMasterList, OldMasterRow, DBT);

                ArrayList Para = new ArrayList();
                Para.Clear();
                Para.Add(OldMasterRow["PURCHASE_NO"].ToString().Trim());
                Para.Add("M");
                Para.Add(ParMasterList[0].ToString());
                dbo.doCloseCaseDetailByPurNo(Para, DBT);

                #region ������\
                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Commit();
                }
                #endregion
            }
            catch (Exception ex)
            {
                #region �������
                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Rollback();
                }
                #endregion

                throw ex;
            }
            finally
            {
                #region �P�_�O�_��������s�u

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation,�����s�u
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }

                #endregion

            }
        }
 //public DataTable QueryPurchaseOrderByALL()
 //{
 //    try
 //    {
 //        DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
 //        return dbo.doQueryAll();
 //    }
 //    catch (Exception ex)
 //    {
 //        throw ex;
 //    }
 //}
 //public DataTable QueryPurchaseOrderByCode(ArrayList ParameterList)
 //{
 //    try
 //    {
 //        DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
 //        return dbo.doQueryByCode(ParameterList);
 //    }
 //    catch (Exception ex)
 //    {
 //        throw ex;
 //    }
 //}
 public DataTable QueryPurchaseOrderByLike(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.doQueryByLIKE(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public int Get_AcceptQty(ArrayList ParameterList)
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.doGet_AcceptQty(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void OpenPurchaseOrderDetail(ArrayList ParameterList, DbTransaction RootDBT)
        {
            bool IsRootTranscation = false;

            try
            {
                //�P�_�O�_���ǤJRoot Transcation
                IsRootTranscation = (RootDBT == null) ? true : false;

                #region �Ұʥ���Ϋ��wRootTranscation
                if (IsRootTranscation)
                {
                    //�W�ߩI�s�Ұ�Transcation
                    Conn = USEDB.CreateConnection();
                    Conn.Open();
                    DBT = Conn.BeginTransaction();
                }
                else
                {
                    DBT = RootDBT;
                }
                #endregion

                DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);

                dbo.doOpenPurchaseOrderDetail(ParameterList, DBT);

                #region ������\
                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Commit();
                }
                #endregion
            }
            catch (Exception ex)
            {
                #region �������
                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation����
                    DBT.Rollback();
                }
                #endregion

                throw ex;
            }
            finally
            {
                #region �P�_�O�_��������s�u

                if (IsRootTranscation)
                {
                    //�W�ߩI�sTranscation,�����s�u
                    if (Conn.State == ConnectionState.Connecting)
                    {
                        Conn.Close();
                    }
                }
                #endregion
            }
        }
 public DataTable QueryItemSchema()
 {
     try
     {
         DBO.OUT_PurchaseOrderDBO dbo = new OUT_PurchaseOrderDBO(ref USEDB);
         return dbo.doQueryItemSchema();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }