コード例 #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //This is to redirect the page if the user is not logged in
     if (string.IsNullOrEmpty((string)Session["role"]))
     {
         Response.Redirect("~/");
     }
     VaccencyList.DataBind();
     EmployeeInfo.DataBind();
 }
コード例 #2
0
        //Adding a new department
        void AddNew()
        {
            try
            {
                SqlConnection con = new SqlConnection(Strcon);
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                SqlCommand cmd = new SqlCommand("INSERT INTO employee(emp_id,emp_name,emp_designation,dept_id) values (@emp_id,@emp_name,@emp_designation,@dept_id)", con);
                cmd.Parameters.AddWithValue("@emp_id", EmpID.Text.Trim());
                cmd.Parameters.AddWithValue("@emp_name", EmpName.Text.Trim());
                cmd.Parameters.AddWithValue("@emp_designation", Designation.Text.Trim());
                cmd.Parameters.AddWithValue("@dept_id", DeptID.Text.Trim());
                cmd.ExecuteNonQuery();

                SqlCommand    cmdo    = new SqlCommand("SELECT vaccency FROM vaccency where dept_id='" + DeptID.Text.Trim() + "';", con);
                int           temp    = 0;
                SqlDataReader readerw = cmdo.ExecuteReader();
                while (readerw.Read())
                {
                    temp = Convert.ToInt32(readerw["vaccency"]);
                }
                temp = temp - 1;
                SqlCommand cmdu = new SqlCommand("Update vaccency set vaccency='" + temp + "' where dept_id='" + DeptID.Text.Trim() + "';", con);
                cmdu.ExecuteNonQuery();
                con.Close();
                Response.Write("<script>alert ('Employee added Successfully');</script>");
                EmployeeInfo.DataBind();
                VaccencyList.DataBind();
                ClearForm();
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
        }