managediscountcode.component.ts
4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { Component, OnInit, AfterViewInit, Input, Output, EventEmitter } from '@angular/core';
import { ManageDiscountCodeService } from './managediscountcode.service';
import { Router } from '@angular/router';
import { FormControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { DiscountCode } from '../UpdateProfile/datamodel';
import { BsDatepickerModule } from 'ngx-bootstrap';
import { Http, Response } from '@angular/http';
//import { Global } from '../../Shared/global';
//import { DBOperation } from 'S';
//import { Observable } from 'rxjs/Observable';
@Component({
templateUrl: './managediscountcode.component.html'
})
export class ManageDiscountCode implements OnInit {
Mode: string = 'Manage';
discountCode: DiscountCode;
discountCodes: Array<DiscountCode>;
manageDiscountCodeFrm: FormGroup;
insertUpdateDiscountCodeFrm: FormGroup;
error: any;
alerts: string;
divClass: string = '';
topPos: string = '2000px';
bsValue: Date = new Date();
constructor(private manageDiscountCodeService: ManageDiscountCodeService, private router: Router, private fb: FormBuilder) { }
ngOnInit(): void {
this.divClass = 'col-sm-12';
this.discountCode = new DiscountCode();
this.alerts = '';
this.manageDiscountCodeFrm = this.fb.group({
searchDiscountCode: [''],
searchStartDate: [''],
searchEndDate: [''],
discountCodes: this.fb.array([])
});
this.insertUpdateDiscountCodeFrm = this.fb.group({
discountId: [''],
discountCode: ['', Validators.required],
startDate: ['', Validators.required],
endDate: ['', Validators.required],
percentage: ['', Validators.required],
isActive: ['']
});
this.SearchDiscountCodes();
}
SearchDiscountCodes() {
console.log(this.manageDiscountCodeFrm.controls['searchDiscountCode'].value + ', ' +
this.manageDiscountCodeFrm.controls['searchStartDate'].value + ', ' +
this.manageDiscountCodeFrm.controls['searchEndDate'].value);
this.manageDiscountCodeService.GetDiscountCodes(
{
discountCode: this.manageDiscountCodeFrm.controls['searchDiscountCode'].value,
startDate: this.manageDiscountCodeFrm.controls['searchStartDate'].value,
endDate: this.manageDiscountCodeFrm.controls['searchEndDate'].value
})
.subscribe(x => { this.BindFormFields(x) }, error => this.error = error);
}
public InsertUpdateDiscountCode() {
console.log('InsertUpdateDiscountCode');
this.alerts = '';
if(this.alerts == ''){
var obj = this.insertUpdateDiscountCodeFrm.value;
return this.manageDiscountCodeService.InsertDiscountCode(obj)
.subscribe(
n => (this.AfterInsertData(n)),
error => this.error = <any>error);
}
}
AfterInsertData(data) {
if (data.Status == "false") {
this.alerts = "<span>Password change unsuccessfully</span>";
} else {
this.alerts = "<span>Password changed successfully</span>";
}
}
BindFormFields(data){
this.discountCodes = data;
this.manageDiscountCodeFrm.setControl('discountCodes', this.fb.array(this.discountCodes));
}
ResetFormFields(){
this.manageDiscountCodeFrm.reset()
//this.manageDiscountCodeFrm.controls['loginId'].setValue(this.user.LoginId);
//this.manageDiscountCodeFrm.controls['oldPassword'].setValue('');
//this.manageDiscountCodeFrm.controls['newPassword'].setValue('');
//this.manageDiscountCodeFrm.controls['confirmPassword'].setValue('');
this.alerts = '';
}
AddDiscountCode(){
this.Mode = 'Add';
this.topPos = '100px';
this.divClass = 'col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3';
}
EditDiscountCode(){
this.Mode = 'Edit';
this.topPos = '100px';
this.divClass = 'col-sm-10 col-sm-offset-1 col-md-8 col-md-offset-2 col-lg-6 col-lg-offset-3';
}
CancelAddEdit(){
this.Mode = 'Manage';
this.topPos = '2000px';
this.divClass = 'col-sm-12';
}
}