Beispiel #1
0
 private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (SCMS.CurrentSystemUser != null)
     {
         if (SCMS.CurrentSystemUser.IsSignedIn)
         {
             e.Cancel = VisualBasic.CBool(MsgBoxEx.Ask("Quit from the application?", "Exit") != System.Windows.Forms.DialogResult.Yes);
             if (!e.Cancel)
             {
                 SCMS.CleanUp(); SCMS.CurrentSystemUser.LogOut();
                 SCMS.CurrentSystemUser = null; SCMS.Connection = null;
                 Application.Exit();
             }
             else
             {
                 _isclosing = false;
             }
         }
         else
         {
             Program.StartUpForm.Show();
         }
     }
     else
     {
         if (!e.Cancel)
         {
             SCMS.CleanUp();   SCMS.Connection = null; Application.Exit();
         }
     }
 }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!btnDelete.Enabled)
            {
                return;
            }
            if (!grdScripts.Redraw)
            {
                return;
            }
            if (grdScripts.DataSource == null)
            {
                return;
            }
            if (grdScripts.RowSel < (grdScripts.Rows.Fixed))
            {
                return;
            }

            string _referenceno = grdScripts[grdScripts.RowSel, "ReferenceNo"].ToString();

            if (MsgBoxEx.Ask("Delete script: <font color=\"blue\">" + _referenceno + "</font> from the scipts list permanently?", "Delete Script") != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            string _query = "DELETE FROM `scripts` WHERE (`ReferenceNo` LIKE '" + _referenceno.ToSqlValidString() + "');";

            Cursor = Cursors.WaitCursor;

            IAsyncResult _result = Que.BeginExecution(SCMS.Connection, _query);

            while (!_result.IsCompleted &&
                   !_cancelled)
            {
                Thread.Sleep(1); Application.DoEvents();
            }

            if (_cancelled)
            {
                if (!_result.IsCompleted)
                {
                    try { _result = null; }
                    catch { }
                    finally { Materia.RefreshAndManageCurrentProcess(); }
                }

                return;
            }
            else
            {
                QueResult _queresult = Que.EndExecution(_result);
                if (string.IsNullOrEmpty(_queresult.Error.RLTrim()))
                {
                    Cursor = Cursors.WaitCursor;
                    IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.Delete, "Deleted script : " + _referenceno + " from the database script list.", _referenceno);
                    _logresult.WaitToFinish(); Cursor = Cursors.Default;

                    DataTable _datasource = null;

                    try { _datasource = (DataTable)grdScripts.DataSource; }
                    catch { }

                    if (_datasource != null)
                    {
                        if (grdScripts.Redraw)
                        {
                            grdScripts.BeginUpdate();
                        }

                        DataRow[] _rows = _datasource.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                        if (_rows.Length > 0)
                        {
                            System.Collections.IEnumerator _enumerators = _rows.GetEnumerator();
                            while (_enumerators.MoveNext())
                            {
                                ((DataRow)_enumerators.Current).Delete();
                            }
                            _datasource.AcceptChanges();
                        }

                        DataTable _scripts = Cache.GetCachedTable("scripts");
                        if (_scripts != null)
                        {
                            DataRow[] _syncrows = _scripts.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                            System.Collections.IEnumerator _enumerators = _syncrows.GetEnumerator();
                            while (_enumerators.MoveNext())
                            {
                                ((DataRow)_enumerators.Current).Delete();
                            }
                            Cache.Save();
                        }

                        FormatGrid(); ResizeGrid();

                        while (!grdScripts.Redraw)
                        {
                            grdScripts.EndUpdate();
                        }
                        EnableButtons(); DisplayInfo();
                    }
                }
                else
                {
                    SCMS.LogError(this.GetType().Name, new Exception(_queresult.Error));
                    MsgBoxEx.Alert("Failed to permanently delete the specified database script.", "Deletion Failed");
                }

                _queresult.Dispose(); Materia.RefreshAndManageCurrentProcess();
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!btnDelete.Enabled)
            {
                return;
            }
            if (!grdUsers.Redraw)
            {
                return;
            }
            if (grdUsers.DataSource == null)
            {
                return;
            }
            if (grdUsers.RowSel < grdUsers.Rows.Fixed)
            {
                return;
            }

            string _username      = grdUsers[grdUsers.RowSel, "Username"].ToString();
            string _accountholder = grdUsers[grdUsers.RowSel, "FullName"].ToString();

            if (_username == SCMS.CurrentSystemUser.Username)
            {
                MsgBoxEx.Shout("System does not allow to remove your own user account.", "Delete User Account"); return;
            }

            if (MsgBoxEx.Ask("Do you really want to remove <font color=\"blue\">" + _accountholder + " (" + _username + ")</font> from the user<br />account list?<br /><br /><b>Note :</b> If account has historical data along with it, user account will<br />not be removed permanently to retain historical logs of the account.", "Delete User Account") != System.Windows.Forms.DialogResult.Yes)
            {
                return;
            }

            string _query = "DELETE FROM `users` WHERE (`Username` LIKE '" + _username.ToSqlValidString() + "');";

            btnAdd.Enabled     = false; btnEdit.Enabled = false; btnDelete.Enabled = false;
            btnRefresh.Enabled = false; txtSearch.Enabled = false;

            Cursor = Cursors.WaitCursor;
            IAsyncResult _delresult = Que.BeginExecution(SCMS.Connection, _query);

            while (!_delresult.IsCompleted &&
                   !_cancelled)
            {
                Thread.Sleep(1); Application.DoEvents();
            }

            if (_cancelled)
            {
                if (!_delresult.IsCompleted)
                {
                    try { _delresult = null; }
                    catch { }
                    finally { Materia.RefreshAndManageCurrentProcess(); }
                }

                return;
            }
            else
            {
                QueResult _result = Que.EndExecution(_delresult);
                if (string.IsNullOrEmpty(_result.Error.RLTrim()))
                {
                    IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.Delete, "Removed " + _accountholder + " (" + _username + ") from the user accounts list.");
                    _logresult.WaitToFinish();

                    DataTable _datasource = null;

                    try { _datasource = (DataTable)grdUsers.DataSource; }
                    catch { }

                    if (_datasource != null)
                    {
                        DataRow[] _rows = _datasource.Select("[Username] LIKE '" + _username.ToSqlValidString(true) + "'");
                        if (_rows.Length > 0)
                        {
                            if (grdUsers.Redraw)
                            {
                                grdUsers.BeginUpdate();
                            }

                            _rows[0].Delete();
                            _datasource.AcceptChanges();
                            FormatGrid(); ResizeGrid();

                            DataTable _users = Cache.GetCachedTable("users");
                            if (_users != null)
                            {
                                DataRow[] _delusers = _users.Select("[Username] LIKE '" + _username.ToSqlValidString(true) + "'");
                                System.Collections.IEnumerator _delenums = _delusers.GetEnumerator();
                                while (_delenums.MoveNext())
                                {
                                    ((DataRow)_delenums.Current).Delete();
                                }
                                _users.AcceptChanges(); Cache.Save();
                            }

                            while (!grdUsers.Redraw)
                            {
                                grdUsers.EndUpdate();
                            }
                            DisplayInfo();
                        }
                    }
                }
                else
                {
                    _query = "UPDATE `users` SET\n" +
                             "`Voided` = 1, `DateVoided` = NOW()\n" +
                             "WHERE\n" +
                             "(`Username` LIKE '" + _username.ToSqlValidString(true) + "');";

                    Cursor     = Cursors.WaitCursor;
                    _delresult = null; Materia.RefreshAndManageCurrentProcess();
                    _delresult = Que.BeginExecution(SCMS.Connection, _query);
                    while (!_delresult.IsCompleted &&
                           !_cancelled)
                    {
                        Thread.Sleep(1); Application.DoEvents();
                    }

                    if (_cancelled)
                    {
                        if (!_delresult.IsCompleted)
                        {
                            try { _delresult = null; }
                            catch { }
                            finally { Materia.RefreshAndManageCurrentProcess(); }
                        }

                        return;
                    }
                    else
                    {
                        _result.Dispose(); Materia.RefreshAndManageCurrentProcess();
                        _result = Que.EndExecution(_delresult);
                        if (string.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.Delete, "Removed " + _accountholder + " (" + _username + ") from the user accounts list.");
                            _logresult.WaitToFinish();

                            DataTable _datasource = null;

                            try { _datasource = (DataTable)grdUsers.DataSource; }
                            catch { }

                            if (_datasource != null)
                            {
                                DataRow[] _rows = _datasource.Select("[Username] LIKE '" + _username.ToSqlValidString(true) + "'");
                                if (_rows.Length > 0)
                                {
                                    if (grdUsers.Redraw)
                                    {
                                        grdUsers.BeginUpdate();
                                    }

                                    _rows[0].Delete();
                                    _datasource.AcceptChanges();
                                    FormatGrid(); ResizeGrid();

                                    DataTable _users = Cache.GetCachedTable("users");
                                    if (_users != null)
                                    {
                                        DataRow[] _delusers = _users.Select("[Username] LIKE '" + _username.ToSqlValidString(true) + "'");
                                        System.Collections.IEnumerator _delenums = _delusers.GetEnumerator();
                                        while (_delenums.MoveNext())
                                        {
                                            ((DataRow)_delenums.Current).Delete();
                                        }
                                        _users.AcceptChanges(); Cache.Save();
                                    }

                                    while (!grdUsers.Redraw)
                                    {
                                        grdUsers.EndUpdate();
                                    }
                                    DisplayInfo();
                                }
                            }
                        }
                        else
                        {
                            SCMS.LogError(this.GetType().Name, new Exception(_result.Error));
                            MsgBoxEx.Alert("Failed to remove the specified user account from the list.", "Delete User Account");
                        }
                    }
                }

                _result.Dispose(); EnabledButtons();
            }

            Cursor = Cursors.Default;
        }
Beispiel #4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (!btnDelete.Enabled)
            {
                return;
            }
            if (!grdStockAdjustments.Redraw)
            {
                return;
            }
            if (grdStockAdjustments.DataSource == null)
            {
                return;
            }
            if (grdStockAdjustments.RowSel < grdStockAdjustments.Rows.Fixed)
            {
                return;
            }
            if (Materia.IsNullOrNothing(grdStockAdjustments[grdStockAdjustments.RowSel, "ReferenceNo"]))
            {
                return;
            }

            string    _referenceno      = grdStockAdjustments[grdStockAdjustments.RowSel, "ReferenceNo"].ToString();
            DataTable _stockadjustments = Cache.GetCachedTable("stockadjustments");

            if (_stockadjustments != null)
            {
                DataRow[] _rows = _stockadjustments.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                if (_rows.Length > 0)
                {
                    DataRow _row = _rows[0];
                    if (VisualBasic.IsNumeric(_row["Closed"]))
                    {
                        if (VisualBasic.CBool(_row["Closed"]))
                        {
                            MsgBoxEx.Shout("Cannot delete stock adjustment : <font color=\"blue\">" + _referenceno + "</font> because it is already marked as final.", "Delete Stock Adjustment");
                            return;
                        }
                    }

                    if (MsgBoxEx.Ask("Delete stock adjustment <font color=\"blue\">" + _referenceno + "</font> permanently from the list?", "Delete Stock Adjustments") != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }

                    string       _query      = "DELETE FROM `stockadjustments` WHERE (`ReferenceNo` LIKE '" + _referenceno.ToSqlValidString(true) + "')";
                    IAsyncResult _execresult = Que.BeginExecution(SCMS.Connection, _query);

                    btnNew.Enabled     = false; btnEdit.Enabled = false; btnDelete.Enabled = false;
                    btnRefresh.Enabled = false; txtSearch.Enabled = false;

                    while (!_execresult.IsCompleted &&
                           !_cancelled)
                    {
                        Thread.Sleep(1); Application.DoEvents();
                    }

                    if (_cancelled)
                    {
                        if (!_execresult.IsCompleted)
                        {
                            try { _execresult = null; }
                            catch { }
                            finally { Materia.RefreshAndManageCurrentProcess(); }
                        }

                        return;
                    }
                    else
                    {
                        QueResult _result = Que.EndExecution(_execresult);
                        if (string.IsNullOrEmpty(_result.Error.RLTrim()))
                        {
                            _row.Delete(); _stockadjustments.AcceptChanges();

                            if (grdStockAdjustments.Redraw)
                            {
                                grdStockAdjustments.BeginUpdate();
                            }

                            DataTable _datasource = null;

                            try { _datasource = (DataTable)grdStockAdjustments.DataSource; }
                            catch { }

                            if (_datasource != null)
                            {
                                DataRow[] _currows = _datasource.Select("[ReferenceNo] LIKE '" + _referenceno.ToSqlValidString(true) + "'");
                                if (_currows.Length > 0)
                                {
                                    _currows[0].Delete();
                                }
                                _datasource.AcceptChanges();
                            }

                            FormatGrid(); ResizeGrid();

                            Cursor = Cursors.WaitCursor;
                            IAsyncResult _logresult = SCMS.CurrentSystemUser.LogActionAsync(UserAction.Delete, "Deletes stock adjustment : " + _referenceno + ".", _referenceno);
                            _logresult.WaitToFinish(); Cursor = Cursors.Default;

                            while (!grdStockAdjustments.Redraw)
                            {
                                grdStockAdjustments.EndUpdate();
                            }
                        }
                        else
                        {
                            SCMS.LogError(this.GetType().Name, new Exception(_result.Error));
                            MsgBoxEx.Alert("Failed to delete the specified stock adjustment.", "Delete Stock Adjustment");
                        }

                        _result.Dispose(); EnableButtons(); DisplayInfo();
                    }
                }
            }
        }