public List <WellCompletion> GetCompletionsBySearchDate(GenericSearch search)
        {
            try
            {
                var wellCompletions = new WellCompletionServices().GetAllOrderedCompletionsByMonth(search.Month, search.Year);

                if (!wellCompletions.Any())
                {
                    return(new List <WellCompletion>());
                }

                wellCompletions.ForEach(m =>
                {
                    m.EquipmentName          = m.Equipment.Name;
                    m.WellName               = m.Well.Name;
                    m.WellCompletionTypeName = m.WellCompletionType.Type;
                    m.EquipmentName          = m.Equipment.Name;
                });
                return(wellCompletions);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(new List <WellCompletion>());
            }
        }
Exemplo n.º 2
0
        public ActionResult GetWellCompletions2(int queryId)
        {
            if (queryId < 1)
            {
                return(Json(new List <WellCompletionReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var query = new WellCompletionQueryBuilderServices().GetWellCompletionQuery(queryId);

            if (query == null || query.WellCompletionQueryId < 1)
            {
                return(Json(new List <WellCompletionReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var wellCompletionList = new WellCompletionServices().GetWellCompletionReports(query) ?? new List <WellCompletionReportObject>();

            if (!wellCompletionList.Any())
            {
                return(Json(new List <WellCompletionReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var jsonResult = Json(wellCompletionList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
        public ViewResult WellCompletionIntervals()
        {
            var wellCompletionList = new WellCompletionServices().GetAllOrderedWellCompletions() ?? new List <WellCompletion>();

            if (!wellCompletionList.Any())
            {
                ViewBag.Edit  = 1;
                ViewBag.Title = "Well Completion SetUp";
                var wellCompletionTypeList = new WellCompletionTypeServices().GetAllOrderedWellCompletionTypes() ?? new List <WellCompletionType>();

                if (!wellCompletionTypeList.Any())
                {
                    ViewBag.Edit  = 0;
                    ViewBag.Title = "Well Completion Type SetUp";
                    return(View("~/Views/WellCompletionType/WellCompletionTypes.cshtml", new List <WellCompletionType>()));
                }
            }

            wellCompletionList.ForEach(m =>
            {
                m.WellName = m.Well.Name;
                m.WellCompletionTypeName = m.WellCompletionType.Type;
                m.EquipmentName          = m.Equipment.Name;
            });

            var wellCompletionIntervalList = new WellCompletionIntervalServices().GetAllOrderedWellCompletionIntervals() ?? new List <WellCompletionInterval>();

            if (!wellCompletionIntervalList.Any())
            {
                ViewBag.Edit  = 0;
                ViewBag.Title = "Well Completion Interval SetUp";
                return(View(Tuple.Create(wellCompletionList, new List <WellCompletionInterval>())));
            }

            wellCompletionIntervalList.ForEach(m =>
            {
                m.DatecomPletedString = m.DateCompleted;
                m.WellName            = wellCompletionList.Find(x => x.WellId == m.WellCompletion.WellId).Well.Name;
            });

            var txx = Tuple.Create(wellCompletionList, wellCompletionIntervalList);

            ViewBag.Title = "Manage Well Completion Intervals";
            return(View(txx));
        }
        private List <WellCompletionObject> GetWellComletionObjects(int itemsPerPage, int pageNumber)
        {
            try
            {
                var wellCompletions = new WellCompletionServices().GetWellObjects(itemsPerPage, pageNumber);

                if (!wellCompletions.Any())
                {
                    return(new List <WellCompletionObject>());
                }

                return(wellCompletions);
            }
            catch (Exception ex)
            {
                return(new List <WellCompletionObject>());
            }
        }
        private List <WellCompletionReportObject> GetWellCompletionStaticReports(int itemsPerPage, int pageNumber, GenericSearch search)
        {
            try
            {
                var wellCompletions = new WellCompletionServices().GetWellStaticCompletionReport(itemsPerPage, pageNumber, search.Month, search.Year);

                if (!wellCompletions.Any())
                {
                    return(new List <WellCompletionReportObject>());
                }


                return(wellCompletions);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(new List <WellCompletionReportObject>());
            }
        }
        private List <WellCompletion> GetWellComletions(int itemsPerPage, int pageNumber, out int dataCount)
        {
            try
            {
                var wellCompletions = new WellCompletionServices().GetAllOrderedWellCompletions(itemsPerPage, pageNumber, out dataCount);

                if (!wellCompletions.Any())
                {
                    dataCount          = 0;
                    ViewBag.TotalPages = 0;
                    ViewBag.Page       = 1;
                    return(new List <WellCompletion>());
                }
                ViewBag.PrDataCount = dataCount.ToString(CultureInfo.InvariantCulture);

                var totalPages = dataCount / itemsPerPage;

                if (dataCount % itemsPerPage != 0)
                {
                    totalPages++;
                }

                ViewBag.PrTotalPages = totalPages;
                ViewBag.PrPage       = pageNumber;
                wellCompletions.ForEach(m =>
                {
                    m.WellName = m.Well.Name;
                    m.WellCompletionTypeName = m.WellCompletionType.Type;
                    m.EquipmentName          = m.Equipment.Name;
                });

                return(wellCompletions);
            }
            catch (Exception ex)
            {
                dataCount          = 0;
                ViewBag.TotalPages = 0;
                ViewBag.Page       = 1;
                return(new List <WellCompletion>());
            }
        }
        private List <WellCompletion> GetWellComletionReportByQueryPeriods(GenericSearch search)
        {
            try
            {
                var wellCompletions = new WellCompletionServices().GetAllOrderedWellCompletionReportByPeriod(search.Month, search.Year);

                if (!wellCompletions.Any())
                {
                    return(new List <WellCompletion>());
                }

                return(wellCompletions);
            }
            catch (Exception ex)
            {
                //dataCount = 0;
                //ViewBag.TotalPages = 0;
                //ViewBag.Page = 1;
                return(new List <WellCompletion>());
            }
        }
Exemplo n.º 8
0
        private List <DocObject> GetYears()
        {
            var jxs = new WellCompletionServices().GetWellCompletionYears();

            if (!jxs.Any())
            {
                return(new List <DocObject>());
            }
            var tdv = new List <DocObject>();

            jxs.ForEach(m =>
            {
                var ts = int.Parse(m);

                if (!tdv.Exists(t => t.DocId == ts))
                {
                    tdv.Add(new DocObject {
                        DocName = m, DocId = ts
                    });
                }
            });
            return(tdv.OrderByDescending(m => m.DocName).ToList());
        }
Exemplo n.º 9
0
        public ActionResult GetWellCompletions(WellCompletionQuery queryBuilder)
        {
            if (queryBuilder == null)
            {
                return(Json(new List <WellCompletionReportObject>(), JsonRequestBehavior.AllowGet));
            }

            if (queryBuilder.EquipmentId < 1 && queryBuilder.WellTypeId < 1 && queryBuilder.CompanyId < 1 && ((queryBuilder.StartDate != null && queryBuilder.StartDate.Value.Year == 0001) || (queryBuilder.StartDate == null)) && ((queryBuilder.EndDate != null && queryBuilder.EndDate.Value.Year == 0001) || (queryBuilder.EndDate == null)) && queryBuilder.CompletionTypeId < 1 && queryBuilder.WellClassId < 1 && queryBuilder.TerrainId < 1 && queryBuilder.ZoneId < 1 && queryBuilder.WellId < 1)
            {
                return(Json(new List <WellCompletionReportObject>(), JsonRequestBehavior.AllowGet));
            }

            var wellCompletionList = new WellCompletionServices().GetWellCompletionReports(queryBuilder) ?? new List <WellCompletionReportObject>();

            if (!wellCompletionList.Any())
            {
                return(Json(new List <WellCompletionReportObject>(), JsonRequestBehavior.AllowGet));
            }
            Session["_successfulWellCompletionQuery"] = queryBuilder;
            var jsonResult = Json(wellCompletionList, JsonRequestBehavior.AllowGet);

            jsonResult.MaxJsonLength = int.MaxValue;
            return(jsonResult);
        }
        private WellCompletion ProcessRecord2(DataRowView dv, ref string msg, int completionTypeId)
        {
            if (dv == null)
            {
                return(null);
            }
            try
            {
                var wellName = dv.Row["wellname"].ToString().Replace(" ", "").Replace(",", "").Trim();

                if (string.IsNullOrEmpty(wellName.Trim()))
                {
                    return(null);
                }

                var mInfo = new WellCompletion
                {
                    WellName = wellName,
                };

                var ttcg = new WellServices().GetWellIdByName(wellName);

                if (ttcg < 1)
                {
                    msg = "Well Information could not be processed";
                    return(null);
                }

                mInfo.WellId = ttcg;

                var year = dv.Row["datecompleted(yyyy/MM/dd)"].ToString().Trim();
                if (string.IsNullOrEmpty(year))
                {
                    msg = "Completion Date is empty.";
                    return(null);
                }
                else
                {
                    DateTime outYear;
                    var      yrResult = DateTime.TryParse(year, out outYear);
                    if (!yrResult)
                    {
                        msg = "Completion Date is empty.";
                        return(null);
                    }
                    else
                    {
                        mInfo.DateCompleted = outYear;
                    }
                }

                var completionStatus = dv.Row["isinitialcompletion(YES/NO)"].ToString().Trim();

                if (string.IsNullOrEmpty(completionStatus))
                {
                    msg = "Please indicate if Well Completion is Initial or ortherwise.";
                    return(null);
                }
                else
                {
                    if (completionStatus.Trim().ToLower().Replace(" ", "") == "yes")
                    {
                        mInfo.IsInitial = true;
                    }
                    if (completionStatus.Trim().ToLower().Replace(" ", "") == "no")
                    {
                        mInfo.IsInitial = false;
                    }
                }
                double l1;
                double up1;
                double l2;
                double up2;
                var    lowerInter1 = dv.Row["lower_interval_1"].ToString().Trim();
                if (string.IsNullOrEmpty(lowerInter1))
                {
                    msg = "Please provide lower Interval 1.";
                    return(null);
                }
                else
                {
                    double outLint;
                    var    dtResult = double.TryParse(lowerInter1, out outLint);
                    if (!dtResult && outLint < 1)
                    {
                        msg = "Please provide a valid lower Interval 1.";
                        return(null);
                    }
                    else
                    {
                        l1 = outLint;
                    }
                }

                var upperInter = dv.Row["upper_interval_1"].ToString().Trim();
                if (string.IsNullOrEmpty(upperInter))
                {
                    msg = "Please provide Upper Interval 1.";
                    return(null);
                }
                else
                {
                    double outUpint;
                    var    dtResult = double.TryParse(upperInter, out outUpint);
                    if (!dtResult && outUpint < 1)
                    {
                        msg = "Please provide a valid Upper Interval 1.";
                        return(null);
                    }
                    else
                    {
                        up1 = outUpint;
                    }
                }

                var lowerInter2 = dv.Row["lower_interval_2"].ToString().Trim();
                if (string.IsNullOrEmpty(lowerInter2))
                {
                    msg = "Please provide lower Interval 2.";
                    return(null);
                }
                else
                {
                    double outLint2;
                    var    dtResult = double.TryParse(lowerInter2, out outLint2);
                    if (!dtResult && outLint2 < 1)
                    {
                        msg = "Please provide a valid lower Interval 2.";
                        return(null);
                    }
                    else
                    {
                        l2 = outLint2;
                    }
                }

                var upperInter2 = dv.Row["upper_interval_2"].ToString().Trim();
                if (string.IsNullOrEmpty(upperInter2))
                {
                    msg = "Please provide Upper Interval 2.";
                    return(null);
                }
                else
                {
                    double outUpint2;
                    var    dtResult = double.TryParse(upperInter2, out outUpint2);
                    if (!dtResult && outUpint2 < 1)
                    {
                        msg = "Please provide a valid Upper Interval 2.";
                        return(null);
                    }
                    else
                    {
                        up2 = outUpint2;
                    }
                }


                if (!string.IsNullOrEmpty(dv.Row["equipmentused"].ToString().Trim()))
                {
                    var dfv         = dv.Row["equipmentused"].ToString().Trim();
                    var equipmentId = new EquipmentServices().GetEquipmentId(dfv);
                    if (equipmentId < 1)
                    {
                        msg = "Equipment Information could not be processed";
                        return(null);
                    }

                    mInfo.EquipmentId = equipmentId;
                }
                else
                {
                    msg = "Equipment used empty.";
                    return(null);
                }

                mInfo.WellCompletionTypeId = completionTypeId;

                var vvz = new WellCompletionServices().AddWellCompletionCheckDuplicate3(mInfo);
                if (vvz < 1)
                {
                    msg = "Well Completion Interval for the same Period, Reason, Completion Type and Equipment already exists for this well.";
                    return(null);
                }

                var wellCompInt = new WellCompletionInterval
                {
                    LowerInterval    = l1,
                    WellCompletionId = vvz,
                    UpperInterval    = up1,
                    DateCompleted    = mInfo.DateCompleted.ToString(),
                    LastUpdatedTime  = DateTime.Now.ToString("G")
                };

                var vvzk = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(wellCompInt);
                if (vvzk < 1)
                {
                    msg = "Well Completion Information could not be processed.";
                    return(null);
                }

                var tdd = new WellCompletionInterval
                {
                    LowerInterval    = l2,
                    WellCompletionId = vvz,
                    UpperInterval    = up2,
                    DateCompleted    = mInfo.DateCompleted.ToString(),
                    LastUpdatedTime  = DateTime.Now.ToString("G")
                };

                var vvzk2 = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(tdd);
                if (vvzk2 < 1)
                {
                    new WellCompletionIntervalServices().DeleteWellCompletionIntervalCheckReferences(vvzk);
                    msg = "Well Completion Information could not be processed.";
                    return(null);
                }

                return(mInfo);
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
        public ActionResult EditWellCompletion(int id)
        {
            var wellCompletion = new WellCompletion();

            try
            {
                if (id < 1)
                {
                    wellCompletion.Error     = "Invalid Selection!";
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                var myViewObj = new WellCompletionServices().GetWellCompletion(id);

                if (myViewObj == null || myViewObj.WellCompletionId < 1)
                {
                    wellCompletion.Error     = "Well Completion  Information could not be retrieved.";
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                var welllcompObj = new WellCompletionObject
                {
                    DatecomPletedString = myViewObj.DatecomPletedString,
                    WellCompletionId    = myViewObj.WellCompletionId,
                    WellId               = myViewObj.WellId,
                    EquipmentId          = myViewObj.EquipmentId,
                    WellCompletionTypeId = myViewObj.WellCompletionTypeId,
                    IsInitial            = myViewObj.IsInitial
                };

                if (myViewObj.WellCompletionIntervals.Any())
                {
                    var intervals = myViewObj.WellCompletionIntervals.ToList();

                    if (myViewObj.WellCompletionTypeId > 1)
                    {
                        var upperInt = intervals.Max(m => m.UpperInterval);
                        var lowerInt = intervals.Min(m => m.UpperInterval);

                        if (lowerInt > 0)
                        {
                            var interval1 = intervals.Find(m => m.UpperInterval.Equals(lowerInt));
                            if (interval1 != null && interval1.WellCompletionIntervalId > 0)
                            {
                                welllcompObj.L1          = interval1.LowerInterval;
                                welllcompObj.U1          = interval1.UpperInterval;
                                welllcompObj.IntervalId1 = interval1.WellCompletionIntervalId;
                            }
                        }

                        if (upperInt > 0)
                        {
                            var interval2 = intervals.Find(m => m.UpperInterval.Equals(upperInt));
                            if (interval2 != null)
                            {
                                welllcompObj.L2            = interval2.LowerInterval;
                                welllcompObj.U2            = interval2.UpperInterval;
                                welllcompObj.IntervalId2   = interval2.WellCompletionIntervalId;
                                welllcompObj.DateCompleted = DateTime.Parse(interval2.DateCompleted);
                            }
                        }
                    }

                    if (myViewObj.WellCompletionTypeId < 2)
                    {
                        welllcompObj.L1            = intervals[0].LowerInterval;
                        welllcompObj.U1            = intervals[0].UpperInterval;
                        welllcompObj.IntervalId1   = intervals[0].WellCompletionIntervalId;
                        welllcompObj.DateCompleted = DateTime.Parse(intervals[0].DateCompleted);
                    }
                }

                Session["_wellCompletion"] = myViewObj;
                Session["_wellCompObj"]    = welllcompObj;
                welllcompObj.ErrorCode     = 5;
                return(Json(welllcompObj, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                wellCompletion.Error     = "An unknown error was encountered. Well Completion  Information could not be retrieved.";
                wellCompletion.ErrorCode = -1;
                return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult EditWellCompletion(WellCompletion wellCompletion)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (Session["_wellCompletion"] == null || Session["_wellCompObj"] == null)
                {
                    wellCompletion.Error     = "Session has expired";
                    wellCompletion.ErrorCode = 0;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                var oldWellCompletion = Session["_wellCompletion"] as WellCompletion;
                var oldWellCompObj    = Session["_wellCompObj"] as WellCompletionObject;

                if (oldWellCompletion == null || oldWellCompletion.WellCompletionId < 1 || oldWellCompObj == null || oldWellCompObj.WellCompletionId < 1)
                {
                    wellCompletion.Error     = "Session has expired";
                    wellCompletion.ErrorCode = 0;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                if (!ModelState.IsValid)
                {
                    wellCompletion.Error     = "Please supply all required entries and try again";
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(wellCompletion);

                if (wx.Code < 1)
                {
                    wellCompletion.Error     = wx.Error;
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                oldWellCompletion.EquipmentId          = wellCompletion.EquipmentId;
                oldWellCompletion.WellId               = wellCompletion.WellId;
                oldWellCompletion.WellCompletionTypeId = wellCompletion.WellCompletionTypeId;
                wellCompletion.IsInitial               = wellCompletion.IsInitial;

                if (wellCompletion.WellCompletionTypeId > 1)
                {
                    if (wellCompletion.L2 <= 0)
                    {
                        wellCompletion.Error     = "Please provide a valid Lower Intervalv 2";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    if (wellCompletion.U2 <= 0)
                    {
                        wellCompletion.Error     = "Please provide a valid Upper Interval 2";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    if (wellCompletion.U2 < wellCompletion.L2 || wellCompletion.U2.Equals(wellCompletion.L2))
                    {
                        wellCompletion.Error     = "Please provide a valid Second Upper Interval 2";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }


                    var newCompletionInterval2 = new WellCompletionInterval
                    {
                        LowerInterval    = wellCompletion.L2,
                        UpperInterval    = wellCompletion.U2,
                        DateCompleted    = wellCompletion.DateCompleted.ToString(),
                        LastUpdatedTime  = DateTime.Now.ToString("g"),
                        WellCompletionId = oldWellCompletion.WellCompletionId
                    };

                    if (oldWellCompObj.IntervalId2 > 0)
                    {
                        newCompletionInterval2.WellCompletionIntervalId = oldWellCompObj.IntervalId2;
                        var r = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(newCompletionInterval2);
                        if (r < 1)
                        {
                            wellCompletion.Error     = "Well Completion Interval could not be updated";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }

                    if (oldWellCompObj.IntervalId2 < 1)
                    {
                        var r = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(newCompletionInterval2);
                        if (r < 1)
                        {
                            wellCompletion.Error     = "Well Completion Interval could not be updated";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }

                    var newCompletionInterval1 = new WellCompletionInterval
                    {
                        LowerInterval    = wellCompletion.L1,
                        UpperInterval    = wellCompletion.U1,
                        DateCompleted    = wellCompletion.DateCompleted.ToString(),
                        LastUpdatedTime  = DateTime.Now.ToString("g"),
                        WellCompletionId = oldWellCompletion.WellCompletionId
                    };

                    if (oldWellCompObj.IntervalId1 > 0)
                    {
                        newCompletionInterval1.WellCompletionIntervalId = oldWellCompObj.IntervalId1;
                        var r = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(newCompletionInterval1);
                        if (r < 1)
                        {
                            wellCompletion.Error     = "Well Completion Interval could not be updated";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }

                    if (oldWellCompObj.IntervalId1 < 1)
                    {
                        var r = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(newCompletionInterval1);
                        if (r < 1)
                        {
                            wellCompletion.Error     = "Well Completion Interval could not be updated";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }
                }

                if (wellCompletion.WellCompletionTypeId < 2)
                {
                    if (wellCompletion.U1 <= 0)
                    {
                        wellCompletion.Error     = "Please provide a valid Upper Interval";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    if (wellCompletion.U1 < wellCompletion.L1 || wellCompletion.U1.Equals(wellCompletion.L1))
                    {
                        wellCompletion.Error     = "Please provide a valid Upper Interval";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    if (oldWellCompObj.IntervalId2 > 0)
                    {
                        var r = new WellCompletionIntervalServices().DeleteWellCompletionIntervalCheckReferences(oldWellCompObj.IntervalId2);
                        if (!r)
                        {
                            wellCompletion.Error     = "The process could not be completed. The requested item update will cause data loss.";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }

                    var newCompletionInterval = new WellCompletionInterval
                    {
                        LowerInterval    = wellCompletion.L1,
                        UpperInterval    = wellCompletion.U1,
                        DateCompleted    = wellCompletion.DateCompleted.ToString(),
                        LastUpdatedTime  = DateTime.Now.ToString("g"),
                        WellCompletionId = oldWellCompletion.WellCompletionId
                    };

                    if (oldWellCompObj.IntervalId1 > 0)
                    {
                        newCompletionInterval.WellCompletionIntervalId = oldWellCompObj.IntervalId1;
                        var r = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(newCompletionInterval);
                        if (r < 1)
                        {
                            wellCompletion.Error     = "Well Completion Interval could not be updated";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }

                    if (oldWellCompObj.IntervalId1 < 1)
                    {
                        var r = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(newCompletionInterval);
                        if (r < 1)
                        {
                            wellCompletion.Error     = "Well Completion Interval could not be updated";
                            wellCompletion.ErrorCode = 0;
                            return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                        }
                    }
                }

                var k = new WellCompletionServices().UpdateWellCompletionCheckDuplicate(oldWellCompletion);
                if (k < 1)
                {
                    wellCompletion.Error     = "Process Failed! Please contact the Admin or try again later";
                    wellCompletion.ErrorCode = 0;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                wellCompletion.Error     = "Well Completion  Information was successfully updated";
                wellCompletion.ErrorCode = 1;
                return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                wellCompletion.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                wellCompletion.ErrorCode = 0;
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddWellCompletion(WellCompletion wellCompletion)
        {
            ModelState.Clear();
            ViewBag.LoadStatus = "0";
            try
            {
                if (!ModelState.IsValid)
                {
                    wellCompletion.Error     = "Please supply all required well Completions and try again";
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                var wx = ValidateControl(wellCompletion);

                if (wx.Code < 1)
                {
                    wellCompletion.Error     = wx.Error;
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                if (wellCompletion.U1 <= 0)
                {
                    wellCompletion.Error     = "Please provide a valid Upper Interval";
                    wellCompletion.ErrorCode = -1;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                if (wellCompletion.WellCompletionTypeId > 1)
                {
                    if (wellCompletion.L2 <= 0)
                    {
                        wellCompletion.Error     = "Please provide a valid Lower Intervalv 2";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    if (wellCompletion.U2 <= 0)
                    {
                        wellCompletion.Error     = "Please provide a valid Upper Interval 2";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    if (wellCompletion.U2 < wellCompletion.L2 || wellCompletion.U2.Equals(wellCompletion.L2))
                    {
                        wellCompletion.Error     = "Please provide a valid Upper Interval 2";
                        wellCompletion.ErrorCode = -1;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }
                }

                var k = new WellCompletionServices().AddWellCompletionCheckDuplicate(wellCompletion);
                if (k < 1)
                {
                    if (k == -3)
                    {
                        wellCompletion.Error     = "Well Completion  already exists";
                        wellCompletion.ErrorCode = -3;
                        return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                    }

                    wellCompletion.Error     = "Process Failed! Please contact the Admin or try again later";
                    wellCompletion.ErrorCode = 0;
                    return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
                }

                wellCompletion.Error               = "Record was added successfully";
                wellCompletion.ErrorCode           = 1;
                wellCompletion.WellCompletionId    = k;
                wellCompletion.DatecomPletedString = wellCompletion.DateCompleted.ToString();
                return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);
                wellCompletion.Error     = "An unknown error was encountered. Request could not be serviced. Please try again later.";
                wellCompletion.ErrorCode = 0;
                ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message);

                return(Json(wellCompletion, JsonRequestBehavior.AllowGet));
            }
        }