Beispiel #1
0
        private void GenerateNotificationErrorMsg(bool validVin, bool isVinExists, bool validChassisNumber, bool isChassisExists,
                                                  bool validEngineCub, bool validMakeYear)
        {
            string notificationMsg = string.Empty;

            if (validVin == false)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Vin is not valid", this.notificationMsgList);
            }
            else if (isVinExists)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Vin is not unique", this.notificationMsgList);
            }
            if (validChassisNumber == false)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Chassis number is not valid", this.notificationMsgList);
            }
            else if (isChassisExists)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Chassis number is not unique", this.notificationMsgList);
            }
            if (validEngineCub == false)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Engine cub is not valid number", this.notificationMsgList);
            }
            if (validMakeYear == false)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Make year is not valid", this.notificationMsgList);
            }
            this.notificationMsgList.CssClass = CarServiceConstants.NEGATIVE_CSS_CLASS_NAME;
        }
        protected void AddPart_OnClick(object sender, EventArgs e)
        {
            string partIdTxt = this.PartId.Text;
            int    partId;
            bool   validIdValue = Int32.TryParse(partIdTxt, out partId);

            this.notificationMsgList.CssClass = CarServiceConstants.NEGATIVE_CSS_CLASS_NAME;
            if (validIdValue == false)
            {
                CarServicePresentationUtility.AppendNotificationMsg("ID is not valid", this.notificationMsgList);
            }
            string  partPriceTxt = this.PartPrice.Text;
            decimal partPrice;
            bool    validPriceValue = Decimal.TryParse(partPriceTxt, out partPrice);

            if (validPriceValue == false)
            {
                CarServicePresentationUtility.AppendNotificationMsg("Price is not valid", this.notificationMsgList);
            }
            int isPartActiveNum;

            if (validIdValue && validPriceValue &&
                Int32.TryParse(this.PartActive.SelectedValue, out isPartActiveNum) == true)
            {
                bool   isPartActive = (isPartActiveNum == 1);
                string partName     = this.PartName.Text;
                SaveSparePart(partId, partName, partPrice, isPartActive);
                CarServicePresentationUtility.AppendNotificationMsg("Part is saved successfully", this.notificationMsgList);
                this.notificationMsgList.CssClass = CarServiceConstants.POSITIVE_CSS_CLASS_NAME;
            }
            CarServicePresentationUtility.ShowNotificationMsgList(this.notificationMsgList);
        }
        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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }