Ejemplo n.º 1
0
        private void btn_AddAgent_Click(object sender, EventArgs e)
        {
            try
            {
                mycon.Open();

                //Inserting data in to table
                DataSet dsCl = new DataSet();


                string gender = "";
                //String refEmployeeName = cbAgentName.SelectedItem.ToString();

                if (radioButtonMale.Checked == true)
                {
                    gender = radioButtonMale.Text;
                }
                else
                {
                    gender = radioButtonFemale.Text;
                }

                if (clsGLobalVariables.method == "add")
                {
                    SqlCommand mycmdAgentAdd = new SqlCommand("INSERT INTO Employees (Name, Email, Phone, Address, Password, Gender, Position) " +
                                                              " VALUES('" + txt_name.Text + "','" + txt_mail.Text + "','" + txt_phone.Text + "','" + txt_Addr.Text + "','" + txt_pwd.Text + "','" + gender +
                                                              "','" + txt_post.Text + "')", mycon);
                    SqlDataAdapter daAgentAdd = new SqlDataAdapter(mycmdAgentAdd);
                    var            dsAgentAdd = new DataSet();
                    daAgentAdd.Fill(dsAgentAdd);

                    MessageBox.Show("Agent added successfully !!!", "Agent Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                if (clsGLobalVariables.method == "edit")
                {
                    SqlCommand mycmdeditAgents = new SqlCommand("UPDATE Employees " +
                                                                "SET Name ='" + txt_name.Text + "', Email ='" + txt_mail.Text +
                                                                "', Phone =" + txt_phone.Text + ", Password ='******', Address ='" + txt_Addr.Text + "', Position = '" + txt_post.Text +
                                                                "', Gender ='" + gender + "' WHERE Name = '" + clsGLobalVariables.Id + "'"
                                                                , mycon);
                    SqlDataAdapter daeditAgents = new SqlDataAdapter(mycmdeditAgents);
                    var            dsAgentsEdit = new DataSet();
                    daeditAgents.Fill(dsAgentsEdit);

                    MessageBox.Show("Agents Detail has been Updated!", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                mycon.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error due to " + ex.Message, "Error");
            }
            this.Close();
            frmAgentsView agentsView = new frmAgentsView();

            agentsView.Show();
        }
        private void btn_DeleteEmployee_Click(object sender, EventArgs e)
        {
            clsGLobalVariables.Id = dataAgentView.SelectedRows[0].Cells[1].Value.ToString();
            mycon.Open();
            SqlCommand     mycmddeleteAgents = new SqlCommand("DELETE FROM Employees WHERE Name ='" + clsGLobalVariables.Id.ToString() + "'", mycon);
            SqlDataAdapter daAgentsdelete    = new SqlDataAdapter(mycmddeleteAgents);
            var            dsAgentsdelete    = new DataSet();

            daAgentsdelete.Fill(dsAgentsdelete);
            mycon.Close();
            this.Close();

            MessageBox.Show("The Agents has been deleted!", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Information);
            frmAgentsView agentsView = new frmAgentsView();

            agentsView.Show();
        }
Ejemplo n.º 3
0
        private void viewAgentsMenu_Click(object sender, EventArgs e)
        {
            frmAgentsView frmAgentsView = new frmAgentsView();

            frmAgentsView.Show();
        }