개정판 8f24b438
dev issue #000 : dev
Change-Id: I9028fd2c54a0abd4dc23db92e63e20422b486fbd
DTI_PID/ID2PSN/DB.cs | ||
---|---|---|
8 | 8 |
using System.Globalization; |
9 | 9 |
using System.Data.SQLite; |
10 | 10 |
using System.Data; |
11 |
using System.Text.RegularExpressions; |
|
11 | 12 |
|
12 | 13 |
namespace ID2PSN |
13 | 14 |
{ |
... | ... | |
15 | 16 |
{ |
16 | 17 |
const string PSN_TOPOLOGY_RULE = "T_PSN_TOPOLOGY_RULE"; |
17 | 18 |
const string PSN_HEADER_SETTING = "T_PSN_HEADER_SETTING"; |
18 |
const string PSN_PATHITEMS = "T_PSN_PATHITEMS";
|
|
19 |
const string PSN_SEQUENCEDATA = "T_PSN_SEQUENCEDATA";
|
|
20 |
const string PSN_PIPESYSTEMNETWORK = "T_PSN_PIPESYSTEMNETWORK";
|
|
21 |
const string PSN_EQUIPMENT = "T_PSN_EQUIPMENT";
|
|
22 |
const string PSN_NOZZLE = "T_PSN_NOZZLE";
|
|
23 |
const string PSN_FLUIDCODE = "T_PSN_FLUIDCODE";
|
|
24 |
const string PSN_PIPINGMATLCLASS = "T_PSN_PIPINGMATLCLASS";
|
|
19 |
const string PSN_PATHITEMS = "SPPIDPathItem";
|
|
20 |
const string PSN_SEQUENCEDATA = "SPPIDSequenceData";
|
|
21 |
const string PSN_PIPESYSTEMNETWORK = "SPPIDPipeSystemNetwork";
|
|
22 |
const string PSN_EQUIPMENT = "SPPIDEquipment";
|
|
23 |
const string PSN_NOZZLE = "SPPIDNozzle";
|
|
24 |
const string PSN_FLUIDCODE = "SPPIDFluidCode";
|
|
25 |
const string PSN_PIPINGMATLCLASS = "SPPIDPipingMatClass";
|
|
25 | 26 |
public static bool ConnTestAndCreateTable() |
26 | 27 |
{ |
27 | 28 |
bool result = false; |
... | ... | |
79 | 80 |
} |
80 | 81 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_FLUIDCODE)).Length == 0) |
81 | 82 |
{ |
82 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Code TEXT, Description TEXT, Condition TEXT, GroundLevel TEXT)", PSN_FLUIDCODE); |
|
83 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Code TEXT, Description TEXT, Condition TEXT, Remarks TEXT, GroundLevel TEXT)", PSN_FLUIDCODE);
|
|
83 | 84 |
cmd.ExecuteNonQuery(); |
84 | 85 |
} |
85 | 86 |
if (dt.Select(string.Format("NAME = '{0}'", PSN_PIPINGMATLCLASS)).Length == 0) |
86 | 87 |
{ |
87 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Priority TEXT, Code TEXT, Description TEXT, Condition TEXT, GroundLevel TEXT)", PSN_PIPINGMATLCLASS); |
|
88 |
cmd.CommandText = string.Format("CREATE TABLE {0} (UID TEXT, Priority TEXT, Code TEXT, Description TEXT, Condition TEXT, Remarks TEXT, GroundLevel TEXT)", PSN_PIPINGMATLCLASS);
|
|
88 | 89 |
cmd.ExecuteNonQuery(); |
89 | 90 |
} |
90 | 91 |
} |
... | ... | |
490 | 491 |
|
491 | 492 |
foreach (DataRow row in dt.Rows) |
492 | 493 |
{ |
493 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Code, @Description, @Condition, @GroundLevel)", PSN_FLUIDCODE); |
|
494 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Code, @Description, @Condition, @Remarks, @GroundLevel)", PSN_FLUIDCODE);
|
|
494 | 495 |
cmd.Parameters.Clear(); |
495 | 496 |
cmd.Parameters.AddWithValue("@UID", row["UID"].ToString()); |
496 | 497 |
cmd.Parameters.AddWithValue("@Code", row["Code"].ToString()); |
497 | 498 |
cmd.Parameters.AddWithValue("@Description", row["Description"].ToString()); |
498 | 499 |
cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString()); |
500 |
cmd.Parameters.AddWithValue("@Remarks", row["Remarks"].ToString()); |
|
499 | 501 |
cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString()); |
500 | 502 |
cmd.ExecuteNonQuery(); |
501 | 503 |
} |
... | ... | |
550 | 552 |
|
551 | 553 |
foreach (DataRow row in dt.Rows) |
552 | 554 |
{ |
553 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Priority, @Code, @Description, @Condition, @GroundLevel)", PSN_PIPINGMATLCLASS); |
|
555 |
cmd.CommandText = string.Format("INSERT INTO {0} VALUES (@UID, @Priority, @Code, @Description, @Condition, @Remarks, @GroundLevel)", PSN_PIPINGMATLCLASS);
|
|
554 | 556 |
cmd.Parameters.Clear(); |
555 | 557 |
cmd.Parameters.AddWithValue("@UID", row["UID"].ToString()); |
556 | 558 |
cmd.Parameters.AddWithValue("@Priority", row["Priority"].ToString()); |
557 | 559 |
cmd.Parameters.AddWithValue("@Code", row["Code"].ToString()); |
558 | 560 |
cmd.Parameters.AddWithValue("@Description", row["Description"].ToString()); |
559 | 561 |
cmd.Parameters.AddWithValue("@Condition", row["Condition"].ToString()); |
562 |
cmd.Parameters.AddWithValue("@Remarks", row["Remarks"].ToString()); |
|
560 | 563 |
cmd.Parameters.AddWithValue("@GroundLevel", row["GroundLevel"].ToString()); |
561 | 564 |
cmd.ExecuteNonQuery(); |
562 | 565 |
} |
... | ... | |
715 | 718 |
return result; |
716 | 719 |
} |
717 | 720 |
|
718 |
public static bool SavePipeSystemNetwork(DataTable dt) |
|
721 |
public static bool SavePipeSystemNetwork(DataTable dt, string revision)
|
|
719 | 722 |
{ |
720 | 723 |
ID2Info id2Info = ID2Info.GetInstance(); |
721 | 724 |
|
... | ... | |
732 | 735 |
{ |
733 | 736 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
734 | 737 |
{ |
735 |
cmd.CommandText = string.Format("DELETE FROM {0}", PSN_PIPESYSTEMNETWORK);
|
|
738 |
cmd.CommandText = string.Format("DELETE FROM {0} WHERE PSNRevisionNumber = '{1}'", PSN_PIPESYSTEMNETWORK, revision);
|
|
736 | 739 |
cmd.ExecuteNonQuery(); |
737 | 740 |
|
738 | 741 |
foreach (DataRow row in dt.Rows) |
... | ... | |
903 | 906 |
|
904 | 907 |
return result; |
905 | 908 |
} |
909 |
|
|
910 |
public static int GetRevision() |
|
911 |
{ |
|
912 |
int result = 0; |
|
913 |
DataTable dt = new DataTable(); |
|
914 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
915 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
916 |
{ |
|
917 |
try |
|
918 |
{ |
|
919 |
connection.Open(); |
|
920 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
921 |
{ |
|
922 |
cmd.CommandText = string.Format("SELECT DISTINCT PSNRevisionNumber FROM {0};", PSN_PIPESYSTEMNETWORK); |
|
923 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
924 |
dt.Load(dr); |
|
925 |
|
|
926 |
foreach (DataRow row in dt.Rows) |
|
927 |
{ |
|
928 |
int revisionNumber = Convert.ToInt32(row["PSNRevisionNumber"]); |
|
929 |
if (result < revisionNumber) |
|
930 |
result = revisionNumber; |
|
931 |
} |
|
932 |
|
|
933 |
result++; |
|
934 |
} |
|
935 |
connection.Close(); |
|
936 |
} |
|
937 |
catch (Exception ex) |
|
938 |
{ |
|
939 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
940 |
result = -1; |
|
941 |
} |
|
942 |
finally |
|
943 |
{ |
|
944 |
connection.Dispose(); |
|
945 |
} |
|
946 |
} |
|
947 |
|
|
948 |
return result; |
|
949 |
} |
|
950 |
|
|
951 |
public static double[] GetDrawingSize() |
|
952 |
{ |
|
953 |
double[] result = null; |
|
954 |
|
|
955 |
DataTable dt = new DataTable(); |
|
956 |
ID2Info id2Info = ID2Info.GetInstance(); |
|
957 |
using (SQLiteConnection connection = new SQLiteConnection(string.Format(CultureInfo.CurrentCulture, "Data Source = {0}", id2Info.DBFilePath), true)) |
|
958 |
{ |
|
959 |
try |
|
960 |
{ |
|
961 |
connection.Open(); |
|
962 |
using (SQLiteCommand cmd = connection.CreateCommand()) |
|
963 |
{ |
|
964 |
cmd.CommandText = "SELECT value FROM Configuration WHERE Section = 'Area' AND Key = 'Drawing';"; |
|
965 |
using (SQLiteDataReader dr = cmd.ExecuteReader()) |
|
966 |
dt.Load(dr); |
|
967 |
|
|
968 |
if (dt.Rows.Count == 1) |
|
969 |
{ |
|
970 |
string value = dt.Rows[0][0].ToString(); |
|
971 |
string[] split = value.Split(new char[] { ',' }); |
|
972 |
result = new double[] { |
|
973 |
Convert.ToDouble(Regex.Replace(split[0], @"[^0-9]", "")), |
|
974 |
Convert.ToDouble(Regex.Replace(split[1], @"[^0-9]", "")), |
|
975 |
Convert.ToDouble(Regex.Replace(split[2], @"[^0-9]", "")), |
|
976 |
Convert.ToDouble(Regex.Replace(split[3], @"[^0-9]", "")) |
|
977 |
}; |
|
978 |
result = new double[] { |
|
979 |
Math.Min(result[0], result[2]), |
|
980 |
Math.Min(result[1], result[3]), |
|
981 |
Math.Max(result[0], result[2]), |
|
982 |
Math.Max(result[1], result[3]) |
|
983 |
}; |
|
984 |
} |
|
985 |
} |
|
986 |
connection.Close(); |
|
987 |
} |
|
988 |
catch (Exception ex) |
|
989 |
{ |
|
990 |
Log.Write(ex.Message + "\r\n" + ex.StackTrace); |
|
991 |
} |
|
992 |
finally |
|
993 |
{ |
|
994 |
connection.Dispose(); |
|
995 |
} |
|
996 |
} |
|
997 |
|
|
998 |
return result; |
|
999 |
} |
|
906 | 1000 |
} |
907 | 1001 |
} |
내보내기 Unified diff