Exemplo n.º 1
0
        private void frmSearch_Load(object sender, EventArgs e)
        {
            String sItem = "";

            // Bind datatable to listview
            lvwGrid.Items.Clear();
            lvwGrid.Columns.Clear();

            // Create header columns
            for (int iCol = 0; iCol < 3; iCol++)
            {
                System.Windows.Forms.ColumnHeader ch = new System.Windows.Forms.ColumnHeader();

                switch (iCol)
                {
                    case 0: ch.Text = clsGeneral.fnGetControlCaption(this, "lvwGrid-Field"); break;
                    case 1: ch.Text = clsGeneral.fnGetControlCaption(this, "lvwGrid-Operation"); break;
                    case 2: ch.Text = clsGeneral.fnGetControlCaption(this, "lvwGrid-Value"); break;
                }

                lvwGrid.Columns.Add(ch);

            }

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

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

            // Fill BE class properties
            objBE.oConnection  = oConnection;
            objBE.sItem = GlobalBE.sOpenedItem;

            // Instantiate Business class
            StudioByte.StudioMoney.Main.Business.Main objBusiness = new StudioByte.StudioMoney.Main.Business.Main();

            // Fill Business class properties
            objBusiness.ObjMainBE = objBE;
            
            // Fill field combobox
            uceField.Items.Add(0, clsGeneral.fnGetControlCaption(this, "uceField"));

            switch (GlobalBE.sOpenedItem)
            {

                case "utsMainBank":
                    {
                        sItem = "-Bank"; break;
                    }

            }

            foreach (DataRow dr in objBusiness.fnGetFields().Rows) {

                uceField.Items.Add(dr["W_NOBJECT"].ToString(), clsGeneral.fnGetControlCaption("frmMain", "lbl" + dr["W_SOBJECT"].ToString().Substring(3) + sItem));

            }

            uceField.SelectedIndex = 0;

            // Fill operation combobox
            uceOperation.Items.Add(0, clsGeneral.fnGetControlCaption(this, "uceOperation"));
            uceOperation.Items.Add(1, clsGeneral.fnGetControlCaption(this, "uceOperation.Equals"));
            uceOperation.Items.Add(2, clsGeneral.fnGetControlCaption(this, "uceOperation.Content"));
            uceOperation.Items.Add(3, clsGeneral.fnGetControlCaption(this, "uceOperation.Greater"));
            uceOperation.Items.Add(4, clsGeneral.fnGetControlCaption(this, "uceOperation.Smaller"));
            uceOperation.Items.Add(5, clsGeneral.fnGetControlCaption(this, "uceOperation.Different"));
            uceOperation.Items.Add(6, clsGeneral.fnGetControlCaption(this, "uceOperation.Beginning"));
            uceOperation.Items.Add(7, clsGeneral.fnGetControlCaption(this, "uceOperation.Finishing"));

            uceOperation.SelectedIndex = 0;

            lvwGrid.Columns[lvwGrid.Columns.Count - 1].Width = -2;

        }
Exemplo n.º 2
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);

            }

        }
Exemplo n.º 3
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);

            }

        }
Exemplo n.º 4
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);

            }

        }