public WellOperationsModel Insert(WellOperationsModel model) { try { string query = @"INSERT INTO WellOperations( WellId ,OperationsId ,OprId ,Remarks ,StartTime ,SecId ,CurrentDepth ,CreatedDateTime) OUTPUT INSERTED.WellOpId VALUES( @WellId ,@OperationsId ,@OprId ,@Remarks ,@StartTime ,@SecId ,@CurrentDepth ,@CreatedDateTime)"; List <SqlParameter> param = new List <SqlParameter>(); param.Add(new SqlParameter("@WellId", model.WellId)); param.Add(new SqlParameter("@OperationsId", model.OperationsId)); param.Add(new SqlParameter("@OprId", model.OprId)); param.Add(new SqlParameter("@Remarks", model.Remarks)); param.Add(new SqlParameter("@StartTime", model.StartTime)); param.Add(new SqlParameter("@SecId", model.SecId)); param.Add(new SqlParameter("@CurrentDepth", model.CurrentDepth)); param.Add(new SqlParameter("@CreatedDateTime", model.CreatedDateTime)); fun.OpenConnection(); if (fun.getConnection().State == ConnectionState.Open) { model.WellOpId = fun.ExecuteQueryWithParameters(query, param, "Yes"); if (model.WellOpId > 0) { query = @"with A as ( select WellOpId, ROW_NUMBER()OVER(ORDER BY WellOpId Desc)RowNumber from WellOperations where WellId = @WellId and WellOpId <> @WellOpId )update B set B.EndTime = @EndTime from A inner join WellOperations B on A.WellOpId = B.WellOpId and A.RowNumber = 1"; param = new List <SqlParameter>(); param.Add(new SqlParameter("@WellId", model.WellId)); param.Add(new SqlParameter("@WellOpId", model.WellOpId)); param.Add(new SqlParameter("@EndTime", model.StartTime)); fun.execQry(query, param); } } else { throw new Exception("Please check network connection"); } } catch (Exception ex) { throw ex; } return(model); }
public WellOperationsModel Update(WellOperationsModel model) { try { string query = @"UPDATE WellOperations SET OperationsId = @OperationsId ,OprId = @OprId ,Remarks = @Remarks ,StartTime = @StartTime ,SecId = @SecId ,CurrentDepth = @CurrentDepth ,LastUpdatedDateTime = @LastUpdatedDateTime WHERE WellOpId = @WellOpId"; List <SqlParameter> param = new List <SqlParameter>(); param.Add(new SqlParameter("@OperationsId", model.OperationsId)); param.Add(new SqlParameter("@OprId", model.OprId)); param.Add(new SqlParameter("@Remarks", model.Remarks)); param.Add(new SqlParameter("@StartTime", model.StartTime)); param.Add(new SqlParameter("@SecId", model.SecId)); param.Add(new SqlParameter("@CurrentDepth", model.CurrentDepth)); param.Add(new SqlParameter("@LastUpdatedDateTime", model.CreatedDateTime)); param.Add(new SqlParameter("@WellOpId", model.WellOpId)); fun.OpenConnection(); if (fun.getConnection().State == ConnectionState.Open) { fun.ExecuteQueryWithParameters(query, param); if (model.EndTime != null) { query = @"UPDATE WellOperations SET EndTime = @EndTime WHERE WellOpId = @WellOpId"; param = new List <SqlParameter>(); param.Add(new SqlParameter("@EndTime", model.EndTime)); param.Add(new SqlParameter("@WellOpId", model.WellOpId)); fun.ExecuteQueryWithParameters(query, param); } } else { throw new Exception("Please check network connection"); } } catch (Exception ex) { throw ex; } return(model); }
public WellOperationsModel GetOperationEditDetails(int WellOpId) { WellOperationsModel model = new WellOperationsModel(); try { string query = String.Format(@"select WellOpId, WellId, OperationsId, OprId, StartTime, EndTime, SecId, CurrentDepth, Remarks from WellOperations where WellOpId = {0}", WellOpId); fun.OpenConnection(); if (fun.getConnection().State == ConnectionState.Open) { DataSet ds = fun.fillComboDataset(query); if (ds.Tables.Count > 0) { foreach (DataRow item in ds.Tables[0].Rows) { model.WellOpId = Convert.ToInt32(item["WellOpId"].ToString()); model.WellId = Convert.ToInt32(item["WellId"].ToString()); model.SecId = Convert.ToInt32(item["SecId"].ToString()); model.OperationsId = Convert.ToInt32(item["OperationsId"].ToString()); model.OprId = Convert.ToInt32(item["OprId"].ToString()); model.StartTime = Convert.ToDateTime(item["StartTime"].ToString()); if (item["EndTime"].ToString() != "") { model.EndTime = Convert.ToDateTime(item["EndTime"].ToString()); } model.Remarks = item["Remarks"].ToString(); model.CurrentDepth = Convert.ToInt32(item["CurrentDepth"].ToString()); } } } } catch (Exception ex) { throw ex; } return(model); }