Ejemplo n.º 1
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            //Get agent from selection
            int agentId = Convert.ToInt32(dgvAgents.SelectedRows[0].Cells[0].Value);

            try
            {
                agent = AgentDB.GetAgent(agentId);

                frmAgentModify modifyAgentForm = new frmAgentModify();
                modifyAgentForm.addAgent = false;
                modifyAgentForm.agent    = agent;

                DialogResult result = modifyAgentForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    agent = modifyAgentForm.agent;
                    SearchFor();
                }
                else if (result == DialogResult.Retry)
                {
                    //this.GetAgent(agent.AgentId);
                    SearchFor();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                string enteredAgentId  = txtAgentId.Text;
                string enteredPassword = txtPassword.Text;

                //AgentDB agentToCheck = new AgentDB();

                agentExists = AgentDB.CheckPassword(enteredAgentId, enteredPassword);

                if (agentExists)
                {
                    this.Hide();
                    frmMain mainForm = new frmMain(); //presenting the main form
                    mainForm.agent = AgentDB.GetAgent(Convert.ToInt32(enteredAgentId));
                    mainForm.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("You entered an invalid AgentID or Password");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Ejemplo n.º 3
0
        //Supporting methods --------------------------------
        private void SearchFor()
        {
            dgvAgents.DataSource          = AgentDB.SearchAgents(txtAgentId.Text);
            dgvAgents.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

            //not visible for column with password
            dgvAgents.Columns[8].Visible = false;
            this.Refresh();
        }
        private void SearchFor()
        {
            bool isIncludeExpiredPackagesEnabled = false;

            dgvMainPage.DataSource = null;

            //search for Packages
            if (rdbPackage.Checked)
            {
                grpListOf.Text = "List Of Package";
                isIncludeExpiredPackagesEnabled = true;
                dgvMainPage.DataSource          = PackageDB.GetPackages(txtSearch.Text, chbIncludeExpiredPackages.Checked);
                hideColumn(5);
                hideColumn(6);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
            }
            //search for Products
            if (rdbProduct.Checked)
            {
                grpListOf.Text                  = "List Of Products";
                dgvMainPage.DataSource          = ProductDB.SearchProducts(txtSearch.Text);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            //search for Suppliers
            if (rdbSupplier.Checked)
            {
                grpListOf.Text                  = "List Of Suppliers";
                dgvMainPage.DataSource          = SupplierDB.SearchSuppliers(txtSearch.Text);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            }
            //search for Agents
            if (rdbAgents.Checked)
            {
                grpListOf.Text                  = "List Of Agents";
                dgvMainPage.DataSource          = AgentDB.SearchAgents(txtSearch.Text);
                dgvMainPage.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                hideColumn(8);
            }

            chbIncludeExpiredPackages.Enabled = isIncludeExpiredPackagesEnabled;//enable 'IncludeExpiredPackages' box or not
            this.Refresh();
            EnableDisableEditButton();

            //dgvMainPage.Columns[columNo].Visible = false;
        }
        //Form Methods --------------------------------
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (IsValidData())
            {
                if (addAgent)
                {
                    agent = new Agent();//Adding a new agent
                    this.PutAgentData(agent);

                    try
                    {
                        agent.AgentId     = AgentDB.AddAgent(agent);
                        this.DialogResult = DialogResult.OK;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
                else
                {
                    Agent newAgent = new Agent();
                    newAgent.AgentId = agent.AgentId;
                    this.PutAgentData(newAgent);
                    try
                    {
                        if (!AgentDB.UpdateAgent(agent, newAgent))
                        {
                            MessageBox.Show("Another user has updated or deleted that agent.", "Database Error");
                            this.DialogResult = DialogResult.Retry;
                        }
                        else
                        {
                            agent             = newAgent;
                            this.DialogResult = DialogResult.OK;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.GetType().ToString());
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void txtAgentId_TextChanged(object sender, EventArgs e)
        {
            string searchMe = txtAgentId.Text;

            dgvAgents.DataSource = AgentDB.SearchAgents(searchMe);
        }