Esempio n. 1
0
        /// <summary>
        /// 刪除主表記錄 function
        /// </summary>
        /// <returns></returns>
        //waitfix:交易及檢查未處理
        protected override Boolean WfToolbarDelete()
        {
            DataTable dtMasterOld;
            int       activeIndex = -1;

            try
            {
                if (WfPreDeleteCheck(DrMaster) == false)
                {
                    return(false);
                }

                var result = WfShowConfirmMsg("是否確定要刪除資料 ?");

                if (result != DialogResult.Yes)
                {
                    return(true);
                }
                //記錄原來的 GridRow index
                if (this.uGridMaster.ActiveRow != null)
                {
                    activeIndex = this.uGridMaster.ActiveRow.Index;
                }
                else
                {
                    activeIndex = -1;
                }

                //複製要刪除的資料
                dtMasterOld = DrMaster.Table.Clone();
                dtMasterOld.ImportRow(DrMaster);

                if (TabMaster.CanUseRowLock == true)
                {
                    if (WfLockMasterRow() == false)
                    {
                        return(false);
                    }
                }
                else
                if (WfBeginTran() == false)
                {
                    return(false);
                }

                WfSetBllTransaction();

                //主檔與明細檔的額外資料要在此先做處理
                if (WfDeleteAppenUpdate(dtMasterOld.Rows[0]) == false)
                {
                    WfRollback();
                    return(false);
                }
                DrMaster.Delete();
                this.TabMaster.BoBasic.OfUpdate(BoMaster.TRAN, DrMaster.Table);

                #region 如果已無定位在下一筆 Row
                if (this.TabMaster.DtSource.Rows.Count != 0)
                {
                    if (uGridMaster.Rows.Count == 1)
                    {
                        uGridMaster.ActiveRow = uGridMaster.Rows[0];
                    }
                    else
                    {
                        if (activeIndex < 0)
                        {
                            WfActiveGridNextRow(this.uGridMaster, 9999);
                        }
                        else
                        {
                            WfActiveGridNextRow(this.uGridMaster, activeIndex);
                        }
                    }
                }
                #endregion

                TabMaster.DtSource.AcceptChanges();
                WfCommit();
                //加入這一段,統一將節點移至root---------開始
                uTree.Enabled = true;
                if (DrMaster != null)
                {
                    uTree.ActiveNode = uTree.GetNodeByKey(DrMaster["gba01"].ToString());
                }
                else
                {
                    uTree.ActiveNode = uTree.GetNodeByKey("root");
                }
                //加入這一段,統一將節點移至root----------結束

                return(true);
            }
            catch (Exception ex)
            {
                WfRollback();
                throw ex;
            }
            finally
            {
                this.IsChanged = false;
            }
        }