Repository navigation
Expand file tree
/
Copy pathfrm_AddCourse.aspx.cs
More file actions
134 lines (128 loc) · 4.61 KB
/
Copy pathfrm_AddCourse.aspx.cs
File metadata and controls
134 lines (128 loc) · 4.61 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class frm_AddCourse : System.Web.UI.Page
{
string QRY;
string CNS = ConfigurationManager.ConnectionStrings["cnStr"].ToString();
SqlConnection CNN;
SqlCommand CMD;
int InstId;
protected void Page_Load(object sender, EventArgs e)
{
InstId = int.Parse(Session["InstId"].ToString());
if (!IsPostBack)
{
BindmyStream(ddl_stream);
BindMyGrid();
}
}
public void BindmyStream(DropDownList ddl)
{
QRY = "SELECT Stream_Id,Stream_Name FROM Tbl_StreamMaster WHERE Stream_IsActive='TRUE' OR Stream_Id=0";
CNN = new SqlConnection(CNS);
CMD = new SqlCommand(QRY, CNN);
SqlDataAdapter DA = new SqlDataAdapter(CMD);
DataSet DS = new DataSet();
DA.Fill(DS);
ddl.DataTextField = "Stream_Name";
ddl.DataValueField = "Stream_Id";
ddl.DataSource = DS.Tables[0];
ddl.DataBind();
CMD.Dispose();
}
protected void btn_cancel_Click(object sender, EventArgs e)
{
ddl_stream.SelectedIndex = 0;
txtcourse.Text = string.Empty;
txtcourseduration.Text = string.Empty;
}
protected void btn_insert_Click(object sender, EventArgs e)
{
int CourId=0;
QRY = "SELECT MAX(Cour_Id)+1 FROM Tbl_CourseMaster WHERE Cour_IsActive='TRUE'";
CNN = new SqlConnection(CNS);
CMD = new SqlCommand(QRY, CNN);
CNN.Open();
SqlDataReader DR = CMD.ExecuteReader();
if (DR.Read())
{
CourId = int.Parse(DR[0].ToString());
}
DR.Close();
CNN.Close();
CMD.Dispose();
QRY = "INSERT INTO Tbl_CourseMaster VALUES (";
QRY += ""+CourId+", ";
QRY += ""+InstId+", ";
QRY += ""+ddl_stream.SelectedValue+", ";
QRY += "'"+txtcourse.Text+"', ";
QRY += "'"+txtcourseduration.Text+"', ";
QRY+="'TRUE')";
CNN = new SqlConnection(CNS);
CMD = new SqlCommand(QRY, CNN);
CNN.Open();
CMD.ExecuteNonQuery();
CNN.Close();
CMD.Dispose();
for (int i = 1; i <= int.Parse(txtcourseduration.Text.ToString()) * 2; i++)
{
QRY = "INSERT INTO Tbl_SemMaster VALUES (";
QRY += "(SELECT MAX(Sem_Id)+1 FROM Tbl_SemMaster), ";
QRY += "" + CourId + ", ";
QRY += "'SEM - " + i + "', ";
QRY += "'TRUE')";
CNN = new SqlConnection(CNS);
CMD = new SqlCommand(QRY, CNN);
CNN.Open();
CMD.ExecuteNonQuery();
CNN.Close();
CMD.Dispose();
}
}
void BindMyGrid()
{
QRY = "SELECT CM.Cour_Id, SM.Stream_Name, CM.Cour_Name FROM Tbl_StreamMaster SM, Tbl_CourseMaster CM ";
QRY+="WHERE SM.Stream_Id=CM.Stream_Id AND CM.Inst_Id="+InstId;
CNN = new SqlConnection(CNS);
CMD = new SqlCommand(QRY, CNN);
SqlDataAdapter DA = new SqlDataAdapter(CMD);
DataSet DS = new DataSet();
DA.Fill(DS);
Grd_Course.DataSource = DS;
Grd_Course.DataBind();
CMD.Dispose();
}
protected void Grd_Course_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
QRY = "UPDATE Tbl_CourseMaster SET Cour_Name = '" + e.NewValues["Cour_Name"] + "'";
if (((DropDownList)Grd_Course.Rows[e.RowIndex].Cells[1].FindControl("ddlStream")).SelectedIndex>0)
QRY += ", Stream_Id="+((DropDownList)Grd_Course.Rows[e.RowIndex].Cells[1].FindControl("ddlStream")).SelectedValue;
QRY += "WHERE Cour_Id=" + ((Label)Grd_Course.Rows[e.RowIndex].Cells[0].FindControl("Label1")).Text.ToString();
CNN = new SqlConnection(CNS);
CMD = new SqlCommand(QRY, CNN);
CNN.Open();
CMD.ExecuteNonQuery();
CNN.Close();
CMD.Dispose();
Grd_Course.EditIndex = -1;
BindMyGrid();
}
protected void Grd_Course_RowEditing(object sender, GridViewEditEventArgs e)
{
Grd_Course.EditIndex = e.NewEditIndex;
BindMyGrid();
//Response.Write(((DropDownList)Grd_Course.Rows[Grd_Course.EditIndex].Cells[1].FindControl("ddlStream")).ID);
BindmyStream((DropDownList)Grd_Course.Rows[Grd_Course.EditIndex].Cells[1].FindControl("ddlStream"));
}
protected void Grd_Course_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
Grd_Course.EditIndex = -1;
BindMyGrid();
}
}