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

            try
            {
                switch (QT)
                {
                    case QueryType.ALL:
                        Dt = dbo.doQueryAll();
                        break;
                    case QueryType.ID:
                        Dt = dbo.doQueryByID(ParameterList);
                        break;
                    case QueryType.Custom:
                        Dt = dbo.doQueryByFind(ParameterList);
                        break;
                    default:
                        Dt = new DataTable();
                        break;
                }

                return Dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public DataTable QueryExpressItemDtlByLike(ArrayList ParameterList)
 {
     try
     {
         DBO.MKT_ExpressItemDtlDBO dbo = new MKT_ExpressItemDtlDBO(ref USEDB);
         return dbo.doQueryByLIKE(ParameterList);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public DataTable QueryExpressItemDtlByALL()
 {
     try
     {
         DBO.MKT_ExpressItemDtlDBO dbo = new MKT_ExpressItemDtlDBO(ref USEDB);
         return dbo.doQueryAll();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// 測試SP交易失敗
        /// </summary>
        /// <param name="ParameterList">變數</param>
        /// <param name="RootDBT">是否有主交易,無主交易輸入null</param>
        public void TestTranscation(ArrayList ParameterList1,
                                    ArrayList ParameterList2,
                                    ArrayList ParameterList3,
                                    DbTransaction RootDBT
                                    )
        {
            bool IsRootTranscation = false;

            try
            {
                DBO.MKT_ExpressItemDtlDBO dbo = new MKT_ExpressItemDtlDBO(ref USEDB);

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

                #region 啟動交易或指定RootTranscation

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

                #endregion

                dbo.doCreate(ParameterList1, DBT);

                dbo.doUpdate(ParameterList2, DBT);

                dbo.doDelete(ParameterList3, DBT);

                throw new Exception("交易失敗");

                #region 交易成功

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

                #endregion

            }
            catch (Exception ex)
            {
                #region 交易失敗

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

                #endregion

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

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

                #endregion
            }

        }
Ejemplo n.º 5
0
        public void DeleteMainDetail(ArrayList ParameterList, DataTable Dt_Detail, DbTransaction RootDBT)
        {
            bool IsRootTranscation = false;

            DBO.MKT_ExpressItemDBO dboM = new MKT_ExpressItemDBO(ref USEDB);
            DBO.MKT_ExpressItemDtlDBO dboD = new MKT_ExpressItemDtlDBO(ref USEDB);
            ArrayList ALD = new ArrayList();

            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

                dboM.DeleteMain(ParameterList, DBT);

                for (int i = 0; i < Dt_Detail.Rows.Count; i++)
                {
                    ALD.Clear();

                    ALD.Add(Dt_Detail.Rows[i]["ID"]);
                    ALD.Add(Dt_Detail.Rows[i]["PID"]);
                    ALD.Add(Dt_Detail.Rows[i]["UPDATEDATE"]);
                    ALD.Add(Dt_Detail.Rows[i]["UPDATEUID"]);
                    ALD.Add(ParameterList[3]);

                    dboD.DeleteDetail(ALD, DBT);
                }
                

                #region 交易成功

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

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

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

                #endregion

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

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

                #endregion
            }
        }
Ejemplo n.º 6
0
        public void UpdateMainDetail(DataTable Dt_Main, DataTable Dt_Detail, DbTransaction RootDBT,string strMode,out int intMainID,out int intDetailID)
        {
            bool IsRootTranscation = false;

            intMainID = 0;
            intDetailID = 0;

            DBO.MKT_ExpressItemDBO dboM = new MKT_ExpressItemDBO(ref USEDB);
            DBO.MKT_ExpressItemDtlDBO dboD = new MKT_ExpressItemDtlDBO(ref USEDB);
            ArrayList ALD = new ArrayList();

            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

                DataTable DtM_A = Dt_Main.GetChanges(DataRowState.Added);
                DataTable DtM_M = Dt_Main.GetChanges(DataRowState.Modified);
                DataTable DtM_D = Dt_Main.GetChanges(DataRowState.Deleted);

                DataTable DtD_A = Dt_Detail.GetChanges(DataRowState.Added);
                DataTable DtD_M = Dt_Detail.GetChanges(DataRowState.Modified);
                DataTable DtD_D = Dt_Detail.GetChanges(DataRowState.Deleted);

                if (DtM_A != null)
                {
                    for (int i = 0; i < DtM_A.Rows.Count; i++)
                    {
                        ALD.Clear();

                        ALD.Add(DtM_A.Rows[i]["NAME",DataRowVersion.Current].ToString());
                        ALD.Add(DtM_A.Rows[i]["CREATEUID", DataRowVersion.Current].ToString());
                        ALD.Add(DtM_A.Rows[i]["UPDATEUID", DataRowVersion.Current].ToString());
                        ALD.Add(DtM_A.Rows[i]["SET_QTY", DataRowVersion.Current].ToString());
                        ALD.Add(DtM_A.Rows[i]["ITEM", DataRowVersion.Current].ToString());

                        dboM.InsertMain(ALD, DBT, out intMainID);
                    }
                    DtM_A.Clear();
                }

                

                if (DtM_M != null)
                {
                    for (int i = 0; i < DtM_M.Rows.Count; i++)
                    {
                        ALD.Clear();

                        ALD.Add(DtM_M.Rows[i]["ID",DataRowVersion.Original].ToString());
                        ALD.Add(DtM_M.Rows[i]["UPDATEDATE", DataRowVersion.Original]);
                        ALD.Add(DtM_M.Rows[i]["UPDATEUID", DataRowVersion.Original].ToString());
                        ALD.Add(DtM_M.Rows[i]["UPDATEUID", DataRowVersion.Current].ToString());
                        ALD.Add(DtM_M.Rows[i]["SET_QTY", DataRowVersion.Current]);

                        dboM.UpdateMain(ALD, DBT);
                    }

                    DtM_M.Clear();
                }

                if (DtM_D != null)
                {
                    for (int i = 0; i < DtM_D.Rows.Count; i++)
                    {
                        ALD.Clear();

                        ALD.Add(DtM_D.Rows[i]["ID",DataRowVersion.Original]);
                        ALD.Add(DtM_D.Rows[i]["UPDATEDATE", DataRowVersion.Original]);
                        ALD.Add(DtM_D.Rows[i]["UPDATEUID", DataRowVersion.Original]);
                        ALD.Add(DtM_D.Rows[i]["UPDATEUID", DataRowVersion.Current]);

                        dboM.DeleteMain(ALD, DBT);
                    }

                    DtM_D.Clear();
                }

                if (DtD_A != null)
                {
                    for (int i = 0; i < DtD_A.Rows.Count; i++)
                    {
                        ALD.Clear();

                        switch (strMode)
                        { 
                            case "new":
                                ALD.Add(intMainID);
                                break;
                            case "edit":
                                ALD.Add(Dt_Main.Rows[0]["ID"]);
                                break;
                        }
                        
                        ALD.Add(DtD_A.Rows[i]["CREATEUID",DataRowVersion.Current].ToString());
                        ALD.Add(DtD_A.Rows[i]["UPDATEUID", DataRowVersion.Current].ToString());
                        ALD.Add(DtD_A.Rows[i]["CHAN_NO", DataRowVersion.Current].ToString());
                        ALD.Add(DtD_A.Rows[i]["STORE", DataRowVersion.Current].ToString());

                        dboD.InsertDetail(ALD, DBT, out intDetailID);
                    }
                    DtD_A.Clear();
                }

                if (DtD_D != null)
                {
                    for (int i = 0; i < DtD_D.Rows.Count; i++)
                    {
                        ALD.Clear();

                        ALD.Add(DtD_D.Rows[i]["ID",DataRowVersion.Original]);
                        ALD.Add(DtD_D.Rows[i]["PID", DataRowVersion.Original]);
                        ALD.Add(DtD_D.Rows[i]["UPDATEDATE", DataRowVersion.Original]);
                        ALD.Add(DtD_D.Rows[i]["UPDATEUID", DataRowVersion.Original].ToString());
                        ALD.Add(Dt_Main.Rows[0]["UPDATEUID"].ToString());

                        dboD.DeleteDetail(ALD, DBT);
                    }
                    DtD_D.Clear();
                }

                if (DtD_M != null)
                {
                    for (int i = 0; i < DtD_M.Rows.Count; i++)
                    {
                        ALD.Clear();

                        ALD.Add(DtD_M.Rows[i]["ID", DataRowVersion.Original]);
                        ALD.Add(DtD_M.Rows[i]["PID", DataRowVersion.Original]);
                        ALD.Add(DtD_M.Rows[i]["UPDATEDATE", DataRowVersion.Original]);
                        ALD.Add(DtD_M.Rows[i]["UPDATEUID", DataRowVersion.Original].ToString());
                        ALD.Add(DtD_M.Rows[i]["PID",DataRowVersion.Current].ToString());
                        ALD.Add(DtD_M.Rows[i]["UPDATEUID", DataRowVersion.Current].ToString());
                        ALD.Add(DtD_M.Rows[i]["CHAN_NO", DataRowVersion.Current].ToString());
                        ALD.Add(DtD_M.Rows[i]["STORE", DataRowVersion.Current].ToString());

                        dboD.UpdateDetail(ALD, DBT);
                    }
                    DtD_M.Clear();
                }

                #region 交易成功

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

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

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

                #endregion

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

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

                #endregion
            }
        }