public ActionResult DeleteWellCompletionInterval(int id) { var wellCompletionInterval = new WellCompletionInterval(); try { if (id < 1) { wellCompletionInterval.Error = "Invalid Selection"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } if (new WellCompletionIntervalServices().DeleteWellCompletionIntervalCheckReferences(id)) { wellCompletionInterval.Error = "WellCompletionInterval Information was successfully deleted."; wellCompletionInterval.ErrorCode = 1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } wellCompletionInterval.Error = "Process Failed! Please try again later"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletionInterval.Error = "An unknown error was encountered. Please contact the Administrator or try again later."; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditWellCompletionInterval(int id) { var wellCompletionInterval = new WellCompletionInterval(); try { if (id < 1) { wellCompletionInterval.Error = "Invalid Selection!"; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } var myViewObj = new WellCompletionIntervalServices().GetWellCompletionInterval(id); if (myViewObj == null || myViewObj.WellCompletionIntervalId < 1) { wellCompletionInterval.Error = "Well Completion Interval Information could not be retrieved."; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } Session["_wellCompletionInterval"] = myViewObj; myViewObj.ErrorCode = myViewObj.WellCompletionIntervalId; return(Json(myViewObj, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletionInterval.Error = "An unknown error was encountered. Well Completion Interval Information could not be retrieved."; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } }
public int UpdateWellCompletionIntervalCheckDuplicate(WellCompletionInterval wellCompletionInterval) { try { if (wellCompletionInterval == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { var entityToUpdateList = db.WellCompletionIntervals.Where(m => m.WellCompletionIntervalId == wellCompletionInterval.WellCompletionIntervalId).ToList(); if (entityToUpdateList.Any()) { var entityToUpdate = entityToUpdateList[0]; entityToUpdate.LowerInterval = wellCompletionInterval.LowerInterval; entityToUpdate.UpperInterval = wellCompletionInterval.UpperInterval; entityToUpdate.DateCompleted = wellCompletionInterval.DateCompleted; entityToUpdate.LastUpdatedTime = DateTime.Now.ToString("hh:mm:ss t "); entityToUpdate.WellCompletionId = wellCompletionInterval.WellCompletionId; //db.WellCompletionIntervals.Attach(wellCompletionInterval); //db.Entry(wellCompletionInterval).State = EntityState.Modified; return(db.SaveChanges()); } return(-2); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
public ActionResult AddWellCompletionInterval(WellCompletionInterval wellCompletionInterval) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (!ModelState.IsValid) { wellCompletionInterval.Error = "Please supply all required wellCompletionIntervals and try again"; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(wellCompletionInterval); if (wx.Code < 1) { wellCompletionInterval.Error = wx.Error; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } //TimeSpan ts = new TimeSpan(DateTime.Now.TimeOfDay); wellCompletionInterval.LastUpdatedTime = DateTime.Now.ToString("hh:mm:ss t z"); var k = new WellCompletionIntervalServices().AddWellCompletionIntervalCheckDuplicate(wellCompletionInterval); if (k < 1) { if (k == -3) { wellCompletionInterval.Error = "WellCompletionInterval already exists"; wellCompletionInterval.ErrorCode = -3; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } wellCompletionInterval.Error = "Process Failed! Please contact the Admin or try again later"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } wellCompletionInterval.DatecomPletedString = wellCompletionInterval.DateCompleted; wellCompletionInterval.Error = "Record was added successfully"; wellCompletionInterval.ErrorCode = 1; wellCompletionInterval.WellCompletionIntervalId = k; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletionInterval.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } }
public int AddWellCompletionIntervalCheckDuplicate(WellCompletionInterval wellCompletionInterval) { try { if (wellCompletionInterval == null) { return(-2); } using (var db = new DPRDataMigrationEngineDBEntities()) { db.WellCompletionIntervals.Add(wellCompletionInterval); return(db.SaveChanges()); } } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(0); } }
private static GenericValidator ValidateControl(WellCompletionInterval model) { var gVal = new GenericValidator(); try { if (model.WellCompletionId < 1) { gVal.Error = "Please select a valid Well Completion information"; gVal.Code = 0; return(gVal); } if (model.UpperInterval <= 0) { gVal.Error = "Please provide a valid Upper Interval"; gVal.Code = 0; return(gVal); } if (model.UpperInterval < model.LowerInterval) { gVal.Error = "The Lower Interval should not be higher than the Upper Interval"; gVal.Code = 0; return(gVal); } gVal.Code = 1; return(gVal); } catch (Exception ex) { gVal.Error = "Process validation failed. Please supply all required entries and try again."; gVal.Code = 0; return(gVal); } }
public ActionResult EditWellCompletionInterval(WellCompletionInterval wellCompletionInterval) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (Session["_wellCompletionInterval"] == null) { wellCompletionInterval.Error = "Session has expired"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } var oldWellCompletionInterval = Session["_wellCompletionInterval"] as WellCompletionInterval; if (oldWellCompletionInterval == null || oldWellCompletionInterval.WellCompletionIntervalId < 1) { wellCompletionInterval.Error = "Session has expired"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } if (!ModelState.IsValid) { wellCompletionInterval.Error = "Please supply all required entries and try again"; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(wellCompletionInterval); if (wx.Code < 1) { wellCompletionInterval.Error = wx.Error; wellCompletionInterval.ErrorCode = -1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } oldWellCompletionInterval.WellCompletionId = wellCompletionInterval.WellCompletionId; oldWellCompletionInterval.UpperInterval = wellCompletionInterval.UpperInterval; oldWellCompletionInterval.LowerInterval = wellCompletionInterval.LowerInterval; oldWellCompletionInterval.LastUpdatedTime = DateTime.Now.ToString("hh:mm:ss t "); wellCompletionInterval.DateCompleted = wellCompletionInterval.DateCompleted; var k = new WellCompletionIntervalServices().UpdateWellCompletionIntervalCheckDuplicate(oldWellCompletionInterval); if (k < 1) { if (k == -3) { wellCompletionInterval.Error = "Well Completion Interval already exists"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } wellCompletionInterval.Error = "Process Failed! Please contact the Admin or try again later"; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } wellCompletionInterval.DatecomPletedString = oldWellCompletionInterval.DateCompleted; wellCompletionInterval.Error = "Well Completion Interval Information was successfully updated"; wellCompletionInterval.ErrorCode = 1; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); wellCompletionInterval.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; wellCompletionInterval.ErrorCode = 0; return(Json(wellCompletionInterval, JsonRequestBehavior.AllowGet)); } }
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(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)); } }