Exemple #1
0
 public override void Save()
 {
     try
     {
         int Id = 0;
         foreach (var item in grdLister.Rows)
         {
             Id = item.Cells["Id"].Value.ToInt();
             if (Id > 0)
             {
                 objMaster.GetByPrimaryKey(Id);
                 objMaster.Edit();
                 objMaster.Current.PerMinJourneyCharges = item.Cells[COLS.PerMinJourneyCharges].Value.ToDecimal();
                 objMaster.CheckDataValidation          = false;
                 objMaster.Save();
                 objMaster.Clear();
             }
         }
     }
     catch (Exception ex)
     {
         if (objMaster.Errors.Count > 0)
         {
             ENUtils.ShowMessage(objMaster.ShowErrors());
         }
         else
         {
             ENUtils.ShowMessage(ex.Message);
         }
     }
 }
Exemple #2
0
        public frmPDAMeterFares(int vehicleTypeId)
        {
            InitializeComponent();
            InitializeConstructors();


            ddlVehicleType.SelectedValue = vehicleTypeId;
            int fareId = General.GetObject <Fare>(c => c.VehicleTypeId == vehicleTypeId && c.CompanyId == null).DefaultIfEmpty().Id;

            ddlVehicleType.Enabled = false;

            objMaster.GetByPrimaryKey(fareId);
            OnDisplayRecord(fareId);

            if (ddlVehicleType.Text.Trim().Length > 0)
            {
                this.FormTitle = "Fare Meter Settings for " + ddlVehicleType.Text.Trim();
            }
        }
        public override void Save()
        {
            FareBO objFareMaster = null;

            try
            {
                int vehicleId = 0;


                string  oldFrom = string.Empty;
                string  vehicle = string.Empty;
                string  from    = string.Empty;
                string  to      = string.Empty;
                decimal fares   = 0.00m;

                int?fromLocId     = null;
                int?toLocId       = null;
                int?fromLocTypeId = null;
                int?toLocTypeId   = null;

                List <Fleet_VehicleType> listOfVehicle   = AppVars.BLData.GetQueryable <Fleet_VehicleType>(null).ToList();
                List <Gen_Location>      listOfLocations = General.GetQueryable <Gen_Location>(null).ToList();


                LocationBO objLocationMaster = null;

                int recordNo = 0;
                foreach (var row in grdFixFares.Rows)
                {
                    if (!string.IsNullOrEmpty(row.Cells[COLS.VehicleName].Value.ToStr()))
                    {
                        vehicle = row.Cells[COLS.VehicleName].Value.ToStr();
                    }

                    from    = row.Cells[COLS.From].Value.ToStr().ToUpper();
                    oldFrom = from;

                    if (!string.IsNullOrEmpty(row.Cells[COLS.To].Value.ToStr().ToUpper()))
                    {
                        to = row.Cells[COLS.To].Value.ToStr().ToUpper();
                    }

                    if (row.Cells[COLS.Fare].Value.ToStr().StartsWith("£"))
                    {
                        fares = row.Cells[COLS.Fare].Value.ToStr().Substring(1).ToDecimal();
                    }
                    else
                    {
                        fares = row.Cells[COLS.Fare].Value.ToDecimal();
                    }



                    if (string.IsNullOrEmpty(from))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(to))
                    {
                    }

                    vehicleId = listOfVehicle.FirstOrDefault(c => c.VehicleType.ToLower().Trim() == vehicle).DefaultIfEmpty().Id;

                    if (vehicleId == 0)
                    {
                        // row.Cells[COLS.Status].Value = "Required : Vehicle";
                        continue;
                    }



                    Gen_Location objLoc = listOfLocations.FirstOrDefault(c =>
                                                                         ((c.LocationName.ToUpper().Trim() + " " + c.PostCode.ToUpper()) == from) ||
                                                                         (c.PostCode == from));


                    if (objLoc == null)
                    {
                        objLocationMaster = new LocationBO();

                        try
                        {
                            objLocationMaster.New();

                            from = General.GetPostCodeMatch(from);



                            if (string.IsNullOrEmpty(from))
                            {
                            }

                            objLocationMaster.Current.LocationName   = from;
                            objLocationMaster.Current.PostCode       = from;
                            objLocationMaster.Current.LocationTypeId = Enums.LOCATION_TYPES.POSTCODE;

                            objLocationMaster.Save();
                        }
                        catch (Exception ex)
                        {
                            if (objLocationMaster.Errors.Count > 0)
                            {
                                ENUtils.ShowMessage(objLocationMaster.ShowErrors());
                            }
                            else
                            {
                                ENUtils.ShowMessage(ex.Message);
                            }
                            break;
                        }

                        objLoc = objLocationMaster.Current;

                        listOfLocations.Add(objLoc);
                    }

                    fromLocId     = objLoc.Id;
                    fromLocTypeId = objLoc.LocationTypeId;



                    objLoc = listOfLocations.FirstOrDefault(c =>
                                                            ((c.LocationName.ToUpper().Trim() + " " + c.PostCode.ToUpper()) == to) ||
                                                            (c.PostCode == to));

                    if (objLoc == null)
                    {
                        objLocationMaster = new LocationBO();

                        try
                        {
                            objLocationMaster.New();


                            to = General.GetPostCodeMatch(to);

                            // to = General.GetPostCodeMatch(to);


                            if (to.Contains(' ') == false)
                            {
                            }

                            objLocationMaster.Current.LocationName   = to;
                            objLocationMaster.Current.PostCode       = to;
                            objLocationMaster.Current.LocationTypeId = Enums.LOCATION_TYPES.POSTCODE;

                            objLocationMaster.Save();
                        }
                        catch (Exception ex)
                        {
                            if (objLocationMaster.Errors.Count > 0)
                            {
                                ENUtils.ShowMessage(objLocationMaster.ShowErrors());
                            }
                            else
                            {
                                ENUtils.ShowMessage(ex.Message);
                            }
                            break;
                        }
                        objLoc = objLocationMaster.Current;
                        listOfLocations.Add(objLoc);
                    }

                    toLocId     = objLoc.Id;
                    toLocTypeId = objLoc.LocationTypeId;


                    if (recordNo == 0)
                    {
                        objFareMaster = new FareBO();


                        int fareId = General.GetObject <Fare>(c => c.VehicleTypeId == vehicleId).DefaultIfEmpty().Id;

                        if (fareId > 0)
                        {
                            objFareMaster.GetByPrimaryKey(fareId);
                        }
                        else
                        {
                            objFareMaster.New();
                        }


                        objFareMaster.Current.VehicleTypeId = vehicleId;
                        objFareMaster.Current.IsCompanyWise = false;
                    }

                    objFareMaster.Current.Fare_ChargesDetails.Add(new Fare_ChargesDetail
                    {
                        OriginId                  = fromLocId,
                        DestinationId             = toLocId,
                        OriginLocationTypeId      = fromLocTypeId,
                        DestinationLocationTypeId = toLocTypeId,
                        Rate = fares
                    });

                    recordNo++;
                }

                objFareMaster.Save();
            }
            catch (Exception ex)
            {
                if (objFareMaster.Errors.Count > 0)
                {
                    ENUtils.ShowMessage(objFareMaster.ShowErrors());
                }
                else
                {
                    ENUtils.ShowMessage(ex.Message);
                }
            }
        }