예제 #1
0
        protected void RepairCardsGridView_PageIndexChanging(Object sender, GridViewPageEventArgs e)
        {
            this.repairCardsGrid.PageIndex = e.NewPageIndex;
            object repairCardsFilterObject = Session[CarServiceConstants.REPAIR_CARDS_FILTER_SESSION_ATTR_NAME];
            IQueryable <RepairCard> repairCards;

            if (repairCardsFilterObject != null)
            {
                RepairCardFilter filter = (RepairCardFilter)repairCardsFilterObject;
                repairCards = FilterRepairCards(filter);
            }
            else
            {
                repairCards = this.persister.GetRepairCards();
            }
            object sortDirectionObj  = ViewState[CarServiceConstants.SORT_DIRECTION_VIEW_STATE_ATTR];
            object sortExpressionObj = ViewState[CarServiceConstants.SORT_EXPRESSION_VIEW_STATE_ATTR];

            if (sortDirectionObj != null && sortExpressionObj != null)
            {
                repairCards = SortingUtility.SortRepairCards(repairCards,
                                                             sortExpressionObj.ToString(), (SortDirection)sortDirectionObj);
            }
            BindRepairCardsGrid(repairCards);
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
        }
예제 #2
0
        protected void ReportType_IndexChanged(object sender, EventArgs e)
        {
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
            int    filterType = this.repairCardsFilterType.SelectedIndex;
            string filterBtnValidationGroupName = string.Empty;

            if (filterType == CarServiceConstants.ALL_REPAIR_CARDS_FILTER_TYPE)
            {
                this.allRepairCardsFilter.Visible        = true;
                this.finishedRepairCardsFilter.Visible   = false;
                this.unfinishedRepairCardsFilter.Visible = false;
                filterBtnValidationGroupName             = "AllRepairCardsFilterValidationGroup";
            }
            else if (filterType == CarServiceConstants.FINISHED_REPAIR_CARDS_FILTER_TYPE)
            {
                this.finishedRepairCardsFilter.Visible   = true;
                this.allRepairCardsFilter.Visible        = false;
                this.unfinishedRepairCardsFilter.Visible = false;
                filterBtnValidationGroupName             = "UnfinishedRepairCardsFilterValidationGroup";
            }
            else if (filterType == CarServiceConstants.UNFINISHED_REPAIR_CARDS_FILTER_TYPE)
            {
                this.unfinishedRepairCardsFilter.Visible = true;
                this.finishedRepairCardsFilter.Visible   = false;
                this.allRepairCardsFilter.Visible        = false;
                filterBtnValidationGroupName             = "FinishedRepairCardsFilterValidationGroup";
            }
            this.filterButton.ValidationGroup = filterBtnValidationGroupName;
        }
예제 #3
0
        protected void SaveRepairCard_OnClick(object sender, EventArgs e)
        {
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
            this.notificationMsgList.CssClass = CarServiceConstants.NEGATIVE_CSS_CLASS_NAME;

            DateTime?startRepairDate      = null;
            string   startRepairDateTxt   = this.startRepairDate.SelectedDate;
            bool     validStartRepairDate = CarServicePresentationUtility.ProcessStartRepairDate(startRepairDateTxt,
                                                                                                 this.notificationMsgList, out startRepairDate);

            decimal sparePartsPrice    = 0M;
            decimal repairPrice        = 0M;
            string  repairPriceTxt     = this.repairPrice.Text;
            string  sparePartsPriceTxt = this.sparePartsPrice.Text;
            bool    validPrices        = CarServicePresentationUtility.ProcessRepairPrices(sparePartsPriceTxt, repairPriceTxt,
                                                                                           this.notificationMsgList, out sparePartsPrice, out repairPrice);

            string     automobileIdTxt   = this.automobileDropDown.SelectedValue;
            Automobile automobile        = CarServiceUtility.GetAutomobile(automobileIdTxt, this.persister);
            bool       validAutomobileId = (automobile != null);

            ListItemCollection selectedSparePartItems = this.selectedSpareParts.Items;
            bool validSpareParts = CarServicePresentationUtility.IsSparePartItemsValid(selectedSparePartItems, this.notificationMsgList);

            if (validAutomobileId && validPrices && validSpareParts &&
                (validStartRepairDate && startRepairDate.HasValue))
            {
                string description        = this.repairCardDescription.Text;
                object repairCardIdObject = Session[CarServiceConstants.REPAIR_CARD_ID_PARAM_NAME];
                if (repairCardIdObject != null)
                {
                    int repairCardId;
                    if (Int32.TryParse(repairCardIdObject.ToString(), out repairCardId))
                    {
                        DateTime?finishRepairDate      = null;
                        string   finishRepairDateTxt   = this.finishRepairDate.SelectedDate;
                        bool     validFinishRepairDate = CarServicePresentationUtility.ProcessFinishRepairDate(finishRepairDateTxt,
                                                                                                               this.notificationMsgList, out finishRepairDate);
                        if (validFinishRepairDate == true)
                        {
                            RepairCard repairCard = this.persister.GetRepairCardById(repairCardId);
                            UpdateRepairCard(repairCard, automobile, finishRepairDate, description,
                                             sparePartsPrice, repairPrice, selectedSparePartItems);
                            CarServicePresentationUtility.AppendNotificationMsg("Repair card is updated successfully", this.notificationMsgList);
                            this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME;
                        }
                    }
                }
                else
                {
                    SaveRepairCard(automobile, startRepairDate.Value, description,
                                   sparePartsPrice, repairPrice, selectedSparePartItems);
                    CarServicePresentationUtility.AppendNotificationMsg("Repair card is saved successfully", this.notificationMsgList);
                    this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME;
                }
            }
            CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList);
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.persister == null)
            {
                this.persister = new CarServicePersister();
            }
            if (IsPostBack == false)
            {
                this.finishRepairDate.Enabled = false;
                object repairCardIdObject = Session[CarServiceConstants.REPAIR_CARD_ID_PARAM_NAME];
                if (repairCardIdObject != null)
                {
                    int repairCardId;
                    if (Int32.TryParse(repairCardIdObject.ToString(), out repairCardId))
                    {
                        RepairCard repairCard = this.persister.GetRepairCardById(repairCardId);
                        LoadRepairCardInfo(repairCard);

                        Guid           creatorUserId = repairCard.UserId;
                        MembershipUser currentUser   = Membership.GetUser();
                        Guid           currentUserId = (Guid)currentUser.ProviderUserKey;
                        if (currentUserId.Equals(creatorUserId) == false)
                        {
                            DisableAllInputControls();
                        }
                        else
                        {
                            this.startRepairDate.Enabled = false;
                        }
                    }
                }
                else
                {
                    IQueryable <SparePart> spareParts = this.persister.GetActiveSpareParts();
                    object customSpareParts           = CarServicePresentationUtility.GetSparePartsFormatForListBox(spareParts);
                    CarServicePresentationUtility.BindListBox(this.unselectedSpareParts, customSpareParts);
                    this.startRepairDate.SelectedDate =
                        DateTime.Now.ToString(CarServiceConstants.DATE_FORMAT, new CultureInfo(CarServiceConstants.ENGLISH_CULTURE_INFO));
                    this.finishRepairDate.Enabled = false;
                    this.operatorLbl.Text         = this.User.Identity.Name;
                }
            }
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
            Session[CarServiceConstants.AUTOMOBILE_ID_REQUEST_PARAM_NAME] = null;
        }
예제 #5
0
        private void HandleAutomobileInformation(string vin, string chassisNumber, string engineNumberTxt,
                                                 string engineCubTxt, string make, string model, string makeYearTxt, string owner,
                                                 string phoneNumber, string colour, string description)
        {
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
            bool       validVin           = false;
            bool       validChassisNumber = false;
            Automobile auto         = null;
            object     autoIdObject = Session[CarServiceConstants.AUTOMOBILE_ID_REQUEST_PARAM_NAME];

            // Updating existing automobile
            if (autoIdObject != null)
            {
                int autoId;
                if (Int32.TryParse(autoIdObject.ToString(), out autoId))
                {
                    auto = this.persister.GetAutomobilById(autoId);
                    string currentVin   = auto.Vin;
                    bool   isVinChanged = string.IsNullOrEmpty(currentVin) ||
                                          currentVin.Equals(vin) == false;
                    if (isVinChanged)
                    {
                        validVin = IsVinValid(vin);
                    }
                    else
                    {
                        validVin = true;
                    }
                    string currentChassisNumber   = auto.ChassisNumber;
                    bool   isChassisNumberChanged = string.IsNullOrEmpty(currentChassisNumber) ||
                                                    currentChassisNumber.Equals(chassisNumber) == false;
                    if (isChassisNumberChanged)
                    {
                        validChassisNumber = IsChassisNumberValid(chassisNumber);
                    }
                    else
                    {
                        validChassisNumber = true;
                    }
                }
            }
            else //Creates new automobile
            {
                validVin           = IsVinValid(vin);
                validChassisNumber = IsChassisNumberValid(chassisNumber);
            }
            bool     isVinExists     = this.persister.IsVinExists(vin);
            bool     isChassisExists = this.persister.IsChassisNumberExists(chassisNumber);
            int      engineCubValue  = -1;
            bool     emptyEngineCub  = string.IsNullOrEmpty(engineCubTxt);
            bool     validEngineCub  = emptyEngineCub || Int32.TryParse(engineCubTxt, out engineCubValue);
            DateTime makeYearValue   = DateTime.Now;
            bool     emptyMakeYear   = string.IsNullOrEmpty(makeYearTxt);
            bool     validMakeYear   = emptyMakeYear ||
                                       DateTime.TryParseExact(makeYearTxt, CarServiceConstants.DATE_FORMAT,
                                                              new CultureInfo(CarServiceConstants.ENGLISH_CULTURE_INFO), DateTimeStyles.None, out makeYearValue);

            GenerateNotificationErrorMsg(validVin, isVinExists, validChassisNumber, isChassisExists, validEngineCub, validMakeYear);
            if (validVin && validChassisNumber && validEngineCub && validMakeYear &&
                (isVinExists == false) && (isChassisExists == false))
            {
                DateTime?makeYear = null;
                if (emptyMakeYear == false)
                {
                    makeYear = makeYearValue;
                }
                int?engineCub = null;
                if (emptyEngineCub == false)
                {
                    engineCub = engineCubValue;
                }
                bool successfullySaved = SaveAutomobile(auto, vin, chassisNumber, engineNumberTxt,
                                                        engineCub, make, model, makeYear, owner, phoneNumber, colour, description);
                if (successfullySaved)
                {
                    CarServicePresentationUtility.AppendNotificationMsg("Car is saved successfully", this.notificationMsgList);
                    this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME;
                }
            }
            CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList);
        }
예제 #6
0
        protected void FilterRepairCards_OnClick(object sender, EventArgs e)
        {
            CarServicePresentationUtility.ClearNotificationMsgList(this.notificationMsgList);
            CarServicePresentationUtility.HideNotificationMsgList(this.notificationMsgList);
            int filterType          = this.repairCardsFilterType.SelectedIndex;
            RepairCardFilter filter = new RepairCardFilter(filterType);

            if (filterType == CarServiceConstants.ALL_REPAIR_CARDS_FILTER_TYPE)
            {
                filter.VinChassis = this.VinChassisAllRepairCardsTxt.Text;
            }
            else if (filterType == CarServiceConstants.FINISHED_REPAIR_CARDS_FILTER_TYPE)
            {
                DateTime?fromFinishRepairDate      = null;
                bool     validFromFinishRepairDate = false;
                string   fromFinishDateTxt         = this.fromFinishRepairDate.SelectedDate;
                if (string.IsNullOrEmpty(fromFinishDateTxt) == false)
                {
                    DateTime fromFinishRepairDateValue = DateTime.Now;
                    validFromFinishRepairDate = CarServiceUtility.IsValidDate(fromFinishDateTxt, out fromFinishRepairDateValue);
                    if (validFromFinishRepairDate == true)
                    {
                        fromFinishRepairDate = fromFinishRepairDateValue;
                    }
                }
                DateTime?toFinishRepairDate      = null;
                bool     validToFinishRepairDate = false;
                string   toFinishRepairDateTxt   = this.toFinishRepairDate.SelectedDate;
                if (string.IsNullOrEmpty(toFinishRepairDateTxt) == false)
                {
                    DateTime toFinishRepairDateValue = DateTime.Now;
                    validToFinishRepairDate = CarServiceUtility.IsValidDate(toFinishRepairDateTxt, out toFinishRepairDateValue);
                    if (validToFinishRepairDate == true)
                    {
                        toFinishRepairDate = toFinishRepairDateValue;
                    }
                }
                if (validFromFinishRepairDate && validToFinishRepairDate)
                {
                    filter.FromFinishRepair = fromFinishRepairDate.Value;
                    filter.ToFinishRepair   = toFinishRepairDate.Value;
                }
                else
                {
                    if (validFromFinishRepairDate == false)
                    {
                        CarServicePresentationUtility.AppendNotificationMsg("From finish repair date is not valid format", this.notificationMsgList);
                    }
                    if (validToFinishRepairDate == false)
                    {
                        CarServicePresentationUtility.AppendNotificationMsg("To finish repair date is not valid format", this.notificationMsgList);
                    }
                    CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList);
                    return;
                }
            }
            else if (filterType == CarServiceConstants.UNFINISHED_REPAIR_CARDS_FILTER_TYPE)
            {
                bool   validDate          = false;
                string startRepairDateTxt = this.startRepairDate.SelectedDate;
                if (string.IsNullOrEmpty(startRepairDateTxt) == false)
                {
                    DateTime startRepairDateValue = DateTime.Now;
                    validDate = CarServiceUtility.IsValidDate(startRepairDateTxt, out startRepairDateValue);
                    if (validDate == true)
                    {
                        filter.StartRepair = startRepairDateValue;
                    }
                }
                if (validDate == false)
                {
                    CarServicePresentationUtility.AppendNotificationMsg("Start repair date is not valid format", this.notificationMsgList);
                    CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList);
                    return;
                }
                filter.VinChassis = this.VinChassisTxt.Text;
            }
            ViewState[CarServiceConstants.SORT_DIRECTION_VIEW_STATE_ATTR]      = SortDirection.Ascending;
            ViewState[CarServiceConstants.SORT_EXPRESSION_VIEW_STATE_ATTR]     = CarServiceConstants.REPAIR_CARD_ID_SORT_EXPRESSION;
            Session[CarServiceConstants.REPAIR_CARDS_FILTER_SESSION_ATTR_NAME] = filter;
            IQueryable <RepairCard> customRepairCards = FilterRepairCards(filter);

            BindRepairCardsGrid(customRepairCards);
        }