Beispiel #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;
            }
        }