Ejemplo n.º 1
0
        protected void _grdTodaysTimesheet_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.Header)
                {
                    foreach (TableCell tc in e.Row.Cells)
                    {
                        if (tc.Controls.Count == 1)
                        {
                            if (tc.HasControls())
                            {
                                // search for the header link
                                LinkButton lnk = (LinkButton)tc.Controls[0];
                                if (lnk != null)
                                {
                                    // inizialize a new image
                                    System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                                    // setting the dynamically URL of the image
                                    img.ImageUrl = "~/Images/PNGs/sort_az_" + (_grdTodaysTimesheet.SortDirection == SortDirection.Ascending ? "descending" : "ascending") + ".png";
                                    // checking if the header link is the user's choice
                                    if (_grdTodaysTimesheet.SortExpression == lnk.CommandArgument)
                                    {
                                        // adding a space and the image to the header link
                                        tc.Controls.Add(new LiteralControl(" "));
                                        tc.Controls.Add(img);
                                    }
                                }
                            }
                        }
                    }
                }

                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    UnPostedTimeSearchItem timeEntry = (UnPostedTimeSearchItem)e.Row.DataItem;

                    LinkButton lnkMatterReference = (LinkButton)e.Row.FindControl("_lnkBtnEditMatter");
                    lnkMatterReference.Text = lnkMatterReference.Text.Insert(6, "-");

                    //Truncate large descriptions
                    if (timeEntry.MatterDescription.Length > 20)
                    {
                        Label lbldescription = (Label)e.Row.FindControl("_lblMatterDescription");
                        lbldescription.Text = timeEntry.MatterDescription.Substring(0, 20) + "...";
                    }

                    //Truncate large notes
                    if (timeEntry.TimeComments.Length > 20)
                    {
                        Label lblNotes = (Label)e.Row.FindControl("_lblNotes");
                        lblNotes.Text = timeEntry.TimeComments.Substring(0, 20) + "...";
                    }

                    //Add to the total cost (displayed in the footer)
                    _charge += timeEntry.TimeCharge;

                    Label lblUnits = (Label)e.Row.FindControl("_lblUnits");
                    lblUnits.Text = (timeEntry.TimeElapsed / _logonSettings.TimeUnits).ToString();

                    Label lblTime = (Label)e.Row.FindControl("_lblTime");
                    lblTime.Text = AppFunctions.ConvertUnits(timeEntry.TimeElapsed);
                }
                else if (e.Row.RowType == DataControlRowType.Footer)
                {
                    ((Label)e.Row.FindControl("_lblTotal")).Text = "£" + _charge.ToString("0.00");
                }
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                _lblMessage.Text     = DataConstants.WSEndPointErrorMessage;
                _lblMessage.CssClass = "errorMessage";
            }
            catch (Exception ex)
            {
                _lblMessage.CssClass = "errorMessage";
                _lblMessage.Text     = ex.Message;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This method will post the selected timesheet entries for accounting
        /// </summary>
        /// <param name="displayWarnings">if set to <c>true</c> display warnings.</param>
        private void PostTime(bool displayWarnings)
        {
            TimeServiceClient   timeService   = null;
            EarnerServiceClient earnerService = null;

            try
            {
                UnPostedTimeSearchCriteria searchCriteria = new UnPostedTimeSearchCriteria();
                searchCriteria.UserId   = _logonSettings.DbUid;
                searchCriteria.TimeDate = DateTime.Now.Date;

                earnerService = new EarnerServiceClient();
                EarnerReturnValue earnerReturnVal = earnerService.GetFeeEarnerReference(_logonSettings.LogonId,
                                                                                        _logonSettings.MemberId);
                if (earnerReturnVal.Success)
                {
                    searchCriteria.FeeEarnerRef = earnerReturnVal.EarnerRef;
                }
                else
                {
                    throw new Exception(earnerReturnVal.Message);
                }


                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.StartRow = _grdTodaysTimesheet.PageIndex * _grdTodaysTimesheet.PageSize;
                collectionRequest.RowCount = _grdTodaysTimesheet.PageSize;

                //Get unposted time entries
                timeService = new TimeServiceClient();
                UnPostedTimeSearchReturnValue returnValue = timeService.UnPostedTimeSheetSearch(_logonSettings.LogonId,
                                                                                                collectionRequest,
                                                                                                searchCriteria);

                if (returnValue.UnPostedTimeSheet.Rows != null && returnValue.UnPostedTimeSheet.Rows.Length > 0)
                {
                    foreach (GridViewRow row in _grdTodaysTimesheet.Rows)
                    {
                        CheckBox timeSheetSelected = (CheckBox)row.FindControl("_chkSelect");
                        int      timeId            = (int)_grdTodaysTimesheet.DataKeys[row.RowIndex].Values["TimeId"];

                        //Find the item in the collection
                        UnPostedTimeSearchItem timeSheetItem = returnValue.UnPostedTimeSheet.Rows.First(time => time.TimeId == timeId);


                        //Check if the item is selected
                        if (timeSheetSelected.Checked)
                        {
                            //Validate the posting period
                            PeriodCriteria criteria = new PeriodCriteria();
                            criteria.Date                         = timeSheetItem.TimeDate;//returnValue.UnPostedTimeSheet.Rows[0].TimeDate;
                            criteria.IsTime                       = true;
                            criteria.IsPostingVATable             = false;
                            criteria.IsAllowedPostBack2ClosedYear = false;

                            PeriodDetailsReturnValue periodDetailsReturnValue = new PeriodDetailsReturnValue();
                            periodDetailsReturnValue = timeService.ValidatePeriod(_logonSettings.LogonId, criteria);

                            if (periodDetailsReturnValue.Success)
                            {
                                //Display warning mesg(if any)
                                if (periodDetailsReturnValue.PeriodStatus == 3 && displayWarnings)
                                {
                                    _mdlPopUpCofirmationBox.Show();
                                    return;
                                }

                                if (periodDetailsReturnValue.PeriodStatus == 2)
                                {
                                    throw new Exception(periodDetailsReturnValue.ErrorMessage);
                                }

                                if (timeSheetItem != null)
                                {
                                    bool canBePosted = true;

                                    if (timeSheetItem.BillingTypeActive &&
                                        timeSheetItem.BillingTypeArchived == false &&
                                        timeSheetItem.TimeLAAsked == false)
                                    {
                                        canBePosted = false;
                                    }

                                    if (canBePosted)
                                    {
                                        TimeSheet timeSheet = new TimeSheet();
                                        timeSheet.TimeId              = timeSheetItem.TimeId;
                                        timeSheet.PeriodId            = periodDetailsReturnValue.PeriodId;
                                        timeSheet.MemberId            = timeSheetItem.MemberId.ToString();
                                        timeSheet.CurrencyId          = timeSheetItem.CurrencyId;
                                        timeSheet.PeriodMinutes       = timeSheetItem.TimeElapsed;
                                        timeSheet.MasterPostedCost    = timeSheetItem.TimeCost;
                                        timeSheet.MasterPostedCharge  = timeSheetItem.TimeCharge;
                                        timeSheet.WorkingPostedCost   = timeSheetItem.TimeCost;
                                        timeSheet.WorkingPostedCharge = timeSheetItem.TimeCharge;
                                        timeSheet.OrganisationId      = timeSheetItem.OrganisationId;
                                        timeSheet.DepartmentId        = timeSheetItem.DepartmentId;
                                        timeSheet.ProjectId           = timeSheetItem.ProjectId;
                                        timeSheet.TimeTypeId          = timeSheetItem.TimeTypeId;
                                        timeSheet.TimeDate            = timeSheetItem.TimeDate;

                                        ReturnValue returnVal = timeService.PostTime(_logonSettings.LogonId, timeSheet);
                                        if (!returnVal.Success)
                                        {
                                            throw new Exception(returnVal.Message);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception(periodDetailsReturnValue.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (timeService != null)
                {
                    if (timeService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        timeService.Close();
                    }
                }
                if (earnerService != null)
                {
                    if (earnerService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        earnerService.Close();
                    }
                }
            }
        }