You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1769 lines
71 KiB
C#

1 month ago
using DevExpress.Drawing.Internal.Interop;
using DevExpress.Office.Utils;
using DevExpress.XtraRichEdit.Model;
using DevExpress.XtraScheduler.Drawing.Internal;
using DevExpress.XtraTreeList.Data;
using GeoSigma.SigmaDrawerElement;
using GeoSigmaDrawLib;
using InterfaceWorkAreaData;
//using InterfaceWorkAreaData;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.SS.Formula.Functions;
using SigmaDrawerElement;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using WorkData;
using WorkData.Entity;
using static ScintillaNET.Style;
namespace GeoSigma.UCDraw.WellAndSection
{
public class StringIntMapper
{
private readonly Dictionary<string, int> _mappings;
private readonly int _defaultValue;
public StringIntMapper(int defaultValue = -1)
{
_mappings = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
_defaultValue = defaultValue;
}
public void AddMapping(string key, int value = -1) => _mappings[key] = value;
public void AddMappings(IEnumerable<KeyValuePair<string, int>> mappings)
{
foreach (var mapping in mappings)
{
_mappings[mapping.Key] = mapping.Value;
}
}
public int this[string key]
{
get => _mappings.TryGetValue(key, out int value) ? value : _defaultValue;
set => _mappings[key] = value;
}
public bool TryGetValue(string key, out int value) =>
_mappings.TryGetValue(key, out value);
public bool UpdateMapping(string key, int newValue)
{
if (_mappings.ContainsKey(key))
{
_mappings[key] = newValue;
return true;
}
return false;
}
public bool HasKey(string key)
{
return _mappings.ContainsKey(key);
}
public IEnumerable<string> Keys => _mappings.Keys;
public IEnumerable<int> Values => _mappings.Values;
}
class WellDataConvert
{
public static void getWellPerforationsJson(ref string jsonStr, List<cPerforation> listPerforations)
{
jsonStr = "";
if (listPerforations.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "Shot";
JArray jCols = new JArray();
jCols.Add("name");
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("date"); // kep工区表中没有
jCols.Add("density"); //kep工区表中没有
jCols.Add("method");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < listPerforations.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(listPerforations[k].layer);
tdata.Add(listPerforations[k].top.ToString());
tdata.Add(listPerforations[k].bottom.ToString());
tdata.Add("");
tdata.Add("");
tdata.Add(listPerforations[k].perforationMethod);
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellFaultPointsJson(ref string jsonStr, List<cFaultPoint> listFaultPts)
{
jsonStr = "";
if (listFaultPts.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "FaultPoint";
JArray jCols = new JArray();
jCols.Add("depth");
jCols.Add("name");
jCols.Add("topLayer");
jCols.Add("bottomLayer");
jCols.Add("compareWell");
jCols.Add("compareWellTop");
jCols.Add("compareWellBottom");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < listFaultPts.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(listFaultPts[k].depth.ToString());
tdata.Add(listFaultPts[k].faultName);
tdata.Add(listFaultPts[k].faultTopLayer);
tdata.Add(listFaultPts[k].faultBottomLayer);
tdata.Add("");
tdata.Add(listFaultPts[k].compareWellTop.ToString());
tdata.Add(listFaultPts[k].compareWellBottom.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellTrajectoryJson(ref string jsonStr, List<cWellTrackPoint> listTrackPts)
{
jsonStr = "";
if (listTrackPts.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "trajectory";
JArray jCols = new JArray();
jCols.Add("depth");
jCols.Add("bevel");
jCols.Add("azimuth");
jCols.Add("depthV");
jCols.Add("x");
jCols.Add("y");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < listTrackPts.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(listTrackPts[k].depth.ToString());
tdata.Add(listTrackPts[k].bevel.ToString());
tdata.Add(listTrackPts[k].azimuth.ToString());
tdata.Add(listTrackPts[k].depthV.ToString());
tdata.Add(listTrackPts[k].x.ToString());
tdata.Add(listTrackPts[k].y.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellStratificationJson(ref string jsonStr, List<cWellStratification> listWellStrati)
{
jsonStr = "";
if (listWellStrati.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "wellStratification";
JArray jCols = new JArray();
jCols.Add("id");
jCols.Add("level");
jCols.Add("name");
jCols.Add("code");
jCols.Add("parentId");
jCols.Add("order");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < listWellStrati.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(listWellStrati[k].id.ToString());
tdata.Add(listWellStrati[k].level.ToString());
tdata.Add(listWellStrati[k].name.ToString());
tdata.Add(listWellStrati[k].code.ToString());
tdata.Add(listWellStrati[k].parentId.ToString());
tdata.Add(listWellStrati[k].order.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellCurveValueForNewWell(DataTable curvesTable, GeoSigmaWellPoleXY wellGeo, UInt64 wellHandle, UInt64 trackHandle, string dataStrRef)
{
int depthid = 0; //认为深度是第一列
for (int j = 0; j < curvesTable.Columns.Count; j++)
{
if (curvesTable.Columns[j].ColumnName.ToUpper() == dataStrRef.ToUpper())
{
JObject json = new JObject();
json["dataType"] = "Curve";
JArray jCols = new JArray();
jCols.Add("depth");
jCols.Add("value");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < curvesTable.Rows.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(curvesTable.Rows[k][depthid]);
tdata.Add(curvesTable.Rows[k][j]);
jDatas.Add(tdata);
}
json["data"] = jDatas;
string strJson = JsonConvert.SerializeObject(json);
byte[] databytes = Encoding.UTF8.GetBytes(strJson);
wellGeo.SetWellTrackDataJson(trackHandle, strJson);
}
}
}
public static void getWellSandSetsJson(ref string jsonStr, List<cWellSandSet> lstWellSandSets)
{
jsonStr = "";
if (lstWellSandSets.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "SandSet";
JArray jCols = new JArray();
jCols.Add("id");
jCols.Add("name");
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("result");
jCols.Add("facies");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < lstWellSandSets.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(lstWellSandSets[k].id.ToString());
tdata.Add(lstWellSandSets[k].name.ToString());
tdata.Add(lstWellSandSets[k].top.ToString());
tdata.Add(lstWellSandSets[k].bottom.ToString());
tdata.Add(lstWellSandSets[k].result.ToString());
tdata.Add(lstWellSandSets[k].facies.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getStratumDivisionJson(ref string jsonStr, List<cStratumDivision> listStratums)
{
jsonStr = "";
if (listStratums.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "stratumDivision";
JArray jCols = new JArray();
jCols.Add("id");
jCols.Add("name");
jCols.Add("code");
jCols.Add("parentId");
jCols.Add("classname");
jCols.Add("orderId");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < listStratums.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(listStratums[k].id.ToString());
tdata.Add(listStratums[k].name.ToString());
tdata.Add(listStratums[k].code.ToString());
tdata.Add(listStratums[k].parentID.ToString());
tdata.Add(listStratums[k].classname.ToString());
tdata.Add(listStratums[k].orderId.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getReservesLayerJson(ref string jsonStr, List<cWellReservesLayer> lstReservesLayers)
{
jsonStr = "";
if (lstReservesLayers.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "ReservesLayer";
JArray jCols = new JArray();
// jCols.Add("well");
jCols.Add("layer");
jCols.Add("topSecondSandstone");
jCols.Add("bottomSecondSandstone");
jCols.Add("topFirstSandstone");
jCols.Add("bottomFirstSandstone");
jCols.Add("pureEffectiveTopEstimate");
jCols.Add("pureEffectiveThicknessEstimate");
jCols.Add("viewEffectiveTop");
jCols.Add("viewEffectiveThickness");
jCols.Add("electricLogInterpretation");
jCols.Add("facies");
jCols.Add("subfacies");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < lstReservesLayers.Count; k++)
{
JArray tdata = new JArray();
// tdata.Add(lstReservesLayers[k].well);
tdata.Add(lstReservesLayers[k].layer);
tdata.Add(lstReservesLayers[k].topSecondSandstone.ToString());
tdata.Add(lstReservesLayers[k].bottomSecondSandstone.ToString());
tdata.Add(lstReservesLayers[k].topFirstSandstone.ToString());
tdata.Add(lstReservesLayers[k].bottomFirstSandstone.ToString());
tdata.Add(lstReservesLayers[k].pureEffectiveTopEstimate.ToString());
tdata.Add(lstReservesLayers[k].pureEffectiveThicknessEstimate.ToString());
tdata.Add(lstReservesLayers[k].viewEffectiveTop.ToString());
tdata.Add(lstReservesLayers[k].viewEffectiveThickness.ToString());
tdata.Add(lstReservesLayers[k].electricLogInterpretation.ToString());
tdata.Add(lstReservesLayers[k].facies);
tdata.Add(lstReservesLayers[k].subfacies);
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getInnerLayersJson(ref string jsonStr, List<cWellInnerLayer> lstInnerLayers)
{
jsonStr = "";
if (lstInnerLayers.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "InnerLayer";
JArray jCols = new JArray();
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("thickness");
jCols.Add("type");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < lstInnerLayers.Count; k++)
{
JArray tdata = new JArray();
// tdata.Add(lstReservesLayers[k].well);
tdata.Add(lstInnerLayers[k].top.ToString());
tdata.Add(lstInnerLayers[k].bottom.ToString());
tdata.Add(lstInnerLayers[k].thickness.ToString());
tdata.Add(lstInnerLayers[k].type);
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellLithologysJson(ref string jsonStr, List<cWellLithology> lstLithologys)
{
jsonStr = "";
if (lstLithologys.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "Lithology";
JArray jCols = new JArray();
// jCols.Add("well");
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("color");
jCols.Add("oilcontent");
jCols.Add("inclusions");
jCols.Add("structure");
jCols.Add("lithologyprefix");
jCols.Add("lithology");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < lstLithologys.Count; k++)
{
JArray tdata = new JArray();
// tdata.Add(lstReservesLayers[k].well);
tdata.Add(lstLithologys[k].top.ToString());
tdata.Add(lstLithologys[k].bottom.ToString());
tdata.Add(lstLithologys[k].color);
tdata.Add(lstLithologys[k].oilcontent);
tdata.Add(lstLithologys[k].inclusions);
tdata.Add(lstLithologys[k].structure);
tdata.Add(lstLithologys[k].lithologyprefix);
tdata.Add(lstLithologys[k].lithology);
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellOilTestJson(ref string jsonStr, List<cWellOilTest> lstOilTests)
{
jsonStr = "";
if (lstOilTests.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "OilTest";
JArray jCols = new JArray();
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("conclusion");
jCols.Add("daily_oil");
jCols.Add("daily_water");
jCols.Add("daily_gas");
jCols.Add("total_oil");
jCols.Add("total_gas");
jCols.Add("total_water");
jCols.Add("method");
jCols.Add("layer");
jCols.Add("staticMpa");
jCols.Add("caseMpa");
jCols.Add("flowMpa");
jCols.Add("density");
jCols.Add("viscosity");
jCols.Add("start");
jCols.Add("end");
jCols.Add("staticTemperature");
jCols.Add("thickness");
jCols.Add("stroke");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < lstOilTests.Count; k++)
{
JArray tdata = new JArray();
tdata.Add(lstOilTests[k].top.ToString());
tdata.Add(lstOilTests[k].bottom.ToString());
tdata.Add(lstOilTests[k].verdict);
tdata.Add(lstOilTests[k].dayOil.ToString());
tdata.Add(lstOilTests[k].dayWater.ToString());
tdata.Add(lstOilTests[k].dayGas.ToString());
tdata.Add(lstOilTests[k].sumOil.ToString());
tdata.Add(lstOilTests[k].sumWater.ToString());
tdata.Add(lstOilTests[k].sumGas.ToString());
tdata.Add(lstOilTests[k].method);
tdata.Add(lstOilTests[k].layer);
tdata.Add(lstOilTests[k].staticMpa.ToString());
tdata.Add(lstOilTests[k].caseMpa.ToString());
tdata.Add(lstOilTests[k].flowMpa.ToString());
tdata.Add(lstOilTests[k].density.ToString()); //密度
tdata.Add(lstOilTests[k].viscosity.ToString()); //粘度
tdata.Add(lstOilTests[k].startTime);
tdata.Add(lstOilTests[k].endTime);
tdata.Add(lstOilTests[k].staticTemperature.ToString());
tdata.Add(lstOilTests[k].thickness.ToString());
tdata.Add(lstOilTests[k].stroke.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellCoringJson(ref string jsonStr,List<cWellCoring>list)
{
jsonStr = "";
if (list.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "Coring";
JArray jCols = new JArray();
// jCols.Add("well");
jCols.Add("name");
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("times");
jCols.Add("length");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < list.Count; k++)
{
JArray tdata = new JArray();
// tdata.Add(lstReservesLayers[k].well);
tdata.Add(list[k].layer);
tdata.Add(list[k].top.ToString());
tdata.Add(list[k].bottom.ToString());
tdata.Add(list[k].times.ToString());
tdata.Add(list[k].length.ToString());
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellSideWallCoringsJson(ref string jsonStr, List<cWellSideWallCoring> list)
{
jsonStr = "";
if (list.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "CoreWell";
JArray jCols = new JArray();
// jCols.Add("well");
jCols.Add("depth");
jCols.Add("lithology");
jCols.Add("oil_level");
jCols.Add("times");
jCols.Add("color");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < list.Count; k++)
{
JArray tdata = new JArray();
// tdata.Add(lstReservesLayers[k].well);
tdata.Add(list[k].top.ToString());
tdata.Add(list[k].lithology);
tdata.Add(list[k].oilcontent);
tdata.Add(list[k].number.ToString());
tdata.Add(list[k].color);
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getWellCyclesJson(ref string jsonStr, List<cWellCycle> lstCycles)
{
jsonStr = "";
if (lstCycles.Count == 0)
return;
JObject json = new JObject();
json["dataType"] = "Cycle";
JArray jCols = new JArray();
// jCols.Add("well");
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("type");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < lstCycles.Count; k++)
{
JArray tdata = new JArray();
// tdata.Add(lstReservesLayers[k].well);
tdata.Add(lstCycles[k].top.ToString());
tdata.Add(lstCycles[k].bottom.ToString());
tdata.Add(lstCycles[k].type);
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
}
public static void getDataJson(string wellName, string sourceId, ref string jsonStr) //通过数据表标识获得数据
{
if (sourceId == "Shot")
{
List<cPerforation> listPerforations = workAreaDb.Instance.workData.getWellPerforations(wellName);
getWellPerforationsJson(ref jsonStr, listPerforations);
}
if (sourceId == "Lithology")
{
List<cWellLithology> lstLiths = workAreaDb.Instance.workData.getWellLithologys(wellName);
getWellLithologysJson(ref jsonStr, lstLiths);
}
else if (sourceId == "OilTest")
{
List<cWellOilTest> lstOilTest = workAreaDb.Instance.workData.getWellOilTests(wellName);
getWellOilTestJson(ref jsonStr, lstOilTest);
}
else if (sourceId == "InnerLayer")
{
List<cWellInnerLayer> lstInnerLayers = workAreaDb.Instance.workData.getInnerLayers(wellName);
getInnerLayersJson(ref jsonStr, lstInnerLayers);
}
}
public static bool setWellCycleDataToTrack(GeoSigmaWellPoleXY geoWell, string wellName, UInt64 cycleTrack, string cycleTableType)
{
bool b = false;
int cycleId = 2;
if (cycleTableType == WellObjectBaseInfo.CycleTableTypes[(int)(WellObjectBaseInfo.eCycleDataType.CycleLongterm)]) //"CycleLongterm")
cycleId = 1;
else if (cycleTableType == WellObjectBaseInfo.CycleTableTypes[(int)(WellObjectBaseInfo.eCycleDataType.CycleShortterm)])
cycleId = 3;
List<cWellCycle> lstCycles = workAreaDb.Instance.workData.getWellCycles(wellName, cycleId);
if (lstCycles.Count > 0)
{
string jsonStr = "";
WellDataConvert.getWellCyclesJson(ref jsonStr, lstCycles);
b = geoWell.SetWellTrackDataJson(cycleTrack, jsonStr);
}
return b;
}
/// <summary>
//目前 读取的井数据使用的是InterfaceWorkArea中的结构
// 写入井使用WorkData中的实体,注意区别
/// </summary>
//enum eLithid {well, top , bottom, thickness, color , oilcontent , inclusions, lithologyprefix, structure,
// lithology,firstlayer, secondlayer ,fourthlayer, fifthlayer};
public static bool getWellLithologyFromJson(string jh, string jsonStr, out List<WellLithology> listWellLith)
{
string[] Cols = { "well", "top", "bottom", "thickness", "color", "oilcontent", "inclusions", "lithologyprefix",
"structure", "lithology", "firstlayer", "secondlayer", "fourthlayer", "fifthlayer" };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
listWellLith = new List<WellLithology>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "Lithology")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (colMap.HasKey(col))
colMap.UpdateMapping(col, i);
}
int id = DBHelp.Db.Queryable<WellLithology>().Max<int>("id") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
WellLithology wellLith = new WellLithology();
wellLith.ID = id;
for (int j = 0; j < jCols.Count; j++)
{
wellLith.Well = jh;
if (colMap["top"] > -1)
{ wellLith.top = Convert.ToDouble(jRec[colMap["top"]].ToString()); }
if (colMap["bottom"] > -1)
{ wellLith.bottom = Convert.ToDouble(jRec[colMap["bottom"]].ToString()); }
wellLith.thickness = wellLith.bottom - wellLith.top;
if (colMap["color"] > -1)
{ wellLith.color = jRec[colMap["color"]].ToString(); }
if (colMap["oilcontent"] > -1)
{ wellLith.oilcontent = jRec[colMap["oilcontent"]].ToString(); }
if (colMap["inclusions"] > -1)
{ wellLith.inclusions = jRec[colMap["inclusions"]].ToString(); }
if (colMap["lithologyprefix"] > -1)
{ wellLith.lithologyprefix = jRec[colMap["lithologyprefix"]].ToString(); }
if (colMap["structure"] > -1)
{ wellLith.structure = jRec[colMap["structure"]].ToString(); }
if (colMap["lithology"] > -1)
{ wellLith.lithology = jRec[colMap["lithology"]].ToString(); }
if (colMap["firstlayer"] > -1)
{ wellLith.firstlayer = jRec[colMap["firstlayer"]].ToString(); }
if (colMap["secondlayer"] > -1)
{ wellLith.secondlayer = jRec[colMap["secondlayer"]].ToString(); }
if (colMap["thirdlayer"] > -1)
{ wellLith.thirdlayer = jRec[colMap["thirdlayer"]].ToString(); }
if (colMap["fourthlayer"] > -1)
{ wellLith.fourthlayer = jRec[colMap["fourthlayer"]].ToString(); }
if (colMap["fifthlayer"] > -1)
{ wellLith.fifthlayer = jRec[colMap["fifthlayer"]].ToString(); }
if (colMap["lithologyname"] > -1)
{ wellLith.lithologyname = jRec[colMap["lithologyname"]].ToString(); }
if (colMap["markerlayer"] > -1)
{ wellLith.markerlayer = jRec[colMap["markerlayer"]].ToString(); }
}
listWellLith.Add(wellLith);
id++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellInnerLayerFromJson(string jh, string jsonStr, out List<WellInnerLayer> listWellInner)
{
string[] Cols = { "well", "top", "bottom", "thickness", "type" };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
listWellInner = new List<WellInnerLayer>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "InnerLayer")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (colMap.HasKey(col))
colMap.UpdateMapping(col, i);
}
int id = DBHelp.Db.Queryable<WellInnerLayer>().Max<int>("id") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
WellInnerLayer welldata = new WellInnerLayer();
welldata.ID = id;
for (int j = 0; j < jCols.Count; j++)
{
welldata.Well = jh;
if (colMap["top"] > -1)
{ welldata.top = Convert.ToDouble(jRec[colMap["top"]].ToString()); }
if (colMap["bottom"] > -1)
{ welldata.bottom = Convert.ToDouble(jRec[colMap["bottom"]].ToString()); }
welldata.thickness = welldata.bottom - welldata.top;
if (colMap["type"] > -1)
{ welldata.type = jRec[colMap["type"]].ToString(); }
}
listWellInner.Add(welldata);
id++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellPerforationFromJson(string jh, string jsonStr, out List<WellPerforation> list)
{
string[] Cols = { "JH", "DS", "DS2", "CW", "SK" };
//Dictionary<string, string> colNameMap = new Dictionary<string, string> { { "DS", "" }, };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
list = new List<WellPerforation>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "Shot")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (col == "name")
colMap.UpdateMapping("CW", i);
if (col == "top")
colMap.UpdateMapping("DS", i);
if (col == "bottom")
colMap.UpdateMapping("DS2", i);
if (col == "method")
colMap.UpdateMapping("SK", i);
}
int id = DBHelp.Db.Queryable<WellPerforation>().Max<int>("id") + 1;
int xhid = DBHelp.Db.Queryable<WellPerforation>().Max<int>("xhid") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
WellPerforation welldata = new WellPerforation();
welldata.ID = id;
welldata.XHID = xhid;
for (int j = 0; j < jCols.Count; j++)
{
welldata.JH = jh;
if (colMap["DS"] > -1)
{ welldata.DS = Convert.ToDouble(jRec[colMap["DS"]].ToString()); }
if (colMap["DS2"] > -1)
{ welldata.DS2 = Convert.ToDouble(jRec[colMap["DS2"]].ToString()); }
if (colMap["CW"] > -1)
{ welldata.CW = jRec[colMap["CW"]].ToString(); }
if (colMap["SK"] > -1)
{ welldata.SK = jRec[colMap["SK"]].ToString(); }
}
list.Add(welldata);
id++;
xhid++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static void getColNameAndDatasFromJson(string jsonStr, ref string dataType, ref string[] colName, ref string[,] strData)
{ //从json串中获得数据
JObject json = JObject.Parse(jsonStr);
dataType = (string)json["dataType"];
JArray colNames = (JArray)json["columnName"];
colName = new string[colNames.Count()];
int ii = 0;
foreach (string jitem in colNames)
{
//JObject j = (JObject)jitem;
colName[ii] = jitem; // j.ToString();
ii++;
}
ii = 0;
JArray datas = (JArray)json["data"];
strData = new string[datas.Count(), colNames.Count()];
foreach (var jitem in datas)
{
JArray jarr = (JArray)jitem;
int jj = 0;
foreach (string jstr in jarr)
{
strData[ii, jj] = jstr; // Encoding.Unicode.GetString(unicodebytes); // Encoding.UTF8.GetString(utf8byts);
jj++;
}
ii++;
}
}
public static bool getWellFaultsFromJson(string jh, string jsonStr, out List<WellBreakPoint> list)
{
string[] Cols = { "JH", "DCBH", "DDSD", "DSDC", "DSDC2", "DBJDS", "DBJDS2" };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
bool b = false;
list = new List<WellBreakPoint>();
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "FaultPoint")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (col == "name")
colMap.UpdateMapping("DCBH", i);
if (col == "depth")
colMap.UpdateMapping("DDSD", i);
if (col == "topLayer")
colMap.UpdateMapping("DSDC", i);
if (col == "bottomLayer")
colMap.UpdateMapping("DSDC2", i);
if (col == "compareWellTop")
colMap.UpdateMapping("DBJDS", i);
if (col == "compareWellBottom")
colMap.UpdateMapping("DBJDS2", i);
}
int id = DBHelp.Db.Queryable<WellBreakPoint>().Max<int>("id") + 1;
int xhid = DBHelp.Db.Queryable<WellBreakPoint>().Max<int>("XHID") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
WellBreakPoint welldata = new WellBreakPoint();
welldata.ID = id;
welldata.XHID = id;
for (int j = 0; j < jCols.Count; j++)
{
welldata.JH = jh;
if (colMap["DCBH"] > -1)
{ welldata.DCBH = (jRec[colMap["DCBH"]].ToString()); }
if (colMap["DDSD"] > -1)
{ welldata.DDSD = Convert.ToDouble(jRec[colMap["DDSD"]].ToString()); }
if (colMap["DSDC"] > -1)
{ welldata.DSDC = jRec[colMap["DSDC"]].ToString(); }
if (colMap["DSDC2"] > -1)
{ welldata.DSDC2 = jRec[colMap["DSDC2"]].ToString(); }
if (colMap["DBJDS"] > -1)
{ welldata.DBJDS = Convert.ToDouble(jRec[colMap["DBJDS"]].ToString()); }
if (colMap["DBJDS2"] > -1)
{ welldata.DBJDS2 = Convert.ToDouble(jRec[colMap["DBJDS2"]].ToString()); }
}
list.Add(welldata);
id++;
xhid++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellInterpretDrillLayerFromJson(string jh, string jsonStr, out List<InterpretDrillWellLayered> list)
{
string[] Cols = { "JH", "CW", "SD", "DJSD", "JSJL" };
//Dictionary<string, string> colNameMap = new Dictionary<string, string> { { "DS", "" }, };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
list = new List<InterpretDrillWellLayered>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "SandSet") //砂层组对应 kep井分层
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (col == "name")
colMap.UpdateMapping("CW", i);
if (col == "top")
colMap.UpdateMapping("SD", i);
if (col == "bottom")
colMap.UpdateMapping("DJSD", i);
if (col == "result")
colMap.UpdateMapping("JSJL", i);
}
int id = DBHelp.Db.Queryable<InterpretDrillWellLayered>().Max<int>("id") + 1;
int xhid = DBHelp.Db.Queryable<InterpretDrillWellLayered>().Max<int>("XHID") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
InterpretDrillWellLayered welldata = new InterpretDrillWellLayered();
welldata.ID = id;
welldata.XHID = xhid;
for (int j = 0; j < jCols.Count; j++)
{
welldata.JH = jh;
if (colMap["SD"] > -1)
{ welldata.SD = Convert.ToDouble(jRec[colMap["SD"]].ToString()); }
if (colMap["DJSD"] > -1)
{ welldata.DJSD = Convert.ToDouble(jRec[colMap["DJSD"]].ToString()); }
if (colMap["CW"] > -1)
{ welldata.CW = jRec[colMap["CW"]].ToString(); }
if (colMap["JSJL"] > -1)
{ welldata.JSJL = jRec[colMap["JSJL"]].ToString(); }
welldata.HD = welldata.DJSD - welldata.SD;
}
list.Add(welldata);
id++;
xhid++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellReserversLayerFromJson(string jh, string jsonStr, out List<WellReservesLayer> list)
{
string[] Cols = { "layer", "topSecondSandstone", "bottomSecondSandstone", "topFirstSandstone", "bottomFirstSandstone",
"pureEffectiveTopEstimate","pureEffectiveThicknessEstimate","electricLogInterpretation","facies","subfacies"};
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
list = new List<WellReservesLayer>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "ReservesLayer")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (colMap.HasKey(col))
colMap.UpdateMapping(col, i);
}
int id = DBHelp.Db.Queryable<WellReservesLayer>().Max<int>("id") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
WellReservesLayer welldata = new WellReservesLayer();
welldata.ID = id;
for (int j = 0; j < jCols.Count; j++)
{
welldata.Well = jh;
if (colMap["layer"] > -1)
{ welldata.Layer = jRec[colMap["layer"]].ToString(); }
if (colMap["topSecondSandstone"] > -1)
{ welldata.TopSecondSandstone = Convert.ToDouble(jRec[colMap["topSecondSandstone"]].ToString()); }
if (colMap["bottomSecondSandstone"] > -1)
{ welldata.BottomSecondSandstone = Convert.ToDouble(jRec[colMap["bottomSecondSandstone"]].ToString()); }
if (colMap["topFirstSandstone"] > -1)
{ welldata.TopFirstSandstone = Convert.ToDouble(jRec[colMap["topFirstSandstone"]].ToString()); }
if (colMap["bottomFirstSandstone"] > -1)
{ welldata.BottomFirstSandstone = Convert.ToDouble(jRec[colMap["bottomFirstSandstone"]].ToString()); }
if (colMap["pureEffectiveTopEstimate"] > -1)
{ welldata.PureEffectiveTopEstimate = Convert.ToDouble(jRec[colMap["pureEffectiveTopEstimate"]].ToString()); }
if (colMap["pureEffectiveThicknessEstimate"] > -1)
{ welldata.PureEffectiveThicknessEstimate = Convert.ToDouble(jRec[colMap["pureEffectiveThicknessEstimate"]].ToString()); }
if (colMap["electricLogInterpretation"] > -1)
{ welldata.ElectricLogInterpretation = jRec[colMap["electricLogInterpretation"]].ToString(); }
if (colMap["facies"] > -1)
{ welldata.Facies = jRec[colMap["facies"]].ToString(); }
if (colMap["subfacies"] > -1)
{ welldata.Subfacies = jRec[colMap["subfacies"]].ToString(); }
}
list.Add(welldata);
id++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellLongCyClesJsonFromJson(string jh, string jsonStr, out List<CycleLongterm> list)
{
string[] Cols = { "Well", "top", "bottom", "type" };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
list = new List<CycleLongterm>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "Cycle")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (colMap.HasKey(col))
colMap.UpdateMapping(col, i);
}
int id = DBHelp.Db.Queryable<CycleLongterm>().Max<int>("id") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
CycleLongterm welldata = new CycleLongterm();
welldata.ID = id;
for (int j = 0; j < jCols.Count; j++)
{
welldata.Well = jh;
if (colMap["top"] > -1)
{ welldata.top = Convert.ToDouble(jRec[colMap["top"]].ToString()); }
if (colMap["bottom"] > -1)
{ welldata.bottom = Convert.ToDouble(jRec[colMap["bottom"]].ToString()); }
if (colMap["type"] > -1)
{ welldata.type = jRec[colMap["type"]].ToString(); }
}
list.Add(welldata);
id++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellMediumCyClesJsonFromJson(string jh, string jsonStr, out List<CycleMediumterm> list)
{
string[] Cols = { "Well", "top", "bottom", "type" };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
list = new List<CycleMediumterm>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "Cycle")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (colMap.HasKey(col))
colMap.UpdateMapping(col, i);
}
int id = DBHelp.Db.Queryable<CycleMediumterm>().Max<int>("id") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
CycleMediumterm welldata = new CycleMediumterm();
welldata.ID = id;
for (int j = 0; j < jCols.Count; j++)
{
welldata.Well = jh;
if (colMap["top"] > -1)
{ welldata.top = Convert.ToDouble(jRec[colMap["top"]].ToString()); }
if (colMap["bottom"] > -1)
{ welldata.bottom = Convert.ToDouble(jRec[colMap["bottom"]].ToString()); }
if (colMap["type"] > -1)
{ welldata.type = jRec[colMap["type"]].ToString(); }
}
list.Add(welldata);
id++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static bool getWellShortCyClesJsonFromJson(string jh, string jsonStr, out List<CycleShortterm> list)
{
string[] Cols = { "Well", "top", "bottom", "type" };
StringIntMapper colMap = new StringIntMapper();
for (int i = 0; i < Cols.Length; i++)
{
colMap.AddMapping(Cols[i]);
}
list = new List<CycleShortterm>();
bool b = false;
try
{
JObject json = JObject.Parse(jsonStr);
bool bType = json.ContainsKey("dataType");
bool bhaveCols = json.ContainsKey("columnName");
bool bhaveData = json.ContainsKey("data");
if (bType && bhaveCols && bhaveData)
{
string typeName = json["dataType"].ToString();
if (typeName == "Cycle")
{
JArray jCols = (JArray)json["columnName"];
JArray jDatas = (JArray)json["data"];
for (int i = 0; i < jCols.Count; i++)
{
string col = jCols[i].ToString();
if (colMap.HasKey(col))
colMap.UpdateMapping(col, i);
}
int id = DBHelp.Db.Queryable<CycleShortterm>().Max<int>("id") + 1;
for (int i = 0; i < jDatas.Count; i++)
{
JArray jRec = (JArray)jDatas[i];
CycleShortterm welldata = new CycleShortterm();
welldata.ID = id;
for (int j = 0; j < jCols.Count; j++)
{
welldata.Well = jh;
if (colMap["top"] > -1)
{ welldata.top = Convert.ToDouble(jRec[colMap["top"]].ToString()); }
if (colMap["bottom"] > -1)
{ welldata.bottom = Convert.ToDouble(jRec[colMap["bottom"]].ToString()); }
if (colMap["type"] > -1)
{ welldata.type = jRec[colMap["type"]].ToString(); }
}
list.Add(welldata);
id++;
}
b = true;
}
}
}
catch (Exception ex)
{
b = false;
}
return b;
}
public static List<T> GetRowsList<T>( Expression<Func<T, bool>> expression)
{
//ISugarQueryable<T> query = DBHelp.NewDb.Queryable<T>();
//query = query.Where(expression);
//List<T> list = new List<T>();
//query.ForEach(x =>
//{
// list.Add(x);
//});
//return list;
return DBHelp.NewDb.Queryable<T>()
.Where(expression)
.ToList();
}
//public static List<int> getColumnIDInDataset<T>(DataItems dataitems)
//{
// List<int> idList = new List<int>();
// List<EntityColumnInfo> colInfos = DBHelp.GetEntityColumnInfo(typeof(T));
// for(int i = 0; i < dataitems.DataItem.Count; i++)
// {
// for (int jj = 0; jj < colInfos.Count; jj++)
// {
// if (dataitems.DataItem[i].RefColId == colInfos[jj].DbColumnName)
// {
// idList.Add(jj);
// break;
// }
// }
// }
// return idList;
//}
public static List<Dictionary<string, object>> ExtractToDictionaryList<T>(List<T> source,List<string> columnNames)
{
var result = new List<Dictionary<string, object>>();
foreach (var item in source)
{
var dict = new Dictionary<string, object>();
foreach (var columnName in columnNames)
{
var property = typeof(T).GetProperty(columnName);
if (property != null)
{
var value = property.GetValue(item);
dict[columnName] = value ?? DBNull.Value;
}
}
result.Add(dict);
}
return result;
}
public static bool setWellTableDataToTrack(GeoSigmaWellPoleXY geoWell, string wellName, UInt64 trackHandle, string tableId,string colName)
{
bool b = false;
if (tableId == "" || colName=="")
return b;
List<string> colNames = new List<string>();
colNames.Add(colName);
List<Dictionary<string, object>> dataset = null;
if (tableId == DBHelp.GetTableName<WellReservesLayer>())
{
List<WellReservesLayer> listData = GetRowsList<WellReservesLayer>(o => o.Well == wellName);
colNames.Insert(0, "TopSecondSandstone");
colNames.Insert(1, "BottomSecondSandstone");
dataset = ExtractToDictionaryList<WellReservesLayer>(listData, colNames);
}
else if (tableId == DBHelp.GetTableName<WellLithology>())
{
List<WellLithology> listData = GetRowsList<WellLithology>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellLithology>(listData, colNames);
b = true;
}
else if (tableId == DBHelp.GetTableName<WellPerforation>())
{
List<WellPerforation> listData = GetRowsList<WellPerforation>(o => o.JH == wellName);
colNames.Insert(0, "DS");
colNames.Insert(1, "DS2");
dataset = ExtractToDictionaryList<WellPerforation>(listData, colNames);
b = true;
}
else if (tableId == DBHelp.GetTableName<InterpretDrillWellLayered>())
{
List<InterpretDrillWellLayered> listData = GetRowsList<InterpretDrillWellLayered>(o => o.JH == wellName);
colNames.Insert(0, "SD");
colNames.Insert(1, "DJSD");
dataset = ExtractToDictionaryList<InterpretDrillWellLayered>(listData, colNames);
b = true;
}
else if (tableId == DBHelp.GetTableName<WellInnerLayer>())
{
List<WellInnerLayer> listData = GetRowsList<WellInnerLayer>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellInnerLayer>(listData, colNames);
b = true;
}
else if (tableId == DBHelp.GetTableName<WellLithologicalAnalysis>())
{
List<WellLithologicalAnalysis> listData = GetRowsList<WellLithologicalAnalysis>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellLithologicalAnalysis>(listData, colNames);
b = true;
}
else if (tableId == DBHelp.GetTableName<WellSideWallCoring>())
{
List<WellSideWallCoring> listData = GetRowsList<WellSideWallCoring>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellSideWallCoring>(listData, colNames);
b = true;
}
else if (tableId == DBHelp.GetTableName<WellCoring>())
{
List<WellCoring> listData = GetRowsList<WellCoring>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellCoring>(listData, colNames);
b = true;
}
if (dataset.Count == 0)
return b;
JObject json = new JObject();
json["dataType"] = "Data";
JArray jCols = new JArray();
jCols.Add("top");
jCols.Add("bottom");
jCols.Add("name");
json["columnName"] = jCols;
JArray jDatas = new JArray();
for (int k = 0; k < dataset.Count; k++)
{
JArray tdata = new JArray();
for (int h = 0; h < colNames.Count; h++)
{
if (dataset[k].TryGetValue(colNames[h], out object val))
{
tdata.Add(val.ToString());
}
else
tdata.Add("");
}
jDatas.Add(tdata);
}
json["data"] = jDatas;
string jsonStr = "";
jsonStr = JsonConvert.SerializeObject(json);
b = geoWell.SetWellTrackDataJson( trackHandle, jsonStr);
return b;
}
public static bool setDataToWellCommonDataTrack(GeoSigmaWellPoleXY geoWell, string wellName, UInt64 commonDataTrack, string refTable, DataItems tdataItems)
{
bool b = false;
if (refTable == "")
return b;
List<string> colNames = new List<string>();
for(int i =0; i < tdataItems.DataItem.Count; i++)
{
colNames.Add(tdataItems.DataItem[i].RefColId);
}
List<Dictionary<string, object>> dataset = null;
if (refTable == DBHelp.GetTableName<WellReservesLayer>())
{
List<WellReservesLayer> listData = GetRowsList<WellReservesLayer>(o => o.Well == wellName);
if (tdataItems.DepthSegmentMode == "SecondTopBottom")
{
colNames.Insert(0, "TopSecondSandstone");
colNames.Insert(1, "BottomSecondSandstone");
}
else if (tdataItems.DepthSegmentMode == "PureEffectiveTopBottom")
{
colNames.Insert(0, "PureEffectiveTopEstimate");
colNames.Insert(1, "PureEffectiveThicknessEstimate");
}
else if (tdataItems.DepthSegmentMode == "ViewEffectiveTopBottom")
{
colNames.Insert(0, "ViewEffectiveTop");
colNames.Insert(1, "ViewEffectiveThickness");
}
else
{
colNames.Insert(0, "TopFirstSandstone");
colNames.Insert(1, "BottomFirstSandstone");
}
dataset = ExtractToDictionaryList<WellReservesLayer>(listData, colNames);
if (tdataItems.DepthSegmentMode == "PureEffectiveTopBottom")
{
for(int i =0; i< dataset.Count; i++)
{
double dtop = 0;
double dbottom = 0;
if (dataset[i].TryGetValue("PureEffectiveTopEstimate", out object top) && dataset[i].TryGetValue("PureEffectiveThicknessEstimate", out object thick))
{
if(double.TryParse(top.ToString(), out double top1)&& double.TryParse(thick.ToString(),out double thick1))
{
dtop = top1;
dbottom = top1 + thick1;
dataset[i]["PureEffectiveThicknessEstimate"] = dbottom.ToString(); //计算出底深
}
else
{//无效顶底深就赋值为0
dataset[i]["PureEffectiveTopEstimate"] = "0".ToString();
dataset[i]["PureEffectiveThicknessEstimate"] = "0".ToString();
}
}
else
{
dataset[i]["PureEffectiveTopEstimate"] = "0".ToString();
dataset[i]["PureEffectiveThicknessEstimate"] = "0".ToString();
}
}
}
else if (tdataItems.DepthSegmentMode == "ViewEffectiveTopBottom")
{
for (int i = 0; i < dataset.Count; i++)
{
double dtop = 0;
double dbottom = 0;
if (dataset[i].TryGetValue("ViewEffectiveTop", out object top) && dataset[i].TryGetValue("ViewEffectiveThickness", out object thick))
{
if (double.TryParse(top.ToString(), out double top1) && double.TryParse(thick.ToString(), out double thick1))
{
dtop = top1;
dbottom = top1 + thick1;
dataset[i]["ViewEffectiveThickness"] = dbottom.ToString(); //计算出底深
}
else
{//无效顶底深就赋值为0
dataset[i]["ViewEffectiveTop"] = "0".ToString();
dataset[i]["ViewEffectiveThickness"] = "0".ToString();
}
}
else
{
dataset[i]["ViewEffectiveTop"] = "0".ToString();
dataset[i]["ViewEffectiveThickness"] = "0".ToString();
}
}
}
b = true;
}
else if (refTable == DBHelp.GetTableName<WellLithology>())
{
List<WellLithology> listData = GetRowsList<WellLithology>( o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellLithology>(listData, colNames);
b = true;
}
else if (refTable == DBHelp.GetTableName<WellPerforation>())
{
List<WellPerforation> listData = GetRowsList<WellPerforation>(o => o.JH == wellName);
colNames.Insert(0, "DS");
colNames.Insert(1, "DS2");
dataset = ExtractToDictionaryList<WellPerforation>(listData, colNames);
b = true;
}
else if (refTable == DBHelp.GetTableName<InterpretDrillWellLayered>())
{
List<InterpretDrillWellLayered> listData = GetRowsList<InterpretDrillWellLayered>(o => o.JH == wellName);
colNames.Insert(0, "SD");
colNames.Insert(1, "DJSD");
dataset = ExtractToDictionaryList<InterpretDrillWellLayered>(listData, colNames);
b = true;
}
else if (refTable == DBHelp.GetTableName<WellInnerLayer>())
{
List<WellInnerLayer> listData = GetRowsList<WellInnerLayer>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellInnerLayer>(listData, colNames);
b = true;
}
else if (refTable == DBHelp.GetTableName<WellLithologicalAnalysis>())
{
List<WellLithologicalAnalysis> listData = GetRowsList<WellLithologicalAnalysis>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellLithologicalAnalysis>(listData, colNames);
b = true;
}
else if (refTable == DBHelp.GetTableName<WellSideWallCoring>())
{
List<WellSideWallCoring> listData = GetRowsList<WellSideWallCoring>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellSideWallCoring>(listData, colNames);
b = true;
}
else if (refTable == DBHelp.GetTableName<WellCoring>())
{
List<WellCoring> listData = GetRowsList<WellCoring>(o => o.Well == wellName);
colNames.Insert(0, "top");
colNames.Insert(1, "bottom");
dataset = ExtractToDictionaryList<WellCoring>(listData, colNames);
b = true;
}
if (dataset == null)
return b;
string jsonStr = "";
if (dataset.Count == 0)
return b;
JObject json = new JObject();
json["dataType"] = "CommonData";
JArray jCols = new JArray();
jCols.Add("top");
jCols.Add("bottom");
for(int i = 0; i < tdataItems.DataItem.Count; i++)
{
jCols.Add(tdataItems.DataItem[i].RefColId);
}
json["columnName"] = jCols;
JArray jDatas = new JArray();
for(int k = 0; k< dataset.Count; k++)
{
JArray tdata = new JArray();
for (int h = 0; h < colNames.Count; h++)
{
if (dataset[k].TryGetValue(colNames[h], out object val))
{
tdata.Add(val.ToString());
}
else
tdata.Add("");
}
jDatas.Add(tdata);
}
json["data"] = jDatas;
jsonStr = JsonConvert.SerializeObject(json);
b = geoWell.SetWellTrackDataJson(commonDataTrack, jsonStr);
return b;
}
}
}