private HyperLink BuildCheckOutLinkButton(UserSwipe item)
    {
        try
        {
            string buildtext = "<br/>" + " " + lblCheckOut;

            //Create a HyperLink instance.
            HyperLink link = new HyperLink();
            if (item.CheckOutTime.HasValue)
            {
                buildtext += item.CheckOutTime.Value.ToString("<b>hh:mm tt</br></b>");
            }
            else
            {
                buildtext += "<b>NE</br></b>";
            }
            link.Text = buildtext;

            //Build the argument in json format.
            string arguments = string.Format("{{'Action': 'CheckOut', 'WorkDate': '{0}', 'Id': '{1}'}}", item.WorkDate.ToString("MM/dd/yyyy"), item.Id);

            //Pass the argument in json format.
            link.NavigateUrl = Page.ClientScript.GetPostBackClientHyperlink(this.CalendarLinkButton1, arguments, false);

            //return the link.
            return(link);
        }
        catch { throw; }
    }
Example #2
0
    private HtmlGenericControl BuildTimeZoneShortName(UserSwipe item)
    {
        HtmlGenericControl span = new HtmlGenericControl("span");

        span.InnerHtml = item.CustomData["ShortName"].ToString();
        return(span);
    }
    //validate the checkoutTime.
    private void ValidateCheckOutTime(DateTime CheckOutTime, UserSwipe swipe)
    {
        try
        {
            //create a Exception Instances.
            ValidationException exception = new ValidationException();
            if (this.UserType != "Self")
            {
                //if (CheckOutTime.ToString("MM/dd/yyyy") != swipe.WorkDate.ToString("MM/dd/yyyy") && CheckOutTime.ToString("MM/dd/yyyy") != swipe.WorkDate.AddDays(1).ToString("MM/dd/yyyy") )
                //    exception.Data.Add("CHECK_OUT_DATE", "Check-Out date should be in work date or Tommorrow date.");

                //else if (swipe.CheckInTime.HasValue)
                if (swipe.CheckInTime.HasValue)
                {
                    if (CheckOutTime < swipe.CheckInTime.Value)
                    {
                        exception.Data.Add("CHECK_OUT_DATE", "Check-Out  time should be after then Check-In Time");
                    }
                }
            }

            //Throw exception.
            if (exception.Data.Count > 0)
            {
                throw exception;
            }
        }
        catch
        {
            throw;
        }
    }
    //validte the checkInTime.
    private void ValidateCheckInTime(DateTime checkInTime, UserSwipe swipe)
    {
        try
        {
            //create a Exception Instances
            ValidationException exception = new ValidationException();
            if (UserType != "Self")
            {
                //if (checkInTime.ToString("MM/dd/yyyy") != swipe.WorkDate.ToString("MM/dd/yyyy"))
                //    exception.Data.Add("CHECK_IN_TIME", "Check-In date should be in work date.");

                //else if (swipe.CheckOutTime.HasValue)
                if (swipe.CheckOutTime.HasValue)
                {
                    if (checkInTime > swipe.CheckOutTime.Value)
                    {
                        exception.Data.Add("CHECK_IN_TIME", "Check-In time should be earlier than Check-Out time.");
                    }
                }
            }


            // Throw exception.
            if (exception.Data.Count > 0)
            {
                throw exception;
            }
        }
        catch { throw; }
    }
    private HtmlGenericControl BuildCheckOutLabel(UserSwipe item)
    {
        // Create as span.
        HtmlGenericControl span = new HtmlGenericControl("span");

        span.InnerHtml = string.Format("Check Out: {0}", (item.CheckOutTime.HasValue) ? item.CheckOutTime.Value.ToString("<b>HH:mm tt</b>") : "NE");

        return(span);
    }
    protected void CalendarLinkButton1_CalendarClick(object sender, CalendarClickEventArgs e)
    {
        try
        {
            // Deserialize.
            JavaScriptSerializer        serializer = new JavaScriptSerializer();
            Dictionary <string, object> swipeInfo  = serializer.DeserializeObject(e.DataKey.ToString()) as Dictionary <string, object>;

            // Fetch values.
            string   action   = swipeInfo["Action"].ToString();
            int      id       = Int32.Parse(swipeInfo["Id"].ToString());
            DateTime workDate = DateTime.Parse(swipeInfo["WorkDate"].ToString());
            this.FillUserSwipes();
            UserSwipe userSwipe = null;

            if (mSwipeList != null)
            {
                // Check whether selected item is available in the list.
                userSwipe = mSwipeList.Where(item => item.Id == id && item.WorkDate.ToString("MM/dd/yyyy") == workDate.ToString("MM/dd/yyyy")).FirstOrDefault();
            }

            // Exists
            if (userSwipe == null)
            {
                userSwipe                = new UserSwipe(id);
                userSwipe.UserId         = Int32.Parse(this.hdnuserid.Value);
                userSwipe.WorkDate       = workDate;
                userSwipe.CreateDate     = DateTime.Now;
                userSwipe.LastUpdateDate = DateTime.Now;
            }

            // Display edit panel as dialog.
            this.userSwipeEditControl.AppManager = this.mAppManager;
            this.userSwipeEditControl.Action     = action;
            this.userSwipeEditControl.UserSwipe  = userSwipe;

            this.userSwipeEditControl.UserType = "Sup";
            this.userSwipeEditControl.InitializeView();


            // Register startup script.
            string script = string.Format("showEditPanelDialog({{'title': '{0}','width':'{1}'}})", action.ToString(), "400px");
            ScriptManager.RegisterStartupScript(
                this,
                typeof(Page),
                System.Guid.NewGuid().ToString(),
                script,
                true);
        }
        catch
        {
            throw;
        }
    }
    private HtmlGenericControl BuildCheckInLabel(UserSwipe item)
    {
        try
        {
            // Create as span.
            HtmlGenericControl span = new HtmlGenericControl("span");
            span.InnerHtml = string.Format("Check In: {0}", (item.CheckInTime.HasValue) ? item.CheckInTime.Value.ToString("<b>HH:mm tt<br/></b>") : "NE<br/>");

            return(span);
        }
        catch { throw; }
    }
Example #8
0
    private HyperLink BuildCheckInLinkButton(UserSwipe item)
    {
        try
        {
            //Create a hyperlink
            HyperLink link = new HyperLink();
            link.Text = "<br/>" + lblCheckIn;

            //pass the parameter as  json
            string arguments = string.Format("{{'Action': 'CheckIn', 'WorkDate': '{0}', 'Id': '{1}'}}", item.WorkDate.ToString("MM/dd/yyyy"), item.Id);
            link.NavigateUrl = Page.ClientScript.GetPostBackClientHyperlink(this.CalendarLinkButton1, arguments, false);

            //return the link.
            return(link);
        }
        catch { throw; }
    }
    protected void CalendUserSwipe_DayRender(object sender, DayRenderEventArgs e)
    {
        try
        {
            bool             IsParentuser = true;
            List <UserSwipe> uslist       = new List <UserSwipe>();
            //calender date.
            DateTime calendarDate = DateTime.Parse(e.Day.Date.ToString("MM/dd/yyyy"));

            //get the Current Date.
            DateTime  CurrentDate = DateTime.Parse(this.RetrieveCurrentDateTime().AddDays(1).ToString("MM/dd/yyyy"));
            string    DTdate      = null;
            UserSwipe userswipe   = null;

            IUserService             mUserService = null;
            List <Tks.Entities.User> LstUser      = null;
            mUserService            = AppService.Create <IUserService>();
            mUserService.AppManager = this.mAppManager;
            LstUser = mUserService.RetrieveAttachedUsers(Convert.ToInt32(mAppManager.LoginUser.Id));
            if (LstUser != null)
            {
                // Filter only active location.
                IEnumerable <User> list = from item in LstUser
                                          where item.Id.ToString() == hdnuserid.Value.ToString()
                                          select item;
                LstUser = list.ToList <User>();
                if (LstUser.Count == 0)
                {
                    IsParentuser = false;
                }
                else
                {
                    IsParentuser = true;
                }
            }

            // Check whether user swipe is available for the given calendar date.
            if (mSwipeList != null)
            {
                //if (mSwipeList != null)
                //{
                //    // Filter only active location.
                //    IEnumerable<UserSwipe> list = from item in mSwipeList
                //                                  where item.CustomData["Parentuserid"].ToString() == mAppManager.LoginUser.Id.ToString()
                //                                            && item.CustomData["ActiveStatus"].ToString() == "InActive"
                //                                  // && item.CustomData["ShortName"].ToString() == "det"
                //                                  select item;
                //    uslist = list.ToList<UserSwipe>();


                //    if (uslist.Count > 0)
                //    {
                //        //mSwipeList = uslist;
                //        DTdate = list.ElementAtOrDefault(0).CustomData["DetachDate"].ToString();
                //    }

                //    // Filter only active location.
                //    //IEnumerable<UserSwipe> list2 = from item in mSwipeList
                //    //                              where item.CustomData["Parentuserid"].ToString() == mAppManager.LoginUser.Id.ToString()
                //    //                                        && item.CustomData["ActiveStatus"].ToString() == "InActive"
                //    //                                        select item;
                //    if (DTdate != null)
                //    {
                //        IEnumerable<UserSwipe> list2 = from item in mSwipeList
                //                                       where item.CustomData["ActiveStatus"].ToString() == "InActive" && item.WorkDate <= DateTime.Parse(DTdate)
                //                                       select item;
                //        uslist = list2.ToList<UserSwipe>();

                //        if (uslist.Count > 0)
                //        {
                //            mSwipeList = uslist;
                //        }
                //    }

                //}

                userswipe = mSwipeList.Where(
                    x => x.WorkDate.ToString("MM/dd/yyyy") == calendarDate.ToString("MM/dd/yyyy"))
                            .FirstOrDefault();
            }
            // If available then display the check in and check out time span.
            HtmlGenericControl container = new HtmlGenericControl("div");
            //If  not available the dispaly the the Link
            if (userswipe == null && calendarDate <= CurrentDate)
            {
                if (e.Day.IsOtherMonth)
                {
                    e.Cell.Text = "";
                    //else if (e.Day.IsWeekend)
                    //{
                    //    e.Cell.Text = "";
                    //    container.InnerText = "NE";
                    //    e.Cell.Controls.Add(container);
                    //}
                }
                else if (Convert.ToDateTime(DTdate) < Convert.ToDateTime(calendarDate) && DTdate != null)
                {
                    //create dummy userswipe instance.
                    UserSwipe dummy = new UserSwipe(0);
                    dummy.WorkDate = calendarDate;
                }

                else
                {
                    //create dummy userswipe instance.
                    UserSwipe dummy = new UserSwipe(0);
                    dummy.WorkDate = calendarDate;

                    container.Controls.Add(this.BuildCheckInLinkButton(dummy));
                    container.Controls.Add(this.BuildCheckOutLinkButton(dummy));
                }
            }
            else if (userswipe != null && calendarDate <= CurrentDate)
            {
                container.Controls.Add(this.BuildTimeZoneShortName(userswipe));
                container.Controls.Add(this.BuildCheckInLinkButton(userswipe));
                container.Controls.Add(this.BuildCheckOutLinkButton(userswipe));
            }
            else
            {
                if (e.Day.IsOtherMonth)
                {
                    e.Cell.Text = "";
                }
            }


            e.Cell.Controls.Add(container);
        }
        catch
        {
            throw;
        }
    }
Example #10
0
    protected void CalUserSwipe_DayRender(object sender, DayRenderEventArgs e)
    {
        try
        {
            DateTime calendarDate = DateTime.Parse(e.Day.Date.ToString("MM/dd/yyyy"));
            //System.Diagnostics.Debug.Assert(calendarDate.ToString("MM/dd/yyyy") != "09/23/2011");

            //  Remove time span.
            DateTime  currentDate = DateTime.Parse(this.RetrieveCurrentDateTime().ToString("MM/dd/yyyy"));
            UserSwipe userswipe   = null;
            // Check whether user swipe is available for the given calendar date.
            if (mSwipeList != null)
            {
                userswipe = mSwipeList.Where(
                    x => x.WorkDate.ToString("MM/dd/yyyy") == calendarDate.ToString("MM/dd/yyyy"))
                            .FirstOrDefault();
            }

            // If available then display the check in and check out time span.
            HtmlGenericControl container = new HtmlGenericControl("div");
            //if (e.Day.Date.DayOfWeek.ToString().Equals("Sunday"))
            //{
            //    container.InnerText = "NE";
            //    e.Cell.Controls.Add(container);
            //    return;
            //}

            if (userswipe != null)
            {
                if (userswipe.WorkDate.ToString("MM/dd/yyyy") == currentDate.ToString("MM/dd/yyyy"))
                {
                    // Calendar date is current date then display as text/link.
                    if (userswipe.CheckInTime.HasValue)
                    {
                        container.Controls.Add(this.BuildTimeZoneShortName(userswipe));
                        container.Controls.Add(this.BuildCheckInLabel(userswipe));
                    }
                    else
                    {
                        container.Controls.Add(this.BuildCheckInLinkButton(userswipe));
                    }

                    if (userswipe.CheckOutTime.HasValue)
                    {
                        container.Controls.Add(this.BuildCheckOutLabel(userswipe));
                    }
                    else
                    {
                        container.Controls.Add(this.BuildCheckOutLinkButton(userswipe));
                    }
                }
                else if (calendarDate.ToString("MM/dd/yyyy") == currentDate.AddDays(1).ToString("MM/dd/yyy"))
                {
                    if (userswipe.CheckInTime.HasValue)
                    {
                        container.Controls.Add(this.BuildTimeZoneShortName(userswipe));
                        container.Controls.Add(this.BuildCheckInLabel(userswipe));
                    }
                    else
                    {
                        container.Controls.Add(this.BuildCheckInLinkButton(userswipe));
                    }
                    if (userswipe.CheckOutTime.HasValue)
                    {
                        container.Controls.Add(this.BuildCheckOutLabel(userswipe));
                    }
                    else
                    {
                        container.Controls.Add(this.BuildCheckOutLinkButton(userswipe));
                    }
                }
                else if (calendarDate.ToString("MM/dd/yyyy") == currentDate.AddDays(-1).ToString("MM/dd/yyyy"))
                {
                    if (userswipe.CheckInTime.HasValue)
                    {
                        container.Controls.Add(this.BuildTimeZoneShortName(userswipe));
                        container.Controls.Add(this.BuildCheckInLabel(userswipe));
                    }
                    else
                    {
                        container.Controls.Add(this.BuildCheckInLinkButton(userswipe));
                    }
                    if (userswipe.CheckOutTime.HasValue)
                    {
                        container.Controls.Add(this.BuildCheckOutLabel(userswipe));
                    }
                    else
                    {
                        container.Controls.Add(this.BuildCheckOutLinkButton(userswipe));
                    }
                }
                else if (userswipe.WorkDate < currentDate)
                {
                    // Calendar date less than current date then display as text.
                    container.Controls.Add(this.BuildTimeZoneShortName(userswipe));
                    container.Controls.Add(this.BuildCheckInLabel(userswipe));
                    container.Controls.Add(this.BuildCheckOutLabel(userswipe));
                }
            }
            else if (userswipe == null)
            {
                if (e.Day.IsOtherMonth)
                {
                    e.Cell.Text = string.Empty;
                }

                else
                {
                    // Create dummy instance.
                    UserSwipe dummy = new UserSwipe(0);

                    dummy.WorkDate = calendarDate;



                    // If calendar day is today and user swipe is not available then provide links to check in and check out.
                    if (calendarDate.ToString("MM/dd/yyyy") == currentDate.ToString("MM/dd/yyyy"))
                    {
                        // Display as link.
                        container.Controls.Add(this.BuildCheckInLinkButton(dummy));
                        container.Controls.Add(this.BuildCheckOutLinkButton(dummy));
                    }
                    else if (calendarDate.ToString("MM/dd/yyyy") == currentDate.AddDays(1).ToString("MM/dd/yyyy") || calendarDate.ToString("MM/dd/yyyy") == currentDate.AddDays(-1).ToString("MM/dd/yyyy"))
                    {
                        container.Controls.Add(this.BuildCheckInLinkButton(dummy));
                        container.Controls.Add(this.BuildCheckOutLinkButton(dummy));
                    }
                    // If not available then display the check in and check out time as NE (Not Entered).
                    else
                    {
                        if (calendarDate < currentDate)
                        {
                            // Display as text
                            container.Controls.Add(this.BuildCheckInLabel(dummy));
                            container.Controls.Add(this.BuildCheckOutLabel(dummy));
                        }
                    }
                }
            }



            // Add container to calendar day cell.
            e.Cell.Controls.Add(container);
        }
        catch { throw; }
    }
Example #11
0
        public List <UserSwipe> Retrieve(int userId, DateTime fromDate, DateTime toDate)
        {
            SqlCommand     command = null;
            SqlDataAdapter adapter = null;

            try
            {
                //Define a Command.
                command             = mDbConnection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "RetriveUserSwipe_new";

                // Assign the parameters.
                command.Parameters.Add("@Userid", SqlDbType.Int).Value        = userId;
                command.Parameters.Add("@datefrom", SqlDbType.DateTime).Value = fromDate;
                command.Parameters.Add("@dateto", SqlDbType.DateTime).Value   = toDate;
                adapter = new SqlDataAdapter(command);

                //Define the DataTable.
                DataTable SwipeDataTable = new DataTable();
                adapter.Fill(SwipeDataTable);
                List <UserSwipe> userSwipes = null;

                if (SwipeDataTable.Rows.Count > 0)
                {
                    //create a List Instance  of type UserSwipe.
                    userSwipes = new List <UserSwipe>();

                    //Define the Datarow.
                    foreach (DataRow dr in SwipeDataTable.Rows)
                    {
                        UserSwipe swipe = new UserSwipe(Int32.Parse(dr["SINO"].ToString()));
                        swipe.UserId     = Int32.Parse(dr["UserId"].ToString());
                        swipe.WorkDate   = Convert.ToDateTime(dr["WorkDate"].ToString());
                        swipe.TimeZoneId = Int32.Parse(dr["TimeZoneId"].ToString());
                        if (dr["CheckDateTime"].ToString() != "")
                        {
                            swipe.CheckInTime = Convert.ToDateTime(dr["CheckDateTime"].ToString());
                        }
                        else
                        {
                            swipe.CheckInTime = null;
                        }
                        if (dr["CheckOutDateTime"].ToString() != "")
                        {
                            swipe.CheckOutTime = Convert.ToDateTime(dr["CheckOutDateTime"].ToString());
                        }
                        else
                        {
                            swipe.CheckOutTime = null;
                        }
                        swipe.CreateUserId     = Int32.Parse(dr["CreateUserId"].ToString());
                        swipe.CreateDate       = Convert.ToDateTime(dr["CreateUserDate"].ToString());
                        swipe.LastUpdateUserId = Int32.Parse(dr["LastUpdateUserId"].ToString());
                        swipe.LastUpdateDate   = Convert.ToDateTime(dr["LastUpdateDate"].ToString());
                        swipe.Shift            = string.IsNullOrEmpty(dr["Shift"].ToString()) ? 0 : Int32.Parse(dr["Shift"].ToString());

                        swipe.UserworktypeId = string.IsNullOrEmpty(dr["UserworktypeId"].ToString()) ? 1 : Int32.Parse(dr["UserworktypeId"].ToString());

                        swipe.Reason = dr["Reason"].ToString();
                        swipe.CustomData.Add("ShortName", dr["ShortName"].ToString());
                        //swipe.CustomData.Add("ActiveStatus", dr["ActiveStatus"].ToString());
                        //swipe.CustomData.Add("Parentuserid", dr["Parentuserid"].ToString());
                        //swipe.CustomData.Add("Attachdate", dr["Attachdate"].ToString());
                        //swipe.CustomData.Add("DetachDate", dr["DetachDate"].ToString());
                        //Add to the list.
                        userSwipes.Add(swipe);
                    }
                }
                return(userSwipes);
            }
            catch { throw; }
            finally
            {
                if (command != null)
                {
                    command.Dispose();
                }
                if (adapter != null)
                {
                    adapter.Dispose();
                }
            }
        }
Example #12
0
        public void CheckOut(UserSwipe entity)
        {
            SqlCommand     command     = null;
            SqlDataAdapter adapter     = null;
            SqlTransaction transaction = null;

            try
            {
                //Define the Command.
                command             = mDbConnection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "UpdateUsersSwipe";

                //Assign the Parameters.
                command.Parameters.Add("@Data", SqlDbType.Xml).Value         = entity.GetXml();
                command.Parameters.Add("@hasError", SqlDbType.Bit).Direction = ParameterDirection.Output;

                //Define the transaction
                transaction         = mDbConnection.BeginTransaction();
                command.Transaction = transaction;

                // fill error datatable
                adapter = new SqlDataAdapter(command);
                DataTable errorDataTable = new DataTable();
                adapter.Fill(errorDataTable);

                // commit
                transaction.Commit();

                // Get output parameters.
                bool hasError = bool.Parse(command.Parameters["@hasError"].Value.ToString());

                if (hasError)
                {
                    // Create exception instance.
                    //ValidationException exception = new ValidationException("Validation error(s) occurred.");
                    ValidationException exception = new ValidationException("");

                    if (errorDataTable != null)
                    {
                        StringBuilder message = new StringBuilder();
                        foreach (DataRow row in errorDataTable.Rows)
                        {
                            message.Append(string.Format("{0}", row["Value"].ToString()));
                        }
                        exception.Data.Add("IsExists", message);
                    }


                    //Throw exception if any.
                    throw exception;
                }
            }
            catch (ValidationException ve)
            {
                throw ve;
            }
            catch
            {
                if (transaction != null)
                {
                    if (transaction.Connection != null)
                    {
                        //Rollback the transaction.
                        transaction.Rollback();
                    }
                }

                throw;
            }
            finally
            {
                // Dispose.
                if (transaction != null)
                {
                    transaction.Dispose();
                }
                if (command != null)
                {
                    command.Dispose();
                }
                if (adapter != null)
                {
                    adapter.Dispose();
                }
            }
        }