Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
namespace CTP.HRMS.WebApp.Forms
{
    public partial class EmployeeAbsentForm : PageBase
    {
        protected override string ModuleName
        {
            get
            {
                return "EmployeeAbsentForm";
            }
        }

        private Employee _employee;
        private Employee Employee
        {
            get
            {
                if (_employee == null)
                {
                    if (Request.QueryString["id"] != null)
                    {
                        _employee = _service.GetEmployee(Request.QueryString["id"].ToString());
                    }

                    if (_employee == null)
                        _employee = new Employee();
                }
                return _employee;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!MyUser.CanAccess.AbsentRecord)
            {
                Redirect("/Forms/Redirected.aspx", "You do not have access to this page");
            }

            if (!Page.IsPostBack)
            {
                Page.Header.Title = "Please Enter New Absent Record:";
                BindData();
                // PopulateData();
            }
        }

        protected void BindData()
        {
            // Fill all Dropdowns
            ddlRollNo.Bind(_service.GetAllEmployee(), "IdName", "Id");
            ddlRank.Bind(_service.GetAllRank());
        }

        //protected void PopulateData()
        //{
        //    if ( Employee.Id != null)
        //    {

        //       // txtName.Text = Employee.Name;
        //        EmployeeAbsent empAbsent = new EmployeeAbsent();

        //        txtRollNo.Text = Employee.Id;
        //        ddlRank.SelectedValue = 
        //        txtStartDate.Text = empAbsent.StartDate.ToString();
        //        txtEndDate.Text = empAbsent.EndDate.ToString();
        //        txtDurtion.Text = empAbsent.Durtion;
        //        txtReason.Text = empAbsent.Reason;

        //    }
        //}


        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string[] temp = txtstartTime.Value.Split(new char[] { ' ', ':' });
                DateTime startDate = SafeConvert.ToDateTime(txtStartDate.Text).AddHours(temp[2] == "PM" ? SafeConvert.ToInt32(temp[0]) + 12 : SafeConvert.ToInt32(temp[0]))
                    .AddMinutes(SafeConvert.ToInt32(temp[1]));

                temp = txtEndTime.Value.Split(new char[] { ' ', ':' });
                DateTime endDate = SafeConvert.ToDateTime(txtEndDate.Text).AddHours(temp[2] == "PM" ? SafeConvert.ToInt32(temp[0]) + 12 : SafeConvert.ToInt32(temp[0]))
                    .AddMinutes(SafeConvert.ToInt32(temp[1]));

                EmployeeAbsent empAbsent = new EmployeeAbsent();
                empAbsent.UserName = MyUser.UserName;
                empAbsent.EntryDate = DateTime.Now;
                empAbsent.Emlopyee_Id = ddlRollNo.Text;
                empAbsent.Rank_Id = SafeConvert.ToByte(ddlRank.SelectedValue);
                empAbsent.StartDate = startDate;
                empAbsent.EndDate = endDate;
                empAbsent.Durtion = txtDurtion.Text;
                _service.InsertEmployeeAbsent(empAbsent);
                _queryStatus = empAbsent.Id > 0;

            }
            catch (Exception ex) { HandException(ex); }

            Redirect("EmployeeAbsentForm.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("EmployeeAbsentForm.aspx");
        }

        protected void txtStartDate_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtStartDate.Text) && !string.IsNullOrEmpty(txtstartTime.Value) &&
                !string.IsNullOrEmpty(txtEndDate.Text) && !string.IsNullOrEmpty(txtEndTime.Value))
            {

                string[] temp = txtstartTime.Value.Split(new char[] { ' ', ':' });
                DateTime startDate = SafeConvert.ToDateTime(txtStartDate.Text).AddHours(temp[2] == "PM" ? SafeConvert.ToInt32(temp[0]) + 12 : SafeConvert.ToInt32(temp[0]))
                    .AddMinutes(SafeConvert.ToInt32(temp[1]));

                temp = txtEndTime.Value.Split(new char[] { ' ', ':' });
                DateTime endDate = SafeConvert.ToDateTime(txtEndDate.Text).AddHours(temp[2] == "PM" ? SafeConvert.ToInt32(temp[0]) + 12 : SafeConvert.ToInt32(temp[0]))
                    .AddMinutes(SafeConvert.ToInt32(temp[1]));

                txtDurtion.Text = (endDate - startDate).ToString();

            }
        }
    }
}
ASP.NET
<%@ Page Title="" Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true"
    CodeBehind="EmployeeAbsentForm.aspx.cs" Inherits="CTP.HRMS.WebApp.Forms.EmployeeAbsentForm" %>

<asp:Content ContentPlaceHolderID="PageHeader" runat="server">
    <div class="breadcrumb">
        <h3 style="padding: 0; margin: 0"><%=Page.Header.Title%></h3>

    </div>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <div class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        Roll No <span class="symbol required"></span>
                    </label>
                    <div class="col-sm-3">
                       <asp:DropDownList CssClass="form-control search-select" runat="server" MaxLength="7" ID="ddlRollNo"  />
                       <asp:RequiredFieldValidator ValidationGroup="vgEmployee" runat="server" ID="rfvrOLL" ControlToValidate="ddlRollNo" Required="required"></asp:RequiredFieldValidator>
                     </div>
                    <label class="col-sm-2 control-label">
                        Rank <span class="symbol required"></span>
                    </label>
                    <div class="col-sm-3">
                        <asp:DropDownList CssClass="form-control" ID="ddlRank" runat="server" />
                        <asp:RequiredFieldValidator ValidationGroup="vgEmployee" runat="server" Required="required" ID="rfvRank" ControlToValidate="ddlRank"  ForeColor="#CC0000"></asp:RequiredFieldValidator>
                    </div>
                    <div class="col-sm-1">  </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        Start Date:
                    </label>
                    <div class="col-sm-3">
                        <asp:TextBox ID="txtStartDate" runat="server" MaxLength="10" Required="required" data-date-viewmode="years"
                            CssClass="form-control date-picker" data-date-format="dd-mm-yyyy"></asp:TextBox>
                     </div>
                    <label class="col-sm-2 control-label">
                        Start Time:
                    </label>
                    <div class="input-group input-append bootstrap-timepicker col-sm-3">
						<input id="txtstartTime" runat="server" type="text" class="form-control time-picker" />
						<span class="input-group-addon add-on"></span>
					</div>
                    </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        End Date:
                    </label>
                    <div class="col-sm-3">
                        <asp:TextBox ID="txtEndDate" runat="server" 
                            CssClass="form-control date-picker" data-date-viewmode="years" Required="required" MaxLength="10" data-date-format="dd-mm-yyyy"></asp:TextBox>
                       </div>
                    <label class="col-sm-2 control-label">
                        End Time:
                    </label>
                    <div class="input-group input-append bootstrap-timepicker col-sm-3">
						<input id="txtEndTime" runat="server" type="text" class="form-control time-picker"  />
						<span class="input-group-addon add-on">^__i class="fa fa-clock-o"></span>
					</div>
                    <div class="col-sm-1">  </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">
                        Durtion: <span class="symbol required"></span>
                    </label>
                    <div class="col-sm-3">
                        <asp:TextBox CssClass="form-control"  runat="server" ID="txtDurtion" Required="required" />
                        <asp:RegularExpressionValidator runat="server" ID="revDurtion" ControlToValidate="txtDurtion" Required="required"></asp:RegularExpressionValidator><br />
                    </div
                    <div class="col-sm-1 ">
                         <asp:LinkButton runat="server" CausesValidation="false" OnClick="txtStartDate_TextChanged" CssClass="btn btn-block" Text="Calculate" Width="120" />
                    </div>
                    <div class="col-sm-3"></div>
                </div>
                <div class="form-group" style="background-color: whitesmoke;">
                    <div class="col-md-5"> </div>
                    <div class="col-md-2">
                        <asp:Button ID="btnSubmit" runat="server" Text="Save" CausesValidation="true"
                            CssClass="btn btn-success btn-block"
                            ValidationGroup="vgEmployee" OnClick="btnSubmit_Click" />
                    </div>
                    <div class="col-md-2">
                        <asp:LinkButton ID="btnCancel2" runat="server" Text="Cancel" CssClass="btn btn-danger btn-block" OnClick="btnCancel_Click" />
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>

i have tried bootstrap but it is not function properly
Posted
Comments
Dilan Shaminda 2-Oct-14 13:45pm    
Not functioning properly means?you can show JavaScript alert if exception is occurred during data insert
ZurdoDev 2-Oct-14 14:03pm    
Where are you stuck? If you call update or insert in SQL an easy way to know if it worked or not is if your code does not hit the catch section.
Sajid227 2-Oct-14 14:08pm    
<form runat="server" role="form">
<ajaxToolkit:ToolkitScriptManager runat="server">


<script>
{
$('.date-picker').datepicker({ dateFormat: 'dd/mm/yyyy' });
$('.search-select').select2();
$('.time-picker').timepicker();
$(".alert").alert().fadeOut(10000);
<%--$('<%=_alert.ClientID%>').alert().fadeOut(1000);--%>

}
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
</script>

<asp:UpdatePanel runat="server" class="alert">
<contenttemplate>
<asp:Literal runat="server" >
<asp:ContentPlaceHolder runat="server" ID="MainContent">



when i use _alert then error and success message display,but when i click on close icon then it does not disappear ,if i use alert then no message display
khurram ali lashari 2-Oct-14 14:11pm    
try something like this....
try
{
insert_Reocrd();// you insert method
Response.Write("Record is successfully inserted");
// here print that record is successfully inserted
}
catch(Exception)
{
//here print exception occurs or some thing that you want to display
Response.Write("Record is not successfully inserted :An Exception occurred");
}

1 solution

Quick solution is to execute JavaScript code from C# as mentioned here[^].

If you can apply Ajax ModalPopups, then read the article Message Popup for Errors, Warnings, Success and Information Message With ModalPopup[^]
 
Share this answer
 
Comments
Sajid227 2-Oct-14 17:40pm    
how i use this solution to my save button,i.e if user click on save button then according to scenario message is display
http://www.codeproject.com/Tips/626350/Message-Popup-for-Errors-Warnings-Success-and-Info
Simply execute the a JavaScript function from code behind as given in the first link.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900