Ejemplo n.º 1
0
        protected void btnGetData_Click(object sender, EventArgs e)
        {
            try
            {
                // dataLayer = new DataLayer(ConfigurationManager.ConnectionStrings["DefaultConStr"].ConnectionString);
                if (((Button)sender).ID == "btnGetAllData")
                {
                    tboxId.Text = "0";
                }
                if (int.TryParse(tboxId.Text, out int Id))
                {
                    DataSet dataSet = DataLayer.GetData("sp_GetStudentDetailsById", new Dictionary <string, object>()
                    {
                        { "@Id", Id }
                    });

                    //DataSet dataSet = dataLayer.GetData("Select * from tbl_Student_Details where Id =@Id", new Dictionary<string, object>() { {"@Id",tboxId.Text } });

                    if (tboxId.Text != "0")
                    {
                        if (dataSet.Tables[0].Rows.Count > 0)
                        {
                            tboxFName.Text  = dataSet.Tables[0].Rows[0][1].ToString();//.ToString();
                            tboxLName.Text  = dataSet.Tables[0].Rows[0][2].ToString();
                            tboxEmail.Text  = dataSet.Tables[0].Rows[0][3].ToString();
                            tboxGender.Text = dataSet.Tables[0].Rows[0][4].ToString();

                            GridViewStudentDetails.DataSource = null;
                            GridViewStudentDetails.DataBind();
                        }
                    }
                    else
                    {
                        if (dataSet.Tables[0].Rows.Count > 0)
                        {
                            tboxFName.Text  = "";
                            tboxLName.Text  = "";
                            tboxEmail.Text  = "";
                            tboxGender.Text = "";
                            GridViewStudentDetails.DataSource = dataSet.Tables[0];
                            GridViewStudentDetails.DataBind();
                        }
                    }

                    lblMessage.Text = "";
                }
                else
                {
                    lblMessage.Text = "Enter Numeric values only";
                }
            }
            catch (Exception ex)
            {
                Logger.ErrorLog(ex);
                Server.Transfer("~/ErrorPage/ErrorPage.aspx");
            }
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            try
            {
                int EmpId = 0;
                if (txtEmpId.Text != null && txtEmpId.Text != string.Empty)
                {
                    EmpId = Convert.ToInt32(txtEmpId.Text);
                }
                string Name     = txtName.Text.Trim();
                string Salary   = txtSalary.Text.Trim();
                string DeptId   = txtDeptId.Text.Trim();
                string DeptName = txtDeptName.Text.Trim();

                proxy = new ServiceReference1.EmployeeServiceClient();
                ServiceReference1.Employees newStudent =
                    new ServiceReference1.Employees()
                {
                    EmpId    = EmpId,
                    Name     = Name,
                    Salary   = Salary,
                    DeptId   = DeptId,
                    DeptName = DeptName
                };

                proxy.UpdateEmpDetails(newStudent);

                GridViewStudentDetails.DataSource = proxy.GetEmployees();
                GridViewStudentDetails.DataBind();
                lblMsg.Text = "Record Saved Successfully";
            }
            catch (FaultException <ExceptionMessage> exceptionFromService)
            {
                if (ButtonInsert.Visible == true)
                {
                    lblMsg.Text = "Error while adding new customer details :" + exceptionFromService.Detail.errorMessageOfAction;
                }
                else
                {
                    lblMsg.Text = "Error while updating customer details :" + exceptionFromService.Detail.errorMessageOfAction;
                }
            }
            catch (Exception exception)
            {
                if (ButtonInsert.Visible == true)
                {
                    lblMsg.Text = "Error while adding new customer details :" + exception.Message;
                }
                else
                {
                    lblMsg.Text = "Error while updating customer details :" + exception.Message;
                }
            }

            ResetAll();
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             proxy = new ServiceReference1.EmployeeServiceClient();
             GridViewStudentDetails.DataSource = proxy.GetEmployees();
             GridViewStudentDetails.DataBind();
         }
         catch (FaultException <ExceptionMessage> exceptionFromService)
         {
             lblMsg.Text = "Error while loading Employee details :" + exceptionFromService.Detail.errorMessageOfAction;
         }
         catch (Exception exception)
         {
             lblMsg.Text = "Error while loading Employee details :" + exception.Message;
         }
     }
 }
Ejemplo n.º 4
0
 protected void DropDownListStudentIDs_SelectedIndexChanged(object sender, EventArgs e)
 {
     GridViewStudentDetails.Visible    = true;
     GridViewStudentDetails.DataSource = std.GetStudentDetails(DropDownListStudentIDs.SelectedItem.ToString()).Tables["Student"];
     GridViewStudentDetails.DataBind();
 }