/// <summary>
        /// Reverts changes made to the water meter reading control is there is an update pending.
        /// </summary>
        /// <param name="relationshipViewModel"></param>
        private void CancelWaterSystemAction(WaterMeterViewModel waterSystemViewModel)
        {
            bool      undo      = false;
            ChangeSet changeSet = this.dc.GetChangeSet();

            foreach (var v in changeSet.Updates)
            {
                if (typeof(Property) == v.GetType())
                {
                    Property p = v as Property;
                    if (this.SelectedProperty.PropertyID == p.PropertyID)
                    {
                        undo = true;
                    }
                }
                if (typeof(WaterMeterReading) == v.GetType())
                {
                    WaterMeterReading w = v as WaterMeterReading;
                    if (this.SelectedProperty.PropertyID == w.PropertyID)
                    {
                        undo = true;
                    }
                }

                if (undo)
                {
                    this.dc.Refresh(RefreshMode.OverwriteCurrentValues, v);
                    undo = false;
                }
            }
        }
Ejemplo n.º 2
0
 public JsonResult AddRegisteredReading(RegisteredWaterMeterReadingViewModel viewModel)
 {
     try
     {
         using (VesiPortalDbContext context = new VesiPortalDbContext())
         {
             RegisteredWaterMeterReading registeredWaterMeterReading = new RegisteredWaterMeterReading
             {
                 Guid           = Guid.NewGuid(),
                 WaterMeterGuid = viewModel.WaterMeterGuid,
                 Reading        = viewModel.Reading,
                 ReadingDate    = viewModel.ReadingDate
             };
             WaterMeterReading.Add(context, registeredWaterMeterReading);
         }
         return(Json(data: new { Valid = true, Message = Messages.WaterMeterReadingAdded },
                     behavior: JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(data: new
         {
             Valid = false,
             ErrorMessage = ErrorMessages.WaterMeterReadingAddError
         },
                     behavior: JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="row"></param>
 /// <returns></returns>
 internal static string IsWaterMeterReadingRowValid(WaterMeterReading row)
 {
     if (String.IsNullOrEmpty(row.ReadingDate.ToString()))
     {
         return("Date");
     }
     else if (String.IsNullOrEmpty(row.MeterReading.ToString()))
     {
         return("Reading");
     }
     else
     {
         return(String.Empty);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Validates a grid row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tableViewDetail_ValidateRow(object sender, DevExpress.Xpf.Grid.GridRowValidationEventArgs e)
        {
            WaterMeterViewModel vm  = this.DataContext as WaterMeterViewModel;
            WaterMeterReading   row = e.Row as WaterMeterReading;

            try
            {
                if (null != row)
                {
                    // Rule-1:  All required fields must contain data
                    string results = ValidationRules.IsWaterMeterReadingRowValid((WaterMeterReading)e.Row);
                    if (!String.IsNullOrEmpty(results))
                    {
                        e.IsValid      = false;
                        e.ErrorType    = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical;
                        e.ErrorContent = "The highlighted field cannot be blank";
                        e.SetError(e.ErrorContent);
                        return;
                    }
                    // Rule-2: Meter Reading must be greater than previous reading.
                    //if (row.ReadingDate <= vm.SelectedProperty.LastMeterEntry.ReadingDate ||
                    //    row.MeterReading <= vm.SelectedProperty.LastMeterEntry.MeterReading)
                    if (row.ReadingDate <= vm.SelectedProperty.ReadingDate ||
                        row.MeterReading <= vm.SelectedProperty.MeterReading)
                    {
                        e.IsValid      = false;
                        e.ErrorType    = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical;
                        e.ErrorContent = "The highlighted field cannot be less then the previous reading";
                        e.SetError(e.ErrorContent);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Row Error: " + ex.Message);
            }
            finally
            {
                if (e.IsValid)
                {
                    //row.Consumption = vm.CalculateWaterConsumption();
                    //row.PropertyID = vm.SelectedProperty.PropertyID; // assign the PropertID since it's a FK
                }
                e.Handled = true;
            }
        }
Ejemplo n.º 5
0
 public JsonResult AddUnregisteredReading(UnregisteredWaterMeterReadingViewModel viewModel)
 {
     try
     {
         using (VesiPortalDbContext context = new VesiPortalDbContext())
         {
             UnregisteredWaterMeterReading unregisteredWaterMeterReading = Mapper.Map <UnregisteredWaterMeterReading>(viewModel);
             WaterMeterReading.Add(context, unregisteredWaterMeterReading);
         }
         return(Json(data: new { Valid = true, Message = Messages.WaterMeterReadingAdded },
                     behavior: JsonRequestBehavior.AllowGet));
     }
     catch (Exception)
     {
         return(Json(data: new {
             Valid = false, ErrorMessage = ErrorMessages.WaterMeterReadingAddError
         },
                     behavior: JsonRequestBehavior.AllowGet));
     }
 }
Ejemplo n.º 6
0
        public ActionResult AddMeterReading(FormCollection frm, string PreviousReading)
        {
            var    userid    = User.Identity.GetUserId();
            string ZoneGroup = context.Users.FirstOrDefault(m => m.Id == userid).ZoneGroup;
            var    username  = User.Identity.GetUserName();
            RoleAssignmentMatrix roleAssignmentMatrix = db.RoleAssignmentMatrix.FirstOrDefault(m => m.UserName == username);

            ViewBag.IsValidRole = roleAssignmentMatrix.Water;

            SearchWaterViewModel SearchWaterViewModels = new SearchWaterViewModel();
            WaterMeterReading    waterMeterReading     = new WaterMeterReading();

            TryUpdateModel(waterMeterReading);
            int    CompanyID   = int.Parse(frm["CompanyID"].ToString());
            string MeterNumber = frm["MeterNumber"].ToString();

            waterMeterReading.CompanyId   = CompanyID;
            waterMeterReading.MeterNumber = MeterNumber;
            //var errors = ModelState.Values.SelectMany(v => v.Errors);
            if (ModelState.IsValid)
            {
                int     BillingPeriod    = int.Parse(frm["BillingPeriod"].ToString());
                decimal PreviousReading1 = decimal.Parse(frm["PreviousReading"].ToString());
                decimal PresentReading   = decimal.Parse(frm["PresentReading"].ToString());
                string  remarks          = frm["remarks"].ToString();
                string  isEdit           = frm["isEdit"].ToString();
                bool    threeMonthsAvg   = false;
                if (frm["MonthAverage"].ToString() != "")
                {
                    threeMonthsAvg = true;
                    decimal avg = decimal.Parse(frm["MonthAverage"].ToString());
                    PresentReading += avg;
                }
                if (isEdit.ToLower() == "add")
                {
                    var recordExist = db.WaterMeterReading.Any(m => m.BillingPeriod == BillingPeriod && m.MeterNumber == MeterNumber);
                    if (!recordExist)
                    {
                        //waterMeterReading.BillingPeriod = BillingPeriod;//ok
                        //waterMeterReading.PresentReading = PresentReading;//ok
                        //waterMeterReading.PreviousReading = PreviousReading1;//OK
                        //waterMeterReading.CreatedBy = userid;//ok
                        //waterMeterReading.CreateDate = DateTime.Now;//ok
                        //waterMeterReading.remarks = remarks;

                        db.Database.ExecuteSqlCommand("insert into WaterMeterReadings(CompanyId,BillingPeriod,MeterNumber,PreviousReading,PresentReading,CreateDate,CreatedBy,remarks,UseThreeMonthsAverage) values('" + CompanyID + "','" + BillingPeriod + "','" + MeterNumber + "','" + PreviousReading1 + "','" + PresentReading + "','" + DateTime.Now + "','" + userid + "','" + remarks + "','" + threeMonthsAvg + "')");
                        SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Water - Add meter reading  - from Terminal: " + ipaddress);
                        TempData["TransactionSuccess"] = "Add";
                        //db.WaterMeterReading.Add(waterMeterReading);
                        //db.SaveChanges();
                    }
                    else
                    {
                        TempData["TransactionSuccess"] = "WaterReadingFailed";
                    }
                }
                else if (isEdit.ToLower() == "edit")
                {
                    int waterMeterId = int.Parse(frm["meterid"].ToString());
                    //WaterMeterReading waterreading = new WaterMeterReading();
                    //waterreading = db.WaterMeterReading.Find(waterMeterId);
                    //waterreading.PresentReading = PresentReading;
                    //waterreading.PreviousReading = PreviousReading1;
                    //waterreading.remarks = remarks;

                    db.Database.ExecuteSqlCommand("Update WaterMeterReadings set UpdatedBy='" + userid + "',BillingPeriod = '" + BillingPeriod + "',UpdateDate='" + DateTime.Now + "', PresentReading = '" + PresentReading + "',PreviousReading = '" + PreviousReading1 + "',remarks='" + remarks + "',UseThreeMonthsAverage='" + threeMonthsAvg + "' where WaterMeterReadingId='" + waterMeterId + "'");
                    //Use execute sql command coz ef use only 2 decimal places
                    SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Water - Edit meter reading  - from Terminal: " + ipaddress);
                    TempData["TransactionSuccess"] = "Edit";
                    //db.Entry(waterreading).State = System.Data.Entity.EntityState.Modified;
                    //db.SaveChanges();
                }

                ViewBag.ValidatePostback = "True";
            }
            else
            {
                ViewBag.ValidatePostback = "False";
            }


            ViewBag.CompanySelected = "OK";
            SearchWaterViewModels.BillingPeriods        = BillingPeriods();
            SearchWaterViewModels.Companies             = db.Company.Where(m => m.CompanyID == CompanyID).ToList();
            SearchWaterViewModels.WaterMeterAssignments = db.WaterMeterAssignment.Where(m => m.MeterNumber == MeterNumber).ToList();
            SearchWaterViewModels.WaterMeterReadings    = db.WaterMeterReading.Where(m => m.MeterNumber == MeterNumber).OrderByDescending(x => x.PresentReading).ToList();
            SearchWaterViewModels.BillingPeriods        = BillingPeriods();
            decimal?sewerageRate = db.BillingRates.FirstOrDefault(m => m.ZoneGroup == ZoneGroup && m.Category.ToUpper() == "SEWERAGE").Rate;

            TempData["SewerageRate"]     = sewerageRate;
            TempData["WaterReadingData"] = SearchWaterViewModels;

            SL.LogInfo(User.Identity.Name, Request.RawUrl, "Data Entry Water - Meter Reading Added  - from Terminal: " + ipaddress);

            return(RedirectToAction("ViewWaterReadingPRG", "DataEntryWater"));
            //return View("ViewWaterReading", SearchWaterViewModels);
        }