Esempio n. 1
0
 public override bool DeleteData()
 {
     try
     {
         //找出目前的使用者記錄的物件
         var rowUsers = (XINUsers)(xINUsersBindingSource.Current);
         if (rowUsers != null)
         {
             if (!rowUsers.UserAuthority.IsLoaded)
             {
                 rowUsers.UserAuthority.Load();
             }
             //刪除使用者記錄
             context.DeleteObject(rowUsers);
             //更新資料
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //秀出錯誤訊息
         MessageBox.Show(ex.Message, "刪除錯誤",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     PrimaryID = employeeNoTextBox.Text;
     return(true);
 }
Esempio n. 2
0
        public override bool DeleteData()
        {
            //建立交易物件
            DbTransaction db;

            //如果ObjectContext類別的連接物件未開啟,就把它給開啟
            if (context.Connection.State != ConnectionState.Open)
            {
                context.Connection.Open();
            }
            //開啟交易
            db = context.Connection.BeginTransaction();
            try
            {
                //找出目前的存貨異動單記錄的物件
                var rowDelivery = (Transfer)(transferBindingSource.Current);
                if (rowDelivery != null)
                {
                    //刪除存貨異動單明細記錄
                    if (rowDelivery.TransferDetails.Count != 0)
                    {
                        context.DeleteObject(rowDelivery.TransferDetails.First());
                    }
                    //刪除存貨異動單記錄
                    context.DeleteObject(rowDelivery);
                    //更新資料
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                //回復交易
                db.Rollback();
                //秀出錯誤訊息
                MessageBox.Show(ex.Message, "刪除錯誤",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            PrimaryID = transferIDLabel.Text;
            //確認交易
            db.Commit();
            return(true);
        }
Esempio n. 3
0
 public override bool DeleteData()
 {
     try
     {
         //找出目前的客戶記錄的物件
         var rowCustomer = (Customer)(customerBindingSource.Current);
         if (rowCustomer != null)
         {
             //刪除客戶記錄
             context.DeleteObject(rowCustomer);
             //更新資料
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //秀出錯誤訊息
         MessageBox.Show(ex.Message, "刪除錯誤",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     PrimaryID = customerIDTextBox.Text;
     return(true);
 }
Esempio n. 4
0
 public override bool DeleteData()
 {
     try
     {
         //找出目前的商品記錄的物件
         var rowProduct = (Product)(productBindingSource.Current);
         if (rowProduct != null)
         {
             //刪除商品記錄
             context.DeleteObject(rowProduct);
             //更新資料
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //秀出錯誤訊息
         MessageBox.Show(ex.Message, "刪除錯誤",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     PrimaryID = productIDTextBox.Text;
     return(true);
 }