Vehicle IViolationHistory.GetViolationHistoryByPlateNumber(string country, string emirate, string plateCategory, string plateNumber, string plateCode)
        {
            try
            {
                violationService.ViolationInformationServiceClient service = new violationService.ViolationInformationServiceClient();
                //violationService.ViolationInformationService service = new violationService.ViolationInformationService();
                //   violationService.ViolationInformationService service = new violationService.ViolationBlockedService()


                violationService.Inspection[] inspection;
                violationService.AuthHeader header = new VSDApp.violationService.AuthHeader();
                header.userName = AppProperties.empUserName;
                header.password = AppProperties.empPassword;

                // violationService.
                //   service.authHeader = header;

                // service.Timeout = 180000;
                violationService.Response response = new VSDApp.violationService.Response();

               

                violationService.VehiclePlate vehPlate = new violationService.VehiclePlate();
                vehPlate.category = (plateCategory != "") ? plateCategory.Trim() : "NA";
                vehPlate.code = (plateCode != "") ? plateCode.Trim() : "NA";
                vehPlate.number = plateNumber.Trim();
                vehPlate.source = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetPlateSourceCode((emirate == "") ? country : emirate).Trim();
                //service.max

                //  inspection = service.inquireViolationById("S-VI-IV-1", vioID, out response);
                inspection = service.inquireViolationByPlate(header, "S-VI-IV-1", vehPlate, out response);
                //  service.inquireViolationByPlate(header,"",





                if (response.code.Equals("1000"))
                {
                    // Resources res = Resources.GetInstance();
                    // bool isEng = (res.GetLocale().Equals(Resources.locale_EN));
                    bool isEng = true;
                    AppProperties.vehicle = null;

                    AppProperties.vehicle = new Vehicle();
                    AppProperties.vehicle.PlateCategory = inspection[0].vehicle.plateDetails.category;
                    AppProperties.vehicle.PlateCode = inspection[0].vehicle.plateDetails.code;
                    AppProperties.vehicle.Emirate = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetPlateEmirateByCode(inspection[0].vehicle.plateDetails.source).Trim();
                    AppProperties.vehicle.PlateNumber = inspection[0].vehicle.plateDetails.number;
                    // AppProperties.vehicle.Country = inspection[0].vehicle.country;
                    if (inspection[0].vehicle.country == null)
                        AppProperties.vehicle.Country = country;
                    else
                        AppProperties.vehicle.Country = inspection[0].vehicle.country;
                    AppProperties.vehicle.ChassisNumber = inspection[0].vehicle.chassisNumber;
                    AppProperties.vehicle.Year = inspection[0].vehicle.manufacturedYear;
                    if (AppProperties.vehicle.Operator == null)
                    {
                        AppProperties.vehicle.Operator = new Operator();
                    }
                    if (AppProperties.Selected_Resource == "English")
                    {
                        if (inspection[0].vehicle.manufacturer.name == null || inspection[0].vehicle.manufacturer.name == "")
                            AppProperties.vehicle.Make = inspection[0].vehicle.manufacturer.nameArabic;
                        else
                            AppProperties.vehicle.Make = inspection[0].vehicle.manufacturer.name;
                        if (inspection[0].vehicle.manufacturer.model == null || inspection[0].vehicle.manufacturer.model == "")
                            AppProperties.vehicle.Model = inspection[0].vehicle.manufacturer.modelArabic;
                        else
                            AppProperties.vehicle.Model = inspection[0].vehicle.manufacturer.model;
                        if (inspection[0].vehicle.owner.ownerName == null || inspection[0].vehicle.owner.ownerName == "")
                            AppProperties.vehicle.Operator.OperatorName = inspection[0].vehicle.owner.ownerNameArabic;
                        else
                            AppProperties.vehicle.Operator.OperatorName = inspection[0].vehicle.owner.ownerName;
                    }
                    else
                    {
                        if (inspection[0].vehicle.manufacturer.name != null || inspection[0].vehicle.manufacturer.name != "")
                            AppProperties.vehicle.Make = inspection[0].vehicle.manufacturer.nameArabic;
                        else
                            AppProperties.vehicle.Make = inspection[0].vehicle.manufacturer.name;
                        if (inspection[0].vehicle.manufacturer.model != null || inspection[0].vehicle.manufacturer.model != "")
                            AppProperties.vehicle.Model = inspection[0].vehicle.manufacturer.model;
                        else
                            AppProperties.vehicle.Model = inspection[0].vehicle.manufacturer.modelArabic;
                        if (inspection[0].vehicle.owner.ownerName != null || inspection[0].vehicle.owner.ownerName != "")
                            AppProperties.vehicle.Operator.OperatorName = inspection[0].vehicle.owner.ownerNameArabic;
                        else
                            AppProperties.vehicle.Operator.OperatorName = inspection[0].vehicle.owner.ownerName;
                    }


                    //  AppProperties.vehicle.Operator = new Operator();
                    AppProperties.vehicle.Operator.OperatorName = inspection[0].vehicle.owner.ownerName;
                    AppProperties.vehicle.Operator.OperatorNameAr = inspection[0].vehicle.owner.ownerNameArabic;
                    AppProperties.vehicle.Operator.TrafficFileNumber = inspection[0].vehicle.owner.trafficFileNumber;


                    AppProperties.vehicle.VehicleOVRRScore = (null != inspection[0].vehicle.riskRating) ? inspection[0].vehicle.riskRating.riskRatingName : "";

                    //AppProperties.vehicle.Recomendation = ((null != respItem.plateConfiscationInstruction) ? ((respItem.plateConfiscationInstruction.Equals("false", StringComparison.CurrentCultureIgnoreCase)) ? "" : Resources.GetInstance().GetString("Confiscate")) : "");
                    // AppProperties.vehicle.Recomendation = ((null != inspection[0].plateConfiscationInstruction) ? ((inspection[0].plateConfiscationInstruction.Equals("false", StringComparison.CurrentCultureIgnoreCase)) ? "" : "Confiscate") : "");
                    // AppProperties.vehicle.Instruction = (null != inspection[0].inspectionInstruction) ? inspection[0].inspectionInstruction : "";

                    // Violation[] searchedViolation = new Violation[1];
                    if (null != inspection)
                    {

                        Violation[] searchedViolation = new Violation[inspection.Length];

                        for (int i = 0; i < inspection.Length; i++)
                        {
                            searchedViolation[i] = new Violation();



                            //  searchedViolation[0] = new Violation();

                            searchedViolation[i].ViolationComments = inspection[i].violation.comments;
                            searchedViolation[i].ViolationCommentsAr = inspection[i].violation.commentsArabic;
                            searchedViolation[i].Inspection_location = inspection[i].locationName;
                            searchedViolation[i].Inspection_locationAr = inspection[i].locationNameArabic;
                            searchedViolation[i].ViolationDueDays = inspection[i].violation.dueDate;
                            searchedViolation[i].ViolationIssueDate = inspection[i].time;
                            searchedViolation[i].ViolationID = inspection[i].violation.ticketNumber;
                            searchedViolation[i].ViolationTicketCode = inspection[i].violation.ticketNumber;
                            searchedViolation[i].ViolationStatus = (isEng) ? inspection[i].violation.statusName : inspection[i].violation.statusNameArabic;
                            searchedViolation[i].ViolationSeverity = inspection[i].violation.severityLevel.name;
                            searchedViolation[i].ViolationSeverityAr = inspection[i].violation.severityLevel.nameArabic;

                            searchedViolation[i].DriverLicNo = inspection[i].vehicle.driver.licenseNumber;
                            searchedViolation[i].RtaEmpID = inspection[i].inspectorEmployeeId;

                            Violation.Defects[] searchedDefects = new Violation.Defects[inspection[i].violation.defects.Length];
                            for (int j = 0; j < searchedDefects.Length; j++)
                            {
                                int id;
                                searchedDefects[j] = new Violation.Defects();
                                searchedDefects[j].DefectID = ((id = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectIDByCode(inspection[i].violation.defects[j].code)) != -1) ? id : 0;
                                //  searchedDefects[i].DefectName = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectNameByID(inspection[0].violation.defects[i].code);
                                searchedDefects[j].DefectName = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectNameByID(inspection[i].violation.defects[j].code);
                                searchedDefects[j].DefectNameAr = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectNameArByID(inspection[i].violation.defects[j].code);
                                searchedDefects[j].DefectCode = inspection[i].violation.defects[j].code;
                                searchedDefects[j].DefectType = inspection[i].violation.defects[j].type;
                                searchedDefects[j].DefectCategory = inspection[i].violation.defects[j].category;
                                searchedDefects[j].DefectValue = inspection[i].violation.defects[j].comment;
                                string[][] cat = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectMainCategoryByID(searchedDefects[j].DefectCode.ToString());

                                if (cat.Length > 0)
                                {
                                    searchedDefects[j].DefectCategory = cat[0][0].Trim();

                                }

                                if (null != inspection[i].violation.defects[j].vehicleCategories && inspection[i].violation.defects[j].vehicleCategories.Length > 0)
                                {
                                    searchedDefects[j].DefectSeverity = inspection[i].violation.defects[j].vehicleCategories[0].defectSeverityLevel.name;
                                    searchedDefects[j].DefectSeverityAr = inspection[i].violation.defects[j].vehicleCategories[0].defectSeverityLevel.nameArabic;
                                }
                            }
                            searchedViolation[i].Defect = searchedDefects;
                            AppProperties.vehicle.Violations = searchedViolation;

                        }
                    }
                }
                else if (response.code.Equals("2000"))
                {
                    AppProperties.businessError = true;
                    AppProperties.errorMessageFromBusiness = response.message;

                }
                else
                {
                    AppProperties.NotFoundError = true;
                    AppProperties.errorMessageFromBusiness = response.message;
                    //System.Windows.Forms.MessageBox.Show(response.message);
                }

            }
            catch (Exception connectionEx)
            {
               // CommonUtils.WriteLog(connectionEx.StackTrace)
                    AppProperties.IsException = true;
                    AppProperties.errorMessageFromBusiness = connectionEx.InnerException.Message;
               // System.Windows.Forms.MessageBox.Show(connectionEx.Message);
            }
            return null;
        }
        Vehicle IViolationHistory.GetViolationHistoryByID(string vioID)
        {
            try
            {
                violationService.ViolationInformationServiceClient service = new violationService.ViolationInformationServiceClient();
                //violationService.ViolationInformationService service = new violationService.ViolationInformationService();
                //   violationService.ViolationInformationService service = new violationService.ViolationBlockedService()


                violationService.Inspection[] inspection;
                violationService.AuthHeader header = new VSDApp.violationService.AuthHeader();
                header.userName = AppProperties.empUserName;
                header.password = AppProperties.empPassword;

                //   service.authHeader = header;

                // service.Timeout = 180000;
                violationService.Response response = new VSDApp.violationService.Response();
                //  inspection = service.inquireViolationById("S-VI-IV-1", vioID, out response);
                inspection = service.inquireViolationById(header, "S-VI-IV-1", vioID, out response);
                // service.inquireViolationByPlate(





                if (response.code.Equals("1000"))
                {
                    // Resources res = Resources.GetInstance();
                    // bool isEng = (res.GetLocale().Equals(Resources.locale_EN));
                    bool isEng = true;
                    AppProperties.vehicle = null;

                    AppProperties.vehicle = new Vehicle();
                    AppProperties.vehicle.PlateCategory = inspection[0].vehicle.plateDetails.category;
                    AppProperties.vehicle.PlateCode = inspection[0].vehicle.plateDetails.code;
                    AppProperties.vehicle.Emirate = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetPlateEmirateByCode(inspection[0].vehicle.plateDetails.source).Trim();
                    AppProperties.vehicle.PlateNumber = inspection[0].vehicle.plateDetails.number;
                    AppProperties.vehicle.Country = inspection[0].vehicle.country;

                    AppProperties.vehicle.ChassisNumber = inspection[0].vehicle.chassisNumber;
                    AppProperties.vehicle.Make = (isEng) ? inspection[0].vehicle.manufacturer.name : inspection[0].vehicle.manufacturer.nameArabic;
                    AppProperties.vehicle.Model = (isEng) ? inspection[0].vehicle.manufacturer.model : inspection[0].vehicle.manufacturer.modelArabic;
                    AppProperties.vehicle.Year = inspection[0].vehicle.manufacturedYear;


                    AppProperties.vehicle.Operator = new Operator();
                    AppProperties.vehicle.Operator.OperatorName = inspection[0].vehicle.owner.ownerName;
                    AppProperties.vehicle.Operator.OperatorNameAr = inspection[0].vehicle.owner.ownerNameArabic;
                    AppProperties.vehicle.Operator.TrafficFileNumber = inspection[0].vehicle.owner.trafficFileNumber;

                    Violation[] searchedViolation = new Violation[1];
                    searchedViolation[0] = new Violation();

                    searchedViolation[0].ViolationComments = inspection[0].violation.comments;
                    searchedViolation[0].ViolationCommentsAr = inspection[0].violation.commentsArabic;
                    searchedViolation[0].Inspection_location = inspection[0].locationName;
                    searchedViolation[0].Inspection_locationAr = inspection[0].locationNameArabic;
                    searchedViolation[0].ViolationDueDays = inspection[0].violation.dueDate;
                    searchedViolation[0].ViolationIssueDate = inspection[0].time;
                    searchedViolation[0].ViolationID = vioID;
                    searchedViolation[0].ViolationTicketCode = vioID;
                    searchedViolation[0].ViolationStatus = (isEng) ? inspection[0].violation.statusName : inspection[0].violation.statusNameArabic;
                    searchedViolation[0].ViolationSeverity = inspection[0].violation.severityLevel.name;
                    searchedViolation[0].ViolationSeverityAr = inspection[0].violation.severityLevel.nameArabic;

                    searchedViolation[0].DriverLicNo = inspection[0].vehicle.driver.licenseNumber;
                    searchedViolation[0].RtaEmpID = inspection[0].inspectorEmployeeId;

                    Violation.Defects[] searchedDefects = new Violation.Defects[inspection[0].violation.defects.Length];
                    for (int i = 0; i < searchedDefects.Length; i++)
                    {
                        int id;
                        searchedDefects[i] = new Violation.Defects();
                        searchedDefects[i].DefectID = ((id = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectIDByCode(inspection[0].violation.defects[i].code)) != -1) ? id : 0;
                        //  searchedDefects[i].DefectName = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectNameByID(inspection[0].violation.defects[i].code);
                        searchedDefects[i].DefectName = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectNameByID(inspection[0].violation.defects[i].code);
                        searchedDefects[i].DefectNameAr = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectNameArByID(inspection[0].violation.defects[i].code);
                        searchedDefects[i].DefectCode = inspection[0].violation.defects[i].code;
                        searchedDefects[i].DefectType = inspection[0].violation.defects[i].type;
                        searchedDefects[i].DefectCategory = inspection[0].violation.defects[i].category;
                        searchedDefects[i].DefectValue = inspection[0].violation.defects[i].comment;
                        string[][] cat = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetDefectMainCategoryByID(searchedDefects[i].DefectCode.ToString());

                        if (cat.Length > 0)
                        {
                            searchedDefects[i].DefectCategory = cat[0][0].Trim();

                        }
                        if (null != inspection[0].violation.defects[i].vehicleCategories && inspection[0].violation.defects[i].vehicleCategories.Length > 0)
                        {
                            searchedDefects[i].DefectSeverity = inspection[0].violation.defects[i].vehicleCategories[0].defectSeverityLevel.name;

                            searchedDefects[i].DefectSeverityAr = inspection[0].violation.defects[i].vehicleCategories[0].defectSeverityLevel.name;
                        }
                    }
                    searchedViolation[0].Defect = searchedDefects;
                    AppProperties.vehicle.Violations = searchedViolation;

                }
                else if (response.code.Equals("2000"))
                {
                    AppProperties.businessError = true;
                    AppProperties.errorMessageFromBusiness = response.message;

                }
                else
                {
                    AppProperties.NotFoundError = true;
                    AppProperties.errorMessageFromBusiness = response.message;
                   // System.Windows.Forms.MessageBox.Show(response.message);
                }

            }
            catch (Exception connectionEx)
            {
                CommonUtils.WriteLog(connectionEx.StackTrace);
               // System.Windows.Forms.MessageBox.Show(connectionEx.Message);
                AppProperties.IsException = true;
                AppProperties.errorMessageFromBusiness = connectionEx.InnerException.Message;
            }
            return null;
        }