public ActionResult EditBlock(int id) { var block = new Block(); try { if (id < 1) { block.Error = "Invalid Selection!"; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } var myViewObj = new BlockServices().GetBlock(id); if (myViewObj == null || myViewObj.BlockId < 1) { block.Error = "Block Information could not be retrieved."; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } Session["_block"] = myViewObj; myViewObj.ErrorCode = myViewObj.BlockId; return(Json(myViewObj, JsonRequestBehavior.AllowGet)); } catch (Exception) { //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); block.Error = "An unknown error was Block Information could not be retrieved."; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } }
public void SetServiceState(BlockServices service, bool state) { int sid = (int)service; bState[sid] = state; string srvName = blockServices[sid].Substring(4); logger.Log("MITM" + srvName + " set to " + ((state) ? "Enabled" : "Disabled"), VLogger.LogLevel.service); }
public bool CheckServiceState(BlockServices service) { int sid = (int)service; bool state = bState[sid]; if (service == BlockServices.Undefined) { logger.Log("Invalid service name specified!", VLogger.LogLevel.error); } return(state); }
public ActionResult AddBlock(Block block) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (!ModelState.IsValid) { block.Error = "Please supply all required fields and try again"; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(block); if (wx.Code < 1) { block.Error = wx.Error; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } var k = new BlockServices().AddBlockCheckDuplicate(block); if (k < 1) { if (k == -3) { block.Error = "Block already exists"; block.ErrorCode = -3; return(Json(block, JsonRequestBehavior.AllowGet)); } block.Error = "Process Failed! Please contact the Admin or try again later"; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } block.Error = "Record was added successfully"; block.ErrorCode = 1; block.BlockId = k; return(Json(block, JsonRequestBehavior.AllowGet)); } catch (Exception) { //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); block.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } }
public ActionResult GetBlocksByCompany(long companyId) { try { if (companyId < 1) { return(Json(new List <BlockObject>(), JsonRequestBehavior.AllowGet)); } var blocklist = new BlockServices().GetCompanyBlocksWithFields(companyId); if (!blocklist.Any()) { return(Json(new List <BlockObject>(), JsonRequestBehavior.AllowGet)); } return(Json(blocklist, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new List <BlockObject>(), JsonRequestBehavior.AllowGet)); } }
private Field ProcessRecord(DataRowView dv, ref string msg) { if (dv == null) { return(null); } try { var mInfo = new Field { Name = dv.Row["Field_Name"].ToString().Trim() }; //[Field_Name], [Block_Name] var companyName = dv.Row["Company_Name"].ToString().Trim(); if (string.IsNullOrEmpty(companyName)) { mInfo.CompanyId = 1; } else { var cannonicalName = ""; if (string.IsNullOrEmpty(dv.Row["Canonial_Name"].ToString().Trim())) { cannonicalName = dv.Row["Canonial_Name"].ToString().Trim(); } var companyId = new CompanyServices().GetCompanyId(companyName, cannonicalName); if (companyId < 1) { mInfo.CompanyId = 1; } mInfo.CompanyId = companyId; } var terrainName = dv.Row["Terrain_Name"].ToString().Trim(); if (string.IsNullOrEmpty(terrainName)) { mInfo.TerrainId = 1; } else { var terrainId = new TerrainServices().GetTerrainIdByName(terrainName.Trim()); if (terrainId < 1) { mInfo.TerrainId = 1; } mInfo.TerrainId = terrainId; } mInfo.ZoneId = 1; var techAllowed = dv.Row["Technical_Allowable"].ToString().Trim(); if (!string.IsNullOrEmpty(techAllowed)) { float outTech = 0; var techResult = float.TryParse(techAllowed, out outTech); if (techResult && outTech > 0) { mInfo.TechnicalAllowable = outTech; } } var blockName = dv.Row["Block_Name"].ToString().Trim(); if (string.IsNullOrEmpty(blockName)) { msg = "Block Name is empty"; return(mInfo);; } var ttsd = new FieldServices().AddFieldCheckDuplicate(mInfo); if (ttsd < 1) { msg = "Field could not be processed."; return(null); } if (blockName.Contains("/")) { var dxx = blockName.Split('/'); dxx.ForEach(v => { if (!string.IsNullOrEmpty(v)) { var tId = 0; if (v.Trim().ToLower().Contains("oml")) { tId = 1; } if (v.Trim().ToLower().Contains("opl")) { tId = 2; } var block = new Block { CompanyId = mInfo.CompanyId, BlockTypeId = tId, Name = blockName, LeaseTypeId = 1, YearOfAward = DateTime.Now.Year }; var ssd = new BlockServices().AddBlockCheckDuplicate(block); if (ssd < 1) { return; } } }); } else { var tId = 0; if (blockName.Trim().ToLower().Contains("oml")) { tId = 1; } if (blockName.Trim().ToLower().Contains("opl")) { tId = 2; } var block = new Block { CompanyId = mInfo.CompanyId, BlockTypeId = tId, Name = blockName, LeaseTypeId = 1, YearOfAward = DateTime.Now.Year }; var ssd = new BlockServices().AddBlockCheckDuplicate(block); if (ssd < 1) { mInfo.FieldId = ttsd; return(mInfo); } } mInfo.FieldId = ttsd; return(mInfo); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(null); } }
private Field ProcessRecord(DataRowView dv, ref string msg) { if (dv == null) { return(null); } try { var mInfo = new Field { Name = dv.Row["Field_Name"].ToString().Trim() }; var zoneName = dv.Row["Zone_Name"].ToString().Trim(); if (string.IsNullOrEmpty(zoneName)) { msg = "Zone Name is empty"; return(null); } var zoneId = new ZoneServices().GetZoneIdByName(zoneName.Trim()); if (zoneId < 1) { msg = "Zone Information could not be processed."; return(null); } mInfo.ZoneId = zoneId; var terrainName = dv.Row["Terrain_Name"].ToString().Trim(); if (string.IsNullOrEmpty(zoneName)) { msg = "Terrain Name is empty"; return(null); } var terrainId = new TerrainServices().GetTerrainIdByName(terrainName.Trim()); if (terrainId < 1) { msg = "Terrain Information could not be processed."; return(null); } mInfo.TerrainId = terrainId; var blockName = dv.Row["Block_Name"].ToString().Trim(); if (string.IsNullOrEmpty(blockName)) { msg = "Block Name is empty"; return(null); } var blockId = new BlockServices().GetBlockId(blockName.Trim()); if (blockId < 1) { msg = "Block Information could not be processed."; return(null); } mInfo.BlockId = blockId; var companyName = dv.Row["Company_Name"].ToString().Trim(); if (string.IsNullOrEmpty(companyName)) { msg = "Company Name is empty"; return(null); } var companyId = new CompanyServices().GetCompanyId(companyName.Trim()); if (companyId < 1) { msg = "Company Information could not be processed."; return(null); } mInfo.CompanyId = companyId; var techAllowed = dv.Row["Technical_Allowable"].ToString().Trim(); if (!string.IsNullOrEmpty(techAllowed)) { float outTech = 0; var techResult = float.TryParse(techAllowed, out outTech); if (techResult && outTech > 0) { mInfo.TechnicalAllowable = outTech; } } return(mInfo); } catch (Exception ex) { ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(null); } }
public string ServiceToString(BlockServices input) { int sid = (int)input; return(blockServices[sid]); }
public ActionResult BlockUpload(HttpPostedFileBase file) { try { if (file.ContentLength > 0) { const string folderPath = "~/BulkUploadTemplate"; var fileName = file.FileName; var path = folderPath + "/" + fileName; if (System.IO.File.Exists(Server.MapPath(path))) { System.IO.File.Delete(Server.MapPath(path)); } file.SaveAs(Server.MapPath(folderPath + "/" + fileName)); var mList = new List <Block>(); var msg = string.Empty; if (!new BlockUploadManager().Import(Server.MapPath(path), "Blocks", ref mList, ref msg)) { ViewBag.ErrorCode = -1; ViewBag.ErrorMessage = msg; return(View()); } if (!mList.Any()) { const string error = "Bulk upload Failed! unknown error occurred"; ViewBag.ErrorCode = -1; ViewBag.ErrorMessage = error; return(View()); } var errorList = new List <Block>(); var successList = new List <Block>(); mList.ForEach(m => { var processedItem = new BlockServices().AddBlockCheckDuplicate(m); if (processedItem < 1) { errorList.Add(m); } else { successList.Add(m); } }); if (errorList.Any() && successList.Any()) { var ts = successList.Count + " record(s) were successfully uploaded." + "\n" + errorList.Count + " record(s) could not be uploaded due to duplicates/unknown errors encountered."; ViewBag.ErrorCode = -1; if (msg.Length > 0) { ts += "<br/>" + msg; } ViewBag.ErrorMessage = ts; return(View(new WellViewModel { Blocks = new List <Block>(), Fields = GetFields() })); } if (errorList.Any() && !successList.Any()) { var ts = errorList.Count + " records could not be uploaded due to duplicates/unknown errors encountered after processing the template."; ViewBag.ErrorCode = -1; if (msg.Length > 0) { ts += "<br/>" + msg; } ViewBag.ErrorMessage = ts; return(View(new WellViewModel { Blocks = new List <Block>(), Fields = GetFields() })); } if (!errorList.Any() && successList.Any() && msg.Length > 0) { ViewBag.ErrorCode = -1; //ViewBag.ErrorMessage = mList.Count + " records were successfully uploaded."; var tsx = successList.Count + " records were successfully uploaded."; tsx += "<br/>" + msg; ViewBag.ErrorMessage = tsx; return(View()); } else { ViewBag.ErrorCode = 5; var tsx = successList.Count + " records were successfully uploaded."; ViewBag.ErrorMessage = tsx; return(View()); } } ViewBag.ErrorCode = -1; ViewBag.ErrorMessage = "Error: File is empty or the content could not be accessed"; return(View()); } catch (Exception ex) { const string error = "Bulk upload Failed! unknown error occurred"; ViewBag.ErrorCode = -1; ViewBag.ErrorMessage = error; ErrorLogger.LogEror(ex.StackTrace, ex.Source, ex.Message); return(View()); } }
public ActionResult EditBlock(Block block) { ModelState.Clear(); ViewBag.LoadStatus = "0"; try { if (Session["_block"] == null) { block.Error = "Session has expired"; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } var oldBlock = Session["_block"] as Block; if (oldBlock == null || oldBlock.BlockId < 1) { block.Error = "Session has expired"; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } if (!ModelState.IsValid) { block.Error = "Please supply all required fields and try again"; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } var wx = ValidateControl(block); if (wx.Code < 1) { block.Error = wx.Error; block.ErrorCode = -1; return(Json(block, JsonRequestBehavior.AllowGet)); } oldBlock.Name = block.Name; oldBlock.CompanyId = block.CompanyId; oldBlock.LeaseTypeId = block.LeaseTypeId; oldBlock.YearOfAward = block.YearOfAward; oldBlock.Area = block.Area; oldBlock.BlockTypeId = block.BlockTypeId; var k = new BlockServices().UpdateBlockCheckDuplicate(oldBlock); if (k < 1) { if (k == -3) { block.Error = "Block already exists"; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } block.Error = "Process Failed! Please contact the Admin or try again later"; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } block.Error = "Block Information was successfully updated"; block.ErrorCode = 1; return(Json(block, JsonRequestBehavior.AllowGet)); } catch (Exception) { //ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message); block.Error = "An unknown error was encountered. Request could not be serviced. Please try again later."; block.ErrorCode = 0; return(Json(block, JsonRequestBehavior.AllowGet)); } }