Sie sind auf Seite 1von 11

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Data.OracleClient;
using System.Web.UI.WebControls;

namespace WebApplication1
{
public partial class EmployeeDetails : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)

{
try
{
if (!IsPostBack)
{
loadGrade();
loadEmployeeDetails();
loadDepartments();
}

}
catch (Exception ex)
{

lblError.Text = "Error in Page_lod :" + ex.Message;


}

}
private void loadDepartments()
{
try
{
DataTable dtDepartment = getDepartments();
if (dtDepartment != null)
{
ddlDepartment.DataTextField = "SDEPARTMENTNAME";
ddlDepartment.DataValueField = "IDDEPARTMENT";
ddlDepartment.DataSource = dtDepartment;
ddlDepartment.DataBind();
}
}
catch (Exception ex)
{

lblError.Text = "Error in loadGrade :" + ex.Message;


}
}

private DataTable getDepartments()


{
String strSql = String.Empty;
OracleConnection cnn = new OracleConnection("user id=aamis_ownr; data
source=idev11; password=aamis_ownr123");
OracleCommand cmd = new OracleCommand();
DataTable dt = new DataTable("Departments");
OracleDataAdapter dadap;
try
{

strSql = "select D.IDDEPARTMENT, D.SDEPARTMENTNAME from tDepartment D


";
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}

dadap = new OracleDataAdapter(strSql, cnn);


dadap.Fill(dt);

}
finally
{
dadap = null;
if (cnn.State == ConnectionState.Open)
{
cnn.Close();
}
cnn = null;
}
return dt;
}

private void loadGrade()


{
try
{
DataTable dtGrade = getGrade();
if (dtGrade != null)
{

}
}
catch (Exception ex)
{

lblError.Text = "Error in loadGrade :" + ex.Message;


}
}

private DataTable getGrade()


{
DataTable dt = new DataTable("dtgr");
try
{

DataColumn dcName = new DataColumn("grdName");


DataColumn dcVal = new DataColumn("grdVal");
dt.Columns.Add(dcName);
dt.Columns.Add(dcVal);
DataRow drow = dt.NewRow();
drow["grdName"] = "1";
drow["grdVal"] = "1";
dt.Rows.Add(drow);
DataRow drow2 = dt.NewRow();
drow2["grdName"] = "2";
drow2["grdVal"] = "2";
dt.Rows.Add(drow2);
}
catch (Exception ex)
{

lblError.Text = "Error in loadGrade :" + ex.Message;


}
return dt;
}

private void loadEmployeeDetails()


{
try
{
DataTable dtEmployeeDetails = getEmployeeDetails();
if (dtEmployeeDetails != null)
{

grdEmployee.DataSource = dtEmployeeDetails;
grdEmployee.DataBind();

}
}
catch (Exception ex)
{
lblError.Text = "Error while loading Employee " + ex.Message;
}
}

private DataTable getMarksTable()


{

DataTable dt = new DataTable("dtmarks");


try
{
DataColumn dcSubject = new DataColumn("Nationality");
DataColumn dcMarks = new DataColumn("Religion");
DataColumn dcPercentage = new DataColumn("Working Hrs");
DataColumn dcGrade = new DataColumn("Total Service Years");
dt.Columns.Add(dcSubject);
dt.Columns.Add(dcMarks);
dt.Columns.Add(dcPercentage);
dt.Columns.Add(dcGrade);

DataRow drow = dt.NewRow();


drow["Nationality"] = "United Arab Emirates";
drow["Religion"] = "Muslim";
drow["Working Hrs"] = "42";
drow["Total Service Years"] = "8";
dt.Rows.Add(drow);

}
catch (Exception ex)
{
// lblError.Text = "Error while loading grade " + ex.Message;
}
return dt;
}

private DataTable getMarksTable2()


{

DataTable dt = new DataTable("dtmarks");


try
{
DataColumn dcSubject = new DataColumn("Nationality");
DataColumn dcMarks = new DataColumn("Religion");
DataColumn dcPercentage = new DataColumn("Working Hrs");
DataColumn dcGrade = new DataColumn("Total Service Years");
dt.Columns.Add(dcSubject);
dt.Columns.Add(dcMarks);
dt.Columns.Add(dcPercentage);
dt.Columns.Add(dcGrade);

DataRow drow = dt.NewRow();


drow["Nationality"] = "United Arab Emirates";
drow["Religion"] = "Muslim";
drow["Working Hrs"] = "25";
drow["Total Service Years"] = "30";
dt.Rows.Add(drow);

}
catch (Exception ex)
{
// lblError.Text = "Error while loading grade " + ex.Message;
}
return dt;
}

protected void ddlGrade_SelectedIndexChanged(object sender, EventArgs e)


{
/* if (ddlGrade.SelectedValue == "2")
{
loadMarks2();

}
else
{
loadMarks();
}*/
}

protected void ddlGender0_SelectedIndexChanged(object sender, EventArgs e)


{

protected void CheckBox1_CheckedChanged(object sender, EventArgs e)


{

protected void btnSave_Click(object sender, EventArgs e)


{
String strSql = String.Empty;
try
{
lblError.Text = "";
lblMessage.Text = "";
if (txtEmployeeID.Text != "" && txtEmployeeName.Text != "")
{
lblError.Text = "";
DateTime dtOB = Convert.ToDateTime(ddlDayDob.Text + '-' +
ddlMonthDob.Text + '-' + ddlyearDob.Text);
string sGender = "";
if (rdFemale.Checked)
sGender = "F";
else
sGender = "M";

strSql = "insert into


temployee(idemployee,semployeename,iddepartment,dtdateofbirth,sgender) values(" +
txtEmployeeID.Text + ", '" + txtEmployeeName.Text + "' , " +
ddlDepartment.SelectedValue + ", '" + dtOB.ToString("dd-MMM-yyyy") + "', '" + sGender
+ "' )";

bool result = saveData(strSql);


if (result == true)
{
lblMessage.Text = "Success";
}
else
{
lblError.Text = "Failed";
}
loadEmployeeDetails();
}
else
{
lblError.Text = "Please enter student number and name";
}
}
catch (Exception ex)
{
lblError.Text = "Error while saving data :" + ex.Message;
}

private bool saveData(string strSql)


{
bool result = false;

OracleConnection cnn = new OracleConnection("user id=aamis_ownr; data


source=idev11; password=aamis_ownr123");
OracleCommand cmd = new OracleCommand();
try
{
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}

cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql;
cmd.Connection = cnn;
if (cmd.ExecuteNonQuery() < 1)
{
throw new Exception("Insert into DB failed");
}

result = true;

}
catch (Exception ex)
{
result = false;
lblError.Text = "Error while saving data :" + ex.Message;
}
finally
{
if (cnn.State == ConnectionState.Open)
cnn.Close();
}
return result;

private DataTable getEmployeeDetails()


{
String strSql = String.Empty;
OracleConnection cnn = new OracleConnection("user id=aamis_ownr; data
source=idev11; password=aamis_ownr123");
OracleCommand cmd = new OracleCommand();
DataTable dt = new DataTable("Departments");
OracleDataAdapter dadap;
try
{

strSql = "select e.idemployee EmployeeID, e.semployeename Name,


d.sdepartmentname Department, e.dtdateofbirth DOB, e.sgender from temployee e,
tdepartment d where e.iddepartment=d.iddepartment order by e.idemployee";
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}

dadap = new OracleDataAdapter(strSql, cnn);


dadap.Fill(dt);

}
finally
{
dadap = null;
if (cnn.State == ConnectionState.Open)
{
cnn.Close();
}
cnn = null;
}
return dt;
}

protected void rdFemale_CheckedChanged(object sender, EventArgs e)


{
if (rdFemale.Checked)
{
rdMale.Checked = false;
}
}

protected void rdMale_CheckedChanged(object sender, EventArgs e)


{
if (rdMale.Checked)
{
rdFemale.Checked = false;
}
}

}
}

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EmployeeDetails.aspx.cs"


Inherits="WebApplication1.EmployeeDetails" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">

.auto-style1 {
height: 23px;
}
.auto-style41 {
height: 23px;
width: 142px;
}
.auto-style12 {
height: 23px;
width: 332px;
}
.auto-style15 {
height: 23px;
width: 395px;
}
.auto-style32 {
height: 26px;
width: 161px;
}
.auto-style10 {
height: 26px;
width: 142px;
}
.auto-style36 {
height: 26px;
width: 152px;
}
.auto-style13 {
height: 26px;
width: 332px;
}
.auto-style16 {
height: 26px;
width: 395px;
}
.auto-style38 {
height: 23px;
width: 14px;
}
.auto-style33 {
width: 161px;
height: 149px;
}
.auto-style40 {
width: 395px;
height: 149px;
}
</style>
</head>
<body>
<form id="form2" runat="server" style="background-position: -19px 0px; background-
image: url('NewImages/BackGround.jpg'); background-size: 100% 100%; background-repeat:
repeat-y; background-attachment: inherit; margin-right: 0px;">
<asp:Label ID="lblEmp" runat="server" BackColor="#666666" BorderColor="Black"
CssClass="auto-style1" Font-Bold="True" Font-Italic="True" Font-Overline="False" Font-
Size="XX-Large" Font-Strikeout="False" ForeColor="White" Text="Employee
Profile"></asp:Label>
<div>

</div>
<table style="width:100%; margin-right: 0px;">
<tr>
<td colspan="5">
&nbsp;</td>

</tr>
<tr>
<td class="auto-style1" style="color: #FFFFFF; font-weight: bold;
background-color: #666666;">
Employee ID</td>
<td class="auto-style41">
<asp:TextBox ID="txtEmployeeID" runat="server"></asp:TextBox>
</td>
<td class="auto-style1" style="color: #FFFFFF; font-weight: bold;
background-color: #666666;">
Employee Name</td>
<td class="auto-style12">
<asp:TextBox ID="txtEmployeeName" runat="server"></asp:TextBox>
</td>
<td class="auto-style15"></td>
</tr>
<tr>
<td class="auto-style32" style="color: #FFFFFF; font-weight: bold;
background-color: #666666;">Gender </td>
<td class="auto-style10">
<asp:RadioButton ID="rdMale" runat="server" AutoPostBack="true"
Text="Male" OnCheckedChanged="rdMale_CheckedChanged" />
<asp:RadioButton ID="rdFemale" runat="server" AutoPostBack="true"
Text="Female" OnCheckedChanged="rdFemale_CheckedChanged" />
</td>
<td class="auto-style1" style="color: #FFFFFF; font-weight: bold;
background-color: #666666;">
Department</td>
<td class="auto-style13">
<asp:DropDownList ID="ddlDepartment" runat="server"
OnSelectedIndexChanged="ddlGender0_SelectedIndexChanged" Height="16px" Width="98px">
</asp:DropDownList>
</td>
<td class="auto-style16"></td>
</tr>
<tr>
<td class="auto-style1" style="font-weight: bold; color: #FFFFFF;
background-color: #666666;">
DOB</td>
<td class="auto-style38" colspan="3">
<asp:DropDownList ID="ddlDayDob" runat="server"
OnSelectedIndexChanged="ddlGender0_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>17</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>31</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlMonthDob" runat="server"
OnSelectedIndexChanged="ddlGender0_SelectedIndexChanged">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlyearDob" runat="server"
OnSelectedIndexChanged="ddlGender0_SelectedIndexChanged">
<asp:ListItem Value="1960">1960</asp:ListItem>
<asp:ListItem Value="1961">1961</asp:ListItem>
<asp:ListItem>1962</asp:ListItem>
<asp:ListItem>1963</asp:ListItem>
<asp:ListItem>1964</asp:ListItem>
<asp:ListItem>1965</asp:ListItem>
<asp:ListItem>1966</asp:ListItem>
<asp:ListItem>1967</asp:ListItem>
<asp:ListItem>1968</asp:ListItem>
<asp:ListItem>1969</asp:ListItem>
<asp:ListItem>1970</asp:ListItem>
<asp:ListItem>1971</asp:ListItem>
<asp:ListItem>1972</asp:ListItem>
<asp:ListItem>1973</asp:ListItem>
<asp:ListItem>1974</asp:ListItem>
<asp:ListItem>1975</asp:ListItem>
<asp:ListItem>1976</asp:ListItem>
<asp:ListItem>1977</asp:ListItem>
<asp:ListItem>1978</asp:ListItem>
<asp:ListItem>1979</asp:ListItem>
<asp:ListItem>1980</asp:ListItem>
<asp:ListItem>1981</asp:ListItem>
<asp:ListItem>1982</asp:ListItem>
<asp:ListItem>1983</asp:ListItem>
<asp:ListItem>1984</asp:ListItem>
<asp:ListItem>1985</asp:ListItem>
<asp:ListItem>1986</asp:ListItem>
<asp:ListItem>1987</asp:ListItem>
<asp:ListItem>1988</asp:ListItem>
<asp:ListItem>1989</asp:ListItem>
<asp:ListItem>1990</asp:ListItem>
<asp:ListItem>1991</asp:ListItem>
<asp:ListItem Value="1992">1992</asp:ListItem>
<asp:ListItem>1993</asp:ListItem>
<asp:ListItem>1994</asp:ListItem>
<asp:ListItem>1995</asp:ListItem>
<asp:ListItem>1996</asp:ListItem>
<asp:ListItem>1997</asp:ListItem>
<asp:ListItem>1998</asp:ListItem>
</asp:DropDownList>
</td>

</tr>
<tr>
<td class="auto-style32"></td>
<td class="auto-style10"></td>
<td class="auto-style36">
</td>
<td class="auto-style13"></td>
<td class="auto-style16"></td>
</tr>
<tr>
<td class="auto-style32">&nbsp;</td>
<td class="auto-style10">
<asp:Button ID="btnSave" runat="server" Text="Save" Width="75px"
OnClick="btnSave_Click" />
</td>
<td class="auto-style36">
</td>
<td class="auto-style13"></td>
<td class="auto-style16"></td>
</tr>
<tr>
<td class="auto-style33" colspan="4">
<asp:GridView ID="grdEmployee" runat="server" Width="596px"
ForeColor="Red">
<AlternatingRowStyle BackColor="#990000" />
<EditRowStyle Font-Names="Bernard MT Condensed"
ForeColor="Black" />
<HeaderStyle BackColor="Maroon" BorderColor="Black"
BorderStyle="Solid" BorderWidth="1px" ForeColor="White" />
<RowStyle BackColor="#333333" ForeColor="White" />
</asp:GridView>
</td>

<td class="auto-style40">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</td>

</tr>
<tr>
<td colspan="5">
<div style="font-size: xx-large; font-weight: bold; color:
#900000" > <marquee direction="right"><strong>Please fill your details
</strong></marquee>
</div></td>

</tr>

</table>
<asp:Label ID="lblError" runat="server" Font-Bold="True"
ForeColor="Red"></asp:Label>
<table style="width:100%;">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br />
<asp:Label ID="lblMessage" runat="server" Font-Bold="True"
ForeColor="Red"></asp:Label>
</form>
</body>
</html>

Das könnte Ihnen auch gefallen