Poent Ts

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';

import { FormControl, FormGroup, Validators } from '@angular/forms';


import { MatDialog } from '@angular/material/dialog';
import { UserService } from '../Services/user.service';

@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.css']
})
export class UserComponent implements OnInit {

constructor(public user: UserService, public dialog: MatDialog) { }

displayedColumns: string[] = ['position', 'name', 'description', 'examduration',


'examprice', 'numofquestions', 'passmark', 'coursename', 'symbol', 'Options'];
dataSource = '';

CreateForm: FormGroup = new FormGroup({


name: new FormControl('', [Validators.required, Validators.pattern('^[a-zA-
Z ]*$')]),
description: new FormControl('', [Validators.required, Validators.pattern('^[\
u0621-\u064A]+$')]),
examduration: new FormControl('', Validators.required),
examprice: new FormControl('', Validators.required),
numofquestions: new FormControl('', Validators.required),
passmark: new FormControl('', Validators.required),
courseid: new FormControl('', Validators.required),
imagepath: new FormControl()
})

UpdateForm: FormGroup = new FormGroup({


examid: new FormControl(),
name: new FormControl('', [Validators.required, Validators.pattern('^[a-zA-
Z ]*$')]),
description: new FormControl('', [Validators.required, Validators.pattern('^[\
u0621-\u064A]+$')]),
examduration: new FormControl('', Validators.required),
examprice: new FormControl('', Validators.required),
numofquestions: new FormControl('', Validators.required),
passmark: new FormControl('', Validators.required),
courseid: new FormControl('', Validators.required),
imagepath: new FormControl()
})

@ViewChild('CallCreateDialog') CallCreateDialog!: TemplateRef<any>;


@ViewChild('CallUpdateDialog') CallUpdateDialog!: TemplateRef<any>;
@ViewChild('CallDeleteDialog') CallDeleteDialog!: TemplateRef<any>;

ngOnInit(): void {
this.user.getAllExams();
}

OpenCreateDialog() {
this.dialog.open(this.CallCreateDialog);
}

CreateData() {
this.user.CreateExam(this.CreateForm.value)
}

previous_data: any = {};


OpenUpdateDialog(obj: any) {
this.previous_data = {
examid: obj.examid,
name: obj.name,
description: obj.description,
examduration: obj.examduration,
examprice: obj.examprice,
numofquestions: obj.numofquestions,
passmark: obj.passmark,
courseid: obj.courseid,
imagepath: obj.imagepath
}
this.UpdateForm.controls['examid'].setValue(this.previous_data.examid);
this.dialog.open(this.CallUpdateDialog)
}

SaveData() {
this.user.UpdateExam(this.UpdateForm.value);
}

OpenDeleteDialog(id: number) {
// debugger
const dialogRef = this.dialog.open(this.CallDeleteDialog);
dialogRef.afterClosed().subscribe((result) => {
console.log(result)
if (result != undefined) {
if (result == 'yes') {
this.user.DeleteExam(id);
}
}
})
}

examName: string = "";


Search(ev: any) {
this.examName = ev.target.value;
}

SearchButton() {
if (this.examName == ''){
this.user.getAllExams();
}else{
this.user.SearchByExamName(this.examName)
console.log(this.user.exams);
}
}
}

You might also like