Пример #1
0
        private void ubtDelete_Click(object sender, EventArgs e)
        {

            try
            {
                clsSounds.fnPlay("Click");
                usbStatus.Panels[0].Text = clsGeneral.fnGetControlCaption(this, "usbStatus.Deleting");
                usbStatus.Refresh();

                if (lvwGrid.SelectedItems.Count > 0)
                {

                    // Play defined sound
                    clsSounds.fnPlay("Attention");

                    if (MessageBox.Show(clsGeneral.fnGetControlCaption(this, "msgDelete.Confirm"), clsGeneral.fnGetControlCaption(this, "msgDelete.Header"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {

                        Database objDatabase = new Database();
                        oConnection = (Object)objDatabase.oConnection;

                        // Instantiate BE class
                        BankBE objBE = new BankBE();

                        // Fill BE class properties
                        objBE.oConnection = oConnection;
                        objBE.nBank = Int32.Parse(lvwGrid.SelectedItems[0].Text);

                        // Instantiate Business class
                        Bank objBusiness = new Bank();

                        // Fill Business class properties
                        objBusiness.ObjBankBE = objBE;

                        // Fill Grid

                        // Try delete record
                        // If there wasn't an error
                        if (objBusiness.fnDeleteBank() == 0)
                        {
                            // Get selected index on datatable and listview to delete
                            int nSelectedIndex = lvwGrid.SelectedItems[0].Index;
                            int nSelectedRecord = nSelectedIndex + (nRecordsOnPage * (nCurrentPage - 1));

                            // Get DataTable records
                            DataRowCollection rc = dtGrid.Rows;

                            // Delete record from datatable
                            rc[nSelectedRecord].Delete();
                            dtGrid.AcceptChanges();

                            // Remove record from listview
                            lvwGrid.Items.Remove(lvwGrid.SelectedItems[0]);

                            // If there aren't record on listview
                            if (lvwGrid.Items.Count == 0)
                            {
                                // Return to previous page
                                fnPaginateGrid(Navigation.Previous);
                            }
                            else
                            {
                                // Stand on same page
                                fnPaginateGrid(Navigation.Same);
                            }

                            // If there are record on listview
                            if (lvwGrid.Items.Count > 0)
                            {
                                // Select next record on listview
                                lvwGrid.Items[nSelectedIndex - 1].Selected = true;
                                lvwGrid.Select();
                                lvwGrid.Focus();
                                lvwGrid_Click(null, null);
                            }
                            else
                            {
                                // Clean all fields on screen
                                ubtNew_Click(null, null);
                            }

                            clsSounds.fnPlay("Deleted");

                        }

                    }

                    else
                    {
                        lvwGrid.Items[lvwGrid.SelectedItems[0].Index].Selected = true;
                        lvwGrid.Select();
                        lvwGrid.Focus();
                    }
                }
                else
                {
                    // Play defined sound
                    clsSounds.fnPlay("Error");

                    clsGeneral.fnMessageBox(clsGeneral.fnGetControlCaption(this, "msgDelete.NoRecord"), clsGeneral.fnGetControlCaption(this, "msgDelete.Header"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                usbStatus.Panels[0].Text = clsGeneral.fnGetControlCaption(this, "usbStatus.Ready");

            }

            catch (Exception ex)
            {

                // Play defined sound
                clsSounds.fnPlay("Error");

                // Show exception in a message box
                clsGeneral.fnException(this, ex);

            }

        }
Пример #2
0
         private void ubtSave_Click(object sender, EventArgs e)
        {

            try
            {
                clsSounds.fnPlay("Click");
                usbStatus.Panels[0].Text = clsGeneral.fnGetControlCaption(this, "usbStatus.Saving");
                usbStatus.Refresh();

                int nSelectedRecord = 0;
                int nSelectedIndex = 0;

                // Case edit item
                if (lvwGrid.SelectedItems.Count > 0)
                {
                    // Get selected index on datatable and listview to delete
                    nSelectedIndex = lvwGrid.SelectedItems[0].Index;
                    nSelectedRecord = nSelectedIndex + (nRecordsOnPage * (nCurrentPage - 1));
                }

                switch (sOpenedMenuItem)
                {

                    case "CadastreBank":
                        {

                            frmCadastreBank _frmCadastreBank = (frmCadastreBank)this._form;

                            if (fnValidateEmpty(_frmCadastreBank.txtCode, _frmCadastreBank.txtDescription) == true)
                            {
                                Database objDatabase = new Database();
                                oConnection = (Object)objDatabase.oConnection;

                                // Instantiate BE class
                                BankBE objBE = new BankBE();

                                // Fill BE class properties
                                objBE.oConnection = oConnection;
                                objBE.nBank = Int32.Parse(_frmCadastreBank.txtCode.Text);
                                objBE.sBank = _frmCadastreBank.txtDescription.Text;

                                // Instantiate Business class
                                Bank objBusiness = new Bank();

                                // Fill Business class properties
                                objBusiness.ObjBankBE = objBE;

                                // Fill Grid

                                // Try delete record
                                // If there wasn't an error
                                Int32 nResult = objBusiness.fnSaveBank();

                                if (nResult > 1)
                                {

                                    // Get datatable records
                                    switch (nResult)
                                    {
                                        // Added
                                        case 3:
                                            {
                                                DataRow dr = dtGrid.NewRow();

                                                dr[0] = objBE.nBank;
                                                dr[1] = objBE.sBank;

                                                // Add record to datatable
                                                dtGrid.Rows.Add(dr);

                                                // Go to last page
                                                fnPaginateGrid(Navigation.Last);

                                                // Select last register - added register
                                                lvwGrid.Items[lvwGrid.Items.Count - 1].Selected = true;
                                                lvwGrid.Select();

                                                clsSounds.fnPlay("Added");

                                                break;
                                            }

                                        // Updated
                                        case 2:
                                            {

                                                DataRow dr = dtGrid.Rows[nSelectedRecord];

                                                // Update datatable
                                                dr[0] = objBE.nBank;
                                                dr[1] = objBE.sBank;

                                                // Update record on datatable
                                                dtGrid.AcceptChanges();

                                                // Update listview
                                                lvwGrid.Items[nSelectedIndex].SubItems[1].Text = objBE.sBank;

                                                // Select updated record
                                                lvwGrid.Items[nSelectedIndex].Selected = true;
                                                lvwGrid.Select();

                                                clsSounds.fnPlay("Updated");

                                                break;
                                            }

                                        // Error
                                        default:
                                            {
                                                // Play defined sound
                                                clsSounds.fnPlay("Error");

                                                clsGeneral.fnMessageBox(clsGeneral.fnGetControlCaption(this, "msgSave.Error"), clsGeneral.fnGetControlCaption(this, "msgSave.Header"), MessageBoxButtons.OK, MessageBoxIcon.Error);

                                                break;
                                            }
                                    }


                                }

                            }

                            break;

                        }

                }

                usbStatus.Panels[0].Text = clsGeneral.fnGetControlCaption(this, "usbStatus.Ready");

            }

            catch (Exception ex)
            {

                // Play defined sound
                clsSounds.fnPlay("Error");

                // Show exception in a message box
                clsGeneral.fnException(this, ex);

            }

        }
Пример #3
0
        public void fnGridPopulate(params object[] args)
        {

            try
            {
                String sCaption = "";
                String sParameters = "";

                for (int i = 1; i < args.GetLength(0) + 1; i++)
                {

                    if (i == 1)
                    {
                        sCaption = (String)args[i - 1];
                    }

                    else
                    {
                        sParameters += (String)args[i - 1];
                    }

                }

                switch (sCaption.Substring(3, sCaption.Length - 3))
                {

                    case "CadastreBank":

                        Database objDatabase = new Database();
                        oConnection = (Object)objDatabase.oConnection;

                        // Instantiate BE class
                        BankBE objBE = new BankBE();

                        // Fill BE class properties
                        objBE.oConnection = oConnection;

                        if (sParameters != "")
                        {
                            objBE.sSearchCommand = sParameters;
                        }

                        // Instantiate Business class
                        Bank objBusiness = new Bank();

                        // Fill Business class properties
                        objBusiness.ObjBankBE = objBE;

                        // Fill Grid

                        // Create datatable with same structure of returned datatable by fill grid function

                        if (sParameters == "")
                        {
                            dtGrid = objBusiness.fnGetBank();
                        }
                        else
                        {
                            dtGrid = objBusiness.fnSearchBank();
                        }

                        fnPaginateGrid(Navigation.First);

                        break;

                }

            }

            catch (Exception ex)
            {

                // Play defined sound
                clsSounds.fnPlay("Error");

                // Show exception in a message box
                clsGeneral.fnException(this, ex);

            }

        }