Exemple #1
0
        private void Delete_Member_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                dataGridView1.Columns.Clear();
                dataGridView1.Items.Refresh();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "delete from Register_admin where id = " + Convert.ToInt32(idNum) + " ";
                cmd.ExecuteNonQuery();

                fillGrid();

                NewInsNameTxt.Text           = "";
                NewInsGenderTxt.Text         = "";
                NewMemberPhoneNumberTxt.Text = "";
                NewInsEmailTxt.Text          = "";
                NewInsNICTxt.Text            = "";
                NewInsUnameTxt.Text          = "";
                NewInspasswordTxt.Text       = "";
            }

            catch (Exception ex)
            {
                MsgProfile msgProfile = new MsgProfile(ex.ToString());
                msgProfile.Show();
            }
        }
        private void Member_Search_Click(object sender, RoutedEventArgs e)
        {
            int i = 0;

            try
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from Register_member where firstname like '%" + MemberNameSearch.Text + "%' ";
                cmd.ExecuteNonQuery();
                con.Close();

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                i = Convert.ToInt32(dt.Rows.Count.ToString());
                dataGridView1.ItemsSource = dt.DefaultView;
                con.Close();
                if (i == 0)
                {
                    MsgProfile msgProfile = new MsgProfile("No Members Found!!!");
                    msgProfile.Show();
                }
            }

            catch (Exception ex)
            {
                MsgProfile msgProfile = new MsgProfile(ex.ToString());
                msgProfile.Show();
            }
        }
        void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Subtract)
            {
                try
                {
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "select * from Register_member where nic like '%" + MemberNIC_Search.Text + "%' ";
                    cmd.ExecuteNonQuery();
                    con.Close();

                    DataTable      dt = new DataTable();
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    da.Fill(dt);
                    dataGridView1.ItemsSource = dt.DefaultView;
                    con.Close();
                }

                catch (Exception ex)
                {
                    MsgProfile msgProfile = new MsgProfile(ex.ToString());
                    msgProfile.Show();
                }
            }
        }
        private void SaveDataBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string img_path;
                File.Copy(openFileDialog1.FileName, wanted_path + "\\instructor_images\\" + pwd + ".jpg");

                img_path = "\\instructor_images\\" + pwd + ".jpg";

                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                con.Close();

                MsgProfile msgBox = new MsgProfile("Records Saved Succefully!!");
                msgBox.Show();
            }

            catch (Exception ex)
            {
                MsgProfile msgBox = new MsgProfile(ex.Message.ToString());
                msgBox.Show();
            }
        }
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (AdminloginNameTxt.Text == "admin" && AdminloginPasswordTxt.Password == "admin123")
            {
                AdminloginNameTxt.Clear();
                AdminloginPasswordTxt.Clear();

                if (path == "help")
                {
                    ChatBot_Loader chatBot_Loader = new ChatBot_Loader();
                    this.Hide();
                    chatBot_Loader.Show();
                }
                if (path == "instructor")
                {
                    InstructorMenu instructorMenu = new InstructorMenu();
                    this.Hide();
                    instructorMenu.Show();
                }
            }
            else
            {
                MsgProfile msgBox = new MsgProfile("Incorrect Username or Password!!");
                msgBox.Show();

                AdminloginNameTxt.Clear();
                AdminloginPasswordTxt.Clear();
            }
        }
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from Register_admin where admin_username = '******' and admin_password = '******' ";
            cmd.ExecuteNonQuery();
            con.Close();

            DataTable      dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            da.Fill(dt);
            count = Convert.ToInt32(dt.Rows.Count.ToString());
            if (loginNameTxt.Text == "" && loginPasswordTxt.Password == "")
            {
                MsgProfile msgBox = new MsgProfile("Fields are required!!");
                msgBox.Show();
            }
            else if (count == 0)
            {
                MsgProfile msgBox = new MsgProfile("Incorrect Username and password");
                msgBox.Show();
            }
            else
            {
                userName = loginNameTxt.Text;
                this.Hide();
                Dashboard dashboardView = new Dashboard(userName);
                dashboardView.Show();
            }
        }
        private void SubmitNewMemberBtn_Click(object sender, RoutedEventArgs e)
        {
            if (regMaleIndex.IsChecked == true)
            {
                gender = Convert.ToString("Male");
            }
            if (regFeMaleIndex.IsChecked == true)
            {
                gender = Convert.ToString("FeMale");
            }


            try
            {
                if (NewMemberFNameTxt.Text == "" || NewMemberLNameTxt.Text == "" || NewMemberEmailTxt.Text == "" || NewMemberPhoneNumberTxt.Text == "" || NewMemberNICTxt.Text == "")
                {
                    MsgProfile msgBox = new MsgProfile("All Fields are required!!");
                    msgBox.Show();
                }
                else
                {
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "insert into Register_member values('" + NewMemberFNameTxt.Text + "','" + NewMemberLNameTxt.Text + "','" + NewMemberEmailTxt.Text + "','" + NewMemberPhoneNumberTxt.Text + "','" + NewMemberNICTxt.Text + "' , '" + gender + "' , '" + NewMemberInstructorID.Text + "' , '" + NewMemberInstructorName.Text + "')";
                    cmd.ExecuteNonQuery();
                    con.Close();

                    MsgProfile msgBox = new MsgProfile("Member Registered!!");
                    msgBox.Show();
                    NewMemberFNameTxt.Clear();
                    NewMemberLNameTxt.Clear();
                    NewMemberEmailTxt.Clear();
                    NewMemberPhoneNumberTxt.Clear();
                    NewMemberNICTxt.Clear();
                    regFeMaleIndex.IsChecked = false;
                    regMaleIndex.IsChecked   = false;
                    NewMemberInstructorID.Clear();
                    NewMemberInstructorName.Clear();
                }
            }
            catch (Exception ex)
            {
                MsgProfile msgBox = new MsgProfile(ex.Message.ToString());
                msgBox.Show();
            }
        }
        private void dataGridView1_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            DataGrid    gd           = (DataGrid)sender;
            DataRowView row_selected = gd.SelectedItem as DataRowView;

            try {
                if (row_selected != null)
                {
                    NewMemberFNameTxt.Text       = row_selected["firstname"].ToString();
                    NewMemberLNameTxt.Text       = row_selected["lastname"].ToString();
                    NewMemberEmailTxt.Text       = row_selected["email"].ToString();
                    NewMemberPhoneNumberTxt.Text = row_selected["phonenum"].ToString();
                    NewMemberNICTxt.Text         = row_selected["nic"].ToString();
                    NewMemberInstructorID.Text   = row_selected["instruc_id"].ToString();
                    NewMemberInstructorName.Text = row_selected["instruc_name"].ToString();
                    idNum = row_selected["id"].ToString();
                }
                else
                {
                    MsgProfile msgProfile = new MsgProfile("Selected Row Empty!!");
                    msgProfile.Show();

                    fillGrid();

                    NewMemberFNameTxt.Text       = "";
                    NewMemberLNameTxt.Text       = "";
                    NewMemberEmailTxt.Text       = "";
                    NewMemberPhoneNumberTxt.Text = "";
                    NewMemberNICTxt.Text         = "";
                    NewMemberInstructorID.Text   = "";
                    NewMemberInstructorName.Text = "";
                }
            }
            catch (Exception ex)
            {
                MsgProfile msgProfile = new MsgProfile(ex.ToString());
                msgProfile.Show();
            }
        }
        private void View_Members_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                con.Open();
                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from Register_member";
                cmd.ExecuteNonQuery();

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                dataGridView1.ItemsSource = dt.DefaultView;

                con.Close();
            }
            catch (Exception ex)
            {
                MsgProfile msgProfile = new MsgProfile(ex.ToString());
                msgProfile.Show();
            }
        }
        private void Update_Members1_Click(object sender, RoutedEventArgs e)
        {
            dataGridView1.Items.Refresh();
            SqlCommand cmd = con.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "update  Register_admin set admin_name='" + NewInsNameTxt.Text + "',admin_gender='" + NewInsGenderTxt.Text + "',admin_tel='" + NewMemberPhoneNumberTxt.Text + "',admin_email='" + NewInsEmailTxt.Text + "',admin_NIC='" + NewInsNICTxt.Text + "',admin_username='******',admin_password='******' where id = " + Convert.ToInt32(idNum) + " ";
            cmd.ExecuteNonQuery();

            MsgProfile msgProfile = new MsgProfile("Record Update Successfully!!");

            msgProfile.Show();

            fillGrid();

            NewInsNameTxt.Text           = "";
            NewInsGenderTxt.Text         = "";
            NewMemberPhoneNumberTxt.Text = "";
            NewInsEmailTxt.Text          = "";
            NewInsNICTxt.Text            = "";
            NewInsUnameTxt.Text          = "";
            NewInspasswordTxt.Text       = "";
        }
        private void Update_Members1_Click(object sender, RoutedEventArgs e)
        {
            dataGridView1.Items.Refresh();
            SqlCommand cmd = con.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "update  Register_member set firstname='" + NewMemberFNameTxt.Text + "',lastname='" + NewMemberLNameTxt.Text + "',email='" + NewMemberEmailTxt.Text + "',phonenum='" + NewMemberPhoneNumberTxt.Text + "',nic='" + NewMemberNICTxt.Text + "',instruc_id='" + NewMemberInstructorID.Text + "',instruc_name='" + NewMemberInstructorName.Text + "' where id = " + Convert.ToInt32(idNum) + " ";
            cmd.ExecuteNonQuery();

            MsgProfile msgProfile = new MsgProfile("Record Update Successfully!!");

            msgProfile.Show();

            fillGrid();

            NewMemberFNameTxt.Text       = "";
            NewMemberLNameTxt.Text       = "";
            NewMemberEmailTxt.Text       = "";
            NewMemberPhoneNumberTxt.Text = "";
            NewMemberNICTxt.Text         = "";
            NewMemberInstructorID.Text   = "";
            NewMemberInstructorName.Text = "";
        }
        private void InsNameSearch_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                dataGridView1.Columns.Clear();
                dataGridView1.Items.Refresh();

                SqlCommand cmd = con.CreateCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "select * from Register_admin where admin_name like '%" + InsNameSearch.Text + "%' ";
                cmd.ExecuteNonQuery();

                DataTable      dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(dt);
                dataGridView1.ItemsSource = dt.DefaultView;
            }

            catch (Exception ex)
            {
                MsgProfile msgProfile = new MsgProfile(ex.ToString());
                msgProfile.Show();
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (regMaleIndex.IsChecked == true)
            {
                gender = "Male";
            }
            if (regFeMaleIndex.IsChecked == true)
            {
                gender = "Female";
            }

            try
            {
                if (regEmailTxt.Text == "" || regNameTxt.Text == "" || regNICTxt.Text == "" || regUserNameTxt.Text == "" || regPhoneNumberTxt.Text == "" || regPasswordTxt.Password == "")
                {
                    MsgProfile msgBox = new MsgProfile("All Fields are required!!");
                    msgBox.Show();
                }
                else
                {
                    con.Open();
                    SqlCommand cmd = con.CreateCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "insert into Register_admin values('" + regNameTxt.Text + "','" + gender + "','" + regPhoneNumberTxt.Text + "','" + regEmailTxt.Text + "','" + regNICTxt.Text + "','" + regUserNameTxt.Text + "','" + regPasswordTxt.Password + "')";
                    cmd.ExecuteNonQuery();
                    con.Close();

                    MsgProfile msgBox = new MsgProfile("Registered Succefully!! Welcome " + regNameTxt.Text);
                    msgBox.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }