Exemple #1
0
        bool IViolation.SubmitOfflineViolation()
        {
            try
            {
                List<Object> inspections;
                IDBDataLoad iDataLoad = ((IDBDataLoad)DBDataLoadManager.GetInstance());
                inspections = iDataLoad.GetStoredInspection();

                if (inspections.Count > 0)
                {
                    handHeldService.HandHeldService service = new VSDApp.handHeldService.HandHeldService();
                    handHeldService.SubmitOfflineViolationResponseItem[] resItem;
                    handHeldService.Inspection[] storedInspection = new VSDApp.handHeldService.Inspection[inspections.Count];

                    int inspectionID = -1;
                    int vehInfoID = -1;
                    int vioID = -1;

                    for (int i = 0; i < inspections.Count; i++)
                    {
                        storedInspection[i] = new VSDApp.handHeldService.Inspection();
                        string[] inspection = (string[])inspections[i];
                        inspectionID = Int32.Parse(inspection[0]);
                        vehInfoID = Int32.Parse(inspection[1]);
                        vioID = Int32.Parse(inspection[2]);
                        int locID = Int32.Parse(inspection[3]);

                        string locationExternalCode = iDataLoad.GetLocationCode(locID);

                        string[] vehicleInfo = iDataLoad.GetVehicleInfo(vehInfoID);
                        int vehicleCategoryID = Int32.Parse(vehicleInfo[1]);

                        String vehCatCode = iDataLoad.GetVehicleCategoryCode(vehicleCategoryID);

                        string[] ownerInfo = iDataLoad.GetOwnerInfo(vehInfoID);
                        string[] driverInfo = iDataLoad.GetDriverInfo(vehInfoID);
                        string[] violation = iDataLoad.GetViolation(vioID);
                        string[][] defectCodes = iDataLoad.GetDefectCodesForViolation(vioID);


                        storedInspection[i].time = DateTime.Parse(inspection[11].Trim());
                        storedInspection[i].address = locationExternalCode;


                        if (vioID != -1)
                        {
                            VSDApp.handHeldService.Defect[] defects = new VSDApp.handHeldService.Defect[defectCodes.Length];
                            for (int j = 0; j < defectCodes.Length; j++)
                            {
                                defects[j] = new VSDApp.handHeldService.Defect();
                                defects[j].code = defectCodes[j][0].Trim();
                                defects[j].comment = defectCodes[j][1].Trim();

                            }

                            handHeldService.Violation storedViolation = new VSDApp.handHeldService.Violation();
                            storedViolation.defects = defects;
                            storedViolation.comments = (violation[2] != "NULL") ? violation[2].Trim() : violation[3].Trim();
                            storedViolation.provisionalTicketNumber = violation[0].Trim();
                            storedInspection[i].violation = storedViolation;
                        }


                        storedInspection[i].channelPartInspectionCode = AppProperties.deviceCode;
                        storedInspection[i].inspectorName = (inspection[10].Trim());
                        storedInspection[i].inspectorEmployeeId = AppProperties.empID;
                        storedInspection[i].time = DateTime.Parse((inspection[11].Trim()));
                        storedInspection[i].timeSpecified = true;
                        storedInspection[i].frontPlateConditionName = (inspection[4].Trim() != "NULL") ? inspection[4].Trim() : "Good Condition";
                        storedInspection[i].rearPlateConditionName = (inspection[4].Trim() != "NULL") ? inspection[4].Trim() : "Good Condition";
                        storedInspection[i].isPlateConfiscated = inspection[6].Trim();
                        storedInspection[i].isRegistrationExpired = "F";


                        handHeldService.Vehicle veh = new VSDApp.handHeldService.Vehicle();
                        handHeldService.VehiclePlate plate = new VSDApp.handHeldService.VehiclePlate();

                        plate.source = iDataLoad.GetPlateSourceCode((vehicleInfo[4].Trim() != "") ? vehicleInfo[4].Trim() : vehicleInfo[6].Trim()).Trim();
                        plate.number = vehicleInfo[5].Trim();
                        plate.category = ("" != vehicleInfo[2].Trim()) ? vehicleInfo[2].Trim() : "NA";
                        plate.code = ("" != vehicleInfo[3].Trim()) ? vehicleInfo[3].Trim() : "NA";
                        veh.country = vehicleInfo[6].Trim();
                        veh.plateDetails = plate;

                        handHeldService.VehicleCategory vehCat = new VSDApp.handHeldService.VehicleCategory();
                        vehCat.code = vehCatCode.Trim();
                        veh.category = vehCat;

                        handHeldService.VehicleDriver driver = new VSDApp.handHeldService.VehicleDriver();
                        if (vioID != -1)
                        {
                            driver.licenseNumber = ("" != driverInfo[4].Trim()) ? driverInfo[4].Trim() : "NA";
                            driver.name = ("" != driverInfo[2].Trim()) ? driverInfo[2].Trim() : "NA";
                        }
                        else
                        {
                            driver.licenseNumber = "NA";
                            driver.name = "NA";
                        }

                        veh.driver = driver;
                        storedInspection[i].vehicle = veh;

                    }

                    handHeldService.AuthHeader header = new VSDApp.handHeldService.AuthHeader();
                    header.userName = AppProperties.empUserName;
                    header.password = AppProperties.empPassword;
                    service.authHeader = header;
                    service.Timeout = 180000;
                    resItem = service.submitOfflineViolation("RC123", storedInspection);


                    for (int j = 0; j < resItem.Length; j++)
                    {
                        if (resItem[j].response.code.Equals("1000"))
                        {
                            //System.Windows.MessageBox.Show(Resources.GetInstance().GetString("Offline Data Sysnchronized"));
                            if (AppProperties.Selected_Resource == "English")
                                System.Windows.MessageBox.Show("Offline Data Sysnchronized");
                            else
                                System.Windows.MessageBox.Show("تم مزامنة البيانات");
                            ClearInspections();
                            return true;
                        }
                        else if (resItem[j].response.code.Equals("2000"))
                        {
                            AppProperties.businessError = true;
                            AppProperties.errorMessageFromBusiness = resItem[j].response.message;
                            return true;

                        }
                        else
                        {
                            System.Windows.MessageBox.Show("Unable to upload data " + resItem[j].response.message);
                            break;
                        }

                    }


                }
                else
                {
                    if (AppProperties.Selected_Resource == "English")
                        System.Windows.MessageBox.Show("No offline data available");
                    else
                        System.Windows.MessageBox.Show("لا توجد بيانات للمزامنة");

                }


                return true;
            }
            catch (Exception e)
            {
                CommonUtils.WriteLog(e.StackTrace);
                System.Windows.MessageBox.Show("Unable to connect: " + e.Message);
                return false;
            }
        }
Exemple #2
0
        bool IViolation.SubmitViolation()
        {
            IDBDataLoad iDataLoad = ((IDBDataLoad)DBDataLoadManager.GetInstance());

            try
            {

                handHeldService.SubmitViolationResponseItem respItem = new VSDApp.handHeldService.SubmitViolationResponseItem();
                handHeldService.Inspection inspection = new VSDApp.handHeldService.Inspection();

                handHeldService.AuthHeader header = new VSDApp.handHeldService.AuthHeader();


                inspection.time = System.DateTime.Now;
                inspection.timeSpecified = true;

                AppProperties.recordedViolation.ViolationIssueDate = inspection.time;
                string adr = iDataLoad.GetLocationCode(AppProperties.recordedViolation.InspectionArea.city, AppProperties.recordedViolation.InspectionArea.area, AppProperties.recordedViolation.InspectionArea.location);
                
                //Dubai,Deira,Dafza
                if (adr == "")
                {
                 //   string adr = iDataLoad.GetLocationCode(AppProperties.de, AppProperties.recordedViolation.InspectionArea.area, AppProperties.recordedViolation.InspectionArea.location);
                }
                inspection.address = (adr != null) ? adr : "247.00012";


                // inspection.channelPartInspectionCode = "01";

                Regex regExp = new Regex("[A-Za-z0-9]*");
                bool isEng = regExp.IsMatch(AppProperties.empUserName);


                if (isEng)
                {
                    header.userName = AppProperties.empUserName;
                    header.password = AppProperties.empPassword;
                    inspection.inspectorName = AppProperties.empUserName;

                }
                else
                {
                    header.userName = AppProperties.empUserName;
                    header.password = AppProperties.empPassword;
                    inspection.inspectorNameArabic = AppProperties.empUserName;
                }


                string serialNumber = "39";// Schweers.Sys.Device.SerialNumber;
                //empUserName code
                inspection.inspectorEmployeeId = AppProperties.empID;
                inspection.channelPartInspectionCode = AppProperties.deviceCode;


                //  isEng = regExp.IsMatch((AppProperties.recordedViolation.PlateCondition != null) ? AppProperties.recordedViolation.PlateCondition : (Resources.GetInstance().GetLocale().Equals(Resources.locale_EN)) ? "ENG" : "استعمال");
                isEng = true;

                if (AppProperties.Selected_Resource == "English")
                {
                    inspection.frontPlateConditionName = (AppProperties.recordedViolation.PlateCondition != null) ? AppProperties.recordedViolation.PlateCondition : "Good Condition";
                    inspection.rearPlateConditionName = (AppProperties.recordedViolation.PlateCondition != null) ? AppProperties.recordedViolation.PlateCondition : "Good Condition";
                }
                else
                {
                    inspection.frontPlateConditionName = (AppProperties.recordedViolation.PlateCondition != null) ? AppProperties.recordedViolation.PlateCondition : new CommonUtils().GetStringValue("Good Condition");
                    inspection.rearPlateConditionName = (AppProperties.recordedViolation.PlateCondition != null) ? AppProperties.recordedViolation.PlateCondition : new CommonUtils().GetStringValue("Good Condition");
                }


                handHeldService.Vehicle veh = new VSDApp.handHeldService.Vehicle();
                handHeldService.VehiclePlate plate = new VSDApp.handHeldService.VehiclePlate();

                plate.source = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetPlateSourceCode((AppProperties.vehicle.Emirate == "") ? AppProperties.vehicle.Country : AppProperties.vehicle.Emirate).Trim();
                if (plate.source == null || plate.source == "")
                {
                    plate.source = AppProperties.vehicle.PlateSource;
                }
                plate.number = AppProperties.vehicle.PlateNumber.ToString();
                plate.category = (AppProperties.vehicle.PlateCategory != "") ? AppProperties.vehicle.PlateCategory.Trim() : "NA";
                plate.code = (AppProperties.vehicle.PlateCode != "") ? AppProperties.vehicle.PlateCode : "NA";
                if (AppProperties.vehicle.Country == "")
                {
                    veh.country = AppProperties.defaultCountry;
                }
                else
                {
                    veh.country = AppProperties.vehicle.Country.Trim();
                }
                veh.plateDetails = plate;
                veh.chassisNumber = AppProperties.vehicle.ChassisNumber;
                handHeldService.VehicleOwner owner = new VSDApp.handHeldService.VehicleOwner();
                if (AppProperties.vehicle.Operator != null)
                    owner.ownerName = AppProperties.vehicle.Operator.OperatorName;
                else
                    owner.ownerName = "";
                owner.ownerNameArabic = AppProperties.vehicle.Operator.OperatorNameAr;
                owner.trafficFileNumber = AppProperties.vehicle.Operator.TrafficFileNumber;
                veh.owner = owner;
                handHeldService.VehicleCategory vehCat = new VSDApp.handHeldService.VehicleCategory();
                vehCat.code = ((IDBDataLoad)DBDataLoadManager.GetInstance()).GetVehicleCategoryCode((AppProperties.vehicle.VehicleCategory != null) ? AppProperties.vehicle.VehicleCategory : AppProperties.vehicle.VehicleCategoryAr).Trim();
                veh.category = vehCat;
                VSDApp.handHeldService.VehicleManufacturer manu = new VSDApp.handHeldService.VehicleManufacturer();
                manu.name = AppProperties.vehicle.Make;
                manu.model = AppProperties.vehicle.Model;
                veh.manufacturedYear = AppProperties.vehicle.Year;
                veh.manufacturer = manu;


                //create violation here


                if (null != AppProperties.recordedViolation.Defect && AppProperties.recordedViolation.Defect.Length > 0)
                {
                    //create violation
                    handHeldService.Violation violation = new VSDApp.handHeldService.Violation();
                    violation.comments = AppProperties.recordedViolation.ViolationComments;
                    violation.commentsArabic = AppProperties.recordedViolation.ViolationCommentsAr;
                    violation.provisionalTicketNumber = "?";

                    handHeldService.Defect[] defect = new VSDApp.handHeldService.Defect[AppProperties.recordedViolation.Defect.Length];

                    for (int i = 0; i < defect.Length; i++)
                    {
                        defect[i] = new VSDApp.handHeldService.Defect();
                        defect[i].comment = AppProperties.recordedViolation.Defect[i].DefectValue.Trim();
                        defect[i].code = iDataLoad.GetDefectCode(AppProperties.recordedViolation.Defect[i].DefectID).Trim();

                    }
                    violation.defects = defect;
                    inspection.violation = violation;
                    if (AppProperties.recordedViolation.IsConfiscated)
                    {
                        inspection.plateConfiscatedReason = (null != AppProperties.recordedViolation.ConfiscationReason) ? AppProperties.recordedViolation.ConfiscationReason : "NA";
                        inspection.plateConfiscatedReasonArabic = (null != AppProperties.recordedViolation.ConfiscationReasonAr) ? AppProperties.recordedViolation.ConfiscationReasonAr : "NA";
                    }

                    handHeldService.VehicleDriver driver = new VSDApp.handHeldService.VehicleDriver();
                    driver.name = ("" != AppProperties.vehicle.DriverName) ? AppProperties.vehicle.DriverName : "NA";
                    driver.nameArabic = ("" != AppProperties.vehicle.DriverNameAr) ? AppProperties.vehicle.DriverNameAr : "NA";
                    driver.licenseNumber = ("" != AppProperties.vehicle.DriverLicense) ? AppProperties.vehicle.DriverLicense : "NA";
                    veh.driver = driver;
                    //To Do
                    //inspection.isPlateConfiscated = (AppProperties.recordedViolation.IsConfiscated) ? "T" : "F";
                    inspection.isPlateConfiscated = "F";
                    inspection.isRegistrationExpired = "F";
                }
                else
                {

                   // inspection.isPlateConfiscated = (AppProperties.recordedViolation.IsConfiscated) ? "T" : "F";
                    inspection.isPlateConfiscated = "F";
                    inspection.isRegistrationExpired = "F";

                }



                inspection.vehicle = veh;
                //inspection.time = AppProperties.recordedViolation.ViolationIssueDate;

                handHeldService.HandHeldService hh = new VSDApp.handHeldService.HandHeldService();
                hh.authHeader = header;
                hh.Timeout = 180000;
                respItem = hh.submitViolation("RC123", inspection);



                if (respItem.response.code.Equals("1000"))
                {
                    //create violation here


                    if (null != AppProperties.recordedViolation.Defect && AppProperties.recordedViolation.Defect.Length > 0)
                    {
                        //System.Windows.Forms.MessageBox.Show("Violation Uploaded");
                        handHeldService.Inspection savedInspection = new VSDApp.handHeldService.Inspection();
                        savedInspection = respItem.savedInspection;
                        AppProperties.recordedViolation.ViolationDueDays = (savedInspection.violation.dueDateSpecified) ? savedInspection.violation.dueDate : AppProperties.recordedViolation.ViolationDueDays;
                        AppProperties.recordedViolation.ViolationSeverity = savedInspection.violation.severityLevel.value;
                        AppProperties.recordedViolation.ViolationTicketCode = savedInspection.violation.ticketNumber;
                        AppProperties.recordedViolation.ViolationTestType = savedInspection.violation.testTypeName;
                        AppProperties.vehicle.VehicleSuspensionDate = (savedInspection.violation.vehicleSuspensionDateSpecified) ? savedInspection.violation.vehicleSuspensionDate : AppProperties.vehicle.VehicleSuspensionDate;
                        AppProperties.vehicle.Operator.CompanySuspensionDate = (savedInspection.violation.ownerSuspensionDateSpecified) ? savedInspection.violation.ownerSuspensionDate : AppProperties.vehicle.Operator.CompanySuspensionDate;


                        return true;

                    }
                    else
                    {
                        /////////////////////////
                       // Ispe
                        
                        /////
                        AppProperties.isInspectionUploaded = true;
                        /*
                        if (AppProperties.Selected_Resource == "English")
                            System.Windows.MessageBox.Show("Inspection Uploaded")
                        else
                            System.Windows.MessageBox.Show("تم تسجيل عملية التفتيش بنجاح");*/
                        AppProperties.recordedViolation.ViolationTicketCode = respItem.response.message;
                        return true;
                    }

                }
                else if (respItem.response.code.Equals("2000"))
                {
                    AppProperties.businessError = true;
                    AppProperties.errorMessageFromBusiness = respItem.response.message;
                    return true;
                }
                else
                {
                   // System.Windows.MessageBox.Show(respItem.response.message);
                    //return ((IDBManager)DBOfflineDataManager.GetInstance()).StoreOfflineData();
                    AppProperties.NotFoundError = true;
                    AppProperties.errorMessageFromBusiness = respItem.response.message;
                    AppProperties.vehicle = null;
                    return false;
                }


            }
            catch (Exception e)
            {
              //  CommonUtils.WriteLog(e.StackTrace);
              //  System.Windows.MessageBox.Show("Unable to connect: " + e.Message);
                //and generate provisional id and rest of the information. if defects exists
                AppProperties.IsException = true;
                AppProperties.errorMessageFromBusiness = e.InnerException.Message;
                return ((IDBManager)DBOfflineDataManager.GetInstance()).StoreOfflineData();

            }


        }